diff sat_frontends/primitivus/contact_list.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/contact_list.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat_frontends/primitivus/contact_list.py	Sat Apr 08 13:54:42 2023 +0200
@@ -46,21 +46,21 @@
 
         # we now build the widget
         self.status_bar = StatusBar(host)
-        self.frame = sat_widgets.FocusFrame(self._buildList(), None, self.status_bar)
+        self.frame = sat_widgets.FocusFrame(self._build_list(), None, self.status_bar)
         PrimitivusWidget.__init__(self, self.frame, _("Contacts"))
         if on_click:
             urwid.connect_signal(self, "click", on_click, user_data)
         if on_change:
             urwid.connect_signal(self, "change", on_change, user_data)
-        self.host.addListener("notification", self.onNotification, [self.profile])
-        self.host.addListener("notificationsClear", self.onNotification, [self.profile])
-        self.postInit()
+        self.host.addListener("notification", self.on_notification, [self.profile])
+        self.host.addListener("notificationsClear", self.on_notification, [self.profile])
+        self.post_init()
 
     def update(self, entities=None, type_=None, profile=None):
         """Update display, keep focus"""
         # FIXME: full update is done each time, must handle entities, type_ and profile
         widget, position = self.frame.body.get_focus()
-        self.frame.body = self._buildList()
+        self.frame.body = self._build_list()
         if position:
             try:
                 self.frame.body.focus_position = position
@@ -85,27 +85,27 @@
         elif (
             key == a_key["DISCONNECTED_HIDE"]
         ):  # user wants to (un)hide disconnected contacts
-            self.host.bridge.setParam(
+            self.host.bridge.param_set(
                 C.SHOW_OFFLINE_CONTACTS,
-                C.boolConst(not self.contact_list.show_disconnected),
+                C.bool_const(not self.contact_list.show_disconnected),
                 "General",
                 profile_key=self.profile,
             )
         elif key == a_key["RESOURCES_HIDE"]:  # user wants to (un)hide contacts resources
-            self.contact_list.showResources(not self.contact_list.show_resources)
+            self.contact_list.show_resources(not self.contact_list.show_resources)
             self.update()
         return super(ContactList, self).keypress(size, key)
 
     # QuickWidget methods
 
     @staticmethod
-    def getWidgetHash(target, profiles):
+    def get_widget_hash(target, profiles):
         profiles = sorted(profiles)
         return tuple(profiles)
 
     # modify the contact list
 
-    def setFocus(self, text, select=False):
+    def set_focus(self, text, select=False):
         """give focus to the first element that matches the given text. You can also
         pass in text a sat_frontends.tools.jid.JID (it's a subclass of unicode).
 
@@ -117,7 +117,7 @@
             try:
                 if isinstance(widget, sat_widgets.ClickableText):
                     # contact group
-                    value = widget.getValue()
+                    value = widget.get_value()
                 elif isinstance(widget, sat_widgets.SelectableText):
                     # contact or muc
                     value = widget.data
@@ -128,36 +128,36 @@
                 if text.strip() == value.strip():
                     self.frame.body.focus_position = idx
                     if select:
-                        self._contactClicked(False, widget, True)
+                        self._contact_clicked(False, widget, True)
                     return
             except AttributeError:
                 pass
             idx += 1
 
-        log.debug("Not element found for {} in setFocus".format(text))
+        log.debug("Not element found for {} in set_focus".format(text))
 
     # events
 
-    def _groupClicked(self, group_wid):
-        group = group_wid.getValue()
-        data = self.contact_list.getGroupData(group)
+    def _group_clicked(self, group_wid):
+        group = group_wid.get_value()
+        data = self.contact_list.get_group_data(group)
         data[C.GROUP_DATA_FOLDED] = not data.setdefault(C.GROUP_DATA_FOLDED, False)
-        self.setFocus(group)
+        self.set_focus(group)
         self.update()
 
-    def _contactClicked(self, use_bare_jid, contact_wid, selected):
+    def _contact_clicked(self, use_bare_jid, contact_wid, selected):
         """Method called when a contact is clicked
 
-        @param use_bare_jid: True if use_bare_jid is set in self._buildEntityWidget.
+        @param use_bare_jid: True if use_bare_jid is set in self._build_entity_widget.
         @param contact_wid: widget of the contact, must have the entity set in data attribute
         @param selected: boolean returned by the widget, telling if it is selected
         """
         entity = contact_wid.data
-        self.host.modeHint(C.MODE_INSERTION)
+        self.host.mode_hint(C.MODE_INSERTION)
         self._emit("click", entity)
 
-    def onNotification(self, entity, notif, profile):
-        notifs = list(self.host.getNotifs(C.ENTITY_ALL, profile=self.profile))
+    def on_notification(self, entity, notif, profile):
+        notifs = list(self.host.get_notifs(C.ENTITY_ALL, profile=self.profile))
         if notifs:
             self.title_dynamic = "({})".format(len(notifs))
         else:
@@ -166,7 +166,7 @@
 
     # Methods to build the widget
 
-    def _buildEntityWidget(
+    def _build_entity_widget(
         self,
         entity,
         keys=None,
@@ -222,10 +222,10 @@
             entity_attr = "default"
 
         notifs = list(
-            self.host.getNotifs(entity, exact_jid=special, profile=self.profile)
+            self.host.get_notifs(entity, exact_jid=special, profile=self.profile)
         )
         mentions = list(
-                self.host.getNotifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile)
+                self.host.get_notifs(entity.bare, C.NOTIFY_MENTION, profile=self.profile)
             )
         if notifs or mentions:
             attr = 'cl_mention' if mentions else 'cl_notifs'
@@ -245,11 +245,11 @@
         widget.data = entity
         widget.comp = entity_txt.lower()  # value to use for sorting
         urwid.connect_signal(
-            widget, "change", self._contactClicked, user_args=[use_bare_jid]
+            widget, "change", self._contact_clicked, user_args=[use_bare_jid]
         )
         return widget
 
-    def _buildEntities(self, content, entities):
+    def _build_entities(self, content, entities):
         """Add entity representation in widget list
 
         @param content: widget list, e.g. SimpleListWalker
@@ -262,7 +262,7 @@
         for entity in entities:
             if (
                 entity in self.contact_list._specials
-                or not self.contact_list.entityVisible(entity)
+                or not self.contact_list.entity_visible(entity)
             ):
                 continue
             markup_extra = []
@@ -288,7 +288,7 @@
                     status = self.contact_list.getCache(entity, "status", default=None)
                     status_disp = ("status", "\n  " + status) if status else ""
                     markup_extra.append(status_disp)
-            widget = self._buildEntityWidget(
+            widget = self._build_entity_widget(
                 entity,
                 ("cache_nick", "cache_name", "node"),
                 use_bare_jid=True,
@@ -301,22 +301,22 @@
         for widget in widgets:
             content.append(widget)
 
-    def _buildSpecials(self, content):
+    def _build_specials(self, content):
         """Build the special entities"""
-        specials = sorted(self.contact_list.getSpecials())
+        specials = sorted(self.contact_list.get_specials())
         current = None
         for entity in specials:
             if current is not None and current.bare == entity.bare:
                 # nested entity (e.g. MUC private conversations)
-                widget = self._buildEntityWidget(
+                widget = self._build_entity_widget(
                     entity, ("resource",), markup_prepend="  ", special=True
                 )
             else:
                 # the special widgets
                 if entity.resource:
-                    widget = self._buildEntityWidget(entity, ("resource",), special=True)
+                    widget = self._build_entity_widget(entity, ("resource",), special=True)
                 else:
-                    widget = self._buildEntityWidget(
+                    widget = self._build_entity_widget(
                         entity,
                         ("cache_nick", "cache_name", "node"),
                         with_show_attr=False,
@@ -324,30 +324,30 @@
                     )
             content.append(widget)
 
-    def _buildList(self):
+    def _build_list(self):
         """Build the main contact list widget"""
         content = urwid.SimpleListWalker([])
 
-        self._buildSpecials(content)
+        self._build_specials(content)
         if self.contact_list._specials:
             content.append(urwid.Divider("="))
 
         groups = list(self.contact_list._groups)
         groups.sort(key=lambda x: x.lower() if x else '')
         for group in groups:
-            data = self.contact_list.getGroupData(group)
+            data = self.contact_list.get_group_data(group)
             folded = data.get(C.GROUP_DATA_FOLDED, False)
             jids = list(data["jids"])
             if group is not None and (
-                self.contact_list.anyEntityVisible(jids)
+                self.contact_list.any_entity_visible(jids)
                 or self.contact_list.show_empty_groups
             ):
                 header = "[-]" if not folded else "[+]"
                 widget = sat_widgets.ClickableText(group, header=header + " ")
                 content.append(widget)
-                urwid.connect_signal(widget, "click", self._groupClicked)
+                urwid.connect_signal(widget, "click", self._group_clicked)
             if not folded:
-                self._buildEntities(content, jids)
+                self._build_entities(content, jids)
         not_in_roster = (
             set(self.contact_list._cache)
             .difference(self.contact_list._roster)
@@ -356,7 +356,7 @@
         )
         if not_in_roster:
             content.append(urwid.Divider("-"))
-            self._buildEntities(content, not_in_roster)
+            self._build_entities(content, not_in_roster)
 
         return urwid.ListBox(content)