Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/main/python/gui/modulespecification_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,27 +609,54 @@ def __init__(self):
super().__init__()
self.tab_bar = self.tabBar()
self.tab_bar.setStyle(BoldTabBarStyle())
self.currentChanged.connect(self.decide_bold_label)
self.currentChanged.connect(self.on_tab_change)

def __repr__(self):
current_index = self.currentIndex()
current_tab = self.tabText(current_index) if current_index >= 0 else "None"
count = self.count()
return (f"<{self.__class__.__name__} "
f"selected: '{current_tab}' (tab # {current_index} out of {count})")

def check_components(self, widget):
all_cb = widget.findChildren(QCheckBox)
all_rb = widget.findChildren(QRadioButton)
all_ai = widget.findChildren(AddedInfoPushButton)
return any(btn.isChecked() for btn in all_rb+all_cb) or any(btn.addedinfo.hascontent() for btn in all_ai)

def decide_bold_label(self, index):
def decide_bold_label(self):
# called when tab selection updates.
# it decides which tabs need the label bolded
idx = 0
while self.widget(idx) is not None:
need_bold = self.check_components(self.widget(idx))
self.tab_bar.style().setBoldTabIndex(idx, need_bold)
idx += 1
self.setCurrentIndex(index)

def get_bold_indices(self):
return self.tab_bar.style().bold_tab_index

def get_nested_tabs(self, idx):
# returns None or QTabWidget
widget = self.widget(idx)
if widget is None:
return False
nested_tabs = widget.findChildren(QTabWidget)
if len(nested_tabs) > 1:
raise NotImplementedError("Hi future developers, nesting many QTabWidgets is not expected as of July 2025!")
return nested_tabs[0] if nested_tabs else None

# wrapper for decide_bold_label(). it applies bolding to matrix and nested tabs
def on_tab_change(self, index):
self.decide_bold_label() # decide bold for the current tab

# and then check if nested tab needs to be bolded
nested_tab = self.get_nested_tabs(index)
if nested_tab:
nested_tab.decide_bold_label()

self.setCurrentIndex(index) # finally move the selection


class BoldTabBarStyle(QProxyStyle):
def __init__(self, bold_tab_index=None):
Expand Down