diff --git a/src/gui_qt/_py/ellipsewidget.py b/src/gui_qt/_py/ellipsewidget.py new file mode 100644 index 0000000..b75a353 --- /dev/null +++ b/src/gui_qt/_py/ellipsewidget.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'src/resources/_ui/ellipsewidget.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_ellipsewidget(object): + def setupUi(self, ellipsewidget): + ellipsewidget.setObjectName("ellipsewidget") + ellipsewidget.resize(400, 300) + self.gridLayout = QtWidgets.QGridLayout(ellipsewidget) + 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(ellipsewidget) + self.color_label.setObjectName("color_label") + self.gridLayout.addWidget(self.color_label, 0, 0, 1, 1) + self.center_x = QtWidgets.QLineEdit(ellipsewidget) + self.center_x.setObjectName("center_x") + self.gridLayout.addWidget(self.center_x, 1, 1, 1, 1) + self.center_y = QtWidgets.QLineEdit(ellipsewidget) + self.center_y.setObjectName("center_y") + self.gridLayout.addWidget(self.center_y, 1, 2, 1, 1) + self.label = QtWidgets.QLabel(ellipsewidget) + self.label.setObjectName("label") + self.gridLayout.addWidget(self.label, 1, 0, 1, 1) + self.color_box = ColorListEditor(ellipsewidget) + self.color_box.setObjectName("color_box") + self.gridLayout.addWidget(self.color_box, 0, 1, 1, 2) + self.axes_label = QtWidgets.QLabel(ellipsewidget) + self.axes_label.setObjectName("axes_label") + self.gridLayout.addWidget(self.axes_label, 2, 0, 1, 1) + self.width_line = QtWidgets.QLineEdit(ellipsewidget) + self.width_line.setObjectName("width_line") + self.gridLayout.addWidget(self.width_line, 2, 1, 1, 1) + self.height_line = QtWidgets.QLineEdit(ellipsewidget) + self.height_line.setObjectName("height_line") + self.gridLayout.addWidget(self.height_line, 2, 2, 1, 1) + + self.retranslateUi(ellipsewidget) + QtCore.QMetaObject.connectSlotsByName(ellipsewidget) + + def retranslateUi(self, ellipsewidget): + _translate = QtCore.QCoreApplication.translate + ellipsewidget.setWindowTitle(_translate("ellipsewidget", "Form")) + self.color_label.setText(_translate("ellipsewidget", "Color")) + self.center_x.setPlaceholderText(_translate("ellipsewidget", "x")) + self.center_y.setPlaceholderText(_translate("ellipsewidget", "y")) + self.label.setText(_translate("ellipsewidget", "Center")) + self.axes_label.setText(_translate("ellipsewidget", "Axes")) + self.width_line.setPlaceholderText(_translate("ellipsewidget", "axis 1")) + self.height_line.setPlaceholderText(_translate("ellipsewidget", "axis 2")) +from gui_qt.lib.delegates import ColorListEditor diff --git a/src/gui_qt/_py/linedrawwidget.py b/src/gui_qt/_py/linedrawwidget.py new file mode 100644 index 0000000..122bd50 --- /dev/null +++ b/src/gui_qt/_py/linedrawwidget.py @@ -0,0 +1,54 @@ +# -*- 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 diff --git a/src/gui_qt/_py/multipointwidget.py b/src/gui_qt/_py/multipointwidget.py new file mode 100644 index 0000000..e063b23 --- /dev/null +++ b/src/gui_qt/_py/multipointwidget.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'src/resources/_ui/multipointwidget.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_multipointwidget(object): + def setupUi(self, multipointwidget): + multipointwidget.setObjectName("multipointwidget") + multipointwidget.resize(400, 300) + self.gridLayout = QtWidgets.QGridLayout(multipointwidget) + self.gridLayout.setObjectName("gridLayout") + self.loop_checkbox = QtWidgets.QCheckBox(multipointwidget) + self.loop_checkbox.setObjectName("loop_checkbox") + self.gridLayout.addWidget(self.loop_checkbox, 1, 0, 1, 2) + self.addButton = QtWidgets.QPushButton(multipointwidget) + self.addButton.setObjectName("addButton") + self.gridLayout.addWidget(self.addButton, 3, 0, 1, 1) + self.color_label = QtWidgets.QLabel(multipointwidget) + self.color_label.setObjectName("color_label") + self.gridLayout.addWidget(self.color_label, 0, 0, 1, 1) + self.table_widget = QtWidgets.QTableWidget(multipointwidget) + self.table_widget.setObjectName("table_widget") + self.table_widget.setColumnCount(2) + self.table_widget.setRowCount(0) + item = QtWidgets.QTableWidgetItem() + self.table_widget.setHorizontalHeaderItem(0, item) + item = QtWidgets.QTableWidgetItem() + self.table_widget.setHorizontalHeaderItem(1, item) + self.table_widget.horizontalHeader().setStretchLastSection(True) + self.gridLayout.addWidget(self.table_widget, 2, 0, 1, 2) + self.color_box = ColorListEditor(multipointwidget) + 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, 4, 0, 1, 1) + self.removeButton = QtWidgets.QPushButton(multipointwidget) + self.removeButton.setObjectName("removeButton") + self.gridLayout.addWidget(self.removeButton, 3, 1, 1, 1) + + self.retranslateUi(multipointwidget) + QtCore.QMetaObject.connectSlotsByName(multipointwidget) + + def retranslateUi(self, multipointwidget): + _translate = QtCore.QCoreApplication.translate + multipointwidget.setWindowTitle(_translate("multipointwidget", "Form")) + self.loop_checkbox.setText(_translate("multipointwidget", "Close loop")) + self.addButton.setText(_translate("multipointwidget", "Add point")) + self.color_label.setText(_translate("multipointwidget", "Color")) + item = self.table_widget.horizontalHeaderItem(0) + item.setText(_translate("multipointwidget", "x")) + item = self.table_widget.horizontalHeaderItem(1) + item.setText(_translate("multipointwidget", "y")) + self.removeButton.setText(_translate("multipointwidget", "Remove last point")) +from gui_qt.lib.delegates import ColorListEditor diff --git a/src/gui_qt/_py/rectanglewidget.py b/src/gui_qt/_py/rectanglewidget.py new file mode 100644 index 0000000..e0ee4a8 --- /dev/null +++ b/src/gui_qt/_py/rectanglewidget.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'src/resources/_ui/rectanglewidget.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_rectanglewidget(object): + def setupUi(self, rectanglewidget): + rectanglewidget.setObjectName("rectanglewidget") + rectanglewidget.resize(400, 300) + self.gridLayout = QtWidgets.QGridLayout(rectanglewidget) + 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.setObjectName("color_label") + self.gridLayout.addWidget(self.color_label, 0, 0, 1, 1) + self.left_x = QtWidgets.QLineEdit(rectanglewidget) + self.left_x.setObjectName("left_x") + self.gridLayout.addWidget(self.left_x, 1, 1, 1, 1) + self.left_y = QtWidgets.QLineEdit(rectanglewidget) + self.left_y.setObjectName("left_y") + self.gridLayout.addWidget(self.left_y, 1, 2, 1, 1) + self.left_label = QtWidgets.QLabel(rectanglewidget) + self.left_label.setObjectName("left_label") + self.gridLayout.addWidget(self.left_label, 1, 0, 1, 1) + self.color_box = ColorListEditor(rectanglewidget) + self.color_box.setObjectName("color_box") + self.gridLayout.addWidget(self.color_box, 0, 1, 1, 2) + self.right_label = QtWidgets.QLabel(rectanglewidget) + self.right_label.setObjectName("right_label") + self.gridLayout.addWidget(self.right_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.setObjectName("right_y") + self.gridLayout.addWidget(self.right_y, 2, 2, 1, 1) + + self.retranslateUi(rectanglewidget) + QtCore.QMetaObject.connectSlotsByName(rectanglewidget) + + def retranslateUi(self, rectanglewidget): + _translate = QtCore.QCoreApplication.translate + rectanglewidget.setWindowTitle(_translate("rectanglewidget", "Form")) + self.color_label.setText(_translate("rectanglewidget", "Color")) + self.left_x.setPlaceholderText(_translate("rectanglewidget", "x")) + 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_y.setPlaceholderText(_translate("rectanglewidget", "y")) +from gui_qt.lib.delegates import ColorListEditor diff --git a/src/gui_qt/_py/textdrawidget.py b/src/gui_qt/_py/textdrawidget.py new file mode 100644 index 0000000..eb44823 --- /dev/null +++ b/src/gui_qt/_py/textdrawidget.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'src/resources/_ui/textdrawidget.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_textwidget(object): + def setupUi(self, textwidget): + textwidget.setObjectName("textwidget") + textwidget.resize(400, 300) + self.gridLayout = QtWidgets.QGridLayout(textwidget) + 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(textwidget) + self.color_label.setObjectName("color_label") + self.gridLayout.addWidget(self.color_label, 0, 0, 1, 1) + self.center_x = QtWidgets.QLineEdit(textwidget) + self.center_x.setObjectName("center_x") + self.gridLayout.addWidget(self.center_x, 1, 1, 1, 1) + self.center_y = QtWidgets.QLineEdit(textwidget) + self.center_y.setObjectName("center_y") + self.gridLayout.addWidget(self.center_y, 1, 2, 1, 1) + self.center_label = QtWidgets.QLabel(textwidget) + self.center_label.setObjectName("center_label") + self.gridLayout.addWidget(self.center_label, 1, 0, 1, 1) + self.color_box = ColorListEditor(textwidget) + self.color_box.setObjectName("color_box") + self.gridLayout.addWidget(self.color_box, 0, 1, 1, 2) + self.text_label = QtWidgets.QLabel(textwidget) + self.text_label.setObjectName("text_label") + self.gridLayout.addWidget(self.text_label, 2, 0, 1, 1) + self.text_lineedit = QtWidgets.QLineEdit(textwidget) + self.text_lineedit.setObjectName("text_lineedit") + self.gridLayout.addWidget(self.text_lineedit, 2, 1, 1, 2) + + self.retranslateUi(textwidget) + QtCore.QMetaObject.connectSlotsByName(textwidget) + + def retranslateUi(self, textwidget): + _translate = QtCore.QCoreApplication.translate + textwidget.setWindowTitle(_translate("textwidget", "Form")) + self.color_label.setText(_translate("textwidget", "Color")) + self.center_x.setPlaceholderText(_translate("textwidget", "x")) + self.center_y.setPlaceholderText(_translate("textwidget", "y")) + self.center_label.setText(_translate("textwidget", "Center")) + self.text_label.setText(_translate("textwidget", "Text")) +from gui_qt.lib.delegates import ColorListEditor diff --git a/src/gui_qt/graphs/draw_inputs.py b/src/gui_qt/graphs/draw_inputs.py index 98e8ca5..9cff13d 100644 --- a/src/gui_qt/graphs/draw_inputs.py +++ b/src/gui_qt/graphs/draw_inputs.py @@ -2,96 +2,59 @@ from __future__ import annotations from PyQt5 import QtCore, QtGui, QtWidgets -from gui_qt.lib.delegates import ColorListEditor +from .._py.ellipsewidget import Ui_ellipsewidget +from .._py.linedrawwidget import Ui_linewidget +from .._py.rectanglewidget import Ui_rectanglewidget -class ObjectWidget(QtWidgets.QWidget): +__all__ = ['LineWidget', 'MultiPointWidget', 'RectangleWidget', 'EllipseWidget', 'TextWidget'] + +from .._py.multipointwidget import Ui_multipointwidget +from .._py.textdrawidget import Ui_textwidget + + +def parse_point(x_widget: QtWidgets.QLineEdit, y_widget: QtWidgets.QLineEdit) -> None | tuple[float, float]: + x = x_widget.text() + if not x: + return + y = y_widget.text() + if not y: + return + + try: + return float(x), float(y) + except ValueError: + return + + +class LineWidget(QtWidgets.QWidget, Ui_linewidget): def __init__(self, parent=None): super().__init__(parent=parent) + self.setupUi(self) - self.layout = QtWidgets.QGridLayout() - self.layout.setContentsMargins(3, 3, 3, 3) - - self.color_label = QtWidgets.QLabel('Color') - self.layout.addWidget(self.color_label, 0, 0, 1, 1) - self.color_box = ColorListEditor(self) - self.layout.addWidget(self.color_box, 0, 1, 1, 2) - self.setLayout(self.layout) - - def collect_args(self) -> dict: - return {'color': self.color_box.currentData(QtCore.Qt.UserRole)} - - @staticmethod - def parse_point(x_widget: QtWidgets.QLineEdit, y_widget: QtWidgets.QLineEdit) -> None | tuple[float, float]: - x = x_widget.text() - if not x: - return - y = y_widget.text() - if not y: - return - - try: - return float(x), float(y) - except ValueError: - return - - -class LineWidget(ObjectWidget): - def __init__(self, parent=None): - super().__init__(parent=parent) - - self.pos_label = QtWidgets.QLabel('Position') - self.layout.addWidget(self.pos_label, 1, 0, 1, 1) - self.pos_lineedit = QtWidgets.QLineEdit() self.pos_lineedit.setValidator(QtGui.QDoubleValidator()) - self.layout.addWidget(self.pos_lineedit, 1, 1, 1, 2) - self.orientation_label = QtWidgets.QLabel('Orientation') - self.layout.addWidget(self.orientation_label, 2, 0, 1, 1) - self.orient_combobox = QtWidgets.QComboBox() - self.orient_combobox.addItems(['Horizontal', 'Vertical']) - self.layout.addWidget(self.orient_combobox, 2, 1, 1, 2) - self.layout.setRowStretch(3, 1) def collect_args(self): - dic = super().collect_args() pos = self.pos_lineedit.text() - if not pos: - return - try: - dic['pos'] = float(pos) + pos = float(pos) except ValueError: return - dic['angle'] = self.orient_combobox.currentIndex() * 90 + dic = { + 'color': self.color_box.currentData(), + 'pos': pos, + 'angle': self.orient_combobox.currentIndex() * 90 + } return dic -class MultiPointWidget(ObjectWidget): +class MultiPointWidget(QtWidgets.QWidget, Ui_multipointwidget): def __init__(self, parent=None): super().__init__(parent=parent) - - self.loop_checkbox = QtWidgets.QCheckBox('Close loop') - self.layout.addWidget(self.loop_checkbox, 1, 0, 1, 3) - - self.table_widget = QtWidgets.QTableWidget() - self.table_widget.setColumnCount(2) - self.table_widget.setHorizontalHeaderLabels(['x', 'y']) - header = self.table_widget.horizontalHeader() - header.setStretchLastSection(True) - self.layout.addWidget(self.table_widget, 2, 0, 1, 3) - - self.addButton = QtWidgets.QPushButton('Add point') - self.layout.addWidget(self.addButton, 3, 1, 1, 1) - self.layout.setRowStretch(3, 1) - self.addButton.clicked.connect(self.new_point) - - self.removeButton = QtWidgets.QPushButton('Remove point') - self.layout.addWidget(self.removeButton, 3, 2, 1, 1) - self.layout.setRowStretch(3, 1) - self.removeButton.clicked.connect(self.less_point) + self.setupUi(self) def new_point(self, _): row = self.table_widget.rowCount() @@ -129,33 +92,15 @@ class MultiPointWidget(ObjectWidget): return -class RectangleWidget(ObjectWidget): +class RectangleWidget(QtWidgets.QWidget, Ui_rectanglewidget): def __init__(self, parent=None): super().__init__(parent=parent) + self.setupUi(self) - self.leftbottom_label = QtWidgets.QLabel('Lower left') - self.layout.addWidget(self.leftbottom_label, 1, 0, 1, 1) - self.left_x = QtWidgets.QLineEdit() - self.left_x.setPlaceholderText('x') - self.layout.addWidget(self.left_x, 1, 1, 1, 1) - self.left_y = QtWidgets.QLineEdit() - self.left_y.setPlaceholderText('y') self.left_x.setValidator(QtGui.QDoubleValidator()) self.left_y.setValidator(QtGui.QDoubleValidator()) - self.layout.addWidget(self.left_y, 1, 2, 1, 1) - - self.righttop_label = QtWidgets.QLabel('Upper right') - self.layout.addWidget(self.righttop_label, 2, 0, 1, 1) - self.right_x = QtWidgets.QLineEdit() - self.right_x.setPlaceholderText('x') - self.layout.addWidget(self.right_x, 2, 1, 1, 1) - self.right_y = QtWidgets.QLineEdit() - self.right_y.setPlaceholderText('y') self.right_x.setValidator(QtGui.QDoubleValidator()) self.right_y.setValidator(QtGui.QDoubleValidator()) - self.layout.addWidget(self.right_y, 2, 2, 1, 1) - - self.layout.setRowStretch(3, 1) def collect_args(self): dic = super().collect_args() @@ -172,42 +117,24 @@ class RectangleWidget(ObjectWidget): return dic -class EllipseWidget(ObjectWidget): +class EllipseWidget(QtWidgets.QWidget, Ui_ellipsewidget): def __init__(self, parent=None): super().__init__(parent=parent) + self.setupUi(self) - self.centre_label = QtWidgets.QLabel('Centre') - self.layout.addWidget(self.centre_label, 1, 0, 1, 1) - self.centre_x = QtWidgets.QLineEdit() - self.centre_x.setPlaceholderText('x') - self.layout.addWidget(self.centre_x, 1, 1, 1, 1) - self.centre_y = QtWidgets.QLineEdit() - self.centre_y.setPlaceholderText('y') - self.centre_x.setValidator(QtGui.QDoubleValidator()) - self.centre_y.setValidator(QtGui.QDoubleValidator()) - self.layout.addWidget(self.centre_y, 1, 2, 1, 1) - - self.axes_label = QtWidgets.QLabel('Axes') - self.layout.addWidget(self.axes_label, 2, 0, 1, 1) - self.width = QtWidgets.QLineEdit() - self.width.setPlaceholderText('width') - self.layout.addWidget(self.width, 2, 1, 1, 1) - self.height = QtWidgets.QLineEdit() - self.height.setPlaceholderText('Height') - self.width.setValidator(QtGui.QDoubleValidator()) - self.width.setValidator(QtGui.QDoubleValidator()) - self.layout.addWidget(self.height, 2, 2, 1, 1) - - self.layout.setRowStretch(3, 1) + self.center_x.setValidator(QtGui.QDoubleValidator()) + self.center_y.setValidator(QtGui.QDoubleValidator()) + self.width_line.setValidator(QtGui.QDoubleValidator()) + self.height_line.setValidator(QtGui.QDoubleValidator()) def collect_args(self): dic = super().collect_args() - centre = self.parse_point(self.centre_x, self.centre_y) + centre = self.parse_point(self.center_x, self.center_y) if centre is None: return dic['centre'] = centre - axes = self.parse_point(self.width, self.height) + axes = self.parse_point(self.width_line, self.height_line) if axes is None: return dic['axes'] = axes @@ -215,31 +142,17 @@ class EllipseWidget(ObjectWidget): return dic -class TextWidget(ObjectWidget): +class TextWidget(QtWidgets.QWidget, Ui_textwidget): def __init__(self, parent=None): super().__init__(parent=parent) + self.setupUi(self) - self.centre_label = QtWidgets.QLabel('Centre') - self.layout.addWidget(self.centre_label, 1, 0, 1, 1) - self.centre_x = QtWidgets.QLineEdit() - self.centre_x.setPlaceholderText('x') - self.layout.addWidget(self.centre_x, 1, 1, 1, 1) - self.centre_y = QtWidgets.QLineEdit() - self.centre_y.setPlaceholderText('y') - self.centre_x.setValidator(QtGui.QDoubleValidator()) - self.centre_y.setValidator(QtGui.QDoubleValidator()) - self.layout.addWidget(self.centre_y, 1, 2, 1, 1) - - self.text_label = QtWidgets.QLabel('Text') - self.layout.addWidget(self.text_label, 2, 0, 1, 1) - self.text_lineedit =QtWidgets.QLineEdit() - self.layout.addWidget(self.text_lineedit, 2, 1, 1, 2) - - self.layout.setRowStretch(3, 1) + self.center_x.setValidator(QtGui.QDoubleValidator()) + self.center_y.setValidator(QtGui.QDoubleValidator()) def collect_args(self): dic = super().collect_args() - centre = self.parse_point(self.centre_x, self.centre_y) + centre = self.parse_point(self.center_x, self.center_y) if centre is None: return dic['centre'] = centre diff --git a/src/gui_qt/graphs/draw_objects.py b/src/gui_qt/graphs/draw_objects.py index 528ed1e..bf8b0eb 100644 --- a/src/gui_qt/graphs/draw_objects.py +++ b/src/gui_qt/graphs/draw_objects.py @@ -2,18 +2,33 @@ from __future__ import annotations import uuid -from pyqtgraph import mkPen +from pyqtgraph import mkPen, GraphicsObject, mkBrush +from numpy import log10 +from gui_qt.Qt import QtCore, QtGui from gui_qt.lib.pg_objects import LogInfiniteLine, PlotItem -class LineObject: - def __init__(self, **kwargs): - self.id = str(uuid.uuid4()) +__all__ = ['LineObject', 'MultipointObject', 'RectangleObject'] - self.pos = kwargs['pos'] - self.angle = kwargs['angle'] - self.color = kwargs['color'] + +class BaseObject: + def __init__(self, color=None): + self.id = str(uuid.uuid4()) + self.color = color + + self.drawing = None + + def __str__(self): + raise NotImplementedError + + +class LineObject(BaseObject): + def __init__(self, pos: float, angle: float, **kwargs): + super().__init__(**kwargs) + + self.pos = pos + self.angle = angle self.drawing = LogInfiniteLine(pos=self.pos, angle=self.angle, pen=mkPen(color=self.color.rgb())) @@ -21,13 +36,11 @@ class LineObject: return f'{"x" if self.angle==90 else "y"}={self.pos}' -class MultipointObject: - def __init__(self, **kwargs): - self.id = str(uuid.uuid4()) - - self.color = kwargs['color'] - x, y = zip(*kwargs['pts']) - self.closed = kwargs['closed'] +class MultipointObject(BaseObject): + def __init__(self, pts: list, closed: bool = False, **kwargs): + super().__init__(**kwargs) + x, y = zip(*pts) + self.closed = closed if self.closed: x += (x[0],) @@ -39,3 +52,59 @@ class MultipointObject: def __str__(self): return f'{len(self._y)-int(self.closed)}-pts' + + +class RectangleObject(GraphicsObject, BaseObject): + def __init__(self, left: tuple, right: tuple, **kwargs): + GraphicsObject.__init__(self) + BaseObject.__init__(self, **kwargs) + + self.p0 = left + self.delta = [right[0]-self.p0[0], right[1]-self.p0[1]] + self.log_mode = [False, False] + self.generatePicture() + + def __str__(self): + return 'rectangle' + + 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.drawRect(QtCore.QRectF(*self.p0, *self.delta)) + 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: + xmax = log10(self.p0[0]+self.delta[0]) + self.x_disp = log10(self.p0[0]) + self.dx = xmax - self.x0 + else: + self.x_disp = self.p0[0] + self.dx = self.delta[0] + if args[1] and self.log_mode[1] != args[1]: + ymax = log10(self.y0 + self.dy) + self.y0 = log10(self.y0) + self.dy = ymax - self.y0 + + self.generatePicture() + + self.log_mode = [x_mode, y_mode] + + self.informViewBoundsChanged() diff --git a/src/gui_qt/graphs/drawings.py b/src/gui_qt/graphs/drawings.py index 000e777..b9219c2 100644 --- a/src/gui_qt/graphs/drawings.py +++ b/src/gui_qt/graphs/drawings.py @@ -1,9 +1,9 @@ from __future__ import annotations -from gui_qt.Qt import QtWidgets, QtCore -from gui_qt._py.guidelinewidget import Ui_Form -from gui_qt.graphs.draw_inputs import EllipseWidget, LineWidget, MultiPointWidget, RectangleWidget, TextWidget -from gui_qt.graphs.draw_objects import LineObject, MultipointObject +from ..Qt import QtWidgets, QtCore +from .._py.guidelinewidget import Ui_Form +from .draw_inputs import * +from .draw_objects import * class DrawingsWidget(QtWidgets.QWidget, Ui_Form): @@ -44,6 +44,7 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form): if dic is None: QtWidgets.QMessageBox.information(self, 'Not working', 'Something is missing to create this object') return + idx = self.treeWidget_2.selectedIndexes() if idx: item = self.treeWidget_2.itemFromIndex(idx[0]) @@ -52,6 +53,8 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form): 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.setData(0, QtCore.Qt.UserRole, new_obj.id) item.addChild(child) @@ -61,10 +64,3 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form): QtWidgets.QMessageBox.information(self, 'Not working', 'No graph is selected to add this object.') self.treeWidget_2.expandAll() - - -if __name__ == '__main__': - app = QtWidgets.QApplication([]) - w = DrawingsWidget() - w.show() - app.exec() diff --git a/src/gui_qt/graphs/objects.py b/src/gui_qt/graphs/objects.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/gui_qt/linedrawwidget.py b/src/gui_qt/linedrawwidget.py new file mode 100644 index 0000000..4a0fcc8 --- /dev/null +++ b/src/gui_qt/linedrawwidget.py @@ -0,0 +1,54 @@ +# -*- 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 diff --git a/src/resources/_ui/ellipsewidget.ui b/src/resources/_ui/ellipsewidget.ui new file mode 100644 index 0000000..595083f --- /dev/null +++ b/src/resources/_ui/ellipsewidget.ui @@ -0,0 +1,93 @@ + + + ellipsewidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Color + + + + + + + x + + + + + + + y + + + + + + + Center + + + + + + + + + + Axes + + + + + + + axis 1 + + + + + + + axis 2 + + + + + + + + ColorListEditor + QComboBox +
gui_qt.lib.delegates
+
+
+ + +
diff --git a/src/resources/_ui/linedrawwidget.ui b/src/resources/_ui/linedrawwidget.ui new file mode 100644 index 0000000..56a03bf --- /dev/null +++ b/src/resources/_ui/linedrawwidget.ui @@ -0,0 +1,82 @@ + + + linewidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + Orientation + + + + + + + + Horizontal + + + + + Vertical + + + + + + + + Color + + + + + + + Position + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + ColorListEditor + QComboBox +
gui_qt.lib.delegates
+
+
+ + +
diff --git a/src/resources/_ui/multipointwidget.ui b/src/resources/_ui/multipointwidget.ui new file mode 100644 index 0000000..0971eef --- /dev/null +++ b/src/resources/_ui/multipointwidget.ui @@ -0,0 +1,89 @@ + + + multipointwidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Close loop + + + + + + + Add point + + + + + + + Color + + + + + + + true + + + + x + + + + + y + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Remove last point + + + + + + + + ColorListEditor + QComboBox +
gui_qt.lib.delegates
+
+
+ + +
diff --git a/src/resources/_ui/rectanglewidget.ui b/src/resources/_ui/rectanglewidget.ui new file mode 100644 index 0000000..0b78a65 --- /dev/null +++ b/src/resources/_ui/rectanglewidget.ui @@ -0,0 +1,93 @@ + + + rectanglewidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Color + + + + + + + x + + + + + + + y + + + + + + + Lower left + + + + + + + + + + Upper right + + + + + + + x + + + + + + + y + + + + + + + + ColorListEditor + QComboBox +
gui_qt.lib.delegates
+
+
+ + +
diff --git a/src/resources/_ui/textdrawidget.ui b/src/resources/_ui/textdrawidget.ui new file mode 100644 index 0000000..302adf2 --- /dev/null +++ b/src/resources/_ui/textdrawidget.ui @@ -0,0 +1,82 @@ + + + textwidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Color + + + + + + + x + + + + + + + y + + + + + + + Center + + + + + + + + + + Text + + + + + + + + + + + ColorListEditor + QComboBox +
gui_qt.lib.delegates
+
+
+ + +