Skip to content
Browse files

Remove redundancies from EnamlTaskPane and EnamlEditor.

  • Loading branch information...
1 parent c3e3318 commit 7bc85948687377f3e40a7a1e9e5ce112042a90ab @pberkes pberkes committed Nov 20, 2013
Showing with 73 additions and 130 deletions.
  1. +2 −65 pyface/tasks/enaml_editor.py
  2. +69 −0 pyface/tasks/enaml_pane.py
  3. +2 −65 pyface/tasks/enaml_task_pane.py
View
67 pyface/tasks/enaml_editor.py
@@ -1,70 +1,7 @@
-# Enthought library imports.
-from traits.api import Instance
-from enaml.widgets.toolkit_object import ToolkitObject
-
# local imports
from pyface.tasks.editor import Editor
+from pyface.tasks.enaml_pane import EnamlPane
-class EnamlEditor(Editor):
+class EnamlEditor(EnamlPane, Editor):
""" Create an Editor for Enaml Components. """
-
- ###########################################################################
- # 'EnamlEditor' interface
- ###########################################################################
-
- #: The Enaml component defining the contents of the Editor.
- component = Instance(ToolkitObject)
-
- def create_component(self):
- """ Return an Enaml component defining the contents of the Editor.
-
- Returns
- -------
- component : ToolkitObject
- """
- raise NotImplementedError
-
- ###########################################################################
- # 'IEditor' interface.
- ###########################################################################
-
- def create(self, parent):
- """ Create the toolkit-specific control that represents the editor. """
-
- self.component = self.create_component()
-
- # We start with an invisible component to avoid flicker. We restore the
- # initial state after the Qt control is parented.
- visible = self.component.visible
- self.component.visible = False
-
- # Initialize the proxy.
- self.component.initialize()
-
- # Activate the proxy.
- if not self.component.proxy_is_active:
- self.component.activate_proxy()
-
- # Fish the Qt control out of the proxy. That's our TaskPane content.
- self.control = self.component.proxy.widget
-
- # Set the parent
- if parent is not None:
- self.control.setParent(parent)
-
- # Restore the visibility state
- self.component.visible = visible
- self.component.proxy.relayout()
-
- def destroy(self):
- """ Destroy the toolkit-specific control that represents the editor.
- """
-
- control = self.control
- if control is not None:
- control.hide()
- self.component.destroy()
- control.deleteLater()
-
- self.control = None
View
69 pyface/tasks/enaml_pane.py
@@ -0,0 +1,69 @@
+""" Base class defining common code for EnamlTaskPane and EnamlEditor. """
+
+# Enthought library imports.
+from enaml.widgets.toolkit_object import ToolkitObject
+from traits.api import HasTraits, Instance
+
+
+class EnamlPane(HasTraits):
+ """ Base class defining common code for EnamlTaskPane and EnamlEditor. """
+
+ ###########################################################################
+ # 'EnamlPane' interface
+ ###########################################################################
+
+ #: The Enaml component defining the contents of the TaskPane.
+ component = Instance(ToolkitObject)
+
+ def create_component(self):
+ """ Return an Enaml component defining the contents of the pane.
+
+ Returns
+ -------
+ component : ToolkitObject
+ """
+ raise NotImplementedError
+
+ ###########################################################################
+ # 'TaskPane'/'Editor' interface
+ ###########################################################################
+
+ def create(self, parent):
+ """ Create the toolkit-specific control that represents the editor. """
+
+ self.component = self.create_component()
+
+ # We start with an invisible component to avoid flicker. We restore the
+ # initial state after the Qt control is parented.
+ visible = self.component.visible
+ self.component.visible = False
+
+ # Initialize the proxy.
+ self.component.initialize()
+
+ # Activate the proxy.
+ if not self.component.proxy_is_active:
+ self.component.activate_proxy()
+
+ # Fish the Qt control out of the proxy. That's our TaskPane content.
+ self.control = self.component.proxy.widget
+
+ # Set the parent
+ if parent is not None:
+ self.control.setParent(parent)
+
+ # Restore the visibility state
+ self.component.visible = visible
+ self.component.proxy.relayout()
+
+ def destroy(self):
+ """ Destroy the toolkit-specific control that represents the editor.
+ """
+
+ control = self.control
+ if control is not None:
+ control.hide()
+ self.component.destroy()
+ control.deleteLater()
+
+ self.control = None
View
67 pyface/tasks/enaml_task_pane.py
@@ -1,70 +1,7 @@
-# Enthought library imports.
-from traits.api import Instance
-from enaml.widgets.toolkit_object import ToolkitObject
-
# Local imports.
from pyface.tasks.task_pane import TaskPane
+from pyface.tasks.enaml_pane import EnamlPane
-class EnamlTaskPane(TaskPane):
+class EnamlTaskPane(EnamlPane, TaskPane):
""" Create a Task pane for Enaml Components. """
-
- ###########################################################################
- # 'EnamlTaskPane' interface
- ###########################################################################
-
- #: The Enaml component defining the contents of the TaskPane.
- component = Instance(ToolkitObject)
-
- def create_component(self):
- """ Return an Enaml component defining the contents of the TaskPane.
-
- Returns
- -------
- component : ToolkitObject
- """
- raise NotImplementedError
-
- ###########################################################################
- # 'ITaskPane' interface.
- ###########################################################################
-
- def create(self, parent):
- """ Create the toolkit-specific control that represents the pane. """
-
- self.component = self.create_component()
-
- # We start with an invisible component to avoid flicker. We restore the
- # initial state after the Qt control is parented.
- visible = self.component.visible
- self.component.visible = False
-
- # Initialize the proxy.
- self.component.initialize()
-
- # Activate the proxy.
- if not self.component.proxy_is_active:
- self.component.activate_proxy()
-
- # Fish the Qt control out of the proxy. That's our TaskPane content.
- self.control = self.component.proxy.widget
-
- # Set the parent
- if parent is not None:
- self.control.setParent(parent)
-
- # Restore the visibility state
- self.component.visible = visible
- self.component.proxy.relayout()
-
- def destroy(self):
- """ Destroy the toolkit-specific control that represents the pane. """
-
- control = self.control
- if control is not None:
- control.hide()
- self.component.destroy()
- control.setParent(None)
- control.deleteLater()
-
- self.control = None

0 comments on commit 7bc8594

Please sign in to comment.
Something went wrong with that request. Please try again.