Question

I just started with envisage framework. In the 4.x version I saw a few example, but I need a good documentation: link.

How can I add custom buttons to the envisage workbench, or how can I create a similar one?

Was it helpful?

Solution

The best place look for documentation is the Acmelab example in the Envisage source tree.

I'm assuming when you talk about custom buttons you mean buttons on a toolbar. First you need to create a WorkbenchActionSet, add your toolbar there, and then define your actions and assign them a button image. Here is the (slightly modified) Acmelab example with non-relevant parts taken out:

test_action_set.py

# Enthought library imports.
from envisage.ui.action.api import Action, Group, Menu, ToolBar
from envisage.ui.workbench.api import WorkbenchActionSet


class TestActionSet(WorkbenchActionSet):
    """ An action test useful for testing. """

    #### 'ActionSet' interface ################################################

    tool_bars = [
        ToolBar(name='Fred', groups=['AToolBarGroup']),
        ToolBar(name='Wilma'),
        ToolBar(name='Barney')
    ]

    actions = [
        Action(
            path='ToolBar',
            class_name='acme.workbench.action.new_view_action:NewViewAction'
        ),]

new_view_action.py

""" An action that dynamically creates and adds a view. """


# Enthought library imports.
from pyface.api import ImageResource
from pyface.action.api import Action
from pyface.workbench.api import View


class NewViewAction(Action):
    """ An action that dynamically creates and adds a view. """

    #### 'Action' interface ###################################################

    # A longer description of the action.
    description = 'Create and add a new view'

    # The action's name (displayed on menus/tool bar tools etc).
    name = 'New View'

    # A short description of the action used for tooltip text etc.
    tooltip = 'Create and add a new view'

    image = ImageResource(Your Image File Name Goes Here)

    ###########################################################################
    # 'Action' interface.
    ###########################################################################

    def perform(self, event):
        """ Perform the action. """
    # You can give the view a position... (it default to 'left')...
    view = View(id='my.view.fred', name='Fred', position='right')
    self.window.add_view(view)

    # or you can specify it on the call to 'add_view'...
    view = View(id='my.view.wilma', name='Wilma')
    self.window.add_view(view, position='top')

    return

#### EOF ######################################################################
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top