forked from IPKM/nmreval
ellipses done
This commit is contained in:
parent
3ddc81dbfa
commit
2d42a8cd46
@ -17,32 +17,38 @@ class Ui_ellipsewidget(object):
|
|||||||
ellipsewidget.resize(400, 300)
|
ellipsewidget.resize(400, 300)
|
||||||
self.gridLayout = QtWidgets.QGridLayout(ellipsewidget)
|
self.gridLayout = QtWidgets.QGridLayout(ellipsewidget)
|
||||||
self.gridLayout.setObjectName("gridLayout")
|
self.gridLayout.setObjectName("gridLayout")
|
||||||
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
self.height_line = QtWidgets.QLineEdit(ellipsewidget)
|
||||||
self.gridLayout.addItem(spacerItem, 3, 0, 1, 1)
|
self.height_line.setObjectName("height_line")
|
||||||
|
self.gridLayout.addWidget(self.height_line, 3, 2, 1, 1)
|
||||||
|
self.center_x = QtWidgets.QLineEdit(ellipsewidget)
|
||||||
|
self.center_x.setObjectName("center_x")
|
||||||
|
self.gridLayout.addWidget(self.center_x, 2, 1, 1, 1)
|
||||||
|
self.axes_label = QtWidgets.QLabel(ellipsewidget)
|
||||||
|
self.axes_label.setObjectName("axes_label")
|
||||||
|
self.gridLayout.addWidget(self.axes_label, 3, 0, 1, 1)
|
||||||
self.color_label = QtWidgets.QLabel(ellipsewidget)
|
self.color_label = QtWidgets.QLabel(ellipsewidget)
|
||||||
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.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 = QtWidgets.QLineEdit(ellipsewidget)
|
||||||
self.center_y.setObjectName("center_y")
|
self.center_y.setObjectName("center_y")
|
||||||
self.gridLayout.addWidget(self.center_y, 1, 2, 1, 1)
|
self.gridLayout.addWidget(self.center_y, 2, 2, 1, 1)
|
||||||
self.label = QtWidgets.QLabel(ellipsewidget)
|
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
||||||
self.label.setObjectName("label")
|
self.gridLayout.addItem(spacerItem, 4, 0, 1, 1)
|
||||||
self.gridLayout.addWidget(self.label, 1, 0, 1, 1)
|
self.center_label = QtWidgets.QLabel(ellipsewidget)
|
||||||
|
self.center_label.setObjectName("center_label")
|
||||||
|
self.gridLayout.addWidget(self.center_label, 2, 0, 1, 1)
|
||||||
|
self.width_line = QtWidgets.QLineEdit(ellipsewidget)
|
||||||
|
self.width_line.setObjectName("width_line")
|
||||||
|
self.gridLayout.addWidget(self.width_line, 3, 1, 1, 1)
|
||||||
self.color_box = ColorListEditor(ellipsewidget)
|
self.color_box = ColorListEditor(ellipsewidget)
|
||||||
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.axes_label = QtWidgets.QLabel(ellipsewidget)
|
self.fill_box = ColorListEditor(ellipsewidget)
|
||||||
self.axes_label.setObjectName("axes_label")
|
self.fill_box.setObjectName("fill_box")
|
||||||
self.gridLayout.addWidget(self.axes_label, 2, 0, 1, 1)
|
self.gridLayout.addWidget(self.fill_box, 1, 1, 1, 2)
|
||||||
self.width_line = QtWidgets.QLineEdit(ellipsewidget)
|
self.fill_label = QtWidgets.QLabel(ellipsewidget)
|
||||||
self.width_line.setObjectName("width_line")
|
self.fill_label.setObjectName("fill_label")
|
||||||
self.gridLayout.addWidget(self.width_line, 2, 1, 1, 1)
|
self.gridLayout.addWidget(self.fill_label, 1, 0, 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)
|
self.retranslateUi(ellipsewidget)
|
||||||
QtCore.QMetaObject.connectSlotsByName(ellipsewidget)
|
QtCore.QMetaObject.connectSlotsByName(ellipsewidget)
|
||||||
@ -50,11 +56,12 @@ class Ui_ellipsewidget(object):
|
|||||||
def retranslateUi(self, ellipsewidget):
|
def retranslateUi(self, ellipsewidget):
|
||||||
_translate = QtCore.QCoreApplication.translate
|
_translate = QtCore.QCoreApplication.translate
|
||||||
ellipsewidget.setWindowTitle(_translate("ellipsewidget", "Form"))
|
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"))
|
self.height_line.setPlaceholderText(_translate("ellipsewidget", "axis 2"))
|
||||||
|
self.center_x.setPlaceholderText(_translate("ellipsewidget", "x"))
|
||||||
|
self.axes_label.setText(_translate("ellipsewidget", "Axes"))
|
||||||
|
self.color_label.setText(_translate("ellipsewidget", "Color"))
|
||||||
|
self.center_y.setPlaceholderText(_translate("ellipsewidget", "y"))
|
||||||
|
self.center_label.setText(_translate("ellipsewidget", "Center"))
|
||||||
|
self.width_line.setPlaceholderText(_translate("ellipsewidget", "axis 1"))
|
||||||
|
self.fill_label.setText(_translate("ellipsewidget", "Fill color"))
|
||||||
from gui_qt.lib.delegates import ColorListEditor
|
from gui_qt.lib.delegates import ColorListEditor
|
||||||
|
@ -137,8 +137,6 @@ class RectangleWidget(QtWidgets.QWidget, Ui_rectanglewidget):
|
|||||||
if right is None:
|
if right is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
print(self.fill_box.currentIndex(), self.fill_box.currentData(QtCore.Qt.UserRole))
|
|
||||||
|
|
||||||
dic = {
|
dic = {
|
||||||
'color': self.color_box.currentData(QtCore.Qt.UserRole),
|
'color': self.color_box.currentData(QtCore.Qt.UserRole),
|
||||||
'fill': self.fill_box.currentData(QtCore.Qt.UserRole),
|
'fill': self.fill_box.currentData(QtCore.Qt.UserRole),
|
||||||
@ -154,11 +152,23 @@ class EllipseWidget(QtWidgets.QWidget, Ui_ellipsewidget):
|
|||||||
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.center_x.setValidator(QtGui.QDoubleValidator())
|
self.center_x.setValidator(QtGui.QDoubleValidator())
|
||||||
self.center_y.setValidator(QtGui.QDoubleValidator())
|
self.center_y.setValidator(QtGui.QDoubleValidator())
|
||||||
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 set_args(self, center: tuple = (0, 0), axes: tuple = (1, 1), color=None, fill=None):
|
||||||
|
self.center_x.setText(str(center[0]))
|
||||||
|
self.center_y.setText(str(center[1]))
|
||||||
|
self.width_line.setText(str(axes[0]))
|
||||||
|
self.width_line.setText(str(axes[1]))
|
||||||
|
|
||||||
|
self.color_box.setCurrentIndex(self.color_box.findData(color, QtCore.Qt.UserRole))
|
||||||
|
self.fill_box.setCurrentIndex(self.fill_box.findData(fill, QtCore.Qt.UserRole))
|
||||||
|
|
||||||
def collect_args(self) -> dict | None:
|
def collect_args(self) -> dict | None:
|
||||||
centre = 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:
|
||||||
@ -169,6 +179,7 @@ class EllipseWidget(QtWidgets.QWidget, Ui_ellipsewidget):
|
|||||||
|
|
||||||
dic = {
|
dic = {
|
||||||
'color': self.color_box.currentData(QtCore.Qt.UserRole),
|
'color': self.color_box.currentData(QtCore.Qt.UserRole),
|
||||||
|
'fill': self.fill_box.currentData(QtCore.Qt.UserRole),
|
||||||
'center': centre,
|
'center': centre,
|
||||||
'axes': axes,
|
'axes': axes,
|
||||||
}
|
}
|
||||||
|
@ -222,31 +222,47 @@ class TextObject(BaseObject):
|
|||||||
|
|
||||||
|
|
||||||
class EllipseObject(BaseObject):
|
class EllipseObject(BaseObject):
|
||||||
def __init__(self, center: tuple, axes: tuple, **kwargs):
|
def __init__(self, center: tuple, axes: tuple, fill: BaseColor, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
self.center = center
|
self.center = center
|
||||||
self.axes = axes
|
self.axes = axes
|
||||||
|
self.fill = fill
|
||||||
|
|
||||||
self.drawing = Ellipse(center, axes)
|
self.drawing = Ellipse(self.center, self.axes, self.color, self.fill)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'Ellipse at {self.center}'
|
return f'Ellipse at {self.center}'
|
||||||
|
|
||||||
|
def get_values(self):
|
||||||
|
return {'type': 'ellipse', 'color': self.color, 'center': self.center, 'axes': self.axes, 'fill': self.fill}
|
||||||
|
|
||||||
|
def set_values(self, center=None, axes=None, color=None, fill=None):
|
||||||
|
if center is not None:
|
||||||
|
self.center = center
|
||||||
|
|
||||||
|
if axes is not None:
|
||||||
|
self.axes = axes
|
||||||
|
|
||||||
|
if fill is not None:
|
||||||
|
self.fill = fill
|
||||||
|
|
||||||
|
if color is not None:
|
||||||
|
self.color = color
|
||||||
|
|
||||||
|
self.drawing.setData(self.center, self.axes, self.color, self.fill)
|
||||||
|
|
||||||
|
|
||||||
class Ellipse(GraphicsObject):
|
class Ellipse(GraphicsObject):
|
||||||
# adapted from pyqtgraph example on custom objects
|
# adapted from pyqtgraph example on custom objects
|
||||||
|
|
||||||
def __init__(self, center: tuple, axes: tuple):
|
def __init__(self, center: tuple, axes: tuple, color: BaseColor, fill: BaseColor):
|
||||||
GraphicsObject.__init__(self)
|
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.log_mode = [False, False]
|
||||||
|
|
||||||
|
self.setData(center, axes, color, fill)
|
||||||
|
|
||||||
self.generatePicture()
|
self.generatePicture()
|
||||||
|
|
||||||
def generatePicture(self):
|
def generatePicture(self):
|
||||||
@ -254,8 +270,9 @@ class Ellipse(GraphicsObject):
|
|||||||
## rather than re-drawing the shapes every time.
|
## rather than re-drawing the shapes every time.
|
||||||
self.picture = QtGui.QPicture()
|
self.picture = QtGui.QPicture()
|
||||||
p = QtGui.QPainter(self.picture)
|
p = QtGui.QPainter(self.picture)
|
||||||
p.setPen(mkPen('w'))
|
p.setPen(mkPen(self.color.rgb()))
|
||||||
p.setBrush(mkBrush('r'))
|
if self.fill is not None:
|
||||||
|
p.setBrush(mkBrush(self.fill.rgb()))
|
||||||
p.drawEllipse(QtCore.QPointF(*self.center_disp), *self.ax_disp)
|
p.drawEllipse(QtCore.QPointF(*self.center_disp), *self.ax_disp)
|
||||||
p.end()
|
p.end()
|
||||||
|
|
||||||
@ -274,23 +291,23 @@ class Ellipse(GraphicsObject):
|
|||||||
|
|
||||||
if self.log_mode[0] != x_mode:
|
if self.log_mode[0] != x_mode:
|
||||||
if x_mode:
|
if x_mode:
|
||||||
x0 = self.p0[0]
|
x0 = self.center[0]
|
||||||
xmax = log10(x0+self.delta[0])
|
xmax = log10(x0+self.ax[0])
|
||||||
self.x_disp = log10(x0)
|
self.center_disp = (log10(x0), self.center_disp[1])
|
||||||
self.dx = xmax - self.x_disp
|
self.ax_disp = (xmax, self.ax_disp[1])
|
||||||
else:
|
else:
|
||||||
self.x_disp = self.p0[0]
|
self.center_disp = (self.center[0], self.center_disp[1])
|
||||||
self.dx = self.delta[0]
|
self.ax_disp = (self.ax[0], self.ax_disp[1])
|
||||||
|
|
||||||
if self.log_mode[1] != y_mode:
|
if self.log_mode[1] != y_mode:
|
||||||
if y_mode:
|
if y_mode:
|
||||||
y0 = self.p0[1]
|
y0 = self.center[1]
|
||||||
ymax = log10(y0 + self.delta[1])
|
ymax = log10(y0+self.ax[1])
|
||||||
self.y_disp = log10(y0)
|
self.center_disp = (self.center_disp[0], log10(y0))
|
||||||
self.dy = ymax - self.y_disp
|
self.ax_disp = (self.ax_disp[0], ymax)
|
||||||
else:
|
else:
|
||||||
self.y_disp = self.p0[1]
|
self.ax_disp = (self.ax_disp[0], self.ax[1])
|
||||||
self.dy = self.delta[1]
|
self.center_disp = (self.center_disp[0], self.center[1])
|
||||||
|
|
||||||
self.generatePicture()
|
self.generatePicture()
|
||||||
|
|
||||||
@ -298,5 +315,17 @@ class Ellipse(GraphicsObject):
|
|||||||
|
|
||||||
self.informViewBoundsChanged()
|
self.informViewBoundsChanged()
|
||||||
|
|
||||||
def get_state(self):
|
def setData(self, center, axes, color, fill):
|
||||||
return {'center': self.center, 'axes': self.ax}
|
self.center = center
|
||||||
|
self.ax = axes
|
||||||
|
|
||||||
|
self.center_disp = self.center
|
||||||
|
self.ax_disp = self.ax
|
||||||
|
|
||||||
|
self.color = color
|
||||||
|
self.fill = fill
|
||||||
|
|
||||||
|
l = [self.log_mode[0], self.log_mode[1]]
|
||||||
|
self.log_mode = [None, None]
|
||||||
|
|
||||||
|
self.setLogMode(*l)
|
||||||
|
@ -14,7 +14,42 @@
|
|||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="3" column="2">
|
||||||
|
<widget class="QLineEdit" name="height_line">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>axis 2</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLineEdit" name="center_x">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>x</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="axes_label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Axes</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="2">
|
||||||
|
<widget class="QLineEdit" name="center_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,55 +62,30 @@
|
|||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="color_label">
|
<widget class="QLabel" name="center_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">
|
<property name="text">
|
||||||
<string>Center</string>
|
<string>Center</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1" colspan="2">
|
<item row="3" column="1">
|
||||||
<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">
|
<widget class="QLineEdit" name="width_line">
|
||||||
<property name="placeholderText">
|
<property name="placeholderText">
|
||||||
<string>axis 1</string>
|
<string>axis 1</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="2">
|
<item row="0" column="1" colspan="2">
|
||||||
<widget class="QLineEdit" name="height_line">
|
<widget class="ColorListEditor" name="color_box"/>
|
||||||
<property name="placeholderText">
|
</item>
|
||||||
<string>axis 2</string>
|
<item row="1" column="1" colspan="2">
|
||||||
|
<widget class="ColorListEditor" name="fill_box"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="fill_label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Fill color</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user