diff --git a/src/gui_qt/_py/basewindow.py b/src/gui_qt/_py/basewindow.py
index f21b01c..2c8e195 100644
--- a/src/gui_qt/_py/basewindow.py
+++ b/src/gui_qt/_py/basewindow.py
@@ -506,7 +506,7 @@ class Ui_BaseWindow(object):
self.menuMethod.setTitle(_translate("BaseWindow", "Method"))
self.menuLimits.setTitle(_translate("BaseWindow", "Limits"))
self.menuOptions.setTitle(_translate("BaseWindow", "Options"))
- self.menuWindow.setTitle(_translate("BaseWindow", "Plots"))
+ self.menuWindow.setTitle(_translate("BaseWindow", "&Plots"))
self.menuView.setTitle(_translate("BaseWindow", "View"))
self.menuNMR.setTitle(_translate("BaseWindow", "NMR"))
self.menuBDS.setTitle(_translate("BaseWindow", "BDS"))
diff --git a/src/gui_qt/_py/guidelinewidget.py b/src/gui_qt/_py/guidelinewidget.py
index 39cf6c8..2ec313e 100644
--- a/src/gui_qt/_py/guidelinewidget.py
+++ b/src/gui_qt/_py/guidelinewidget.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Form implementation generated from reading ui file 'src/resources/_ui/guidelinewidget.ui'
+# Form implementation generated from reading ui file '/autohome/dominik/nmreval-gitea/src/resources/_ui/guidelinewidget.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
@@ -60,9 +60,15 @@ class Ui_Form(object):
self.stackedWidget.setFrameShape(QtWidgets.QFrame.NoFrame)
self.stackedWidget.setObjectName("stackedWidget")
self.formLayout.setWidget(1, QtWidgets.QFormLayout.SpanningRole, self.stackedWidget)
+ self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
+ self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.createButton = QtWidgets.QPushButton(self.frame)
self.createButton.setObjectName("createButton")
- self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.createButton)
+ self.horizontalLayout_2.addWidget(self.createButton)
+ self.cancelbutton = QtWidgets.QPushButton(self.frame)
+ self.cancelbutton.setObjectName("cancelbutton")
+ self.horizontalLayout_2.addWidget(self.cancelbutton)
+ self.formLayout.setLayout(2, QtWidgets.QFormLayout.SpanningRole, self.horizontalLayout_2)
self.verticalLayout_2.addWidget(self.frame)
self.retranslateUi(Form)
@@ -81,3 +87,4 @@ class Ui_Form(object):
self.mode_comboBox.setItemText(3, _translate("Form", "Rectangle"))
self.mode_comboBox.setItemText(4, _translate("Form", "Ellipse"))
self.createButton.setText(_translate("Form", "Apply"))
+ self.cancelbutton.setText(_translate("Form", "Cancel"))
diff --git a/src/gui_qt/graphs/draw_inputs.py b/src/gui_qt/graphs/draw_inputs.py
index faa122d..c0547ff 100644
--- a/src/gui_qt/graphs/draw_inputs.py
+++ b/src/gui_qt/graphs/draw_inputs.py
@@ -5,13 +5,11 @@ from PyQt5 import QtCore, QtGui, QtWidgets
from .._py.ellipsewidget import Ui_ellipsewidget
from .._py.linedrawwidget import Ui_linewidget
from .._py.rectanglewidget import Ui_rectanglewidget
-
-
-__all__ = ['LineWidget', 'MultiPointWidget', 'RectangleWidget', 'EllipseWidget', 'TextWidget']
-
from .._py.multipointwidget import Ui_multipointwidget
from .._py.textdrawidget import Ui_textwidget
+__all__ = ['LineWidget', 'MultiPointWidget', 'RectangleWidget', 'EllipseWidget', 'TextWidget']
+
def parse_point(x_widget: QtWidgets.QLineEdit, y_widget: QtWidgets.QLineEdit) -> None | tuple[float, float]:
x = x_widget.text()
@@ -50,6 +48,11 @@ class LineWidget(QtWidgets.QWidget, Ui_linewidget):
return dic
+ def set_args(self, pos: float = None, angle: int = None, color = None):
+ self.pos_lineedit.setText(str(pos))
+ self.orient_combobox.setCurrentIndex(angle%90)
+ self.color_box.setCurrentIndex(self.color_box.findData(color))
+
class MultiPointWidget(QtWidgets.QWidget, Ui_multipointwidget):
def __init__(self, parent=None):
@@ -97,6 +100,11 @@ class MultiPointWidget(QtWidgets.QWidget, Ui_multipointwidget):
return dic
+ def set_args(self, pos: float=0.0, angle: int = None, color = None):
+ self.pos_lineedit.setText(str(pos))
+ self.orient_combobox.setCurrentIndex(angle%90)
+ self.color_box.setCurrentIndex(self.color_box.findData(color))
+
class RectangleWidget(QtWidgets.QWidget, Ui_rectanglewidget):
def __init__(self, parent=None):
diff --git a/src/gui_qt/graphs/draw_objects.py b/src/gui_qt/graphs/draw_objects.py
index c1c06f4..29b3582 100644
--- a/src/gui_qt/graphs/draw_objects.py
+++ b/src/gui_qt/graphs/draw_objects.py
@@ -22,6 +22,12 @@ class BaseObject:
def __str__(self):
raise NotImplementedError
+ def get_values(self):
+ raise NotImplementedError
+
+ def set_values(self, *args, **kwargs):
+ raise NotImplementedError
+
class LineObject(BaseObject):
def __init__(self, pos: float, angle: float, **kwargs):
@@ -35,6 +41,18 @@ class LineObject(BaseObject):
def __str__(self):
return f'{"x" if self.angle==90 else "y"}={self.pos}'
+ def get_values(self):
+ return {'type': 'line', 'color': self.color, 'pos': self.pos, 'angle': self.angle}
+
+ def set_values(self, pos=None, angle=None, color=None):
+
+ if pos != self.pos:
+ self.drawing.setPos(pos)
+ if angle != self.angle:
+ self.drawing.setAngle(angle)
+ if color != self.color:
+ self.drawing.setPen(mkPen(color.rgb()))
+
class MultipointObject(BaseObject):
def __init__(self, pts: list, closed: bool = False, **kwargs):
@@ -53,6 +71,28 @@ class MultipointObject(BaseObject):
def __str__(self):
return f'{len(self._y)-int(self.closed)}-pts'
+ def get_values(self):
+ dic = {'type': 'multipts', 'color': self.color, 'x': None, 'y': None, 'closed': self.closed}
+
+ if self.closed:
+ dic['x'] = self._x[:-1]
+ dic['y'] = self._y[:-1]
+ else:
+ dic['x'] = self._x
+ dic['y'] = self._y
+ return dic
+
+ def set_values(self, x=None, y=None, closed=None, color=None):
+
+ if color != self.color:
+ self.drawing.setPen(mkPen(color.rgb()))
+
+ self._x = x
+ self._y = y
+
+ if closed:
+ self._x += (x[0],)
+ self._y += (y[0],)
class Rectangle(GraphicsObject):
# adapted from pyqtgraph example on custom objects
diff --git a/src/gui_qt/graphs/drawings.py b/src/gui_qt/graphs/drawings.py
index b820349..81067fb 100644
--- a/src/gui_qt/graphs/drawings.py
+++ b/src/gui_qt/graphs/drawings.py
@@ -13,16 +13,39 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
self.setupUi(self)
- self.widgets = [LineWidget(self), MultiPointWidget(self), TextWidget(self), RectangleWidget(self), EllipseWidget(self)]
- for w in self.widgets:
+ self.widgets = {
+ 'line': LineWidget(self),
+ 'multipts': MultiPointWidget(self),
+ 'text': TextWidget(self),
+ 'rectangle': RectangleWidget(self),
+ 'ellipse': EllipseWidget(self),
+ }
+ for w in self.widgets.values():
self.stackedWidget.addWidget(w)
self.graphs = None
+ self._editmode = False
+ self.frame.setEnabled(False)
def update_tree(self):
for gid, windows in self.graphs.items():
self.graph_combobox.addItem(windows.title, userData=gid)
+ @QtCore.pyqtSlot(name='on_newButton_clicked')
+ @QtCore.pyqtSlot(name='on_editButton_clicked')
+ def start_drawing(self):
+ self._editmode = self.sender() == self.editButton
+ if self._editmode:
+
+ graph_id, obj = self.get_item()
+ arguments = obj.get_values()
+ obj_type = arguments.pop('type')
+ self.widgets[obj_type].set_args(**arguments)
+
+ self.listWidget.setEnabled(False)
+ self.graph_combobox.setEnabled(False)
+ self.frame.setEnabled(True)
+
def clear(self):
self.graph_combobox.clear()
@@ -37,13 +60,36 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
QtWidgets.QMessageBox.information(self, 'Not working', 'Something is missing to create this object')
return
- new_obj = [LineObject, MultipointObject, TextObject, RectangleObject, EllipseObject][self.mode_comboBox.currentIndex()](**dic)
+ graph_id, obj = self.get_item()
+
+ if self._editmode:
+ obj.set_values(**dic)
+
+ else:
+ new_obj = [LineObject, MultipointObject, TextObject, RectangleObject, EllipseObject][self.mode_comboBox.currentIndex()](**dic)
+
+ child = QtWidgets.QListWidgetItem(str(new_obj))
+ child.setData(QtCore.Qt.UserRole, new_obj.id)
+ self.listWidget.addItem(child)
+
+ self.graphs[graph_id].addDrawing(new_obj)
+
+ self.graph_combobox.setEnabled(True)
+ self.listWidget.setEnabled(True)
+ self.frame.setEnabled(False)
+
+ @QtCore.pyqtSlot(name='on_cancelbutton_clicked')
+ def cancel_edit(self):
+ self.graph_combobox.setEnabled(True)
+ self.listWidget.setEnabled(True)
+ self.frame.setEnabled(False)
+
+ def get_item(self):
+ edit_item = self.listWidget.currentItem()
graph_id = self.graph_combobox.currentData()
+ if edit_item is None:
+ return graph_id, None
+ object_id = edit_item.data(QtCore.Qt.UserRole)
- child = QtWidgets.QListWidgetItem(str(new_obj))
- child.setData(QtCore.Qt.UserRole, new_obj.id)
- self.listWidget.addItem(child)
-
- self.graphs[graph_id].addDrawing(new_obj)
-
+ return graph_id, self.graphs[graph_id].drawings[object_id]
diff --git a/src/resources/_ui/basewindow.ui b/src/resources/_ui/basewindow.ui
index 7e45310..f71039f 100644
--- a/src/resources/_ui/basewindow.ui
+++ b/src/resources/_ui/basewindow.ui
@@ -266,7 +266,7 @@
@@ -128,4 +139,21 @@
+
+
+ 10
+
+
+ 10
+
+
+ true
+
+
+ true
+
+
+ true
+
+