Ejemplo n.º 1
0
    def add_button ( self, action, bbox, method=None, enabled=True,
                     name=None, default=False ):
        """ Creates a button.
        """
        ui = self.ui
        if ((action.defined_when != '') and
            (not ui.eval_when( action.defined_when ))):
            return None

        if name is None:
            name = action.name
        id     = action.id
        button = Button( str(name) )
        bbox.addComponent(button)

        bbox.setComponentAlignment(button, Alignment.MIDDLE_RIGHT)

        if default:
            button.focus()
        button.setEnabled(enabled)
        if (method is None) or (action.enabled_when != '') or (id != ''):
            editor = ButtonEditor( ui      = ui,
                                   action  = action,
                                   control = button )
            if id != '':
                ui.info.bind( id, editor )
            if action.visible_when != '':
                ui.add_visible( action.visible_when, editor )
            if action.enabled_when != '':
                ui.add_enabled( action.enabled_when, editor )
            if method is None:
                method = editor.perform

        if method is not None:
            button.addCallback(method, ClickEvent)

        if action.tooltip != '':
            button.setDescription(action.tooltip)

        return button