1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
""" A view containing a main walter canvas. """
# Enthought library imports.
from pyface.workbench.api import View, WorkbenchWindow
from traits.api import HasTraits, Instance, Str, on_trait_change
from traitsui.api import View as TraitsView
class DebugViewModel(HasTraits):
""" The model for the debug view! """
#### 'Model' interface ####################################################
active_editor = Str
active_part = Str
active_view = Str
window = Instance(WorkbenchWindow)
###########################################################################
# 'Model' interface.
###########################################################################
@on_trait_change(
'window.active_editor', 'window.active_part', 'window.active_view'
)
def refresh(self):
""" Refresh the model. """
self.active_editor = self._get_id(self.window.active_editor)
self.active_part = self._get_id(self.window.active_part)
self.active_view = self._get_id(self.window.active_view)
return
def _window_changed(self):
""" Window changed! """
self.refresh()
return
###########################################################################
# Private interface.
###########################################################################
def _get_id(self, obj):
""" Return the Id of an object. """
if obj is None:
id = 'None'
else:
id = obj.id
return id
class DebugView(View):
""" A view containing a main walter canvas. """
#### 'IWorkbenchPart' interface ###########################################
# The part's name (displayed to the user).
name = 'Debug'
#### 'DebugView' interface ################################################
# The model for the debug view!
model = Instance(DebugViewModel)
###########################################################################
# 'IWorkbenchPart' interface.
###########################################################################
def create_control(self, parent):
""" Creates the toolkit-specific control that represents the view.
'parent' is the toolkit-specific control that is the view's parent.
"""
self.model = DebugViewModel(window=self.window)
ui = self.model.edit_traits(
parent = parent,
kind = 'subpanel',
view = TraitsView('active_part', 'active_editor', 'active_view')
)
return ui.control
#### EOF ######################################################################
|