Skip to content

Commit

Permalink
ran reformatter on code
Browse files Browse the repository at this point in the history
  • Loading branch information
phys-cgarnier committed Feb 12, 2024
1 parent 49d4f1c commit 455d85a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 19 deletions.
62 changes: 47 additions & 15 deletions pydm/widgets/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@

logger = logging.getLogger(__name__)

_penRuleProperties = {"Set Pen Color": ["penColor", QColor],
"Set Pen Style": ["penStyle", int],
"Set Pen Width": ["penWidth", float]}
_penRuleProperties = {
"Set Pen Color": ["penColor", QColor],
"Set Pen Style": ["penStyle", int],
"Set Pen Width": ["penWidth", float],
}


def deg_to_qt(deg):
"""
Converts from degrees to QT degrees.
Expand Down Expand Up @@ -65,6 +69,7 @@ class PyDMDrawing(QWidget, PyDMWidget):
init_channel : str, optional
The channel to be used by the widget.
"""

def __init__(self, parent=None, init_channel=None):
self._rotation = 0.0
self._brush = QBrush(Qt.SolidPattern)
Expand Down Expand Up @@ -216,11 +221,15 @@ def get_inner_max(self):
origHeight = self.height()

if origWidth == 0:
logger.error("Invalid width. The value must be greater than {0}".format(origWidth))
logger.error(
"Invalid width. The value must be greater than {0}".format(origWidth)
)
return

if origHeight == 0:
logger.error("Invalid height. The value must be greater than {0}".format(origHeight))
logger.error(
"Invalid height. The value must be greater than {0}".format(origHeight)
)
return

if origWidth <= origHeight:
Expand Down Expand Up @@ -448,7 +457,7 @@ def alarm_severity_changed(self, new_alarm_severity):
self.penStyle = self._original_pen_style


class PyDMDrawingLine(PyDMDrawing,new_properties= _penRuleProperties):
class PyDMDrawingLine(PyDMDrawing, new_properties=_penRuleProperties):
"""
A widget with a line drawn in it.
This class inherits from PyDMDrawing.
Expand Down Expand Up @@ -825,7 +834,9 @@ def draw_item(self, painter):
super(PyDMDrawingImage, self).draw_item(painter)
x, y, w, h = self.get_bounds(maxsize=True, force_no_pen=True)
if not isinstance(self._pixmap, QMovie):
_scaled = self._pixmap.scaled(int(w), int(h), self._aspect_ratio_mode, Qt.SmoothTransformation)
_scaled = self._pixmap.scaled(
int(w), int(h), self._aspect_ratio_mode, Qt.SmoothTransformation
)
# Make sure the image is centered if smaller than the widget itself
if w > _scaled.width():
logger.debug("Centering image horizontally ...")
Expand Down Expand Up @@ -1063,7 +1074,9 @@ def draw_item(self, painter):
super(PyDMDrawingArc, self).draw_item(painter)
maxsize = not self.is_square()
x, y, w, h = self.get_bounds(maxsize=maxsize)
painter.drawArc(QRectF(x, y, w, h), int(self._start_angle), int(self._span_angle))
painter.drawArc(
QRectF(x, y, w, h), int(self._start_angle), int(self._span_angle)
)


class PyDMDrawingPie(PyDMDrawingArc):
Expand All @@ -1090,7 +1103,9 @@ def draw_item(self, painter):
super(PyDMDrawingPie, self).draw_item(painter)
maxsize = not self.is_square()
x, y, w, h = self.get_bounds(maxsize=maxsize)
painter.drawPie(QRectF(x, y, w, h), int(self._start_angle), int(self._span_angle))
painter.drawPie(
QRectF(x, y, w, h), int(self._start_angle), int(self._span_angle)
)


class PyDMDrawingChord(PyDMDrawingArc):
Expand All @@ -1117,7 +1132,9 @@ def draw_item(self, painter):
super(PyDMDrawingChord, self).draw_item(painter)
maxsize = not self.is_square()
x, y, w, h = self.get_bounds(maxsize=maxsize)
painter.drawChord(QRectF(x, y, w, h), int(self._start_angle), int(self._span_angle))
painter.drawChord(
QRectF(x, y, w, h), int(self._start_angle), int(self._span_angle)
)


class PyDMDrawingPolygon(PyDMDrawing):
Expand Down Expand Up @@ -1236,17 +1253,24 @@ def p2d(pt):
midpoint_x = (point1.x() + point2.x()) / 2
midpoint_y = (point1.y() + point2.y()) / 2
midpoint = QPointF(midpoint_x, midpoint_y)
points = PyDMDrawingLine._arrow_points(point1, midpoint, 6, 6) # 6 = arbitrary arrow size
points = PyDMDrawingLine._arrow_points(
point1, midpoint, 6, 6
) # 6 = arbitrary arrow size
painter.drawPolygon(points)

# Draw the arrows
if self._arrow_end_point_selection and (len(self._points[1]) >= 2):
points = PyDMDrawingLine._arrow_points(p2d(self._points[1]), p2d(self._points[0]), 6, 6)
points = PyDMDrawingLine._arrow_points(
p2d(self._points[1]), p2d(self._points[0]), 6, 6
)
painter.drawPolygon(points)

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 @@ -1288,10 +1312,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
18 changes: 14 additions & 4 deletions pydm/widgets/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,18 @@ def register(self, widget, rules):

for ch_idx, ch in enumerate(channels_list):
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)
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,
)
item["channels"].append(c)
rules_db.append(item)

Expand Down Expand Up @@ -367,7 +376,8 @@ def calculate_expression(self, widget_ref, idx, rule):
self.emit_value(widget_ref, name, prop, val)
except Exception:
logger.exception(
f"Error while evaluating Rule with name: {name} and type: {prop} " f"and expression: {expression}"
f"Error while evaluating Rule with name: {name} and type: {prop} "
f"and expression: {expression}"
)

def emit_value(self, widget_ref, name, prop, val):
Expand Down

0 comments on commit 455d85a

Please sign in to comment.