Python设想框架

时间:2011-09-12 11:29:20

标签: python user-interface frameworks enthought

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

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

1 个答案:

答案 0 :(得分:2)

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

我假设当你谈论自定义按钮时,你的意思是工具栏上的按钮。首先,您需要创建一个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 ######################################################################