def add_dock_window_splitter_item(self, window, item, group): """ Adds a single group or item to a DockWindow. """ if isinstance(item, Group): sizer, resizable, contents = fill_panel_for_group( window, item, self.ui, suppress_label=True, is_dock_window=True) self.resizable |= resizable return contents orientation = wx.VERTICAL if self.is_horizontal: orientation = wx.HORIZONTAL sizer = wx.BoxSizer(orientation) panel = TraitsUIPanel(window, -1) panel.SetSizer(sizer) self.add_items([item], panel, sizer) return DockRegion(contents=[ DockControl(name=item.get_label(self.ui), image=item.image, id=item.get_id(), style=item.dock, dockable=DockableViewElement(ui=self.ui, element=item), export=item.export, control=panel) ])
def create_fold_for_item(self, notebook, item): """ Adds a single group or item to a vertical notebook. """ # Create a new notebook page: page = notebook.create_page() # Create the page contents: if isinstance(item, Group): panel, resizable, contents = fill_panel_for_group( page.parent, item, self.ui, suppress_label=True, create_panel=True) else: panel = TraitsUIPanel(page.parent, -1) sizer = wx.BoxSizer(wx.VERTICAL) panel.SetSizer(sizer) self.add_items([item], panel, sizer) # Set the page name and control: page.name = item.get_label(self.ui) page.control = panel # Return the new notebook page: return page
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