2

我刚开始使用设想框架。在 4.x 版本中我看到了一些示例,但我需要一个好的文档:链接

如何将自定义按钮添加到设想工作台,或者如何创建类似的按钮?

4

1 回答 1

2

查找文档的最佳位置是 Envisage 源代码树中的Acmelab 示例

我假设当您谈论自定义按钮时,您的意思是工具栏上的按钮。首先,您需要创建一个 WorkbenchActionSet,在其中添加您的工具栏,然后定义您的操作并为其分配一个按钮图像。这是(稍作修改的)Acmelab 示例,其中不相关的部分被删除:

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 ######################################################################
于 2011-09-12T14:23:15.243 回答