diff cagou/core/xmlui.py @ 491:203755bbe0fe

massive refactoring from camelCase -> snake_case. See backend commit log for more details
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:44:32 +0200
parents 3c9ba4a694ef
children
line wrap: on
line diff
--- a/cagou/core/xmlui.py	Sat Apr 08 13:34:55 2023 +0200
+++ b/cagou/core/xmlui.py	Sat Apr 08 13:44:32 2023 +0200
@@ -47,7 +47,7 @@
         self._xmlui_onchange_cb = None
         self._got_focus = False
 
-    def _xmluiOnChange(self, callback):
+    def _xmlui_on_change(self, callback):
         self._xmlui_onchange_cb = callback
 
     def on_focus(self, instance, focus):
@@ -88,10 +88,10 @@
         TextInputOnChange.__init__(self)
         self.readonly = read_only
 
-    def _xmluiSetValue(self, value):
+    def _xmlui_set_value(self, value):
         self.text = value
 
-    def _xmluiGetValue(self):
+    def _xmlui_get_value(self):
         return self.text
 
 
@@ -110,7 +110,7 @@
         self.text = value
         self.callback = click_callback
 
-    def _xmluiOnClick(self, callback):
+    def _xmlui_on_click(self, callback):
         self.callback = callback
 
     def on_release(self):
@@ -155,8 +155,8 @@
         self.multi = 'single' not in flags
         self._values = []
         for option in options:
-            self.addValue(option)
-        self._xmluiSelectValues(selected)
+            self.add_value(option)
+        self._xmlui_select_values(selected)
         self._on_change = None
 
     @property
@@ -165,11 +165,11 @@
 
     def select(self, item):
         if not self.multi:
-            self._xmluiSelectValues([item.value])
+            self._xmlui_select_values([item.value])
         if self._on_change is not None:
             self._on_change(self)
 
-    def addValue(self, option, selected=False):
+    def add_value(self, option, selected=False):
         """add a value in the list
 
         @param option(tuple): value, label in a tuple
@@ -180,24 +180,24 @@
         item.selected = selected
         self.layout.add_widget(item)
 
-    def _xmluiSelectValue(self, value):
-        self._xmluiSelectValues([value])
+    def _xmlui_select_value(self, value):
+        self._xmlui_select_values([value])
 
-    def _xmluiSelectValues(self, values):
+    def _xmlui_select_values(self, values):
         for item in self.items:
             item.selected = item.value in values
             if item.selected and not self.multi:
                 self.text = item.text
 
-    def _xmluiGetSelectedValues(self):
+    def _xmlui_get_selected_values(self):
         return [item.value for item in self.items if item.selected]
 
-    def _xmluiAddValues(self, values, select=True):
+    def _xmlui_add_values(self, values, select=True):
         values = set(values).difference([c.value for c in self.items])
         for v in values:
-            self.addValue(v, select)
+            self.add_value(v, select)
 
-    def _xmluiOnChange(self, callback):
+    def _xmlui_on_change(self, callback):
         self._on_change = callback
 
 
@@ -215,10 +215,10 @@
             text=value, readonly=read_only, size=(100,25), size_hint=(1,None))
         TextInputOnChange.__init__(self)
 
-    def _xmluiSetValue(self, value):
+    def _xmlui_set_value(self, value):
         self.text = value
 
-    def _xmluiGetValue(self):
+    def _xmlui_get_value(self):
         return self.text
 
 
@@ -229,13 +229,13 @@
         if read_only:
             self.disabled = True
 
-    def _xmluiSetValue(self, value):
+    def _xmlui_set_value(self, value):
         self.active = value
 
-    def _xmluiGetValue(self):
+    def _xmlui_get_value(self):
         return C.BOOL_TRUE if self.active else C.BOOL_FALSE
 
-    def _xmluiOnChange(self, callback):
+    def _xmlui_on_change(self, callback):
         self.bind(active=lambda instance, value: callback(instance))
 
 
@@ -247,10 +247,10 @@
         if read_only:
             self.disabled = True
 
-    def _xmluiSetValue(self, value):
+    def _xmlui_set_value(self, value):
         self.text = value
 
-    def _xmluiGetValue(self):
+    def _xmlui_get_value(self):
         return self.text
 
 
@@ -263,7 +263,7 @@
         self.xmlui_parent = xmlui_parent
         BoxLayout.__init__(self)
 
-    def _xmluiAppend(self, widget):
+    def _xmlui_append(self, widget):
         self.add_widget(widget)
 
 
@@ -273,7 +273,7 @@
         self.xmlui_parent = xmlui_parent
         GridLayout.__init__(self)
 
-    def _xmluiAppend(self, widget):
+    def _xmlui_append(self, widget):
         self.add_widget(widget)
 
 
@@ -284,7 +284,7 @@
 class TabsPanelContainer(TabbedPanelItem):
     layout = properties.ObjectProperty(None)
 
-    def _xmluiAppend(self, widget):
+    def _xmlui_append(self, widget):
         self.layout.add_widget(widget)
 
 
@@ -294,7 +294,7 @@
         self.xmlui_parent = xmlui_parent
         TabbedPanel.__init__(self, do_default_tab=False)
 
-    def _xmluiAddTab(self, label, selected):
+    def _xmlui_add_tab(self, label, selected):
         tab = TabsPanelContainer(text=label)
         self.add_widget(tab)
         return tab
@@ -319,7 +319,7 @@
                 log.error("Can't find parent AdvancedListContainer")
             else:
                 if parent.selectable:
-                    self.selected = parent._xmluiToggleSelected(self)
+                    self.selected = parent._xmlui_toggle_selected(self)
 
         return super(AdvancedListRow, self).on_touch_down(touch)
 
@@ -335,7 +335,7 @@
         self._selected = []
         self._xmlui_select_cb = None
 
-    def _xmluiToggleSelected(self, row):
+    def _xmlui_toggle_selected(self, row):
         """inverse selection status of an AdvancedListRow
 
         @param row(AdvancedListRow): row to (un)select
@@ -351,27 +351,27 @@
         else:
             return False
 
-    def _xmluiAppend(self, widget):
+    def _xmlui_append(self, widget):
         if self._current_row is None:
             log.error("No row set, ignoring append")
             return
         self._current_row.add_widget(widget)
 
-    def _xmluiAddRow(self, idx):
+    def _xmlui_add_row(self, idx):
         self._current_row = AdvancedListRow()
         self._current_row.cols = self._columns
         self._current_row.index = idx
         self.add_widget(self._current_row)
 
-    def _xmluiGetSelectedWidgets(self):
+    def _xmlui_get_selected_widgets(self):
         return self._selected
 
-    def _xmluiGetSelectedIndex(self):
+    def _xmlui_get_selected_index(self):
         if not self._selected:
             return None
         return self._selected[0].index
 
-    def _xmluiOnSelect(self, callback):
+    def _xmlui_on_select(self, callback):
         """ Call callback with widget as only argument """
         self._xmlui_select_cb = callback
 
@@ -385,8 +385,8 @@
         xmlui.NoteDialog.__init__(self, _xmlui_parent)
         self.title, self.message, self.level = title, message, level
 
-    def _xmluiShow(self):
-        G.host.addNote(self.title, self.message, self.level)
+    def _xmlui_show(self):
+        G.host.add_note(self.title, self.message, self.level)
 
 
 class MessageDialog(xmlui.MessageDialog, dialog.MessageDialog):
@@ -400,16 +400,16 @@
         xmlui.MessageDialog.__init__(self, _xmlui_parent)
 
     def close_cb(self):
-        self._xmluiClose()
+        self._xmlui_close()
 
-    def _xmluiShow(self):
-        G.host.addNotifUI(self)
+    def _xmlui_show(self):
+        G.host.add_notif_ui(self)
 
-    def _xmluiClose(self, reason=None):
-        G.host.closeUI()
+    def _xmlui_close(self, reason=None):
+        G.host.close_ui()
 
     def show(self, *args, **kwargs):
-        G.host.showUI(self)
+        G.host.show_ui(self)
 
 
 class ConfirmDialog(xmlui.ConfirmDialog, dialog.ConfirmDialog):
@@ -423,22 +423,22 @@
         self.yes_cb = self.yes_cb
 
     def no_cb(self):
-        G.host.closeUI()
-        self._xmluiCancelled()
+        G.host.close_ui()
+        self._xmlui_cancelled()
 
     def yes_cb(self):
-        G.host.closeUI()
-        self._xmluiValidated()
+        G.host.close_ui()
+        self._xmlui_validated()
 
-    def _xmluiShow(self):
-        G.host.addNotifUI(self)
+    def _xmlui_show(self):
+        G.host.add_notif_ui(self)
 
-    def _xmluiClose(self, reason=None):
-        G.host.closeUI()
+    def _xmlui_close(self, reason=None):
+        G.host.close_ui()
 
     def show(self, *args, **kwargs):
         assert kwargs["force"]
-        G.host.showUI(self)
+        G.host.show_ui(self)
 
 
 class FileDialog(xmlui.FileDialog, BoxLayout):
@@ -451,26 +451,26 @@
         if filetype == C.XMLUI_DATA_FILETYPE_DIR:
             self.file_chooser.dirselect = True
 
-    def _xmluiShow(self):
-        G.host.addNotifUI(self)
+    def _xmlui_show(self):
+        G.host.add_notif_ui(self)
 
-    def _xmluiClose(self, reason=None):
+    def _xmlui_close(self, reason=None):
         # FIXME: notif UI is not removed if dialog is not shown yet
-        G.host.closeUI()
+        G.host.close_ui()
 
-    def onSelect(self, path):
+    def on_select(self, path):
         try:
             path = path[0]
         except IndexError:
             path = None
         if not path:
-            self._xmluiCancelled()
+            self._xmlui_cancelled()
         else:
-            self._xmluiValidated({'path': path})
+            self._xmlui_validated({'path': path})
 
     def show(self, *args, **kwargs):
         assert kwargs["force"]
-        G.host.showUI(self)
+        G.host.show_ui(self)
 
 
 ## Factory ##
@@ -531,7 +531,7 @@
                                   ignore=ignore,
                                   whitelist=whitelist,
                                   profile=profile)
-        self.bind(height=self.onHeight)
+        self.bind(height=self.on_height)
 
     def on_touch_down(self, touch, after=False):
         if self._skip_scroll_events:
@@ -551,33 +551,33 @@
         else:
             return super(XMLUIPanel, self).on_touch_move(touch)
 
-    def setCloseCb(self, close_cb):
+    def set_close_cb(self, close_cb):
         self.close_cb = close_cb
 
-    def _xmluiClose(self, __=None, reason=None):
+    def _xmlui_close(self, __=None, reason=None):
         if self.close_cb is not None:
             self.close_cb(self, reason)
         else:
-            G.host.closeUI()
+            G.host.close_ui()
 
-    def onParamChange(self, ctrl):
-        super(XMLUIPanel, self).onParamChange(ctrl)
+    def on_param_change(self, ctrl):
+        super(XMLUIPanel, self).on_param_change(ctrl)
         self.save_btn.disabled = False
 
-    def addPostTreat(self, callback):
+    def add_post_treat(self, callback):
         self._post_treats.append(callback)
 
-    def _postTreatCb(self):
+    def _post_treat_cb(self):
         for cb in self._post_treats:
             cb()
         del self._post_treats
 
-    def _saveButtonCb(self, button):
+    def _save_button_cb(self, button):
         button.disabled = True
-        self.onSaveParams(button)
+        self.on_save_params(button)
 
-    def constructUI(self, parsed_dom):
-        xmlui.XMLUIPanel.constructUI(self, parsed_dom, self._postTreatCb)
+    def construct_ui(self, parsed_dom):
+        xmlui.XMLUIPanel.construct_ui(self, parsed_dom, self._post_treat_cb)
         if self.xmlui_title:
             self.layout.add_widget(Title(text=self.xmlui_title))
         if isinstance(self.main_cont, TabsContainer):
@@ -586,23 +586,23 @@
         self.layout.add_widget(self.main_cont)
         if self.type == 'form':
             submit_btn = SubmitButton()
-            submit_btn.bind(on_press=self.onFormSubmitted)
+            submit_btn.bind(on_press=self.on_form_submitted)
             self.layout.add_widget(submit_btn)
             if not 'NO_CANCEL' in self.flags:
                 cancel_btn = CancelButton(text=_("Cancel"))
-                cancel_btn.bind(on_press=self.onFormCancelled)
+                cancel_btn.bind(on_press=self.on_form_cancelled)
                 self.layout.add_widget(cancel_btn)
         elif self.type == 'param':
             self.save_btn = SaveButton(text=_("Save"), disabled=True)
-            self.save_btn.bind(on_press=self._saveButtonCb)
+            self.save_btn.bind(on_press=self._save_button_cb)
             self.layout.add_widget(self.save_btn)
         elif self.type == 'window':
             cancel_btn = CancelButton(text=_("Cancel"))
             cancel_btn.bind(
-                on_press=partial(self._xmluiClose, reason=C.XMLUI_DATA_CANCELLED))
+                on_press=partial(self._xmlui_close, reason=C.XMLUI_DATA_CANCELLED))
             self.layout.add_widget(cancel_btn)
 
-    def onHeight(self, __, height):
+    def on_height(self, __, height):
         if isinstance(self.main_cont, TabsContainer):
             other_children_height = sum([c.height for c in self.layout.children
                                          if c is not self.main_cont])
@@ -610,9 +610,9 @@
 
     def show(self, *args, **kwargs):
         if not self.user_action and not kwargs.get("force", False):
-            G.host.addNotifUI(self)
+            G.host.add_notif_ui(self)
         else:
-            G.host.showUI(self)
+            G.host.show_ui(self)
 
 
 class XMLUIDialog(xmlui.XMLUIDialog):