mirror of https://gitlab.com/pamhyr/pamhyr2
MainWindow: Add windows menu with list of windows (depth 1).
parent
e96e291ec4
commit
a8c8e14d6a
|
|
@ -341,6 +341,10 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
|
||||
def _do_propagate_update(self):
|
||||
for key in self._propagation_keys:
|
||||
if key == "window_list":
|
||||
self._do_update_window_list()
|
||||
continue
|
||||
|
||||
logger.debug(f"Propagation of {key}")
|
||||
for _, window in self.sub_win_list:
|
||||
window._propagated_update(key=key)
|
||||
|
|
@ -568,6 +572,36 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
|||
# 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):
|
||||
"""Open configure window
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ class ListedSubWindow(object):
|
|||
def sub_win_add(self, name, win):
|
||||
self._sub_win_list.append((name, win))
|
||||
self._sub_win_cnt += 1
|
||||
|
||||
self._update_window_list()
|
||||
|
||||
try:
|
||||
logger.info(
|
||||
f"Open window: {name}: {self._sub_win_cnt}")
|
||||
|
|
@ -54,6 +57,8 @@ class ListedSubWindow(object):
|
|||
)
|
||||
)
|
||||
self._sub_win_cnt = len(self._sub_win_list)
|
||||
self._update_window_list()
|
||||
|
||||
logger.info(f"Close window: ({h}) {self._sub_win_cnt}")
|
||||
|
||||
def _sub_win_exists(self, h):
|
||||
|
|
@ -78,8 +83,7 @@ class ListedSubWindow(object):
|
|||
except Exception:
|
||||
return None
|
||||
|
||||
def sub_window_exists(self, cls,
|
||||
data=None):
|
||||
def sub_window_exists(self, cls, data=None):
|
||||
"""Check if window already exists
|
||||
|
||||
Check if window already exists, used to deni window open
|
||||
|
|
@ -97,7 +101,11 @@ class ListedSubWindow(object):
|
|||
hash = cls._hash(data)
|
||||
if self._sub_win_exists(hash):
|
||||
win = self.get_sub_win(hash)
|
||||
logger.debug(f"subwindow: {hash} -> {win} ({win.hash()})")
|
||||
win.activateWindow()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def _update_window_list(self):
|
||||
return
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>850</width>
|
||||
<height>646</height>
|
||||
<width>1280</width>
|
||||
<height>720</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
|
|
@ -65,7 +65,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>850</width>
|
||||
<width>1280</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
|
@ -179,6 +179,14 @@
|
|||
<addaction name="action_menu_sediment_layers"/>
|
||||
<addaction name="action_menu_edit_reach_sediment_layers"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_windows">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>&Windows</string>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="menu_File"/>
|
||||
<addaction name="menu_network"/>
|
||||
<addaction name="menu_geometry"/>
|
||||
|
|
@ -187,6 +195,7 @@
|
|||
<addaction name="menu_run"/>
|
||||
<addaction name="menu_results"/>
|
||||
<addaction name="menu_cartography"/>
|
||||
<addaction name="menu_windows"/>
|
||||
<addaction name="menu_help"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
|
|
@ -263,10 +272,7 @@
|
|||
<string>New study</string>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
<font/>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+N</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue