[python] pyqt4,system tray,zavreni aplikace
vepro
p.zlamal na gmail.com
Čtvrtek Červen 17 13:56:00 CEST 2010
Pratele,
Zkousim udelat cast kodu, ktera ma mit za cil vytvorit v system tray
ikonu + menu. V tomto menu budou ruzne polozky (ktere budou dale
otevirat ruzna okna) a take polozka Exit. Polozka Exit ukonci celou
aplikaci. Zatim se mi podaril nasledujici kod (viz nize), ktery aplikaci
ukonci, avsak v konzoli se objevi: Segmentation fault. Je to nekorektni
postup, ci co to presne znamena?? Nejake navrhy jak to udelat pr ipadne
lepe? Dekuji
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class SystemTrayIcon(QtGui.QSystemTrayIcon):
def __init__(self, icon, parent=None):
QtGui.QSystemTrayIcon.__init__(self,parent)
self.setIcon(QtGui.QIcon("./pig_icon.gif"))
self.trayMenu = QtGui.QMenu()
self.exitAction = self.trayMenu.addAction("Exit")
self.loadAction = self.trayMenu.addAction("Load")
self.setContextMenu(self.trayMenu)
self.connect(self.exitAction,
QtCore.SIGNAL('triggered()'), self.closeApp)
self.connect(self.loadAction,
QtCore.SIGNAL('triggered()'), self.load)
def closeApp(self):
app.exit()
def load(self):
print "load"
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
trayIcon = SystemTrayIcon(QtGui.QIcon())
trayIcon.show()
sys.exit(app.exec_())
Vepro
Další informace o konferenci Python