diff sat_frontends/jp/xmlui_manager.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 53a8b50d69ca
children 2594e1951cf7
line wrap: on
line diff
--- a/sat_frontends/jp/xmlui_manager.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat_frontends/jp/xmlui_manager.py	Sat Apr 08 13:54:42 2023 +0200
@@ -74,7 +74,7 @@
         """
         raise NotImplementedError(self.__class__)
 
-    def verboseName(self, elems=None, value=None):
+    def verbose_name(self, elems=None, value=None):
         """add name in color to the elements
 
         helper method to display name which can then be used to automate commands
@@ -114,7 +114,7 @@
         super(InputWidget, self).__init__(xmlui_parent, value)
         self.read_only = read_only
 
-    def _xmluiGetValue(self):
+    def _xmlui_get_value(self):
         return self.value
 
 
@@ -141,13 +141,13 @@
     def value(self, value):
         self.selected = [value]
 
-    def _xmluiSelectValue(self, value):
+    def _xmlui_select_value(self, value):
         self.value = value
 
-    def _xmluiSelectValues(self, values):
+    def _xmlui_select_values(self, values):
         self.values = values
 
-    def _xmluiGetSelectedValues(self):
+    def _xmlui_get_selected_values(self):
         return self.values
 
     @property
@@ -219,7 +219,7 @@
             self.disp(self.value)
         else:
             elems = []
-            self.verboseName(elems)
+            self.verbose_name(elems)
             if self.value:
                 elems.append(_("(enter: {value})").format(value=self.value))
             elems.extend([C.A_HEADER, "> "])
@@ -243,7 +243,7 @@
     # TODO: use a more advanced input method
 
     async def show(self):
-        self.verboseName()
+        self.verbose_name()
         if self.read_only or self.root.read_only:
             self.disp(self.value)
         else:
@@ -275,7 +275,7 @@
         # FIXME: we use bridge in a blocking way as permitted by python-dbus
         #        this only for now to make it simpler, it must be refactored
         #        to use async when jp will be fully async (expected for 0.8)
-        self.value = await self.host.bridge.syntaxConvert(
+        self.value = await self.host.bridge.syntax_convert(
             self.value, C.SYNTAX_XHTML, "markdown", False, self.host.profile
         )
         await super(XHTMLBoxWidget, self).show()
@@ -294,14 +294,14 @@
             return
 
             # list display
-        self.verboseName()
+        self.verbose_name()
 
         for idx, (value, label) in enumerate(self.options):
             elems = []
             if not self.root.read_only:
                 elems.extend([C.A_SUBHEADER, str(idx), A.RESET, ": "])
             elems.append(label)
-            self.verboseName(elems, value)
+            self.verbose_name(elems, value)
             self.disp(A.color(*elems))
 
         if self.root.read_only:
@@ -350,13 +350,13 @@
             choice = None
             while choice not in ("0", "1"):
                 elems = [C.A_HEADER, _("your choice (0,1): ")]
-                self.verboseName(elems)
+                self.verbose_name(elems)
                 choice = await self.host.ainput(A.color(*elems))
             self.value = bool(int(choice))
             self.disp("")
 
-    def _xmluiGetValue(self):
-        return C.boolConst(self.value)
+    def _xmlui_get_value(self):
+        return C.bool_const(self.value)
 
         ## Containers ##
 
@@ -371,10 +371,10 @@
     def __iter__(self):
         return iter(self.children)
 
-    def _xmluiAppend(self, widget):
+    def _xmlui_append(self, widget):
         self.children.append(widget)
 
-    def _xmluiRemove(self, widget):
+    def _xmlui_remove(self, widget):
         self.children.remove(widget)
 
     async def show(self):
@@ -486,9 +486,9 @@
             input_ = await self.host.ainput(f"{self.message} (y/n)? ")
             input_ = input_.lower()
         if input_ == "y":
-            self._xmluiValidated()
+            self._xmlui_validated()
         else:
-            self._xmluiCancelled()
+            self._xmlui_cancelled()
 
             ## Factory ##
 
@@ -502,7 +502,7 @@
 
 class XMLUIPanel(xmlui_base.AIOXMLUIPanel):
     widget_factory = WidgetFactory()
-    _actions = 0  # use to keep track of bridge's launchAction calls
+    _actions = 0  # use to keep track of bridge's action_launch calls
     read_only = False
     values_only = False
     workflow = None
@@ -557,11 +557,11 @@
         if workflow:
             XMLUIPanel.workflow = workflow
         if XMLUIPanel.workflow:
-            await self.runWorkflow()
+            await self.run_workflow()
         else:
             await self.main_cont.show()
 
-    async def runWorkflow(self):
+    async def run_workflow(self):
         """loop into workflow commands and execute commands
 
         SUBMIT will interrupt workflow (which will be continue on callback)
@@ -574,7 +574,7 @@
             except IndexError:
                 break
             if cmd == SUBMIT:
-                await self.onFormSubmitted()
+                await self.on_form_submitted()
                 self.submit_id = None  # avoid double submit
                 return
             elif isinstance(cmd, list):
@@ -585,22 +585,22 @@
                 widget.value = value
         await self.show()
 
-    async def submitForm(self, callback=None):
+    async def submit_form(self, callback=None):
         XMLUIPanel._submit_cb = callback
-        await self.onFormSubmitted()
+        await self.on_form_submitted()
 
-    async def onFormSubmitted(self, ignore=None):
+    async def on_form_submitted(self, ignore=None):
         # self.submitted is a Q&D workaround to avoid
         # double submit when a workflow is set
         if self.submitted:
             return
         self.submitted = True
-        await super(XMLUIPanel, self).onFormSubmitted(ignore)
+        await super(XMLUIPanel, self).on_form_submitted(ignore)
 
-    def _xmluiClose(self):
+    def _xmlui_close(self):
         pass
 
-    async def _launchActionCb(self, data):
+    async def _launch_action_cb(self, data):
         XMLUIPanel._actions -= 1
         assert XMLUIPanel._actions >= 0
         if "xmlui" in data:
@@ -608,7 +608,7 @@
             xmlui = create(self.host, xmlui_raw)
             await xmlui.show()
             if xmlui.submit_id:
-                await xmlui.onFormSubmitted()
+                await xmlui.on_form_submitted()
                 # TODO: handle data other than XMLUI
         if not XMLUIPanel._actions:
             if self._submit_cb is None:
@@ -616,10 +616,10 @@
             else:
                 self._submit_cb()
 
-    async def _xmluiLaunchAction(self, action_id, data):
+    async def _xmlui_launch_action(self, action_id, data):
         XMLUIPanel._actions += 1
         try:
-            data = await self.host.bridge.launchAction(
+            data = await self.host.bridge.action_launch(
                 action_id,
                 data,
                 self.profile,
@@ -628,7 +628,7 @@
             self.disp(f"can't launch XMLUI action: {e}", error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
         else:
-            await self._launchActionCb(data)
+            await self._launch_action_cb(data)
 
 
 class XMLUIDialog(xmlui_base.XMLUIDialog):
@@ -639,7 +639,7 @@
     async def show(self, __=None):
         await self.dlg.show()
 
-    def _xmluiClose(self):
+    def _xmlui_close(self):
         pass