1. thijsdezoete
  2. appindicators

Commits

thijsdezoete  committed e9252ae

Menuitems can have icons

  • Participants
  • Parent commits dc59b2b
  • Branches master

Comments (0)

Files changed (3)

File api/__init__.py

  • Ignore whitespace
Empty file added.

File api/testing.py

View file
  • Ignore whitespace
+def some_call():
+    print 'hello in teh api'
+
+def get_entries():
+    def test():
+        print 'hellooooo!'
+    return [('From api', test)]

File test.py

View file
  • Ignore whitespace
 
 import os
-#import PyQt4
-from PyQt4 import QtCore, QtGui #, QtSvg
+import sys
+
+platform = sys.platform
+from PyQt4 import QtCore, QtGui  # , QtSvg
 
 FOLDER = os.path.dirname(os.path.abspath(__file__))
 IMAGE = FOLDER + '/ImageCache.png'
         FOLDER + '/apple.png',
         )
 
-app = QtGui.QApplication([])
-i = QtGui.QSystemTrayIcon()
-m = QtGui.QMenu()
-
 
 def quitCB():
-   QtGui.QApplication.quit()
+    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])
+    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', swap_image)
-QtCore.QObject.connect(m, QtCore.SIGNAL('aboutToShow()'), aboutToShowCB)
-i.setContextMenu(m)
-
-
-pm = QtGui.QPixmap(16, 16)
-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)
-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 i #, icon          # deleted before the painter
-del app
+    print 'about to show'
+
+
+def hide_mac_dock_icon():
+    try:
+        import AppKit
+        # https://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSRunningApplication_Class/Reference/Reference.html
+        NSApplicationActivationPolicyRegular = 0
+        NSApplicationActivationPolicyAccessory = 1
+        NSApplicationActivationPolicyProhibited = 2
+        AppKit.NSApp.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
+    except: 
+        # Don't do anything if we can't remove dock icon... 
+        print 'Cant remove icon from dock. Install pyobjc to fix this'
+        pass
+
+def generate_menu(menu):
+    from api import testing as my_plugin
+    for (label, function) in my_plugin.get_entries():
+        menu.addAction(label, function)
+
+
+
+if __name__ == '__main__':
+    app = QtGui.QApplication([])
+
+    if 'darwin' in platform:
+        hide_mac_dock_icon()
+
+    i = QtGui.QSystemTrayIcon()
+    m = QtGui.QMenu()
+    generate_menu(m)
+
+
+    m.addAction('Hai', swap_image)
+    QtCore.QObject.connect(m, QtCore.SIGNAL('aboutToShow()'), aboutToShowCB)
+    i.setContextMenu(m)
+
+    pm = QtGui.QPixmap(16, 16)
+    IMG_ICONS = ()
+    for image in IMAGES:
+        tmp = QtGui.QIcon(image)
+        tmp.addPixmap(pm)
+        IMG_ICONS += (tmp,)
+
+
+    #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()
+
+    # Add quit button at the bottom
+    m.addAction('Quit', quitCB)
+    app.exec_()
+
+    #del svg #,pm avoid the paint device getting
+    del i  # , icon          # deleted before the painter
+    del app
+