X-Git-Url: https://v.licheni.net/stack/code/dboxswitch.git/blobdiff_plain/d13b4666ed644a5bc5c0cee5657ad0b801ee5ad6..2c94e3c217ecc734c7af00cacccf9451a4f7dedb:/gui.py diff --git a/gui.py b/gui.py index 17a4e14..56d0802 100755 --- a/gui.py +++ b/gui.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- """ @@ -36,6 +35,7 @@ import sys import os from PyQt4 import QtGui from PyQt4.QtCore import SIGNAL +from qmenutooltip import QMenuToolTip from apperror import AppError from settings import appconf @@ -118,7 +118,7 @@ class Gui(QtGui.QDialog): action to add a new One """ if reason in (QtGui.QSystemTrayIcon.Trigger, QtGui.QSystemTrayIcon.DoubleClick): - self.menuProfiles = QtGui.QMenu() + self.menuProfiles = QMenuToolTip() self.menuProfiles.setTitle("Profiles") #Get profiles from the ProfHandler embedded in the gui @@ -129,8 +129,10 @@ 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) self.menuProfiles.addAction(menuItem_Profile) @@ -141,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 """