basics are working
This commit is contained in:
parent
72d2fc5018
commit
3bb99f4406
@ -18,21 +18,21 @@ class Ui_Form(object):
|
|||||||
self.verticalLayout_2 = QtWidgets.QVBoxLayout(Form)
|
self.verticalLayout_2 = QtWidgets.QVBoxLayout(Form)
|
||||||
self.verticalLayout_2.setContentsMargins(3, 3, 3, 3)
|
self.verticalLayout_2.setContentsMargins(3, 3, 3, 3)
|
||||||
self.verticalLayout_2.setObjectName("verticalLayout_2")
|
self.verticalLayout_2.setObjectName("verticalLayout_2")
|
||||||
self.treeWidget_2 = QtWidgets.QTreeWidget(Form)
|
self.treeWidget = QtWidgets.QTreeWidget(Form)
|
||||||
self.treeWidget_2.setRootIsDecorated(True)
|
self.treeWidget.setRootIsDecorated(True)
|
||||||
self.treeWidget_2.setObjectName("treeWidget_2")
|
self.treeWidget.setObjectName("treeWidget")
|
||||||
self.treeWidget_2.headerItem().setText(0, "1")
|
self.treeWidget.headerItem().setText(0, "1")
|
||||||
self.treeWidget_2.header().setVisible(False)
|
self.treeWidget.header().setVisible(False)
|
||||||
self.treeWidget_2.header().setHighlightSections(True)
|
self.treeWidget.header().setHighlightSections(True)
|
||||||
self.verticalLayout_2.addWidget(self.treeWidget_2)
|
self.verticalLayout_2.addWidget(self.treeWidget)
|
||||||
self.horizontalLayout = QtWidgets.QHBoxLayout()
|
self.horizontalLayout = QtWidgets.QHBoxLayout()
|
||||||
self.horizontalLayout.setObjectName("horizontalLayout")
|
self.horizontalLayout.setObjectName("horizontalLayout")
|
||||||
self.pushButton = QtWidgets.QPushButton(Form)
|
self.newButton = QtWidgets.QPushButton(Form)
|
||||||
self.pushButton.setObjectName("pushButton")
|
self.newButton.setObjectName("newButton")
|
||||||
self.horizontalLayout.addWidget(self.pushButton)
|
self.horizontalLayout.addWidget(self.newButton)
|
||||||
self.pushButton_2 = QtWidgets.QPushButton(Form)
|
self.editButton = QtWidgets.QPushButton(Form)
|
||||||
self.pushButton_2.setObjectName("pushButton_2")
|
self.editButton.setObjectName("editButton")
|
||||||
self.horizontalLayout.addWidget(self.pushButton_2)
|
self.horizontalLayout.addWidget(self.editButton)
|
||||||
self.verticalLayout_2.addLayout(self.horizontalLayout)
|
self.verticalLayout_2.addLayout(self.horizontalLayout)
|
||||||
self.frame = QtWidgets.QFrame(Form)
|
self.frame = QtWidgets.QFrame(Form)
|
||||||
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
|
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
|
||||||
@ -41,14 +41,14 @@ class Ui_Form(object):
|
|||||||
self.formLayout = QtWidgets.QFormLayout(self.frame)
|
self.formLayout = QtWidgets.QFormLayout(self.frame)
|
||||||
self.formLayout.setContentsMargins(-1, -1, -1, 6)
|
self.formLayout.setContentsMargins(-1, -1, -1, 6)
|
||||||
self.formLayout.setObjectName("formLayout")
|
self.formLayout.setObjectName("formLayout")
|
||||||
self.label_12 = QtWidgets.QLabel(self.frame)
|
self.type_label = QtWidgets.QLabel(self.frame)
|
||||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
|
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
|
||||||
sizePolicy.setHorizontalStretch(0)
|
sizePolicy.setHorizontalStretch(0)
|
||||||
sizePolicy.setVerticalStretch(0)
|
sizePolicy.setVerticalStretch(0)
|
||||||
sizePolicy.setHeightForWidth(self.label_12.sizePolicy().hasHeightForWidth())
|
sizePolicy.setHeightForWidth(self.type_label.sizePolicy().hasHeightForWidth())
|
||||||
self.label_12.setSizePolicy(sizePolicy)
|
self.type_label.setSizePolicy(sizePolicy)
|
||||||
self.label_12.setObjectName("label_12")
|
self.type_label.setObjectName("type_label")
|
||||||
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_12)
|
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.type_label)
|
||||||
self.mode_comboBox = QtWidgets.QComboBox(self.frame)
|
self.mode_comboBox = QtWidgets.QComboBox(self.frame)
|
||||||
self.mode_comboBox.setObjectName("mode_comboBox")
|
self.mode_comboBox.setObjectName("mode_comboBox")
|
||||||
self.mode_comboBox.addItem("")
|
self.mode_comboBox.addItem("")
|
||||||
@ -61,9 +61,9 @@ 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.pushButton_3 = QtWidgets.QPushButton(self.frame)
|
self.createButton = QtWidgets.QPushButton(self.frame)
|
||||||
self.pushButton_3.setObjectName("pushButton_3")
|
self.createButton.setObjectName("createButton")
|
||||||
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.pushButton_3)
|
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.createButton)
|
||||||
self.verticalLayout_2.addWidget(self.frame)
|
self.verticalLayout_2.addWidget(self.frame)
|
||||||
|
|
||||||
self.retranslateUi(Form)
|
self.retranslateUi(Form)
|
||||||
@ -73,12 +73,12 @@ class Ui_Form(object):
|
|||||||
def retranslateUi(self, Form):
|
def retranslateUi(self, Form):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
Form.setWindowTitle(_translate("Form", "Form"))
|
Form.setWindowTitle(_translate("Form", "Form"))
|
||||||
self.pushButton.setText(_translate("Form", "New object"))
|
self.newButton.setText(_translate("Form", "New object"))
|
||||||
self.pushButton_2.setText(_translate("Form", "Edit"))
|
self.editButton.setText(_translate("Form", "Edit"))
|
||||||
self.label_12.setText(_translate("Form", "Type"))
|
self.type_label.setText(_translate("Form", "Type"))
|
||||||
self.mode_comboBox.setItemText(0, _translate("Form", "Infinite Line"))
|
self.mode_comboBox.setItemText(0, _translate("Form", "Infinite Line"))
|
||||||
self.mode_comboBox.setItemText(1, _translate("Form", "Multiple points"))
|
self.mode_comboBox.setItemText(1, _translate("Form", "Multiple points"))
|
||||||
self.mode_comboBox.setItemText(2, _translate("Form", "Text"))
|
self.mode_comboBox.setItemText(2, _translate("Form", "Text"))
|
||||||
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.pushButton_3.setText(_translate("Form", "Create"))
|
self.createButton.setText(_translate("Form", "Apply"))
|
||||||
|
@ -17,32 +17,38 @@ class Ui_rectanglewidget(object):
|
|||||||
rectanglewidget.resize(400, 300)
|
rectanglewidget.resize(400, 300)
|
||||||
self.gridLayout = QtWidgets.QGridLayout(rectanglewidget)
|
self.gridLayout = QtWidgets.QGridLayout(rectanglewidget)
|
||||||
self.gridLayout.setObjectName("gridLayout")
|
self.gridLayout.setObjectName("gridLayout")
|
||||||
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
|
||||||
self.gridLayout.addItem(spacerItem, 3, 0, 1, 1)
|
|
||||||
self.color_label = QtWidgets.QLabel(rectanglewidget)
|
self.color_label = QtWidgets.QLabel(rectanglewidget)
|
||||||
self.color_label.setObjectName("color_label")
|
self.color_label.setObjectName("color_label")
|
||||||
self.gridLayout.addWidget(self.color_label, 0, 0, 1, 1)
|
self.gridLayout.addWidget(self.color_label, 0, 0, 1, 1)
|
||||||
self.left_x = QtWidgets.QLineEdit(rectanglewidget)
|
self.left_x = QtWidgets.QLineEdit(rectanglewidget)
|
||||||
self.left_x.setObjectName("left_x")
|
self.left_x.setObjectName("left_x")
|
||||||
self.gridLayout.addWidget(self.left_x, 1, 1, 1, 1)
|
self.gridLayout.addWidget(self.left_x, 2, 1, 1, 1)
|
||||||
self.left_y = QtWidgets.QLineEdit(rectanglewidget)
|
self.left_y = QtWidgets.QLineEdit(rectanglewidget)
|
||||||
self.left_y.setObjectName("left_y")
|
self.left_y.setObjectName("left_y")
|
||||||
self.gridLayout.addWidget(self.left_y, 1, 2, 1, 1)
|
self.gridLayout.addWidget(self.left_y, 2, 2, 1, 1)
|
||||||
self.left_label = QtWidgets.QLabel(rectanglewidget)
|
self.right_x = QtWidgets.QLineEdit(rectanglewidget)
|
||||||
self.left_label.setObjectName("left_label")
|
self.right_x.setObjectName("right_x")
|
||||||
self.gridLayout.addWidget(self.left_label, 1, 0, 1, 1)
|
self.gridLayout.addWidget(self.right_x, 3, 1, 1, 1)
|
||||||
self.color_box = ColorListEditor(rectanglewidget)
|
self.color_box = ColorListEditor(rectanglewidget)
|
||||||
self.color_box.setObjectName("color_box")
|
self.color_box.setObjectName("color_box")
|
||||||
self.gridLayout.addWidget(self.color_box, 0, 1, 1, 2)
|
self.gridLayout.addWidget(self.color_box, 0, 1, 1, 2)
|
||||||
self.right_label = QtWidgets.QLabel(rectanglewidget)
|
self.left_label = QtWidgets.QLabel(rectanglewidget)
|
||||||
self.right_label.setObjectName("right_label")
|
self.left_label.setObjectName("left_label")
|
||||||
self.gridLayout.addWidget(self.right_label, 2, 0, 1, 1)
|
self.gridLayout.addWidget(self.left_label, 2, 0, 1, 1)
|
||||||
self.right_x = QtWidgets.QLineEdit(rectanglewidget)
|
|
||||||
self.right_x.setObjectName("right_x")
|
|
||||||
self.gridLayout.addWidget(self.right_x, 2, 1, 1, 1)
|
|
||||||
self.right_y = QtWidgets.QLineEdit(rectanglewidget)
|
self.right_y = QtWidgets.QLineEdit(rectanglewidget)
|
||||||
self.right_y.setObjectName("right_y")
|
self.right_y.setObjectName("right_y")
|
||||||
self.gridLayout.addWidget(self.right_y, 2, 2, 1, 1)
|
self.gridLayout.addWidget(self.right_y, 3, 2, 1, 1)
|
||||||
|
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
||||||
|
self.gridLayout.addItem(spacerItem, 4, 0, 1, 1)
|
||||||
|
self.right_label = QtWidgets.QLabel(rectanglewidget)
|
||||||
|
self.right_label.setObjectName("right_label")
|
||||||
|
self.gridLayout.addWidget(self.right_label, 3, 0, 1, 1)
|
||||||
|
self.fill_label = QtWidgets.QLabel(rectanglewidget)
|
||||||
|
self.fill_label.setObjectName("fill_label")
|
||||||
|
self.gridLayout.addWidget(self.fill_label, 1, 0, 1, 1)
|
||||||
|
self.fill_box = ColorListEditor(rectanglewidget)
|
||||||
|
self.fill_box.setObjectName("fill_box")
|
||||||
|
self.gridLayout.addWidget(self.fill_box, 1, 1, 1, 2)
|
||||||
|
|
||||||
self.retranslateUi(rectanglewidget)
|
self.retranslateUi(rectanglewidget)
|
||||||
QtCore.QMetaObject.connectSlotsByName(rectanglewidget)
|
QtCore.QMetaObject.connectSlotsByName(rectanglewidget)
|
||||||
@ -53,8 +59,9 @@ class Ui_rectanglewidget(object):
|
|||||||
self.color_label.setText(_translate("rectanglewidget", "Color"))
|
self.color_label.setText(_translate("rectanglewidget", "Color"))
|
||||||
self.left_x.setPlaceholderText(_translate("rectanglewidget", "x"))
|
self.left_x.setPlaceholderText(_translate("rectanglewidget", "x"))
|
||||||
self.left_y.setPlaceholderText(_translate("rectanglewidget", "y"))
|
self.left_y.setPlaceholderText(_translate("rectanglewidget", "y"))
|
||||||
self.left_label.setText(_translate("rectanglewidget", "Lower left"))
|
|
||||||
self.right_label.setText(_translate("rectanglewidget", "Upper right"))
|
|
||||||
self.right_x.setPlaceholderText(_translate("rectanglewidget", "x"))
|
self.right_x.setPlaceholderText(_translate("rectanglewidget", "x"))
|
||||||
|
self.left_label.setText(_translate("rectanglewidget", "Lower left"))
|
||||||
self.right_y.setPlaceholderText(_translate("rectanglewidget", "y"))
|
self.right_y.setPlaceholderText(_translate("rectanglewidget", "y"))
|
||||||
|
self.right_label.setText(_translate("rectanglewidget", "Upper right"))
|
||||||
|
self.fill_label.setText(_translate("rectanglewidget", "Fill color"))
|
||||||
from gui_qt.lib.delegates import ColorListEditor
|
from gui_qt.lib.delegates import ColorListEditor
|
||||||
|
@ -35,7 +35,7 @@ class LineWidget(QtWidgets.QWidget, Ui_linewidget):
|
|||||||
self.pos_lineedit.setValidator(QtGui.QDoubleValidator())
|
self.pos_lineedit.setValidator(QtGui.QDoubleValidator())
|
||||||
|
|
||||||
|
|
||||||
def collect_args(self):
|
def collect_args(self) -> dict | None:
|
||||||
pos = self.pos_lineedit.text()
|
pos = self.pos_lineedit.text()
|
||||||
try:
|
try:
|
||||||
pos = float(pos)
|
pos = float(pos)
|
||||||
@ -56,7 +56,11 @@ class MultiPointWidget(QtWidgets.QWidget, Ui_multipointwidget):
|
|||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
def new_point(self, _):
|
self.new_point()
|
||||||
|
self.new_point()
|
||||||
|
|
||||||
|
@QtCore.pyqtSlot(name='on_addButton_clicked')
|
||||||
|
def new_point(self):
|
||||||
row = self.table_widget.rowCount()
|
row = self.table_widget.rowCount()
|
||||||
self.table_widget.setRowCount(row+1)
|
self.table_widget.setRowCount(row+1)
|
||||||
placeholder = ['x', 'y']
|
placeholder = ['x', 'y']
|
||||||
@ -68,28 +72,30 @@ class MultiPointWidget(QtWidgets.QWidget, Ui_multipointwidget):
|
|||||||
|
|
||||||
self.table_widget.setCellWidget(row, column, line_edit)
|
self.table_widget.setCellWidget(row, column, line_edit)
|
||||||
|
|
||||||
def less_point(self, _):
|
@QtCore.pyqtSlot(name='on_removeButton_clicked')
|
||||||
self.table_widget.removeRow(self.table_widget.rowCount()-1)
|
def less_point(self):
|
||||||
|
if self.table_widget.rowCount() > 2:
|
||||||
|
self.table_widget.removeRow(self.table_widget.rowCount()-1)
|
||||||
|
|
||||||
def collect_args(self):
|
def collect_args(self) -> dict | None:
|
||||||
dic = super().collect_args()
|
|
||||||
|
|
||||||
pts = []
|
pts = []
|
||||||
if self.table_widget.rowCount() <= 1:
|
if self.table_widget.rowCount() < 2:
|
||||||
return
|
return
|
||||||
|
|
||||||
for row in range(self.table_widget.rowCount()):
|
for row in range(self.table_widget.rowCount()):
|
||||||
next_pt = self.parse_point(self.table_widget.cellWidget(row, 0), self.table_widget.cellWidget(row, 1))
|
next_pt = parse_point(self.table_widget.cellWidget(row, 0), self.table_widget.cellWidget(row, 1))
|
||||||
if next_pt is None:
|
if next_pt is None:
|
||||||
return
|
return
|
||||||
pts.append(next_pt)
|
pts.append(next_pt)
|
||||||
|
|
||||||
if pts:
|
dic = {
|
||||||
dic['pts'] = pts
|
'color': self.color_box.currentData(QtCore.Qt.UserRole),
|
||||||
dic['closed'] = self.loop_checkbox.isChecked()
|
'pts': pts,
|
||||||
return dic
|
'closed': self.loop_checkbox.isChecked(),
|
||||||
else:
|
}
|
||||||
return
|
|
||||||
|
return dic
|
||||||
|
|
||||||
|
|
||||||
class RectangleWidget(QtWidgets.QWidget, Ui_rectanglewidget):
|
class RectangleWidget(QtWidgets.QWidget, Ui_rectanglewidget):
|
||||||
@ -97,22 +103,29 @@ class RectangleWidget(QtWidgets.QWidget, Ui_rectanglewidget):
|
|||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
|
self.fill_box.insertItem(0, 'No fill', None)
|
||||||
|
self.fill_box.setCurrentIndex(0)
|
||||||
|
|
||||||
self.left_x.setValidator(QtGui.QDoubleValidator())
|
self.left_x.setValidator(QtGui.QDoubleValidator())
|
||||||
self.left_y.setValidator(QtGui.QDoubleValidator())
|
self.left_y.setValidator(QtGui.QDoubleValidator())
|
||||||
self.right_x.setValidator(QtGui.QDoubleValidator())
|
self.right_x.setValidator(QtGui.QDoubleValidator())
|
||||||
self.right_y.setValidator(QtGui.QDoubleValidator())
|
self.right_y.setValidator(QtGui.QDoubleValidator())
|
||||||
|
|
||||||
def collect_args(self):
|
def collect_args(self) -> dict | None:
|
||||||
dic = super().collect_args()
|
left = parse_point(self.left_x, self.left_y)
|
||||||
left = self.parse_point(self.left_x, self.left_y)
|
|
||||||
if left is None:
|
if left is None:
|
||||||
return
|
return
|
||||||
dic['left'] = left
|
|
||||||
|
|
||||||
right = self.parse_point(self.right_x, self.right_y)
|
right = parse_point(self.right_x, self.right_y)
|
||||||
if right is None:
|
if right is None:
|
||||||
return
|
return
|
||||||
dic['right'] = right
|
|
||||||
|
dic = {
|
||||||
|
'color': self.color_box.currentData(QtCore.Qt.UserRole),
|
||||||
|
'fill': self.fill_box.currentData(QtCore.Qt.UserRole),
|
||||||
|
'left': left,
|
||||||
|
'right': right,
|
||||||
|
}
|
||||||
|
|
||||||
return dic
|
return dic
|
||||||
|
|
||||||
@ -127,17 +140,19 @@ class EllipseWidget(QtWidgets.QWidget, Ui_ellipsewidget):
|
|||||||
self.width_line.setValidator(QtGui.QDoubleValidator())
|
self.width_line.setValidator(QtGui.QDoubleValidator())
|
||||||
self.height_line.setValidator(QtGui.QDoubleValidator())
|
self.height_line.setValidator(QtGui.QDoubleValidator())
|
||||||
|
|
||||||
def collect_args(self):
|
def collect_args(self) -> dict | None:
|
||||||
dic = super().collect_args()
|
centre = parse_point(self.center_x, self.center_y)
|
||||||
centre = self.parse_point(self.center_x, self.center_y)
|
|
||||||
if centre is None:
|
if centre is None:
|
||||||
return
|
return
|
||||||
dic['centre'] = centre
|
axes = parse_point(self.width_line, self.height_line)
|
||||||
|
|
||||||
axes = self.parse_point(self.width_line, self.height_line)
|
|
||||||
if axes is None:
|
if axes is None:
|
||||||
return
|
return
|
||||||
dic['axes'] = axes
|
|
||||||
|
dic = {
|
||||||
|
'color': self.color_box.currentData(QtCore.Qt.UserRole),
|
||||||
|
'center': centre,
|
||||||
|
'axes': axes,
|
||||||
|
}
|
||||||
|
|
||||||
return dic
|
return dic
|
||||||
|
|
||||||
@ -150,13 +165,16 @@ class TextWidget(QtWidgets.QWidget, Ui_textwidget):
|
|||||||
self.center_x.setValidator(QtGui.QDoubleValidator())
|
self.center_x.setValidator(QtGui.QDoubleValidator())
|
||||||
self.center_y.setValidator(QtGui.QDoubleValidator())
|
self.center_y.setValidator(QtGui.QDoubleValidator())
|
||||||
|
|
||||||
def collect_args(self):
|
def collect_args(self) -> dict | None:
|
||||||
dic = super().collect_args()
|
|
||||||
centre = self.parse_point(self.center_x, self.center_y)
|
centre = parse_point(self.center_x, self.center_y)
|
||||||
if centre is None:
|
if centre is None:
|
||||||
return
|
return
|
||||||
dic['centre'] = centre
|
|
||||||
|
|
||||||
dic['text'] = self.text_lineedit.text()
|
dic = {
|
||||||
|
'color': self.color_box.currentData(QtCore.Qt.UserRole),
|
||||||
|
'pos': centre,
|
||||||
|
'text': self.text_lineedit.text(),
|
||||||
|
}
|
||||||
|
|
||||||
return dic
|
return dic
|
||||||
|
@ -2,14 +2,14 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from pyqtgraph import mkPen, GraphicsObject, mkBrush
|
from pyqtgraph import TextItem, mkPen, GraphicsObject, mkBrush
|
||||||
from numpy import log10
|
from numpy import log10
|
||||||
|
|
||||||
from gui_qt.Qt import QtCore, QtGui
|
from gui_qt.Qt import QtCore, QtGui
|
||||||
from gui_qt.lib.pg_objects import LogInfiniteLine, PlotItem
|
from gui_qt.lib.pg_objects import LogInfiniteLine, PlotItem
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['LineObject', 'MultipointObject', 'RectangleObject']
|
__all__ = ['LineObject', 'MultipointObject', 'RectangleObject', 'TextObject', 'EllipseObject']
|
||||||
|
|
||||||
|
|
||||||
class BaseObject:
|
class BaseObject:
|
||||||
@ -54,19 +54,23 @@ class MultipointObject(BaseObject):
|
|||||||
return f'{len(self._y)-int(self.closed)}-pts'
|
return f'{len(self._y)-int(self.closed)}-pts'
|
||||||
|
|
||||||
|
|
||||||
class RectangleObject(GraphicsObject, BaseObject):
|
class Rectangle(GraphicsObject):
|
||||||
def __init__(self, left: tuple, right: tuple, **kwargs):
|
# adapted from pyqtgraph example on custom objects
|
||||||
|
|
||||||
|
def __init__(self, left: tuple, right: tuple):
|
||||||
GraphicsObject.__init__(self)
|
GraphicsObject.__init__(self)
|
||||||
BaseObject.__init__(self, **kwargs)
|
|
||||||
|
|
||||||
self.p0 = left
|
self.p0 = left
|
||||||
self.delta = [right[0]-self.p0[0], right[1]-self.p0[1]]
|
self.delta = [right[0]-self.p0[0], right[1]-self.p0[1]]
|
||||||
|
|
||||||
|
self.x_disp = self.p0[0]
|
||||||
|
self.dx = self.delta[0]
|
||||||
|
self.y_disp = self.p0[1]
|
||||||
|
self.dy = self.delta[1]
|
||||||
|
|
||||||
self.log_mode = [False, False]
|
self.log_mode = [False, False]
|
||||||
self.generatePicture()
|
self.generatePicture()
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return 'rectangle'
|
|
||||||
|
|
||||||
def generatePicture(self):
|
def generatePicture(self):
|
||||||
## pre-computing a QPicture object allows paint() to run much more quickly,
|
## pre-computing a QPicture object allows paint() to run much more quickly,
|
||||||
## rather than re-drawing the shapes every time.
|
## rather than re-drawing the shapes every time.
|
||||||
@ -74,10 +78,10 @@ class RectangleObject(GraphicsObject, BaseObject):
|
|||||||
p = QtGui.QPainter(self.picture)
|
p = QtGui.QPainter(self.picture)
|
||||||
p.setPen(mkPen('w'))
|
p.setPen(mkPen('w'))
|
||||||
p.setBrush(mkBrush('r'))
|
p.setBrush(mkBrush('r'))
|
||||||
p.drawRect(QtCore.QRectF(*self.p0, *self.delta))
|
p.drawRect(QtCore.QRectF(self.x_disp, self.y_disp, self.dx, self.dy))
|
||||||
p.end()
|
p.end()
|
||||||
|
|
||||||
def paint(self, p, _):
|
def paint(self, p, *_):
|
||||||
p.drawPicture(0, 0, self.picture)
|
p.drawPicture(0, 0, self.picture)
|
||||||
|
|
||||||
def boundingRect(self):
|
def boundingRect(self):
|
||||||
@ -92,16 +96,124 @@ class RectangleObject(GraphicsObject, BaseObject):
|
|||||||
|
|
||||||
if self.log_mode[0] != x_mode:
|
if self.log_mode[0] != x_mode:
|
||||||
if x_mode:
|
if x_mode:
|
||||||
xmax = log10(self.p0[0]+self.delta[0])
|
x0 = self.p0[0]
|
||||||
self.x_disp = log10(self.p0[0])
|
xmax = log10(x0+self.delta[0])
|
||||||
self.dx = xmax - self.x0
|
self.x_disp = log10(x0)
|
||||||
|
self.dx = xmax - self.x_disp
|
||||||
else:
|
else:
|
||||||
self.x_disp = self.p0[0]
|
self.x_disp = self.p0[0]
|
||||||
self.dx = self.delta[0]
|
self.dx = self.delta[0]
|
||||||
if args[1] and self.log_mode[1] != args[1]:
|
|
||||||
ymax = log10(self.y0 + self.dy)
|
if self.log_mode[1] != y_mode:
|
||||||
self.y0 = log10(self.y0)
|
if y_mode:
|
||||||
self.dy = ymax - self.y0
|
y0 = self.p0[1]
|
||||||
|
ymax = log10(y0 + self.delta[1])
|
||||||
|
self.y_disp = log10(y0)
|
||||||
|
self.dy = ymax - self.y_disp
|
||||||
|
else:
|
||||||
|
self.y_disp = self.p0[1]
|
||||||
|
self.dy = self.delta[1]
|
||||||
|
|
||||||
|
self.generatePicture()
|
||||||
|
|
||||||
|
self.log_mode = [x_mode, y_mode]
|
||||||
|
|
||||||
|
self.informViewBoundsChanged()
|
||||||
|
|
||||||
|
class RectangleObject(BaseObject):
|
||||||
|
def __init__(self, left: tuple, right: tuple, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
self.left = left
|
||||||
|
self.right = right
|
||||||
|
|
||||||
|
self.drawing = Rectangle(left, right)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'Rectangle {self.left} to {self.right}'
|
||||||
|
|
||||||
|
|
||||||
|
class TextObject(BaseObject):
|
||||||
|
def __init__(self, text, pos, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
self.pos = pos
|
||||||
|
self.drawing = TextItem(text, anchor=(0.5, 0.5), color=self.color.rgb())
|
||||||
|
self.drawing.setPos(*pos)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'{self.drawing.toPlainText()} at {self.pos}'
|
||||||
|
|
||||||
|
|
||||||
|
class EllipseObject(BaseObject):
|
||||||
|
def __init__(self, center: tuple, axes: tuple, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
self.center = center
|
||||||
|
self.axes = axes
|
||||||
|
|
||||||
|
self.drawing = Ellipse(center, axes)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'Ellipse at {self.center}'
|
||||||
|
|
||||||
|
class Ellipse(GraphicsObject):
|
||||||
|
# adapted from pyqtgraph example on custom objects
|
||||||
|
|
||||||
|
def __init__(self, center: tuple, axes: tuple):
|
||||||
|
GraphicsObject.__init__(self)
|
||||||
|
|
||||||
|
self.center = center
|
||||||
|
self.ax = axes
|
||||||
|
|
||||||
|
self.center_disp = self.center
|
||||||
|
self.ax_disp = self.ax
|
||||||
|
|
||||||
|
self.log_mode = [False, False]
|
||||||
|
self.generatePicture()
|
||||||
|
|
||||||
|
def generatePicture(self):
|
||||||
|
## pre-computing a QPicture object allows paint() to run much more quickly,
|
||||||
|
## rather than re-drawing the shapes every time.
|
||||||
|
self.picture = QtGui.QPicture()
|
||||||
|
p = QtGui.QPainter(self.picture)
|
||||||
|
p.setPen(mkPen('w'))
|
||||||
|
p.setBrush(mkBrush('r'))
|
||||||
|
p.drawEllipse(QtCore.QPointF(*self.center_disp), *self.ax_disp)
|
||||||
|
p.end()
|
||||||
|
|
||||||
|
def paint(self, p, *_):
|
||||||
|
p.drawPicture(0, 0, self.picture)
|
||||||
|
|
||||||
|
def boundingRect(self):
|
||||||
|
## boundingRect _must_ indicate the entire area that will be drawn on
|
||||||
|
## or else we will get artifacts and possibly crashing.
|
||||||
|
## (in this case, QPicture does all the work of computing the bouning rect for us)
|
||||||
|
return QtCore.QRectF(self.picture.boundingRect())
|
||||||
|
|
||||||
|
def setLogMode(self, x_mode, y_mode):
|
||||||
|
if self.log_mode == [x_mode, y_mode]:
|
||||||
|
return
|
||||||
|
|
||||||
|
if self.log_mode[0] != x_mode:
|
||||||
|
if x_mode:
|
||||||
|
x0 = self.p0[0]
|
||||||
|
xmax = log10(x0+self.delta[0])
|
||||||
|
self.x_disp = log10(x0)
|
||||||
|
self.dx = xmax - self.x_disp
|
||||||
|
else:
|
||||||
|
self.x_disp = self.p0[0]
|
||||||
|
self.dx = self.delta[0]
|
||||||
|
|
||||||
|
if self.log_mode[1] != y_mode:
|
||||||
|
if y_mode:
|
||||||
|
y0 = self.p0[1]
|
||||||
|
ymax = log10(y0 + self.delta[1])
|
||||||
|
self.y_disp = log10(y0)
|
||||||
|
self.dy = ymax - self.y_disp
|
||||||
|
else:
|
||||||
|
self.y_disp = self.p0[1]
|
||||||
|
self.dy = self.delta[1]
|
||||||
|
|
||||||
self.generatePicture()
|
self.generatePicture()
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
child = QtWidgets.QTreeWidgetItem([d])
|
child = QtWidgets.QTreeWidgetItem([d])
|
||||||
item.addChild(child)
|
item.addChild(child)
|
||||||
|
|
||||||
self.treeWidget_2.addTopLevelItem(item)
|
self.treeWidget.addTopLevelItem(item)
|
||||||
# self.graph_comboBox.addItem(name, userData=gid)
|
# self.graph_comboBox.addItem(name, userData=gid)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
@ -38,29 +38,27 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
def change_draw_type(self, idx: int):
|
def change_draw_type(self, idx: int):
|
||||||
self.stackedWidget.setCurrentIndex(idx)
|
self.stackedWidget.setCurrentIndex(idx)
|
||||||
|
|
||||||
@QtCore.pyqtSlot(name='on_pushButton_3_clicked')
|
@QtCore.pyqtSlot(name='on_createButton_clicked')
|
||||||
def make_drawing(self):
|
def make_drawing(self):
|
||||||
dic = self.stackedWidget.currentWidget().collect_args()
|
dic = self.stackedWidget.currentWidget().collect_args()
|
||||||
if dic is None:
|
if dic is None:
|
||||||
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
|
||||||
|
|
||||||
idx = self.treeWidget_2.selectedIndexes()
|
idx = self.treeWidget.selectedIndexes()
|
||||||
if idx:
|
if idx:
|
||||||
item = self.treeWidget_2.itemFromIndex(idx[0])
|
idx = idx[0]
|
||||||
|
new_obj = [LineObject, MultipointObject, TextObject, RectangleObject, EllipseObject][self.mode_comboBox.currentIndex()](**dic)
|
||||||
|
item = self.treeWidget.itemFromIndex(idx)
|
||||||
graph_id = item.data(0, QtCore.Qt.UserRole)
|
graph_id = item.data(0, QtCore.Qt.UserRole)
|
||||||
if self.mode_comboBox.currentIndex() == 0:
|
|
||||||
new_obj = LineObject(**dic)
|
|
||||||
elif self.mode_comboBox.currentIndex() == 1:
|
|
||||||
new_obj = MultipointObject(**dic)
|
|
||||||
elif self.mode_comboBox.currentIndex() == 3:
|
|
||||||
new_obj = RectangleObject(**dic)
|
|
||||||
child = QtWidgets.QTreeWidgetItem([str(new_obj)])
|
child = QtWidgets.QTreeWidgetItem([str(new_obj)])
|
||||||
child.setData(0, QtCore.Qt.UserRole, new_obj.id)
|
child.setData(0, QtCore.Qt.UserRole, new_obj.id)
|
||||||
|
|
||||||
item.addChild(child)
|
item.addChild(child)
|
||||||
|
|
||||||
self.graphs[graph_id].addDrawing(new_obj)
|
self.graphs[graph_id].addDrawing(new_obj)
|
||||||
else:
|
else:
|
||||||
QtWidgets.QMessageBox.information(self, 'Not working', 'No graph is selected to add this object.')
|
QtWidgets.QMessageBox.information(self, 'Not working', 'No graph is selected to add this object.')
|
||||||
|
|
||||||
self.treeWidget_2.expandAll()
|
self.treeWidget.expandAll()
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Form implementation generated from reading ui file 'src/resources/_ui/linedrawwidget.ui'
|
|
||||||
#
|
|
||||||
# Created by: PyQt5 UI code generator 5.15.7
|
|
||||||
#
|
|
||||||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
|
||||||
# run again. Do not edit this file unless you know what you are doing.
|
|
||||||
|
|
||||||
|
|
||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
||||||
|
|
||||||
|
|
||||||
class Ui_linewidget(object):
|
|
||||||
def setupUi(self, linewidget):
|
|
||||||
linewidget.setObjectName("linewidget")
|
|
||||||
linewidget.resize(400, 300)
|
|
||||||
self.gridLayout = QtWidgets.QGridLayout(linewidget)
|
|
||||||
self.gridLayout.setObjectName("gridLayout")
|
|
||||||
self.pos_lineedit = QtWidgets.QLineEdit(linewidget)
|
|
||||||
self.pos_lineedit.setObjectName("pos_lineedit")
|
|
||||||
self.gridLayout.addWidget(self.pos_lineedit, 1, 1, 1, 1)
|
|
||||||
self.orientation_label = QtWidgets.QLabel(linewidget)
|
|
||||||
self.orientation_label.setObjectName("orientation_label")
|
|
||||||
self.gridLayout.addWidget(self.orientation_label, 2, 0, 1, 1)
|
|
||||||
self.orient_combobox = QtWidgets.QComboBox(linewidget)
|
|
||||||
self.orient_combobox.setObjectName("orient_combobox")
|
|
||||||
self.orient_combobox.addItem("")
|
|
||||||
self.orient_combobox.addItem("")
|
|
||||||
self.gridLayout.addWidget(self.orient_combobox, 2, 1, 1, 1)
|
|
||||||
self.color_label = QtWidgets.QLabel(linewidget)
|
|
||||||
self.color_label.setObjectName("color_label")
|
|
||||||
self.gridLayout.addWidget(self.color_label, 0, 0, 1, 1)
|
|
||||||
self.pos_label = QtWidgets.QLabel(linewidget)
|
|
||||||
self.pos_label.setObjectName("pos_label")
|
|
||||||
self.gridLayout.addWidget(self.pos_label, 1, 0, 1, 1)
|
|
||||||
self.color_box = ColorListEditor(linewidget)
|
|
||||||
self.color_box.setObjectName("color_box")
|
|
||||||
self.gridLayout.addWidget(self.color_box, 0, 1, 1, 1)
|
|
||||||
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
|
||||||
self.gridLayout.addItem(spacerItem, 3, 1, 1, 1)
|
|
||||||
|
|
||||||
self.retranslateUi(linewidget)
|
|
||||||
QtCore.QMetaObject.connectSlotsByName(linewidget)
|
|
||||||
|
|
||||||
def retranslateUi(self, linewidget):
|
|
||||||
_translate = QtCore.QCoreApplication.translate
|
|
||||||
linewidget.setWindowTitle(_translate("linewidget", "Form"))
|
|
||||||
self.orientation_label.setText(_translate("linewidget", "Orientation"))
|
|
||||||
self.orient_combobox.setItemText(0, _translate("linewidget", "Horizontal"))
|
|
||||||
self.orient_combobox.setItemText(1, _translate("linewidget", "Vertical"))
|
|
||||||
self.color_label.setText(_translate("linewidget", "Color"))
|
|
||||||
self.pos_label.setText(_translate("linewidget", "Position"))
|
|
||||||
from gui_qt.lib,delegates import ColorListEditor
|
|
@ -27,7 +27,7 @@
|
|||||||
<number>3</number>
|
<number>3</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeWidget" name="treeWidget_2">
|
<widget class="QTreeWidget" name="treeWidget">
|
||||||
<property name="rootIsDecorated">
|
<property name="rootIsDecorated">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -47,14 +47,14 @@
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="newButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>New object</string>
|
<string>New object</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_2">
|
<widget class="QPushButton" name="editButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Edit</string>
|
<string>Edit</string>
|
||||||
</property>
|
</property>
|
||||||
@ -75,7 +75,7 @@
|
|||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_12">
|
<widget class="QLabel" name="type_label">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -127,9 +127,9 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QPushButton" name="pushButton_3">
|
<widget class="QPushButton" name="createButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Create</string>
|
<string>Apply</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -14,7 +14,52 @@
|
|||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="3" column="0">
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="color_label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Color</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLineEdit" name="left_x">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>x</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QLineEdit" name="left_y">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>y</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QLineEdit" name="right_x">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>x</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" colspan="2">
|
||||||
|
<widget class="ColorListEditor" name="color_box"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="left_label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Lower left</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="2">
|
||||||
|
<widget class="QLineEdit" name="right_y">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>y</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -27,57 +72,22 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="color_label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Color</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLineEdit" name="left_x">
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>x</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="2">
|
|
||||||
<widget class="QLineEdit" name="left_y">
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string>y</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="left_label">
|
|
||||||
<property name="text">
|
|
||||||
<string>Lower left</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" colspan="2">
|
|
||||||
<widget class="ColorListEditor" name="color_box"/>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="right_label">
|
<widget class="QLabel" name="right_label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Upper right</string>
|
<string>Upper right</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="1" column="0">
|
||||||
<widget class="QLineEdit" name="right_x">
|
<widget class="QLabel" name="fill_label">
|
||||||
<property name="placeholderText">
|
<property name="text">
|
||||||
<string>x</string>
|
<string>Fill color</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
<item row="1" column="1" colspan="2">
|
||||||
<widget class="QLineEdit" name="right_y">
|
<widget class="ColorListEditor" name="fill_box"/>
|
||||||
<property name="placeholderText">
|
|
||||||
<string>y</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
Loading…
Reference in New Issue
Block a user