Python设想框架

发布于 2024-12-04 09:27:31 字数 156 浏览 7 评论 0原文

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗恋未遂 2024-12-11 09:27:31

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

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

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 ######################################################################
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文