def auto_sync_toggled(auto_button, time_button): active = auto_button.get_active() if active: (hours, minutes) = time_button.get_time() event = alarm.Event() event.appid = "erminig" event.title = "Synchronization with erminig" #event.flags |= alarm.EVENT_RUN_DELAYED action = event.add_actions(1)[0] action.flags |= alarm.ACTION_WHEN_TRIGGERED | alarm.ACTION_WHEN_DELAYED | alarm.ACTION_TYPE_EXEC action.command = os.path.abspath(sys.argv[0]) + " -a -d" recur = event.add_recurrences(1)[0] # let's see what this does... recur.mask_min = 1 << minutes recur.mask_hour = 1 << hours # initialize alarm time to somewhere in the future event.alarm_time = time.time() + 5 # lt = time.localtime(time.time() + 5) # tz = time.tzname[lt.tm_isdst] # event.alarm_time = time.mktime(recur.next(lt, tz)) event.recurrences_left = -1 sync_id = alarm.add_event(event) auto_sync_update_syncid(sync_id) auto_sync_update_synctime(hours, minutes) else: alarm.delete_event(int(auto_sync_get_syncid())) dblayer.run("DELETE FROM Prefs where name='auto_sync_id'") dblayer.commit()
def auto_sync_toggled(auto_button, time_button): active = auto_button.get_active() if active: (hours, minutes) = time_button.get_time() event = alarm.Event() event.appid = "erminig" event.title = "Synchronization with erminig" #event.flags |= alarm.EVENT_RUN_DELAYED action = event.add_actions(1)[0] action.flags |= alarm.ACTION_WHEN_TRIGGERED | alarm.ACTION_WHEN_DELAYED | alarm.ACTION_TYPE_EXEC action.command = os.path.abspath(sys.argv[0]) + " -a -d" recur = event.add_recurrences(1)[0] # let's see what this does... recur.mask_min = 1 << minutes recur.mask_hour = 1 << hours # initialize alarm time to somewhere in the future event.alarm_time = time.time() + 5 # lt = time.localtime(time.time() + 5) # tz = time.tzname[lt.tm_isdst] # event.alarm_time = time.mktime(recur.next(lt, tz)) event.recurrences_left = -1 sync_id=alarm.add_event(event) auto_sync_update_syncid(sync_id) auto_sync_update_synctime(hours, minutes) else: alarm.delete_event(int(auto_sync_get_syncid())) dblayer.run("DELETE FROM Prefs where name='auto_sync_id'") dblayer.commit()
def testExecuteCommand(self): '''Execute a command through alarm activation''' action = self.event.add_actions(1)[0] action.flags |= alarm.ACTION_WHEN_TRIGGERED | alarm.ACTION_TYPE_EXEC action.command = 'touch /tmp/alarm.txt' self.cookie = alarm.add_event(self.event) sleep(2) self.assert_(os.path.isfile('/tmp/alarm.txt'))
def main(): event = alarm.Event() event.appid = 'simple_recurrence' event.message = 'Example Recurring Message' event.alarm_time = time() + 5 action = event.add_actions(1)[0] action.flags |= alarm.ACTION_WHEN_RESPONDED | alarm.ACTION_TYPE_NOP action.label = 'Stop' recurrence = event.add_recurrences(1)[0] recurrence.mask_min |= alarm.RECUR_MIN_ALL recurrence.mask_hour |= alarm.RECUR_HOUR_DONTCARE recurrence.mask_mday |= alarm.RECUR_MDAY_DONTCARE recurrence.mask_wday |= alarm.RECUR_WDAY_DONTCARE recurrence.mask_mon |= alarm.RECUR_MON_DONTCARE recurrence.special |= alarm.RECUR_SPECIAL_NONE event.recurrences_left = 5 print alarm.add_event(event)
def add_two_button_alarm(): event = alarm.Event() event.appid = 'myappid' event.message = 'Example Message' event.alarm_time = time() + 10 action_stop, action_snooze = event.add_actions(2) action_stop.label = 'Stop' action_stop.flags |= alarm.ACTION_WHEN_RESPONDED | alarm.ACTION_TYPE_NOP action_snooze.label = 'Snooze' action_snooze.flags |= alarm.ACTION_WHEN_RESPONDED | alarm.ACTION_TYPE_SNOOZE print event.is_sane() cookie = alarm.add_event(event) return cookie
def testSimple(self): '''Simple DBus call through alarm''' event = alarm.Event() event.appid = 'dbus-alarm-test' event.alarm_time = time.time() + 2 action = event.add_actions(1)[0] action.flags |= alarm.ACTION_WHEN_TRIGGERED | alarm.ACTION_TYPE_DBUS action.dbus_service = 'org.foobar.Dummy' action.dbus_path = '/SomeObject' action.dbus_interface = 'org.foobar.Dummy' action.dbus_name = 'CallMe' self.cookie = alarm.add_event(event) time.sleep(3) self.assert_(os.path.isfile(confirmation_file))
def testCreateDelete(self): '''General lifecycle of an Event: Add, Retrieve, Update, Delete''' event = alarm.Event() appid = 'aaaa' event.appid = appid action = event.add_actions(1)[0] action.flags |= alarm.ACTION_WHEN_TRIGGERED | alarm.ACTION_TYPE_SNOOZE cookie = alarm.add_event(event) # Compare with 'cookie', as event.cookie is still 0 after adding event2 = alarm.get_event(cookie) self.assertEqual(cookie, event2.cookie) self.assertEqual(appid, event2.appid) event2.alarm_time = time() + 3 alarm.update_event(event2) alarm.delete_event(cookie) self.assertRaises(IndexError, alarm.get_event, cookie)
def _set_alarm(self, recurrenceMins): assert 1 <= recurrenceMins, "Notifications set to occur too frequently: %d" % recurrenceMins alarmTime = _get_start_time(recurrenceMins) event = alarm.Event() event.appid = self._TITLE event.alarm_time = alarmTime event.recurrences_left = self._REPEAT_FOREVER action = event.add_actions(1)[0] action.flags |= alarm.ACTION_TYPE_EXEC | alarm.ACTION_WHEN_TRIGGERED action.command = self._launcher recurrence = event.add_recurrences(1)[0] recurrence.mask_min |= _create_recurrence_mask(recurrenceMins, 60) recurrence.mask_hour |= alarm.RECUR_HOUR_DONTCARE recurrence.mask_mday |= alarm.RECUR_MDAY_DONTCARE recurrence.mask_wday |= alarm.RECUR_WDAY_DONTCARE recurrence.mask_mon |= alarm.RECUR_MON_DONTCARE recurrence.special |= alarm.RECUR_SPECIAL_NONE assert event.is_sane() self._alarmCookie = alarm.add_event(event)
def new_alarm(input): event = alarm.Event() event.appid = 'saera' event.message = 'Wake Up' time = datetime.datetime.today() words, has_nums = parse_to_nums(input.lower().split()) day_identifier = [i for i in words if i in weekdays] if "after tomorrow" in input.lower(): time = time+datetime.timedelta(days=2) elif 'tomorrow' in words: time = time+datetime.timedelta(days=1) elif day_identifier: day = weekdays.index(day_identifier[0]) print day time = time+datetime.timedelta(days=(day-time.weekday())%7) hour = [i for i in words if i in times] if hour: time = time.replace(hour=times[hour[0]],minute=0,second=0,microsecond=0) hour = False minute = 0 pmam = False bell = False for i in words: if hasattr(i, '__int__'): if type(hour)==bool and not hour: hour = i elif not minute: minute = i if i in bells: bell = True minute = bells[i] elif bell: if i in ['as', 'past', 'after']: pass elif i in ['to', 'told', 'til', 'till', 'of']: minute = -minute bell = False elif pmam: if i=='m.': if pmam=='pm': hour = hour%12+12 elif pmam=='am': hour = hour%12 pmam = False elif i in ['p.', 'a.']: pmam = {'p.':'pm','a.':'am'}[i] if minute<0: hour=(hour-1)%24 minute = 60+minute if type(hour)==bool: hour = time.hour time = time.replace(hour=hour,minute=minute,second=0,microsecond=0) event.alarm_time = float(time.strftime("%s")) action_stop, action_snooze = event.add_actions(2) action_stop.label = 'Stop' action_stop.flags |= alarm.ACTION_WHEN_RESPONDED | alarm.ACTION_TYPE_NOP action_snooze.label = 'Snooze' action_snooze.flags |= alarm.ACTION_WHEN_RESPONDED | alarm.ACTION_TYPE_SNOOZE print event.is_sane() cookie = alarm.add_event(event) return "Okay, I set your alarm for "+time.strftime("%I:%M %P"), None
def new_alarm(input): event = alarm.Event() event.appid = 'saera' event.message = 'Wake Up' time = datetime.datetime.today() words, has_nums = parse_to_nums(input.lower().split()) day_identifier = [i for i in words if i in weekdays] if "after tomorrow" in input.lower(): time = time + datetime.timedelta(days=2) elif 'tomorrow' in words: time = time + datetime.timedelta(days=1) elif day_identifier: day = weekdays.index(day_identifier[0]) print day time = time + datetime.timedelta(days=(day - time.weekday()) % 7) hour = [i for i in words if i in times] if hour: time = time.replace(hour=times[hour[0]], minute=0, second=0, microsecond=0) hour = False minute = 0 pmam = False bell = False for i in words: if hasattr(i, '__int__'): if type(hour) == bool and not hour: hour = i elif not minute: minute = i if i in bells: bell = True minute = bells[i] elif bell: if i in ['as', 'past', 'after']: pass elif i in ['to', 'told', 'til', 'till', 'of']: minute = -minute bell = False elif pmam: if i == 'm.': if pmam == 'pm': hour = hour % 12 + 12 elif pmam == 'am': hour = hour % 12 pmam = False elif i in ['p.', 'a.']: pmam = {'p.': 'pm', 'a.': 'am'}[i] if minute < 0: hour = (hour - 1) % 24 minute = 60 + minute if type(hour) == bool: hour = time.hour time = time.replace(hour=hour, minute=minute, second=0, microsecond=0) event.alarm_time = float(time.strftime("%s")) action_stop, action_snooze = event.add_actions(2) action_stop.label = 'Stop' action_stop.flags |= alarm.ACTION_WHEN_RESPONDED | alarm.ACTION_TYPE_NOP action_snooze.label = 'Snooze' action_snooze.flags |= alarm.ACTION_WHEN_RESPONDED | alarm.ACTION_TYPE_SNOOZE print event.is_sane() cookie = alarm.add_event(event) return "Okay, I set your alarm for " + time.strftime("%I:%M %P"), None