Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove redundancies from EnamlTaskPane and EnamlEditor.
- Loading branch information
Pietro Berkes
committed
Nov 20, 2013
1 parent
c3e3318
commit 7bc8594
Showing
3 changed files
with
73 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |