-
Notifications
You must be signed in to change notification settings - Fork 9
/
ChannelsBrick.py
87 lines (75 loc) · 3.5 KB
/
ChannelsBrick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import qt
from BlissFramework.BaseComponents import BlissWidget
import logging
__category__ = "General"
class ChannelsBrick(BlissWidget):
def __init__(self, parent, name):
BlissWidget.__init__(self, parent, name)
self.addProperty("xmlFile", "string", "")
self.addProperty("uiFile", "string", "")
self.addProperty("expert_channels", "string", "", hidden=True)
self.__brick_properties = self.propertyBag.properties.keys()
self.hwo = None
self.expert_channels = []
self.property_expert_channels = {}
def propertyChanged(self, prop, oldValue, newValue):
if prop == "xmlFile":
if not self.isRunning():
# we are changing xmlFile in design mode
for propname in self.propertyBag.properties.keys():
if not propname in self.__brick_properties:
self.delProperty(propname)
self.hwo = self.getHardwareObject(newValue)
if self.hwo is None:
return
if not self.isRunning():
for channel in self.hwo.getChannels():
self.addProperty("%s expert only" % channel.name(), "boolean", False)
elif prop == "uiFile":
self.widget = self.createGUIFromUI(newValue)
self.widget.show()
elif prop == 'expert_channels':
if self.isRunning():
# it is time to set expert channels
expert_channels = eval(self["expert_channels"])
for channel_prop in expert_channels.keys():
expert = expert_channels[channel_prop]
try:
self.getProperty(channel_prop).setValue(expert)
except:
del expert_channels[channel_prop]
continue
self.getProperty("expert_channels").setValue(str(expert_channels))
else:
if prop.endswith("expert only"):
self.property_expert_channels[prop] = newValue
self.getProperty("expert_channels").setValue(str(self.property_expert_channels))
def run(self):
self.expert_channels = []
# trigger evaluation of previously saved expert channels
self["expert_channels"] = self["expert_channels"]
# look for all checkboxes
all_checkboxes = self.widget.queryList("QCheckBox")
for checkbox in all_checkboxes:
channel_name = str(checkbox.name())
channel = self.hwo.getChannelObject(channel_name)
def channelValueChanged(new_value, widget=checkbox):
widget.setChecked(str(new_value)=='1')
channelValueChanged(channel.getValue())
def widgetValueChanged(widget=checkbox, channel=channel):
if widget.isChecked():
channel.setValue(1)
else:
channel.setValue(0)
channel.connectSignal("update", channelValueChanged)
qt.QObject.connect(checkbox, qt.SIGNAL("clicked()"), widgetValueChanged)
try:
if self["%s expert only" % channel_name] and checkbox.isEnabled():
# if widget is expert, but not enabled since the beginning: ignore
self.expert_channels.append(checkbox)
checkbox.setEnabled(False)
except:
logging.getLogger().exception("%s: could not set expert property for channel %s", self.name(), channel_name)
def setExpertMode(self, expert):
for widget in self.expert_channels:
widget.setEnabled(expert)