Hello again, guys. I'm stuck here -- still learning OOP and Python.
How do I structure this program so that I am able to spawn a QWidget object on start-up? Moreover, how do I make it so that each time I click on the System Tray Icon (namely mediaIcon.png), that same widget will not re-instantiate itself but, rather, show/hide itself with every other click?
As of right now, when I click on the icon, the program echos "Clicked." then closes. I don't know why that is.
Thanks a bunch,
Akratix
#!/usr/bin/python
import sys, os
from PyQt4 import QtGui, QtCore
class MediaFeed(QtGui.QSystemTrayIcon):
def __init__(self, icon, parent=None):
QtGui.QSystemTrayIcon.__init__(self, icon, parent)
menu = QtGui.QMenu()
aboutAction = menu.addAction("About")
aboutAction.triggered.connect(self.aboutMenu)
exitAction = menu.addAction("Exit")
exitAction.triggered.connect(QtGui.qApp.quit)
self.setContextMenu(menu)
self.activated.connect(self.systemIcon)
def aboutMenu(self):
print "This should be some information."
def systemIcon(self, reason):
w = QtGui.QWidget()
if reason == QtGui.QSystemTrayIcon.Trigger:
print "Clicked."
w.show()
def main():
app = QtGui.QApplication(sys.argv)
mediaFeed = MediaFeed(QtGui.QIcon("mediaIcon.png"), None)
mediaFeed.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()