comparison frontends/primitivus/profile_manager.py @ 113:e5ca22113280

Primitivus: profile manager - new custom widgets: Password, List, GenericDialog, InputDialog, ConfirmationDialog
author Goffi <goffi@goffi.org>
date Thu, 01 Jul 2010 15:35:56 +0800
parents f551e44adb25
children eed4f77c942e
comparison
equal deleted inserted replaced
112:f551e44adb25 113:e5ca22113280
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 import urwid 22 import urwid
23 from custom_widgets import Password,List,InputDialog,ConfirmDialog
23 24
24 25
25 class ProfileManager(urwid.WidgetWrap): 26 class ProfileManager(urwid.WidgetWrap):
26 27
27 def __init__(self, host): 28 def __init__(self, host):
28 self.host = host 29 self.host = host
30 #profiles list
29 profiles = self.host.bridge.getProfilesList() 31 profiles = self.host.bridge.getProfilesList()
30 widgets = [urwid.Text(str(profiles))] 32 profiles.sort()
31 content = urwid.SimpleListWalker(widgets) 33
32 display_widget = urwid.Frame(urwid.ListBox(content),urwid.AttrMap(urwid.Text("Profile Manager",align='center'),'title')) 34 #login & password box must be created before list because of onProfileChange
33 urwid.WidgetWrap.__init__(self, display_widget) 35 self.login_wid = urwid.Edit(_('Login:'),align='center')
36 self.pass_wid = Password(_('Password:'),align='center')
37
38 self.list_profile = List(profiles, style=['single'], align='center', on_state_change=self.onProfileChange)
34 39
40 #toto = urwid.Padding(urwid.Text('toto'), align='center')
41
42 #new & delete buttons
43 buttons = [urwid.Button(_("New"), self.onNewProfile),
44 urwid.Button(_("Delete"), self.onDeleteProfile)]
45 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center')
46
47 #second part: login information:
48 divider = urwid.Divider('-')
49
50 #connect button
51 connect_button = urwid.Button(_("Connect"), self.onConnectProfile)
52
53 #we now build the widget
54 body_content = urwid.SimpleListWalker([buttons_flow,self.list_profile,divider,self.login_wid, self.pass_wid, connect_button])
55 frame_body = urwid.ListBox(body_content)
56 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text("Profile Manager",align='center'),'title'))
57 self.main_widget = urwid.LineBox(frame)
58 urwid.WidgetWrap.__init__(self, self.main_widget)
59
60 def __refillProfiles(self):
61 """Update the list of profiles"""
62 profiles = self.host.bridge.getProfilesList()
63 profiles.sort()
64 self.list_profile.changeValues(profiles)
65
66 def cancelDialog(self, button):
67 self._set_w(self.main_widget)
68
69 def newProfile(self, button, edit):
70 self._set_w(self.main_widget)
71 name = edit.get_edit_text()
72 self.host.bridge.createProfile(name)
73 self.__refillProfiles()
74 self.list_profile.selectValue(name)
75
76 def deleteProfile(self, button):
77 self._set_w(self.main_widget)
78 self.host.bridge.deleteProfile(self.list_profile.getValues()[0])
79 self.__refillProfiles()
80
81
82 def onNewProfile(self, e):
83 pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile)
84 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40))
85 self._set_w(display_widget)
86
87 def onDeleteProfile(self, e):
88 pop_up_widget = ConfirmDialog(_("Are you sure you want to delete the profile %s ?") % self.list_profile.getValues()[0], no_cb=self.cancelDialog, yes_cb=self.deleteProfile)
89 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40))
90 self._set_w(display_widget)
91
92 def onProfileChange(self, list_wid):
93 profile_name = list_wid.getValues()[0]
94 jabberID = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile_name)
95 password = self.host.bridge.getParamA("Password", "Connection", profile_key=profile_name)
96 self.login_wid.set_edit_text(jabberID)
97 self.pass_wid.set_edit_text(password)
98
99 def onConnectProfile(self, button):
100 pass