Skip to content

Commit

Permalink
Remove redundancies from EnamlTaskPane and EnamlEditor.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Berkes committed Nov 20, 2013
1 parent c3e3318 commit 7bc8594
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 130 deletions.
67 changes: 2 additions & 65 deletions 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
69 changes: 69 additions & 0 deletions 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
67 changes: 2 additions & 65 deletions 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.