[PyQt] Problems with QSystemTrayIcon
Philippe Fremy
phil at freehackers.org
Thu Feb 19 10:58:29 GMT 2009
Hi,
I am having problem to get QSystemTrayIcon to work. I am running on
windows XP and I never see any notification messages.
My setup: windows XP, PyQt 4.3.3, python 2.5
See my attached simplified code, that runs standalone. Any idea what I
could be doing wrong ?
cheers,
Philippe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: croquemonster.png
Type: image/png
Size: 209 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090219/4f58d516/croquemonster.png
-------------- next part --------------
# -*- coding: latin1 -*-
# vim: set fileencoding=latin1
#
# PyTiCroque - Copyright Philippe Fremy 2009
#
# This file is released under the BSD License, see the accompanying file LICENSE.txt
#
import locale, sys
locale.setlocale( locale.LC_ALL, '' )
from PyQt4 import QtGui, QtCore
def dbg( s ):
print (u'PTCrWindow: %s' % s).encode( locale.getlocale()[1] )
class PTCrWindow( QtGui.QTextEdit ):
def __init__( self ):
QtGui.QTextEdit.__init__( self )
self.initAppIcon()
self.initSystray()
self.timer = QtCore.QTimer()
self.timer.start( 2 * 1000 )
QtCore.QObject.connect( self.timer, QtCore.SIGNAL('timeout()'), self.addMsg )
self.appendEvent( 'QPyTiCroque is alive !' )
def initAppIcon( self ):
pixmap = QtGui.QPixmap( 'croquemonster.png' )
dbg( 'pixmap size: %dx%d' % (pixmap.width(), pixmap.height()) )
self.appIcon = QtGui.QIcon( pixmap )
self.setWindowIcon( self.appIcon )
def initSystray( self ):
self.systray = QtGui.QSystemTrayIcon( self.appIcon , self )
self.systray.setToolTip( 'PyTiCroque' )
self.systray.show()
dbg( 'SystemTray available: %s' % str( bool ( QtGui.QSystemTrayIcon.isSystemTrayAvailable() ) ) )
dbg( 'SystemTray supports messages: %s' % str( bool ( self.systray.supportsMessages() ) ) )
def addMsg( self ):
self.appendEvent( 'timer event!' )
def appendEvent( self, s ):
dbg( s )
self.append( s )
self.systray.showMessage( QtCore.QString(u'Evenement PyTiCroque'), QtCore.QString(s),
QtGui.QSystemTrayIcon.Information, 100 * 1000 )
DEBUG_FLAG=False
def main():
app = QtGui.QApplication([])
w = PTCrWindow()
w.show()
app.exec_()
w.systray.hide()
app.processEvents()
if __name__ == '__main__':
main()
More information about the PyQt
mailing list