def get_gauge(self, parent, macros): aux = [] for k, v in macros.items(): aux.append('{}\t{}\n'.format(k, v)) tooltip = ''.join(aux) width = 320 height = 100 frame = QFrame(parent) frame.setGeometry(QRect(10, 10, width, height)) frame.setMinimumSize(width, height) frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) frame.setObjectName("frame") brush = QBrush(QColor(180, 180, 180)) brush.setStyle(Qt.NoBrush) alarmRec = PyDMDrawingRectangle(frame) alarmRec.channel = "ca://{}".format(macros.get('ALARM', None)) alarmRec.setGeometry(QRect(0, 0, width, height)) alarmRec.setToolTip(tooltip) alarmRec.setProperty("alarmSensitiveContent", True) alarmRec.setProperty("brush", brush) alarmRec.setObjectName("alarmRec") # alarmRec.setStyleSheet("margin:5px; border:3px solid rgb(0, 0, 0);") lblName = QLabel(frame) lblName.setGeometry(QRect(width * 0.05, 50, width - width * 0.05, 20)) font = QFont() font.setPointSize(12) lblName.setFont(font) lblName.setAlignment(Qt.AlignCenter) lblName.setText("{}".format(macros.get('DISP', None))) lblName.setObjectName("lblName") lblName.setToolTip(tooltip) lblVal = PyDMLabel(frame) lblVal.setGeometry(QRect(width * 0.05, 10, width - width * 0.05, 30)) font = QFont() font.setPointSize(18) lblVal.setFont(font) lblVal.setToolTip(tooltip) lblVal.setAlignment(Qt.AlignCenter) lblVal.setProperty("showUnits", False) lblVal.setObjectName("lblVal") lblVal.channel = "ca://{}".format(macros.get('PV', None)) lblVal.precisionFromPV = False lblVal.precision = 2 if self.macros.get('FORMAT', '') == 'EXP': lblVal.displayFormat = PyDMLabel.DisplayFormat.Exponential return frame
def get_gauge(self, parent, pv_info: PVInfo): tooltip = "".join( [f"{key}\t{value}\n" for key, value in pv_info.__dict__.items()] ) width = 320 height = 100 frame = QFrame(parent) frame.setGeometry(QRect(10, 10, width, height)) frame.setMinimumSize(width, height) frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) frame.setObjectName("frame") brush = QBrush(QColor(180, 180, 180)) brush.setStyle(Qt.NoBrush) alarmRec = PyDMDrawingRectangle(frame) alarmRec.channel = "ca://{}".format(pv_info.ALARM) alarmRec.setGeometry(QRect(0, 0, width, height)) alarmRec.setToolTip(tooltip) alarmRec.setProperty("alarmSensitiveContent", True) alarmRec.setProperty("brush", brush) alarmRec.setObjectName("alarmRec") # alarmRec.setStyleSheet("margin:5px; border:3px solid rgb(0, 0, 0);") lblName = QLabel(frame) lblName.setGeometry(QRect(width * 0.05, 50, width - width * 0.05, 20)) font = QFont() font.setPointSize(12) lblName.setFont(font) lblName.setAlignment(Qt.AlignCenter) lblName.setText("{}".format(pv_info.DISP)) lblName.setObjectName("lblName") lblName.setToolTip(tooltip) lblVal = PyDMLabel(frame) lblVal.setGeometry(QRect(width * 0.05, 10, width - width * 0.05, 30)) font = QFont() font.setPointSize(18) lblVal.setFont(font) lblVal.setToolTip(tooltip) lblVal.setAlignment(Qt.AlignCenter) lblVal.setProperty("showUnits", False) lblVal.setObjectName("lblVal") lblVal.channel = "ca://{}".format(pv_info.PV) lblVal.precisionFromPV = False lblVal.precision = 2 if self.macros().get("FORMAT", "") == "EXP": lblVal.displayFormat = PyDMLabel.DisplayFormat.Exponential return frame
def __init__(self, parent=None): super(UiMainWindow, self).__init__(parent) DispatchHandle.setup(self) self.showMaximized() self.setMinimumSize(QSize(640, 480)) self.setDockOptions(QMainWindow.AnimatedDocks) self.setWindowTitle("SpecViz") self.widget_central = QWidget(self) self.setCentralWidget(self.widget_central) # Toolbar self.layout_vertical = QVBoxLayout(self.widget_central) # MDI area setup self.mdi_area = MdiArea(self.widget_central) self.mdi_area.setFrameShape(QFrame.StyledPanel) self.mdi_area.setFrameShadow(QFrame.Plain) self.mdi_area.setLineWidth(2) brush = QBrush(QColor(200, 200, 200)) brush.setStyle(Qt.SolidPattern) self.mdi_area.setBackground(brush) self.mdi_area.setAcceptDrops(True) self.layout_vertical.addWidget(self.mdi_area) # Menu bar setup self.menu_bar = QMenuBar(self) self.menu_file = QMenu(self.menu_bar) self.menu_file.setTitle("File") self.menu_edit = QMenu(self.menu_bar) self.menu_edit.setTitle("Edit") self.menu_view = QMenu(self.menu_bar) self.menu_edit.setTitle("View") self.menu_docks = QMenu(self.menu_bar) self.setMenuBar(self.menu_bar) # Status bar setup self.status_bar = QStatusBar(self) self.setStatusBar(self.status_bar)
class MarkerFactory(QObject): """ Parameters ------------ shape: Shape See config.Shape color: str, QColor Color of the marker. Marker must be filled and outlined with the same color. size: int Width and height of the output QGraphicsItem filled: bool Whether to fill the item. """ _shape_to_class = EnumDict([(Shape.CIRCLE, EllipseMarker), (Shape.DIAMOND, DiamondMarker)]) def __init__(self, shape=Shape.CIRCLE, color=Qt.red, size=3, filled=True): super().__init__() self._brush = QBrush() self._pen = QPen() self.set_marker_shape(shape) self.set_marker_size(size) self.set_marker_color(color) self.set_marker_fill(filled) def get_marker_color(self) -> QColor: return self._pen.color() def set_marker_color(self, color: Union[QColor, int]): # XXX: what's the difference between settning alpha to 0 and # passing Qt.NoBrush to the constructor? # filled = deepcopy(self._brush.style()) self._pen.setColor(color) self._brush.setColor(color) # self._brush.setStyle(filled) def get_marker_fill(self) -> bool: return bool(self._brush.style()) def set_marker_fill(self, f: bool): if f: style = Qt.SolidPattern else: style = Qt.NoBrush self._brush.setStyle(style) def get_marker_shape(self) -> Shape: return self._shape def set_marker_shape(self, shape: Shape): self._shape = shape def get_marker_size(self): return self._size def set_marker_size(self, size: int): self._size = size def __call__(self, x: float, y: float, **kwargs: Any) -> Marker: """ Create a Marker with the properties specified by this Factory. Parameters ------------ x : float y : float X, Y coordinates of the marker. key : int Index that this marker will have in the parent VGraphicsGroup. """ marker = TunableMarker(self._shape, self._size, key=None, **kwargs) marker.set_marker_color(self.get_marker_color()) marker.set_marker_fill(self.get_marker_fill()) # marker = self._marker_class(self._size, **kwargs) # marker.setBrush(self._brush) # marker.setPen(self._pen) marker.setPos(x, y) return marker
class TunableMarker(QGraphicsItem): def __init__(self, shape: Shape, size: int, key: Optional[int] = None, **kwargs): super().__init__() self._shape = shape self._size = size self.key = key self.info = kwargs self._pen = QPen() self._pen.setWidthF(0.25) self._brush = QBrush() def _make_rect(self, length): # make a rectangle of width and height equal to 'length' and centered # about (0, 0) return QRectF(-length / 2, -length / 2, length, length) def boundingRect(self): return self._make_rect(self._size + 4) def _paint_ellipse(self, painter): rect = self._make_rect(self._size) painter.drawEllipse(rect) def _paint_diamond(self, painter): size = self._size X = [0, size / 2, 0, -size / 2, 0] Y = [size / 2, 0, -size / 2, 0, size / 2] points = [QPointF(x, y) for x, y in zip(X, Y)] polygon = QPolygonF(points) painter.drawPolygon(polygon, len(points)) def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget): painter.setPen(self._pen) painter.setBrush(self._brush) shape_to_paint_method = { Shape.CIRCLE: self._paint_ellipse, Shape.DIAMOND: self._paint_diamond } drawing_method = shape_to_paint_method[self._shape] drawing_method(painter) def get_marker_color(self): """ Marker color. """ return self._pen.color() def set_marker_color(self, color: Union[QColor, int]): color = QColor(color) self._pen.setColor(color) self._brush.setColor(color) self.update() def get_marker_fill(self) -> bool: """ Whether this marker is filled in or merely an outline. """ return bool(self._brush.style()) def set_marker_fill(self, f: bool): if f: f = Qt.SolidPattern else: f = Qt.NoBrush self._brush.setStyle(f) self.update() def get_marker_shape(self): return self._shape def set_marker_shape(self, shape: Shape): self._shape = shape self.update() def get_marker_size(self): return self._size def set_marker_size(self, sz: int): self._size = sz self.update()
def get_gauge(self, parent, pv): aux = [] for k, v in pv.items(): aux.append("{}\t{}\n".format(k, v)) tooltip = "".join(aux) width = 320 height = 100 frame = QFrame(parent) frame.setGeometry(QRect(10, 10, width, height)) frame.setMinimumSize(width, height) frame.setFrameShape(QFrame.StyledPanel) frame.setFrameShadow(QFrame.Raised) frame.setObjectName("frame") brush = QBrush(QColor(180, 180, 180)) brush.setStyle(Qt.NoBrush) alarmRec = PyDMDrawingRectangle(frame) alarmRec.channel = "ca://{}".format(pv.get("ALARM", None)) alarmRec.setGeometry(QRect(0, 0, width, height * 0.8)) alarmRec.setToolTip(tooltip) alarmRec.setProperty("alarmSensitiveContent", True) alarmRec.setProperty("brush", brush) alarmRec.setObjectName("alarmRec") alarmRecComm = PyDMDrawingRectangle(frame) alarmRecComm.channel = "ca://{}".format( pv.get("DEVICE", None) + ":Pressure:Read") alarmRecComm.setGeometry(QRect(0, height * 0.8, width, height * 0.2)) alarmRecComm.setToolTip("Connection Indicator: {}\t{}".format( "DEVICE", pv.get("DEVICE", None) + ":Pressure:Read")) alarmRecComm.setProperty("alarmSensitiveContent", True) alarmRecComm.setProperty("brush", brush) alarmRecComm.setObjectName("alarmRecComm") alarmRecComm.setStyleSheet(""" border:1px solid rgb(214, 214, 214); """) lblName = QLabel(frame) lblName.setGeometry(QRect(width * 0.05, 50, width - width * 0.05, 20)) font = QFont() font.setPointSize(12) lblName.setFont(font) lblName.setAlignment(Qt.AlignCenter) lblName.setText("{}".format(pv.get("DISP", None))) lblName.setObjectName("lblName") lblName.setToolTip(tooltip) font = QFont() font.setPointSize(12) lblComm = QLabel(frame) lblComm.setGeometry(QRect(10, 80, 190, 20)) lblComm.setFont(font) lblComm.setAlignment(Qt.AlignCenter) lblComm.setText("COMM Status") lblComm.setObjectName("lblComm") lblComm.setToolTip("Communication status to device {}".format( pv.get("DEVICE", ""))) lblCommPv = PyDMLabel(frame) lblCommPv.setGeometry(QRect(150, 80, 190, 20)) lblCommPv.setFont(font) lblCommPv.setToolTip("Communication status to device {}".format( pv.get("DEVICE", ""))) lblCommPv.setAlignment(Qt.AlignCenter) lblCommPv.setObjectName("lblCommPv") lblCommPv.channel = "ca://{}".format( pv.get("DEVICE", None) + ":Pressure:Read.STAT") lblVal = PyDMLabel(frame) lblVal.setGeometry(QRect(width * 0.05, 10, width - width * 0.05, 30)) font = QFont() font.setPointSize(18) lblVal.setFont(font) lblVal.setToolTip(tooltip) lblVal.setAlignment(Qt.AlignCenter) lblVal.setProperty("showUnits", False) lblVal.setObjectName("lblVal") lblVal.channel = "ca://{}".format(pv.get("PV", None)) lblVal.precisionFromPV = False lblVal.precision = 2 if self.macros.get("FORMAT", "") == "EXP": lblVal.displayFormat = PyDMLabel.DisplayFormat.Exponential return frame