1 2from traits.api import Float, Enum, Any, Property 3 4from ..view import View 5 6from ..item import Item 7 8from ..editor_factory import EditorFactory 9 10from ..basic_editor_factory import BasicEditorFactory 11 12from .text_editor import TextEditor 13 14from ..ui_traits import EditorStyle 15 16from ..ui_editor import UIEditor 17 18from ..toolkit import toolkit_object 19 20# ------------------------------------------------------------------------- 21# '_PopupEditor' class: 22# ------------------------------------------------------------------------- 23 24 25class _PopupEditor(UIEditor): 26 def init_ui(self, parent): 27 """ Creates the traits UI for the editor. 28 """ 29 return self.object.edit_traits(view=self.base_view(), parent=parent) 30 31 def base_view(self): 32 """ Returns the View that allows the popup view to be displayed. 33 """ 34 return View( 35 Item( 36 self.name, 37 show_label=False, 38 style="readonly", 39 editor=TextEditor(view=self.popup_view()), 40 padding=-4, 41 ), 42 kind="subpanel", 43 ) 44 45 def popup_view(self): 46 """ Returns the popup View. 47 """ 48 factory = self.factory 49 item = Item( 50 self.name, 51 show_label=False, 52 padding=-4, 53 style=factory.style, 54 height=factory.height, 55 width=factory.width, 56 ) 57 58 editor = factory.editor 59 if editor is not None: 60 if not isinstance(editor, EditorFactory): 61 editor = editor() 62 item.editor = editor 63 64 return View(item, kind=factory.kind) 65 66 67# ------------------------------------------------------------------------- 68# 'PopupEditor' class: 69# ------------------------------------------------------------------------- 70 71 72class PopupEditor(BasicEditorFactory): 73 74 #: The class used to construct editor objects: 75 klass = Property() 76 77 #: The kind of popup to use: 78 kind = Enum("popover", "popup", "info") 79 80 #: The editor to use for the pop-up view (can be None (use default editor), 81 #: an EditorFactory instance, or a callable that returns an EditorFactory 82 #: instance): 83 editor = Any() 84 85 #: The style of editor to use for the popup editor (same as Item.style): 86 style = EditorStyle 87 88 #: The height of the popup (same as Item.height): 89 height = Float(-1.0) 90 91 #: The width of the popup (same as Item.width): 92 width = Float(-1.0) 93 94 def _get_klass(self): 95 """ The class used to construct editor objects. 96 """ 97 return toolkit_object("popup_editor:_PopupEditor") 98