Hello Everybody!!!
I have a problem with SystemTray and PyQt…
I want to write little project, which calculate how many times we press “ENTER”
when I minimize my program to “tray” and open another window then press “ENTER”, in this case program doesn't calucalate. How can I running my program in SystemTray?
my code is the following…
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
class SystemTrayIcon(QtGui.QSystemTrayIcon):
def __init__(self, parent=None):
QtGui.QSystemTrayIcon.__init__(self, parent)
self.setIcon(QtGui.QIcon(“icon.jpg”))
self.mainMenu = QtGui.QMenu(parent)
#==================== M E N U ====================
systemInformation = self.mainMenu.addAction(“System Information”)
aboutButton = self.mainMenu.addAction(“About”)
exitButton = self.mainMenu.addAction(“Exit”)
self.setContextMenu(self.mainMenu)
#==================== EVENT ======================
self.connect(systemInformation,QtCore.SIGNAL('triggered()'),self.keyPressEvent)
self.connect(aboutButton,QtCore.SIGNAL('triggered()'),self.showAbout)
self.connect(exitButton,QtCore.SIGNAL('triggered()'),self.appExit)
self.show()
def keyPressEvent(self, e):
if e.key() == QtCore.Qt.Key_Enter: # IT DOESN'T WORK WHEN I MINIMIZE PROGRAM
print “some text”
def showAbout(self):
QtGui.QMessageBox.information(QtGui.QWidget(), self.tr(“About Tunarium”), self.tr(“Your text here.”))
def appExit(self):
sys.exit()
if __name__ == “__main__”:
app = QtGui.QApplication(sys.argv)
trayIcon = SystemTrayIcon()
trayIcon.show()
sys.exit(app.exec_())
Thanks!!!!