rectangles done
This commit is contained in:
parent
9681d09ed4
commit
3ddc81dbfa
@ -119,6 +119,15 @@ class RectangleWidget(QtWidgets.QWidget, Ui_rectanglewidget):
|
|||||||
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 set_args(self, left: tuple = (0, 0), right: tuple = (1, 1), color=None, fill=None):
|
||||||
|
self.left_x.setText(str(left[0]))
|
||||||
|
self.left_y.setText(str(left[1]))
|
||||||
|
self.right_x.setText(str(right[0]))
|
||||||
|
self.right_y.setText(str(right[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:
|
||||||
left = parse_point(self.left_x, self.left_y)
|
left = parse_point(self.left_x, self.left_y)
|
||||||
if left is None:
|
if left is None:
|
||||||
@ -128,6 +137,8 @@ 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),
|
||||||
|
@ -11,6 +11,8 @@ from gui_qt.lib.pg_objects import LogInfiniteLine, PlotItem
|
|||||||
|
|
||||||
__all__ = ['LineObject', 'MultipointObject', 'RectangleObject', 'TextObject', 'EllipseObject']
|
__all__ = ['LineObject', 'MultipointObject', 'RectangleObject', 'TextObject', 'EllipseObject']
|
||||||
|
|
||||||
|
from nmreval.lib.colors import BaseColor
|
||||||
|
|
||||||
|
|
||||||
class BaseObject:
|
class BaseObject:
|
||||||
def __init__(self, color=None):
|
def __init__(self, color=None):
|
||||||
@ -45,11 +47,12 @@ class LineObject(BaseObject):
|
|||||||
return {'type': 'line', 'color': self.color, 'pos': self.pos, 'angle': self.angle}
|
return {'type': 'line', 'color': self.color, 'pos': self.pos, 'angle': self.angle}
|
||||||
|
|
||||||
def set_values(self, pos=None, angle=None, color=None):
|
def set_values(self, pos=None, angle=None, color=None):
|
||||||
|
|
||||||
if pos != self.pos:
|
if pos != self.pos:
|
||||||
self.drawing.setPos(pos)
|
self.drawing.setPos(pos)
|
||||||
|
|
||||||
if angle != self.angle:
|
if angle != self.angle:
|
||||||
self.drawing.setAngle(angle)
|
self.drawing.setAngle(angle)
|
||||||
|
|
||||||
if color != self.color:
|
if color != self.color:
|
||||||
self.drawing.setPen(mkPen(color.rgb()))
|
self.drawing.setPen(mkPen(color.rgb()))
|
||||||
|
|
||||||
@ -94,30 +97,27 @@ class MultipointObject(BaseObject):
|
|||||||
self._x += (x[0],)
|
self._x += (x[0],)
|
||||||
self._y += (y[0],)
|
self._y += (y[0],)
|
||||||
|
|
||||||
|
self.drawing.setPos(self._x, self._y)
|
||||||
|
|
||||||
|
|
||||||
class Rectangle(GraphicsObject):
|
class Rectangle(GraphicsObject):
|
||||||
# adapted from pyqtgraph example on custom objects
|
# adapted from pyqtgraph example on custom objects
|
||||||
|
|
||||||
def __init__(self, left: tuple, right: tuple):
|
def __init__(self, left: tuple, right: tuple, color: BaseColor, fill: BaseColor):
|
||||||
GraphicsObject.__init__(self)
|
GraphicsObject.__init__(self)
|
||||||
|
|
||||||
self.p0 = left
|
|
||||||
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.setData(left, right, color, fill)
|
||||||
|
|
||||||
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.
|
||||||
|
print(self.x_disp, self.y_disp, self.dx, self.dy, self.color, self.fill)
|
||||||
self.picture = QtGui.QPicture()
|
self.picture = QtGui.QPicture()
|
||||||
p = QtGui.QPainter(self.picture)
|
p = QtGui.QPainter(self.picture)
|
||||||
p.setPen(mkPen('w'))
|
if self.fill is not None:
|
||||||
p.setBrush(mkBrush('r'))
|
p.setBrush(mkBrush(self.fill.rgb()))
|
||||||
|
p.setPen(mkPen(self.color.rgb()))
|
||||||
p.drawRect(QtCore.QRectF(self.x_disp, self.y_disp, self.dx, self.dy))
|
p.drawRect(QtCore.QRectF(self.x_disp, self.y_disp, self.dx, self.dy))
|
||||||
p.end()
|
p.end()
|
||||||
|
|
||||||
@ -160,18 +160,54 @@ class Rectangle(GraphicsObject):
|
|||||||
|
|
||||||
self.informViewBoundsChanged()
|
self.informViewBoundsChanged()
|
||||||
|
|
||||||
class RectangleObject(BaseObject):
|
def setData(self, left, right, color, fill):
|
||||||
def __init__(self, left: tuple, right: tuple, **kwargs):
|
self.p0 = left
|
||||||
super().__init__(**kwargs)
|
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.color = color
|
||||||
|
self.fill = fill
|
||||||
|
|
||||||
|
l = [self.log_mode[0], self.log_mode[1]]
|
||||||
|
self.log_mode = [None, None]
|
||||||
|
|
||||||
|
self.setLogMode(*l)
|
||||||
|
|
||||||
|
|
||||||
|
class RectangleObject(BaseObject):
|
||||||
|
def __init__(self, left: tuple, right: tuple, fill: BaseColor, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
self.fill = fill
|
||||||
self.left = left
|
self.left = left
|
||||||
self.right = right
|
self.right = right
|
||||||
|
|
||||||
self.drawing = Rectangle(left, right)
|
self.drawing = Rectangle(left, right, self.color, self.fill)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'Rectangle {self.left} to {self.right}'
|
return f'Rectangle {self.left} to {self.right}'
|
||||||
|
|
||||||
|
def get_values(self):
|
||||||
|
return {'type': 'rectangle', 'color': self.color, 'left': self.left, 'right': self.right, 'fill': self.fill}
|
||||||
|
|
||||||
|
def set_values(self, left=None, right=None, color=None, fill=None):
|
||||||
|
if left is not None:
|
||||||
|
self.left = left
|
||||||
|
|
||||||
|
if right is not None:
|
||||||
|
self.right = right
|
||||||
|
|
||||||
|
if fill is not None:
|
||||||
|
self.fill = fill
|
||||||
|
|
||||||
|
if color is not None:
|
||||||
|
self.color = color
|
||||||
|
|
||||||
|
self.drawing.setData(self.left, self.right, self.color, self.fill)
|
||||||
|
|
||||||
|
|
||||||
class TextObject(BaseObject):
|
class TextObject(BaseObject):
|
||||||
def __init__(self, text, pos, **kwargs):
|
def __init__(self, text, pos, **kwargs):
|
||||||
@ -197,6 +233,7 @@ class EllipseObject(BaseObject):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'Ellipse at {self.center}'
|
return f'Ellipse at {self.center}'
|
||||||
|
|
||||||
|
|
||||||
class Ellipse(GraphicsObject):
|
class Ellipse(GraphicsObject):
|
||||||
# adapted from pyqtgraph example on custom objects
|
# adapted from pyqtgraph example on custom objects
|
||||||
|
|
||||||
|
@ -62,6 +62,8 @@ class DrawingsWidget(QtWidgets.QWidget, Ui_Form):
|
|||||||
|
|
||||||
graph_id, obj = self.get_item()
|
graph_id, obj = self.get_item()
|
||||||
|
|
||||||
|
print(dic)
|
||||||
|
|
||||||
if self._editmode:
|
if self._editmode:
|
||||||
obj.set_values(**dic)
|
obj.set_values(**dic)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user