Mercurial > libervia-backend
comparison frontends/src/primitivus/progress.py @ 1636:e00f450c25fc
primitivus: fixed progress panel
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 20 Nov 2015 01:57:18 +0100 |
parents | 069ad98b360d |
children | d17772b0fe22 |
comparison
equal
deleted
inserted
replaced
1635:591e04f0103c | 1636:e00f450c25fc |
---|---|
32 self.host = host | 32 self.host = host |
33 self.progress_list = urwid.SimpleListWalker([]) | 33 self.progress_list = urwid.SimpleListWalker([]) |
34 self.progress_dict = {} | 34 self.progress_dict = {} |
35 listbox = urwid.ListBox(self.progress_list) | 35 listbox = urwid.ListBox(self.progress_list) |
36 buttons = [] | 36 buttons = [] |
37 buttons.append(sat_widgets.CustomButton(_('Clear progress list'), self.__onClear)) | 37 buttons.append(sat_widgets.CustomButton(_('Clear progress list'), self._onClear)) |
38 max_len = max([button.getSize() for button in buttons]) | 38 max_len = max([button.getSize() for button in buttons]) |
39 buttons_wid = urwid.GridFlow(buttons,max_len,1,0,'center') | 39 buttons_wid = urwid.GridFlow(buttons,max_len,1,0,'center') |
40 main_wid = sat_widgets.FocusFrame(listbox, footer=buttons_wid) | 40 main_wid = sat_widgets.FocusFrame(listbox, footer=buttons_wid) |
41 urwid.WidgetWrap.__init__(self, main_wid) | 41 urwid.WidgetWrap.__init__(self, main_wid) |
42 | 42 |
43 def addProgress(self, progress_id, message): | 43 def add(self, progress_id, message, profile): |
44 profile = self.host.profile # TODO: manage multiple profiles | |
45 mess_wid = urwid.Text(message) | 44 mess_wid = urwid.Text(message) |
46 progr_wid = urwid.ProgressBar('progress_normal', 'progress_complete') | 45 progr_wid = urwid.ProgressBar('progress_normal', 'progress_complete') |
47 column = urwid.Columns([mess_wid, progr_wid]) | 46 column = urwid.Columns([mess_wid, progr_wid]) |
48 self.progress_dict[(progress_id, profile)] = {'full':column,'progress':progr_wid,'state':'init'} | 47 self.progress_dict[(progress_id, profile)] = {'full':column,'progress':progr_wid,'state':'init'} |
49 self.progress_list.append(column) | 48 self.progress_list.append(column) |
50 self.progressCB(self.host.loop, (progress_id, message, profile)) | 49 self.progressCB(self.host.loop, (progress_id, message, profile)) |
51 | 50 |
52 def progressCB(self, loop, data): | 51 def progressCB(self, loop, data): |
53 progress_id, message, profile = data | 52 progress_id, message, profile = data |
54 data = self.host.bridge.getProgress(progress_id, profile) | 53 data = self.host.bridge.progressGet(progress_id, profile) |
55 pbar = self.progress_dict[(progress_id, profile)]['progress'] #FIXME: must manage profiles | 54 pbar = self.progress_dict[(progress_id, profile)]['progress'] |
56 if data: | 55 if data: |
57 if self.progress_dict[(progress_id, profile)]['state'] == 'init': | 56 if self.progress_dict[(progress_id, profile)]['state'] == 'init': |
58 #first answer, we must construct the bar | 57 #first answer, we must construct the bar |
59 self.progress_dict[(progress_id, profile)]['state'] = 'progress' | 58 self.progress_dict[(progress_id, profile)]['state'] = 'progress' |
60 pbar.done = float(data['size']) | 59 pbar.done = float(data['size']) |
66 self.progress_dict[(progress_id, profile)]['state'] = 'done' | 65 self.progress_dict[(progress_id, profile)]['state'] = 'done' |
67 pbar.set_completion(pbar.done) | 66 pbar.set_completion(pbar.done) |
68 self.updateNotBar() | 67 self.updateNotBar() |
69 return | 68 return |
70 | 69 |
71 loop.set_alarm_in(1,self.progressCB, (progress_id, message, profile)) | 70 loop.set_alarm_in(0.2,self.progressCB, (progress_id, message, profile)) |
72 | 71 |
73 def __removeBar(self, progress_id, profile): | 72 def _removeBar(self, progress_id, profile): |
74 wid = self.progress_dict[(progress_id, profile)]['full'] | 73 wid = self.progress_dict[(progress_id, profile)]['full'] |
75 self.progress_list.remove(wid) | 74 self.progress_list.remove(wid) |
76 del(self.progress_dict[(progress_id, profile)]) | 75 del(self.progress_dict[(progress_id, profile)]) |
77 | 76 |
78 def __onClear(self, button): | 77 def _onClear(self, button): |
79 to_remove = [] | 78 to_remove = [] |
80 for progress_id, profile in self.progress_dict: | 79 for progress_id, profile in self.progress_dict: |
81 if self.progress_dict[(progress_id, profile)]['state'] == 'done': | 80 if self.progress_dict[(progress_id, profile)]['state'] == 'done': |
82 to_remove.append((progress_id, profile)) | 81 to_remove.append((progress_id, profile)) |
83 for progress_id, profile in to_remove: | 82 for progress_id, profile in to_remove: |
84 self.__removeBar(progress_id, profile) | 83 self._removeBar(progress_id, profile) |
85 self.updateNotBar() | 84 self.updateNotBar() |
86 | 85 |
87 def updateNotBar(self): | 86 def updateNotBar(self): |
88 if not self.progress_dict: | 87 if not self.progress_dict: |
89 self.host.setProgress(None) | 88 self.host.setProgress(None) |