def insert_tab(self, index, label, add_panel=True, add_sizer=False): # add tab/page; called from GUI self.properties["tabs"].insert(index, [ label, ]) # create panel and node, add to tree self.insert_item(None, index) # placeholder if add_panel: if not isinstance(add_panel, compat.unicode): add_panel = self.next_pane_name() editor = panel.EditPanel(add_panel, self, index) if add_sizer: sizer = edit_sizers._builder(editor, 0) else: # just add a slot editor = edit_base.Slot(self, index) if self.widget: # add to widget editor.create() compat.SetToolTip(editor.widget, _("Notebook page pane:\nAdd a sizer here")) self.vs_insert_tab(index) try: wx.CallAfter(editor.sel_marker.update) except AttributeError: #self._logger.exception(_('Internal Error')) if config.debugging: raise self.widget.SetSelection(index) self.properties["tabs"].update_display() misc.rebuild_tree(self)
def set_tabs(self, old_labels, indices, user=True): # called from tabs property on Apply button """tabs: list of strings indices: the current indices of the tabs or None for a new tab; re-ordering is currently not supported""" import clipboard removed_tabs = [] # (index,xml_data) added_tabs = [] keep_indices = [index for index in indices if index is not None] if keep_indices != sorted(keep_indices): raise ValueError("Re-ordering is not yet implemented") keep_indices = set(keep_indices) # set tab labels of existing pages, if modified for (label,), index in zip(self.tabs, indices): if index is not None and old_labels[index]!=label and self.widget: self.widget.SetPageText(index, label) # remove tabs for index in range(len(old_labels)-1, -1, -1): if not index in keep_indices: removed_tabs.append( (index, clipboard.dump_widget(self.children[index])) ) self.children[index].recursive_remove(level=0) # insert/add tabs set_selected_page = None for index, (label,) in enumerate(self.tabs): if indices[index] is not None: continue # keep tab # actually add/insert self.children.insert(index, None) # create panel and node, add to tree suggestion = "%s_%s" % (self.name, label) editor = panel.EditPanel( self.next_pane_name(suggestion), self, index ) if self.widget: # add to widget editor.create() self.vs_insert_tab(index) try: wx.CallAfter(editor.sel_marker.update) except AttributeError: if config.debugging: raise set_selected_page = index # remember last added index for selection added_tabs.append( (index, clipboard.dump_widget(editor)) ) # select the last added tab if set_selected_page is not None: self.widget.SetSelection(set_selected_page) if user: # history: undo/redo item = common.history._finalize_item(stop=True) # property_changing was called for "tabs" common.history.add_item( HistoryNotebookTabsItem(self, item, removed_tabs, added_tabs) ) common.app_tree.build(self, recursive=False)
def set_tabs(self, old_labels, indices): # called from tabs property on Apply button """tabs: list of strings indices: the current indices of the tabs or None for a new tab; re-ordering is currently not supported""" keep_indices = [index for index in indices if index is not None] if keep_indices != sorted(keep_indices): raise ValueError("Re-ordering is not yet implemented") keep_indices = set(keep_indices) # set tab labels of existing pages, if modified for (label, ), index in zip(self.tabs, indices): if index is not None and old_labels[index] != label and self.widget: self.widget.SetPageText(index, label) # remove tabs for index in range(len(old_labels) - 1, -1, -1): if not index in keep_indices: self.children[index].recursive_remove(level=0) # insert/add tabs added = None for index, (label, ) in enumerate(self.tabs): if indices[index] is not None: continue # keep tab # actually add/insert self.children.insert(index, None) # create panel and node, add to tree suggestion = "%s_%s" % (self.name, label) editor = panel.EditPanel(self.next_pane_name(suggestion), self, index) if self.widget: # add to widget editor.create() self.vs_insert_tab(index) try: wx.CallAfter(editor.sel_marker.update) except AttributeError: if config.debugging: raise added = index # remember last added index for selection # select the last added tab if added is not None and self.widget: self.widget.SetSelection(added) common.app_tree.build(self, recursive=False)