Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.
Open

Attr #21

Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions svgsynoptic2/taurussynopticwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def filter_fragment(self, model, value):
# part of a spectrum or image through "slicing". It is up to the
# client to do this, so we implement it here.
frag = self.registry.eval_validator.getNames(model, fragment=True)[3]

if frag:
indices = frag[1:-1]
try:
Expand All @@ -151,6 +152,16 @@ def filter_fragment(self, model, value):
pass
return value

def set_custom_value(self, model, attr_value):
# this is the special case where value is modified for PyAlarm class
# when alarm is trigered PyAlarm attribute returns 'True' value, icon on synoptic is green
# set_custom_value change value for better alarms visualisation
# function can be customised for any other tango device classes
if 'PyAlarm' in PyTango.get_device_proxy(model).info().dev_class:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is better to keep only one return statement:

dev_class = PyTango.get_device_proxy(model).info().dev_class
return not(attr_value) if 'PyAlarm' in dev_class else attr_value

But it is less "customized friendly"

return not(attr_value)
else:
return attr_value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using finally like this cause that there is always returned attr_value, no matter what happens in try. There should be return after except (not inside).


def attribute_listener(self, model, evt_src, evt_type, evt_value):
"Handle events"
if evt_type == TaurusEventType.Error:
Expand Down Expand Up @@ -202,6 +213,8 @@ def attribute_listener(self, model, evt_src, evt_type, evt_value):
(model, value))

elif isinstance(value, (bool, np.bool_)):
#Change value
value = self.set_custom_value('/'.join(model.split('/')[:-1]), value)
classes = {"boolean": True,
"boolean-true": bool(value),
"boolean-false": not value}
Expand Down Expand Up @@ -264,9 +277,9 @@ def get_device_panel(self, device):

def on_rightclick(self, kind, name):
"The default behavior for right clicking a device is to open a panel."
if kind == "model" and self.registry.device_validator.isValid(name):
if kind == "model" and (self.registry.device_validator.isValid(name) or
self.registry.attribute_validator.isValid(name)):
if name.lower() in self._panels:

widget = self._panels[name.lower()]
print "Found existing panel for %s:" % name, widget
if not widget.isVisible():
Expand All @@ -275,7 +288,6 @@ def on_rightclick(self, kind, name):
widget.raise_()
return


# check if we recognise the class of the device
widget = self.get_device_panel(name)

Expand Down Expand Up @@ -305,7 +317,12 @@ def _cleanup_panel(self, w):
if self.registry:
with self.registry.lock:
print "cleaning up panel for", w.getModel(), "..."
self._panels.pop(str(w.getModel()).lower(), None)
# TaurusForm getModel return list
if isinstance(w.getModel(), list):
self._panels.pop(str(w.getModel()[0]).lower(), None)
else:
self._panels.pop(str(w.getModel()).lower(), None)

w.setModel(None)
print "done!"

Expand Down