Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- a/sat_frontends/primitivus/progress.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat_frontends/primitivus/progress.py Sat Apr 08 13:54:42 2023 +0200 @@ -34,8 +34,8 @@ self.progress_dict = {} listbox = urwid.ListBox(self.progress_list) buttons = [] - buttons.append(sat_widgets.CustomButton(_("Clear progress list"), self._onClear)) - max_len = max([button.getSize() for button in buttons]) + buttons.append(sat_widgets.CustomButton(_("Clear progress list"), self._on_clear)) + max_len = max([button.get_size() for button in buttons]) buttons_wid = urwid.GridFlow(buttons, max_len, 1, 0, "center") main_wid = sat_widgets.FocusFrame(listbox, footer=buttons_wid) urwid.WidgetWrap.__init__(self, main_wid) @@ -50,11 +50,11 @@ "state": "init", } self.progress_list.append(column) - self.progressCB(self.host.loop, (progress_id, message, profile)) + self.progress_cb(self.host.loop, (progress_id, message, profile)) - def progressCB(self, loop, data): + def progress_cb(self, loop, data): progress_id, message, profile = data - data = self.host.bridge.progressGet(progress_id, profile) + data = self.host.bridge.progress_get(progress_id, profile) pbar = self.progress_dict[(progress_id, profile)]["progress"] if data: if self.progress_dict[(progress_id, profile)]["state"] == "init": @@ -63,33 +63,33 @@ pbar.done = float(data["size"]) pbar.set_completion(float(data["position"])) - self.updateNotBar() + self.update_not_bar() else: if self.progress_dict[(progress_id, profile)]["state"] == "progress": self.progress_dict[(progress_id, profile)]["state"] = "done" pbar.set_completion(pbar.done) - self.updateNotBar() + self.update_not_bar() return - loop.set_alarm_in(0.2, self.progressCB, (progress_id, message, profile)) + loop.set_alarm_in(0.2, self.progress_cb, (progress_id, message, profile)) - def _removeBar(self, progress_id, profile): + def _remove_bar(self, progress_id, profile): wid = self.progress_dict[(progress_id, profile)]["full"] self.progress_list.remove(wid) del (self.progress_dict[(progress_id, profile)]) - def _onClear(self, button): + def _on_clear(self, button): to_remove = [] for progress_id, profile in self.progress_dict: if self.progress_dict[(progress_id, profile)]["state"] == "done": to_remove.append((progress_id, profile)) for progress_id, profile in to_remove: - self._removeBar(progress_id, profile) - self.updateNotBar() + self._remove_bar(progress_id, profile) + self.update_not_bar() - def updateNotBar(self): + def update_not_bar(self): if not self.progress_dict: - self.host.setProgress(None) + self.host.set_progress(None) return progress = 0 nb_bars = 0 @@ -98,4 +98,4 @@ progress += pbar.current / pbar.done * 100 nb_bars += 1 av_progress = progress / float(nb_bars) - self.host.setProgress(av_progress) + self.host.set_progress(av_progress)