diff sat_frontends/primitivus/profile_manager.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 378188abe941
line wrap: on
line diff
--- a/sat_frontends/primitivus/profile_manager.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat_frontends/primitivus/profile_manager.py	Wed Jun 27 20:14:46 2018 +0200
@@ -19,6 +19,7 @@
 
 from sat.core.i18n import _
 from sat.core import log as logging
+
 log = logging.getLogger(__name__)
 from sat_frontends.quick_frontend.quick_profile_manager import QuickProfileManager
 from sat_frontends.primitivus.constants import Const as C
@@ -28,46 +29,68 @@
 
 
 class ProfileManager(QuickProfileManager, urwid.WidgetWrap):
-
     def __init__(self, host, autoconnect=None):
         QuickProfileManager.__init__(self, host, autoconnect)
 
-        #login & password box must be created before list because of onProfileChange
-        self.login_wid = sat_widgets.AdvancedEdit(_('Login:'), align='center')
-        self.pass_wid = sat_widgets.Password(_('Password:'), align='center')
+        # login & password box must be created before list because of onProfileChange
+        self.login_wid = sat_widgets.AdvancedEdit(_("Login:"), align="center")
+        self.pass_wid = sat_widgets.Password(_("Password:"), align="center")
 
-        style = ['no_first_select']
+        style = ["no_first_select"]
         profiles = host.bridge.profilesListGet()
         profiles.sort()
-        self.list_profile = sat_widgets.List(profiles, style=style, align='center', on_change=self.onProfileChange)
+        self.list_profile = sat_widgets.List(
+            profiles, style=style, align="center", on_change=self.onProfileChange
+        )
 
-        #new & delete buttons
-        buttons = [urwid.Button(_("New"), self.onNewProfile),
-                  urwid.Button(_("Delete"), self.onDeleteProfile)]
-        buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center')
+        # new & delete buttons
+        buttons = [
+            urwid.Button(_("New"), self.onNewProfile),
+            urwid.Button(_("Delete"), self.onDeleteProfile),
+        ]
+        buttons_flow = urwid.GridFlow(
+            buttons,
+            max([len(button.get_label()) for button in buttons]) + 4,
+            1,
+            1,
+            "center",
+        )
+
+        # second part: login information:
+        divider = urwid.Divider("-")
 
-        #second part: login information:
-        divider = urwid.Divider('-')
+        # connect button
+        connect_button = sat_widgets.CustomButton(
+            _("Connect"), self.onConnectProfiles, align="center"
+        )
 
-        #connect button
-        connect_button = sat_widgets.CustomButton(_("Connect"), self.onConnectProfiles, align='center')
-
-        #we now build the widget
-        list_walker = urwid.SimpleFocusListWalker([buttons_flow,self.list_profile, divider, self.login_wid, self.pass_wid, connect_button])
+        # we now build the widget
+        list_walker = urwid.SimpleFocusListWalker(
+            [
+                buttons_flow,
+                self.list_profile,
+                divider,
+                self.login_wid,
+                self.pass_wid,
+                connect_button,
+            ]
+        )
         frame_body = urwid.ListBox(list_walker)
-        frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title'))
+        frame = urwid.Frame(
+            frame_body,
+            urwid.AttrMap(urwid.Text(_("Profile Manager"), align="center"), "title"),
+        )
         self.main_widget = urwid.LineBox(frame)
         urwid.WidgetWrap.__init__(self, self.main_widget)
 
         self.go(autoconnect)
 
-
     def keypress(self, size, key):
-        if key == a_key['APP_QUIT']:
+        if key == a_key["APP_QUIT"]:
             self.host.onExit()
             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
+        elif key in (a_key["FOCUS_UP"], a_key["FOCUS_DOWN"]):
+            focus_diff = 1 if key == a_key["FOCUS_DOWN"] else -1
             list_box = self.main_widget.base_widget.body
             current_focus = list_box.body.get_focus()[1]
             if current_focus is None:
@@ -77,7 +100,9 @@
                 if current_focus < 0 or current_focus >= len(list_box.body):
                     break
                 if list_box.body[current_focus].selectable():
-                    list_box.set_focus(current_focus, 'above' if focus_diff == 1 else 'below')
+                    list_box.set_focus(
+                        current_focus, "above" if focus_diff == 1 else "below"
+                    )
                     list_box._invalidate()
                     return
         return super(ProfileManager, self).keypress(size, key)
@@ -88,17 +113,26 @@
     def newProfile(self, button, edit):
         """Create the profile"""
         name = edit.get_edit_text()
-        self.host.bridge.profileCreate(name, callback=lambda: self.newProfileCreated(name), errback=self.profileCreationFailure)
+        self.host.bridge.profileCreate(
+            name,
+            callback=lambda: self.newProfileCreated(name),
+            errback=self.profileCreationFailure,
+        )
 
     def newProfileCreated(self, profile):
         # new profile will be selected, and a selected profile assume the session is started
-        self.host.bridge.profileStartSession('', profile, callback=lambda dummy: self.newProfileSessionStarted(profile), errback=self.profileCreationFailure)
+        self.host.bridge.profileStartSession(
+            "",
+            profile,
+            callback=lambda dummy: self.newProfileSessionStarted(profile),
+            errback=self.profileCreationFailure,
+        )
 
     def newProfileSessionStarted(self, profile):
         self.host.removePopUp()
         self.refillProfiles()
         self.list_profile.selectValue(profile)
-        self.current.profile=profile
+        self.current.profile = profile
         self.getConnectionParams(profile)
         self.host.redraw()
 
@@ -112,12 +146,23 @@
         self.host.removePopUp()
 
     def onNewProfile(self, e):
-        pop_up_widget = sat_widgets.InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile)
+        pop_up_widget = sat_widgets.InputDialog(
+            _("New profile"),
+            _("Please enter a new profile name"),
+            cancel_cb=self.cancelDialog,
+            ok_cb=self.newProfile,
+        )
         self.host.showPopUp(pop_up_widget)
 
     def onDeleteProfile(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)
+            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,
+            )
             self.host.showPopUp(pop_up_widget)
 
     def onConnectProfiles(self, button):
@@ -149,7 +194,7 @@
     def setJID(self, jid_):
         self.login_wid.set_edit_text(jid_)
         self.current.login = jid_
-        self.host.redraw() # FIXME: redraw should be avoided
+        self.host.redraw()  # FIXME: redraw should be avoided
 
     def setPassword(self, password):
         self.pass_wid.set_edit_text(password)
@@ -164,16 +209,20 @@
         self.updateConnectionParams()
         focused = list_wid.focus
         selected = focused.getState() if focused is not None else False
-        if not selected: # profile was just unselected
+        if not selected:  # profile was just unselected
             return
-        focused.setState(False, invisible=True) # we don't want the widget to be selected until we are sure we can access it
+        focused.setState(
+            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)):
+            if C.bool(data.pop("validated", C.BOOL_FALSE)):
                 self.current.profile = profile
                 focused.setState(True, invisible=True)
                 self.getConnectionParams(profile)
                 self.host.redraw()
             self.host.actionManager(data, callback=authenticate_cb, profile=profile)
 
-        self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=focused.text)
-
+        self.host.launchAction(
+            C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=focused.text
+        )