~ubuntu-branches/ubuntu/lucid/autokey/lucid

« back to all changes in this revision

Viewing changes to src/lib/ui/notifier.py

  • Committer: Bazaar Package Importer
  • Author(s): Luke Faraone
  • Date: 2009-08-17 09:18:07 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090817091807-0g39xeau3xnotc73
Tags: 0.60.4-1
* New upstream version
* Bump standards version
* Update debian/watch file with new URL

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Copyright (C) 2009 Chris Dekter
 
4
 
 
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.
 
9
#
 
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.
 
14
#
 
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.
 
18
 
 
19
from PyKDE4.kdeui import KNotification, KSystemTrayIcon, KIcon, KStandardAction, KToggleAction
 
20
from PyKDE4.kdecore import i18n
 
21
from PyQt4.QtCore import SIGNAL
 
22
 
 
23
import popupmenu
 
24
from autokey.configmanager import *
 
25
 
 
26
ICON_FILE = "/usr/share/pixmaps/akicon.png"
 
27
 
 
28
TOOLTIP_RUNNING = "AutoKey - running"
 
29
TOOLTIP_PAUSED = "AutoKey - paused"
 
30
 
 
31
class Notifier:
 
32
    
 
33
    def __init__(self, app):
 
34
        self.app = app
 
35
        self.configManager = app.configManager
 
36
        
 
37
        if ConfigManager.SETTINGS[SHOW_TRAY_ICON]:
 
38
            self.icon = KSystemTrayIcon(ICON_FILE)
 
39
            self.build_menu()
 
40
            self.update_tool_tip()
 
41
            self.icon.show()
 
42
                        
 
43
    def update_tool_tip(self):
 
44
        if ConfigManager.SETTINGS[SERVICE_RUNNING]:
 
45
            self.icon.setToolTip(TOOLTIP_RUNNING)
 
46
            self.toggleAction.setChecked(True)
 
47
        else:
 
48
            self.icon.setToolTip(TOOLTIP_PAUSED)
 
49
            self.toggleAction.setChecked(False)
 
50
            
 
51
    def build_menu(self):
 
52
        if ConfigManager.SETTINGS[SHOW_TRAY_ICON]:
 
53
            # Get phrase folders to add to main menu
 
54
            folders = []
 
55
            items = []
 
56
 
 
57
            for folder in self.configManager.allFolders:
 
58
                if folder.showInTrayMenu:
 
59
                    folders.append(folder)
 
60
            
 
61
            for item in self.configManager.allItems:
 
62
                if item.showInTrayMenu:
 
63
                    items.append(item)
 
64
                    
 
65
            # Construct main menu
 
66
            menu = popupmenu.PopupMenu(self.app.service, folders, items, False, "AutoKey")
 
67
            if len(items) > 0:
 
68
                menu.addSeparator()
 
69
            
 
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)           
 
74
            
 
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)
 
80
 
 
81
    # ---- Signal handlers ----
 
82
 
 
83
    def on_quit(self):
 
84
        self.app.shutdown()
 
85
 
 
86
    def on_configure(self):
 
87
        self.app.show_configure()
 
88
        
 
89
    def on_enable_toggled(self):
 
90
        if self.toggleAction.isChecked():
 
91
            self.app.unpause_service()
 
92
        else:
 
93
            self.app.pause_service()
 
94
            
 
95
    def on_hide_icon(self):
 
96
        self.icon.hide()
 
97
        ConfigManager.SETTINGS[SHOW_TRAY_ICON] = False
 
 
b'\\ No newline at end of file'