Beispiel #1
0
def create_toolbar_button(parent, toolbar, button_type, **params):
    params = Params(**params)
    params.handler = getattr(params, button_type.handler_callable_name, None)
    if params.handler == None and button_type.handler_name:
        if hasattr(parent, button_type.handler_name):
            params.handler = getattr(parent, button_type.handler_name)
        elif hasattr(parent.parentWidget(), button_type.handler_name):
            params.handler = getattr(parent.parentWidget(),
                                     button_type.handler_name)
        elif hasattr(params, button_type.handler_name):
            params.handler = getattr(params, button_type.handler_name)
    title = nvl(params.button_title, button_type.title)
    handler = params.handler

    #give ability to call addition toolbar handler after proper button handler
    if button_type.handler_callable_name and \
        hasattr(button_type, 'after_toolbar_handler'):
        class ActionToolbarHandler():
            def __init__(self, button_handler, toolbar, after_toolbar_handler):
                self.__button_handler__ = button_handler
                self.__toolbar__ = toolbar
                self.__after_toolbar_handler__ = after_toolbar_handler

            def __call__(self):
                self.__button_handler__()
                self.__after_toolbar_handler__(toolbar)

        #replace button handler with toolbar button handler
        handler = ActionToolbarHandler(handler, toolbar,
                                getattr(button_type, 'after_toolbar_handler'))

    actionSpec = ActionSpec(iconId=button_type.icon_id, handler=handler,
                                 title=title)
    toolbar.addWidget(ToolButtonCommon(toolbar,
                        action=create_action(toolbar, actionSpec)))
Beispiel #2
0
def create_toolbar_button(parent, toolbar, button_type, **params):
    params = Params(**params)
    params.handler = getattr(params, button_type.handler_callable_name, None)
    if params.handler == None and button_type.handler_name:
        if hasattr(parent, button_type.handler_name):
            params.handler = getattr(parent, button_type.handler_name)
        elif hasattr(parent.parentWidget(), button_type.handler_name):
            params.handler = getattr(parent.parentWidget(),
                                     button_type.handler_name)
        elif hasattr(params, button_type.handler_name):
            params.handler = getattr(params, button_type.handler_name)
    title = nvl(params.button_title, button_type.title)
    handler = params.handler

    #give ability to call addition toolbar handler after proper button handler
    if button_type.handler_callable_name and \
        hasattr(button_type, 'after_toolbar_handler'):

        class ActionToolbarHandler():
            def __init__(self, button_handler, toolbar, after_toolbar_handler):
                self.__button_handler__ = button_handler
                self.__toolbar__ = toolbar
                self.__after_toolbar_handler__ = after_toolbar_handler

            def __call__(self):
                self.__button_handler__()
                self.__after_toolbar_handler__(toolbar)

        #replace button handler with toolbar button handler
        handler = ActionToolbarHandler(
            handler, toolbar, getattr(button_type, 'after_toolbar_handler'))

    actionSpec = ActionSpec(iconId=button_type.icon_id,
                            handler=handler,
                            title=title)
    toolbar.addWidget(
        ToolButtonCommon(toolbar, action=create_action(toolbar, actionSpec)))
Beispiel #3
0
 def __createMenuItem(self, _menu, _menuItem):
     for action_spec in _menuItem.actions_specs:
         _menu.addAction(create_action(self.__parent, action_spec))
Beispiel #4
0
 def __createAction__(self, **params):
     return create_action(self.parent, ActionSpec(**params))