From: stack Date: Sun, 8 Jul 2012 18:46:20 +0000 (+0200) Subject: Gui activate profile action X-Git-Url: https://v.licheni.net/stack/code/dboxswitch.git/commitdiff_plain/2c94e3c217ecc734c7af00cacccf9451a4f7dedb Gui activate profile action this now handles the displaying of errors, using a function compiled to activate the right profile and catching AppError exceptions and displaying QErrorMessages with Gui.showError --- diff --git a/gui.py b/gui.py index 61de2f1..56d0802 100755 --- a/gui.py +++ b/gui.py @@ -129,7 +129,7 @@ class Gui(QtGui.QDialog): menuItem_Profile = self.menuProfiles.addAction(pr) #Using lambda function to pass additional arguments to the function, in this case the path of the profile - receiver = lambda pr=pr: self.profileManager.activateProfile(pr) + receiver = self.activateProfileAction(pr) self.connect(menuItem_Profile, SIGNAL('triggered()'), receiver) #set menu item ToolTip menuItem_Profile.setToolTip("Activate profile: "+pr) @@ -143,6 +143,18 @@ class Gui(QtGui.QDialog): self.menuProfiles.activateWindow() self.menuProfiles.popup(QtGui.QCursor.pos()) + def activateProfileAction(self, pr): + """ Returns a callable to be passed as an action for the switching profile mechanism + to self.connect(menuItem_Profile... + It compiles a function with a profile name as argument and also handle the displaying of errors.""" + + def f(): + try: + self.profileManager.activateProfile(pr) + except AppError, e: + self.showError(str(e)) + return f + def addProfile(self): """ Gui frontend to add a new Profile, it requests the user a profile name through a QInputDialog and creates a new profile with the help of the ProfHandler embedded in the Gui """