Skip to content
Browse files

Update EnamlTaskPane to enaml 0.8.8 .

  • Loading branch information...
1 parent 8d896ff commit 0e79017f4a95b09325a4990307a358ac99f13bfd @pberkes pberkes committed Nov 20, 2013
Showing with 98 additions and 12 deletions.
  1. +1 −0 pyface/tasks/api.py
  2. +49 −12 pyface/tasks/enaml_task_pane.py
  3. +48 −0 pyface/tasks/tests/test_enaml_task_pane.py
View
1 pyface/tasks/api.py
@@ -4,6 +4,7 @@
from dock_pane import DockPane
from editor import Editor
from editor_area_pane import EditorAreaPane
+from enaml_task_pane import EnamlTaskPane
from i_dock_pane import IDockPane
from i_editor import IEditor
from i_editor_area_pane import IEditorAreaPane
View
61 pyface/tasks/enaml_task_pane.py
@@ -1,33 +1,70 @@
# Enthought library imports.
-from traits.api import Instance, on_trait_change
-from enaml.components.constraints_widget import ConstraintsWidget
+from traits.api import Instance
+from enaml.widgets.toolkit_object import ToolkitObject
-# local imports
+# Local imports.
from pyface.tasks.task_pane import TaskPane
class EnamlTaskPane(TaskPane):
- """ Create a Task pane for Enaml Components.
- """
+ """ Create a Task pane for Enaml Components. """
- #### EnamlTaskPane interface ##############################################
+ ###########################################################################
+ # 'EnamlTaskPane' interface
+ ###########################################################################
- component = Instance(ConstraintsWidget)
+ #: The Enaml component defining the contents of the TaskPane.
+ component = Instance(ToolkitObject)
def create_component(self):
- raise NotImplementedError
+ """ 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()
- self.component.setup(parent=parent)
- self.control = self.component.toolkit_widget
+
+ # 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
- self.component.destroy()
-
View
48 pyface/tasks/tests/test_enaml_task_pane.py
@@ -0,0 +1,48 @@
+from traits.testing.unittest_tools import unittest
+
+from enaml.widgets.api import Label
+from traits_enaml.testing.gui_test_assistant import GuiTestAssistant
+
+from pyface.tasks.api import EnamlTaskPane
+
+
+class DummyTaskPane(EnamlTaskPane):
+
+ def create_component(self):
+ return Label(text='test label')
+
+
+class TestEnamlTaskPane(GuiTestAssistant, unittest.TestCase):
+
+ ###########################################################################
+ # 'TestCase' interface
+ ###########################################################################
+
+ def setUp(self):
+ GuiTestAssistant.setUp(self)
+ self.task_pane = DummyTaskPane()
+ with self.event_loop():
+ self.task_pane.create(None)
+
+ def tearDown(self):
+ if self.task_pane.control is not None:
+ with self.delete_widget(self.task_pane.control):
+ self.task_pane.destroy()
+ del self.task_pane
+ GuiTestAssistant.tearDown(self)
+
+ ###########################################################################
+ # Tests
+ ###########################################################################
+
+ def test_creation(self):
+ self.assertIsInstance(self.task_pane.component, Label)
+ self.assertIsNotNone(self.task_pane.control)
+
+ def test_destroy(self):
+ task_pane = self.task_pane
+ with self.delete_widget(task_pane.control):
+ task_pane.destroy()
+ self.assertIsNone(task_pane.control)
+ # Second destruction is a no-op.
+ task_pane.destroy()

0 comments on commit 0e79017

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