2011-09-12 62 views
2

我剛從設想框架開始。在4.x版本中,我看到了一些例子,但我需要一個很好的文檔:linkPython設想框架

如何將自定義按鈕添加到設想工作臺,或者如何創建類似的按鈕?

回答

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 ###################################################################### 
+0

我想創建一個用戶接口,具有按鈕,我們從傳感器接收數據,並且我們需要一些帶有動作(任務)的按鈕,並且我們希望使用Mayavi進行繪圖,但是由於插件系統,我們選擇了這個框架,但不幸的是沒有一個很好的文檔框架。 –

+0

在這種情況下,您可能想要使用基於TraitsUI的東西。 http://code.enthought.com/projects/traits/docs/html/TUIUG/index.html –

+0

是否可以使用插件進行擴展? –