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
|
#!/usr/bin/env python
"""
applet.py
by Jason Conti
February 16, 2010
The main applet code.
"""
import pygtk
pygtk.require('2.0')
import gnomeapplet
import gtk
import logging
import os.path
import sys
from optparse import OptionParser
from RecentNotificationsApplet import RecentNotificationsApplet
def applet_factory(applet, iid):
RecentNotificationsApplet(applet, iid)
return True
def run_in_window():
main_window = gtk.Window()
main_window.set_title("Applet")
main_window.connect("destroy", gtk.main_quit)
app = gnomeapplet.Applet()
applet_factory(app, None)
app.reparent(main_window)
main_window.show_all()
gtk.main()
def initialize_applet():
gnomeapplet.bonobo_factory("OAFIID:RecentNotificationsApplet_Factory",
gnomeapplet.Applet.__gtype__,
"hello", "0", applet_factory)
# Get command line options
def parse_options(args):
usage = "Usage: %prog [options]"
parser = OptionParser(usage=usage)
parser.add_option("-w", "--windowed", action="store_true", dest="windowed", default=False, metavar=" ",
help="run the applet in a window for testing purposes [default: %default]")
# Need to specify these options, because they are provided when adding the applet to a panel
# and OptionParser raises an exception for invalid args
parser.add_option("--oaf-activate-iid")
parser.add_option("--oaf-ior-fd")
options, extra = parser.parse_args(args)
return options
def main():
logging.basicConfig(filename=os.path.expanduser("~/.cache/recent-notifications.log"),
level=logging.DEBUG)
options = parse_options(sys.argv)
if options.windowed:
run_in_window()
else:
initialize_applet()
if __name__ == '__main__':
main()
|