Skip to content

uimaker

UI maker.

Attributes

mlogger = get_logger(__name__) module-attribute

CONFIG_SCRIPT_TITLE_POSTFIX = '‚óŹ' module-attribute

current_ui = ribbon.get_current_ui() module-attribute

Classes

UIMakerParams(par_ui, par_cmp, cmp_item, asm_info, create_beta=False)

UI maker parameters.

Parameters:

Name Type Description Default
par_ui _PyRevitUI

Parent UI item

required
par_cmp GenericUIComponent

Parent UI component

required
cmp_item GenericUIComponent

UI component item

required
asm_info AssemblyInfo

Assembly info

required
create_beta bool

Create beta button. Defaults to False

False
Source code in pyrevitlib/pyrevit/loader/uimaker.py
def __init__(self, par_ui, par_cmp, cmp_item, asm_info, create_beta=False):
    self.parent_ui = par_ui
    self.parent_cmp = par_cmp
    self.component = cmp_item
    self.asm_info = asm_info
    self.create_beta_cmds = create_beta

Attributes

parent_ui = par_ui instance-attribute
parent_cmp = par_cmp instance-attribute
component = cmp_item instance-attribute
asm_info = asm_info instance-attribute
create_beta_cmds = create_beta instance-attribute

Functions

update_pyrevit_ui(ui_ext, ext_asm_info, create_beta=False)

Updates/Creates pyRevit ui for the extension and assembly dll address.

Parameters:

Name Type Description Default
ui_ext GenericUIContainer

UI container.

required
ext_asm_info AssemblyInfo

Assembly info.

required
create_beta bool

Create beta ui. Defaults to False.

False
Source code in pyrevitlib/pyrevit/loader/uimaker.py
def update_pyrevit_ui(ui_ext, ext_asm_info, create_beta=False):
    """Updates/Creates pyRevit ui for the extension and assembly dll address.

    Args:
        ui_ext (GenericUIContainer): UI container.
        ext_asm_info (AssemblyInfo): Assembly info.
        create_beta (bool, optional): Create beta ui. Defaults to False.
    """
    mlogger.debug('Creating/Updating ui for extension: %s', ui_ext)
    cmp_count = _recursively_produce_ui_items(
        UIMakerParams(current_ui, None, ui_ext, ext_asm_info, create_beta))
    mlogger.debug('%s components were created for: %s', cmp_count, ui_ext)

sort_pyrevit_ui(ui_ext)

Sorts pyRevit UI.

Parameters:

Name Type Description Default
ui_ext GenericUIContainer

UI container.

required
Source code in pyrevitlib/pyrevit/loader/uimaker.py
def sort_pyrevit_ui(ui_ext):
    """Sorts pyRevit UI.

    Args:
        ui_ext (GenericUIContainer): UI container.
    """
    # only works on panels so far
    # re-ordering of ui components deeper than panels have not been implemented
    for tab in current_ui.get_pyrevit_tabs():
        for litem in ui_ext.find_layout_items():
            if litem.directive:
                if litem.directive.directive_type == 'before':
                    tab.reorder_before(litem.name, litem.directive.target)
                elif litem.directive.directive_type == 'after':
                    tab.reorder_after(litem.name, litem.directive.target)
                elif litem.directive.directive_type == 'afterall':
                    tab.reorder_afterall(litem.name)
                elif litem.directive.directive_type == 'beforeall':
                    tab.reorder_beforeall(litem.name)

cleanup_pyrevit_ui()

Cleanup the pyrevit UI.

Hide all items that were not touched after a reload meaning they have been removed in extension folder structure and thus are not updated.

Source code in pyrevitlib/pyrevit/loader/uimaker.py
def cleanup_pyrevit_ui():
    """Cleanup the pyrevit UI.

    Hide all items that were not touched after a reload
    meaning they have been removed in extension folder structure
    and thus are not updated.
    """
    untouched_items = current_ui.get_unchanged_items()
    for item in untouched_items:
        if not item.is_native():
            try:
                mlogger.debug('Deactivating: %s', item)
                item.deactivate()
            except Exception as deact_err:
                mlogger.debug(deact_err)

reflow_pyrevit_ui(direction=applocales.DEFAULT_LANG_DIR)

Set the flow direction of the tabs.

Source code in pyrevitlib/pyrevit/loader/uimaker.py
def reflow_pyrevit_ui(direction=applocales.DEFAULT_LANG_DIR):
    """Set the flow direction of the tabs."""
    if direction == "LTR":
        current_ui.set_LTR_flow()
    elif direction == "RTL":
        current_ui.set_RTL_flow()