edit existing lines
This commit is contained in:
parent
62f3839b20
commit
9681d09ed4
@ -506,7 +506,7 @@ class Ui_BaseWindow(object):
|
|||||||
self.menuMethod.setTitle(_translate("BaseWindow", "Method"))
|
self.menuMethod.setTitle(_translate("BaseWindow", "Method"))
|
||||||
self.menuLimits.setTitle(_translate("BaseWindow", "Limits"))
|
self.menuLimits.setTitle(_translate("BaseWindow", "Limits"))
|
||||||
self.menuOptions.setTitle(_translate("BaseWindow", "Options"))
|
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.menuView.setTitle(_translate("BaseWindow", "View"))
|
||||||
self.menuNMR.setTitle(_translate("BaseWindow", "NMR"))
|
self.menuNMR.setTitle(_translate("BaseWindow", "NMR"))
|
||||||
self.menuBDS.setTitle(_translate("BaseWindow", "BDS"))
|
self.menuBDS.setTitle(_translate("BaseWindow", "BDS"))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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
|
# 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.setFrameShape(QtWidgets.QFrame.NoFrame)
|
||||||
self.stackedWidget.setObjectName("stackedWidget")
|
self.stackedWidget.setObjectName("stackedWidget")
|
||||||
self.formLayout.setWidget(1, QtWidgets.QFormLayout.SpanningRole, self.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 = QtWidgets.QPushButton(self.frame)
|
||||||
self.createButton.setObjectName("createButton")
|
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.verticalLayout_2.addWidget(self.frame)
|
||||||
|
|
||||||
self.retranslateUi(Form)
|
self.retranslateUi(Form)
|
||||||
@ -81,3 +87,4 @@ class Ui_Form(object):
|
|||||||
self.mode_comboBox.setItemText(3, _translate("Form", "Rectangle"))
|
self.mode_comboBox.setItemText(3, _translate("Form", "Rectangle"))
|
||||||
self.mode_comboBox.setItemText(4, _translate("Form", "Ellipse"))
|
self.mode_comboBox.setItemText(4, _translate("Form", "Ellipse"))
|
||||||
self.createButton.setText(_translate("Form", "Apply"))
|
self.createButton.setText(_translate("Form", "Apply"))
|
||||||
|
self.cancelbutton.setText(_translate("Form", "Cancel"))
|
||||||
|
@ -5,13 +5,11 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
|||||||
from .._py.ellipsewidget import Ui_ellipsewidget
|
from .._py.ellipsewidget import Ui_ellipsewidget
|
||||||
from .._py.linedrawwidget import Ui_linewidget
|
from .._py.linedrawwidget import Ui_linewidget
|
||||||
from .._py.rectanglewidget import Ui_rectanglewidget
|
from .._py.rectanglewidget import Ui_rectanglewidget
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['LineWidget', 'MultiPointWidget', 'RectangleWidget', 'EllipseWidget', 'TextWidget']
|
|
||||||
|
|
||||||
from .._py.multipointwidget import Ui_multipointwidget
|
from .._py.multipointwidget import Ui_multipointwidget
|
||||||
from .._py.textdrawidget import Ui_textwidget
|
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]:
|
def parse_point(x_widget: QtWidgets.QLineEdit, y_widget: QtWidgets.QLineEdit) -> None | tuple[float, float]:
|
||||||
x = x_widget.text()
|
x = x_widget.text()
|
||||||
@ -50,6 +48,11 @@ class LineWidget(QtWidgets.QWidget, Ui_linewidget):
|
|||||||
|
|
||||||
return dic
|
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):
|
class MultiPointWidget(QtWidgets.QWidget, Ui_multipointwidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -97,6 +100,11 @@ class MultiPointWidget(QtWidgets.QWidget, Ui_multipointwidget):
|
|||||||
|
|
||||||
return dic
|
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):
|
class RectangleWidget(QtWidgets.QWidget, Ui_rectanglewidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
|
@ -22,6 +22,12 @@ class BaseObject:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def get_values(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def set_values(self, *args, **kwargs):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class LineObject(BaseObject):
|
class LineObject(BaseObject):
|
||||||
def __init__(self, pos: float, angle: float, **kwargs):
|
def __init__(self, pos: float, angle: float, **kwargs):
|
||||||
@ -35,6 +41,18 @@ class LineObject(BaseObject):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{"x" if self.angle==90 else "y"}={self.pos}'
|
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):
|
class MultipointObject(BaseObject):
|
||||||
def __init__(self, pts: list, closed: bool = False, **kwargs):
|
def __init__(self, pts: list, closed: bool = False, **kwargs):
|
||||||
@ -53,6 +71,28 @@ class MultipointObject(BaseObject):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{len(self._y)-int(self.closed)}-pts'
|
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):
|
class Rectangle(GraphicsObject):
|
||||||
# adapted from pyqtgraph example on custom objects
|
# adapted from pyqtgraph example on custom objects
|
||||||
|
@ -13,16 +13,39 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
|
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
self.widgets = [LineWidget(self), MultiPointWidget(self), TextWidget(self), RectangleWidget(self), EllipseWidget(self)]
|
self.widgets = {
|
||||||
for w in 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.stackedWidget.addWidget(w)
|
||||||
|
|
||||||
self.graphs = None
|
self.graphs = None
|
||||||
|
self._editmode = False
|
||||||
|
self.frame.setEnabled(False)
|
||||||
|
|
||||||
def update_tree(self):
|
def update_tree(self):
|
||||||
for gid, windows in self.graphs.items():
|
for gid, windows in self.graphs.items():
|
||||||
self.graph_combobox.addItem(windows.title, userData=gid)
|
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):
|
def clear(self):
|
||||||
self.graph_combobox.clear()
|
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')
|
QtWidgets.QMessageBox.information(self, 'Not working', 'Something is missing to create this object')
|
||||||
return
|
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()
|
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))
|
return graph_id, self.graphs[graph_id].drawings[object_id]
|
||||||
child.setData(QtCore.Qt.UserRole, new_obj.id)
|
|
||||||
self.listWidget.addItem(child)
|
|
||||||
|
|
||||||
self.graphs[graph_id].addDrawing(new_obj)
|
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuWindow">
|
<widget class="QMenu" name="menuWindow">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Plots</string>
|
<string>&Plots</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuView">
|
<widget class="QMenu" name="menuView">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -114,12 +114,23 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="0" colspan="2">
|
||||||
<widget class="QPushButton" name="createButton">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<property name="text">
|
<item>
|
||||||
<string>Apply</string>
|
<widget class="QPushButton" name="createButton">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>Apply</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="cancelbutton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cancel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -128,4 +139,21 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
<designerdata>
|
||||||
|
<property name="gridDeltaX">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="gridDeltaY">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="gridSnapX">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="gridSnapY">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="gridVisible">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</designerdata>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
Reference in New Issue
Block a user