outsource ui creation

This commit is contained in:
Dominik Demuth 2023-02-04 19:19:15 +01:00
parent 67332cc9b9
commit 72d2fc5018
15 changed files with 922 additions and 160 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -2,26 +2,17 @@ from __future__ import annotations
from PyQt5 import QtCore, QtGui, QtWidgets 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']
def __init__(self, parent=None):
super().__init__(parent=parent)
self.layout = QtWidgets.QGridLayout() from .._py.multipointwidget import Ui_multipointwidget
self.layout.setContentsMargins(3, 3, 3, 3) from .._py.textdrawidget import Ui_textwidget
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]: def parse_point(x_widget: QtWidgets.QLineEdit, y_widget: QtWidgets.QLineEdit) -> None | tuple[float, float]:
x = x_widget.text() x = x_widget.text()
if not x: if not x:
@ -36,62 +27,34 @@ class ObjectWidget(QtWidgets.QWidget):
return return
class LineWidget(ObjectWidget): class LineWidget(QtWidgets.QWidget, Ui_linewidget):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
self.setupUi(self)
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.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): def collect_args(self):
dic = super().collect_args()
pos = self.pos_lineedit.text() pos = self.pos_lineedit.text()
if not pos:
return
try: try:
dic['pos'] = float(pos) pos = float(pos)
except ValueError: except ValueError:
return return
dic['angle'] = self.orient_combobox.currentIndex() * 90 dic = {
'color': self.color_box.currentData(),
'pos': pos,
'angle': self.orient_combobox.currentIndex() * 90
}
return dic return dic
class MultiPointWidget(ObjectWidget): class MultiPointWidget(QtWidgets.QWidget, Ui_multipointwidget):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
self.setupUi(self)
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)
def new_point(self, _): def new_point(self, _):
row = self.table_widget.rowCount() row = self.table_widget.rowCount()
@ -129,33 +92,15 @@ class MultiPointWidget(ObjectWidget):
return return
class RectangleWidget(ObjectWidget): class RectangleWidget(QtWidgets.QWidget, Ui_rectanglewidget):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent=parent) 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_x.setValidator(QtGui.QDoubleValidator())
self.left_y.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_x.setValidator(QtGui.QDoubleValidator())
self.right_y.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): def collect_args(self):
dic = super().collect_args() dic = super().collect_args()
@ -172,42 +117,24 @@ class RectangleWidget(ObjectWidget):
return dic return dic
class EllipseWidget(ObjectWidget): class EllipseWidget(QtWidgets.QWidget, Ui_ellipsewidget):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
self.setupUi(self)
self.centre_label = QtWidgets.QLabel('Centre') self.center_x.setValidator(QtGui.QDoubleValidator())
self.layout.addWidget(self.centre_label, 1, 0, 1, 1) self.center_y.setValidator(QtGui.QDoubleValidator())
self.centre_x = QtWidgets.QLineEdit() self.width_line.setValidator(QtGui.QDoubleValidator())
self.centre_x.setPlaceholderText('x') self.height_line.setValidator(QtGui.QDoubleValidator())
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)
def collect_args(self): def collect_args(self):
dic = super().collect_args() 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: if centre is None:
return return
dic['centre'] = centre 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: if axes is None:
return return
dic['axes'] = axes dic['axes'] = axes
@ -215,31 +142,17 @@ class EllipseWidget(ObjectWidget):
return dic return dic
class TextWidget(ObjectWidget): class TextWidget(QtWidgets.QWidget, Ui_textwidget):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
self.setupUi(self)
self.centre_label = QtWidgets.QLabel('Centre') self.center_x.setValidator(QtGui.QDoubleValidator())
self.layout.addWidget(self.centre_label, 1, 0, 1, 1) self.center_y.setValidator(QtGui.QDoubleValidator())
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)
def collect_args(self): def collect_args(self):
dic = super().collect_args() 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: if centre is None:
return return
dic['centre'] = centre dic['centre'] = centre

View File

@ -2,18 +2,33 @@ from __future__ import annotations
import uuid 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 from gui_qt.lib.pg_objects import LogInfiniteLine, PlotItem
class LineObject: __all__ = ['LineObject', 'MultipointObject', 'RectangleObject']
def __init__(self, **kwargs):
self.id = str(uuid.uuid4())
self.pos = kwargs['pos']
self.angle = kwargs['angle'] class BaseObject:
self.color = kwargs['color'] 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())) 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}' return f'{"x" if self.angle==90 else "y"}={self.pos}'
class MultipointObject: class MultipointObject(BaseObject):
def __init__(self, **kwargs): def __init__(self, pts: list, closed: bool = False, **kwargs):
self.id = str(uuid.uuid4()) super().__init__(**kwargs)
x, y = zip(*pts)
self.color = kwargs['color'] self.closed = closed
x, y = zip(*kwargs['pts'])
self.closed = kwargs['closed']
if self.closed: if self.closed:
x += (x[0],) x += (x[0],)
@ -39,3 +52,59 @@ class MultipointObject:
def __str__(self): def __str__(self):
return f'{len(self._y)-int(self.closed)}-pts' 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()

View File

@ -1,9 +1,9 @@
from __future__ import annotations from __future__ import annotations
from gui_qt.Qt import QtWidgets, QtCore from ..Qt import QtWidgets, QtCore
from gui_qt._py.guidelinewidget import Ui_Form from .._py.guidelinewidget import Ui_Form
from gui_qt.graphs.draw_inputs import EllipseWidget, LineWidget, MultiPointWidget, RectangleWidget, TextWidget from .draw_inputs import *
from gui_qt.graphs.draw_objects import LineObject, MultipointObject from .draw_objects import *
class DrawingsWidget(QtWidgets.QWidget, Ui_Form): class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
@ -44,6 +44,7 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
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_2.selectedIndexes()
if idx: if idx:
item = self.treeWidget_2.itemFromIndex(idx[0]) item = self.treeWidget_2.itemFromIndex(idx[0])
@ -52,6 +53,8 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
new_obj = LineObject(**dic) new_obj = LineObject(**dic)
elif self.mode_comboBox.currentIndex() == 1: elif self.mode_comboBox.currentIndex() == 1:
new_obj = MultipointObject(**dic) 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)
@ -61,10 +64,3 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
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_2.expandAll()
if __name__ == '__main__':
app = QtWidgets.QApplication([])
w = DrawingsWidget()
w.show()
app.exec()

View File

@ -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

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ellipsewidget</class>
<widget class="QWidget" name="ellipsewidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" 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="center_x">
<property name="placeholderText">
<string>x</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="center_y">
<property name="placeholderText">
<string>y</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Center</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="axes_label">
<property name="text">
<string>Axes</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="width_line">
<property name="placeholderText">
<string>axis 1</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="height_line">
<property name="placeholderText">
<string>axis 2</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ColorListEditor</class>
<extends>QComboBox</extends>
<header>gui_qt.lib.delegates</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>linewidget</class>
<widget class="QWidget" name="linewidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QLineEdit" name="pos_lineedit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="orientation_label">
<property name="text">
<string>Orientation</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="orient_combobox">
<item>
<property name="text">
<string>Horizontal</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="color_label">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="pos_label">
<property name="text">
<string>Position</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="ColorListEditor" name="color_box"/>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ColorListEditor</class>
<extends>QComboBox</extends>
<header>gui_qt.lib.delegates</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>multipointwidget</class>
<widget class="QWidget" name="multipointwidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="loop_checkbox">
<property name="text">
<string>Close loop</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add point</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="color_label">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QTableWidget" name="table_widget">
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>x</string>
</property>
</column>
<column>
<property name="text">
<string>y</string>
</property>
</column>
</widget>
</item>
<item row="0" column="1">
<widget class="ColorListEditor" name="color_box"/>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>Remove last point</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ColorListEditor</class>
<extends>QComboBox</extends>
<header>gui_qt.lib.delegates</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>rectanglewidget</class>
<widget class="QWidget" name="rectanglewidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" 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">
<property name="text">
<string>Upper right</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="right_x">
<property name="placeholderText">
<string>x</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="right_y">
<property name="placeholderText">
<string>y</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ColorListEditor</class>
<extends>QComboBox</extends>
<header>gui_qt.lib.delegates</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>textwidget</class>
<widget class="QWidget" name="textwidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" 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="center_x">
<property name="placeholderText">
<string>x</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="center_y">
<property name="placeholderText">
<string>y</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="center_label">
<property name="text">
<string>Center</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="text_label">
<property name="text">
<string>Text</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="text_lineedit"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ColorListEditor</class>
<extends>QComboBox</extends>
<header>gui_qt.lib.delegates</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>