2323 get_prefs_dir ,
2424 get_relative_path ,
2525)
26+ from .group_tab_widget .one_tab_widget import OneTabWidget
2627
2728logger = logging .getLogger (__name__ )
2829
@@ -141,7 +142,10 @@ def __set_last_saved_text__(self, text):
141142 text (str): The text to define as last_saved_text
142143 """
143144 self ._last_saved_text = text
144- self .__tab_widget__ ().tabBar ().update ()
145+
146+ tab_widget = self .__tab_widget__ ()
147+ if tab_widget is not None :
148+ tab_widget .tabBar ().update ()
145149
146150 def __last_saved_text__ (self ):
147151 """Returns the last_saved_text on this workbox
@@ -176,7 +180,14 @@ def __tab_widget__(self):
176180 Returns:
177181 GroupedTabWidget: The tab widget which contains this workbox
178182 """
179- return self ._tab_widget
183+ tab_widget = None
184+ parent = self .parent ()
185+ while parent is not None :
186+ if issubclass (parent .__class__ , OneTabWidget ):
187+ tab_widget = parent
188+ break
189+ parent = parent .parent ()
190+ return tab_widget
180191
181192 def __set_tab_widget__ (self , tab_widget ):
182193 """Set this workbox's _tab_widget to the provided tab_widget"""
@@ -363,8 +374,11 @@ def __workbox_name__(self, workbox=None):
363374 group_name = None
364375 workbox_name = None
365376
377+ grouped_tab_widget = workbox .__tab_widget__ ()
378+ if grouped_tab_widget is None :
379+ return WorkboxName ("" , "" )
380+
366381 if workbox :
367- grouped_tab_widget = workbox .__tab_widget__ ()
368382 for group_idx in range (workboxTAB .count ()):
369383 # If a previous iteration determine workbox_name, bust out
370384 if workbox_name :
@@ -381,20 +395,19 @@ def __workbox_name__(self, workbox=None):
381395 workbox_name = cur_group_widget .tabText (workbox_idx )
382396 break
383397 else :
384- grouped = workbox .__tab_widget__ ()
385- groupedTabBar = grouped .tabBar ()
398+ groupedTabBar = grouped_tab_widget .tabBar ()
386399
387400 idx = - 1
388- for idx in range (grouped .count ()):
389- if grouped .widget (idx ) == workbox :
401+ for idx in range (grouped_tab_widget .count ()):
402+ if grouped_tab_widget .widget (idx ) == workbox :
390403 break
391404 workbox_name = groupedTabBar .tabText (idx )
392405
393- group = grouped .tab_widget ()
394- groupTabBar = group .tabBar ()
406+ group_tab_widget = grouped_tab_widget .tab_widget ()
407+ groupTabBar = group_tab_widget .tabBar ()
395408 idx = - 1
396- for idx in range (group .count ()):
397- if group .widget (idx ) == grouped :
409+ for idx in range (group_tab_widget .count ()):
410+ if group_tab_widget .widget (idx ) == grouped_tab_widget :
398411 break
399412 group_name = groupTabBar .tabText (idx )
400413
@@ -564,7 +577,10 @@ def __set_workbox_title__(self, title):
564577 title (str): The text to put on the grouped tab's tabText.
565578 """
566579 _group_idx , editor_idx = self .__group_tab_index__ ()
567- self .__tab_widget__ ().tabBar ().setTabText (editor_idx , title )
580+
581+ tab_widget = self .__tab_widget__ ()
582+ if tab_widget is not None :
583+ tab_widget .tabBar ().setTabText (editor_idx , title )
568584
569585 def __linked_file_changed__ (self ):
570586 """If a file was modified or deleted this method
@@ -588,12 +604,19 @@ def __linked_file_changed__(self):
588604 'The file was deleted, removing document from editor' ,
589605 )
590606 group_idx , editor_idx = self .__group_tab_index__ ()
591- self .__tab_widget__ ().close_tab (editor_idx )
607+
608+ tab_widget = self .__tab_widget__ ()
609+ if tab_widget is not None :
610+ tab_widget .close_tab (editor_idx )
611+
592612 return False
593613 elif choice :
594614 self .__set_filename__ ("" )
595- title = self .__tab_widget__ ().get_next_available_tab_name ()
596- self .__set_workbox_title__ (title )
615+
616+ tab_widget = self .__tab_widget__ ()
617+ if tab_widget is not None :
618+ title = tab_widget .get_next_available_tab_name ()
619+ self .__set_workbox_title__ (title )
597620
598621 # TODO: The file no longer exists, and the document should be marked as
599622 # changed.
@@ -985,7 +1008,10 @@ def __load_workbox_version_text__(self, versionType):
9851008 self ._backup_file = str (filepath )
9861009
9871010 self .__set_text__ (txt )
988- self .__tab_widget__ ().tabBar ().update ()
1011+
1012+ tab_widget = self .__tab_widget__ ()
1013+ if tab_widget is not None :
1014+ tab_widget .tabBar ().update ()
9891015
9901016 filename = Path (filepath ).name
9911017 return filename , idx , count
0 commit comments