-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathhamster-applet
More file actions
executable file
·139 lines (110 loc) · 4.64 KB
/
hamster-applet
File metadata and controls
executable file
·139 lines (110 loc) · 4.64 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python
# - coding: utf-8 -
# Copyright (C) 2007, 2008 Toms Bauģis <toms.baugis at gmail.com>
# Copyright (C) 2007 Patryk Zawadzki <patrys at pld-linux.org>
# This file is part of Project Hamster.
# Project Hamster is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# Project Hamster is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Project Hamster. If not, see <http://www.gnu.org/licenses/>.
import gtk, gnomeapplet
import sys
from optparse import OptionParser
import os.path
import gnome
import logging
import gobject
import glib
def applet_factory(applet, iid):
applet.connect("destroy", on_destroy)
applet.set_applet_flags(gnomeapplet.EXPAND_MINOR)
from hamster.applet import HamsterApplet
hamster_applet = HamsterApplet(applet)
applet.show_all()
applet.set_background_widget(applet)
return True
def on_destroy(event):
from hamster.configuration import runtime, conf
# handle config option to stop tracking on shutdown
if conf.get("stop_on_shutdown"):
todays_facts = runtime.storage.get_todays_facts()
if todays_facts and todays_facts[-1].end_time is None:
runtime.storage.stop_tracking()
if gtk.main_level():
gtk.main_quit()
if __name__ == "__main__":
# First thing, ensure our WM_CLASS is hamster-applet, which
# matches the .desktop file.
glib.set_prgname("hamster-applet")
gtk.gdk.threads_init()
parser = OptionParser(usage = "hamster-applet [OPTIONS]")
parser.add_option("-w", "--window",
action="store_true",
dest="standalone",
default=False,
help="Launch the applet in a standalone window")
parser.add_option("-s",
"--start",
dest="start_window",
help="[stats|edit|prefs] Which window to launch on startup.")
parser.add_option("-d", "--debug",
action="store_true",
dest="debug",
default=False,
help="set log level to debug")
#these two come from bonobo
parser.add_option("--oaf-activate-iid")
parser.add_option("--oaf-ior-fd")
(options, args) = parser.parse_args()
# in console set logging lower, in panel write log to file
log_format = "%(asctime)s %(levelname)s: %(message)s"
if options.standalone or options.start_window:
log_level = logging.INFO
if options.debug:
log_level = logging.DEBUG
logging.basicConfig(level = log_level, format = log_format)
else: #otherwise write to the sessions file
logging.basicConfig(filename = os.path.join(os.path.expanduser("~"),
'.xsession-errors'),
format = log_format)
try:
from hamster.lib import i18n
i18n.setup_i18n()
from hamster.configuration import runtime, dialogs
gtk.window_set_default_icon_name("hamster-applet")
if options.start_window or options.standalone:
gobject.set_application_name("hamster-applet")
if (options.start_window or "").startswith("over"):
dialogs.overview.show()
elif options.start_window == "stats":
dialogs.stats.show()
elif options.start_window == "edit":
dialogs.edit.show()
elif options.start_window == "prefs":
dialogs.prefs.show()
else: #default to main applet
gnome.init("hamster-applet", runtime.version)
app = gtk.Window(gtk.WINDOW_TOPLEVEL)
app.set_title(_(u"Time Tracker"))
applet = gnomeapplet.Applet()
applet_factory(applet, None)
applet.reparent(app)
app.show_all()
gtk.main()
else:
gnomeapplet.bonobo_factory(
"OAFIID:Hamster_Applet_Factory",
gnomeapplet.Applet.__gtype__,
"hamster-applet",
runtime.version,
applet_factory)
except:
# make sure the error appears somewhere
import traceback
logging.error(traceback.format_exc())