# -*- 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()