-
Notifications
You must be signed in to change notification settings - Fork 2
/
qtray.py
71 lines (54 loc) · 1.8 KB
/
qtray.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
try:
from PyQt4 import QtGui
except ImportError:
try:
from Qt import QtGui
except Exception, e:
raise e
try:
import AppKit as ak
except:
ak = None
pass
class Indicatr(object):
def __init__(self, application=None):
if ak:
self.hide_mac_dock_icon()
self.top_icon = QtGui.QSystemTrayIcon()
# The important part: the menu itself.
self.menu = QtGui.QMenu()
self.sub_menu = QtGui.QMenu("Jenkinz")
self.settings_menu = self.sub_menu
self.icons = {}
def reset_menu(self):
self.sub_menu.clear()
self.menu.clear()
def change_icon(self, element, icon):
element.setIcon(icon)
try:
element.show()
except:
pass
def add_setting_submenu(self):
self.menu.addMenu(self.settings_menu)
def add_to_settings(self, text, callback):
return self.settings_menu.addAction(text, callback)
def add_settings_separator(self):
self._add_separator(self.sub_menu)
def _add_separator(self, menu):
menu.addSeparator()
def add_icon_to_menu(self, icon, text, callback):
return self.menu.addAction(icon, text, callback)
def add_to_menu(self, text, callback):
return self.menu.addAction(text, callback)
def add_separator(self):
self._add_separator(self.menu)
def init_top_icon(self):
self.top_icon.show()
self.top_icon.setContextMenu(self.menu)
def hide_mac_dock_icon(self):
if not ak:
return
# https://developer.apple.com/library/mac/#documentation/AppKit/Reference/NSRunningApplication_Class/Reference/Reference.html
NSApplicationActivationPolicyAccessory = 1
ak.NSApp.setActivationPolicy_(NSApplicationActivationPolicyAccessory)