-
Notifications
You must be signed in to change notification settings - Fork 9
/
StatusBarBrick.py
132 lines (105 loc) · 4.46 KB
/
StatusBarBrick.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from BlissFramework.BaseComponents import BlissWidget
from BlissFramework.Utils import widget_colors
from qt import *
import logging
from widgets.spin_box_buttons import SpinBoxButtons
'''
Doc please...
'''
__category__ = 'GuiUtils'
class StatusBarBrick(BlissWidget):
STATES = { "Unknown": QWidget.gray,\
"Disconnected": widget_colors.LIGHT_RED,\
"Connected": QColor(255,165,0),\
"Busy": QWidget.yellow,\
"Ready": widget_colors.LIGHT_GREEN }
def __init__(self, *args):
BlissWidget.__init__(self, *args)
self.specStateHO=None
self.statusBar=None
self.specStateLabel=None
self.addProperty('specstate','string','')
self.addProperty('statusSearchDepth','integer',3)
self.defineSlot('setMessage',())
self.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed)
# Information messages
self.MAX_BUFFER_SIZE = 5
self.messages = []
self.read_idx = 0
self.insert_idx = 0
self.button = QPushButton("Add", self, "add_button")
self.v_scroll = SpinBoxButtons(self, 'v_scroll')
QObject.connect(self.v_scroll, PYSIGNAL("scroll_up"),
self.next_message)
QObject.connect(self.v_scroll, PYSIGNAL("scroll_down"),
self.prev_message)
def next_message(self):
if self.read_idx < self.MAX_BUFFER_SIZE - 1:
self.read_idx += 1
self.statusBar.message(self.messages[self.read_idx])
def prev_message(self):
if self.read_idx > 0:
self.read_idx -= 1
self.statusBar.message(self.messages[self.read_idx])
def findMenu(self,top_widget,depth_level):
if depth_level==0:
return None
child_list=top_widget.children()
if child_list is not None:
for w in child_list:
if isinstance(w,QStatusBar):
return w
menu=self.findMenu(w,depth_level-1)
if menu is not None:
return menu
def setMessage(self, message):
if self.isRunning():
if self.statusBar is not None:
self.messages.insert(self.insert_idx, message)
self.statusBar.message(message)
self.read_idx = self.insert_idx
self.insert_idx = (self.insert_idx + 1) % self.MAX_BUFFER_SIZE
def specStateChanged(self,state, spec_version):
if self.isRunning():
if self.specStateLabel is None:
return
try:
color=self.STATES[state]
except KeyError:
state='Unknown'
color=self.STATES[state]
self.specStateLabel.setPaletteBackgroundColor(QColor(color))
def run(self):
top_widget=qApp.mainWidget()
search_depth=self['statusSearchDepth']
self.statusBar=self.findMenu(top_widget,search_depth)
if self.statusBar is not None:
f=self.statusBar.font()
f.setPointSize(self.font().pointSize())
self.statusBar.setFont(f)
self.statusBar.addWidget(self.v_scroll, 0, True)
if self.specStateHO is not None:
try:
version=self.specStateHO.getVersion()[1]
except:
logging.getLogger().exception("StatusBarBrick: could not get spec version")
else:
self.specStateLabel=QLabel("spec: %s" % version,self.statusBar)
self.statusBar.addWidget(self.specStateLabel,0,True)
self.specStateChanged(*self.specStateHO.getState())
self.setMessage("One")
self.setMessage("Two")
self.setMessage("Three")
self.setMessage("Four")
self.setMessage("Ready")
else:
logging.getLogger().debug("StatusBarBrick: could not find the windows's status bar")
def propertyChanged(self,propertyName,oldValue,newValue):
if propertyName=='specstate':
if self.specStateHO is not None:
self.disconnect(self.specStateHO,'specStateChanged',self.specStateChanged)
self.specStateHO=self.getHardwareObject(newValue)
if self.specStateHO is not None:
self.connect(self.specStateHO,'specStateChanged',self.specStateChanged)
else:
BlissWidget.propertyChanged(self,propertyName,oldValue,newValue)