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 95 96 97
|
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
""" An editor whose content is provided by a traits UI. """
import logging
from traits.api import Instance, Str
from .editor import Editor
# Logging.
logger = logging.getLogger(__name__)
class TraitsUIEditor(Editor):
""" An editor whose content is provided by a traits UI. """
# 'TraitsUIEditor' interface -------------------------------------------
# The traits UI that represents the editor.
#
# The framework sets this to the value returned by 'create_ui'.
ui = Instance("traitsui.ui.UI")
# The name of the traits UI view used to create the UI (if not specified,
# the default traits UI view is used).
view = Str()
# ------------------------------------------------------------------------
# 'IWorkbenchPart' interface.
# ------------------------------------------------------------------------
# Trait initializers ---------------------------------------------------
def _name_default(self):
""" Trait initializer. """
return str(self.obj)
# Methods -------------------------------------------------------------#
def create_control(self, parent):
""" Creates the toolkit-specific control that represents the editor.
'parent' is the toolkit-specific control that is the editor's parent.
Overridden to call 'create_ui' to get the traits UI.
"""
self.ui = self.create_ui(parent)
return self.ui.control
def destroy_control(self):
""" Destroys the toolkit-specific control that represents the editor.
Overridden to call 'dispose' on the traits UI.
"""
# Give the traits UI a chance to clean itself up.
if self.ui is not None:
logger.debug("disposing traits UI for editor [%s]", self)
self.ui.dispose()
self.ui = None
return
# ------------------------------------------------------------------------
# 'TraitsUIEditor' interface.
# ------------------------------------------------------------------------
def create_ui(self, parent):
""" Creates the traits UI that represents the editor.
By default it calls 'edit_traits' on the editor's 'obj'. If you
want more control over the creation of the traits UI then override!
"""
ui = self.obj.edit_traits(
parent=parent, view=self.view, kind="subpanel"
)
return ui
|