1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2009 Chris Dekter
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
from PyKDE4.kdeui import KNotification, KSystemTrayIcon, KIcon, KStandardAction, KToggleAction
20
from PyKDE4.kdecore import i18n
21
from PyQt4.QtCore import SIGNAL
24
from autokey.configmanager import *
26
ICON_FILE = "/usr/share/pixmaps/akicon.png"
28
TOOLTIP_RUNNING = "AutoKey - running"
29
TOOLTIP_PAUSED = "AutoKey - paused"
33
def __init__(self, app):
35
self.configManager = app.configManager
37
if ConfigManager.SETTINGS[SHOW_TRAY_ICON]:
38
self.icon = KSystemTrayIcon(ICON_FILE)
40
self.update_tool_tip()
43
def update_tool_tip(self):
44
if ConfigManager.SETTINGS[SERVICE_RUNNING]:
45
self.icon.setToolTip(TOOLTIP_RUNNING)
46
self.toggleAction.setChecked(True)
48
self.icon.setToolTip(TOOLTIP_PAUSED)
49
self.toggleAction.setChecked(False)
52
if ConfigManager.SETTINGS[SHOW_TRAY_ICON]:
53
# Get phrase folders to add to main menu
57
for folder in self.configManager.allFolders:
58
if folder.showInTrayMenu:
59
folders.append(folder)
61
for item in self.configManager.allItems:
62
if item.showInTrayMenu:
66
menu = popupmenu.PopupMenu(self.app.service, folders, items, False, "AutoKey")
70
self.toggleAction = KToggleAction(i18n("&Enable Monitoring"), menu)
71
self.toggleAction.connect(self.toggleAction, SIGNAL("triggered()"), self.on_enable_toggled)
72
self.toggleAction.setChecked(self.app.service.is_running())
73
self.toggleAction.setEnabled(not self.app.serviceDisabled)
75
menu.addAction(self.toggleAction)
76
menu.addAction(KIcon("edit-clear"), i18n("&Hide Icon"), self.on_hide_icon)
77
menu.addAction(KIcon("configure"), i18n("&Configure..."), self.on_configure)
78
menu.addAction(KStandardAction.quit(self.on_quit, menu))
79
self.icon.setContextMenu(menu)
81
# ---- Signal handlers ----
86
def on_configure(self):
87
self.app.show_configure()
89
def on_enable_toggled(self):
90
if self.toggleAction.isChecked():
91
self.app.unpause_service()
93
self.app.pause_service()
95
def on_hide_icon(self):
97
ConfigManager.SETTINGS[SHOW_TRAY_ICON] = False
b'\\ No newline at end of file'