comparison sat_frontends/primitivus/progress.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children 4b842c1fb686
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
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._on_clear))
38 max_len = max([button.getSize() for button in buttons]) 38 max_len = max([button.get_size() 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 add(self, progress_id, message, profile): 43 def add(self, progress_id, message, profile):
48 "full": column, 48 "full": column,
49 "progress": progr_wid, 49 "progress": progr_wid,
50 "state": "init", 50 "state": "init",
51 } 51 }
52 self.progress_list.append(column) 52 self.progress_list.append(column)
53 self.progressCB(self.host.loop, (progress_id, message, profile)) 53 self.progress_cb(self.host.loop, (progress_id, message, profile))
54 54
55 def progressCB(self, loop, data): 55 def progress_cb(self, loop, data):
56 progress_id, message, profile = data 56 progress_id, message, profile = data
57 data = self.host.bridge.progressGet(progress_id, profile) 57 data = self.host.bridge.progress_get(progress_id, profile)
58 pbar = self.progress_dict[(progress_id, profile)]["progress"] 58 pbar = self.progress_dict[(progress_id, profile)]["progress"]
59 if data: 59 if data:
60 if self.progress_dict[(progress_id, profile)]["state"] == "init": 60 if self.progress_dict[(progress_id, profile)]["state"] == "init":
61 # first answer, we must construct the bar 61 # first answer, we must construct the bar
62 self.progress_dict[(progress_id, profile)]["state"] = "progress" 62 self.progress_dict[(progress_id, profile)]["state"] = "progress"
63 pbar.done = float(data["size"]) 63 pbar.done = float(data["size"])
64 64
65 pbar.set_completion(float(data["position"])) 65 pbar.set_completion(float(data["position"]))
66 self.updateNotBar() 66 self.update_not_bar()
67 else: 67 else:
68 if self.progress_dict[(progress_id, profile)]["state"] == "progress": 68 if self.progress_dict[(progress_id, profile)]["state"] == "progress":
69 self.progress_dict[(progress_id, profile)]["state"] = "done" 69 self.progress_dict[(progress_id, profile)]["state"] = "done"
70 pbar.set_completion(pbar.done) 70 pbar.set_completion(pbar.done)
71 self.updateNotBar() 71 self.update_not_bar()
72 return 72 return
73 73
74 loop.set_alarm_in(0.2, self.progressCB, (progress_id, message, profile)) 74 loop.set_alarm_in(0.2, self.progress_cb, (progress_id, message, profile))
75 75
76 def _removeBar(self, progress_id, profile): 76 def _remove_bar(self, progress_id, profile):
77 wid = self.progress_dict[(progress_id, profile)]["full"] 77 wid = self.progress_dict[(progress_id, profile)]["full"]
78 self.progress_list.remove(wid) 78 self.progress_list.remove(wid)
79 del (self.progress_dict[(progress_id, profile)]) 79 del (self.progress_dict[(progress_id, profile)])
80 80
81 def _onClear(self, button): 81 def _on_clear(self, button):
82 to_remove = [] 82 to_remove = []
83 for progress_id, profile in self.progress_dict: 83 for progress_id, profile in self.progress_dict:
84 if self.progress_dict[(progress_id, profile)]["state"] == "done": 84 if self.progress_dict[(progress_id, profile)]["state"] == "done":
85 to_remove.append((progress_id, profile)) 85 to_remove.append((progress_id, profile))
86 for progress_id, profile in to_remove: 86 for progress_id, profile in to_remove:
87 self._removeBar(progress_id, profile) 87 self._remove_bar(progress_id, profile)
88 self.updateNotBar() 88 self.update_not_bar()
89 89
90 def updateNotBar(self): 90 def update_not_bar(self):
91 if not self.progress_dict: 91 if not self.progress_dict:
92 self.host.setProgress(None) 92 self.host.set_progress(None)
93 return 93 return
94 progress = 0 94 progress = 0
95 nb_bars = 0 95 nb_bars = 0
96 for progress_id, profile in self.progress_dict: 96 for progress_id, profile in self.progress_dict:
97 pbar = self.progress_dict[(progress_id, profile)]["progress"] 97 pbar = self.progress_dict[(progress_id, profile)]["progress"]
98 progress += pbar.current / pbar.done * 100 98 progress += pbar.current / pbar.done * 100
99 nb_bars += 1 99 nb_bars += 1
100 av_progress = progress / float(nb_bars) 100 av_progress = progress / float(nb_bars)
101 self.host.setProgress(av_progress) 101 self.host.set_progress(av_progress)