def panel(ui, parent): """ Creates a panel-based wxPython user interface for a specified UI object. This function does not modify the UI object passed to it """ # Bind the context values to the 'info' object: ui.info.bind_context() # Get the content that will be displayed in the user interface: content = ui._groups # If there is 0 or 1 Groups in the content, create a single panel for it: if len(content) <= 1: panel = TraitsUIPanel(parent, -1) if len(content) == 1: # Fill the panel with the Group's content: sg_sizer, resizable, contents = fill_panel_for_group( panel, content[0], ui) sizer = panel.GetSizer() if sizer is not sg_sizer: sizer.Add(sg_sizer, 1, wx.EXPAND) # Make sure the panel and its contents have been laid out properly: sizer.Fit(panel) # Return the panel that was created: return panel # Create a notebook which will contain a page for each group in the # content: nb = create_notebook_for_items(content, ui, parent, None) nb.ui = ui # Notice when the notebook page changes (to display correct help) ###wx.EVT_NOTEBOOK_PAGE_CHANGED( parent, nb.GetId(), _page_changed ) # 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