~jconti/recent-notifications/trunk

« back to all changes in this revision

Viewing changes to recent-notifications

  • Committer: Jason Conti
  • Date: 2010-02-21 00:51:16 UTC
  • Revision ID: jason.conti@gmail.com-20100221005116-6r8y8tta8f21h3x9
Reorganizing to make it easier to build a package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
3
applet.py
 
4
by Jason Conti
 
5
February 16, 2010
 
6
 
 
7
The main applet code.
 
8
"""
 
9
 
 
10
import pygtk
 
11
pygtk.require('2.0')
 
12
 
 
13
import gnomeapplet
 
14
import gtk
 
15
import logging
 
16
import os.path
 
17
import sys
 
18
 
 
19
from optparse import OptionParser
 
20
 
 
21
from recent_notifications.RecentNotifications import RecentNotifications
 
22
 
 
23
def applet_factory(applet, iid):
 
24
  RecentNotifications(applet, iid)
 
25
  return True
 
26
 
 
27
def run_in_window():
 
28
  main_window = gtk.Window()
 
29
  main_window.set_title("Applet")
 
30
  main_window.connect("destroy", gtk.main_quit)
 
31
  app = gnomeapplet.Applet()
 
32
  applet_factory(app, None)
 
33
  app.reparent(main_window)
 
34
  main_window.show_all()
 
35
  gtk.main()
 
36
 
 
37
def initialize_applet():
 
38
  gnomeapplet.bonobo_factory("OAFIID:RecentNotificationsApplet_Factory", 
 
39
      gnomeapplet.Applet.__gtype__, 
 
40
      "hello", "0", applet_factory)
 
41
 
 
42
# Get command line options
 
43
def parse_options(args):
 
44
  usage = "Usage: %prog [options]"
 
45
  parser = OptionParser(usage=usage)
 
46
 
 
47
  parser.add_option("-w", "--windowed", action="store_true", dest="windowed", default=False, metavar=" ",
 
48
      help="run the applet in a window for testing purposes [default: %default]")
 
49
  # Need to specify these options, because they are provided when adding the applet to a panel
 
50
  # and OptionParser raises an exception for invalid args
 
51
  parser.add_option("--oaf-activate-iid")
 
52
  parser.add_option("--oaf-ior-fd")
 
53
 
 
54
  options, extra = parser.parse_args(args)
 
55
 
 
56
  return options
 
57
 
 
58
def main():
 
59
  logging.basicConfig(filename=os.path.expanduser("~/.cache/recent-notifications.log"),
 
60
      level=logging.DEBUG)
 
61
 
 
62
  options = parse_options(sys.argv)
 
63
 
 
64
  if options.windowed:
 
65
    run_in_window()
 
66
  else:
 
67
    initialize_applet()
 
68
 
 
69
if __name__ == '__main__':
 
70
  main()