moved "Single plot mode" from "Settings" menu to "Windows" menu as "Single window"; moved add/show logic from MainWindow to MDIArea; view-mode actions are grouped to be exclusive

This commit is contained in:
2023-01-05 16:32:39 +01:00
parent 08d77289d9
commit 72a2ff4fa6
2 changed files with 35 additions and 14 deletions

View File

@ -28,7 +28,6 @@ class MainWindow(QMainWindow):
self.menu_settings = menu = BarMenu(bar, "&Settings")
menu.addCheckbox("Open new plots", state=True)
menu.addCheckbox("Single plot mode", state=False)
self.mdi = mdi = MDIArea(bar)
@ -79,18 +78,8 @@ class MainWindow(QMainWindow):
def on_make_new_plot(self, *args, **kwargs):
single = self.menu_settings.checkboxes["Single plot mode"].isChecked()
if single:
self.mdi.closeAllSubWindows()
sub = MDISubPlot(*args, **kwargs)
self.mdi.addSubWindow(sub)
if single:
sub.showMaximized()
else:
sub.show()
self.mdi.add(sub)

View File

@ -1,4 +1,4 @@
from PyQt5.QtWidgets import QMdiArea, QAction
from PyQt5.QtWidgets import QMdiArea, QAction, QActionGroup
from PyQt5.QtGui import QPainter
from .. import assets
@ -20,11 +20,19 @@ class MDIArea(QMdiArea):
self.menu = menu = BarMenu(bar, "&Windows")
menu.addAction("Cascade", self.on_cascade)
menu.addAction("Tile", self.on_tile)
menu.addAction("Tabbed", self.enable_tabbed_view)
menu.addSeparator()
v1 = menu.addCheckbox("Single window", triggered=self.enable_single_window_mode)
v2 = menu.addCheckbox("Tabbed", triggered=self.enable_tabbed_view)
menu.addSeparator()
menu.addAction("Close all", self.closeAllSubWindows)
menu.addAction("Close all but active", self.closeAllButActiveSubWindows)
#TODO: move to MenuBase
ag = QActionGroup(menu.qmenu)
ag.addAction(v1)
ag.addAction(v2)
def on_cascade(self):
self.enable_subwindow_view()
self.cascadeSubWindows()
@ -33,6 +41,13 @@ class MDIArea(QMdiArea):
self.enable_subwindow_view()
self.tileSubWindows()
def enable_single_window_mode(self):
self.enable_subwindow_view()
self.closeAllButActiveSubWindows()
active = self.activeSubWindow()
if active:
active.showMaximized()
def enable_subwindow_view(self):
self.setViewMode(QMdiArea.SubWindowView)
@ -40,6 +55,23 @@ class MDIArea(QMdiArea):
self.setViewMode(QMdiArea.TabbedView)
def add(self, sub):
single = self.menu.checkboxes["Single window"].isChecked()
if single:
self.add_single(sub)
else:
self.add_multiple(sub)
def add_multiple(self, sub):
self.addSubWindow(sub)
sub.show()
def add_single(self, sub):
self.closeAllSubWindows()
self.addSubWindow(sub)
sub.showMaximized()
def paintEvent(self, _event):
self._draw_watermark()