~ubuntu-branches/ubuntu/vivid/hamster-applet/vivid

« back to all changes in this revision

Viewing changes to hamster/hamster-applet.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio, Robert Ancell, Andrew Starr-Bochicchio
  • Date: 2009-12-22 17:52:52 UTC
  • mfrom: (1.1.13 upstream) (5.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091222175252-2r447ri9x56hi4kl
Tags: 2.29.4-0ubuntu1
[ Robert Ancell ]
* debian/control.in:
  - Remove old debian VCS links

[ Andrew Starr-Bochicchio ]
* New upstream release. (LP: #488783)
 - Fixed problems with hamster interfering with 
   screensaver hibernation code. (LP: #448438)
 - Fixes to the dropdown in compiz (not spanning
   over virtual desktops anymore). (LP: #303572)

* Merge with Debian testing, remaining Ubuntu changes:
 - Adapt debian/watch to take unstable version.
 - Point Vcs field at lp:~ubuntu-desktop/hamster-applet/ubuntu

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# along with Project Hamster.  If not, see <http://www.gnu.org/licenses/>.
21
21
 
22
22
import gtk, gnomeapplet
23
 
import getopt, sys
 
23
import sys
 
24
from optparse import OptionParser
24
25
import os.path
25
26
import gettext, locale
26
27
import gnome
27
 
 
28
 
# check from AUTHORS file and if one found - we are running from sources
29
 
name = os.path.join(os.path.dirname(__file__), '..')
30
 
if os.path.exists(os.path.join(name, 'AUTHORS')):
31
 
    print 'Running from source folder, modifying PYTHONPATH'
32
 
    sys.path.insert(0, os.path.join(name, "hamster", "keybinder", ".libs"))
33
 
    sys.path.insert(0, name)
34
 
 
35
 
# Now the path is set, import our applet
36
 
from hamster import defs
37
 
from hamster.configuration import runtime
38
 
 
39
 
# Setup i18n
40
 
locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))
41
 
 
42
 
for module in (gettext, locale):
43
 
    module.bindtextdomain('hamster-applet', locale_dir)
44
 
    module.textdomain('hamster-applet')
45
 
 
46
 
    if hasattr(module, 'bind_textdomain_codeset'):
47
 
        module.bind_textdomain_codeset('hamster-applet','UTF-8')
48
 
 
49
 
 
50
 
from hamster.applet import HamsterApplet
 
28
import logging
 
29
import gobject
51
30
 
52
31
def applet_factory(applet, iid):
53
32
    applet.connect("destroy", on_destroy)
54
33
    applet.set_applet_flags(gnomeapplet.EXPAND_MINOR)
55
34
 
 
35
    from hamster.applet import HamsterApplet    
56
36
    hamster_applet = HamsterApplet(applet)
57
37
 
58
38
    applet.show_all()
73
53
    if gtk.main_level():
74
54
        gtk.main_quit()
75
55
 
76
 
def usage():
77
 
    print _(u"""Time tracker: Usage
78
 
$ hamster-applet [OPTIONS]
79
 
 
80
 
OPTIONS:
81
 
    -w, --window    Launch the applet in a standalone window for test purposes
82
 
                    (default=no).
83
 
    -s, --start     [stats|edit|prefs] Which window to launch on startup.
84
 
                    Use "stats" for overview window, "edit" to add new activity
85
 
                    and "prefs" to launch preferences
86
 
    -t  --trace-sql print out sql statements in terminal
87
 
    """)
88
 
 
89
56
if __name__ == "__main__":
90
 
    standalone = False
91
 
    start_window = None
 
57
    parser = OptionParser(usage = "hamster-applet [OPTIONS]")
 
58
    parser.add_option("-w", "--window",
 
59
                      action="store_true",
 
60
                      dest="standalone",
 
61
                      default=False,
 
62
                      help="Launch the applet in a standalone window")
 
63
    parser.add_option("-s",
 
64
                      "--start",
 
65
                      dest="start_window",
 
66
                      help="[stats|edit|prefs] Which window to launch on startup.")
 
67
    parser.add_option("-d", "--debug",
 
68
                      action="store_true",
 
69
                      dest="debug",
 
70
                      default=False,
 
71
                      help="set log level to debug")
 
72
    
 
73
    #these two come from bonobo
 
74
    parser.add_option("--oaf-activate-iid")
 
75
    parser.add_option("--oaf-ior-fd")
 
76
 
 
77
    (options, args) = parser.parse_args()
 
78
 
 
79
    # in console set logging lower, in panel write log to file
 
80
    log_format = "%(asctime)s %(levelname)s: %(message)s"
 
81
    if options.standalone or options.start_window:
 
82
        log_level = logging.INFO
 
83
        if options.debug:
 
84
            log_level = logging.DEBUG
 
85
 
 
86
        logging.basicConfig(level = log_level, format = log_format)
 
87
    else: #otherwise write to the sessions file
 
88
        logging.basicConfig(filename = os.path.join(os.path.expanduser("~"),
 
89
                                                    '.xsession-errors'),
 
90
                            format = log_format)
92
91
 
93
92
    try:
94
 
        opts, args = getopt.getopt(sys.argv[1:], "ws:t", ["window", "start=", "trace-sql"])
95
 
 
96
 
        for opt, args in opts:
97
 
            if opt in ("-w", "--window"):
98
 
                standalone = True
99
 
            elif opt in ("-s", "--start"):
100
 
                start_window = args
101
 
            elif opt in ("-t", "--trace-sql"):
102
 
                runtime.trace_sql = True
103
 
                
104
 
            
105
 
    except getopt.GetoptError:
106
 
        usage()
107
 
        print "Starting nevertheless, because applet dies otherwise (TODO)"
108
 
 
109
 
 
110
 
    gtk.window_set_default_icon_name("hamster-applet")
111
 
 
112
 
    if standalone:
113
 
        gnome.init(defs.PACKAGE, defs.VERSION)
114
 
 
115
 
        app = gtk.Window(gtk.WINDOW_TOPLEVEL)
116
 
        app.set_title(_(u"Time Tracker"))
 
93
        # by AUTHORS file determine if we run from sources or installed
 
94
        name = os.path.join(os.path.dirname(__file__), '..')
 
95
        if os.path.exists(os.path.join(name, 'AUTHORS')):
 
96
            logging.info("Running from source folder, modifying PYTHONPATH")
 
97
            sys.path.insert(0, os.path.join(name, "hamster", "keybinder", ".libs"))
 
98
            sys.path.insert(0, name)
 
99
        
 
100
        # Now the path is set, import our applet
 
101
        from hamster import defs
 
102
        from hamster.configuration import runtime
 
103
        
 
104
        # Setup i18n
 
105
        locale_dir = os.path.abspath(os.path.join(defs.DATA_DIR, "locale"))        
 
106
        for module in (gettext, locale):
 
107
            module.bindtextdomain('hamster-applet', locale_dir)
 
108
            module.textdomain('hamster-applet')
 
109
        
 
110
            if hasattr(module, 'bind_textdomain_codeset'):
 
111
                module.bind_textdomain_codeset('hamster-applet','UTF-8')
 
112
        
 
113
        gtk.window_set_default_icon_name("hamster-applet")
117
114
    
118
 
        applet = gnomeapplet.Applet()
119
 
        applet_factory(applet, None)
120
 
        applet.reparent(app)
121
 
        app.show_all()
122
 
 
123
 
        gtk.main()
124
 
 
125
 
    elif start_window:
126
 
        if start_window == "stats":
127
 
            from hamster.stats import StatsViewer
128
 
            stats_viewer = StatsViewer().show()
129
 
        elif start_window == "edit":
130
 
            from hamster.edit_activity import CustomFactController
131
 
            CustomFactController().show()
132
 
        elif start_window == "prefs":
133
 
            from hamster.preferences import PreferencesEditor
134
 
            PreferencesEditor().show()
 
115
        if options.start_window or options.standalone:
 
116
            gobject.set_application_name("hamster-applet")
 
117
            if options.start_window == "stats":
 
118
                from hamster.stats import StatsViewer
 
119
                stats_viewer = StatsViewer().show()
 
120
 
 
121
            elif options.start_window == "edit":
 
122
                from hamster.edit_activity import CustomFactController
 
123
                CustomFactController().show()
 
124
 
 
125
            elif options.start_window == "prefs":
 
126
                from hamster.preferences import PreferencesEditor
 
127
                PreferencesEditor().show()
 
128
 
 
129
            else: #default to main applet
 
130
                gnome.init(defs.PACKAGE, defs.VERSION)
 
131
        
 
132
                app = gtk.Window(gtk.WINDOW_TOPLEVEL)
 
133
                app.set_title(_(u"Time Tracker"))
135
134
            
136
 
        gtk.main()
 
135
                applet = gnomeapplet.Applet()
 
136
                applet_factory(applet, None)
 
137
                applet.reparent(app)
 
138
                app.show_all()
137
139
 
138
 
    else:
139
 
        gnomeapplet.bonobo_factory(
140
 
            "OAFIID:Hamster_Applet_Factory",
141
 
            gnomeapplet.Applet.__gtype__,
142
 
            defs.PACKAGE,
143
 
            defs.VERSION,
144
 
            applet_factory)
 
140
            gtk.main()    
 
141
        else:
 
142
            gnomeapplet.bonobo_factory(
 
143
                "OAFIID:Hamster_Applet_Factory",
 
144
                gnomeapplet.Applet.__gtype__,
 
145
                defs.PACKAGE,
 
146
                defs.VERSION,
 
147
                applet_factory)
 
148
    except:
 
149
        # make sure the error appears somewhere
 
150
        import traceback
 
151
        logging.error(traceback.format_exc())