Commits

thijsdezoete committed a2a3309

working - time to refactor

Comments (0)

Files changed (3)

+        
+from PyQt4 import QtCore, QtGui  # , QtSvg
+import os
+
+FOLDER = os.path.dirname(os.path.abspath(__file__) + '../')
+print FOLDER
+IMAGE = FOLDER + '/ImageCache.png'
+
+IMAGES = (
+        FOLDER + '/ImageCache.png',
+        FOLDER + '/apple.png',
+        )
+
+
 def some_call():
-    print 'hello in teh api'
+    print 'some method in api'
 
 def get_entries():
     def test():
-        print 'hellooooo!'
-    return [('From api', test)]
+        print 'function from get_entries'
+    return [('From api', test),
+            ('Another', some_call)]
 
+import pprint
 import os
 import sys
 
     QtGui.QApplication.quit()
 
 
-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'
 
         menu.addAction(label, function)
 
 
+def swap_image(element):
+    global IMG_ICONS
+    (img1, img2) = IMG_ICONS
+    IMG_ICONS = (img2, img1)
+    print 'Setting new image on %s' % element
+    element.setIcon(IMG_ICONS[0])
+    try:
+        element.show()
+    except:  # Can't `show()` element..
+        pass
+
+
+def _chng_icon(action):
+    swap_image(action)
+
 
 if __name__ == '__main__':
     app = QtGui.QApplication([])
     generate_menu(m)
 
 
-    m.addAction('Hai', swap_image)
-    QtCore.QObject.connect(m, QtCore.SIGNAL('aboutToShow()'), aboutToShowCB)
+    m.addAction('Change tray image', lambda: swap_image(i))
+    # Use this to connect buttons in the future..
+    # Qt.Core.SIGNAL:
+    #QtCore.QObject.connect(m, QtCore.SIGNAL('aboutToShow()'), aboutToShowCB)
     i.setContextMenu(m)
 
     pm = QtGui.QPixmap(16, 16)
         tmp.addPixmap(pm)
         IMG_ICONS += (tmp,)
 
+    hello = m.addAction(IMG_ICONS[1], "change this icon")
+    QtCore.QObject.connect(hello, QtCore.SIGNAL('triggered()'), lambda: swap_image(hello))
 
-    #test = QtGui.QImage(IMAGES[0])
-    test = QtGui.QPixmap(IMG_ICONS[0])
-    #bbb = QtGui.QLabel("test!")
-    #test_scaled = test.scaled(bbb.size())
-    #bbb.setPixmap(QtGui.QPixmap.fromImage(test))
-    #$bbb.setPixmap(test_scaled)
-    #test = QtGui.QLabel().setPixmap(IMG_ICONS[0].pixmap(0))
-    def _t():
-        print 'test'
-    m.addAction(IMG_ICONS[0], "testttt", _t)
-
-    swap_image()
-    i.show()
-
+    swap_image(i)
     # Add quit button at the bottom
     m.addAction('Quit', quitCB)
     app.exec_()