comparison frontends/src/primitivus/profile_manager.py @ 421:28e4299d4553

primitivus: profile manager updated to use new asynchronous profile creation
author Goffi <goffi@goffi.org>
date Wed, 02 Nov 2011 22:50:06 +0100
parents dd4caab17008
children 5a18c5f08d9b
comparison
equal deleted inserted replaced
420:acd908528ef7 421:28e4299d4553
66 self.host.removePopUp() 66 self.host.removePopUp()
67 67
68 def newProfile(self, button, edit): 68 def newProfile(self, button, edit):
69 """Create the profile""" 69 """Create the profile"""
70 name = edit.get_edit_text() 70 name = edit.get_edit_text()
71 self.host.bridge.createProfile(name) 71 self.host.bridge.asyncCreateProfile(name, callback=lambda: self._newProfileCreated(name), errback=self._profileCreationFailure)
72
73 def _newProfileCreated(self, name):
72 self.__refillProfiles() 74 self.__refillProfiles()
73 #We select the profile created in the list 75 #We select the profile created in the list
74 self.list_profile.selectValue(name) 76 self.list_profile.selectValue(name)
75 self.host.removePopUp() 77 self.host.removePopUp()
78 self.host.redraw()
79
80 def _profileCreationFailure(self, reason):
81 self.host.removePopUp()
82 if reason=="CONFLICT":
83 message=_("A profile with this name already exists")
84 elif reason=="CANCELED":
85 message=_("Profile creation cancelled by backend")
86 elif reason=="DATABASE":
87 message=_("Database error")
88 else:
89 message=_("Unknown reason (%s)") % reason
90 popup = Alert(_("Can't create profile"), message, ok_cb=self.host.removePopUp)
91 self.host.showPopUp(popup)
76 92
77 def deleteProfile(self, button): 93 def deleteProfile(self, button):
78 profile_name = self.list_profile.getSelectedValue() 94 profile_name = self.list_profile.getSelectedValue()
79 if profile_name: 95 if profile_name:
80 self.host.bridge.deleteProfile(profile_name) 96 self.host.bridge.deleteProfile(profile_name)
81 self.__refillProfiles() 97 self.__refillProfiles()
82 self.host.removePopUp() 98 self.host.removePopUp()
83 99
84
85 def onNewProfile(self, e): 100 def onNewProfile(self, e):
86 pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile) 101 pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile)
87 self.host.showPopUp(pop_up_widget) 102 self.host.showPopUp(pop_up_widget)
88 103
89 def onDeleteProfile(self, e): 104 def onDeleteProfile(self, e):