diff --git a/preditor/gui/group_tab_widget/__init__.py b/preditor/gui/group_tab_widget/__init__.py index 0d9814fb..6f2b3659 100644 --- a/preditor/gui/group_tab_widget/__init__.py +++ b/preditor/gui/group_tab_widget/__init__.py @@ -114,11 +114,20 @@ def add_new_tab(self, group, title="Workbox"): return parent, editor def all_widgets(self): - """Returns every widget under every group.""" - for i in range(self.count()): - tab_widget = self.widget(i) - for j in range(tab_widget.count()): - yield tab_widget.widget(j) + """A generator yielding information about every widget under every group. + + Yields: + widget, group tab name, widget tab name, group tab index, widget tab index + """ + for group_index in range(self.count()): + group_name = self.tabText(group_index) + + tab_widget = self.widget(group_index) + for tab_index in range(tab_widget.count()): + tab_name = tab_widget.tabText(tab_index) + yield tab_widget.widget( + tab_index + ), group_name, tab_name, group_index, tab_index def close_current_tab(self): """Convenient method to close the currently open editor tab prompting diff --git a/preditor/gui/loggerwindow.py b/preditor/gui/loggerwindow.py index ae26b43d..1b63ef30 100644 --- a/preditor/gui/loggerwindow.py +++ b/preditor/gui/loggerwindow.py @@ -311,7 +311,20 @@ def current_workbox(self): return self.uiWorkboxTAB.current_groups_widget() @classmethod - def workbox_for_name(cls, name, show=False): + def name_for_workbox(cls, workbox): + """Returns the name for a given workbox. + The name is the group tab text and the workbox tab text joined by a `/`""" + ret = [] + logger = cls.instance() + index = logger.uiWorkboxTAB.currentIndex() + ret.append(logger.uiWorkboxTAB.tabText(index)) + group_widget = logger.uiWorkboxTAB.currentWidget() + index = group_widget.currentIndex() + ret.append(group_widget.tabText(index)) + return "/".join(ret) + + @classmethod + def workbox_for_name(cls, name, show=False, visible=False): """Used to find a workbox for a given name. It accepts a string matching the "{group}/{workbox}" format, or if True, the current workbox. @@ -319,6 +332,7 @@ def workbox_for_name(cls, name, show=False): name(str, boolean): Used to define which workbox to run. show (bool, optional): If a workbox is found, call `__show__` on it to ensure that it is initialized and its text is loaded. + visible (bool, optional): Make the this workbox visible if found. """ logger = cls.instance() @@ -331,13 +345,19 @@ def workbox_for_name(cls, name, show=False): # If name is a string, find first tab with that name elif isinstance(name, six.string_types): - group, editor = name.split('/', 1) - index = logger.uiWorkboxTAB.index_for_text(group) - if index != -1: - tab_widget = logger.uiWorkboxTAB.widget(index) + split = name.split('/', 1) + if len(split) < 2: + return None + group, editor = split + group_index = logger.uiWorkboxTAB.index_for_text(group) + if group_index != -1: + tab_widget = logger.uiWorkboxTAB.widget(group_index) index = tab_widget.index_for_text(editor) if index != -1: workbox = tab_widget.widget(index) + if visible: + tab_widget.setCurrentIndex(index) + logger.uiWorkboxTAB.setCurrentIndex(group_index) if show and workbox: workbox.__show__() @@ -589,7 +609,7 @@ def closeEvent(self, event): self.uiConsoleTOOLBAR.hide() # Handle any cleanup each workbox tab may need to do before closing - for editor in self.uiWorkboxTAB.all_widgets(): + for editor, _, _, _, _ in self.uiWorkboxTAB.all_widgets(): editor.__close__() def closeLogger(self): @@ -797,7 +817,7 @@ def restoreToolbars(self, pref=None): def setAutoCompleteEnabled(self, state): self.uiConsoleTXT.completer().setEnabled(state) - for workbox in self.uiWorkboxTAB.all_widgets(): + for workbox, _, _, _, _ in self.uiWorkboxTAB.all_widgets(): workbox.__set_auto_complete_enabled__(state) def setSpellCheckEnabled(self, state): @@ -994,13 +1014,13 @@ def show_workbox_options(self): self.uiWorkboxSTACK.setCurrentIndex(WorkboxPages.Options) def updateCopyIndentsAsSpaces(self): - for workbox in self.uiWorkboxTAB.all_widgets(): + for workbox, _, _, _, _ in self.uiWorkboxTAB.all_widgets(): workbox.__set_copy_indents_as_spaces__( self.uiCopyTabsToSpacesACT.isChecked() ) def updateIndentationsUseTabs(self): - for workbox in self.uiWorkboxTAB.all_widgets(): + for workbox, _, _, _, _ in self.uiWorkboxTAB.all_widgets(): workbox.__set_indentations_use_tabs__( self.uiIndentationsTabsACT.isChecked() )