primitivus: profile manager updated to use new asynchronous profile creation

This commit is contained in:
Goffi 2011-11-02 22:50:06 +01:00
commit f5f32a0c9f

View file

@ -68,11 +68,27 @@ class ProfileManager(urwid.WidgetWrap):
def newProfile(self, button, edit):
"""Create the profile"""
name = edit.get_edit_text()
self.host.bridge.createProfile(name)
self.host.bridge.asyncCreateProfile(name, callback=lambda: self._newProfileCreated(name), errback=self._profileCreationFailure)
def _newProfileCreated(self, name):
self.__refillProfiles()
#We select the profile created in the list
self.list_profile.selectValue(name)
self.host.removePopUp()
self.host.redraw()
def _profileCreationFailure(self, reason):
self.host.removePopUp()
if reason=="CONFLICT":
message=_("A profile with this name already exists")
elif reason=="CANCELED":
message=_("Profile creation cancelled by backend")
elif reason=="DATABASE":
message=_("Database error")
else:
message=_("Unknown reason (%s)") % reason
popup = Alert(_("Can't create profile"), message, ok_cb=self.host.removePopUp)
self.host.showPopUp(popup)
def deleteProfile(self, button):
profile_name = self.list_profile.getSelectedValue()
@ -81,7 +97,6 @@ class ProfileManager(urwid.WidgetWrap):
self.__refillProfiles()
self.host.removePopUp()
def onNewProfile(self, e):
pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile)
self.host.showPopUp(pop_up_widget)