[go: up one dir, main page]

File: timer-applet

package info (click to toggle)
timer-applet 2.0.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,216 kB
  • ctags: 251
  • sloc: sh: 3,467; python: 1,403; xml: 111; makefile: 98
file content (116 lines) | stat: -rwxr-xr-x 4,116 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python

from os import path
import gettext
import sys
import gtk
import gnomeapplet
from timerapplet import config
from timerapplet.controllers import GlobalController, TimerApplet, TimerService, TimerManagerService
from timerapplet.core import AppletGConfWrapper, Timer

from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)

DBUS_BUS_NAME = 'net.sourceforge.timerapplet.TimerApplet'
DBUS_OBJ_NAMESPACE = '/net/sourceforge/timerapplet/TimerApplet'

gettext.bindtextdomain(config.GETTEXT_PACKAGE, config.LOCALE_DIR)
gettext.bind_textdomain_codeset(config.GETTEXT_PACKAGE, 'UTF-8')
gettext.textdomain(config.GETTEXT_PACKAGE)

global_controller = GlobalController()
timer_manager_obj_path = path.join(DBUS_OBJ_NAMESPACE, 'TimerManager')
print 'Timer Manager D-Bus object path: %s' % timer_manager_obj_path

timer_manager = None
try:
    timer_manager = TimerManagerService(DBUS_BUS_NAME, timer_manager_obj_path)
except Exception, err:
    print 'ERROR: Could not start TimerManagerService. D-Bus support will not be available. Error message: %s' % err

def check_dependencies():
    # Check for optional dependencies
    try:
        import dbus # >= 0.80
    except ImportError, err:
        print 'Missing optional dependency: %s' % err

    # Check for required dependencies
    try:
        import gobject # >= 2.12
        import gtk # >= 2.10, includes pango
        import gtk.glade # >= 2.10
        import gconf # >= 2.18
        import gnome # >= 2.18, includes bonobo.ui
        import gnomeapplet # >= 2.18, included in python-gnome2-desktop
        import pynotify # >= 0.1.1
    except ImportError, err:
        dialog = gtk.MessageDialog(type=gtk.MESSAGE_ERROR,
                                    buttons=gtk.BUTTONS_CLOSE,
                                    message_format='%s\n\nPlease install required dependencies.' % err)
        dialog.run()
        dialog.destroy()
        sys.exit(1)

def get_timer_id(gconf_wrapper):
    path_components = gconf_wrapper.get_base_path().split('/')
    
    # Use the second component from the end, which should usually be 'applet_*',
    # where '*' is some integer assigned by the system.
    # It could also be 'timer-applet' if we're running in standalone mode.
    # D-Bus doesn't like hyphens in object paths, so we have to replace them
    # with underscores.
    return path_components[-2].replace('-', '_')

def applet_factory(applet, iid):
    check_dependencies()

    timer = Timer()
    gconf_wrapper = AppletGConfWrapper(applet,
                                       '/schemas/apps/timer-applet/prefs',
                                       '/apps/timer-applet/prefs')
    timer_id = get_timer_id(gconf_wrapper)
    print 'Timer ID: %s' % timer_id
    
    if timer_manager is not None:
        timer_manager.register_timer_id(timer_id)
        applet.connect('destroy', lambda sender: timer_manager.unregister_timer_id(timer_id))

    TimerApplet(global_controller.get_presets_store(),
                global_controller.get_manage_presets_dialog(),
                applet,
                timer,
                gconf_wrapper)
    
    timer_obj_path = path.join(DBUS_OBJ_NAMESPACE, 'Timers', timer_id)
    print 'Timer D-Bus object path: %s' % timer_obj_path
    
    try:
        TimerService(DBUS_BUS_NAME, timer_obj_path, timer)
    except Exception, err:
        print 'ERROR: Could not start TimerService. D-Bus support will not be available. Error message: %s' % err
    
    return True

if __name__ == '__main__':
    windowed_mode = (len(sys.argv) > 1 and sys.argv[1] == '-w')
    
    if windowed_mode:
        win = gtk.Window()
        win.set_title('Timer Applet')
        applet = gnomeapplet.Applet()
        applet_factory(applet, None)
        applet.reparent(win)
        
        applet.connect('destroy', gtk.main_quit)
        win.show()
        
        gtk.main()
    else:
        gnomeapplet.bonobo_factory(
            'OAFIID:TimerApplet_Factory',
            gnomeapplet.Applet.__gtype__,
            config.PACKAGE,
            config.VERSION,
            applet_factory)