Commits

thijsdezoete  committed dc59b2b

Auto-swap

  • Participants
  • Parent commits 53a1208

Comments (0)

Files changed (1)

 
 FOLDER = os.path.dirname(os.path.abspath(__file__))
 IMAGE = FOLDER + '/ImageCache.png'
+
+IMAGES = (
+        FOLDER + '/ImageCache.png',
+        FOLDER + '/apple.png',
+        )
+
 app = QtGui.QApplication([])
 i = QtGui.QSystemTrayIcon()
 m = QtGui.QMenu()
 
+
 def quitCB():
    QtGui.QApplication.quit()
-def test_someting():
-   global i
-   print 'SEtting new image'
-   test = QtGui.QIcon(FOLDER+'/apple.png')
-   pm = QtGui.QPixmap(16, 16)
-   test.addPixmap(pm) 
-   i.setIcon(test)
-   print 'thijs says hai'
+
+
+def swap_image():
+   global i, IMG_ICONS
+   (img1, img2) =  IMG_ICONS
+   IMG_ICONS = (img2, img1)
+   print 'Setting new image'
+   i.setIcon(IMG_ICONS[0])
+
+
 def aboutToShowCB():
    print 'about to show'
 
-m.addAction('Hai', test_someting)
+m.addAction('Hai', swap_image)
 QtCore.QObject.connect(m, QtCore.SIGNAL('aboutToShow()'), aboutToShowCB)
 i.setContextMenu(m)
 
-svg = QtGui.QIcon(IMAGE)
-print svg.availableSizes()
+
 pm = QtGui.QPixmap(16, 16)
-svg.addPixmap(pm) 
+IMG_ICONS = ()
+for image in IMAGES:
+    tmp = QtGui.QIcon(image)
+    tmp.addPixmap(pm)
+    IMG_ICONS += (tmp,)
+
+#svg = QtGui.QIcon(IMAGE)
+#print svg.availableSizes()
+#pm = QtGui.QPixmap(16, 16)
+#svg.addPixmap(pm) 
+#test = QtGui.QIcon(FOLDER+'/apple.png')
+#pm = QtGui.QPixmap(16, 16)
+#test.addPixmap(pm) 
 #print svg.availableSizes()
 #painter = QtGui.QPainter(pm)
 #test = painter.render(svg)
 #icon = QtGui.QIcon(test)
-i.setIcon(svg)
+swap_image()
+#i.setIcon(svg)
 i.show()
 
 # Add quit button at the bottom
 m.addAction('Quit', quitCB)
 app.exec_()
 
-del svg #,pm avoid the paint device getting
+#del svg #,pm avoid the paint device getting
 del i #, icon          # deleted before the painter
 del app