def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self._uis = [] # Create a DockWindow to hold each separate object's view: theme = self.factory.dock_theme or self.item.container.dock_theme dw = DockWindow(parent, theme=theme) self.control = dw.control self._sizer = DockSizer(DockSection(dock_window=dw)) self.control.SetSizer(self._sizer) # Set up the additional 'list items changed' event handler needed for # a list based trait. Note that we want to fire the update_editor_item # only when the items in the list change and not when intermediate # traits change. Therefore, replace "." by ":" in the extended_name # when setting up the listener. extended_name = self.extended_name.replace('.', ':') self.context_object.on_trait_change( self.update_editor_item, extended_name + '_items?', dispatch='ui') # Set of selection synchronization: self.sync_value(self.factory.selected, 'selected')
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ self._uis = [] # Create a DockWindow to hold each separate object's view: theme = self.factory.dock_theme or self.item.container.dock_theme dw = DockWindow(parent, theme=theme) self.control = dw.control self._sizer = DockSizer(DockSection(dock_window=dw)) self.control.SetSizer(self._sizer) # Set up the additional 'list items changed' event handler needed for # a list based trait: self.context_object.on_trait_change(self.update_editor_item, self.extended_name + '_items?', dispatch='ui') # Set of selection synchronization: self.sync_value(self.factory.selected, 'selected')
def __init__( self, panel, group, ui, suppress_label, is_dock_window, create_panel ): """ Initializes the object. """ # Get the contents of the group: content = group.get_content() # Create a group editor object if one is needed: self.control = self.sizer = editor = None self.ui = ui self.group = group self.is_horizontal = group.orientation == "horizontal" layout = group.layout is_scrolled_panel = group.scrollable is_splitter = layout == "split" is_tabbed = layout == "tabbed" id = group.id # Assume our contents are not resizable: self.resizable = False if is_dock_window and (is_splitter or is_tabbed): if is_splitter: self.dock_contents = self.add_dock_window_splitter_items( panel, content, group ) else: self.resizable = group.springy self.dock_contents = create_notebook_for_items( content, ui, panel, group, self.add_notebook_item, True ) return if ( is_dock_window or create_panel or is_scrolled_panel or (id != "") or (group.visible_when != "") or (group.enabled_when != "") ): if is_scrolled_panel: new_panel = TraitsUIScrolledPanel(panel) new_panel.SetMinSize(panel.GetMinSize()) self.resizable = True else: new_panel = TraitsUIPanel(panel, -1) sizer = panel.GetSizer() if sizer is None: sizer = wx.BoxSizer(wx.VERTICAL) panel.SetSizer(sizer) self.control = panel = new_panel if is_splitter or is_tabbed: editor = DockWindowGroupEditor(control=panel, ui=ui) else: editor = GroupEditor(control=panel) if id != "": ui.info.bind(group.id, editor) if group.visible_when != "": ui.add_visible(group.visible_when, editor) if group.enabled_when != "": ui.add_enabled(group.enabled_when, editor) self.panel = panel self.dock_contents = None # Determine the horizontal/vertical orientation of the group: if self.is_horizontal: orientation = wx.HORIZONTAL else: orientation = wx.VERTICAL # Set up a group with or without a border around its contents: label = "" if not suppress_label: label = group.label if group.show_border: box = wx.StaticBox(panel, -1, label) self._set_owner(box, group) self.sizer = wx.StaticBoxSizer(box, orientation) else: if layout == "flow": self.sizer = FlowSizer(orientation) else: self.sizer = wx.BoxSizer(orientation) if label != "": self.sizer.Add( heading_text(panel, text=label).control, 0, wx.EXPAND | wx.LEFT | wx.TOP | wx.RIGHT, 4, ) # If no sizer has been specified for the panel yet, make the new sizer # the layout sizer for the panel: if panel.GetSizer() is None: panel.SetSizer(self.sizer) # Set up scrolling now that the sizer has been set: if is_scrolled_panel: if self.is_horizontal: panel.SetupScrolling(scroll_y=False) else: panel.SetupScrolling(scroll_x=False) if is_splitter: dw = DockWindow( panel, handler=ui.handler, handler_args=(ui.info,), id=ui.id, theme=group.dock_theme, ).control if editor is not None: editor.dock_window = dw dw.SetSizer( DockSizer( contents=self.add_dock_window_splitter_items( dw, content, group ) ) ) self.sizer.Add(dw, 1, wx.EXPAND) elif len(content) > 0: if is_tabbed: self.resizable = group.springy dw = create_notebook_for_items( content, ui, panel, group, self.add_notebook_item ) if editor is not None: editor.dock_window = dw self.sizer.Add(dw, self.resizable, wx.EXPAND) # Check if content is all Group objects: elif layout == "fold": self.resizable = True self.sizer.Add( self.create_fold_for_items(panel, content), 1, wx.EXPAND ) elif isinstance(content[0], Group): # If so, add them to the panel and exit: self.add_groups(content, panel) else: self.add_items(content, panel, self.sizer) # If the caller is a DockWindow, we need to define the content we are # adding to it: if is_dock_window: self.dock_contents = DockRegion( contents=[ DockControl( name=group.get_label(self.ui), image=group.image, id=group.get_id(), style=group.dock, dockable=DockableViewElement(ui=ui, element=group), export=group.export, control=panel, ) ] )
def create_notebook_for_items( content, ui, parent, group, item_handler=None, is_dock_window=False ): """ Creates a notebook and adds a list of groups or items to it as separate pages. """ if is_dock_window: nb = parent else: dw = DockWindow( parent, handler=ui.handler, handler_args=(ui.info,), id=ui.id ) if group is not None: dw.theme = group.dock_theme nb = dw.control pages = [] count = 0 # Create a notebook page for each group or item in the content: active = 0 for index, item in enumerate(content): if isinstance(item, Group): # Create the group as a nested DockWindow item: if item.selected: active = index sg_sizer, resizable, contents = fill_panel_for_group( nb, item, ui, suppress_label=True, is_dock_window=True ) # If the result is a region (i.e. notebook) with only one page, # collapse it down into just the contents of the region: if isinstance(contents, DockRegion) and ( len(contents.contents) == 1 ): contents = contents.contents[0] # Add the content to the notebook as a new page: pages.append(contents) else: # Create the new page as a simple DockControl containing the # specified set of controls: page_name = item.get_label(ui) count += 1 if page_name == "": page_name = "Page %d" % count sizer = wx.BoxSizer(wx.VERTICAL) panel = TraitsUIPanel(nb, -1) panel.SetSizer(sizer) pages.append( DockControl( name=page_name, image=item.image, id=item.get_id(), style=item.dock, dockable=DockableViewElement(ui=ui, element=item), export=item.export, control=panel, ) ) item_handler(item, panel, sizer) panel.GetSizer().Fit(panel) region = DockRegion(contents=pages, active=active) # If the caller is a DockWindow, return the region as the result: if is_dock_window: return region nb.SetSizer(DockSizer(contents=DockSection(contents=[region]))) # Return the notebook as the result: return nb
def create_notebook_for_items(content, ui, parent, group, item_handler=None, is_dock_window=False): """ Creates a notebook and adds a list of groups or items to it as separate pages. """ if is_dock_window: nb = parent else: dw = DockWindow(parent, handler=ui.handler, handler_args=(ui.info, ), id=ui.id) if group is not None: dw.theme = group.dock_theme nb = dw.control pages = [] count = 0 # Create a notebook page for each group or item in the content: active = 0 for index, item in enumerate(content): if isinstance(item, Group): # Create the group as a nested DockWindow item: if item.selected: active = index sg_sizer, resizable, contents = \ fill_panel_for_group(nb, item, ui, suppress_label=True, is_dock_window=True) # If the result is a region (i.e. notebook) with only one page, # collapse it down into just the contents of the region: if (isinstance(contents, DockRegion) and (len(contents.contents) == 1)): contents = contents.contents[0] # Add the content to the notebook as a new page: pages.append(contents) else: # Create the new page as a simple DockControl containing the # specified set of controls: page_name = item.get_label(ui) count += 1 if page_name == '': page_name = 'Page %d' % count sizer = wx.BoxSizer(wx.VERTICAL) panel = TraitsUIPanel(nb, -1) panel.SetSizer(sizer) pages.append(DockControl(name=page_name, image=item.image, id=item.get_id(), style=item.dock, dockable=DockableViewElement( ui=ui, element=item), export=item.export, control=panel)) item_handler(item, panel, sizer) panel.GetSizer().Fit(panel) region = DockRegion(contents=pages, active=active) # If the caller is a DockWindow, return the region as the result: if is_dock_window: return region nb.SetSizer(DockSizer(contents=DockSection(contents=[region]))) # Return the notebook as the result: return nb