From 59625c15819077fba194a8684548aaf57e2b8e27 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Sun, 16 Apr 2023 15:40:58 +0000 Subject: [PATCH] more_bugs (#51) closes #46, #47, #7 Co-authored-by: Dominik Demuth Reviewed-on: https://gitea.pkm.physik.tu-darmstadt.de/IPKM/nmreval/pulls/51 --- src/gui_qt/_py/basewindow.py | 13 +++- src/gui_qt/lib/mdiarea.py | 50 +++++++++++++++ src/gui_qt/lib/stuff.py | 2 +- src/gui_qt/main/mainwindow.py | 106 +++++++++++++++++--------------- src/gui_qt/main/management.py | 6 +- src/resources/_ui/basewindow.ui | 22 ++++++- 6 files changed, 142 insertions(+), 57 deletions(-) create mode 100644 src/gui_qt/lib/mdiarea.py diff --git a/src/gui_qt/_py/basewindow.py b/src/gui_qt/_py/basewindow.py index 67fcb95..c0a8cd8 100644 --- a/src/gui_qt/_py/basewindow.py +++ b/src/gui_qt/_py/basewindow.py @@ -70,12 +70,12 @@ class Ui_BaseWindow(object): self.integralwidget = IntegralWidget() self.integralwidget.setObjectName("integralwidget") self.tabWidget.addTab(self.integralwidget, "") - self.area = QtWidgets.QMdiArea(self.splitter) + self.area = MdiAreaTile(self.splitter) self.area.setObjectName("area") self.horizontalLayout.addWidget(self.splitter) BaseWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(BaseWindow) - self.menubar.setGeometry(QtCore.QRect(0, 0, 1386, 20)) + self.menubar.setGeometry(QtCore.QRect(0, 0, 1386, 22)) self.menubar.setObjectName("menubar") self.menuFile = QtWidgets.QMenu(self.menubar) self.menuFile.setObjectName("menuFile") @@ -261,6 +261,10 @@ class Ui_BaseWindow(object): self.actionMaximize.setObjectName("actionMaximize") self.actionTile = QtWidgets.QAction(BaseWindow) self.actionTile.setObjectName("actionTile") + self.actionTileVertical = QtWidgets.QAction(BaseWindow) + self.actionTileVertical.setObjectName("actionTileVertical") + self.actionTileHorizontal = QtWidgets.QAction(BaseWindow) + self.actionTileHorizontal.setObjectName("actionTileHorizontal") self.actionMinimize = QtWidgets.QAction(BaseWindow) self.actionMinimize.setCheckable(True) self.actionMinimize.setVisible(False) @@ -428,6 +432,8 @@ class Ui_BaseWindow(object): self.menuOptions.addAction(self.actionConfiguration) self.menuOptions.addAction(self.actionCreate_starter) self.menuView.addAction(self.actionTile) + self.menuView.addAction(self.actionTileVertical) + self.menuView.addAction(self.actionTileHorizontal) self.menuView.addAction(self.actionCascade_windows) self.menuWindow.addAction(self.actionNew_window) self.menuWindow.addAction(self.actionDelete_window) @@ -571,6 +577,8 @@ class Ui_BaseWindow(object): self.actionGuide_lines.setText(_translate("BaseWindow", "Draw lines...")) self.actionMaximize.setText(_translate("BaseWindow", "Maximize")) self.actionTile.setText(_translate("BaseWindow", "Tile windows")) + self.actionTileVertical.setText(_translate("BaseWindow", "Tile windows vertically")) + self.actionTileHorizontal.setText(_translate("BaseWindow", "Tile windows horizontally")) self.actionMinimize.setText(_translate("BaseWindow", "Minimize")) self.actionNew_window.setText(_translate("BaseWindow", "New graph")) self.actionDelete_window.setText(_translate("BaseWindow", "Delete graph")) @@ -626,4 +634,5 @@ from ..data.signaledit.editsignalwidget import EditSignalWidget from ..data.valueeditwidget import ValueEditWidget from ..fit.fitwindow import QFitDialog from ..graphs.drawings import DrawingsWidget +from ..lib.mdiarea import MdiAreaTile from ..nmr.t1widget import QT1Widget diff --git a/src/gui_qt/lib/mdiarea.py b/src/gui_qt/lib/mdiarea.py new file mode 100644 index 0000000..37f6c27 --- /dev/null +++ b/src/gui_qt/lib/mdiarea.py @@ -0,0 +1,50 @@ +from __future__ import annotations + +from ..Qt import QtWidgets, QtCore + +from nmreval.lib.logger import logger +from ..graphs.graphwindow import QGraphWindow + + +class MdiAreaTile(QtWidgets.QMdiArea): + def __init__(self, parent=None): + super().__init__(parent=parent) + + def tileSubWindowsVertically(self): + window_list = self.subWindowList() + rect = QtCore.QRect(0, 0, self.width(), int(self.height() / len(window_list))) + pos = QtCore.QPoint(0, 0) + + for win in window_list: + win.setGeometry(rect) + win.move(pos) + + pos.setY(pos.y() + win.height()) + + def tileSubWindowsHorizontally(self): + window_list = self.subWindowList() + rect = QtCore.QRect(0, 0, int(self.width() / len(window_list)), self.height()) + pos = QtCore.QPoint(0, 0) + + for win in window_list: + print(win.minimumSize()) + win.setGeometry(rect) + win.move(pos) + + pos.setX(pos.x() + win.width()) + + def addSubWindow(self, widget: QtWidgets.QWidget, flags: QtCore.Qt.WindowFlags = QtCore.Qt.WindowFlags()) -> QtWidgets.QMdiSubWindow | None: + subwindow = super().addSubWindow(widget) + subwindow.setOption(QtWidgets.QMdiSubWindow.RubberBandMove, True) + subwindow.setOption(QtWidgets.QMdiSubWindow.RubberBandResize, True) + subwindow.setMinimumHeight(240) + subwindow.setMinimumWidth(360) + + return subwindow + + def setActiveSubWidget(self, key: str): + for win in self.subWindowList(): + wdgt = win.widget() + if isinstance(wdgt, QGraphWindow) and wdgt.id == key: + self.setActiveSubWindow(win) + break diff --git a/src/gui_qt/lib/stuff.py b/src/gui_qt/lib/stuff.py index e0454cd..e4b682d 100644 --- a/src/gui_qt/lib/stuff.py +++ b/src/gui_qt/lib/stuff.py @@ -6,7 +6,7 @@ import numpy as np from ..Qt import QtWidgets, QtCore, QtGui -__all__ = ['Game'] +__all__ = ['Game', 'QMines'] class Game(QtWidgets.QDialog): diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index da55131..148b458 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -2,7 +2,6 @@ from __future__ import annotations import datetime import os -import pathlib import re from pathlib import Path @@ -115,7 +114,10 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.mousepos = QtWidgets.QLabel('') self.status = QtWidgets.QLabel('') + + # noinspection PyUnresolvedReferences self.statusBar.addWidget(self.status) + # noinspection PyUnresolvedReferences self.statusBar.addWidget(self.mousepos) self.fitregion = RegionItem() @@ -151,8 +153,6 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.actionUndo.setIcon(icon) self.menuData.insertAction(self.actionRedo, self.actionUndo) - # self.actionSave.triggered.connect(lambda: self.management.save('/autohome/dominik/nmreval/testdata/test.nmr', '')) - # self.actionSave.triggered.connect(self.save) self.action_save_fit_parameter.triggered.connect(self.save_fit_parameter) self.ac_group2.triggered.connect(self.change_fit_limits) @@ -165,6 +165,12 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.action_new_set.triggered.connect(self.management.create_empty) + self.actionDelete_window.triggered.connect(self.management.delete_sets) + self.actionCascade_windows.triggered.connect(self.area.cascadeSubWindows) + self.actionTile.triggered.connect(self.area.tileSubWindows) + self.actionTileHorizontal.triggered.connect(self.area.tileSubWindowsHorizontally) + self.actionTileVertical.triggered.connect(self.area.tileSubWindowsVertically) + self.datawidget.keyChanged.connect(self.management.change_keys) self.datawidget.tree.deleteItem.connect(self.management.delete_sets) self.datawidget.tree.moveItem.connect(self.management.move_sets) @@ -178,7 +184,8 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.datawidget.tree.saveFits.connect(self.save_fit_parameter) self.datawidget.tree.extendFits.connect(self.extend_fit) - self.management.newData.connect(self.show_new_data) + self.management.newData[list, str].connect(self.show_new_data) + self.management.newData[list, str, bool].connect(self.show_new_data) self.management.newGraph.connect(self.new_graph) self.management.dataChanged.connect(self.update_data) self.management.deleteData.connect(self.delete_data) @@ -191,13 +198,14 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.fit_dialog._management = self.management self.fit_dialog.preview_emit.connect(self.show_fit_preview) self.fit_dialog.fitStartSig.connect(self.start_fit) - self.fit_dialog.abortFit.connect(lambda : self.management.stopFit.emit()) + self.fit_dialog.abortFit.connect(lambda: self.management.stopFit.emit()) self.movedialog.moveData.connect(self.move_sets) self.movedialog.copyData.connect(self.management.copy_sets) self.ptsselectwidget.points_selected.connect(self.management.extract_points) + self.t1tauwidget.newData.connect(self.management.add_new_data) self.t1tauwidget.newData.connect(self.management.add_new_data) self.editsignalwidget.do_something.connect(self.management.apply) @@ -279,7 +287,7 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): use_underscore = save_dialog.checkBox.isChecked() self.management.save(savefile, selected_filter, strip_spaces=use_underscore) - param_outfile = re.sub('[_\s-]?