Mon, 22 Jan 2018 00:12:51 +0000
Unsuccesfull attempts at clean quit on exceptions that fall through
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | # |
40
cfbeeec8cb82
Improved exception reporting etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
38
diff
changeset
|
2 | # Borgend MacOS UI |
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | # |
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | |
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | import rumps |
10 | 6 | import time |
7 | import datetime | |
8 | import logging | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
9 | import borgend |
40
cfbeeec8cb82
Improved exception reporting etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
38
diff
changeset
|
10 | import utils |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
11 | import backup |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
12 | from threading import Lock, Timer |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
13 | from config import settings |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
14 | import objc |
10 | 15 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
16 | logger=borgend.logger.getChild(__name__) |
31 | 17 | |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
18 | traynames={ |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
19 | backup.INACTIVE: 'B.', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
20 | backup.SCHEDULED: 'B.', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
21 | backup.ACTIVE: 'B!', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
22 | backup.BUSY: 'B⦙', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
23 | backup.OFFLINE: 'B⦙', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
24 | backup.ERRORS: 'B?' |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
25 | } |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
26 | |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
27 | statestring={ |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
28 | backup.INACTIVE: 'inactive', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
29 | backup.SCHEDULED: 'scheduled', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
30 | backup.ACTIVE: 'active', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
31 | backup.BUSY: 'busy', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
32 | backup.OFFLINE: 'offline', |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
33 | backup.ERRORS: 'errors' |
16
d0ffae5550ef
Added offline symbol B⦙ (no offline detection yet)
Tuomo Valkonen <tuomov@iki.fi>
parents:
15
diff
changeset
|
34 | } |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
35 | |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
36 | # Refresh the menu at most once a second to reduce flicker |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
37 | refresh_interval=1.0 |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
38 | |
32 | 39 | # Workaround to rumps brokenness; |
40 | # see https://github.com/jaredks/rumps/issues/59 | |
41 | def notification_workaround(title, subtitle, message): | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
42 | try: |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
43 | NSDictionary = objc.lookUpClass("NSDictionary") |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
44 | d=NSDictionary() |
32 | 45 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
46 | rumps.notification(title, subtitle, message, data=d) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
47 | except Exception as err: |
40
cfbeeec8cb82
Improved exception reporting etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
38
diff
changeset
|
48 | utils.log_exception(logger, err, |
cfbeeec8cb82
Improved exception reporting etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
38
diff
changeset
|
49 | detail='Unable to display notification') |
32 | 50 | |
19
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
51 | # Based on code snatched from |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
52 | # https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778 |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
53 | def humanbytes(B): |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
54 | 'Return the given bytes as a human friendly KB, MB, GB, or TB string' |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
55 | B = float(B) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
56 | KB = float(1024) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
57 | MB = float(KB ** 2) # 1,048,576 |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
58 | GB = float(KB ** 3) # 1,073,741,824 |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
59 | TB = float(KB ** 4) # 1,099,511,627,776 |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
60 | |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
61 | if B < KB: |
20
fdfbe5d7b677
Keychain support and random fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
19
diff
changeset
|
62 | return '{0}B'.format(B) |
19
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
63 | elif KB <= B < MB: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
64 | return '{0:.2f}KB'.format(B/KB) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
65 | elif MB <= B < GB: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
66 | return '{0:.2f}MB'.format(B/MB) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
67 | elif GB <= B < TB: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
68 | return '{0:.2f}GB'.format(B/GB) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
69 | elif TB <= B: |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
70 | return '{0:.2f}TB'.format(B/TB) |
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
71 | |
10 | 72 | def make_title(status): |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
73 | state=status['state'] |
10 | 74 | if status['type']=='scheduled': |
75 | # Operation scheduled | |
76 | when=status['when'] | |
77 | now=time.time() | |
78 | if when<now: | |
79 | whenstr='overdue' | |
80 | else: | |
81 | diff=datetime.timedelta(seconds=when-now) | |
82 | if diff.days>0: | |
83 | whenday=datetime.date.fromtimestamp(when) | |
84 | whenstr='on %s' % whenday.isoformat() | |
85 | else: | |
86 | twhen=time.localtime(when) | |
87 | if twhen.tm_sec>30: | |
88 | # Round up minute display to avoid user confusion | |
89 | twhen=time.localtime(when+30) | |
90 | whenstr='at %02d:%02d' % (twhen.tm_hour, twhen.tm_min) | |
38 | 91 | |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
92 | detail='' |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
93 | if state>=backup.BUSY and state in statestring: |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
94 | detail=statestring[state] + '; ' |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
95 | if status['detail']!='normal': |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
96 | detail=detail+status['detail']+' ' |
11
0bff53095f28
New tray title: B. or B! depending on activity
Tuomo Valkonen <tuomov@iki.fi>
parents:
10
diff
changeset
|
97 | title="%s (%s%s %s)" % (status['name'], detail, status['operation'], whenstr) |
10 | 98 | elif status['type']=='current': |
99 | # Operation running | |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
100 | progress='' |
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
101 | if 'progress_current' in status and 'progress_total' in status: |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
102 | progress=' %d%%' % (status['progress_current']/status['progress_total']) |
19
f9ce2442f14f
Display original/deduplicatd size if no progress percentage available
Tuomo Valkonen <tuomov@iki.fi>
parents:
18
diff
changeset
|
103 | elif 'original_size' in status and 'deduplicated_size' in status: |
20
fdfbe5d7b677
Keychain support and random fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
19
diff
changeset
|
104 | progress=' %s→%s' % (humanbytes(status['original_size']), |
fdfbe5d7b677
Keychain support and random fixes
Tuomo Valkonen <tuomov@iki.fi>
parents:
19
diff
changeset
|
105 | humanbytes(status['deduplicated_size'])) |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
106 | title="%s (running: %s%s)" % (status['name'], status['operation'], progress) |
10 | 107 | else: # status['type']=='nothing': |
108 | # Should be unscheduled, nothing running | |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
109 | detail='' |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
110 | if state>=backup.BUSY and state in statestring: |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
111 | detail=' (' + statestring[state] + ')' |
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
112 | title=status['name'] + detail |
15 | 113 | |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
114 | return title, state |
10 | 115 | |
1
4cdc9c1f6b28
basic scheduler structure draft, etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
116 | class BorgendTray(rumps.App): |
33
91421eeb4426
Use rumps.application_support instead of xdg paths. Also separated branding into config.py
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
117 | def __init__(self, backups): |
10 | 118 | self.lock=Lock() |
119 | self.backups=backups | |
120 | self.statuses=[None]*len(backups) | |
121 | ||
122 | with self.lock: | |
123 | # Initialise reporting callbacks and local status copy | |
124 | # (since rumps doesn't seem to be able to update menu items | |
125 | # without rebuilding the whole menu, and we don't want to lock | |
126 | # when calling Backup.status(), especially as we will be called | |
127 | # from Backup reporting its status, we keep a copy to allow | |
128 | # rebuilding the entire menu | |
129 | for index in range(len(backups)): | |
130 | b=backups[index] | |
131 | # Python closures suck dog's balls; hence the _index=index hack | |
132 | # See also http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/ | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
133 | cb=(lambda obj, status, _index=index, errors=None: |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
134 | self.__status_callback(obj, _index, status, errors)) |
10 | 135 | b.set_status_update_callback(cb) |
136 | self.statuses[index]=b.status() | |
137 | ||
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
138 | menu, state=self.__rebuild_menu() |
9
aa121291eb0e
Rumps/Mac UI stuff is fucked and disables ^C etc.; threading doesn't help
Tuomo Valkonen <tuomov@iki.fi>
parents:
1
diff
changeset
|
139 | |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
140 | self.refresh_timer=None |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
141 | |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
142 | super().__init__(traynames[state], menu=menu, quit_button=None) |
10 | 143 | |
144 | def __rebuild_menu(self): | |
145 | menu=[] | |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
146 | state=backup.INACTIVE |
10 | 147 | for index in range(len(self.backups)): |
148 | b=self.backups[index] | |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
149 | title, this_state=make_title(self.statuses[index]) |
10 | 150 | # Python closures suck dog's balls... |
151 | # first and the last program I write in Python until somebody | |
152 | # fixes this brain damage | |
153 | cbm=lambda sender, _b=b: self.__menu_select_backup(sender, _b) | |
154 | item=rumps.MenuItem(title, callback=cbm) | |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
155 | if this_state==backup.SCHEDULED: |
38 | 156 | item.state=1 |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
157 | elif this_state>=backup.BUSY: |
38 | 158 | item.state=-1 |
10 | 159 | menu.append(item) |
45
aa2a95dc6093
Further improvements to state reporting; indicate busyness if repository lock cannot be acquired
Tuomo Valkonen <tuomov@iki.fi>
parents:
42
diff
changeset
|
160 | state=backup.combine_state(state, this_state) |
10 | 161 | |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
162 | menu_log=rumps.MenuItem("Show log", callback=lambda _: showlog()) |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
163 | menu.append(menu_log) |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
164 | |
30
3dd525652dc8
Added no_quit_menu_entry option
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
165 | if not settings['no_quit_menu_entry']: |
46
ecb41072a1b7
Unsuccesfull attempts at clean quit on exceptions that fall through
Tuomo Valkonen <tuomov@iki.fi>
parents:
45
diff
changeset
|
166 | menu_quit=rumps.MenuItem("Quit...", callback=lambda _: self.quit()) |
30
3dd525652dc8
Added no_quit_menu_entry option
Tuomo Valkonen <tuomov@iki.fi>
parents:
28
diff
changeset
|
167 | menu.append(menu_quit) |
10 | 168 | |
14
5a988a2c2624
UI: progress percentange support (Borg doesn't seem to be reporting) + error indicator in tray: B?
Tuomo Valkonen <tuomov@iki.fi>
parents:
11
diff
changeset
|
169 | return menu, state |
10 | 170 | |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
171 | def refresh_ui(self): |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
172 | with self.lock: |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
173 | self.refresh_timer=None |
31 | 174 | logger.debug('Rebuilding menu') |
28 | 175 | menu, active=self.__rebuild_menu() |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
176 | self.menu.clear() |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
177 | self.menu.update(menu) |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
178 | self.title=traynames[active] |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
179 | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
180 | def __status_callback(self, obj, index, status, errorlog): |
31 | 181 | logger.debug('Status callbackup %s' % str(status)) |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
182 | |
10 | 183 | with self.lock: |
184 | self.statuses[index]=status | |
27
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
185 | if self.refresh_timer==None: |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
186 | self.refresh_timer=Timer(refresh_interval, self.refresh_ui) |
a347387868be
UI refresh delay to reduce flicker
Tuomo Valkonen <tuomov@iki.fi>
parents:
21
diff
changeset
|
187 | self.refresh_timer.start() |
10 | 188 | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
189 | if errorlog: |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
190 | if 'msgid' not in errorlog or not isinstance(errorlog['msgid'], str): |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
191 | msgid='UnknownError' |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
192 | else: |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
193 | msgid=errorlog['msgid'] |
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
194 | |
32 | 195 | logger.debug("Opening notification for error %s '%s'", |
196 | msgid, errorlog['message']) | |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
197 | |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
198 | notification_workaround(borgend.appname_stylised, |
33
91421eeb4426
Use rumps.application_support instead of xdg paths. Also separated branding into config.py
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
199 | msgid, errorlog['message']) |
21
c36e549a7f12
Errors as rumps notifications
Tuomo Valkonen <tuomov@iki.fi>
parents:
20
diff
changeset
|
200 | |
46
ecb41072a1b7
Unsuccesfull attempts at clean quit on exceptions that fall through
Tuomo Valkonen <tuomov@iki.fi>
parents:
45
diff
changeset
|
201 | def quit(self): |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
202 | logging.shutdown() |
28 | 203 | rumps.quit_application() |
204 | ||
205 | def __menu_select_backup(self, sender, b): | |
206 | #sender.state=not sender.state | |
31 | 207 | logger.debug("Manually backup '%s'", b.name) |
32 | 208 | try: |
209 | b.create(None) | |
210 | except Exception as err: | |
40
cfbeeec8cb82
Improved exception reporting etc.
Tuomo Valkonen <tuomov@iki.fi>
parents:
38
diff
changeset
|
211 | utils.log_exception(logger, err) |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
212 | notification_workaround(borgend.appname_stylised, |
33
91421eeb4426
Use rumps.application_support instead of xdg paths. Also separated branding into config.py
Tuomo Valkonen <tuomov@iki.fi>
parents:
32
diff
changeset
|
213 | err.__class__.__name__, str(err)) |
28 | 214 | |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
215 | # |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
216 | # Log window |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
217 | # |
10 | 218 | |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
219 | logwindow=[None] |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
220 | logwindow_lock=Lock() |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
221 | |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
222 | def showlog(): |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
223 | try: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
224 | w=None |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
225 | with logwindow_lock: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
226 | if not logwindow[0]: |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
227 | lines=borgend.fifolog.formatAll() |
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
228 | msg="\n".join(lines[0:]) |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
229 | w=rumps.Window(title=borgend.appname_stylised+' log', |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
230 | default_text=msg, |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
231 | ok='Close', |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
232 | dimensions=(640,320)) |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
233 | logwindow[0]=w |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
234 | if w: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
235 | try: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
236 | w.run() |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
237 | finally: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
238 | with logwindow_lock: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
239 | logwindow[0]=None |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
240 | except Exception as err: |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
241 | utils.log_exception(logger, err) |
34
9fce700d42de
Log window and other logging improvements
Tuomo Valkonen <tuomov@iki.fi>
parents:
33
diff
changeset
|
242 | |
42
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
243 | # |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
244 | # Notification click response => show log window |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
245 | # |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
246 | |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
247 | @rumps.notifications |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
248 | def notification_center(_): |
00accd11978b
Moved logwindow dispay out of BorgendTray, and made notification_center
Tuomo Valkonen <tuomov@iki.fi>
parents:
40
diff
changeset
|
249 | showlog() |