File: alarmclock.py

package info (click to toggle)
exaile 0.2.11.1%2Bdebian-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 3,464 kB
  • ctags: 2,403
  • sloc: python: 17,416; ansic: 224; makefile: 163; perl: 153; sh: 125; sql: 74
file content (293 lines) | stat: -rw-r--r-- 6,810 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/env python

# Copyright (C) 2006 Adam Olsen
#
# This program 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 1, or (at your option)
# any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import gtk, time, gobject
from gettext import gettext as _
import xl.plugins as plugins

PLUGIN_NAME = _("Alarm Clock")
PLUGIN_AUTHORS = ['Adam Olsen <arolsen@gmail.com>']
PLUGIN_VERSION = "0.1.2"
PLUGIN_DESCRIPTION = _(r"""Plays music at a specific time.\n\nNote that when the 
specified time arrives, Exaile will just act like you pressed the play button, 
so be sure you have the music you want to hear in your playlist""")

PLUGIN_ENABLED = False
PLUGIN = None
SETTINGS = None
TIMER_ID = None
RANG = dict()

def configure():
    """
        Configures the time to ring
    """
    exaile = APP
    alarm_time = exaile.settings.get_str("alarm_time", plugin=plugins.name(__file__), default="12:30")
    (hours, minutes) = alarm_time.split(":")

    dialog = plugins.PluginConfigDialog(exaile.window, PLUGIN_NAME)
    hbox = gtk.HBox()
    # TRANSLATORS: Alarm time for the Alarm Clock plugin
    hbox.pack_start(gtk.Label(_("Alarm Time:  ")), False, False)
    hour = gtk.SpinButton(gtk.Adjustment(1, step_incr=1))
    hour.set_range(0, 23)
    hour.set_value(int(hours))
    hbox.pack_start(hour, False, False)
    hbox.pack_start(gtk.Label(":"), False, False)
    minute = gtk.SpinButton(gtk.Adjustment(1, step_incr=1))
    minute.set_range(0, 59)
    minute.set_value(int(minutes))
    hbox.pack_start(minute, False, False)
    dialog.child.pack_start(hbox, False, False)

    dialog.show_all()
    result = dialog.run()
    dialog.hide()

    if result == gtk.RESPONSE_OK:
        hour = hour.get_value()
        minute = minute.get_value()
        exaile.settings.set_str("alarm_time", "%02d:%02d" % (hour, minute),
            plugin=plugins.name(__file__))

def timeout_cb():
    """
        Called every two seconds.  If the plugin is not enabled, it does
        nothing.  If the current time matches the time specified, it starts
        playing
    """
    if not PLUGIN_ENABLED: return True
    alarm_time = SETTINGS.get_str("alarm_time", plugin=plugins.name(__file__), default="")
    if not alarm_time: return True

    current = time.strftime("%H:%M", time.localtime())
    if alarm_time == current:
        check = time.strftime("%m %d %Y %H:%M")
        if RANG.has_key(check): return True
        track = APP.player.current
        if track and (APP.player.is_playing() or APP.player.is_paused()): return True
        APP.play()

        RANG[check] = True

    return True

def initialize():
    """
        Starts the timer
    """
    global TIMER_ID, SETTINGS, APP
    exaile = APP
    SETTINGS = exaile.settings
    TIMER_ID = gobject.timeout_add(2000, timeout_cb)
    return True

def destroy():
    """
        Stops the timer for this plugin
    """
    if TIMER_ID:
        gobject.source_remove(TIMER_ID)

icon_data = ["16 16 168 2",
"  	c None",
". 	c #666864",
"+ 	c #6E716C",
"@ 	c #6D706B",
"# 	c #6B6D69",
"$ 	c #646661",
"% 	c #6B6D68",
"& 	c #888B86",
"* 	c #838783",
"= 	c #747976",
"- 	c #6C716E",
"; 	c #6E716E",
"> 	c #737773",
", 	c #777A75",
"' 	c #626460",
") 	c #6D706A",
"! 	c #999D98",
"~ 	c #727774",
"{ 	c #919692",
"] 	c #B1B6B0",
"^ 	c #B2B7AF",
"/ 	c #B2B7B0",
"( 	c #9CA19C",
"_ 	c #686D6B",
": 	c #757974",
"< 	c #616561",
"[ 	c #696C66",
"} 	c #989B96",
"| 	c #797E7B",
"1 	c #B3B8B1",
"2 	c #DADDD6",
"3 	c #E5E8E3",
"4 	c #E9EBE7",
"5 	c #E7E9E5",
"6 	c #DFE2DD",
"7 	c #CACEC7",
"8 	c #717573",
"9 	c #737672",
"0 	c #575A58",
"a 	c #848782",
"b 	c #767A78",
"c 	c #B7BCB5",
"d 	c #E1E4DE",
"e 	c #EAECE8",
"f 	c #EBEDEA",
"g 	c #ECEEEB",
"h 	c #E6E8E5",
"i 	c #B0B2AE",
"j 	c #BCC0BA",
"k 	c #797C79",
"l 	c #6B6F6B",
"m 	c #444746",
"n 	c #5A5E5B",
"o 	c #7C807C",
"p 	c #9A9F9B",
"q 	c #E0E3DD",
"r 	c #EBEDE9",
"s 	c #EAECE9",
"t 	c #E5E6E3",
"u 	c #EEF0ED",
"v 	c #D5D6D4",
"w 	c #888887",
"x 	c #BCBCBB",
"y 	c #E7EAE5",
"z 	c #B3B7B2",
"A 	c #6A6D6A",
"B 	c #4A4D4C",
"C 	c #5E625F",
"D 	c #6E7270",
"E 	c #BEC2BD",
"F 	c #E8EAE6",
"G 	c #EDEFEB",
"H 	c #E4E6E3",
"I 	c #A1A2A0",
"J 	c #A5A5A4",
"K 	c #5F5F5E",
"L 	c #969795",
"M 	c #EAEBE9",
"N 	c #EFF1EE",
"O 	c #E0E2DF",
"P 	c #656966",
"Q 	c #535755",
"R 	c #666B68",
"S 	c #C4C7C3",
"T 	c #ECEEEA",
"U 	c #EFF0ED",
"V 	c #EFF0EE",
"W 	c #A1A1A0",
"X 	c #AFAFAF",
"Y 	c #616161",
"Z 	c #E4E5E3",
"` 	c #F4F5F3",
" .	c #F3F4F2",
"..	c #626663",
"+.	c #525654",
"@.	c #525756",
"#.	c #646866",
"$.	c #C8CAC7",
"%.	c #F1F2EF",
"&.	c #ECEDEB",
"*.	c #949594",
"=.	c #6D6D6D",
"-.	c #5A5A5A",
";.	c #D4D5D4",
">.	c #F7F8F6",
",.	c #F5F6F4",
"'.	c #646765",
").	c #4B504E",
"!.	c #474B4B",
"~.	c #B1B4B1",
"{.	c #F1F2F0",
"].	c #EBECEB",
"^.	c #CFD0CF",
"/.	c #E8E9E8",
"(.	c #C2C2C2",
"_.	c #B8B8B7",
":.	c #F2F2F1",
"<.	c #F6F7F5",
"[.	c #D2D4D2",
"}.	c #626662",
"|.	c #3F4443",
"1.	c #6F7371",
"2.	c #E7E9E7",
"3.	c #F2F3F1",
"4.	c #F5F6F5",
"5.	c #FAFAF9",
"6.	c #EDEEED",
"7.	c #F6F7F6",
"8.	c #939593",
"9.	c #585B58",
"0.	c #343939",
"a.	c #434847",
"b.	c #636763",
"c.	c #858886",
"d.	c #E2E3E2",
"e.	c #F7F8F7",
"f.	c #F9F9F9",
"g.	c #FBFBFB",
"h.	c #FCFCFC",
"i.	c #F4F5F4",
"j.	c #A2A4A3",
"k.	c #5C5F5B",
"l.	c #414544",
"m.	c #474C4B",
"n.	c #606461",
"o.	c #797C7B",
"p.	c #C6C7C7",
"q.	c #F3F4F3",
"r.	c #F7F7F7",
"s.	c #D8D9D8",
"t.	c #929492",
"u.	c #5A5D5A",
"v.	c #454948",
"w.	c #3D4242",
"x.	c #525553",
"y.	c #5C5F5C",
"z.	c #606361",
"A.	c #5B5F5C",
"B.	c #5C5F5D",
"C.	c #505350",
"D.	c #3D4140",
"E.	c #2F3437",
"F.	c #383C3D",
"G.	c #444847",
"H.	c #464A48",
"I.	c #424745",
"J.	c #393D3C",
"K.	c #313537",
"          . + @ # $             ",
"      % & * = - ; > , '         ",
"    ) ! ~ { ] ^ / ( _ : <       ",
"  [ } | 1 2 3 4 5 6 7 8 9 0     ",
"  a b c d e f g g h i j k l m   ",
"n o p q r s t u v w x y z A B   ",
"C D E F G H I J K L M N O P Q   ",
"n R S T U V W X Y Z `  .e ..+.  ",
"@.#.$.G %.&.*.=.-.;.>.,.g '.).  ",
"!.P ~.V {.].^./.(._.:.<.[.}.|.  ",
"  C 1.2.3.` 4.5.5.6.7.:.8.9.0.  ",
"  a.b.c.d.7.e.f.g.h.i.j.k.l.    ",
"    m.n.o.p.q.g.r.s.t.u.v.      ",
"      w.x.y.z.A.z.B.C.D.        ",
"        E.F.G.H.I.J.K.          ",
"                                "]
PLUGIN_ICON = gtk.gdk.pixbuf_new_from_xpm_data(icon_data)