Debian Codegraph @

envisage/ui/workbench/workbench_editor_manager.py

raw
1 # (C) Copyright 2007-2025 Enthought, Inc., Austin, TX
2 # All rights reserved.
3 #
4 # This software is provided without warranty under the terms of the BSD
5 # license included in LICENSE.txt and may be redistributed only under
6 # the conditions described in the aforementioned license. The license
7 # is also available online at http://www.enthought.com/licenses/BSD.txt
8 #
9 # Thanks for using Enthought open source!
10 """ An editor manager that uses contributed editors. """
11
12 # Enthought library imports.
13 from pyface.workbench.api import EditorManager, TraitsUIEditor
14
15
16 class WorkbenchEditorManager(EditorManager):
17 """An editor manager that uses contributed editors."""
18
19 ###########################################################################
20 # 'IEditorManager' interface.
21 ###########################################################################
22
23 def create_editor(self, window, obj, kind):
24 """Create an editor for an object.
25
26 For now, the 'kind' is actually a factory that produces editors. It
27 should be a callable with the following signature::
28
29 callable(window=window, obj=obj) -> IEditor
30 """
31
32 if kind is None:
33 kind = TraitsUIEditor
34
35 editor = kind(window=window, obj=obj)
36
37 self.add_editor(editor, kind)
38
39 return editor
40
41 ###########################################################################
42 # 'Protected' 'EditorManager' interface.
43 ###########################################################################
44
45 def _is_editing(self, editor, obj, kind):
46 """Return True if the editor is editing the object."""
47
48 if kind is None:
49 kind = TraitsUIEditor
50 return self.get_editor_kind(editor) is kind and editor.obj == obj