def subtitle(self): from wunderlist.util import format_time subtitle = [] if self.starred: subtitle.append(_star) # Task is completed if self.completed: subtitle.append('Completed %s' % short_relative_formatted_date(self.completed_at)) # Task is not yet completed elif self.due_date: subtitle.append('Due %s' % short_relative_formatted_date(self.due_date)) if self.recurrence_type: if self.recurrence_count > 1: subtitle.append( '%s Every %d %ss' % (_recurrence, self.recurrence_count, self.recurrence_type)) # Cannot simply add -ly suffix elif self.recurrence_type == 'day': subtitle.append('%s Daily' % (_recurrence)) else: subtitle.append('%s %sly' % (_recurrence, self.recurrence_type.title())) if not self.completed: overdue_times = self.overdue_times if overdue_times > 1: subtitle.insert( 0, u'%s %dX OVERDUE!' % (_overdue_2x, overdue_times)) elif overdue_times == 1: subtitle.insert(0, u'%s OVERDUE!' % (_overdue_1x)) reminder_date = self.reminder_date_local if reminder_date: reminder_date_phrase = None if reminder_date.date() == self.due_date: reminder_date_phrase = 'On due date' else: reminder_date_phrase = short_relative_formatted_date( reminder_date) subtitle.append('%s %s at %s' % (_reminder, reminder_date_phrase, format_time(reminder_date, 'short'))) subtitle.append(self.title) return ' '.join(subtitle)
def subtitle(self): from wunderlist.util import format_time subtitle = [] if self.starred: subtitle.append(_star) # Task is completed if self.completed: subtitle.append('Completed %s' % short_relative_formatted_date(self.completed_at)) # Task is not yet completed elif self.due_date: subtitle.append('Due %s' % short_relative_formatted_date(self.due_date)) if self.recurrence_type: if self.recurrence_count > 1: subtitle.append('%s Every %d %ss' % (_recurrence, self.recurrence_count, self.recurrence_type)) # Cannot simply add -ly suffix elif self.recurrence_type == 'day': subtitle.append('%s Daily' % (_recurrence)) else: subtitle.append('%s %sly' % (_recurrence, self.recurrence_type.title())) if not self.completed: overdue_times = self.overdue_times if overdue_times > 1: subtitle.insert(0, u'%s %dX OVERDUE!' % (_overdue_2x, overdue_times)) elif overdue_times == 1: subtitle.insert(0, u'%s OVERDUE!' % (_overdue_1x)) reminder_date = self.reminder_date_local if reminder_date: reminder_date_phrase = None if reminder_date.date() == self.due_date: reminder_date_phrase = 'On due date' else: reminder_date_phrase = short_relative_formatted_date(reminder_date) subtitle.append('%s %s at %s' % ( _reminder, reminder_date_phrase, format_time(reminder_date, 'short'))) subtitle.append(self.title) return ' '.join(subtitle)
def task_subtitle(task): subtitle = [] if task.starred: subtitle.append(_star) if task.due_date: subtitle.append('Due %s' % short_relative_formatted_date(task.due_date)) if task.recurrence_type: if task.recurrence_count > 1: subtitle.append( '%s Every %d %ss' % (_recurrence, task.recurrence_count, task.recurrence_type)) # Cannot simply add -ly suffix elif task.recurrence_type == 'day': subtitle.append('%s Daily' % (_recurrence)) else: subtitle.append('%s %sly' % (_recurrence, task.recurrence_type.title())) if task.reminder_date: reminder_date_phrase = None if task.reminder_date.date() == task.due_date: reminder_date_phrase = 'On due date' else: reminder_date_phrase = short_relative_formatted_date( task.reminder_date) subtitle.append('%s %s at %s' % (_reminder, reminder_date_phrase, format_time(task.reminder_date.time(), 'short'))) subtitle.append(task.title) return ' '.join(subtitle)
def filter(args): task = _task(args) subtitle = task_subtitle(task) wf = workflow() matching_hashtags = [] if not task.title: subtitle = 'Begin typing to add a new task' # Preload matching hashtags into a list so that we can get the length if task.has_hashtag_prompt: from wunderlist.models.hashtag import Hashtag hashtags = Hashtag.select().where(Hashtag.id.contains(task.hashtag_prompt.lower())).order_by(fn.Lower(Hashtag.tag).asc()) for hashtag in hashtags: matching_hashtags.append(hashtag) # Show hashtag prompt if there is more than one matching hashtag or the # hashtag being typed does not exactly match the single matching hashtag if task.has_hashtag_prompt and len(matching_hashtags) > 0 and (len(matching_hashtags) > 1 or task.hashtag_prompt != matching_hashtags[0].tag): for hashtag in matching_hashtags: wf.add_item(hashtag.tag[1:], '', autocomplete=' ' + task.phrase_with(hashtag=hashtag.tag) + ' ', icon=icons.HASHTAG) elif task.has_list_prompt: lists = wf.stored_data('lists') if lists: for list in lists: # Show some full list names and some concatenated in command # suggestions sample_command = list['title'] if random() > 0.5: sample_command = sample_command[:int(len(sample_command) * .75)] icon = icons.INBOX if list['list_type'] == 'inbox' else icons.LIST wf.add_item(list['title'], 'Assign task to this list, e.g. %s: %s' % (sample_command.lower(), task.title), autocomplete=' ' + task.phrase_with(list_title=list['title']), icon=icon) wf.add_item('Remove list', 'Tasks without a list are added to the Inbox', autocomplete=' ' + task.phrase_with(list_title=False), icon=icons.CANCEL) elif is_running('sync'): wf.add_item('Your lists are being synchronized', 'Please try again in a few moments', autocomplete=' ' + task.phrase_with(list_title=False), icon=icons.BACK) # Task has an unfinished recurrence phrase elif task.has_recurrence_prompt: wf.add_item('Every month', 'Same day every month, e.g. every mo', uid="recurrence_1m", autocomplete=' %s ' % task.phrase_with(recurrence='every month'), icon=icons.RECURRENCE) wf.add_item('Every week', 'Same day every week, e.g. every week, every Tuesday', uid="recurrence_1w", autocomplete=' %s ' % task.phrase_with(recurrence='every week'), icon=icons.RECURRENCE) wf.add_item('Every year', 'Same date every year, e.g. every 1 y, every April 15', uid="recurrence_1y", autocomplete=' %s ' % task.phrase_with(recurrence='every year'), icon=icons.RECURRENCE) wf.add_item('Every 3 months', 'Same day every 3 months, e.g. every 3 months', uid="recurrence_3m", autocomplete=' %s ' % task.phrase_with(recurrence='every 3 months'), icon=icons.RECURRENCE) wf.add_item('Remove recurrence', autocomplete=' ' + task.phrase_with(recurrence=False), icon=icons.CANCEL) # Task has an unfinished due date phrase elif task.has_due_date_prompt: wf.add_item('Today', 'e.g. due today', autocomplete=' %s ' % task.phrase_with(due_date='due today'), icon=icons.TODAY) wf.add_item('Tomorrow', 'e.g. due tomorrow', autocomplete=' %s ' % task.phrase_with(due_date='due tomorrow'), icon=icons.TOMORROW) wf.add_item('Next Week', 'e.g. due next week', autocomplete=' %s ' % task.phrase_with(due_date='due next week'), icon=icons.NEXT_WEEK) wf.add_item('Next Month', 'e.g. due next month', autocomplete=' %s ' % task.phrase_with(due_date='due next month'), icon=icons.CALENDAR) wf.add_item('Next Year', 'e.g. due next year, due April 15', autocomplete=' %s ' % task.phrase_with(due_date='due next year'), icon=icons.CALENDAR) wf.add_item('Remove due date', 'Add "not due" to fix accidental dates, or see wl-pref', autocomplete=' ' + task.phrase_with(due_date=False), icon=icons.CANCEL) # Task has an unfinished reminder phrase elif task.has_reminder_prompt: prefs = Preferences.current_prefs() default_reminder_time = format_time(prefs.reminder_time, 'short') due_date_hint = ' on the due date' if task.due_date else '' wf.add_item('Reminder at %s%s' % (default_reminder_time, due_date_hint), 'e.g. r %s' % default_reminder_time, autocomplete=' %s ' % task.phrase_with(reminder_date='remind me at %s' % format_time(prefs.reminder_time, 'short')), icon=icons.REMINDER) wf.add_item('At noon%s' % due_date_hint, 'e.g. reminder noon', autocomplete=' %s ' % task.phrase_with(reminder_date='remind me at noon'), icon=icons.REMINDER) wf.add_item('At 8:00 PM%s' % due_date_hint, 'e.g. remind at 8:00 PM', autocomplete=' %s ' % task.phrase_with(reminder_date='remind me at 8:00pm'), icon=icons.REMINDER) wf.add_item('At dinner%s' % due_date_hint, 'e.g. alarm at dinner', autocomplete=' %s ' % task.phrase_with(reminder_date='remind me at dinner'), icon=icons.REMINDER) wf.add_item('Today at 6:00 PM', 'e.g. remind me today at 6pm', autocomplete=' %s ' % task.phrase_with(reminder_date='remind me today at 6:00pm'), icon=icons.REMINDER) wf.add_item('Remove reminder', autocomplete=' ' + task.phrase_with(reminder_date=False), icon=icons.CANCEL) # Main menu for tasks else: wf.add_item(task.list_title + u' – create a new task...', subtitle, modifier_subtitles={ 'alt': u'…then edit it in the Wunderlist app %s' % subtitle }, arg='--stored-query', valid=task.title != '', icon=icons.TASK) title = 'Change list' if task.list_title else 'Select a list' wf.add_item(title, 'Prefix the task, e.g. Automotive: ' + task.title, autocomplete=' ' + task.phrase_with(list_title=True), icon=icons.LIST) title = 'Change the due date' if task.due_date else 'Set a due date' wf.add_item(title, '"due" followed by any date-related phrase, e.g. due next Tuesday; due May 4', autocomplete=' ' + task.phrase_with(due_date=True), icon=icons.CALENDAR) title = 'Change the recurrence' if task.recurrence_type else 'Make it a recurring task' wf.add_item(title, '"every" followed by a unit of time, e.g. every 2 months; every year; every 4w', autocomplete=' ' + task.phrase_with(recurrence=True), icon=icons.RECURRENCE) title = 'Change the reminder' if task.reminder_date else 'Set a reminder' wf.add_item(title, '"remind me" followed by a time and/or date, e.g. remind me at noon; r 10am; alarm 8:45p', autocomplete=' ' + task.phrase_with(reminder_date=True), icon=icons.REMINDER) if task.starred: wf.add_item('Remove star', 'Remove * from the task', autocomplete=' ' + task.phrase_with(starred=False), icon=icons.STAR_REMOVE) else: wf.add_item('Star', 'End the task with * (asterisk)', autocomplete=' ' + task.phrase_with(starred=True), icon=icons.STAR) wf.add_item('Main menu', autocomplete='', icon=icons.BACK)
def filter(args): prefs = Preferences.current_prefs() if 'reminder' in args: reminder_time = _parse_time(' '.join(args)) if reminder_time is not None: workflow().add_item( 'Change default reminder time', u'⏰ %s' % format_time(reminder_time, 'short'), arg=' '.join(args), valid=True, icon=icons.REMINDER ) else: workflow().add_item( 'Type a new reminder time', 'Date offsets like the morning before the due date are not supported yet', valid=False, icon=icons.REMINDER ) workflow().add_item( 'Cancel', autocomplete=':pref', icon=icons.BACK ) elif 'reminder_today' in args: reminder_today_offset = _parse_time(' '.join(args)) if reminder_today_offset is not None: workflow().add_item( 'Set a custom reminder offset', u'⏰ now + %s' % _format_time_offset(reminder_today_offset), arg=' '.join(args), valid=True, icon=icons.REMINDER ) else: workflow().add_item( 'Type a custom reminder offset', 'Use the formats hh:mm or 2h 5m', valid=False, icon=icons.REMINDER ) workflow().add_item( '30 minutes', arg=':pref reminder_today 30m', valid=True, icon=icons.REMINDER ) workflow().add_item( '1 hour', '(default)', arg=':pref reminder_today 1h', valid=True, icon=icons.REMINDER ) workflow().add_item( '90 minutes', arg=':pref reminder_today 90m', valid=True, icon=icons.REMINDER ) workflow().add_item( 'Always use the default reminder time', 'Avoids adjusting the reminder based on the current date', arg=':pref reminder_today disabled', valid=True, icon=icons.CANCEL ) workflow().add_item( 'Cancel', autocomplete=':pref', icon=icons.BACK ) else: current_user = User.get() if current_user and current_user.name: workflow().add_item( 'Sign out', 'You are logged in as ' + current_user.name, autocomplete=':logout', icon=icons.CANCEL ) workflow().add_item( 'Default reminder time', u'⏰ %s Reminders without a specific time will be set to this time' % format_time(prefs.reminder_time, 'short'), autocomplete=':pref reminder ', icon=icons.REMINDER ) workflow().add_item( 'Default reminder when due today', u'⏰ %s Default reminder time for tasks due today is %s' % (_format_time_offset(prefs.reminder_today_offset), 'relative to the current time' if prefs.reminder_today_offset else 'always %s' % format_time(prefs.reminder_time, 'short')), autocomplete=':pref reminder_today ', icon=icons.REMINDER ) workflow().add_item( 'Automatically set a reminder on the due date', u'Sets a default reminder for tasks with a due date.', arg=':pref automatic_reminders', valid=True, icon=icons.TASK_COMPLETED if prefs.automatic_reminders else icons.TASK ) workflow().add_item( 'Require explicit due keyword', 'Requires the due keyword to avoid accidental due date extraction', arg=':pref explicit_keywords', valid=True, icon=icons.TASK_COMPLETED if prefs.explicit_keywords else icons.TASK ) workflow().add_item( 'Check for experimental updates to this workflow', 'The workflow automatically checks for updates; enable this to include pre-releases', arg=':pref prerelease_channel', valid=True, icon=icons.TASK_COMPLETED if prefs.prerelease_channel else icons.TASK ) workflow().add_item( 'Force sync', 'The workflow syncs automatically, but feel free to be forcible.', arg=':pref sync', valid=True, icon=icons.SYNC ) workflow().add_item( 'Switch theme', 'Toggle between light and dark icons', arg=':pref retheme', valid=True, icon=icons.PAINTBRUSH ) workflow().add_item( 'Main menu', autocomplete='', icon=icons.BACK )
def commit(args): prefs = Preferences.current_prefs() relaunch_alfred = False if 'sync' in args: from wunderlist.sync import sync sync() elif 'explicit_keywords' in args: relaunch_alfred = True prefs.explicit_keywords = not prefs.explicit_keywords if prefs.explicit_keywords: print 'Remember to use the "due" keyword' else: print 'Implicit due dates enabled (e.g. "Recycling tomorrow")' elif 'reminder' in args: relaunch_alfred = True reminder_time = _parse_time(' '.join(args)) if reminder_time is not None: prefs.reminder_time = reminder_time print 'Reminders will now default to %s' % format_time(reminder_time, 'short') elif 'reminder_today' in args: relaunch_alfred = True reminder_today_offset = None if not ('disabled' in args): reminder_today_offset = _parse_time(' '.join(args)) prefs.reminder_today_offset = reminder_today_offset print 'The offset for current-day reminders is now %s' % _format_time_offset(reminder_today_offset) elif 'automatic_reminders' in args: relaunch_alfred = True prefs.automatic_reminders = not prefs.automatic_reminders if prefs.automatic_reminders: print 'A reminder will automatically be set for due tasks' else: print 'A reminder will not be added automatically' elif 'retheme' in args: relaunch_alfred = True prefs.icon_theme = 'light' if icons.icon_theme() == 'dark' else 'dark' print 'The workflow is now using the %s icon theme' % (prefs.icon_theme) elif 'prerelease_channel' in args: relaunch_alfred = True prefs.prerelease_channel = not prefs.prerelease_channel # Update the workflow settings and reverify the update data workflow().check_update(True) if prefs.prerelease_channel: print 'The workflow will prompt you to update to experimental pre-releases' else: print 'The workflow will only prompt you to update to final releases' if relaunch_alfred: import subprocess subprocess.call(['/usr/bin/env', 'osascript', 'bin/launch_alfred.scpt', 'wl:pref'])
def filter(args): prefs = Preferences.current_prefs() if 'reminder' in args: reminder_time = _parse_time(' '.join(args)) if reminder_time is not None: workflow().add_item('Change default reminder time', u'⏰ %s' % format_time(reminder_time, 'short'), arg=' '.join(args), valid=True, icon=icons.REMINDER) else: workflow().add_item( 'Type a new reminder time', 'Date offsets like the morning before the due date are not supported yet', valid=False, icon=icons.REMINDER) workflow().add_item('Cancel', autocomplete='-pref', icon=icons.BACK) elif 'reminder_today' in args: reminder_today_offset = _parse_time(' '.join(args)) if reminder_today_offset is not None: workflow().add_item('Set a custom reminder offset', u'⏰ now + %s' % _format_time_offset(reminder_today_offset), arg=' '.join(args), valid=True, icon=icons.REMINDER) else: workflow().add_item('Type a custom reminder offset', 'Use the formats hh:mm or 2h 5m', valid=False, icon=icons.REMINDER) workflow().add_item('30 minutes', arg='-pref reminder_today 30m', valid=True, icon=icons.REMINDER) workflow().add_item('1 hour', '(default)', arg='-pref reminder_today 1h', valid=True, icon=icons.REMINDER) workflow().add_item('90 minutes', arg='-pref reminder_today 90m', valid=True, icon=icons.REMINDER) workflow().add_item( 'Always use the default reminder time', 'Avoids adjusting the reminder based on the current date', arg='-pref reminder_today disabled', valid=True, icon=icons.CANCEL) workflow().add_item('Cancel', autocomplete='-pref', icon=icons.BACK) elif 'default_list' in args: lists = workflow().stored_data('lists') matching_lists = lists if len(args) > 2: list_query = ' '.join(args[2:]) if list_query: matching_lists = workflow().filter( list_query, lists, lambda l: l['title'], # Ignore MATCH_ALLCHARS which is expensive and inaccurate match_on=MATCH_ALL ^ MATCH_ALLCHARS) for i, l in enumerate(matching_lists): if i == 1: workflow().add_item( 'Most recently used list', 'Default to the last list to which a task was added', arg='-pref default_list %d' % DEFAULT_LIST_MOST_RECENT, valid=True, icon=icons.RECURRENCE) icon = icons.INBOX if l['list_type'] == 'inbox' else icons.LIST workflow().add_item(l['title'], arg='-pref default_list %s' % l['id'], valid=True, icon=icon) workflow().add_item('Cancel', autocomplete='-pref', icon=icons.BACK) else: current_user = None lists = workflow().stored_data('lists') default_list_name = 'Inbox' try: current_user = User.get() except User.DoesNotExist: pass except OperationalError: from wunderlist.sync import background_sync background_sync() if prefs.default_list_id == DEFAULT_LIST_MOST_RECENT: default_list_name = 'Most recent list' else: default_list_id = prefs.default_list_id default_list_name = next( (l['title'] for l in lists if l['id'] == default_list_id), 'Inbox') if current_user and current_user.name: workflow().add_item('Sign out', 'You are logged in as ' + current_user.name, autocomplete='-logout', icon=icons.CANCEL) workflow().add_item('Show completed tasks', 'Includes completed tasks in search results', arg='-pref show_completed_tasks', valid=True, icon=icons.TASK_COMPLETED if prefs.show_completed_tasks else icons.TASK) workflow().add_item( 'Default reminder time', u'⏰ %s Reminders without a specific time will be set to this time' % format_time(prefs.reminder_time, 'short'), autocomplete='-pref reminder ', icon=icons.REMINDER) workflow().add_item( 'Default reminder when due today', u'⏰ %s Default reminder time for tasks due today is %s' % (_format_time_offset(prefs.reminder_today_offset), 'relative to the current time' if prefs.reminder_today_offset else 'always %s' % format_time(prefs.reminder_time, 'short')), autocomplete='-pref reminder_today ', icon=icons.REMINDER) workflow().add_item( 'Default list', u'%s Change the default list when creating new tasks' % default_list_name, autocomplete='-pref default_list ', icon=icons.LIST) workflow().add_item( 'Automatically set a reminder on the due date', u'Sets a default reminder for tasks with a due date.', arg='-pref automatic_reminders', valid=True, icon=icons.TASK_COMPLETED if prefs.automatic_reminders else icons.TASK) workflow().add_item( 'Require explicit due keyword', 'Requires the due keyword to avoid accidental due date extraction', arg='-pref explicit_keywords', valid=True, icon=icons.TASK_COMPLETED if prefs.explicit_keywords else icons.TASK) workflow().add_item( 'Check for experimental updates to this workflow', 'The workflow automatically checks for updates; enable this to include pre-releases', arg=':pref prerelease_channel', valid=True, icon=icons.TASK_COMPLETED if prefs.prerelease_channel else icons.TASK) workflow().add_item( 'Force sync', 'The workflow syncs automatically, but feel free to be forcible.', arg='-pref sync', valid=True, icon=icons.SYNC) workflow().add_item('Switch theme', 'Toggle between light and dark icons', arg='-pref retheme', valid=True, icon=icons.PAINTBRUSH) workflow().add_item('Main menu', autocomplete='', icon=icons.BACK)
def commit(args, modifier=None): prefs = Preferences.current_prefs() relaunch_command = '-pref' if '--alfred' in args: relaunch_command = ' '.join(args[args.index('--alfred') + 1:]) if 'sync' in args: from wunderlist.sync import sync sync('background' in args) relaunch_command = None elif 'show_completed_tasks' in args: prefs.show_completed_tasks = not prefs.show_completed_tasks if prefs.show_completed_tasks: print 'Completed tasks are now visible in the workflow' else: print 'Completed tasks will not be visible in the workflow' elif 'default_list' in args: default_list_id = None lists = workflow().stored_data('lists') if len(args) > 2: default_list_id = int(args[2]) prefs.default_list_id = default_list_id if default_list_id: default_list_name = next( (l['title'] for l in lists if l['id'] == default_list_id), 'Inbox') print 'Tasks will be added to your %s list by default' % default_list_name else: print 'Tasks will be added to the Inbox by default' elif 'explicit_keywords' in args: prefs.explicit_keywords = not prefs.explicit_keywords if prefs.explicit_keywords: print 'Remember to use the "due" keyword' else: print 'Implicit due dates enabled (e.g. "Recycling tomorrow")' elif 'reminder' in args: reminder_time = _parse_time(' '.join(args)) if reminder_time is not None: prefs.reminder_time = reminder_time print 'Reminders will now default to %s' % format_time( reminder_time, 'short') elif 'reminder_today' in args: reminder_today_offset = None if not 'disabled' in args: reminder_today_offset = _parse_time(' '.join(args)) prefs.reminder_today_offset = reminder_today_offset print 'The offset for current-day reminders is now %s' % _format_time_offset( reminder_today_offset) elif 'automatic_reminders' in args: prefs.automatic_reminders = not prefs.automatic_reminders if prefs.automatic_reminders: print 'A reminder will automatically be set for due tasks' else: print 'A reminder will not be added automatically' elif 'retheme' in args: prefs.icon_theme = 'light' if icons.icon_theme() == 'dark' else 'dark' print 'The workflow is now using the %s icon theme' % ( prefs.icon_theme) elif 'prerelease_channel' in args: prefs.prerelease_channel = not prefs.prerelease_channel # Update the workflow settings and reverify the update data workflow().check_update(True) if prefs.prerelease_channel: print 'The workflow will prompt you to update to experimental pre-releases' else: print 'The workflow will only prompt you to update to final releases' if relaunch_command: relaunch_alfred(relaunch_command)
def filter(args): task = _task(args) subtitle = [] wf = workflow() if task.starred: subtitle.append(_star) if task.due_date: today = date.today() if task.due_date == today: date_format = 'Today' elif task.due_date.year == today.year: date_format = '%a, %b %d' else: date_format = '%b %d, %Y' subtitle.append('Due %s' % (task.due_date.strftime(date_format))) if task.recurrence_type: if task.recurrence_count > 1: subtitle.append('%s Every %d %ss' % (_recurrence, task.recurrence_count, task.recurrence_type)) # Cannot simply add -ly suffix elif task.recurrence_type == 'day': subtitle.append('%s Daily' % (_recurrence)) else: subtitle.append('%s %sly' % (_recurrence, task.recurrence_type.title())) if task.reminder_date: today = date.today() if task.reminder_date.date() == today: date_format = 'Today' elif task.reminder_date.date() == task.due_date: date_format = 'On due date' elif task.reminder_date.year == today.year: date_format = '%a, %b %d' else: date_format = '%b %d, %Y' subtitle.append('%s %s at %s' % ( _reminder, task.reminder_date.strftime(date_format), format_time(task.reminder_date.time(), 'short')) ) subtitle.append(task.title or 'Begin typing to add a new task') if task.has_list_prompt: lists = wf.stored_data('lists') if lists: for list in lists: # Show some full list names and some concatenated in command # suggestions sample_command = list['title'] if random() > 0.5: sample_command = sample_command[:int(len(sample_command) * .75)] icon = icons.INBOX if list['list_type'] == 'inbox' else icons.LIST wf.add_item(list['title'], 'Assign task to this list, e.g. %s: %s' % (sample_command.lower(), task.title), autocomplete=' ' + task.phrase_with(list_title=list['title']), icon=icon) wf.add_item('Remove list', 'Tasks without a list are added to the Inbox', autocomplete=' ' + task.phrase_with(list_title=False), icon=icons.CANCEL) elif is_running('sync'): wf.add_item('Your lists are being synchronized', 'Please try again in a few moments', autocomplete=' ' + task.phrase_with(list_title=False), icon=icons.BACK) # Task has an unfinished recurrence phrase elif task.has_recurrence_prompt: wf.add_item('Every month', 'Same day every month, e.g. every mo', uid="recurrence_1m", autocomplete=' %s ' % task.phrase_with(recurrence='every month'), icon=icons.RECURRENCE) wf.add_item('Every week', 'Same day every week, e.g. every week, every Tuesday', uid="recurrence_1w", autocomplete=' %s ' % task.phrase_with(recurrence='every week'), icon=icons.RECURRENCE) wf.add_item('Every year', 'Same date every year, e.g. every 1 y, every April 15', uid="recurrence_1y", autocomplete=' %s ' % task.phrase_with(recurrence='every year'), icon=icons.RECURRENCE) wf.add_item('Every 3 months', 'Same day every 3 months, e.g. every 3 months', uid="recurrence_3m", autocomplete=' %s ' % task.phrase_with(recurrence='every 3 months'), icon=icons.RECURRENCE) wf.add_item('Remove recurrence', autocomplete=' ' + task.phrase_with(recurrence=False), icon=icons.CANCEL) # Task has an unfinished due date phrase elif task.has_due_date_prompt: wf.add_item('Today', 'e.g. due today', autocomplete=' %s ' % task.phrase_with(due_date='due today'), icon=icons.TODAY) wf.add_item('Tomorrow', 'e.g. due tomorrow', autocomplete=' %s ' % task.phrase_with(due_date='due tomorrow'), icon=icons.TOMORROW) wf.add_item('Next Week', 'e.g. due next week', autocomplete=' %s ' % task.phrase_with(due_date='due next week'), icon=icons.NEXT_WEEK) wf.add_item('Next Month', 'e.g. due next month', autocomplete=' %s ' % task.phrase_with(due_date='due next month'), icon=icons.CALENDAR) wf.add_item('Next Year', 'e.g. due next year, due April 15', autocomplete=' %s ' % task.phrase_with(due_date='due next year'), icon=icons.CALENDAR) wf.add_item('Remove due date', 'Add "not due" to fix accidental dates, or see wl:pref', autocomplete=' ' + task.phrase_with(due_date=False), icon=icons.CANCEL) # Task has an unfinished reminder phrase elif task.has_reminder_prompt: prefs = Preferences.current_prefs() default_reminder_time = format_time(prefs.reminder_time, 'short') due_date_hint = ' on the due date' if task.due_date else '' wf.add_item('Reminder at %s%s' % (default_reminder_time, due_date_hint), 'e.g. r %s' % default_reminder_time, autocomplete=' %s ' % task.phrase_with(reminder_date='remind me at %s' % format_time(prefs.reminder_time, 'short')), icon=icons.REMINDER) wf.add_item('At noon%s' % due_date_hint, 'e.g. reminder noon', autocomplete=' %s ' % task.phrase_with(reminder_date='remind me at noon'), icon=icons.REMINDER) wf.add_item('At 8:00 PM%s' % due_date_hint, 'e.g. remind at 8:00 PM', autocomplete=' %s ' % task.phrase_with(reminder_date='remind me at 8:00pm'), icon=icons.REMINDER) wf.add_item('At dinner%s' % due_date_hint, 'e.g. alarm at dinner', autocomplete=' %s ' % task.phrase_with(reminder_date='remind me at dinner'), icon=icons.REMINDER) wf.add_item('Today at 6:00 PM', 'e.g. remind me today at 6pm', autocomplete=' %s ' % task.phrase_with(reminder_date='remind me today at 6:00pm'), icon=icons.REMINDER) wf.add_item('Remove reminder', autocomplete=' ' + task.phrase_with(reminder_date=False), icon=icons.CANCEL) # Main menu for tasks else: wf.add_item(task.list_title + u' – create a new task...', ' '.join(subtitle), arg='--stored-query', valid=task.title != '', icon=icons.TASK) title = 'Change list' if task.list_title else 'Select a list' wf.add_item(title, 'Prefix the task, e.g. Automotive: ' + task.title, autocomplete=' ' + task.phrase_with(list_title=True), icon=icons.LIST) title = 'Change the due date' if task.due_date else 'Set a due date' wf.add_item(title, '"due" followed by any date-related phrase, e.g. due next Tuesday; due May 4', autocomplete=' ' + task.phrase_with(due_date=True), icon=icons.CALENDAR) title = 'Change the recurrence' if task.recurrence_type else 'Make it a recurring task' wf.add_item(title, '"every" followed by a unit of time, e.g. every 2 months; every year; every 4w', autocomplete=' ' + task.phrase_with(recurrence=True), icon=icons.RECURRENCE) title = 'Change the reminder' if task.reminder_date else 'Set a reminder' wf.add_item(title, '"remind me" followed by a time and/or date, e.g. remind me at noon; r 10am; alarm 8:45p', autocomplete=' ' + task.phrase_with(reminder_date=True), icon=icons.REMINDER) if task.starred: wf.add_item('Remove star', 'Remove * from the task', autocomplete=' ' + task.phrase_with(starred=False), icon=icons.STAR_REMOVE) else: wf.add_item('Star', 'End the task with * (asterisk)', autocomplete=' ' + task.phrase_with(starred=True), icon=icons.STAR) wf.add_item('Main menu', autocomplete='', icon=icons.BACK)
def filter(args): prefs = Preferences.current_prefs() if 'reminder' in args: reminder_time = _parse_time(' '.join(args)) if reminder_time is not None: workflow().add_item( 'Change default reminder time', u'⏰ %s' % format_time(reminder_time, 'short'), arg=' '.join(args), valid=True, icon=icons.REMINDER ) else: workflow().add_item( 'Type a new reminder time', 'Date offsets like the morning before the due date are not supported yet', valid=False, icon=icons.REMINDER ) workflow().add_item( 'Cancel', autocomplete='-pref', icon=icons.BACK ) elif 'reminder_today' in args: reminder_today_offset = _parse_time(' '.join(args)) if reminder_today_offset is not None: workflow().add_item( 'Set a custom reminder offset', u'⏰ now + %s' % _format_time_offset(reminder_today_offset), arg=' '.join(args), valid=True, icon=icons.REMINDER ) else: workflow().add_item( 'Type a custom reminder offset', 'Use the formats hh:mm or 2h 5m', valid=False, icon=icons.REMINDER ) workflow().add_item( '30 minutes', arg='-pref reminder_today 30m', valid=True, icon=icons.REMINDER ) workflow().add_item( '1 hour', '(default)', arg='-pref reminder_today 1h', valid=True, icon=icons.REMINDER ) workflow().add_item( '90 minutes', arg='-pref reminder_today 90m', valid=True, icon=icons.REMINDER ) workflow().add_item( 'Always use the default reminder time', 'Avoids adjusting the reminder based on the current date', arg='-pref reminder_today disabled', valid=True, icon=icons.CANCEL ) workflow().add_item( 'Cancel', autocomplete='-pref', icon=icons.BACK ) elif 'default_list' in args: lists = workflow().stored_data('lists') matching_lists = lists if len(args) > 2: list_query = ' '.join(args[2:]) if list_query: matching_lists = workflow().filter( list_query, lists, lambda l: l['title'], # Ignore MATCH_ALLCHARS which is expensive and inaccurate match_on=MATCH_ALL ^ MATCH_ALLCHARS ) for i, l in enumerate(matching_lists): if i == 1: workflow().add_item( 'Most recently used list', 'Default to the last list to which a task was added', arg='-pref default_list %d' % DEFAULT_LIST_MOST_RECENT, valid=True, icon=icons.RECURRENCE ) icon = icons.INBOX if l['list_type'] == 'inbox' else icons.LIST workflow().add_item( l['title'], arg='-pref default_list %s' % l['id'], valid=True, icon=icon ) workflow().add_item( 'Cancel', autocomplete='-pref', icon=icons.BACK ) else: current_user = None lists = workflow().stored_data('lists') loc = user_locale() default_list_name = 'Inbox' try: current_user = User.get() except User.DoesNotExist: pass except OperationalError: from wunderlist.sync import background_sync background_sync() if prefs.default_list_id == DEFAULT_LIST_MOST_RECENT: default_list_name = 'Most recent list' else: default_list_id = prefs.default_list_id default_list_name = next((l['title'] for l in lists if l['id'] == default_list_id), 'Inbox') if current_user and current_user.name: workflow().add_item( 'Sign out', 'You are logged in as ' + current_user.name, autocomplete='-logout', icon=icons.CANCEL ) workflow().add_item( 'Show completed tasks', 'Includes completed tasks in search results', arg='-pref show_completed_tasks', valid=True, icon=icons.TASK_COMPLETED if prefs.show_completed_tasks else icons.TASK ) workflow().add_item( 'Default reminder time', u'⏰ %s Reminders without a specific time will be set to this time' % format_time(prefs.reminder_time, 'short'), autocomplete='-pref reminder ', icon=icons.REMINDER ) workflow().add_item( 'Default reminder when due today', u'⏰ %s Default reminder time for tasks due today is %s' % (_format_time_offset(prefs.reminder_today_offset), 'relative to the current time' if prefs.reminder_today_offset else 'always %s' % format_time(prefs.reminder_time, 'short')), autocomplete='-pref reminder_today ', icon=icons.REMINDER ) workflow().add_item( 'Default list', u'%s Change the default list when creating new tasks' % default_list_name, autocomplete='-pref default_list ', icon=icons.LIST ) workflow().add_item( 'Automatically set a reminder on the due date', u'Sets a default reminder for tasks with a due date.', arg='-pref automatic_reminders', valid=True, icon=icons.TASK_COMPLETED if prefs.automatic_reminders else icons.TASK ) if loc != 'en_US' or prefs.date_locale: workflow().add_item( 'Force US English for dates', 'Rather than the current locale (%s)' % loc, arg='-pref force_en_US', valid=True, icon=icons.TASK_COMPLETED if prefs.date_locale == 'en_US' else icons.TASK ) workflow().add_item( 'Require explicit due keyword', 'Requires the due keyword to avoid accidental due date extraction', arg='-pref explicit_keywords', valid=True, icon=icons.TASK_COMPLETED if prefs.explicit_keywords else icons.TASK ) workflow().add_item( 'Check for experimental updates to this workflow', 'The workflow automatically checks for updates; enable this to include pre-releases', arg=':pref prerelease_channel', valid=True, icon=icons.TASK_COMPLETED if prefs.prerelease_channel else icons.TASK ) workflow().add_item( 'Force sync', 'The workflow syncs automatically, but feel free to be forcible.', arg='-pref sync', valid=True, icon=icons.SYNC ) workflow().add_item( 'Switch theme', 'Toggle between light and dark icons', arg='-pref retheme', valid=True, icon=icons.PAINTBRUSH ) workflow().add_item( 'Main menu', autocomplete='', icon=icons.BACK )
def commit(args, modifier=None): prefs = Preferences.current_prefs() relaunch_command = '-pref' if '--alfred' in args: relaunch_command = ' '.join(args[args.index('--alfred') + 1:]) if 'sync' in args: from wunderlist.sync import sync sync('background' in args) relaunch_command = None elif 'show_completed_tasks' in args: prefs.show_completed_tasks = not prefs.show_completed_tasks if prefs.show_completed_tasks: print 'Completed tasks are now visible in the workflow' else: print 'Completed tasks will not be visible in the workflow' elif 'default_list' in args: default_list_id = None lists = workflow().stored_data('lists') if len(args) > 2: default_list_id = int(args[2]) prefs.default_list_id = default_list_id if default_list_id: default_list_name = next((l['title'] for l in lists if l['id'] == default_list_id), 'Inbox') print 'Tasks will be added to your %s list by default' % default_list_name else: print 'Tasks will be added to the Inbox by default' elif 'explicit_keywords' in args: prefs.explicit_keywords = not prefs.explicit_keywords if prefs.explicit_keywords: print 'Remember to use the "due" keyword' else: print 'Implicit due dates enabled (e.g. "Recycling tomorrow")' elif 'reminder' in args: reminder_time = _parse_time(' '.join(args)) if reminder_time is not None: prefs.reminder_time = reminder_time print 'Reminders will now default to %s' % format_time(reminder_time, 'short') elif 'reminder_today' in args: reminder_today_offset = None if not 'disabled' in args: reminder_today_offset = _parse_time(' '.join(args)) prefs.reminder_today_offset = reminder_today_offset print 'The offset for current-day reminders is now %s' % _format_time_offset(reminder_today_offset) elif 'automatic_reminders' in args: prefs.automatic_reminders = not prefs.automatic_reminders if prefs.automatic_reminders: print 'A reminder will automatically be set for due tasks' else: print 'A reminder will not be added automatically' elif 'retheme' in args: prefs.icon_theme = 'light' if icons.icon_theme() == 'dark' else 'dark' print 'The workflow is now using the %s icon theme' % (prefs.icon_theme) elif 'prerelease_channel' in args: prefs.prerelease_channel = not prefs.prerelease_channel # Update the workflow settings and reverify the update data workflow().check_update(True) if prefs.prerelease_channel: print 'The workflow will prompt you to update to experimental pre-releases' else: print 'The workflow will only prompt you to update to final releases' elif 'force_en_US' in args: if prefs.date_locale: prefs.date_locale = None print 'The workflow will expect your local language and date format' else: prefs.date_locale = 'en_US' print 'The workflow will expect dates in US English' if relaunch_command: relaunch_alfred('wl%s' % relaunch_command)