|
2 | 2 |
|
3 | 3 | import copy |
4 | 4 |
|
5 | | -from PySide6.QtCore import QSettings, Qt |
| 5 | +from PySide6.QtCore import QEvent, QSettings, Qt, QTimer |
6 | 6 | from PySide6.QtWidgets import ( |
7 | 7 | QDockWidget, |
8 | 8 | QMainWindow, |
|
35 | 35 |
|
36 | 36 |
|
37 | 37 | class MainWindow(QMainWindow): |
| 38 | + DATA_TAB_INDEX = 0 # Index of the Data Tables tab |
| 39 | + |
38 | 40 | def __init__(self): |
39 | 41 | super().__init__() |
40 | 42 |
|
@@ -131,13 +133,16 @@ def __init__(self): |
131 | 133 |
|
132 | 134 | self.find_replace_bar = None |
133 | 135 |
|
| 136 | + # Track if we're in a minimize/restore cycle |
| 137 | + self._was_minimized = False |
| 138 | + |
134 | 139 | def default_view(self): |
135 | 140 | """Reset the view to a fixed 3x2 grid using manual geometry.""" |
136 | 141 | if hasattr(self, "dock_visibility"): |
137 | 142 | for dock in self.dock_visibility: |
138 | 143 | dock.setParent(None) # fully remove from layout |
139 | 144 |
|
140 | | - self.tab_widget.setCurrentIndex(0) |
| 145 | + self.tab_widget.setCurrentIndex(self.DATA_TAB_INDEX) |
141 | 146 | self.data_tab.updateGeometry() |
142 | 147 | self.data_tab.repaint() |
143 | 148 |
|
@@ -228,17 +233,41 @@ def add_menu_action(self, dock_widget, name): |
228 | 233 |
|
229 | 234 | def save_dock_visibility(self, visible): |
230 | 235 | """Save the visibility status of a QDockWidget when it changes.""" |
| 236 | + # Don't save visibility when window is minimized - Qt hides docks automatically |
| 237 | + if self.isMinimized(): |
| 238 | + return |
231 | 239 | # if current tab is not the data tab return |
232 | | - if self.tab_widget.currentIndex() != 0: |
| 240 | + if self.tab_widget.currentIndex() != self.DATA_TAB_INDEX: |
233 | 241 | return |
234 | 242 | dock = self.sender() # Get the QDockWidget that emitted the signal |
235 | 243 | self.dock_visibility[dock] = dock.isVisible() |
236 | 244 |
|
237 | 245 | def set_docks_visible(self, index): |
238 | 246 | """Set all QDockWidgets to their previous visibility on tab-change.""" |
239 | | - if index != 0: # Another tab is selected |
240 | | - for dock, visible in self.dock_visibility.items(): |
241 | | - dock.setVisible(visible) |
| 247 | + if index != self.DATA_TAB_INDEX: # Another tab is selected |
| 248 | + self._apply_dock_visibility() |
| 249 | + |
| 250 | + def _apply_dock_visibility(self): |
| 251 | + """Apply saved visibility state to all docks.""" |
| 252 | + for dock, visible in self.dock_visibility.items(): |
| 253 | + dock.setVisible(visible) |
| 254 | + |
| 255 | + def changeEvent(self, event): |
| 256 | + """Handle window state changes, including minimize/restore.""" |
| 257 | + super().changeEvent(event) |
| 258 | + |
| 259 | + if event.type() != QEvent.Type.WindowStateChange: |
| 260 | + return |
| 261 | + |
| 262 | + if self.isMinimized(): |
| 263 | + self._was_minimized = True |
| 264 | + elif ( |
| 265 | + self._was_minimized |
| 266 | + and self.tab_widget.currentIndex() == self.DATA_TAB_INDEX |
| 267 | + ): |
| 268 | + # Short delay to not create a segmentation fault. |
| 269 | + QTimer.singleShot(50, self._apply_dock_visibility) |
| 270 | + self._was_minimized = False |
242 | 271 |
|
243 | 272 | def closeEvent(self, event): |
244 | 273 | """Override the closeEvent to emit additional signal.""" |
|
0 commit comments