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

Attr #21

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Attr #21

Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from setuptools import setup

setup(
name="python-svgsynoptic2",
version="3.1",
name="lib-svgsynoptic2",
version="3.7.0",
description="Widget for displaying a SVG synoptic.",
author="Johan Forsberg",
author_email="[email protected]",
Expand Down
25 changes: 14 additions & 11 deletions svgsynoptic2/taurusregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,20 @@ def run(self):

def subscribe(self, models=[]):
"""Set the currently subscribed list of models."""
attrs = CaselessDict()
for model in models:
if self.device_validator.isValid(model):
# for convenience, we subscribe to State for any devices
attrs[model + "/State"] = True
elif (self.attribute_validator.isValid(model) or
self.eval_validator.isValid(model)):
attrs[model] = True
else:
print "Invalid Taurus model %s!?" % model
self._attributes = attrs
try:
attrs = CaselessDict()
for model in models:
if self.device_validator.isValid(model):
# for convenience, we subscribe to State for any devices
attrs[model + "/State"] = True
elif (self.attribute_validator.isValid(model) or
self.eval_validator.isValid(model)):
attrs[model] = True
else:
print "Invalid Taurus model %s!?" % model
self._attributes = attrs
except Exception as e:
print('Problem to subscribe list of models {0}'.format(e))

def get_value(self, model):
evt = self._last_event.get(model)
Expand Down
42 changes: 32 additions & 10 deletions svgsynoptic2/taurussynopticwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ def run_plugin_command(self, plugin, cmd, args):
return getattr(plugins, cmd)(self, args)

def handle_subscriptions(self, models=[]):
print "handle_subscriptions", models
if self.registry:
# print "handle_subscriptions", models
try:
self.registry.subscribe(models)
except Exception as e:
print('Problem to handle_subscriptions {0}'.format(e))

def unsubscribe_listener(self, unsubscribed):
"""Tell the synoptic about unsubscribed models. This is
Expand All @@ -135,6 +137,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 +154,19 @@ 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
try:
if 'PyAlarm' in PyTango.get_device_proxy(model).info().dev_class:
return not(attr_value)
except Exception as e:
print('Problem to set custom value {0} \n for model {1}'.format(e, model))
finally:
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 +218,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)

Choose a reason for hiding this comment

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

I'm not sure why this is commented, but I noticed a problem when I have too complicated functions in some parts like this. It is more possible to get error terminate called after throwing an instance of 'Tango::DevFailed' when this is uncommented. When I removed inquiry to database: PyTango.get_device_proxy(model).info().dev_class: and just checked model name for some simple schemes in name it was less possible to get such error.

classes = {"boolean": True,
"boolean-true": bool(value),
"boolean-false": not value}
Expand Down Expand Up @@ -245,7 +263,7 @@ def on_click(self, kind, name):
clicked section. Override this function if you need something
else.
"""
print "on_click", kind, name
# print "on_click", kind, name
if kind == "model" and self.registry.device_validator.isValid(name):
self.select(kind, [name])
self.emit(Qt.SIGNAL("graphicItemSelected(QString)"), name)
Expand All @@ -264,9 +282,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 +293,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 @@ -304,10 +321,15 @@ def _cleanup_panel(self, w):
become pretty bogged down."""
if self.registry:
with self.registry.lock:
print "cleaning up panel for", w.getModel(), "..."
self._panels.pop(str(w.getModel()).lower(), None)
# print "cleaning up panel for", w.getModel(), "..."
# 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!"
# print "done!"

# Note: the tooltip stuff is broken and not currently in use.
# Currently there is only the default tooltip which displays the
Expand Down Expand Up @@ -370,7 +392,7 @@ def closeEvent(self, event):

if __name__ == '__main__':
import sys
print sys.argv[1]
# print sys.argv[1]
# qapp = Qt.QApplication([])
app = TaurusApplication()
sw = TaurusSynopticWidget()
Expand Down