Commit a8c8e14d authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

MainWindow: Add windows menu with list of windows (depth 1).

Showing with 57 additions and 9 deletions
+57 -9
...@@ -341,6 +341,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -341,6 +341,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
def _do_propagate_update(self): def _do_propagate_update(self):
for key in self._propagation_keys: for key in self._propagation_keys:
if key == "window_list":
self._do_update_window_list()
continue
logger.debug(f"Propagation of {key}") logger.debug(f"Propagation of {key}")
for _, window in self.sub_win_list: for _, window in self.sub_win_list:
window._propagated_update(key=key) window._propagated_update(key=key)
...@@ -568,6 +572,36 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): ...@@ -568,6 +572,36 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
# SUBWINDOW # # SUBWINDOW #
############# #############
def _activate_window(self, window_hash):
window = self.get_sub_win(window_hash)
if window is not None:
window.activateWindow()
def _update_window_list(self):
self._propagation_keys.add("window_list")
def _do_update_window_list(self):
menu = self.findChild(QMenu, "menu_windows")
# Remove all actions
menu.clear()
def lambda_generator(h):
return lambda: self._activate_window(h)
# Add window action
for _, win in self.sub_win_list:
action = QAction(win._title, self)
# action.setStatusTip(
# _translate("MainWindow", "Activate this window")
# )
h = win.hash()
logger.info(f"Get hash: {h}")
fn = lambda_generator(h)
action.triggered.connect(fn)
menu.addAction(action)
def open_configure(self): def open_configure(self):
"""Open configure window """Open configure window
......
...@@ -39,6 +39,9 @@ class ListedSubWindow(object): ...@@ -39,6 +39,9 @@ class ListedSubWindow(object):
def sub_win_add(self, name, win): def sub_win_add(self, name, win):
self._sub_win_list.append((name, win)) self._sub_win_list.append((name, win))
self._sub_win_cnt += 1 self._sub_win_cnt += 1
self._update_window_list()
try: try:
logger.info( logger.info(
f"Open window: {name}: {self._sub_win_cnt}") f"Open window: {name}: {self._sub_win_cnt}")
...@@ -54,6 +57,8 @@ class ListedSubWindow(object): ...@@ -54,6 +57,8 @@ class ListedSubWindow(object):
) )
) )
self._sub_win_cnt = len(self._sub_win_list) self._sub_win_cnt = len(self._sub_win_list)
self._update_window_list()
logger.info(f"Close window: ({h}) {self._sub_win_cnt}") logger.info(f"Close window: ({h}) {self._sub_win_cnt}")
def _sub_win_exists(self, h): def _sub_win_exists(self, h):
...@@ -78,8 +83,7 @@ class ListedSubWindow(object): ...@@ -78,8 +83,7 @@ class ListedSubWindow(object):
except Exception: except Exception:
return None return None
def sub_window_exists(self, cls, def sub_window_exists(self, cls, data=None):
data=None):
"""Check if window already exists """Check if window already exists
Check if window already exists, used to deni window open Check if window already exists, used to deni window open
...@@ -97,7 +101,11 @@ class ListedSubWindow(object): ...@@ -97,7 +101,11 @@ class ListedSubWindow(object):
hash = cls._hash(data) hash = cls._hash(data)
if self._sub_win_exists(hash): if self._sub_win_exists(hash):
win = self.get_sub_win(hash) win = self.get_sub_win(hash)
logger.debug(f"subwindow: {hash} -> {win} ({win.hash()})")
win.activateWindow() win.activateWindow()
return True return True
else: else:
return False return False
def _update_window_list(self):
return
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>850</width> <width>1280</width>
<height>646</height> <height>720</height>
</rect> </rect>
</property> </property>
<property name="font"> <property name="font">
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>850</width> <width>1280</width>
<height>23</height> <height>23</height>
</rect> </rect>
</property> </property>
...@@ -179,6 +179,14 @@ ...@@ -179,6 +179,14 @@
<addaction name="action_menu_sediment_layers"/> <addaction name="action_menu_sediment_layers"/>
<addaction name="action_menu_edit_reach_sediment_layers"/> <addaction name="action_menu_edit_reach_sediment_layers"/>
</widget> </widget>
<widget class="QMenu" name="menu_windows">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>&amp;Windows</string>
</property>
</widget>
<addaction name="menu_File"/> <addaction name="menu_File"/>
<addaction name="menu_network"/> <addaction name="menu_network"/>
<addaction name="menu_geometry"/> <addaction name="menu_geometry"/>
...@@ -187,6 +195,7 @@ ...@@ -187,6 +195,7 @@
<addaction name="menu_run"/> <addaction name="menu_run"/>
<addaction name="menu_results"/> <addaction name="menu_results"/>
<addaction name="menu_cartography"/> <addaction name="menu_cartography"/>
<addaction name="menu_windows"/>
<addaction name="menu_help"/> <addaction name="menu_help"/>
</widget> </widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
...@@ -263,10 +272,7 @@ ...@@ -263,10 +272,7 @@
<string>New study</string> <string>New study</string>
</property> </property>
<property name="font"> <property name="font">
<font> <font/>
<weight>50</weight>
<bold>false</bold>
</font>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>Ctrl+N</string> <string>Ctrl+N</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment