Mercurial > libervia-desktop-kivy
diff cagou/core/common.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/common.py Sat Apr 08 13:34:55 2023 +0200 +++ b/cagou/core/common.py Sat Apr 08 13:44:32 2023 +0200 @@ -53,11 +53,11 @@ def on_kv_post(self, __): if not self.source: - self.source = G.host.getDefaultAvatar() + self.source = G.host.get_default_avatar() def on_data(self, __, data): if data is None: - self.source = G.host.getDefaultAvatar() + self.source = G.host.get_default_avatar() else: self.source = data['path'] @@ -84,9 +84,9 @@ def on_kv_post(self, __): if ((self.profile and self.jid and self.data is not None and ('avatar' not in self.data or 'nicknames' not in self.data))): - G.host.bridge.identityGet( + G.host.bridge.identity_get( self.jid, ['avatar', 'nicknames'], True, self.profile, - callback=self._identityGetCb, + callback=self._identity_get_cb, errback=partial( G.host.errback, message=_("Can't retrieve identity for {jid}: {{msg}}").format( @@ -94,7 +94,7 @@ ) ) - def _identityGetCb(self, identity_raw): + def _identity_get_cb(self, identity_raw): identity_data = data_format.deserialise(identity_raw) self.data.update(identity_data) @@ -131,25 +131,25 @@ def on_avatar(self, wid, jid_): if self.jid and self.profile: - self.getImage() + self.get_image() def on_jid(self, wid, jid_): if self.profile and self.avatar: - self.getImage() + self.get_image() def on_profile(self, wid, profile): if self.jid and self.avatar: - self.getImage() + self.get_image() - def getImage(self): + def get_image(self): host = G.host - if host.contact_lists[self.profile].isRoom(self.jid.bare): + if host.contact_lists[self.profile].is_room(self.jid.bare): self.avatar.opacity = 0 self.avatar.source = "" else: self.avatar.source = ( - host.getAvatar(self.jid, profile=self.profile) - or host.getDefaultAvatar(self.jid) + host.get_avatar(self.jid, profile=self.profile) + or host.get_default_avatar(self.jid) ) @@ -315,36 +315,36 @@ def on_parent(self, wid, parent): if parent is None: log.debug("removing listeners") - G.host.removeListener("contactsFilled", self.onContactsFilled) - G.host.removeListener("notification", self.onNotification) - G.host.removeListener("notificationsClear", self.onNotificationsClear) + G.host.removeListener("contactsFilled", self.on_contacts_filled) + G.host.removeListener("notification", self.on_notification) + G.host.removeListener("notificationsClear", self.on_notifications_clear) G.host.removeListener( - "widgetNew", self.onWidgetNew, ignore_missing=True) + "widgetNew", self.on_widget_new, ignore_missing=True) G.host.removeListener( - "widgetDeleted", self.onWidgetDeleted, ignore_missing=True) + "widgetDeleted", self.on_widget_deleted, ignore_missing=True) else: log.debug("adding listeners") - G.host.addListener("contactsFilled", self.onContactsFilled) - G.host.addListener("notification", self.onNotification) - G.host.addListener("notificationsClear", self.onNotificationsClear) + G.host.addListener("contactsFilled", self.on_contacts_filled) + G.host.addListener("notification", self.on_notification) + G.host.addListener("notificationsClear", self.on_notifications_clear) - def onContactsFilled(self, profile): - log.debug("onContactsFilled event received") + def on_contacts_filled(self, profile): + log.debug("on_contacts_filled event received") self.update() - def onNotification(self, entity, notification_data, profile): + def on_notification(self, entity, notification_data, profile): for item in self.items_map.get(entity.bare, []): - notifs = list(G.host.getNotifs(entity.bare, profile=profile)) + notifs = list(G.host.get_notifs(entity.bare, profile=profile)) item.badge_text = str(len(notifs)) - def onNotificationsClear(self, entity, type_, profile): + def on_notifications_clear(self, entity, type_, profile): for item in self.items_map.get(entity.bare, []): item.badge_text = '' - def onWidgetNew(self, wid): + def on_widget_new(self, wid): if not isinstance(wid, quick_chat.QuickChat): return - item = self.getItemFromWid(wid) + item = self.get_item_from_wid(wid) if item is None: return idx = 0 @@ -354,7 +354,7 @@ idx+=1 self.opened_chats.add_widget(item, index=idx) - def onWidgetDeleted(self, wid): + def on_widget_deleted(self, wid): if not isinstance(wid, quick_chat.QuickChat): return @@ -365,7 +365,7 @@ self.opened_chats.remove_widget(child) break - def _createItem(self, **kwargs): + def _create_item(self, **kwargs): item = self.item_class(**kwargs) jid = kwargs['jid'] self.items_map.setdefault(jid, []).append(item) @@ -377,11 +377,11 @@ for item in self.to_show: if isinstance(item, str): if item == 'roster': - self.addRosterItems() + self.add_roster_items() elif item == 'bookmarks': - self.addBookmarksItems() + self.add_bookmarks_items() elif item == 'opened_chats': - self.addOpenedChatsItems() + self.add_opened_chats_items() else: log.error(f'unknown "to_show" magic string {item!r}') elif isinstance(item, Widget): @@ -389,13 +389,13 @@ elif callable(item): items_kwargs = item() for item_kwargs in items_kwargs: - item = self._createItem(**items_kwargs) + item = self._create_item(**items_kwargs) item.bind(on_press=partial(self.dispatch, 'on_select')) self.layout.add_widget(item) else: log.error(f"unmanaged to_show item type: {item!r}") - def addCategoryLayout(self, label=None): + def add_category_layout(self, label=None): category_layout = JidSelectorCategoryLayout() if label and self.add_separators: @@ -405,16 +405,16 @@ self.items_layouts.append(category_layout) return category_layout - def getItemFromWid(self, wid): + def get_item_from_wid(self, wid): """create JidSelector item from QuickChat widget""" contact_list = G.host.contact_lists[wid.profile] try: - data=contact_list.getItem(wid.target) + data=contact_list.get_item(wid.target) except KeyError: log.warning(f"Can't find item data for {wid.target}") data={} try: - item = self._createItem( + item = self._create_item( jid=wid.target, data=data, profile=wid.profile, @@ -422,42 +422,42 @@ except Exception as e: log.warning(f"Can't add contact {wid.target}: {e}") return - notifs = list(G.host.getNotifs(wid.target, profile=wid.profile)) + notifs = list(G.host.get_notifs(wid.target, profile=wid.profile)) if notifs: item.badge_text = str(len(notifs)) item.bind(on_press=partial(self.dispatch, 'on_select')) return item - def addOpenedChatsItems(self): - G.host.addListener("widgetNew", self.onWidgetNew) - G.host.addListener("widgetDeleted", self.onWidgetDeleted) - self.opened_chats = category_layout = self.addCategoryLayout(_("Opened chats")) - widgets = sorted(G.host.widgets.getWidgets( + def add_opened_chats_items(self): + G.host.addListener("widgetNew", self.on_widget_new) + G.host.addListener("widgetDeleted", self.on_widget_deleted) + self.opened_chats = category_layout = self.add_category_layout(_("Opened chats")) + widgets = sorted(G.host.widgets.get_widgets( quick_chat.QuickChat, profiles = G.host.profiles, with_duplicates=False)) for wid in widgets: - item = self.getItemFromWid(wid) + item = self.get_item_from_wid(wid) if item is None: continue category_layout.add_widget(item) - def addRosterItems(self): - self.roster = category_layout = self.addCategoryLayout(_("Your contacts")) + def add_roster_items(self): + self.roster = category_layout = self.add_category_layout(_("Your contacts")) for profile in G.host.profiles: contact_list = G.host.contact_lists[profile] for entity_jid in sorted(contact_list.roster): - item = self._createItem( + item = self._create_item( jid=entity_jid, - data=contact_list.getItem(entity_jid), + data=contact_list.get_item(entity_jid), profile=profile, ) item.bind(on_press=partial(self.dispatch, 'on_select')) category_layout.add_widget(item) - def addBookmarksItems(self): - self.bookmarks = category_layout = self.addCategoryLayout(_("Your chat rooms")) + def add_bookmarks_items(self): + self.bookmarks = category_layout = self.add_category_layout(_("Your chat rooms")) for profile in G.host.profiles: profile_manager = G.host.profiles[profile] try: @@ -469,10 +469,10 @@ contact_list = G.host.contact_lists[profile] for entity_jid in bookmarks: try: - cache = contact_list.getItem(entity_jid) + cache = contact_list.get_item(entity_jid) except KeyError: cache = {} - item = self._createItem( + item = self._create_item( jid=entity_jid, data=cache, profile=profile,