4
# Alarm Clock is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
11
# You should have received a copy of the GNU General Public License
12
# along with Alarm Clock; if not, write to the Free Software Foundation, Inc.,
13
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15
# Copyright 2007-2008 Tomasz Salacinski <tsalacinski@gmail.com>
24
print _("Error loading GTK+ libraries. Check if they are properly")
25
print _("installed on your system.")
31
msgDialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
32
gtk.BUTTONS_CLOSE, _("Error!"))
33
msgDialog.format_secondary_text(Text)
48
from gettext import gettext as _
53
Error (_("Error loading pynotify module!"))
56
from threading import Thread
58
Error (_("Cannot initialize threading library!"))
66
Error(_("Missing GStreamer Python bindings!"))
69
locale.setlocale(locale.LC_ALL, '')
70
gettext.textdomain('pyalarm')
71
gtk.glade.textdomain('pyalarm')
72
gettext.bindtextdomain('pyalarm', "%s/locale" % os.path.split(os.getcwd())[0])
73
gtk.glade.bindtextdomain('pyalarm', "%s/locale" % os.path.split(os.getcwd())[0])
74
gettext.bindtextdomain('pyalarm', )
80
AnotherInstance = False
82
# Checking if there is only one instance running
84
InstanceFile = file(os.getenv("HOME") + "/.config/Alarm-Clock/lock", "r")
85
Read = InstanceFile.readline()
87
Date = "%s/%s/%s %s:%s:%s" % (datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day, datetime.datetime.now().hour, datetime.datetime.now().minute, datetime.datetime.now().second)
88
Date2 = "%s/%s/%s %s:%s:%s" % (datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day, datetime.datetime.now().hour, datetime.datetime.now().minute, datetime.datetime.now().second - 1)
89
if Date == Read or Read == Date2:
90
msgDialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _("An instance is running"))
91
msgDialog.format_secondary_text(_("Another instance of Alarm Clock is already running, aborting."))
92
AnotherInstance = True
102
player = gst.element_factory_make("playbin", "player")
104
MainWindowGlade = gtk.glade.XML('main.glade', 'main_window')
105
MainWindow = MainWindowGlade.get_widget('main_window')
106
StatusIcon = gtk.status_icon_new_from_file('gfx/alarm-clock.svg')
107
StatusIcon.set_tooltip(_("Alarm Clock"))
113
def Initialize(self, Min = False):
114
StartGUI().RunMe(Min)
115
gtk.gdk.threads_init()
116
gtk.gdk.threads_enter()
119
except KeyboardInterrupt:
120
print "Keyboard interrupt, closing."
122
gtk.gdk.threads_leave()
124
def RunMe(self, Min = False):
125
self.main_hidden = False
128
self.minimized_status_file = file(os.getenv("HOME") + "/.config/Alarm-Clock/minimized", "r")
129
self.minimized = self.minimized_status_file.readline().strip()
135
self.main_hidden = True
137
if self.minimized == "1":
138
self.main_hidden = True
141
MainWindow.set_icon_from_file('gfx/alarm-clock.svg')
143
self.LoadConfigFiles()
144
MainWindow.resize(self.configlist[1][0], self.configlist[1][1])
145
MainWindow.move(self.configlist[0][0], self.configlist[0][1])
146
if self.minimized == "0":
148
self.Event = MainWindowGlade.get_widget('main_event_box')
149
self.Event.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(65535, 65535, 65535, 65535))
151
self.ConnectSignals()
153
self.AT = CheckAlarmThread(MainWindowGlade.get_widget('status_bar'), MainWindowGlade,StatusIcon,self.alarm_model, self.row, self.TreeSelection)
157
self.QuitApplication()
159
pynotify.init("Alarm-Clock")
164
self.alarm_model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
166
self.tree = gtk.TreeView(self.alarm_model)
167
self.alarm_scroll = MainWindowGlade.get_widget('alarms_main_scroll')
168
self.alarm_scroll.add(self.tree)
171
self.tree.set_enable_search(True)
172
self.tree.set_search_column(2)
174
self.type_renderer = gtk.CellRendererText()
175
self.type_column = gtk.TreeViewColumn(_("Type"), self.type_renderer, text=0)
176
self.type_column.set_min_width(140)
178
self.date_renderer = gtk.CellRendererText()
179
self.date_column = gtk.TreeViewColumn(_("Date and Time"), self.date_renderer, text=1)
180
self.date_column.set_min_width(180)
182
self.summary_renderer = gtk.CellRendererText()
183
self.summary_column = gtk.TreeViewColumn(_("Name"), self.summary_renderer, text=2)
184
self.summary_column.set_expand(True)
186
self.tree.append_column(self.summary_column)
187
self.tree.append_column(self.type_column)
188
self.tree.append_column(self.date_column)
189
self.TreeSelection = self.tree.get_selection()
191
self.tree.connect("button_press_event", self.TreeButtonPress)
192
self.tree.connect("key_press_event", self.TreeKeyPress)
194
# I've learnt a lot watching GNOME-Schedule to write these two following functions:)
195
# Some of the code comes from GNOME-Schedule by Gaute Hope eg@gaute.vetsj.com
197
def TreeButtonPress(self,widget,button):
198
if button.type == gtk.gdk._2BUTTON_PRESS:
199
self.ChangeAlarmPrefs(None)
200
if button.button == 3:
201
self.pop = gtk.Menu()
203
self.add_alarm = gtk.ImageMenuItem(_("Add new alarm..."), False)
204
self.add_image = gtk.Image()
205
self.add_image.set_from_stock("gtk-add", gtk.ICON_SIZE_MENU)
206
self.add_alarm.set_image(self.add_image)
208
self.add_counter = gtk.ImageMenuItem(_("Add new counter..."), False)
209
self.add_cntr_image = gtk.Image()
210
self.add_cntr_image.set_from_stock("gtk-add", gtk.ICON_SIZE_MENU)
211
self.add_counter.set_image(self.add_cntr_image)
213
self.sep1 = gtk.SeparatorMenuItem()
214
self.sep2 = gtk.SeparatorMenuItem()
216
self.remove_alarm = gtk.ImageMenuItem(_("Remove this alarm"), False)
217
self.remove_image = gtk.Image()
218
self.remove_image.set_from_stock("gtk-remove", gtk.ICON_SIZE_MENU)
219
self.remove_alarm.set_image(self.remove_image)
221
self.alarm_properties = gtk.ImageMenuItem("gtk-properties", False)
224
self.pop.add(self.add_alarm)
225
self.pop.add(self.add_counter)
226
self.pop.add(self.sep1)
227
self.pop.add(self.remove_alarm)
228
self.pop.add(self.sep2)
229
self.pop.add(self.alarm_properties)
232
self.add_alarm.connect("activate", self.AddAlarmDialog)
233
self.add_counter.connect("activate", self.AddSimpleCounterDialog)
234
self.remove_alarm.connect("activate", self.RemoveAlarmDialog)
235
self.alarm_properties.connect("activate", self.ChangeAlarmPrefs)
238
self.pop.popup(None, None, None, button.button, button.time)
240
def TreeKeyPress (self,widget,key):
241
key = gtk.gdk.keyval_name(key.keyval)
243
if key == "Delete" or key == "KP_Delete":
244
self.RemoveAlarmDialog(None)
245
if (key == "Return" or key == "KP_Return"):
246
self.ChangeAlarmPrefs(None)
249
def ConnectSignals(self):
250
self.Signals = { "show_about" : self.ShowAboutDialog,
251
"hide_application" : self.HideMainWindow,
252
"quit_application" : self.QuitApplication,
253
"add_alarm" : self.AddAlarmDialog,
254
"remove_alarm" : self.RemoveAlarmDialog,
255
"change_alarm_prefs" : self.ChangeAlarmPrefs,
256
"save_alarms" : self.SaveAlarms,
257
"open_alarms" : self.OpenAlarms,
258
"new_alarms" : self.NewAlarms,
259
"test_alarm" : self.TestAlarm,
260
"stop_the_sound" : self.StopTheSound,
261
"birthdays_templates_manager_run" : self.BirthdaysnTemplates,
262
"clicked_prefs" : self.PreferencesDialog,
265
MainWindowGlade.signal_autoconnect(self.Signals)
267
StatusIcon.connect("activate", self.StatusClicked)
268
StatusIcon.connect("popup-menu", self.StatusPopup)
271
def PreferencesDialog(self,obj):
272
self.Prefs_Glade = gtk.glade.XML('main.glade', 'prefs_dialog')
273
self.Prefs = self.Prefs_Glade.get_widget('prefs_dialog')
274
self.Prefs.set_icon_from_file('gfx/alarm-clock.svg')
276
self.MinFil = file(os.getenv("HOME") + "/.config/Alarm-Clock/minimized", "r")
278
self.MinFil = file(os.getenv("HOME") + "/.config/Alarm-Clock/minimized", "w")
279
print >> self.MinFil, "0"
281
self.MinFil = file(os.getenv("HOME") + "/.config/Alarm-Clock/minimized", "r")
283
self.Val = self.MinFil.read()
287
self.MinCheck = self.Prefs_Glade.get_widget('start_minimized_check')
289
if int(self.Val) == 1:
290
self.MinCheck.set_active(True)
294
self.minimized_status_file = file(os.getenv("HOME") + "/.config/Alarm-Clock/minimized", "w")
295
if self.MinCheck.get_active():
296
print >> self.minimized_status_file, "1"
297
self.minimized_status_file.close()
299
print >> self.minimized_status_file, "0"
300
self.minimized_status_file.close()
304
def BirthdaysnTemplates(self,obj):
305
self.Temp_Glade = gtk.glade.XML('main.glade', 'birthdays_templates_manager')
306
self.Template = self.Temp_Glade.get_widget('birthdays_templates_manager')
307
self.Template.set_icon_from_file('gfx/alarm-clock.svg')
308
self.ls = self.Temp_Glade.get_widget('temp_list_scroll')
311
self.tl = gtk.ListStore(gobject.TYPE_STRING)
312
self.TempTree = gtk.TreeView(self.tl)
314
self.temp_renderer = gtk.CellRendererText()
315
self.temp_column = gtk.TreeViewColumn(_("Template name"), self.temp_renderer, text=0)
317
self.ls.add(self.TempTree)
320
self.TempTree.append_column(self.temp_column)
321
self.TempTree.set_headers_visible(True)
323
self.dc = { "add_template" : self.AddTemplate,
324
"remove_template" : self.RemoveTemplate,
325
"template_properties" : self.TemplateProperties,
326
"add_birthday" : self.AddBirthday,
327
"remove_birthday" : self.RemoveBirthday,
328
"birthday_properties" : self.BirthdayProperties,
331
self.temp_event = self.Temp_Glade.get_widget('temp_event')
332
self.color = gtk.gdk.Color()
333
self.color.red = 65535
334
self.color.green = 65535
335
self.color.blue = 65535
336
self.temp_event.modify_bg(gtk.STATE_NORMAL, self.color)
339
self.TemplateSelection = self.TempTree.get_selection()
340
self.Temp_Glade.signal_autoconnect(self.dc)
343
self.TemplateSelection.select_path(0,)
349
self.BirthNotebook = self.Temp_Glade.get_widget('birth_notebook')
351
self.birth_event = self.Temp_Glade.get_widget('birth_event')
352
self.color = gtk.gdk.Color()
353
self.color.red = 65535
354
self.color.green = 65535
355
self.color.blue = 65535
356
self.birth_event.modify_bg(gtk.STATE_NORMAL, self.color)
358
self.List = self.Temp_Glade.get_widget('birth_list_scroll')
361
self.Store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
362
self.BirthTree = gtk.TreeView(self.Store)
363
self.BirthSel = self.BirthTree.get_selection()
365
self.name_renderer = gtk.CellRendererText()
366
self.name_column = gtk.TreeViewColumn(_("First and last name"), self.name_renderer, text=0)
367
self.name_column.set_expand(True)
369
self.Date_renderer = gtk.CellRendererText()
370
self.Date_column = gtk.TreeViewColumn(_("Birthday date"), self.Date_renderer, text=1)
371
self.Date_column.set_expand(False)
373
self.List.add(self.BirthTree)
374
self.BirthTree.show()
376
self.BirthTree.append_column(self.name_column)
377
self.BirthTree.append_column(self.Date_column)
378
self.BirthTree.set_headers_visible(True)
381
self.RefreshBirthdayList()
382
self.RefreshTemplateList()
383
self.BirthSel.select_path(0,)
384
self.TemplateSelection.select_path(0,)
399
self.Template.destroy()
401
def AddBirthday(self,obj):
402
self.Birth_Glade = gtk.glade.XML('main.glade', 'add_birthday_dialog')
403
self.Birth = self.Birth_Glade.get_widget('add_birthday_dialog')
404
self.Cal = self.Birth_Glade.get_widget('birth_calendar')
405
self.Name = self.Birth_Glade.get_widget('name_input')
407
self.temp_row = self.BirthSel.get_selected_rows()
410
self.temp_row = self.temp_row[1][0][0]
415
self.Res = self.Birth.run()
417
if self.Res == gtk.RESPONSE_OK:
418
self.BirthDate = self.Cal.get_date()
419
self.BirthName = self.Name.get_text()
421
self.File = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "a")
423
self.Tuple = [("%i/%i/%i") % (self.BirthDate[0], self.BirthDate[1], self.BirthDate[2]), self.BirthName]
425
print >> self.File, self.Tuple
429
self.RefreshBirthdayList()
430
self.BirthSel.select_path(self.temp_row,)
435
def RefreshBirthdayList(self):
436
self.brth_list = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "r")
440
for line in self.brth_list:
442
self.date_data = re.search('(\d+)/(\d+)/(\d+)', self.d[0])
443
self.oy = int(self.date_data.group(1))
444
self.om = int(self.date_data.group(2)) + 1
445
self.od = int(self.date_data.group(3))
448
self.om = "0" + str(self.om)
451
self.Store.append([self.d[1], ("%s/%s/%s") % (self.od, self.om, self.oy)])
452
self.count = self.count + 1
455
self.Temp_Glade.get_widget('remove_birthday').set_sensitive(False)
456
self.Temp_Glade.get_widget('birthday_prop').set_sensitive(False)
457
self.Temp_Glade.get_widget('birth_notebook').set_current_page(1)
459
self.Temp_Glade.get_widget('remove_birthday').set_sensitive(True)
460
self.Temp_Glade.get_widget('birthday_prop').set_sensitive(True)
461
self.Temp_Glade.get_widget('birth_notebook').set_current_page(0)
465
def BirthdayProperties(self,obj):
466
self.Birth_Glade = gtk.glade.XML('main.glade', 'add_birthday_dialog')
467
self.Birth = self.Birth_Glade.get_widget('add_birthday_dialog')
468
self.Cal = self.Birth_Glade.get_widget('birth_calendar')
469
self.Name = self.Birth_Glade.get_widget('name_input')
471
self.temp_row = self.BirthSel.get_selected_rows()
474
self.temp_row = self.temp_row[1][0][0]
478
self.fg = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "r")
479
self.df = self.fg.readlines()
481
self.info = self.df[self.temp_row]
484
self.date_data = re.search('(\d+)/(\d+)/(\d+)', eval(self.info)[0])
485
self.oy = int(self.date_data.group(1))
486
self.om = int(self.date_data.group(2))
487
self.od = int(self.date_data.group(3))
489
self.Cal.select_day(self.od)
490
self.Cal.select_month(self.om, self.oy)
492
self.Name.set_text(eval(self.info)[1])
495
self.Res = self.Birth.run()
497
if self.Res == gtk.RESPONSE_OK:
498
self.BirthDate = self.Cal.get_date()
499
self.BirthName = self.Name.get_text()
501
self.File = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "a")
503
self.Tuple = [("%i/%i/%i") % (self.BirthDate[0], self.BirthDate[1], self.BirthDate[2]), self.BirthName]
506
self.RefreshBirthdayList()
507
self.BirthSel.select_path(self.temp_row,)
509
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "r")
510
self.lines = self.fbuf.readlines()
512
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "w")
515
for line in self.lines:
516
if self.counter == self.temp_row:
517
print >> self.f, self.Tuple
518
self.counter = self.counter + 1
521
self.counter = self.counter + 1
526
self.RefreshBirthdayList()
527
self.BirthSel.select_path(self.temp_row,)
537
def RemoveBirthday(self,obj):
538
self.row = self.BirthSel.get_selected_rows()
539
self.row = self.row[1][0][0]
542
self.msgDialog = gtk.MessageDialog(self.Template, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Birthday removal"))
543
self.msgDialog.format_secondary_text(_("Are you sure you wish to remove this birthday?"))
545
if self.msgDialog.run() == gtk.RESPONSE_YES:
546
self.msgDialog.destroy()
547
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "r")
548
self.lines = self.fbuf.readlines()
551
for line in self.lines:
552
if self.counter == self.row:
553
self.counter = self.counter + 1
555
self.new_lines.append(line)
556
self.counter = self.counter + 1
560
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "w")
563
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "a")
564
for line in self.new_lines:
565
self.fbuf.write(line)
567
self.RefreshBirthdayList()
570
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "r")
578
if self.row >= self.i:
579
self.BirthSel.select_path(self.i - 1,)
581
self.BirthSel.select_path(self.row,)
583
self.BirthSel.select_path(0,)
585
self.msgDialog.destroy()
614
def RefreshTemplateList(self):
615
self.tmp_list = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "r")
620
for line in self.tmp_list:
622
self.tl.append([self.d[0]])
623
self.count = self.count + 1
626
self.Temp_Glade.get_widget('remove_template').set_sensitive(False)
627
self.Temp_Glade.get_widget('temp_prop').set_sensitive(False)
628
self.Temp_Glade.get_widget('temp_notebook').set_current_page(1)
630
self.Temp_Glade.get_widget('remove_template').set_sensitive(True)
631
self.Temp_Glade.get_widget('temp_prop').set_sensitive(True)
632
self.Temp_Glade.get_widget('temp_notebook').set_current_page(0)
637
def AddTemplate(self,obj):
639
self.ClearAlarmValues()
640
self.temp_row = self.TemplateSelection.get_selected_rows()
642
self.temp_row = self.temp_row[1][0][0]
645
self.value = self.AlarmPrefs().run()
646
if self.value == gtk.RESPONSE_OK:
649
self.AlarmBuffer[0] = self.NameEntry.get_text()
650
self.AlarmBuffer[1] = "%i:%i" % (self.AlarmProps.get_widget('alarm_props_hour_spin').get_value(), self.AlarmProps.get_widget('alarm_props_minute_spin').get_value())
651
if self.SingleRadio.get_active():
652
self.AlarmBuffer[2] = 0
653
if self.ScheduleRadio.get_active():
654
self.AlarmBuffer[2] = 1
655
if self.TodayRadio.get_active():
656
self.AlarmBuffer[2] = 2
657
if self.TomorrowRadio.get_active():
658
self.AlarmBuffer[2] = 3
660
if self.SoundCheck.get_active():
661
self.AlarmBuffer[7] = True
663
self.AlarmBuffer[7] = False
664
if self.PassiveCheck.get_active():
665
self.AlarmBuffer[15] = True
667
self.AlarmBuffer[15] = False
668
if self.DialogCheck.get_active():
669
self.AlarmBuffer[19] = True
671
self.AlarmBuffer[19] = False
672
if self.CmdCheck.get_active():
673
self.AlarmBuffer[27] = True
675
self.AlarmBuffer[27] = False
676
if self.StdCheck.get_active():
677
self.AlarmBuffer[32] = True
679
self.AlarmBuffer[32] = False
682
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "a")
683
print >> self.f, self.AlarmBuffer
686
self.AlarmPropsWidget.destroy()
687
self.RefreshTemplateList()
688
self.TemplateSelection.select_path(self.temp_row,)
690
def RemoveTemplate(self,obj):
691
self.row = self.TemplateSelection.get_selected_rows()
692
self.row = self.row[1][0][0]
695
self.msgDialog = gtk.MessageDialog(self.Template, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Alarm removal"))
696
self.msgDialog.format_secondary_text(_("Are you sure you wish to remove this template?"))
698
if self.msgDialog.run() == gtk.RESPONSE_YES:
699
self.msgDialog.destroy()
700
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "r")
701
self.lines = self.fbuf.readlines()
704
for line in self.lines:
705
if self.counter == self.row:
706
self.counter = self.counter + 1
708
self.new_lines.append(line)
709
self.counter = self.counter + 1
713
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "w")
716
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "a")
717
for line in self.new_lines:
718
self.fbuf.write(line)
720
self.RefreshTemplateList()
723
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "r")
731
if self.row >= self.i:
732
self.TemplateSelection.select_path(self.i - 1,)
734
self.TemplateSelection.select_path(self.row,)
736
self.TemplateSelection.select_path(0,)
738
self.msgDialog.destroy()
741
def TemplateProperties(self,obj):
742
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "r")
743
self.line = self.f.readlines()
744
self.AlarmBuffer = eval(self.line[self.TemplateSelection.get_selected_rows()[1][0][0]])
746
self.value = self.AlarmPrefs().run()
748
if self.value == gtk.RESPONSE_OK:
751
self.AlarmBuffer[0] = self.NameEntry.get_text()
752
self.AlarmBuffer[1] = "%i:%i" % (self.AlarmProps.get_widget('alarm_props_hour_spin').get_value(), self.AlarmProps.get_widget('alarm_props_minute_spin').get_value())
753
if self.SingleRadio.get_active():
754
self.AlarmBuffer[2] = 0
755
if self.ScheduleRadio.get_active():
756
self.AlarmBuffer[2] = 1
757
if self.TodayRadio.get_active():
758
self.AlarmBuffer[2] = 2
759
if self.TomorrowRadio.get_active():
760
self.AlarmBuffer[2] = 3
761
if self.SoundCheck.get_active():
762
self.AlarmBuffer[7] = True
764
self.AlarmBuffer[7] = False
765
if self.PassiveCheck.get_active():
766
self.AlarmBuffer[15] = True
768
self.AlarmBuffer[15] = False
769
if self.DialogCheck.get_active():
770
self.AlarmBuffer[19] = True
772
self.AlarmBuffer[19] = False
773
if self.CmdCheck.get_active():
774
self.AlarmBuffer[27] = True
776
self.AlarmBuffer[27] = False
777
if self.StdCheck.get_active():
778
self.AlarmBuffer[32] = True
780
self.AlarmBuffer[32] = False
782
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "r")
783
self.lines = self.fbuf.readlines()
785
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "w")
787
self.row = self.TemplateSelection.get_selected_rows()[1][0][0]
788
for line in self.lines:
789
if self.counter == self.TemplateSelection.get_selected_rows()[1][0][0]:
790
print >> self.f, self.AlarmBuffer
791
self.counter = self.counter + 1
794
self.counter = self.counter + 1
796
self.AlarmPropsWidget.destroy()
797
self.RefreshTemplateList()
798
self.TemplateSelection.select_path(self.row,)
800
def StopTheSound(self,obj):
801
MainWindowGlade.get_widget('stop_sound').set_sensitive(False)
803
player.set_state(gst.STATE_NULL)
804
player.set_property("volume", 0)
807
def StatusClicked(self,obj):
809
self.fc = file(os.getenv("HOME") + "/.config/Alarm-Clock/configuration", "r")
810
self.Pos = self.fc.readline()
812
self.Pos = eval(self.Pos)
813
MainWindow.move(self.Pos[0][0], self.Pos[0][1])
814
MainWindow.resize(self.Pos[1][0], self.Pos[1][1])
816
self.main_hidden = False
818
self.fc = file(os.getenv("HOME") + "/.config/Alarm-Clock/configuration", "w")
819
print >> self.fc, [MainWindow.get_position(), MainWindow.get_size()]
822
self.main_hidden = True
824
def StatusPopup(self,obj,v1,v2):
825
self.pop = gtk.Menu()
827
self.show_win = gtk.CheckMenuItem(_("Show main window on screen"), True)
828
self.show_win.set_active(self.main_hidden == False)
830
self.add_alarm = gtk.ImageMenuItem(_("Add new alarm..."), False)
831
self.add_image = gtk.Image()
832
self.add_image.set_from_stock("gtk-add", gtk.ICON_SIZE_MENU)
833
self.add_alarm.set_image(self.add_image)
835
self.add_counter = gtk.ImageMenuItem(_("Add new counter..."), False)
836
self.add_cntr_image = gtk.Image()
837
self.add_cntr_image.set_from_stock("gtk-add", gtk.ICON_SIZE_MENU)
838
self.add_counter.set_image(self.add_cntr_image)
842
self.sep1 = gtk.SeparatorMenuItem()
843
self.sep2 = gtk.SeparatorMenuItem()
844
self.quit_a = gtk.ImageMenuItem("gtk-quit", False)
846
self.pop.add(self.show_win)
847
self.pop.add(self.sep1)
848
self.pop.add(self.add_alarm)
849
self.pop.add(self.add_counter)
850
self.pop.add(self.sep2)
851
self.pop.add(self.quit_a)
854
self.quit_a.connect("activate", self.QuitApplication)
855
self.add_alarm.connect("activate", self.AddAlarmDialog)
856
self.show_win.connect("activate", self.StatusClicked)
857
self.add_counter.connect("activate", self.AddSimpleCounterDialog)
860
self.pop.popup(None, None, None, v1, v2)
862
def ShowAboutDialog(self,obj):
863
self.AboutDialog = gtk.AboutDialog()
864
self.AboutDialog.set_name (_("Alarm Clock"))
865
self.AboutDialog.set_version(version.get_version())
866
self.AboutDialog.set_copyright(_("(c) 2008 Tomasz SaÅaciÅski\n"
867
"<tsalacinski@gmail.com>\n"
870
self.AboutDialog.set_icon_from_file('gfx/alarm-clock.svg')
871
self.AboutDialog.set_transient_for(MainWindow)
872
self.AboutDialog.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
873
self.AboutDialog.set_website("http://www.alarm-clock.54.pl")
874
self.Authors = [_("Programming"), "\tTomasz SaÅaciÅski"]
875
self.AboutDialog.set_authors(self.Authors)
876
self.LogoPixbuf = gtk.gdk.pixbuf_new_from_file("gfx/alarm-clock.svg")
877
self.AboutDialog.set_logo(self.LogoPixbuf)
880
Alarm Clock is free software; you can redistribute it and/or modify
881
it under the terms of the GNU General Public License as published by
882
the Free Software Foundation; either version 2 of the License, or
883
(at your option) any later version.
885
Alarm Clock is distributed in the hope that it will be useful,
886
but WITHOUT ANY WARRANTY; without even the implied warranty of
887
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
888
GNU General Public License for more details.
890
You should have received a copy of the GNU General Public License
891
along with Alarm Clock; if not, write to the Free Software Foundation,
892
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA"""
894
self.AboutDialog.set_license(self.License)
896
self.Artists = ["""Alarm Clock icon come from the
897
Dropline Neu! icon theme"""]
899
self.AboutDialog.set_artists(self.Artists)
902
self.AboutDialog.run()
903
self.AboutDialog.destroy()
905
def HideMainWindow(self,obj,v1):
906
self.fc = file(os.getenv("HOME") + "/.config/Alarm-Clock/configuration", "w")
907
print >> self.fc, [MainWindow.get_position(), MainWindow.get_size()]
910
self.main_hidden = True
913
def QuitApplication(self,obj):
914
self.fc = file(os.getenv("HOME") + "/.config/Alarm-Clock/configuration", "w")
915
print >> self.fc, [MainWindow.get_position(), MainWindow.get_size()]
917
player.set_state(gst.STATE_NULL)
920
def ChangeAlarmPrefs(self,obj):
921
self.LoadCurrentAlarm()
922
self.value = self.AlarmPrefs().run()
924
if self.value == gtk.RESPONSE_OK:
927
self.AlarmBuffer[0] = self.NameEntry.get_text()
928
self.AlarmBuffer[1] = "%i:%i" % (self.AlarmProps.get_widget('alarm_props_hour_spin').get_value(), self.AlarmProps.get_widget('alarm_props_minute_spin').get_value())
929
if self.SingleRadio.get_active():
930
self.AlarmBuffer[2] = 0
931
if self.ScheduleRadio.get_active():
932
self.AlarmBuffer[2] = 1
933
if self.TodayRadio.get_active():
934
self.AlarmBuffer[2] = 0
935
self.AlarmBuffer[3] = "%s/%s/%s" % (datetime.datetime.now().year,
936
datetime.datetime.now().month - 1, datetime.datetime.now().day)
937
if self.TomorrowRadio.get_active():
938
self.AlarmBuffer[2] = 0
939
self.Today = datetime.datetime.now() + datetime.timedelta(days=1)
940
self.AlarmBuffer[3] = "%s/%s/%s" % (self.Today.year,
941
self.Today.month - 1, self.Today.day)
951
if self.SoundCheck.get_active():
952
self.AlarmBuffer[7] = True
954
self.AlarmBuffer[7] = False
955
if self.PassiveCheck.get_active():
956
self.AlarmBuffer[15] = True
958
self.AlarmBuffer[15] = False
959
if self.DialogCheck.get_active():
960
self.AlarmBuffer[19] = True
962
self.AlarmBuffer[19] = False
963
if self.CmdCheck.get_active():
964
self.AlarmBuffer[27] = True
966
self.AlarmBuffer[27] = False
967
if self.StdCheck.get_active():
968
self.AlarmBuffer[32] = True
970
self.AlarmBuffer[32] = False
973
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "r")
974
self.lines = self.fbuf.readlines()
976
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "w")
978
for line in self.lines:
979
if self.counter == self.TreeSelection.get_selected_rows()[1][0][0]:
980
print >> self.f, self.AlarmBuffer
981
self.counter = self.counter + 1
984
self.counter = self.counter + 1
987
self.row = self.TreeSelection.get_selected_rows()[1][0][0]
989
self.LoadConfigFiles()
991
self.AlarmPropsWidget.destroy()
994
def LoadCurrentAlarm(self):
995
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "r")
996
self.line = self.f.readlines()
998
self.AlarmBuffer = eval(self.line[self.TreeSelection.get_selected_rows()[1][0][0]])
1002
def AddAlarmDialog(self,obj):
1003
self.AddDialog = gtk.glade.XML('main.glade', 'add_alarm_dialog')
1004
self.AddDialogWidget = self.AddDialog.get_widget('add_alarm_dialog')
1005
self.AddDialogWidget.set_icon_from_file('gfx/alarm-clock.svg')
1007
self.AddAlarmSignals = { "new_alarm_radio_toggled" : self.NewAlarmRadioCheck, }
1008
self.AddDialog.signal_autoconnect(self.AddAlarmSignals)
1010
self.AddAlarmNew = self.AddDialog.get_widget('new_alarm_from_scratch_radio')
1011
self.AddAlarmTemplate = self.AddDialog.get_widget('create_from_template_radio')
1012
self.AddCounter = self.AddDialog.get_widget('create_counter')
1013
self.hbox = self.AddDialog.get_widget('mtable')
1014
self.AddAlarmNew.set_active(True)
1017
self.AddAlarmTemplateCombo = gtk.combo_box_new_text()
1018
self.hbox.attach(self.AddAlarmTemplateCombo, 1, 2, 2, 3)
1019
self.AddAlarmTemplateCombo.show()
1024
self.tmp_list = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "r")
1027
for line in self.tmp_list:
1029
self.AddAlarmTemplateCombo.append_text(self.d[0])
1030
self.count = self.count + 1
1034
self.tmp_list.close()
1037
self.AddAlarmTemplate.set_sensitive(True)
1038
self.AddAlarmTemplateCombo.set_sensitive(True)
1039
self.AddAlarmTemplateCombo.set_active(0)
1041
self.AddAlarmTemplate.set_sensitive(False)
1042
self.AddAlarmTemplateCombo.set_sensitive(False)
1044
self.NewAlarmRadioCheck(self.AddAlarmTemplate)
1046
self.result = self.AddDialogWidget.run()
1047
if self.result == gtk.RESPONSE_OK:
1048
if self.AddAlarmTemplate.get_active():
1049
self.AddDialogWidget.destroy()
1050
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "r")
1051
self.line = self.f.readlines()
1052
self.AlarmBuffer = eval(self.line[self.AddAlarmTemplateCombo.get_active()])
1054
self.value = self.AlarmPrefs().run()
1055
if self.value == gtk.RESPONSE_OK:
1059
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "a")
1060
self.AlarmBuffer[0] = self.NameEntry.get_text()
1061
self.AlarmBuffer[1] = "%i:%i" % (self.AlarmProps.get_widget('alarm_props_hour_spin').get_value(), self.AlarmProps.get_widget('alarm_props_minute_spin').get_value())
1062
if self.SingleRadio.get_active():
1063
self.AlarmBuffer[2] = 0
1064
if self.ScheduleRadio.get_active():
1065
self.AlarmBuffer[2] = 1
1067
if self.TodayRadio.get_active():
1068
self.AlarmBuffer[2] = 0
1069
self.AlarmBuffer[3] = "%s/%s/%s" % (datetime.datetime.now().year,
1070
datetime.datetime.now().month - 1, datetime.datetime.now().day)
1072
if self.TomorrowRadio.get_active():
1073
self.AlarmBuffer[2] = 0
1074
self.Today = datetime.datetime.now() + datetime.timedelta(days=1)
1075
self.AlarmBuffer[3] = "%s/%s/%s" % (self.Today.year,
1076
self.Today.month - 1, self.Today.day)
1080
#now = datetime.date(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day)
1081
#difference1 = datetime.timedelta(days=1)
1082
#difference2 = datetime.timedelta(weeks=-2)
1100
if self.SoundCheck.get_active():
1101
self.AlarmBuffer[7] = True
1103
self.AlarmBuffer[7] = False
1104
if self.PassiveCheck.get_active():
1105
self.AlarmBuffer[15] = True
1107
self.AlarmBuffer[15] = False
1108
if self.DialogCheck.get_active():
1109
self.AlarmBuffer[19] = True
1111
self.AlarmBuffer[19] = False
1112
if self.CmdCheck.get_active():
1113
self.AlarmBuffer[27] = True
1115
self.AlarmBuffer[27] = False
1116
if self.StdCheck.get_active():
1117
self.AlarmBuffer[32] = True
1119
self.AlarmBuffer[32] = False
1122
print >> self.f, self.AlarmBuffer
1125
self.LoadConfigFiles()
1126
self.AlarmPropsWidget.destroy()
1131
if self.AddAlarmNew.get_active():
1132
self.AddDialogWidget.destroy()
1133
self.ClearAlarmValues()
1134
#self.AlarmPrefs().show()
1137
self.AlarmPrefs().connect("response", self.ResponseDialog)
1139
if self.AddCounter.get_active():
1140
self.AddDialogWidget.destroy()
1141
self.AddSimpleCounterDialog()
1145
self.AddDialogWidget.destroy()
1149
def ResponseDialog(self,dialog,arg):
1150
if arg == gtk.RESPONSE_OK:
1152
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "a")
1153
self.AlarmBuffer[0] = self.NameEntry.get_text()
1154
self.AlarmBuffer[1] = "%i:%i" % (self.AlarmProps.get_widget('alarm_props_hour_spin').get_value(), self.AlarmProps.get_widget('alarm_props_minute_spin').get_value())
1155
if self.SingleRadio.get_active():
1156
self.AlarmBuffer[2] = 0
1157
if self.ScheduleRadio.get_active():
1158
self.AlarmBuffer[2] = 1
1159
if self.TodayRadio.get_active():
1160
self.AlarmBuffer[2] = 0
1161
self.AlarmBuffer[3] = "%s/%s/%s" % (datetime.datetime.now().year,
1162
datetime.datetime.now().month - 1, datetime.datetime.now().day)
1164
if self.TomorrowRadio.get_active():
1165
self.AlarmBuffer[2] = 0
1166
self.Today = datetime.datetime.now() + datetime.timedelta(days=1)
1167
self.AlarmBuffer[3] = "%s/%s/%s" % (self.Today.year,
1168
self.Today.month - 1, self.Today.day)
1173
if self.SoundCheck.get_active():
1174
self.AlarmBuffer[7] = True
1176
self.AlarmBuffer[7] = False
1177
if self.PassiveCheck.get_active():
1178
self.AlarmBuffer[15] = True
1180
self.AlarmBuffer[15] = False
1181
if self.DialogCheck.get_active():
1182
self.AlarmBuffer[19] = True
1184
self.AlarmBuffer[19] = False
1185
if self.CmdCheck.get_active():
1186
self.AlarmBuffer[27] = True
1188
self.AlarmBuffer[27] = False
1189
if self.StdCheck.get_active():
1190
self.AlarmBuffer[32] = True
1192
self.AlarmBuffer[32] = False
1196
# Checking if the alarm is not in the past, thanks Marcelo Briones
1197
# 2 - Integer - What option under "Date" frame is checked - scheduled, today etc
1198
# 3 - String - Single day - Date ("Year/Month/Day")
1200
if self.AlarmBuffer[2] == 0:
1201
self.date_data = re.search('(\d+)/(\d+)/(\d+)', self.AlarmBuffer[3])
1202
self.time_data = re.search('(\d+):(\d+)', self.AlarmBuffer[1])
1203
self.Year = int(self.date_data.group(1))
1204
self.Month = int(self.date_data.group(2))
1205
self.Day = int(self.date_data.group(3))
1206
self.Hour = int(self.time_data.group(1))
1207
self.Min = int(self.time_data.group(2))
1208
self.Date = datetime.datetime(self.Year, self.Month + 1, self.Day, self.Hour, self.Min, 0)
1209
self.CurrentDate = datetime.datetime.today()
1210
self.Interval = self.Date - self.CurrentDate
1211
if self.Interval.days < 0:
1212
self.Info = _("This alarm cannot be saved, because it's in the past. You need to manually correct the problem.")
1213
self.msgDialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
1214
gtk.BUTTONS_CLOSE, _("Error"))
1215
self.msgDialog.format_secondary_text(self.Info)
1216
self.msgDialog.run()
1217
self.msgDialog.destroy()
1226
print >> self.f, self.AlarmBuffer
1229
self.LoadConfigFiles()
1230
self.AlarmPropsWidget.destroy()
1236
def ToggleSoundButtons(self, Object):
1237
if self.Radio4.get_active():
1238
self.FChooser.set_sensitive(True)
1240
self.FChooser.set_sensitive(False)
1242
def AddSimpleCounterDialog(self,obj = None):
1243
self.AddCounterDialog = gtk.glade.XML('main.glade', 'add_coffee')
1244
self.AddCounterDialogWidget = self.AddCounterDialog.get_widget('add_coffee')
1245
self.AddCounterDialogWidget.set_icon_from_file('gfx/alarm-clock.svg')
1247
self.Radio3 = self.AddCounterDialog.get_widget("radiobutton3")
1248
self.Radio4 = self.AddCounterDialog.get_widget("radiobutton4")
1249
self.FChooser = self.AddCounterDialog.get_widget("sound_file_choose")
1251
self.file_filter = gtk.FileFilter()
1252
self.file_filter.set_name(_("Audio files"))
1253
self.file_filter.add_mime_type("audio/*")
1254
self.file_filter.add_pattern("*.ogg")
1255
self.file_filter.add_pattern("*.mp3")
1256
self.file_filter.add_pattern("*.wav")
1257
self.file_filter.add_pattern("*.mp4")
1258
self.file_filter.add_pattern("*.flac")
1259
self.FChooser.add_filter(self.file_filter)
1261
self.file_filter_all = gtk.FileFilter()
1262
self.file_filter_all.set_name(_("All files"))
1263
self.file_filter_all.add_pattern("*")
1265
self.FChooser.add_filter(self.file_filter_all)
1267
self.FChooser.set_sensitive(False)
1269
self.FChooser.set_current_folder(os.getenv("HOME"))
1271
self.signals = { "sound_toggle" : self.ToggleSoundButtons }
1273
self.AddCounterDialog.signal_autoconnect(self.signals)
1275
self.tb = gtk.TextBuffer()
1276
self.tb.set_text(_("A simple counter."))
1278
self.AddCounterDialog.get_widget('counter_text').set_buffer(self.tb)
1280
self.result = self.AddCounterDialogWidget.run()
1282
self.Minutes = int(self.AddCounterDialog.get_widget('counter_minute_spin').get_value())
1283
self.Text = self.tb.get_text(self.tb.get_start_iter(), self.tb.get_end_iter())
1286
if self.result == gtk.RESPONSE_OK:
1287
self.ClearAlarmValues()
1288
self.Difference = datetime.timedelta(minutes=self.Minutes)
1289
self.Datenow = datetime.datetime.today()
1290
self.Newdate = self.Datenow + self.Difference
1291
self.NewDate = ("%s/%i/%s") % (self.Newdate.strftime("%Y"), int(self.Newdate.strftime("%m")) - 1,
1292
self.Newdate.strftime("%d"))
1293
self.NewTime = ("%s:%i") % (self.Newdate.strftime("%H"), int(self.Newdate.strftime("%M")))
1297
# 7 - Boolean - whatever to play sound
1298
# 8 - Boolean - Use custom sound file
1299
# 9 - String - path to sound file
1300
# 10 - Boolean - Constant (True) or Fade (False)
1301
# 11 - Integer - Constant volume value
1302
# 12 - Integer - Fade (Initial volume)
1303
# 13 - Integer - Fade (Final volume)
1304
# 14 - Integer - Fade (Duration in seconds)
1308
self.AlarmBuffer[0] = _("Counter")
1309
self.AlarmBuffer[1] = self.NewTime
1310
self.AlarmBuffer[2] = 0
1311
self.AlarmBuffer[3] = self.NewDate
1312
self.AlarmBuffer[15] = True
1313
self.AlarmBuffer[16] = 1
1314
self.AlarmBuffer[17] = 300
1315
self.AlarmBuffer[18] = self.Text
1316
self.AlarmBuffer[37] = _("Counter message")
1317
self.AlarmBuffer[19] = False
1321
if self.Radio3.get_active():
1322
self.AlarmBuffer[7] = True
1323
self.AlarmBuffer[10] = True
1325
if self.Radio4.get_active():
1326
self.AlarmBuffer[7] = True
1327
self.AlarmBuffer[8] = True
1328
self.AlarmBuffer[9] = self.FChooser.get_filename()
1329
self.AlarmBuffer[10] = True
1332
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "a")
1333
print >> self.f, self.AlarmBuffer
1335
self.LoadConfigFiles()
1337
self.AddCounterDialogWidget.destroy()
1343
def NewAlarmRadioCheck(self,obj):
1345
if not self.AddAlarmTemplate.get_active():
1346
self.AddAlarmTemplateCombo.set_sensitive(False)
1348
self.AddAlarmTemplateCombo.set_sensitive(True)
1352
def SoundPrefsActive(self,obj):
1353
self.sp_Glade = gtk.glade.XML('main.glade', 'sound_properties')
1354
self.sp = self.sp_Glade.get_widget('sound_properties')
1355
self.sp.set_icon_from_file('gfx/alarm-clock.svg')
1356
self.dic = { "check_sound_prefs_window" : self.CheckSoundPrefsWindow,
1357
"check_sound_prefs_sliders" : self.CheckSoundPrefsSliders, }
1358
self.sp_Glade.signal_autoconnect(self.dic)
1361
# Creating filechooser
1363
self.fc = self.sp_Glade.get_widget('soundfile_chooser')
1364
self.fc.set_local_only(True)
1365
self.fc.set_current_folder(os.getenv("HOME"))
1366
self.fc.set_action(gtk.FILE_CHOOSER_ACTION_OPEN)
1367
self.fc.set_title(_("Choose your sound file"))
1368
self.file_filter = gtk.FileFilter()
1369
self.file_filter.set_name(_("Audio files"))
1370
self.file_filter.add_mime_type("audio/*")
1371
self.file_filter.add_pattern("*.ogg")
1372
self.file_filter.add_pattern("*.mp3")
1373
self.file_filter.add_pattern("*.wav")
1374
self.file_filter.add_pattern("*.mp4")
1375
self.file_filter.add_pattern("*.flac")
1376
self.fc.add_filter(self.file_filter)
1378
self.file_filter_all = gtk.FileFilter()
1379
self.file_filter_all.set_name(_("All files"))
1380
self.file_filter_all.add_pattern("*")
1383
self.fc.add_filter(self.file_filter_all)
1388
self.buf = self.sp_Glade.get_widget('custom_sound_file_check').set_active(self.AlarmBuffer[8])
1389
self.sp_Glade.get_widget('soundfile_chooser').set_filename(self.AlarmBuffer[9])
1391
if self.AlarmBuffer[10] == True:
1392
self.buf = self.sp_Glade.get_widget('constant_volume_radio').set_active(True)
1393
self.buf = self.sp_Glade.get_widget('fade_volume_radio').set_active(False)
1395
self.buf = self.sp_Glade.get_widget('constant_volume_radio').set_active(False)
1396
self.buf = self.sp_Glade.get_widget('fade_volume_radio').set_active(True)
1398
self.sp_Glade.get_widget('constant_volume_scale').set_value(self.AlarmBuffer[11])
1399
self.sp_Glade.get_widget('vol_init_scale').set_value(self.AlarmBuffer[12])
1400
self.sp_Glade.get_widget('vol_final_scale').set_value(self.AlarmBuffer[13])
1401
self.sp_Glade.get_widget('vol_duration_scale').set_value(self.AlarmBuffer[14])
1402
self.sp_Glade.get_widget('after_fade_scale').set_value(self.AlarmBuffer[40])
1403
self.sp_Glade.get_widget('repeat_volume_scale').set_value(self.AlarmBuffer[41])
1405
self.CheckSoundPrefsWindow(self.sp)
1406
self.CheckSoundPrefsSliders(self.sp,0,0)
1407
self.value = self.sp.run()
1409
if self.value == gtk.RESPONSE_OK:
1410
self.AlarmBuffer[8] = self.buf = self.sp_Glade.get_widget('custom_sound_file_check').get_active()
1411
self.AlarmBuffer[9] = self.buf = self.sp_Glade.get_widget('soundfile_chooser').get_filename()
1413
self.AlarmBuffer[10] = self.sp_Glade.get_widget('constant_volume_radio').get_active()
1415
self.AlarmBuffer[11] = self.sp_Glade.get_widget('constant_volume_scale').get_value()
1416
self.AlarmBuffer[12] = self.sp_Glade.get_widget('vol_init_scale').get_value()
1417
self.AlarmBuffer[13] = self.sp_Glade.get_widget('vol_final_scale').get_value()
1418
self.AlarmBuffer[14] = self.sp_Glade.get_widget('vol_duration_scale').get_value()
1419
self.AlarmBuffer[40] = self.sp_Glade.get_widget('after_fade_scale').get_value()
1420
self.AlarmBuffer[41] = self.sp_Glade.get_widget('repeat_volume_scale').get_value()
1427
def CheckSoundPrefsWindow(self,obj):
1428
self.buf = self.sp_Glade.get_widget('custom_sound_file_check').get_active()
1429
self.sp_Glade.get_widget('soundfile_label').set_sensitive(self.buf)
1430
self.sp_Glade.get_widget('soundfile_chooser').set_sensitive(self.buf)
1431
self.buf = self.sp_Glade.get_widget('constant_volume_radio').get_active()
1432
self.sp_Glade.get_widget('constant_volume_label').set_sensitive(self.buf)
1433
self.sp_Glade.get_widget('constant_volume_scale').set_sensitive(self.buf)
1434
self.sp_Glade.get_widget('constant_volume_percent').set_sensitive(self.buf)
1436
self.sp_Glade.get_widget('repeat_volume_label').set_sensitive(self.buf)
1437
self.sp_Glade.get_widget('repeat_volume_scale').set_sensitive(self.buf)
1438
self.sp_Glade.get_widget('repeat_volume_secs').set_sensitive(self.buf)
1440
self.buf = self.sp_Glade.get_widget('fade_volume_radio').get_active()
1442
self.sp_Glade.get_widget('vol_init_label').set_sensitive(self.buf)
1443
self.sp_Glade.get_widget('vol_init_scale').set_sensitive(self.buf)
1444
self.sp_Glade.get_widget('vol_init_percent').set_sensitive(self.buf)
1445
self.sp_Glade.get_widget('vol_final_label').set_sensitive(self.buf)
1446
self.sp_Glade.get_widget('vol_final_scale').set_sensitive(self.buf)
1447
self.sp_Glade.get_widget('vol_final_percent').set_sensitive(self.buf)
1448
self.sp_Glade.get_widget('vol_duration_label').set_sensitive(self.buf)
1449
self.sp_Glade.get_widget('vol_duration_scale').set_sensitive(self.buf)
1450
self.sp_Glade.get_widget('vol_duration_secs').set_sensitive(self.buf)
1451
self.sp_Glade.get_widget('after_fade_label').set_sensitive(self.buf)
1452
self.sp_Glade.get_widget('after_fade_scale').set_sensitive(self.buf)
1453
self.sp_Glade.get_widget('after_fade_secs').set_sensitive(self.buf)
1455
def CheckSoundPrefsSliders(self,obj,val1, val2):
1456
self.sp_Glade.get_widget('constant_volume_percent').set_text("%i %%" % self.sp_Glade.get_widget('constant_volume_scale').get_value())
1458
self.sp_Glade.get_widget('repeat_volume_secs').set_text("%i" % self.sp_Glade.get_widget('repeat_volume_scale').get_value())
1460
if self.sp_Glade.get_widget('repeat_volume_scale').get_value() == 0:
1461
self.sp_Glade.get_widget('repeat_volume_secs').set_text(_("Unlimited"))
1463
self.sp_Glade.get_widget('vol_init_percent').set_text("%i %%" % self.sp_Glade.get_widget('vol_init_scale').get_value())
1464
self.sp_Glade.get_widget('vol_final_percent').set_text("%i %%" % self.sp_Glade.get_widget('vol_final_scale').get_value())
1465
self.sp_Glade.get_widget('vol_duration_secs').set_text("%i s" % self.sp_Glade.get_widget('vol_duration_scale').get_value())
1466
self.sp_Glade.get_widget('after_fade_secs').set_text("%i s" % self.sp_Glade.get_widget('after_fade_scale').get_value())
1468
def PassivePrefsActive(self,obj):
1469
self.pw_Glade = gtk.glade.XML('main.glade', 'passive_window_properties')
1470
self.pw = self.pw_Glade.get_widget('passive_window_properties')
1471
self.pw.set_icon_from_file('gfx/alarm-clock.svg')
1472
if self.AlarmBuffer[16] == 0:
1473
self.pw_Glade.get_widget('urgency_low_radio').set_active(True)
1474
if self.AlarmBuffer[16] == 1:
1475
self.pw_Glade.get_widget('urgency_medium_radio').set_active(True)
1476
if self.AlarmBuffer[16] == 2:
1477
self.pw_Glade.get_widget('urgency_high_radio').set_active(True)
1479
self.pw_Glade.get_widget('passive_timeout_spin').set_value(self.AlarmBuffer[17])
1481
self.pw_Glade.get_widget('window_title_entry').set_text(self.AlarmBuffer[37])
1482
self.tb = gtk.TextBuffer()
1483
self.tb.set_text(self.AlarmBuffer[18])
1484
self.pw_Glade.get_widget('summary_text').set_buffer(self.tb)
1486
self.value = self.pw.run()
1488
if self.value == gtk.RESPONSE_OK:
1489
if self.pw_Glade.get_widget('urgency_low_radio').get_active():
1490
self.AlarmBuffer[16] = 0
1491
if self.pw_Glade.get_widget('urgency_medium_radio').get_active():
1492
self.AlarmBuffer[16] = 1
1493
if self.pw_Glade.get_widget('urgency_high_radio').get_active():
1494
self.AlarmBuffer[16] = 2
1496
self.AlarmBuffer[17] = self.pw_Glade.get_widget('passive_timeout_spin').get_value()
1498
self.AlarmBuffer[37] = self.pw_Glade.get_widget('window_title_entry').get_text()
1500
self.AlarmBuffer[18] = self.tb.get_text(self.tb.get_start_iter(), self.tb.get_end_iter())
1512
def DialogPrefsActive(self,obj):
1513
self.dw_Glade = gtk.glade.XML('main.glade', 'dialog_window_properties')
1514
self.dw = self.dw_Glade.get_widget('dialog_window_properties')
1515
self.dw.set_icon_from_file('gfx/alarm-clock.svg')
1517
self.dic = { "check_radios" : self.DialogPrefsRadios,
1518
"check_snooze" : self.DialogPrefsSnooze, }
1520
self.dw_Glade.signal_autoconnect(self.dic)
1522
if self.AlarmBuffer[20]:
1523
self.dw_Glade.get_widget('custom_window_radio').set_active(True)
1524
self.dw_Glade.get_widget('default_window_radio').set_active(False)
1526
self.dw_Glade.get_widget('custom_window_radio').set_active(False)
1527
self.dw_Glade.get_widget('default_window_radio').set_active(True)
1529
if self.AlarmBuffer[21] != None:
1530
self.dw_Glade.get_widget('glade_filechooser').set_filename(self.AlarmBuffer[21])
1532
self.colors = re.search("(\d+),(\d+),(\d+)", self.AlarmBuffer[22])
1534
self.color = gtk.gdk.Color()
1537
self.color.red = int (self.colors.group(1))
1538
self.color.green = int (self.colors.group(2))
1539
self.color.blue = int (self.colors.group(3))
1541
self.dw_Glade.get_widget('fg_colorbutton').set_color(self.color)
1543
self.colors = re.search("(\d+),(\d+),(\d+)", self.AlarmBuffer[23])
1547
self.color.red = int (self.colors.group(1))
1548
self.color.green = int (self.colors.group(2))
1549
self.color.blue = int (self.colors.group(3))
1551
self.dw_Glade.get_widget('bg_colorbutton').set_color(self.color)
1554
self.dw_Glade.get_widget('text_size_combo').set_active(self.AlarmBuffer[24])
1556
self.tb = gtk.TextBuffer()
1557
self.tb.set_text(self.AlarmBuffer[25])
1559
self.dw_Glade.get_widget('summary_textview').set_buffer(self.tb)
1561
self.dw_Glade.get_widget('window_title_entry').set_text(self.AlarmBuffer[38])
1563
self.dw_Glade.get_widget('fs_check').set_active(self.AlarmBuffer[26])
1565
if self.AlarmBuffer[39] > 0:
1566
self.dw_Glade.get_widget('snooze_check').set_active(True)
1567
self.dw_Glade.get_widget('snooze_timeout').set_value(self.AlarmBuffer[39])
1571
self.fc = self.dw_Glade.get_widget('glade_filechooser')
1572
self.fc.set_local_only(True)
1573
self.fc.set_title(_("Choose your Glade file"))
1574
self.fc.set_action(gtk.FILE_CHOOSER_ACTION_OPEN)
1575
self.fc.set_current_folder(os.getenv("HOME"))
1576
self.file_filter = gtk.FileFilter()
1577
self.file_filter.set_name(_("Glade files"))
1578
self.file_filter.add_pattern("*.glade")
1580
self.fc.set_filter(self.file_filter)
1582
self.DialogPrefsRadios(self.dw)
1586
self.value = self.dw.run()
1588
if self.value == gtk.RESPONSE_OK:
1589
self.AlarmBuffer[20] = self.dw_Glade.get_widget('custom_window_radio').get_active()
1590
self.AlarmBuffer[21] = self.dw_Glade.get_widget('glade_filechooser').get_filename()
1592
self.c = self.dw_Glade.get_widget('fg_colorbutton').get_color()
1594
self.AlarmBuffer[22] = "%i,%i,%i" % (self.c.red, self.c.green, self.c.blue)
1596
self.c = self.dw_Glade.get_widget('bg_colorbutton').get_color()
1598
self.AlarmBuffer[23] = "%i,%i,%i" % (self.c.red, self.c.green, self.c.blue)
1600
self.AlarmBuffer[24] = self.dw_Glade.get_widget('text_size_combo').get_active()
1602
self.AlarmBuffer[38] = self.dw_Glade.get_widget('window_title_entry').get_text()
1604
self.AlarmBuffer[25] = self.tb.get_text(self.tb.get_start_iter(), self.tb.get_end_iter())
1606
self.AlarmBuffer[26] = self.dw_Glade.get_widget('fs_check').get_active()
1609
if self.dw_Glade.get_widget('snooze_check').get_active() == True:
1610
self.AlarmBuffer[39] = int(self.dw_Glade.get_widget('snooze_timeout').get_value())
1612
if self.dw_Glade.get_widget('snooze_check').get_active() == False:
1613
self.AlarmBuffer[39] = 0
1621
def DialogPrefsSnooze(self,obj):
1622
if obj.get_active():
1623
self.dw_Glade.get_widget('snooze_timeout').set_sensitive(True)
1625
self.dw_Glade.get_widget('snooze_timeout').set_sensitive(False)
1627
def DialogPrefsRadios(self,obj):
1628
if self.dw_Glade.get_widget('custom_window_radio').get_active():
1629
self.dw_Glade.get_widget('custom_window_label').set_sensitive(True)
1630
self.dw_Glade.get_widget('glade_filechooser').set_sensitive(True)
1631
self.dw_Glade.get_widget('fg_color_label').set_sensitive(False)
1632
self.dw_Glade.get_widget('fg_colorbutton').set_sensitive(False)
1633
self.dw_Glade.get_widget('bg_color_label').set_sensitive(False)
1634
self.dw_Glade.get_widget('bg_colorbutton').set_sensitive(False)
1635
self.dw_Glade.get_widget('text_size_label').set_sensitive(False)
1636
self.dw_Glade.get_widget('text_size_combo').set_sensitive(False)
1638
self.dw_Glade.get_widget('custom_window_label').set_sensitive(False)
1639
self.dw_Glade.get_widget('glade_filechooser').set_sensitive(False)
1640
self.dw_Glade.get_widget('fg_color_label').set_sensitive(True)
1641
self.dw_Glade.get_widget('fg_colorbutton').set_sensitive(True)
1642
self.dw_Glade.get_widget('bg_color_label').set_sensitive(True)
1643
self.dw_Glade.get_widget('bg_colorbutton').set_sensitive(True)
1644
self.dw_Glade.get_widget('text_size_label').set_sensitive(True)
1645
self.dw_Glade.get_widget('text_size_combo').set_sensitive(True)
1666
def CommandPrefsActive(self,obj):
1667
self.cm_Glade = gtk.glade.XML('main.glade', 'command_properties')
1668
self.cm = self.cm_Glade.get_widget('command_properties')
1669
self.cm.set_icon_from_file('gfx/alarm-clock.svg')
1671
self.dic = { "radios_toggled" : self.CommandPrefsRadios, }
1673
self.cm_Glade.signal_autoconnect(self.dic)
1675
if self.AlarmBuffer[28]:
1676
self.cm_Glade.get_widget('run_command_radio').set_active(True)
1677
self.cm_Glade.get_widget('run_script_radio').set_active(False)
1679
self.cm_Glade.get_widget('run_command_radio').set_active(False)
1680
self.cm_Glade.get_widget('run_script_radio').set_active(True)
1682
self.cm_Glade.get_widget('command_entry').set_text(self.AlarmBuffer[29])
1684
self.tb = gtk.TextBuffer()
1685
self.tb.set_text(self.AlarmBuffer[30])
1687
self.cm_Glade.get_widget('script_text').set_buffer(self.tb)
1689
self.cm_Glade.get_widget('run_in_terminal_check').set_active(self.AlarmBuffer[31])
1692
self.CommandPrefsRadios(self.cm)
1693
self.value = self.cm.run()
1696
if self.value == gtk.RESPONSE_OK:
1697
if self.cm_Glade.get_widget('run_command_radio').get_active():
1698
self.AlarmBuffer[28] = True
1699
if self.cm_Glade.get_widget('run_script_radio').get_active():
1700
self.AlarmBuffer[28] = False
1701
self.AlarmBuffer[29] = self.cm_Glade.get_widget('command_entry').get_text()
1702
self.AlarmBuffer[30] = self.tb.get_text(self.tb.get_start_iter(), self.tb.get_end_iter())
1703
self.AlarmBuffer[31] = self.cm_Glade.get_widget('run_in_terminal_check').get_active()
1712
def CommandPrefsRadios(self,obj):
1713
if self.cm_Glade.get_widget('run_command_radio').get_active():
1714
self.cm_Glade.get_widget('command_entry').set_sensitive(True)
1715
self.cm_Glade.get_widget('script_text').set_sensitive(False)
1717
self.cm_Glade.get_widget('command_entry').set_sensitive(False)
1718
self.cm_Glade.get_widget('script_text').set_sensitive(True)
1726
def StdPrefsActive(self,obj):
1727
self.sp_Glade = gtk.glade.XML('main.glade', 'standard_action_properties')
1728
self.sp = self.sp_Glade.get_widget('standard_action_properties')
1729
self.sp.set_icon_from_file('gfx/alarm-clock.svg')
1731
self.dic = { "check_toggled" : self.StdPrefsCheck, }
1733
self.sp_Glade.signal_autoconnect(self.dic)
1735
if self.AlarmBuffer[33] == 0:
1736
self.sp_Glade.get_widget('shutdown_radio').set_active(True)
1737
if self.AlarmBuffer[33] == 1:
1738
self.sp_Glade.get_widget('reboot_radio').set_active(True)
1739
if self.AlarmBuffer[33] == 2:
1740
self.sp_Glade.get_widget('lock_radio').set_active(True)
1741
if self.AlarmBuffer[33] == 3:
1742
self.sp_Glade.get_widget('monitor_off_radio').set_active(True)
1744
self.sp_Glade.get_widget('confirm_check').set_active(self.AlarmBuffer[34])
1745
self.sp_Glade.get_widget('confirm_timeout_check').set_active(self.AlarmBuffer[35])
1746
self.sp_Glade.get_widget('confirm_timeout_spin').set_value(self.AlarmBuffer[36])
1748
self.StdPrefsCheck(self.sp_Glade.get_widget('confirm_check'))
1752
self.value = self.sp.run()
1754
if self.value == gtk.RESPONSE_OK:
1755
if self.sp_Glade.get_widget('shutdown_radio').get_active():
1756
self.AlarmBuffer[33] = 0
1757
if self.sp_Glade.get_widget('reboot_radio').get_active():
1758
self.AlarmBuffer[33] = 1
1759
if self.sp_Glade.get_widget('lock_radio').get_active():
1760
self.AlarmBuffer[33] = 2
1761
if self.sp_Glade.get_widget('monitor_off_radio').get_active():
1762
self.AlarmBuffer[33] = 3
1764
self.AlarmBuffer[34] = self.sp_Glade.get_widget('confirm_check').get_active()
1765
self.AlarmBuffer[35] = self.sp_Glade.get_widget('confirm_timeout_check').get_active()
1766
self.AlarmBuffer[36] = self.sp_Glade.get_widget('confirm_timeout_spin').get_value()
1772
# 33 - Integer - Action to perform (0 - Shutdown)
1773
# 34 - Boolean - Ask for confirmation
1774
# 35 - Boolean - Timeout
1775
# 36 - Integer - Confirmation timeout in seconds
1778
def StdPrefsCheck(self,obj):
1779
self.c1 = self.sp_Glade.get_widget('confirm_check')
1780
self.c2 = self.sp_Glade.get_widget('confirm_timeout_check')
1781
self.c3 = self.sp_Glade.get_widget('confirm_timeout_spin')
1783
if self.c1.get_active() != True:
1784
self.c2.set_sensitive(False)
1785
self.c3.set_sensitive(False)
1788
self.c2.set_sensitive(True)
1789
if self.c2.get_active():
1790
self.c3.set_sensitive(True)
1792
self.c3.set_sensitive(False)
1795
def DateComboChanged(self,obj):
1796
s = self.MonthCombo.get_active()
1821
s = self.DaySpin.get_value()
1822
self.DaySpin.set_range(1, m)
1823
self.DaySpin.set_value(s)
1825
def AddExceptionDialog(self,obj):
1826
self.AddException = gtk.glade.XML('main.glade', 'add_exception_dialog')
1827
self.AddExceptionWidget = self.AddException.get_widget('add_exception_dialog')
1828
self.AddExceptionWidget.set_icon_from_file('gfx/alarm-clock.svg')
1830
self.MonthCombo = self.AddException.get_widget('month_combo')
1831
self.DaySpin = self.AddException.get_widget('day_spin')
1832
self.CommentEntry = self.AddException.get_widget('comment_entry')
1834
self.month = int (datetime.datetime.now().strftime("%m"))
1836
self.exc_signals = { "refresh_month" : self.DateComboChanged, }
1838
self.AddException.signal_autoconnect(self.exc_signals)
1841
self.MonthCombo.set_active(self.month - 1)
1842
self.DaySpin.set_value(int(datetime.datetime.now().strftime("%d")))
1844
self.result = self.AddExceptionWidget.run()
1846
if self.result == gtk.RESPONSE_OK:
1848
self.tuplet = [self.MonthCombo.get_active() + 1, int (self.DaySpin.get_value()), self.CommentEntry.get_text()]
1850
self.date = datetime.date(2000, self.tuplet[0], self.tuplet[1])
1851
self.format_date = self.date.strftime("%d %B")
1853
self.sched_model.append([self.format_date, self.tuplet[2]])
1855
self.Al = self.Al + [self.tuplet]
1857
self.RefreshExceptionList()
1859
self.AddExceptionWidget.destroy()
1861
def RefreshExceptionList(self):
1863
self.row = self.SchedTreeSelection.get_selected_rows()
1865
self.row = self.row[1][0][0]
1869
self.sched_model.clear()
1871
for self.item in self.Al:
1872
self.date = datetime.date(2000, self.item[0], self.item[1])
1873
self.format_date = self.date.strftime("%d %B")
1874
self.sched_model.append([self.format_date, self.item[2]])
1875
self.count = self.count + 1
1878
if self.row >= self.count:
1879
self.SchedTreeSelection.select_path(self.count - 1,)
1881
self.SchedTreeSelection.select_path(self.row,)
1883
self.SchedTreeSelection.select_path(0,)
1886
self.ScheduleProps.get_widget('remove_exc').set_sensitive(False)
1887
self.ScheduleProps.get_widget('save_exc').set_sensitive(False)
1889
self.ScheduleProps.get_widget('remove_exc').set_sensitive(True)
1890
self.ScheduleProps.get_widget('save_exc').set_sensitive(True)
1893
def RemoveExceptionDialog(self,obj):
1894
self.row = self.SchedTreeSelection.get_selected_rows()
1895
self.row = self.row[1][0][0]
1905
if self.count == self.row:
1906
self.count = self.count + 1
1908
self.AlBuf = self.AlBuf + [tup]
1909
self.count = self.count + 1
1911
self.Al = self.AlBuf
1912
self.RefreshExceptionList()
1914
def ExcUpdate (self,obj):
1915
self.ff = str (self.ExcListWidget.get_filename())
1917
if os.path.isfile(self.ff) == False:
1918
self.ExcList.get_widget('author_label').set_text(_("None"))
1919
self.ExcList.get_widget('email_label').set_text(_("None"))
1920
self.ExcList.get_widget('comments_label').set_text(_("None"))
1921
self.ExcList.get_widget('open_button').set_sensitive(False)
1923
if os.path.getsize(self.ff) > 10000:
1924
self.ExcList.get_widget('author_label').set_text(_("None"))
1925
self.ExcList.get_widget('email_label').set_text(_("None"))
1926
self.ExcList.get_widget('comments_label').set_text(_("None"))
1927
self.ExcList.get_widget('open_button').set_sensitive(False)
1932
self.f = file(self.ff, "r")
1934
self.Tup = eval(self.f.read())[0]
1936
self.ExcList.get_widget('author_label').set_text(_("None"))
1937
self.ExcList.get_widget('email_label').set_text(_("None"))
1938
self.ExcList.get_widget('comments_label').set_text(_("None"))
1939
self.ExcList.get_widget('open_button').set_sensitive(False)
1942
self.ExcList.get_widget('author_label').set_text(self.Tup[0])
1943
self.ExcList.get_widget('email_label').set_text(self.Tup[1])
1944
self.ExcList.get_widget('comments_label').set_text(self.Tup[2])
1946
if self.Tup[0] == "":
1947
self.ExcList.get_widget('author_label').set_text(_("None"))
1948
if self.Tup[1] == "":
1949
self.ExcList.get_widget('email_label').set_text(_("None"))
1950
if self.Tup[2] == "":
1951
self.ExcList.get_widget('comments_label').set_text(_("None"))
1953
self.ExcList.get_widget('open_button').set_sensitive(True)
1955
def LoadExceptionList(self,obj):
1956
self.ExcList = gtk.glade.XML('main.glade', 'load_exc_list')
1957
self.ExcListWidget = self.ExcList.get_widget('load_exc_list')
1958
self.ExcListWidget.set_icon_from_file('gfx/alarm-clock.svg')
1960
self.ExcListWidget.set_current_folder(os.getenv("HOME"))
1962
self.dic = { "exc_update" : self.ExcUpdate, }
1964
self.combo = self.ExcList.get_widget('act_combo')
1966
self.combo.set_active(0)
1968
self.ExcList.signal_autoconnect(self.dic)
1970
self.result = self.ExcListWidget.run()
1972
if self.result == gtk.RESPONSE_CANCEL:
1973
self.ExcListWidget.destroy()
1977
self.ff = str (self.ExcListWidget.get_filename())
1978
self.f = file(self.ff, "r")
1980
self.Tup = eval(self.f.read())[1]
1984
if self.combo.get_active() == 0:
1985
self.Al = self.Al + self.Tup[0]
1989
self.RefreshExceptionList()
1991
self.ExcListWidget.destroy()
1993
def SaveExceptionList(self,obj):
1994
self.ExcList = gtk.glade.XML('main.glade', 'save_exc_list')
1995
self.ExcListWidget = self.ExcList.get_widget('save_exc_list')
1996
self.ExcListWidget.set_icon_from_file('gfx/alarm-clock.svg')
1998
self.ExcListWidget.set_current_folder(os.getenv("HOME"))
2000
self.result = self.ExcListWidget.run()
2001
if self.result == gtk.RESPONSE_CANCEL:
2002
self.ExcListWidget.destroy()
2005
self.Author = self.ExcList.get_widget('author_entry').get_text()
2006
self.Email = self.ExcList.get_widget('email_entry').get_text()
2007
self.Comments = self.ExcList.get_widget('comments_entry').get_text()
2009
self.FList = [self.Author, self.Email, self.Comments]
2011
for item in self.Al:
2012
self.TList = self.TList + [item]
2014
self.Final = [self.FList, [self.TList]]
2016
self.f = file(self.ExcListWidget.get_filename(), "w")
2018
print >> self.f, self.Final
2022
self.ExcListWidget.destroy()
2024
def LoadMonths(self):
2025
self.a = self.AlarmBuffer[4]
2030
self.ScheduleProps.get_widget('w1').set_active(self.wd[0])
2031
self.ScheduleProps.get_widget('w2').set_active(self.wd[1])
2032
self.ScheduleProps.get_widget('w3').set_active(self.wd[2])
2033
self.ScheduleProps.get_widget('w4').set_active(self.wd[3])
2034
self.ScheduleProps.get_widget('w5').set_active(self.wd[4])
2035
self.ScheduleProps.get_widget('w6').set_active(self.wd[5])
2036
self.ScheduleProps.get_widget('w7').set_active(self.wd[6])
2038
self.ScheduleProps.get_widget('m1').set_active(self.mn[0])
2039
self.ScheduleProps.get_widget('m2').set_active(self.mn[1])
2040
self.ScheduleProps.get_widget('m3').set_active(self.mn[2])
2041
self.ScheduleProps.get_widget('m4').set_active(self.mn[3])
2042
self.ScheduleProps.get_widget('m5').set_active(self.mn[4])
2043
self.ScheduleProps.get_widget('m6').set_active(self.mn[5])
2044
self.ScheduleProps.get_widget('m7').set_active(self.mn[6])
2045
self.ScheduleProps.get_widget('m8').set_active(self.mn[7])
2046
self.ScheduleProps.get_widget('m9').set_active(self.mn[8])
2047
self.ScheduleProps.get_widget('m10').set_active(self.mn[9])
2048
self.ScheduleProps.get_widget('m11').set_active(self.mn[10])
2049
self.ScheduleProps.get_widget('m12').set_active(self.mn[11])
2051
def SaveMonths(self):
2053
self.Tuplet1 = [self.ScheduleProps.get_widget('w1').get_active(),
2054
self.ScheduleProps.get_widget('w2').get_active(),
2055
self.ScheduleProps.get_widget('w3').get_active(),
2056
self.ScheduleProps.get_widget('w4').get_active(),
2057
self.ScheduleProps.get_widget('w5').get_active(),
2058
self.ScheduleProps.get_widget('w6').get_active(),
2059
self.ScheduleProps.get_widget('w7').get_active()]
2061
self.Tuplet2 = [self.ScheduleProps.get_widget('m1').get_active(),
2062
self.ScheduleProps.get_widget('m2').get_active(),
2063
self.ScheduleProps.get_widget('m3').get_active(),
2064
self.ScheduleProps.get_widget('m4').get_active(),
2065
self.ScheduleProps.get_widget('m5').get_active(),
2066
self.ScheduleProps.get_widget('m6').get_active(),
2067
self.ScheduleProps.get_widget('m7').get_active(),
2068
self.ScheduleProps.get_widget('m8').get_active(),
2069
self.ScheduleProps.get_widget('m9').get_active(),
2070
self.ScheduleProps.get_widget('m10').get_active(),
2071
self.ScheduleProps.get_widget('m11').get_active(),
2072
self.ScheduleProps.get_widget('m12').get_active()]
2074
self.Final = [self.Tuplet1, self.Tuplet2]
2076
self.AlarmBuffer[4] = self.Final
2078
def SchedulePrefsActive(self,obj):
2079
self.Al = self.AlarmBuffer[5]
2080
self.ScheduleProps = gtk.glade.XML('main.glade', 'schedule_dialog')
2081
self.SchedulePropsWidget = self.ScheduleProps.get_widget('schedule_dialog')
2082
self.SchedulePropsWidget.set_icon_from_file('gfx/alarm-clock.svg')
2086
self.sched_model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
2088
self.sched_tree = gtk.TreeView(self.sched_model)
2089
self.sched_scroll = self.ScheduleProps.get_widget('exceptions_scroll')
2090
self.sched_scroll.add(self.sched_tree)
2091
self.sched_tree.show()
2093
self.date_renderer = gtk.CellRendererText()
2094
self.date_column = gtk.TreeViewColumn(_("Date"), self.type_renderer, text=0)
2095
self.date_column.set_min_width(120)
2097
self.comment_renderer = gtk.CellRendererText()
2098
self.comment_column = gtk.TreeViewColumn(_("Comment"), self.date_renderer, text=1)
2100
self.sched_tree.append_column(self.date_column)
2101
self.sched_tree.append_column(self.comment_column)
2102
self.SchedTreeSelection = self.sched_tree.get_selection()
2104
self.RefreshExceptionList()
2106
self.SchedSignals = { "add_exception" : self.AddExceptionDialog,
2107
"remove_exception" : self.RemoveExceptionDialog,
2108
"load_exc_click" : self.LoadExceptionList,
2109
"save_exc_click" : self.SaveExceptionList,
2110
"SelectAllWeekdays" : self.SelectAllWeekdays,
2111
"DeselectAllWeekdays" : self.DeselectAllWeekdays,
2112
"SelectAllMonths" : self.SelectAllMoths,
2113
"DeselectAllMonths" : self.DeselectAllMonhts, }
2115
self.ScheduleProps.signal_autoconnect(self.SchedSignals)
2120
self.result = self.SchedulePropsWidget.run()
2122
if self.result == gtk.RESPONSE_OK:
2123
self.AlarmBuffer[5] = self.Al
2127
self.SchedulePropsWidget.destroy()
2131
def SelectAllWeekdays(self, Button):
2132
for x in range(1,8):
2133
self.Deselect = self.ScheduleProps.get_widget("w%i" % x)
2134
self.Deselect.set_active(True)
2136
def DeselectAllWeekdays(self, Button):
2137
for x in range(1,8):
2138
self.Deselect = self.ScheduleProps.get_widget("w%i" % x)
2139
self.Deselect.set_active(False)
2141
def SelectAllMoths(self, Button):
2142
for x in range(1,13):
2143
self.Deselect = self.ScheduleProps.get_widget("m%i" % x)
2144
self.Deselect.set_active(True)
2146
def DeselectAllMonhts(self, Button):
2147
for x in range(1,13):
2148
self.Deselect = self.ScheduleProps.get_widget("m%i" % x)
2149
self.Deselect.set_active(False)
2151
def AlarmPrefs(self):
2152
self.AlarmProps = gtk.glade.XML('main.glade', 'alarm_props_dialog')
2153
self.AlarmPropsWidget = self.AlarmProps.get_widget('alarm_props_dialog')
2154
self.AlarmPropsWidget.set_icon_from_file('gfx/alarm-clock.svg')
2156
self.AlarmPropsSignals = { "date_radio_changed" : self.DateRadioChanged,
2157
"notify_check_toggled" : self.NotifyCheckToggled,
2158
"select_single_day_prefs" : self.SingleDayPrefs,
2159
"sound_prefs_activate" : self.SoundPrefsActive,
2160
"passive_window_activate" : self.PassivePrefsActive,
2161
"dialog_window_activate" : self.DialogPrefsActive,
2162
"command_activate" : self.CommandPrefsActive,
2163
"std_action_active" : self.StdPrefsActive,
2164
"show_schedule_prefs" : self.SchedulePrefsActive,
2166
self.AlarmProps.signal_autoconnect(self.AlarmPropsSignals)
2168
self.PrefsSingle = self.AlarmProps.get_widget('single_day_preferences')
2169
self.PrefsSchedule = self.AlarmProps.get_widget('schedule_preferences')
2170
self.SingleRadio = self.AlarmProps.get_widget('single_day_radio')
2171
self.ScheduleRadio = self.AlarmProps.get_widget('schedule_radio')
2173
self.TodayRadio = self.AlarmProps.get_widget('today_radio')
2174
self.TomorrowRadio = self.AlarmProps.get_widget('tomorrow_radio')
2176
self.SoundCheck = self.AlarmProps.get_widget('play_sound_check')
2177
self.SoundPrefs = self.AlarmProps.get_widget('sound_prefs')
2178
self.PassiveCheck = self.AlarmProps.get_widget('passive_window_check')
2179
self.PassivePrefs = self.AlarmProps.get_widget('passive_prefs')
2180
self.DialogCheck = self.AlarmProps.get_widget('dialog_window_check')
2181
self.DialogPrefs = self.AlarmProps.get_widget('dialog_prefs')
2182
self.CmdCheck = self.AlarmProps.get_widget('run_command_check')
2183
self.CmdPrefs = self.AlarmProps.get_widget('cmd_prefs')
2184
self.StdCheck = self.AlarmProps.get_widget('std_action_check')
2185
self.StdPrefs = self.AlarmProps.get_widget('std_prefs')
2187
self.NameEntry = self.AlarmProps.get_widget('alarm_props_short_name_entry')
2189
self.SingleRadio.set_active(True)
2190
self.PrefsSchedule.set_sensitive(False)
2194
self.time_data = re.search('(\d+):(\d+)', self.AlarmBuffer[1])
2195
self.AlarmProps.get_widget('alarm_props_hour_spin').set_value(int (self.time_data.group(1)))
2196
self.AlarmProps.get_widget('alarm_props_minute_spin').set_value(int (self.time_data.group(2)))
2197
self.AlarmProps.get_widget('alarm_props_short_name_entry').set_text(self.AlarmBuffer[0])
2199
if self.AlarmBuffer[2] == 0:
2200
self.AlarmProps.get_widget('single_day_radio').set_active(True)
2201
if self.AlarmBuffer[2] == 1:
2202
self.AlarmProps.get_widget('schedule_radio').set_active(True)
2203
if self.AlarmBuffer[2] == 2:
2204
self.AlarmProps.get_widget('today_radio').set_active(True)
2205
if self.AlarmBuffer[2] == 3:
2206
self.AlarmProps.get_widget('tomorrow_radio').set_active(True)
2207
if self.AlarmBuffer[7] == True:
2208
self.AlarmProps.get_widget('play_sound_check').set_active(True)
2209
if self.AlarmBuffer[15] == True:
2210
self.AlarmProps.get_widget('passive_window_check').set_active(True)
2211
if self.AlarmBuffer[19] == True:
2212
self.AlarmProps.get_widget('dialog_window_check').set_active(True)
2213
if self.AlarmBuffer[27] == True:
2214
self.AlarmProps.get_widget('run_command_check').set_active(True)
2215
if self.AlarmBuffer[32] == True:
2216
self.AlarmProps.get_widget('std_action_check').set_active(True)
2219
return self.AlarmPropsWidget
2221
def DateRadioChanged(self,obj):
2222
if self.SingleRadio.get_active():
2223
self.PrefsSchedule.set_sensitive(False)
2224
self.PrefsSingle.set_sensitive(True)
2225
if self.ScheduleRadio.get_active():
2226
self.PrefsSchedule.set_sensitive(True)
2227
self.PrefsSingle.set_sensitive(False)
2228
if self.TodayRadio.get_active():
2229
self.PrefsSchedule.set_sensitive(False)
2230
self.PrefsSingle.set_sensitive(False)
2231
if self.TomorrowRadio.get_active():
2232
self.PrefsSchedule.set_sensitive(False)
2233
self.PrefsSingle.set_sensitive(False)
2236
def NotifyCheckToggled(self,obj):
2237
if self.SoundCheck.get_active():
2238
self.SoundPrefs.set_sensitive(True)
2240
self.SoundPrefs.set_sensitive(False)
2241
if self.PassiveCheck.get_active():
2242
self.PassivePrefs.set_sensitive(True)
2244
self.PassivePrefs.set_sensitive(False)
2245
if self.DialogCheck.get_active():
2246
self.DialogPrefs.set_sensitive(True)
2248
self.DialogPrefs.set_sensitive(False)
2249
if self.CmdCheck.get_active():
2250
self.CmdPrefs.set_sensitive(True)
2252
self.CmdPrefs.set_sensitive(False)
2253
if self.StdCheck.get_active():
2254
self.StdPrefs.set_sensitive(True)
2256
self.StdPrefs.set_sensitive(False)
2258
def ClearAlarmValues(self):
2260
# Here we store the alarm value - in a list
2261
# So it's easy to maintain
2270
# 0 - String - Short name
2271
# 1 - String - Time (eg. "12:29")
2272
# 2 - Integer - What option under "Date" frame is checked - scheduled, today etc
2273
# 3 - String - Single day - Date ("Year/Month/Day")
2274
# 4 - Schedule tuplet
2275
# 5 - Exceptions tuplet
2280
# 7 - Boolean - whatever to play sound
2281
# 8 - Boolean - Use custom sound file
2282
# 9 - String - path to sound file
2283
# 10 - Boolean - Constant (True) or Fade (False)
2284
# 11 - Integer - Constant volume value
2285
# 12 - Integer - Fade (Initial volume)
2286
# 13 - Integer - Fade (Final volume)
2287
# 14 - Integer - Fade (Duration in seconds)
2288
# 40 - Integer - Fade (Duration after fade)
2289
# 41 - Integer - Repeat times
2293
# 15 - Boolean - Use passive window
2294
# 16 - Integer - Urgency (0 - Low, 1 - Medium, 2 - High)
2295
# 17 - Integer - Timeout in seconds
2296
# 18 - String - Summary text
2297
# 37 - PASSIVE window title
2301
# 19 - Boolean - Use dialog window
2302
# 20 - Boolean - Load custom (True) or Use default (False)
2303
# 21 - String - Custom window file location
2304
# 22 - String - Default window text color
2305
# 23 - String - Default window Background color
2306
# 24 - Integer - Default window text size (0 - Small)
2307
# 25 - String - Dialog window summary text
2308
# 26 - Boolean - Show in fullscreen
2309
# 38 - Dialog window title
2310
# 39 - Dialog window snooze
2314
# 27 - Boolean - Use command
2315
# 28 - Boolean - Run command (True) or Run shell script (False)
2316
# 29 - String - Command
2317
# 30 - String - Shell script
2318
# 31 - Boolean - Run in Terminal
2322
# 32 - Boolean - Use standard action
2323
# 33 - Integer - Action to perform (0 - Shutdown)
2324
# 34 - Boolean - Ask for confirmation
2325
# 35 - Boolean - Timeout
2326
# 36 - Integer - Confirmation timeout in seconds
2329
self.AlarmBuffer = [_("Untitled"),
2330
"%s:%s" % (time.localtime().tm_hour, time.localtime().tm_min + 1),
2332
"%i/%i/%i" % (time.localtime().tm_year, time.localtime().tm_mon - 1, time.localtime().tm_mday),
2333
[[False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False, False, False, False, False]],
2338
"%s/sound/ring.wav" % os.getcwd(),
2347
_("This is a simple reminder."),
2352
"65535,65535,65535",
2354
_("This is simple dialog window"),
2372
def SingleDayPrefs(self,obj):
2373
self.SingleDate = gtk.glade.XML('main.glade', 'single_day_dialog')
2374
self.SingleDateWidget = self.SingleDate.get_widget('single_day_dialog')
2375
self.SingleDateWidget.set_icon_from_file('gfx/alarm-clock.svg')
2376
self.date_data = re.search('(\d+)/(\d+)/(\d+)', self.AlarmBuffer[3])
2377
self.SingleDate.get_widget('calendar').select_month(int (self.date_data.group(2)), int (self.date_data.group(1)))
2378
self.SingleDate.get_widget('calendar').select_day(int (self.date_data.group(3)))
2381
if self.SingleDateWidget.run() == gtk.RESPONSE_CANCEL:
2382
self.SingleDateWidget.destroy()
2385
self.AlarmBuffer[3] = "%s/%s/%s" % self.SingleDate.get_widget('calendar').get_date()
2386
self.SingleDateWidget.destroy()
2392
def LoadConfigFiles(self):
2394
if os.path.isdir(os.getenv("HOME") + "/.config/Alarm-Clock/") == False:
2395
os.mkdir (os.getenv("HOME") + "/.config/Alarm-Clock")
2397
if os.path.isfile(os.getenv("HOME") + "/.config/Alarm-Clock/configuration") == False:
2398
self.fc = file(os.getenv("HOME") + "/.config/Alarm-Clock/configuration", "w")
2399
print >> self.fc, [MainWindow.get_position(), MainWindow.get_size()]
2401
if os.path.isfile(os.getenv("HOME") + "/.config/Alarm-Clock/alarms") == False:
2402
self.af = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "w")
2403
self.ClearAlarmValues()
2405
if os.path.isfile(os.getenv("HOME") + "/.config/Alarm-Clock/templates") == False:
2406
self.af = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "w")
2408
if os.path.isfile(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays") == False:
2409
self.af = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "w")
2412
self.ConfigFile = file(os.getenv("HOME") + "/.config/Alarm-Clock/configuration", "rw")
2413
self.AlarmFile = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "rw")
2415
for line in self.ConfigFile:
2416
self.configlist = eval(line)
2418
self.alarm_model.clear()
2420
for line in self.AlarmFile:
2422
self.ParseTupletToList(line)
2429
MainWindowGlade.get_widget('notebook').set_current_page(1)
2430
MainWindowGlade.get_widget('remove_alarm_toolbutton').set_sensitive(False)
2431
MainWindowGlade.get_widget('test_alarm_toolbutton').set_sensitive(False)
2432
MainWindowGlade.get_widget('alarm_properties_toolbutton').set_sensitive(False)
2433
MainWindowGlade.get_widget('edit_remove').set_sensitive(False)
2436
MainWindowGlade.get_widget('notebook').set_current_page(0)
2437
MainWindowGlade.get_widget('remove_alarm_toolbutton').set_sensitive(True)
2438
MainWindowGlade.get_widget('alarm_properties_toolbutton').set_sensitive(True)
2439
MainWindowGlade.get_widget('edit_remove').set_sensitive(True)
2440
MainWindowGlade.get_widget('test_alarm_toolbutton').set_sensitive(True)
2444
if self.row >= self.i:
2445
self.TreeSelection.select_path(self.i - 1,)
2447
self.TreeSelection.select_path(self.row,)
2449
self.TreeSelection.select_path(0,)
2454
def ParseTupletToList(self,line):
2455
self.string = eval(line)
2458
self.weekdays = self.string[4][0]
2459
self.months = self.string[4][1]
2461
self.t_weekday = time.localtime().tm_wday
2462
self.t_month = time.localtime().tm_mon
2463
self.t_day = time.localtime().tm_mday
2470
self.t = re.search('(\d+):(\d+)', self.string[1])
2472
self.h = "%s" % self.t.group(1)
2474
if int (self.t.group(2)) < 10:
2475
self.m = "0%s" % self.t.group(2)
2477
self.m = "%s" % self.t.group(2)
2486
self.weekdays = self.string[4][0]
2487
self.months = self.string[4][1]
2489
if self.weekdays[self.t_weekday] == True and self.months[self.t_month - 1] == True:
2492
for t in self.string[5]:
2493
if t[0] == self.t_month and t[1] == self.t_day:
2500
if self.Good == True and self.string[2] == 1:
2501
self.time = _("%s:%s - Today") % (self.h, self.m)
2504
self.time = _("%s:%s - Cancelled") % (self.h, self.m)
2506
self.time = "%s:%s" % (self.h, self.m)
2520
if self.string[2] == 1:
2521
self.AlarmType = _("Scheduled")
2522
self.datetime = "%s" % self.time
2524
self.AlarmType = _("Single")
2525
self.date_data = re.search('(\d+)/(\d+)/(\d+)', self.string[3])
2528
if int(self.date_data.group(3)) < 10:
2529
self.day = "0%s" % self.date_data.group(3)
2531
self.day = self.date_data.group(3)
2533
if int (self.date_data.group(2)) < 9:
2535
self.month = "0%i" % (int(self.date_data.group(2)) + 1)
2537
self.month = "%i" % (int(self.date_data.group(2)) + 1)
2538
self.datetime = "%s %s/%s/%s" % (self.time, self.day, self.month, self.date_data.group(1))
2540
self.alarm_model.append([self.AlarmType, self.datetime, self.string[0]])
2549
def RemoveAlarmDialog(self,obj):
2551
self.row = self.TreeSelection.get_selected_rows()
2552
self.row = self.row[1][0][0]
2555
self.msgDialog = gtk.MessageDialog(MainWindow, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Alarm removal"))
2556
self.msgDialog.format_secondary_text(_("Are you sure you wish to remove this alarm?"))
2558
if self.msgDialog.run() == gtk.RESPONSE_YES:
2559
self.msgDialog.destroy()
2560
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "r")
2561
self.lines = self.fbuf.readlines()
2564
for line in self.lines:
2565
if self.counter == self.row:
2566
self.counter = self.counter + 1
2568
self.new_lines.append(line)
2569
self.counter = self.counter + 1
2573
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "w")
2576
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "a")
2577
for line in self.new_lines:
2578
self.fbuf.write(line)
2580
self.LoadConfigFiles()
2582
self.msgDialog.destroy()
2587
def SaveAlarms(self,obj):
2588
self.fc = gtk.FileChooserDialog(_("Select location"), MainWindow, gtk.FILE_CHOOSER_ACTION_SAVE,
2589
("gtk-cancel", gtk.RESPONSE_CANCEL, "gtk-save", gtk.RESPONSE_OK), None)
2591
self.fc.set_current_folder(os.getenv("HOME"))
2593
self.fc.set_do_overwrite_confirmation(True)
2595
self.value = self.fc.run()
2597
if self.value == gtk.RESPONSE_OK:
2598
self.filewrite = file(self.fc.get_filename(), "w")
2599
self.alarmfile = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "r")
2600
self.filewrite.write(self.alarmfile.read())
2601
self.filewrite.close()
2602
self.alarmfile.close()
2609
def OpenAlarms(self,obj):
2611
self.fc_Glade = gtk.glade.XML('main.glade', 'open_alarms_dialog')
2612
self.fc = self.fc_Glade.get_widget('open_alarms_dialog')
2613
self.fc.set_icon_from_file('gfx/alarm-clock.svg')
2615
self.fc.set_current_folder(os.getenv("HOME"))
2617
self.cb = self.fc_Glade.get_widget('action_combo')
2618
self.cb.set_active(0)
2620
self.value = self.fc.run()
2622
if self.value == gtk.RESPONSE_OK:
2623
self.f = file(self.fc.get_filename(), "r")
2624
self.CheckFile(self.f)
2626
self.f = file(self.fc.get_filename(), "r")
2627
if self.cb.get_active() == 0:
2628
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "a")
2629
self.fbuf.write(self.f.read())
2632
if self.cb.get_active() == 1:
2633
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "w")
2634
self.fbuf.write(self.f.read())
2638
self.LoadConfigFiles()
2643
def CheckFile(self,file_obj):
2644
self.a = file_obj.readline()
2649
self.mess = gtk.MessageDialog(MainWindow, gtk.DIALOG_MODAL |
2650
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
2651
gtk.BUTTONS_OK, "Error!")
2652
self.mess.format_secondary_text(_("This file does not contain any alarm information."))
2658
def NewAlarms(self,obj):
2659
self.msg = gtk.MessageDialog(MainWindow, gtk.DIALOG_MODAL |
2660
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION,
2661
gtk.BUTTONS_YES_NO, _("Are you sure?"))
2662
self.msg.format_secondary_text(_("Are you sure you want to create a new alarm list?\nAny unsaved changes will be lost."))
2664
self.value = self.msg.run()
2666
if self.value == gtk.RESPONSE_YES:
2667
os.remove(os.getenv("HOME") + "/.config/Alarm-Clock/alarms")
2668
self.LoadConfigFiles()
2675
def TestAlarm(self,obj):
2676
self.LoadCurrentAlarm()
2677
self.RunAlarm(self.AlarmBuffer)
2679
def RunAlarm(self,Al):
2685
self.sndfile = Al[9]
2687
self.sndfile = "%s/sound/ring.wav" % os.getcwd()
2690
player.set_property('uri', "file://" + self.sndfile)
2691
MainWindowGlade.get_widget('stop_sound').set_sensitive(True)
2698
self.thread = RepeatSound(Times, MainWindowGlade.get_widget('stop_sound'), Al[11])
2703
RepeatAfter = Al[40]
2706
self.thread = VolumeFade(Al[12], Al[13], Al[14], MainWindowGlade.get_widget('stop_sound'), RepeatAfter)
2710
# 7 - Boolean - whatever to play sound
2711
# 8 - Boolean - Use custom sound file
2712
# 9 - String - path to sound file
2713
# 10 - Boolean - Constant (True) or Fade (False)
2714
# 11 - Integer - Constant volume value
2715
# 12 - Integer - Fade (Initial volume)
2716
# 13 - Integer - Fade (Final volume)
2717
# 14 - Integer - Fade (Duration in seconds)
2730
# PASSIVE WINDOW START
2733
self.n = pynotify.Notification (Al[37], Al[18])
2735
self.n.set_urgency(pynotify.URGENCY_LOW)
2737
self.n.set_urgency(pynotify.URGENCY_NORMAL)
2739
self.n.set_urgency(pynotify.URGENCY_CRITICAL)
2740
self.timeout = int (Al[17])
2741
self.timeout = self.timeout * 1000
2742
self.n.set_timeout(self.timeout)
2744
# Workaround for notify-python 0.1.1 bug, passive window will show only
2745
# when attach_to_status_icon function is available
2746
# See bug #193166 in Launchpad
2749
self.n.attach_to_status_icon(StatusIcon)
2754
# DIALOG WINDOW START
2760
self.dlg_G = gtk.glade.XML(Al[21], 'alarm_dialog')
2761
self.dl = self.dlg_G.get_widget('alarm_dialog')
2762
self.dl.set_icon_from_file('gfx/alarm-clock.svg')
2763
self.dl.set_title(Al[38])
2764
self.dlg_G.get_widget('alarm_label').set_text(Al[25])
2768
self.msg = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, "")
2769
self.msg.set_markup(_("The GLADE file <b>%s</b> is incorrect. It should contain a dialog called \"alarm_dialog\" and a label called \"alarm_label\".") % Al[21])
2777
self.dl_Glade = gtk.glade.XML('main.glade', 'alarm_dialog')
2779
self.dc = { "close_dialog" : self.CloseDialogPopup,
2780
"snooze_clicked" : self.SnoozeClicked, }
2782
self.dl_Glade.signal_autoconnect(self.dc)
2784
self.dl = self.dl_Glade.get_widget('alarm_dialog')
2785
self.dl.set_icon_from_file('gfx/alarm-clock.svg')
2786
self.text = self.dl_Glade.get_widget('text_label')
2787
self.color = gtk.gdk.Color()
2789
self.alarm_event = self.dl_Glade.get_widget('alarm_event')
2790
self.colors = re.search("(\d+),(\d+),(\d+)", Al[23])
2791
self.color.red = int (self.colors.group(1))
2792
self.color.green = int (self.colors.group(2))
2793
self.color.blue = int (self.colors.group(3))
2794
self.alarm_event.modify_bg(gtk.STATE_NORMAL, self.color)
2796
self.colors = re.search("(\d+),(\d+),(\d+)", Al[22])
2797
self.color.red = int (self.colors.group(1))
2798
self.color.green = int (self.colors.group(2))
2799
self.color.blue = int (self.colors.group(3))
2804
self.val = Al[24] - 1
2805
self.tin = "<big>" * self.val
2806
self.tout = "</big>" * self.val
2809
self.tin = "<small>"
2810
self.tout = "</small>"
2812
self.text_to_enter = "<span foreground='%s'>%s%s%s</span>" % (self.color.to_string(), self.tin, Al[25], self.tout)
2814
self.text.set_markup(self.text_to_enter)
2815
self.dl.set_title(Al[38])
2818
self.dl_Glade.get_widget('snooze_button').hide()
2824
self.dl.fullscreen()
2826
print _("Error: cannot create dialog window.")
2833
if Al[28]: # run command
2834
self.f = file (os.getenv("HOME") + "/.config/Alarm-Clock/runscript", "w")
2835
self.f.write(Al[29])
2837
os.chmod(os.getenv("HOME") + "/.config/Alarm-Clock/runscript", 0777)
2839
else: # run shell script
2840
self.f = file (os.getenv("HOME") + "/.config/Alarm-Clock/runscript", "w")
2841
self.f.write(Al[30])
2843
os.chmod(os.getenv("HOME") + "/.config/Alarm-Clock/runscript", 0777)
2846
os.popen2("gnome-terminal -x %s" % (os.getenv("HOME") + "/.config/Alarm-Clock/runscript"), "r")
2848
os.popen2(os.getenv("HOME") + "/.config/Alarm-Clock/runscript", "r")
2851
# STANDARD ACTION START
2855
self.command = "shutdown"
2856
self.message = _("Shutdown")
2858
self.command = "reboot"
2859
self.message = _("Reboot")
2861
self.command = "gnome-screensaver-command --lock"
2862
self.message = _("Lock the screen")
2864
self.command = "xset dpms force off"
2865
self.message = _("Turn off the monitor")
2868
os.system(self.command)
2870
self.thread = CountThread(Al, self.command, self.message)
2875
def CloseDialogPopup(self, DialogWindow):
2876
DialogWindow.get_parent_window().destroy()
2878
def SnoozeClicked(self,obj):
2880
self.snooze_thread = SnoozeThread(self.c, self.dl)
2881
self.snooze_thread.start()
2884
class SnoozeThread(Thread):
2885
def __init__(self,c,dl):
2886
Thread.__init__(self)
2887
self.setDaemon(True)
2895
StartGUI().StopTheSound(None)
2899
self.count = self.count + 1
2900
if self.count == self.c[39]:
2901
StartGUI().RunAlarm(self.c)
2908
class CountThread(Thread):
2909
def __init__(self, Al, cmd, msg):
2910
Thread.__init__(self)
2911
self.setDaemon(True)
2918
if Al[35]: # If there is no timeout, do this
2919
self.CountMsg = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, _("Confirmation equired"))
2920
self.CountMsg.format_secondary_text(_("Alarm Clock will perform the following action:\n\n%s\n\nin %i seconds. Click \"Cancel\" to cancel the action."))
2921
self.CountMsg.show()
2924
else: # If there is a timeout, do this
2925
self.CountMsg = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, _("Confirmation required"))
2926
self.Text = _("Alarm clock will perform the following action:\n\n%s\n\nClick \"Cancel\" to cancel the action.") % (self.msg)
2927
self.CountMsg.format_secondary_text(self.Text)
2928
self.CountMsg.show()
2932
self.CountMsg.connect("destroy", self.Destroy)
2933
self.CountMsg.connect("response", self.Response)
2935
self.counter = Al[36]
2936
self.WidExist = True
2942
while self.Al[35] and self.WidExist:
2943
gtk.gdk.threads_enter()
2944
self.CountMsg.format_secondary_text(_("Alarm Clock will perform the following action:\n\n%s\n\nin %i seconds. Click \"Cancel\" to cancel the action.") % (self.msg, self.counter))
2946
self.counter = self.counter - 1
2947
gtk.gdk.threads_leave()
2949
if self.counter == 0:
2951
self.CountMsg.destroy()
2952
self.WidExist = False
2955
def Destroy(self,obj):
2956
self.WidExist = False
2958
def Response(self,obj,response_id):
2959
self.WidExist = False
2961
if response_id == gtk.RESPONSE_OK:
2967
class RepeatSound(Thread):
2968
def __init__(self, howmanytimes, button, volume):
2970
Thread.__init__(self)
2972
self.setDaemon(True)
2974
self.button = button
2975
self.times = howmanytimes - 1
2976
self.bus = player.get_bus()
2977
self.bus.add_signal_watch()
2978
self.bus.connect('message', self.on_message3)
2979
self.time_format = gst.Format(gst.FORMAT_TIME)
2982
self.volume = volume / 100
2986
player.set_property("volume", self.volume)
2987
player.set_state(gst.STATE_PLAYING)
2990
while self.Repeated < self.times and player.get_state()[1] != gst.STATE_NULL:
2991
if self.times == -1:
2996
while player.get_state()[1] != gst.STATE_NULL:
2999
player.set_property("volume", 0)
3000
player.set_state(gst.STATE_NULL)
3003
gtk.gdk.threads_enter()
3004
self.button.set_sensitive(False)
3005
gtk.gdk.threads_leave()
3007
def on_message3(self, bus, message):
3009
if t == gst.MESSAGE_EOS:
3010
player.set_state(gst.STATE_PAUSED)
3011
player.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, 0)
3012
player.set_property("volume", self.volume)
3013
player.set_state(gst.STATE_PLAYING)
3019
class VolumeFade(Thread):
3020
def __init__(self, initvol, outvol, dur, button, repeat_after):
3022
Thread.__init__(self)
3024
self.setDaemon(True)
3026
self.ovol = outvol * 10
3029
self.bus = player.get_bus()
3030
self.bus.add_signal_watch()
3031
self.bus.connect('message', self.on_message2)
3032
self.time_format = gst.Format(gst.FORMAT_TIME)
3034
self.repeat_after = repeat_after
3035
self.repeating = False
3037
if initvol > outvol:
3039
self.spac = initvol - outvol
3042
self.spac = outvol - initvol
3044
self.change = self.spac / self.sec / 1000
3050
self.volume_current = self.ivol / 100
3051
player.set_property("volume", self.volume_current)
3052
player.set_state(gst.STATE_PLAYING)
3057
if player.get_state()[1] == gst.STATE_PAUSED or player.get_state()[2] == gst.STATE_PAUSED:
3058
player.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, 0)
3059
player.set_property("volume", self.volume_current)
3061
player.set_state(gst.STATE_PLAYING)
3065
if not self.repeating:
3066
if self.voldir == 0:
3067
self.volume_current = self.volume_current - self.change
3068
if self.voldir == 1:
3069
self.volume_current = self.volume_current + self.change
3070
player.set_property("volume", self.volume_current)
3072
self.count = self.count + 1
3076
if player.get_state()[1] == gst.STATE_NULL:
3081
if self.count >= self.sec * 10:
3082
if not self.repeating:
3084
self.sec = self.repeat_after * 10
3085
self.repeating = True
3088
player.set_state(gst.STATE_NULL)
3091
player.set_property("volume", 0)
3092
player.set_state(gst.STATE_NULL)
3093
self.volume_current = 0
3098
gtk.gdk.threads_enter()
3099
self.b.set_sensitive(False)
3100
gtk.gdk.threads_leave()
3104
def on_message2(self, bus, message):
3106
if t == gst.MESSAGE_EOS:
3107
player.set_state(gst.STATE_PAUSED)
3108
player.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, 0)
3109
player.set_property("volume", self.volume_current)
3110
player.set_state(gst.STATE_PLAYING)
3113
class CheckAlarmThread(Thread):
3114
def __init__(self, status, main,StatusIcon,alarm_model, row, treesel):
3115
Thread.__init__(self)
3116
self.setDaemon(True)
3118
self.CheckTodayAlarms()
3119
self.status = status
3121
MainWindowGlade = main
3122
self.st = StatusIcon
3123
self.alarm_model = alarm_model
3125
self.TreeSelection = treesel
3128
self.RefreshList = False
3129
self.Removed = False
3132
self.CheckOldAlarms()
3138
self.CheckTodayBirthdays()
3139
self.CheckTodayAlarms()
3143
self.CheckOldAlarms()
3151
self.CheckOldAlarms()
3154
self.File = file(os.getenv("HOME") + "/.config/Alarm-Clock/lock", "w")
3155
self.File.write("%s/%s/%s %s:%s:%s" % (datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day, datetime.datetime.now().hour, datetime.datetime.now().minute, datetime.datetime.now().second))
3159
self.CheckOldAlarms()
3161
gtk.gdk.threads_enter()
3162
self.status.push(0, time.strftime(_("Current time: %c")))
3163
gtk.gdk.threads_leave()
3164
for tup in self.today:
3165
if tup[0] == time.localtime().tm_hour and tup[1] == time.localtime().tm_min and time.localtime().tm_sec == 0:
3166
self.s = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms")
3167
self.bb = self.s.readlines()
3168
gtk.gdk.threads_enter()
3169
StartGUI().RunAlarm(eval(self.bb[tup[2]]))
3171
gtk.gdk.threads_leave()
3174
if time.localtime().tm_hour == 0 and time.localtime().tm_min == 0 and time.localtime().tm_sec < 1 and self.RefreshList == False:
3175
self.RefreshList = True
3177
if time.localtime().tm_hour == 0 and time.localtime().tm_min == 0 and time.localtime().tm_sec > 1 and self.RefreshList == True:
3178
self.RefreshList = False
3180
self.CheckOldAlarms()
3182
if self.RefreshList == True:
3183
gtk.gdk.threads_enter()
3184
self.LoadConfigFiles()
3185
gtk.gdk.threads_leave()
3186
self.RefreshList = False
3191
self.CheckOldAlarms()
3196
def CheckEmail(self):
3198
self.EmailFile = file(os.getenv("HOME") + "/.config/Alarm-Clock/email", "r")
3202
def CheckOldAlarms(self):
3204
self.AlFile = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "r")
3208
if self.Removed == True:
3209
self.RefreshList = True
3210
self.Removed = False
3213
self.Data = self.AlFile.readlines()
3217
for line in self.Data:
3218
self.OldLine = eval(line)
3220
if self.OldLine[2] == 1:
3221
self.Cnt = self.Cnt + 1
3226
self.Date = self.OldLine[3]
3227
self.Time = self.OldLine[1]
3229
self.date_data = re.search('(\d+)/(\d+)/(\d+)', self.Date)
3230
self.oy = int(self.date_data.group(1))
3231
self.om = int(self.date_data.group(2)) + 1
3232
self.od = int(self.date_data.group(3))
3233
self.time_data = re.search('(\d+):(\d+)', self.Time)
3234
self.oh = int(self.time_data.group(1))
3235
self.omin = int(self.time_data.group(2))
3237
self.DateOld = datetime.datetime(self.oy,self.om,self.od,self.oh,self.omin,0)
3239
self.CurrentDate = datetime.datetime.today()
3241
self.Diff = self.CurrentDate - self.DateOld
3243
if self.Diff.days > 0:
3244
self.RemoveOldAlarm(self.Cnt)
3245
self.Cnt = self.Cnt + 1
3249
if self.Diff.days == 0:
3250
if self.Diff.seconds > 0:
3251
self.RemoveOldAlarm(self.Cnt)
3252
self.Cnt = self.Cnt + 1
3257
self.Cnt = self.Cnt + 1
3261
def RemoveOldAlarm(self,no):
3263
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "r")
3264
self.lines = self.fbuf.readlines()
3267
for line in self.lines:
3268
if self.counter == self.row:
3269
self.counter = self.counter + 1
3271
self.new_lines.append(line)
3272
self.counter = self.counter + 1
3275
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "w")
3278
self.fbuf = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "a")
3279
for line in self.new_lines:
3280
self.fbuf.write(line)
3285
def ParseTupletToList(self,line):
3286
self.string = eval(line)
3289
self.weekdays = self.string[4][0]
3290
self.months = self.string[4][1]
3292
self.t_weekday = time.localtime().tm_wday
3293
self.t_month = time.localtime().tm_mon
3294
self.t_day = time.localtime().tm_mday
3301
self.t = re.search('(\d+):(\d+)', self.string[1])
3303
self.h = "%s" % self.t.group(1)
3305
if int (self.t.group(2)) < 10:
3306
self.m = "0%s" % self.t.group(2)
3308
self.m = "%s" % self.t.group(2)
3317
self.weekdays = self.string[4][0]
3318
self.months = self.string[4][1]
3320
if self.weekdays[self.t_weekday] == True and self.months[self.t_month - 1] == True:
3323
for t in self.string[5]:
3324
if t[0] == self.t_month and t[1] == self.t_day:
3331
if self.Good == True and self.string[2] == 1:
3332
self.time = _("%s:%s - Today") % (self.h, self.m)
3335
self.time = _("%s:%s - Cancelled") % (self.h, self.m)
3337
self.time = "%s:%s" % (self.h, self.m)
3351
if self.string[2] == 1:
3352
self.AlarmType = _("Scheduled")
3353
self.datetime = "%s" % self.time
3355
self.AlarmType = _("Single")
3356
self.date_data = re.search('(\d+)/(\d+)/(\d+)', self.string[3])
3359
if int(self.date_data.group(3)) < 10:
3360
self.day = "0%s" % self.date_data.group(3)
3362
self.day = self.date_data.group(3)
3364
if int (self.date_data.group(2)) < 9:
3366
self.month = "0%i" % (int(self.date_data.group(2)) + 1)
3368
self.month = "%i" % (int(self.date_data.group(2)) + 1)
3369
self.datetime = "%s %s/%s/%s" % (self.time, self.day, self.month, self.date_data.group(1))
3371
self.alarm_model.append([self.AlarmType, self.datetime, self.string[0]])
3378
def LoadConfigFiles(self):
3380
if os.path.isdir(os.getenv("HOME") + "/.config/Alarm-Clock/") == False:
3381
os.mkdir (os.getenv("HOME") + "/.config/Alarm-Clock")
3383
if os.path.isfile(os.getenv("HOME") + "/.config/Alarm-Clock/configuration") == False:
3384
self.fc = file(os.getenv("HOME") + "/.config/Alarm-Clock/configuration", "w")
3385
print >> self.fc, [MainWindow.get_position(), MainWindow.get_size()]
3387
if os.path.isfile(os.getenv("HOME") + "/.config/Alarm-Clock/alarms") == False:
3388
self.af = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "w")
3389
self.ClearAlarmValues()
3391
if os.path.isfile(os.getenv("HOME") + "/.config/Alarm-Clock/templates") == False:
3392
self.af = file(os.getenv("HOME") + "/.config/Alarm-Clock/templates", "w")
3396
self.ConfigFile = file(os.getenv("HOME") + "/.config/Alarm-Clock/configuration", "rw")
3397
self.AlarmFile = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms", "rw")
3399
for line in self.ConfigFile:
3400
self.configlist = eval(line)
3402
self.alarm_model.clear()
3404
for line in self.AlarmFile:
3406
self.ParseTupletToList(line)
3413
MainWindowGlade.get_widget('notebook').set_current_page(1)
3414
MainWindowGlade.get_widget('remove_alarm_toolbutton').set_sensitive(False)
3415
MainWindowGlade.get_widget('test_alarm_toolbutton').set_sensitive(False)
3416
MainWindowGlade.get_widget('alarm_properties_toolbutton').set_sensitive(False)
3417
MainWindowGlade.get_widget('edit_remove').set_sensitive(False)
3420
MainWindowGlade.get_widget('notebook').set_current_page(0)
3421
MainWindowGlade.get_widget('remove_alarm_toolbutton').set_sensitive(True)
3422
MainWindowGlade.get_widget('alarm_properties_toolbutton').set_sensitive(True)
3423
MainWindowGlade.get_widget('edit_remove').set_sensitive(True)
3424
MainWindowGlade.get_widget('test_alarm_toolbutton').set_sensitive(True)
3428
if self.row >= self.i:
3429
self.TreeSelection.select_path(self.i - 1,)
3431
self.TreeSelection.select_path(self.row,)
3433
self.TreeSelection.select_path(0,)
3435
def CheckTodayBirthdays(self):
3436
self.BirthdaysNames = []
3438
self.TodayDate = "%s/%s/%s" % (datetime.datetime.now().year, datetime.datetime.now().month - 1, datetime.datetime.now().day)
3441
self.bfile = file(os.getenv("HOME") + "/.config/Alarm-Clock/birthdays", "r")
3445
self.lnn = self.bfile.readlines()
3447
for line in self.lnn:
3448
if self.TodayDate == eval(line)[0]:
3449
self.BirthdaysNames.append(eval(line)[1])
3452
if self.BDay == True:
3453
self.Text = _("Birthday today! Remember to buy presents:\n")
3454
for name in self.BirthdaysNames:
3455
self.Text = self.Text + "\n" + name
3457
StatusIcon.set_tooltip(self.Text)
3458
StatusIcon.set_from_file('gfx/alarm-caution.svg')
3460
StatusIcon.set_tooltip(_("Alarm Clock"))
3461
StatusIcon.set_from_file('gfx/alarm-clock.svg')
3463
def CheckTodayAlarms(self):
3465
self.f = file(os.getenv("HOME") + "/.config/Alarm-Clock/alarms")
3467
self.ln = self.f.readlines()
3471
self.t_min = time.localtime().tm_min
3472
self.t_hour = time.localtime().tm_hour
3473
self.t_day = time.localtime().tm_mday
3474
self.t_weekday = time.localtime().tm_wday
3475
self.t_month = time.localtime().tm_mon
3476
self.t_year = time.localtime().tm_year
3479
for line in self.ln:
3480
self.buf = eval(line)
3481
self.date_data = re.search('(\d+)/(\d+)/(\d+)', self.buf[3])
3482
self.y = int(self.date_data.group(1))
3483
self.m = int(self.date_data.group(2)) + 1
3484
self.d = int(self.date_data.group(3))
3485
self.time_data = re.search('(\d+):(\d+)', self.buf[1])
3488
if self.buf[2] == 0:
3489
if self.y == self.t_year and self.m == self.t_month and self.d == self.t_day:
3490
self.tup = [int (self.time_data.group(1)), int (self.time_data.group(2)), self.linenumber]
3492
self.today.append(self.tup)
3498
self.weekdays = self.buf[4][0]
3499
self.months = self.buf[4][1]
3501
if self.weekdays[self.t_weekday] == True and self.months[self.t_month - 1] == True:
3504
for t in self.buf[5]:
3505
if t[0] == self.t_month and t[1] == self.t_day:
3508
if self.Good == True:
3509
self.tup = [int (self.time_data.group(1)), int (self.time_data.group(2)), self.linenumber]
3510
self.today = self.today + [self.tup]
3512
self.linenumber = self.linenumber + 1