Skip to content

Commit

Permalink
Merge pull request #1056 from phys-cgarnier/master
Browse files Browse the repository at this point in the history
Adding rules to pydm drawing line
  • Loading branch information
YektaY authored Feb 14, 2024
2 parents 8587254 + 7e3fc65 commit aebd231
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
25 changes: 21 additions & 4 deletions pydm/widgets/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions pydm/widgets/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit aebd231

Please sign in to comment.