Skip to content

Commit 5eaba56

Browse files
macevhiczMHendricks
authored andcommitted
Add __workbox_name__ method
1 parent 4566632 commit 5eaba56

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

preditor/gui/group_tab_widget/grouped_tab_widget.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,14 @@ def tab_shown(self, index):
8282
if hasattr(self.window(), "setWorkboxFontBasedOnConsole"):
8383
self.window().setWorkboxFontBasedOnConsole()
8484

85+
def tab_widget(self):
86+
"""Return the tab widget which contains this group tab
87+
88+
Returns:
89+
self._tab_widget (GroupTabWidget): The tab widget which contains
90+
this workbox
91+
"""
92+
return self.parent().parent()
93+
8594
def update_closable_tabs(self):
8695
self.setTabsClosable(self.count() != 1)

preditor/gui/workbox_mixin.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def __init__(
6464
self._tempfile = tempfile
6565
self.core_name = core_name
6666

67+
self._tab_widget = parent
68+
69+
def __tab_widget__(self):
70+
"""Return the tab widget which contains this workbox
71+
72+
Returns:
73+
GroupedTabWidget: The tab widget which contains this workbox
74+
"""
75+
return self._tab_widget
76+
6777
def __auto_complete_enabled__(self):
6878
raise NotImplementedError("Mixin method not overridden.")
6979

@@ -189,7 +199,57 @@ def __workbox_trace_title__(self, selection=False):
189199
if group == -1 or editor == -1:
190200
return '<{}>'.format(title)
191201
else:
192-
return '<{}>:{},{}'.format(title, group, editor)
202+
name = self.__workbox_name__()
203+
return '<{}>:{}'.format(title, name)
204+
205+
def __workbox_name__(self, workbox=None):
206+
"""Returns the name for this workbox or a given workbox.
207+
The name is the group tab text and the workbox tab text joined by a `/`"""
208+
workboxTAB = self.window().uiWorkboxTAB
209+
group_name = None
210+
workbox_name = None
211+
212+
if workbox:
213+
grouped_tab_widget = workbox.__tab_widget__()
214+
for group_idx in range(workboxTAB.count()):
215+
# If a previous iteration determine workbox_name, bust out
216+
if workbox_name:
217+
break
218+
# Check if current group is the workboxes parent group
219+
cur_group_widget = workboxTAB.widget(group_idx)
220+
if cur_group_widget == grouped_tab_widget:
221+
group_name = workboxTAB.tabText(group_idx)
222+
223+
# Found the group, now find workbox
224+
for workbox_idx in range(cur_group_widget.count()):
225+
cur_workbox_widget = cur_group_widget.widget(workbox_idx)
226+
if cur_workbox_widget == workbox:
227+
workbox_name = cur_group_widget.tabText(workbox_idx)
228+
break
229+
else:
230+
grouped = self.__tab_widget__()
231+
groupedTabBar = grouped.tabBar()
232+
233+
idx = -1
234+
for idx in range(grouped.count()):
235+
if grouped.widget(idx) == self:
236+
break
237+
workbox_name = groupedTabBar.tabText(idx)
238+
239+
group = grouped.tab_widget()
240+
groupTabBar = group.tabBar()
241+
idx = -1
242+
for idx in range(group.count()):
243+
if group.widget(idx) == grouped:
244+
break
245+
group_name = groupTabBar.tabText(idx)
246+
247+
# If both found, construct workbox name
248+
if group_name and workbox_name:
249+
name = WorkboxName(group_name, workbox_name)
250+
else:
251+
name = WorkboxName("", "")
252+
return name
193253

194254
def __goto_line__(self, line):
195255
raise NotImplementedError("Mixin method not overridden.")

0 commit comments

Comments
 (0)