diff --git a/pydm/widgets/drawing.py b/pydm/widgets/drawing.py index b22bd20d9..1ba7ea93d 100644 --- a/pydm/widgets/drawing.py +++ b/pydm/widgets/drawing.py @@ -12,6 +12,12 @@ logger = logging.getLogger(__name__) +_penRuleProperties = { + "Set Pen Color": ["penColor", QColor], + "Set Pen Style": ["penStyle", int], + "Set Pen Width": ["penWidth", float], +} + def deg_to_qt(deg): """ @@ -447,7 +453,7 @@ def alarm_severity_changed(self, new_alarm_severity): self.penStyle = self._original_pen_style -class PyDMDrawingLine(PyDMDrawing): +class PyDMDrawingLine(PyDMDrawing, new_properties=_penRuleProperties): """ A widget with a line drawn in it. This class inherits from PyDMDrawing. @@ -1245,7 +1251,10 @@ def p2d(pt): if self._arrow_start_point_selection and (len(self._points[1]) >= 2): points = PyDMDrawingLine._arrow_points( - p2d(self._points[len(self._points) - 2]), p2d(self._points[len(self._points) - 1]), 6, 6 + p2d(self._points[len(self._points) - 2]), + p2d(self._points[len(self._points) - 1]), + 6, + 6, ) painter.drawPolygon(points) @@ -1287,10 +1296,18 @@ def validate_point(i, point): try: point = ast.literal_eval(point) except SyntaxError: - logger.error("point %d must be two numbers, comma-separated, received '%s'", i, pt) + logger.error( + "point %d must be two numbers, comma-separated, received '%s'", + i, + pt, + ) return if not isinstance(point, (list, tuple)) or len(point) != 2: - logger.error("point %d must be two numbers, comma-separated, received '%s'", i, pt) + logger.error( + "point %d must be two numbers, comma-separated, received '%s'", + i, + pt, + ) return try: point = list(map(float, point)) # ensure all values are float diff --git a/pydm/widgets/rules.py b/pydm/widgets/rules.py index bb7d7cf08..df915ffb6 100644 --- a/pydm/widgets/rules.py +++ b/pydm/widgets/rules.py @@ -5,6 +5,7 @@ from qtpy.QtCore import QThread, QMutex, Signal from qtpy.QtWidgets import QWidget, QApplication +from qtpy.QtGui import QColor from ..utilities import is_qt_designer from .channel import PyDMChannel @@ -183,7 +184,12 @@ def register(self, widget, rules): conn_cb = functools.partial(self.callback_conn, widget_ref, idx, ch_idx) value_cb = functools.partial(self.callback_value, widget_ref, idx, ch_idx, ch["trigger"]) enums_cb = functools.partial(self.callback_enum, widget_ref, idx, ch_idx) - c = PyDMChannel(ch["channel"], connection_slot=conn_cb, value_slot=value_cb, enum_strings_slot=enums_cb) + c = PyDMChannel( + ch["channel"], + connection_slot=conn_cb, + value_slot=value_cb, + enum_strings_slot=enums_cb, + ) item["channels"].append(c) rules_db.append(item) @@ -355,7 +361,7 @@ def calculate_expression(self, widget_ref, idx, rule): pass calc_vals.append(v) - eval_env = {"np": np, "ch": calc_vals} + eval_env = {"np": np, "ch": calc_vals, "QColor": QColor} eval_env.update({k: v for k, v in math.__dict__.items() if k[0] != "_"}) expression = rule["rule"]["expression"]