Skip to content

Commit d98ce71

Browse files
committed
qtvcp notify: multiple changes (see long comment)
Allow notification background click to act as "Close" Allow notification to have icon Fix "Clear All" not working after clicking "Show Last Five" Move to f-strings
1 parent 681705b commit d98ce71

1 file changed

Lines changed: 25 additions & 18 deletions

File tree

lib/python/qtvcp/lib/notify.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Notify:
2727
CLOSE = 'close'
2828
LASTFIVE = 'lastFive'
2929
CLEARALL = 'clearAll'
30+
BACKGROUND = 'background'
3031

3132
def __init__(self):
3233
self.statusbar = None
@@ -36,6 +37,7 @@ def __init__(self):
3637
self.critical_message = None
3738
self.normal_message = None
3839
self.hard_limits_message = None
40+
self.clicked = None
3941
STATUS.connect('shutdown', self.cleanup)
4042

4143
# This prints a message in the status bar (if available)
@@ -155,7 +157,7 @@ def show_ok_notification(self, title, message, icon, timeout, callback):
155157
n.setTimeout(timeout * 1000)
156158
n.addAction("Ok", "ok", self.okClicked, callback)
157159
n.onClose(self.handle_closed)
158-
n.addAction('Canel', 'cancel', self.cancelClicked, callback)
160+
n.addAction('Cancel', 'cancel', self.cancelClicked, callback)
159161
n.show()
160162
self.notify_list.append(n)
161163

@@ -195,16 +197,20 @@ def jogPauseClicked(self, n, action, callback):
195197
STATUS.emit('system_notify_button_pressed', Notify.JOGPAUSE, True)
196198

197199
def handle_closed(self, n):
198-
pass
200+
if not self.clicked in [Notify.CLEARALL, Notify.CLOSE, Notify.LASTFIVE]:
201+
STATUS.emit('system_notify_button_pressed', Notify.BACKGROUND, True)
202+
STATUS.emit('play-sound', 'SPEAK _KILL_')
203+
self.clicked = None
199204

200205
def closeClicked(self, n, text):
206+
self.clicked = Notify.CLOSE
201207
n.close()
202208
STATUS.emit('system_notify_button_pressed', Notify.CLOSE, True)
203209
STATUS.emit('play-sound', 'SPEAK _KILL_')
204210

205211
def OnClicked(self, n, signal_text):
206-
print('1: ' + str(n))
207-
print('2: ' + str(signal_text))
212+
print(f'1: {str(n)}')
213+
print(f'2: {str(signal_text)}')
208214
n.close()
209215

210216
def action_callback(self, *args, **kwds):
@@ -214,18 +220,19 @@ def action_callback(self, *args, **kwds):
214220

215221
# pop up last five critical errors
216222
def last5_callback(self, n, signal_text):
223+
self.clicked = Notify.LASTFIVE
224+
icon = getattr(n, 'icon', None)
225+
n = self.build_error_notification(icon=icon)
217226
n.body = ''
218227
for i in range(1, 6):
219228
num = len(self.alarmpage) - i
220229
if i > len(self.alarmpage): break
221-
n.body = '{}\nREVIEW #{} of {}\n{}'.format(n.body,
222-
num +1,
223-
len(self.alarmpage),
224-
self.alarmpage[num][1])
230+
n.body = f'{n.body}\nREVIEW #{num + 1} of {len(self.alarmpage)}\n{self.alarmpage[num][1]}'
225231
n.show()
226232
STATUS.emit('system_notify_button_pressed', Notify.LASTFIVE, True)
227233

228234
def destroyClicked(self, n, signal_text):
235+
self.clicked = Notify.CLEARALL
229236
self.alarmpage = []
230237
n.body = ''
231238
STATUS.emit('system_notify_button_pressed', Notify.CLEARALL, True)
@@ -237,21 +244,23 @@ def destroyClicked(self, n, signal_text):
237244
# update the critical message display
238245
# this adds the new message to the old
239246
# show a max of 10 messages on screen
240-
def update(self, n, title='', message='', status_timeout=5, timeout=None, msgs=10):
247+
def update(self, n, icon='', title='', message='', status_timeout=5, timeout=None, msgs=10):
241248
if title is not None:
242249
n.title = title
250+
if icon:
251+
n.icon = icon
243252
if self.alarmpage ==[]:
244-
n.body = title + '\n' + message
253+
n.body = f'{title}\n{message}'
245254
elif len(self.alarmpage) < (msgs - 1):
246255
n.body = ''
247256
for i in range(len(self.alarmpage)):
248-
n.body = n.body + '\n' + self.alarmpage[i][1]
249-
n.body = n.body + '\n' + title + '\n' + message
257+
n.body += f'\n{self.alarmpage[i][1]}'
258+
n.body += f'\n{title}\n{message}'
250259
else:
251260
n.body = ''
252261
for i in range(len(self.alarmpage) - (msgs - 1), len(self.alarmpage)):
253-
n.body = n.body + '\n' + self.alarmpage[i][1]
254-
n.body = n.body + '\n' + title + '\n' + message
262+
n.body += f'\n{self.alarmpage[i][1]}'
263+
n.body += f'\n{title}\n{message}'
255264
if timeout is not None:
256265
n.setTimeout(timeout * 1000)
257266
n.show()
@@ -273,7 +282,7 @@ def show_status(self, message, timeout=4):
273282
try:
274283
messageid = self.statusbar.setText(message)
275284
except Exception as e:
276-
log.verbose('Error adding msg to statusbar: {}'.format(e))
285+
log.verbose(f'Error adding msg to statusbar: {e}')
277286

278287
# show the previous critical messages that popped up
279288
# Currently alarm page doesn't keep track of what
@@ -283,9 +292,7 @@ def show_last(self):
283292
if self.critical_message is not None:
284293
if self.alarmpage:
285294
n = self.alarmpage[num][0]
286-
n.body = 'Review #{} of {}\n{}'.format(self.lastnum + 1,
287-
len(self.alarmpage),
288-
self.alarmpage[num][1])
295+
n.body = f'Review #{self.lastnum + 1} of {len(self.alarmpage)}\n{self.alarmpage[num][1]}'
289296
n.show()
290297
self.show_status(n.body)
291298
# ready for next message if there is one, other wise reset counter

0 commit comments

Comments
 (0)