Mercurial > libervia-backend
diff sat_frontends/primitivus/xmlui.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/xmlui.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat_frontends/primitivus/xmlui.py Sat Apr 08 13:54:42 2023 +0200 @@ -38,7 +38,7 @@ """" Call xmlui callback and ignore any extra argument """ args[-1](ctrl) - def _xmluiOnChange(self, callback): + def _xmlui_on_change(self, callback): """ Call callback with widget as only argument """ urwid.connect_signal(self, "change", self._event_callback, callback) @@ -93,10 +93,10 @@ return False return super(PrimitivusStringWidget, self).selectable() - def _xmluiSetValue(self, value): + def _xmlui_set_value(self, value): self.set_edit_text(value) - def _xmluiGetValue(self): + def _xmlui_get_value(self): return self.get_edit_text() @@ -116,10 +116,10 @@ return False return super(PrimitivusPasswordWidget, self).selectable() - def _xmluiSetValue(self, value): + def _xmlui_set_value(self, value): self.set_edit_text(value) - def _xmluiGetValue(self): + def _xmlui_get_value(self): return self.get_edit_text() @@ -135,10 +135,10 @@ return False return super(PrimitivusTextBoxWidget, self).selectable() - def _xmluiSetValue(self, value): + def _xmlui_set_value(self, value): self.set_edit_text(value) - def _xmluiGetValue(self): + def _xmlui_get_value(self): return self.get_edit_text() @@ -152,10 +152,10 @@ return False return super(PrimitivusBoolWidget, self).selectable() - def _xmluiSetValue(self, value): + def _xmlui_set_value(self, value): self.set_state(value == "true") - def _xmluiGetValue(self): + def _xmlui_get_value(self): return C.BOOL_TRUE if self.get_state() else C.BOOL_FALSE @@ -169,10 +169,10 @@ return False return super(PrimitivusIntWidget, self).selectable() - def _xmluiSetValue(self, value): + def _xmlui_set_value(self, value): self.set_edit_text(value) - def _xmluiGetValue(self): + def _xmlui_get_value(self): return self.get_edit_text() @@ -182,38 +182,38 @@ def __init__(self, _xmlui_parent, value, click_callback): sat_widgets.CustomButton.__init__(self, value, on_press=click_callback) - def _xmluiOnClick(self, callback): + def _xmlui_on_click(self, callback): urwid.connect_signal(self, "click", callback) class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents): def __init__(self, _xmlui_parent, options, selected, flags): sat_widgets.List.__init__(self, options=options, style=flags) - self._xmluiSelectValues(selected) + self._xmlui_select_values(selected) - def _xmluiSelectValue(self, value): - return self.selectValue(value) + def _xmlui_select_value(self, value): + return self.select_value(value) - def _xmluiSelectValues(self, values): - return self.selectValues(values) + def _xmlui_select_values(self, values): + return self.select_values(values) - def _xmluiGetSelectedValues(self): - return [option.value for option in self.getSelectedValues()] + def _xmlui_get_selected_values(self): + return [option.value for option in self.get_selected_values()] - def _xmluiAddValues(self, values, select=True): - current_values = self.getAllValues() + def _xmlui_add_values(self, values, select=True): + current_values = self.get_all_values() new_values = copy.deepcopy(current_values) for value in values: if value not in current_values: new_values.append(value) if select: - selected = self._xmluiGetSelectedValues() - self.changeValues(new_values) + selected = self._xmlui_get_selected_values() + self.change_values(new_values) if select: for value in values: if value not in selected: selected.append(value) - self._xmluiSelectValues(selected) + self._xmlui_select_values(selected) class PrimitivusJidsListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents): @@ -224,11 +224,11 @@ option_type=lambda txt, align: sat_widgets.AdvancedEdit( edit_text=txt, align=align ), - on_change=self._onChange, + on_change=self._on_change, ) self.delete = 0 - def _onChange(self, list_widget, jid_widget=None, text=None): + def _on_change(self, list_widget, jid_widget=None, text=None): if jid_widget is not None: if jid_widget != list_widget.contents[-1] and not text: # if a field is empty, we delete the line (except for the last line) @@ -237,9 +237,9 @@ # we always want an empty field as last value to be able to add jids list_widget.contents.append(sat_widgets.AdvancedEdit()) - def _xmluiGetSelectedValues(self): + def _xmlui_get_selected_values(self): # XXX: there is not selection in this list, so we return all non empty values - return [jid_ for jid_ in self.getAllValues() if jid_] + return [jid_ for jid_ in self.get_all_values() if jid_] class PrimitivusAdvancedListContainer( @@ -253,19 +253,19 @@ self, columns=columns, options=options, row_selectable=selectable != "no" ) - def _xmluiAppend(self, widget): - self.addWidget(widget) + def _xmlui_append(self, widget): + self.add_widget(widget) - def _xmluiAddRow(self, idx): - self.setRowIndex(idx) + def _xmlui_add_row(self, idx): + self.set_row_index(idx) - def _xmluiGetSelectedWidgets(self): - return self.getSelectedWidgets() + def _xmlui_get_selected_widgets(self): + return self.get_selected_widgets() - def _xmluiGetSelectedIndex(self): - return self.getSelectedIndex() + def _xmlui_get_selected_index(self): + return self.get_selected_index() - def _xmluiOnSelect(self, callback): + def _xmlui_on_select(self, callback): """ Call callback with widget as only argument """ urwid.connect_signal(self, "click", self._event_callback, callback) @@ -277,11 +277,11 @@ options["FOCUS_ATTR"] = "param_selected" sat_widgets.TableContainer.__init__(self, columns=2, options=options) - def _xmluiAppend(self, widget): + def _xmlui_append(self, widget): if isinstance(widget, PrimitivusEmptyWidget): # we don't want highlight on empty widgets widget = urwid.AttrMap(widget, "default") - self.addWidget(widget) + self.add_widget(widget) class PrimitivusLabelContainer(PrimitivusPairsContainer, xmlui.LabelContainer): @@ -292,12 +292,12 @@ def __init__(self, _xmlui_parent): sat_widgets.TabsContainer.__init__(self) - def _xmluiAppend(self, widget): + def _xmlui_append(self, widget): self.body.append(widget) - def _xmluiAddTab(self, label, selected): + def _xmlui_add_tab(self, label, selected): tab = PrimitivusVerticalContainer(None) - self.addTab(label, tab, selected) + self.add_tab(label, tab, selected) return tab @@ -308,7 +308,7 @@ urwid.ListBox.__init__(self, urwid.SimpleListWalker([])) self._last_size = None - def _xmluiAppend(self, widget): + def _xmlui_append(self, widget): if "flow" not in widget.sizing(): widget = urwid.BoxAdapter(widget, self.BOX_HEIGHT) self.body.append(widget) @@ -331,11 +331,11 @@ def __init__(self, _xmlui_parent): self.host = _xmlui_parent.host - def _xmluiShow(self): - self.host.showPopUp(self) + def _xmlui_show(self): + self.host.show_pop_up(self) - def _xmluiClose(self): - self.host.removePopUp(self) + def _xmlui_close(self): + self.host.remove_pop_up(self) class PrimitivusMessageDialog(PrimitivusDialog, xmlui.MessageDialog, sat_widgets.Alert): @@ -343,7 +343,7 @@ PrimitivusDialog.__init__(self, _xmlui_parent) xmlui.MessageDialog.__init__(self, _xmlui_parent) sat_widgets.Alert.__init__( - self, title, message, ok_cb=lambda __: self._xmluiClose() + self, title, message, ok_cb=lambda __: self._xmlui_close() ) @@ -362,8 +362,8 @@ self, title, message, - no_cb=lambda __: self._xmluiCancelled(), - yes_cb=lambda __: self._xmluiValidated(), + no_cb=lambda __: self._xmlui_cancelled(), + yes_cb=lambda __: self._xmlui_validated(), ) @@ -379,8 +379,8 @@ style.append("dir") files_management.FileDialog.__init__( self, - ok_cb=lambda path: self._xmluiValidated({"path": path}), - cancel_cb=lambda __: self._xmluiCancelled(), + ok_cb=lambda path: self._xmlui_validated({"path": path}), + cancel_cb=lambda __: self._xmlui_cancelled(), message=message, title=title, style=style, @@ -433,7 +433,7 @@ PrimitivusWidget.__init__(self, self.main_cont, self.xmlui_title) - def _parseChilds(self, _xmlui_parent, current_node, wanted=("container",), data=None): + def _parse_childs(self, _xmlui_parent, current_node, wanted=("container",), data=None): # Small hack to always have a VerticalContainer as main container in Primitivus. # this used to be the default behaviour for all frontends, but now # TabsContainer can also be the main container. @@ -442,23 +442,23 @@ if node.nodeName == "container" and node.getAttribute("type") == "tabs": _xmlui_parent = self.widget_factory.createVerticalContainer(self) self.main_cont = _xmlui_parent - return super(XMLUIPanel, self)._parseChilds(_xmlui_parent, current_node, wanted, + return super(XMLUIPanel, self)._parse_childs(_xmlui_parent, current_node, wanted, data) - def constructUI(self, parsed_dom): - def postTreat(): + def construct_ui(self, parsed_dom): + def post_treat(): assert self.main_cont.body if self.type in ("form", "popup"): buttons = [] if self.type == "form": - buttons.append(urwid.Button(_("Submit"), self.onFormSubmitted)) + buttons.append(urwid.Button(_("Submit"), self.on_form_submitted)) if not "NO_CANCEL" in self.flags: - buttons.append(urwid.Button(_("Cancel"), self.onFormCancelled)) + buttons.append(urwid.Button(_("Cancel"), self.on_form_cancelled)) else: buttons.append( - urwid.Button(_("OK"), on_press=lambda __: self._xmluiClose()) + urwid.Button(_("OK"), on_press=lambda __: self._xmlui_close()) ) max_len = max([len(button.get_label()) for button in buttons]) grid_wid = urwid.GridFlow(buttons, max_len + 4, 1, 0, "center") @@ -467,17 +467,17 @@ tabs_cont = self.main_cont.body[0].base_widget assert isinstance(tabs_cont, sat_widgets.TabsContainer) buttons = [] - buttons.append(sat_widgets.CustomButton(_("Save"), self.onSaveParams)) + buttons.append(sat_widgets.CustomButton(_("Save"), self.on_save_params)) buttons.append( sat_widgets.CustomButton( - _("Cancel"), lambda x: self.host.removeWindow() + _("Cancel"), lambda x: self.host.remove_window() ) ) - max_len = max([button.getSize() for button in buttons]) + max_len = max([button.get_size() for button in buttons]) grid_wid = urwid.GridFlow(buttons, max_len, 1, 0, "center") - tabs_cont.addFooter(grid_wid) + tabs_cont.add_footer(grid_wid) - xmlui.XMLUIPanel.constructUI(self, parsed_dom, postTreat) + xmlui.XMLUIPanel.construct_ui(self, parsed_dom, post_treat) urwid.WidgetWrap.__init__(self, self.main_cont) def show(self, show_type=None, valign="middle"): @@ -501,18 +501,18 @@ self._dest = show_type if show_type == "popup": - self.host.showPopUp(self, valign=valign) + self.host.show_pop_up(self, valign=valign) elif show_type == "window": - self.host.newWidget(self, user_action=self.user_action) + self.host.new_widget(self, user_action=self.user_action) else: assert False self.host.redraw() - def _xmluiClose(self): + def _xmlui_close(self): if self._dest == "window": - self.host.removeWindow() + self.host.remove_window() elif self._dest == "popup": - self.host.removePopUp(self) + self.host.remove_pop_up(self) else: raise exceptions.InternalError( "self._dest unknown, are you sure you have called XMLUI.show ?" @@ -523,6 +523,6 @@ dialog_factory = GenericFactory() -xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel) -xmlui.registerClass(xmlui.CLASS_DIALOG, XMLUIDialog) +xmlui.register_class(xmlui.CLASS_PANEL, XMLUIPanel) +xmlui.register_class(xmlui.CLASS_DIALOG, XMLUIDialog) create = xmlui.create