Mercurial > libervia-backend
diff sat_frontends/primitivus/profile_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 | be6d91572633 |
children | 4b842c1fb686 |
line wrap: on
line diff
--- a/sat_frontends/primitivus/profile_manager.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat_frontends/primitivus/profile_manager.py Sat Apr 08 13:54:42 2023 +0200 @@ -32,21 +32,21 @@ def __init__(self, host, autoconnect=None): QuickProfileManager.__init__(self, host, autoconnect) - # login & password box must be created before list because of onProfileChange + # login & password box must be created before list because of on_profile_change self.login_wid = sat_widgets.AdvancedEdit(_("Login:"), align="center") self.pass_wid = sat_widgets.Password(_("Password:"), align="center") style = ["no_first_select"] - profiles = host.bridge.profilesListGet() + profiles = host.bridge.profiles_list_get() profiles.sort() self.list_profile = sat_widgets.List( - profiles, style=style, align="center", on_change=self.onProfileChange + profiles, style=style, align="center", on_change=self.on_profile_change ) # new & delete buttons buttons = [ - urwid.Button(_("New"), self.onNewProfile), - urwid.Button(_("Delete"), self.onDeleteProfile), + urwid.Button(_("New"), self.on_new_profile), + urwid.Button(_("Delete"), self.on_delete_profile), ] buttons_flow = urwid.GridFlow( buttons, @@ -61,7 +61,7 @@ # connect button connect_button = sat_widgets.CustomButton( - _("Connect"), self.onConnectProfiles, align="center" + _("Connect"), self.on_connect_profiles, align="center" ) # we now build the widget @@ -87,7 +87,7 @@ def keypress(self, size, key): if key == a_key["APP_QUIT"]: - self.host.onExit() + self.host.on_exit() raise urwid.ExitMainLoop() elif key in (a_key["FOCUS_UP"], a_key["FOCUS_DOWN"]): focus_diff = 1 if key == a_key["FOCUS_DOWN"] else -1 @@ -107,122 +107,122 @@ return return super(ProfileManager, self).keypress(size, key) - def cancelDialog(self, button): - self.host.removePopUp() + def cancel_dialog(self, button): + self.host.remove_pop_up() - def newProfile(self, button, edit): + def new_profile(self, button, edit): """Create the profile""" name = edit.get_edit_text() - self.host.bridge.profileCreate( + self.host.bridge.profile_create( name, - callback=lambda: self.newProfileCreated(name), - errback=self.profileCreationFailure, + callback=lambda: self.new_profile_created(name), + errback=self.profile_creation_failure, ) - def newProfileCreated(self, profile): + def new_profile_created(self, profile): # new profile will be selected, and a selected profile assume the session is started - self.host.bridge.profileStartSession( + self.host.bridge.profile_start_session( "", profile, - callback=lambda __: self.newProfileSessionStarted(profile), - errback=self.profileCreationFailure, + callback=lambda __: self.new_profile_session_started(profile), + errback=self.profile_creation_failure, ) - def newProfileSessionStarted(self, profile): - self.host.removePopUp() - self.refillProfiles() - self.list_profile.selectValue(profile) + def new_profile_session_started(self, profile): + self.host.remove_pop_up() + self.refill_profiles() + self.list_profile.select_value(profile) self.current.profile = profile - self.getConnectionParams(profile) + self.get_connection_params(profile) self.host.redraw() - def profileCreationFailure(self, reason): - self.host.removePopUp() - message = self._getErrorMessage(reason) + def profile_creation_failure(self, reason): + self.host.remove_pop_up() + message = self._get_error_message(reason) self.host.alert(_("Can't create profile"), message) - def deleteProfile(self, button): - self._deleteProfile() - self.host.removePopUp() + def delete_profile(self, button): + self._delete_profile() + self.host.remove_pop_up() - def onNewProfile(self, e): + def on_new_profile(self, e): pop_up_widget = sat_widgets.InputDialog( _("New profile"), _("Please enter a new profile name"), - cancel_cb=self.cancelDialog, - ok_cb=self.newProfile, + cancel_cb=self.cancel_dialog, + ok_cb=self.new_profile, ) - self.host.showPopUp(pop_up_widget) + self.host.show_pop_up(pop_up_widget) - def onDeleteProfile(self, e): + def on_delete_profile(self, e): if self.current.profile: pop_up_widget = sat_widgets.ConfirmDialog( _("Are you sure you want to delete the profile {} ?").format( self.current.profile ), - no_cb=self.cancelDialog, - yes_cb=self.deleteProfile, + no_cb=self.cancel_dialog, + yes_cb=self.delete_profile, ) - self.host.showPopUp(pop_up_widget) + self.host.show_pop_up(pop_up_widget) - def onConnectProfiles(self, button): + def on_connect_profiles(self, button): """Connect the profiles and start the main widget @param button: the connect button """ - self._onConnectProfiles() + self._on_connect_profiles() - def resetFields(self): + def reset_fields(self): """Set profile to None, and reset fields""" - super(ProfileManager, self).resetFields() - self.list_profile.unselectAll(invisible=True) + super(ProfileManager, self).reset_fields() + self.list_profile.unselect_all(invisible=True) - def setProfiles(self, profiles): + def set_profiles(self, profiles): """Update the list of profiles""" - self.list_profile.changeValues(profiles) + self.list_profile.change_values(profiles) self.host.redraw() - def getProfiles(self): - return self.list_profile.getSelectedValues() + def get_profiles(self): + return self.list_profile.get_selected_values() - def getJID(self): + def get_jid(self): return self.login_wid.get_edit_text() def getPassword(self): return self.pass_wid.get_edit_text() - def setJID(self, jid_): + def set_jid(self, jid_): self.login_wid.set_edit_text(jid_) self.current.login = jid_ self.host.redraw() # FIXME: redraw should be avoided - def setPassword(self, password): + def set_password(self, password): self.pass_wid.set_edit_text(password) self.current.password = password self.host.redraw() - def onProfileChange(self, list_wid, widget=None, selected=None): + def on_profile_change(self, list_wid, widget=None, selected=None): """This is called when a profile is selected in the profile list. @param list_wid: the List widget who sent the event """ - self.updateConnectionParams() + self.update_connection_params() focused = list_wid.focus - selected = focused.getState() if focused is not None else False + selected = focused.get_state() if focused is not None else False if not selected: # profile was just unselected return - focused.setState( + focused.set_state( False, invisible=True ) # we don't want the widget to be selected until we are sure we can access it def authenticate_cb(data, cb_id, profile): if C.bool(data.pop("validated", C.BOOL_FALSE)): self.current.profile = profile - focused.setState(True, invisible=True) - self.getConnectionParams(profile) + focused.set_state(True, invisible=True) + self.get_connection_params(profile) self.host.redraw() - self.host.actionManager(data, callback=authenticate_cb, profile=profile) + self.host.action_manager(data, callback=authenticate_cb, profile=profile) - self.host.launchAction( + self.host.action_launch( C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=focused.text )