Esempio n. 1
0
def copy_todo_to_clipboard(_id):
    todo = datastore.instance.get_todo(_id)
    title = todo['title']
    tag = todo['group']
    helpers.macSetClipboard(title)
    config.update_state(command='copy_to_clipboard', tag='#'+tag)
    print ("Copied '" + title + "' to the clipboard").encode('utf-8')
Esempio n. 2
0
def save_todo(raw_task, silent=False):
	info = parser.parse(raw_task)
	tag = info['tag']
	task = info['task']
	pinned = info['pinned']
	rating = info['rating']

	if len(task) == 0:
		return
	if tag is None:
		tag = 'default'

	todos = get_todo_list()
	newtodo = { 
		'title' : task, 
		'created' : datetime.now(), 
		'id' : uuid4(), 
		'group' : tag,
		'pinned' : pinned,
		'rating' : rating
	}
	todos.append ( newtodo )
	save_todo_list(todos)
	if not silent:
		if tag != 'default':
			print "Added '{0}' tagged #{1}".format(task, tag)		
		else:
			print "Added '{0}'".format(task)
	config.update_state(command='add_todo', tag='#'+tag)
Esempio n. 3
0
def generate_view(query):
	if len(query) == 0  and config.get('todo.command.last') == 'quick_create':
		add_query = config.get('todo.user.query')
		add_tag = config.get('todo.tag.recent')
		itemlist.save_todo(add_query,silent=True)
		config.update_state(command='', query='')

	info = parser.parse(query)
	tag = info['tag']
	q = info['task']
	
	todos = itemlist.get_todo_list()

	# view for pinned items
	# pinned items should have unique uuid and different logo
	pinned = [t for t in todos if itemlist.feature(t,'pinned') == True]
	pinned = [t for t in pinned if (tag is None or t['group'] == tag)]
	pinned = [t for t in pinned if (q is None or t['title'].lower().find(q.lower()) >= 0)] 
	pinned = pinned[::-1]
	# view for non-pinned items
	normal = [t for t in todos if itemlist.feature(t,'pinned') == False]
	normal = [t for t in normal if (tag is None or t['group'] == tag)]
	normal = [t for t in normal if (q is None or t['title'].lower().find(q.lower()) >= 0)] 
	normal = normal[::-1]

	feedback_items = []
	if len(normal) == 0 and len(pinned) == 0:
		feedback_items.append( generate_add_feedbackitem(query, info) )
	else:
		pinned = map(lambda x: generate_pinned_feedbackitem(x), pinned)
		normal = map(lambda x: generate_todo_feedbackitem(x), normal)
		feedback_items = pinned + normal
	
	alfred.write(alfred.xml(feedback_items))
Esempio n. 4
0
def save_todo(raw_task, silent=False):
    info = parser.parse(raw_task)
    tag = info['tag']
    task = info['task']
    pinned = info['pinned']
    rating = info['rating']

    if len(task) == 0:
        return
    if tag is None:
        tag = 'default'

    todos = get_todo_list()
    newtodo = {
        'title': task,
        'created': datetime.now(),
        'id': uuid4(),
        'group': tag,
        'pinned': pinned,
        'rating': rating
    }
    todos.append(newtodo)
    save_todo_list(todos)
    if not silent:
        if tag != 'default':
            print "Added '{0}' tagged #{1}".format(task, tag)
        else:
            print "Added '{0}'".format(task)
    config.update_state(command='add_todo', tag='#' + tag)
Esempio n. 5
0
def generate_view(query, entered_tag, info):
    feedback_items = []
    tags = itemlist.get_tags()

    # check if we have any tags
    if len(tags) == 0:
        feedback_items.append(default_no_tags())
        config.update_state(tag='#default')
    else:
        if entered_tag:
            feedback_items.append(itemview.generate_add_feedbackitem(query, info))
        sorted_tags = sorted(tags, key=lambda x: x)
        for tag in sorted_tags:
            if not entered_tag or tag.lower().find(entered_tag.lower()) >= 0:
                count = tags[tag]
                feedback_items.append(
                    alfred.Item(
                        attributes={
                            'uid': uuid4(),
                            'arg': helpers.encode_tag(tag),
                            'autocomplete': "#{0} ".format(tag),
                            'valid': 'yes'
                        },
                        title="#{0}".format(tag),
                        subtitle="{0} item{1}".format(count, ('' if count == 1 else 's')),
                        icon="todo_tag.png"
                    )
                )
    config.update_state(view='tag_view', command='display_tags')
    alfred.write(alfred.xml(feedback_items))
Esempio n. 6
0
def copy_todo_to_clipboard(_id):
    todo = get_todo(_id)
    title = todo['title']
    tag = todo['group']
    helpers.macSetClipboard(title)
    config.update_state(command='copy_to_clipboard', tag='#' + tag)
    print "Copied '{0}' to the clipboard".format(title)
Esempio n. 7
0
def copy_todo_to_clipboard(_id):
	todo = get_todo(_id)
	title = todo['title']
	tag = todo['group']
	helpers.macSetClipboard(title)
	config.update_state(command='copy_to_clipboard', tag='#'+tag)
	print "Copied '{0}' to the clipboard".format(title)
Esempio n. 8
0
def remove_tag(tag):
	todos = get_todo_list()
	if len(todos) > 0 and len(tag) > 0:
		toremove = [t for t in todos if t['group'] == tag]
		todos = [t for t in todos if t['group'] != tag]
		save_todo_list(todos)
		config.update_state(command='remove_tag', tag='#'+tag)
		print "Removed all items tagged #{2}".format(len(toremove), 'item' if len(toremove) == 1 else 'items', tag)
Esempio n. 9
0
def remove_tag(tag):
    todos = get_todo_list()
    if len(todos) > 0 and len(tag) > 0:
        toremove = [t for t in todos if t['group'] == tag]
        todos = [t for t in todos if t['group'] != tag]
        save_todo_list(todos)
        config.update_state(command='remove_tag', tag='#' + tag)
        print "Removed all items tagged #{2}".format(
            len(toremove), 'item' if len(toremove) == 1 else 'items', tag)
Esempio n. 10
0
def remove_todo(_id):
    todos = get_todo_list()
    if len(todos) > 0 and len(_id) > 0:
        toremove = [t for t in todos if str(t['id']) == _id]
        todos = [t for t in todos if str(t['id']) != _id]
        save_todo_list(todos)
        tag = toremove[0]['group']
        config.update_state(command='remove_todo', tag='#' + tag)
        print "Removed '{0}'".format(toremove[0]['title'])
Esempio n. 11
0
def remove_todo(_id):
	todos = get_todo_list()
	if len(todos) > 0 and len(_id) > 0:
		toremove = [t for t in todos if str(t['id']) == _id]
		todos = [t for t in todos if str(t['id']) != _id]
		save_todo_list(todos)
		tag = toremove[0]['group']
		config.update_state(command='remove_todo', tag='#'+tag)
		print "Removed '{0}'".format(toremove[0]['title'])
Esempio n. 12
0
def retrieve_and_store_tag(item):
	tag = 'default'
	if helpers.is_tag(item):
		tag = helpers.extract_tag(item)
	else:
		_id = helpers.extract_todo_id(item)
		todos = get_todo_list()
		target = [t for t in todos if str(t['id']) == _id]
		tag = target[0]['group']
 	config.update_state(command='retrieve_tag', tag='#'+tag)
Esempio n. 13
0
def retrieve_and_store_tag(item):
    tag = 'default'
    if helpers.is_tag(item):
        tag = helpers.extract_tag(item)
    else:
        _id = helpers.extract_todo_id(item)
        todos = get_todo_list()
        target = [t for t in todos if str(t['id']) == _id]
        tag = target[0]['group']
    config.update_state(command='retrieve_tag', tag='#' + tag)
Esempio n. 14
0
def generate_add_feedbackitem(query, info):
	q = info['task']
	tag = info['tag']

	title = "New item '" + ('...' if len(q)==0 else q) + "'"
	subtitle = "Type something to create a new todo"

	if tag is None:
		tag = 'default'
	if tag != 'default':
		subtitle = "Item will be tagged #{0}".format(tag)

	# quick create only works best in default list mode
	quick_create = False
	if len(q) > 0 and tag == 'default':
		config.update_state(command='quick_create', tag='#'+tag, query=query)
		quick_create = True
	else:
		config.update_state(command='', tag='', query='')


	if quick_create:
		return alfred.Item(
			attributes = { 
			'uid' : uuid4(),
			'arg' : '#' + tag + ' ' + q,
			'valid' : 'no',
			'autocomplete' : ''
			},
			title = title,
			subtitle = subtitle,
			icon = "todo_add.png"
		)
	else:
		return alfred.Item(
			attributes = { 
			'uid' : uuid4(),
			'arg' : '#' + tag + ' ' + q,
			'valid' : 'no' if len(q) == 0 else 'yes',
			'autocomplete' : '' if len(q) > 0 else '#' + tag + ' '
			},
			title = title,
			subtitle = subtitle,
			icon = "todo_add.png"
		)
Esempio n. 15
0
def save_todo(raw_task, silent=False):
    newtodo = parse_todo_text(raw_task)
    task = newtodo['title']
    tag = newtodo['group']
    if len(task) == 0:
        return

    smartcontent.process_todo(newtodo)
    datastore.instance.save_todo(newtodo)

    if not silent:
        if tag != 'default':
            print ("Added '" + task + "' tagged #" + tag).encode('utf-8')
        else:
            print ("Added '" + task + "'").encode('utf-8')

    config.put(ck.KEY_USER_QUERY_NOITEMPREFIX, '')
    config.update_state(command='add_todo', tag='#'+tag)
Esempio n. 16
0
def generate_view():
    feedback_items = []
    tags = itemlist.get_tags()
    for tag, items in tags.items():
        feedback_items.append(
            alfred.Item(attributes={
                'uid': alfred.uid(tag),
                'arg': helpers.encode_tag(tag),
                'autocomplete': "#{0} ".format(tag),
                'valid': 'yes'
            },
                        title="#{0}".format(tag),
                        subtitle="Tag matches {0} item{1}".format(
                            len(items), ('' if len(items) == 1 else 's')),
                        icon="todo_tag.png"))
    if len(feedback_items) == 0:
        feedback_items.append(default_no_tags())
        config.update_state(tag='#default')
    config.update_state(view='tag_view', command='display_tags')
    alfred.write(alfred.xml(feedback_items))
Esempio n. 17
0
def generate_view():
	feedback_items = []
	tags = itemlist.get_tags()
	for tag,items in tags.items():
		feedback_items.append(
			alfred.Item(
				attributes = { 
				'uid' : alfred.uid(tag),
				'arg' : helpers.encode_tag(tag),
				'autocomplete' : "#{0} ".format(tag),
				'valid' : 'yes'
				},
				title = "#{0}".format(tag),
				subtitle = "Tag matches {0} item{1}".format(len(items), ('' if len(items) == 1 else 's')),
				icon = "todo_tag.png"
			)
		)
	if len(feedback_items) == 0:
		feedback_items.append(default_no_tags())
		config.update_state(tag='#default')	
	config.update_state(view='tag_view',command='display_tags')
	alfred.write(alfred.xml(feedback_items))
Esempio n. 18
0
def clear_todos():
    todo_db = config.get('todo.db')
    if (os.path.exists(todo_db)):
        os.remove(todo_db)
    config.update_state(command='clear_todos')
Esempio n. 19
0
def clear_todos():
	todo_db = config.get('todo.db')
	if ( os.path.exists( todo_db ) ):
		os.remove( todo_db )
	config.update_state(command='clear_todos')
Esempio n. 20
0
def toggle_pinned(_id):
    todo = get_todo(_id)
    toggle = False if feature(todo, 'pinned') else True
    update_todo(_id, {'pinned': toggle})
    config.update_state(command='toggle_pinned', tag='#' + todo['group'])
Esempio n. 21
0
def remove_todo(_id):
    removed = datastore.instance.remove_todo(_id)
    config.update_state(command='remove_todo', tag='#'+removed['group'])
    print ("Removed '" + removed['title'] + "'").encode('utf-8')
Esempio n. 22
0
def clear_todos(done=False):
    todos = datastore.instance.get_todo_list()
    todos = [t for t in todos if feature(t, 'done') != done]
    datastore.instance.save_todo_list(todos)
    config.update_state(command='clear_todos')
Esempio n. 23
0
def toggle_done(_id):
    todo = get_todo(_id)
    toggle = False if feature(todo, 'done') else True
    update_todo(_id, {'done': toggle, 'done_when': datetime.now()})
    config.update_state(command='toggle_done', tag='#'+todo['group'])
Esempio n. 24
0
def remove_tag(tag):
    datastore.instance.remove_tag(tag)
    config.update_state(command='remove_tag', tag='#'+tag)
    print ("Removed all items tagged #" + tag).encode('utf-8')
Esempio n. 25
0
def copy_text_to_clipboard(text):
    helpers.macSetClipboard(text)
    config.update_state(command='copy_to_clipboard')
    print ("Copied '" + title + "' to the clipboard").encode('utf-8')
Esempio n. 26
0
def clear_all_todos():
    datastore.instance.clear_all_todos()
    config.update_state(command='clear_todos')
Esempio n. 27
0
def toggle_pinned(_id):
	todo = get_todo(_id)
	toggle = False if feature(todo,'pinned') else True
	update_todo(_id, {'pinned':toggle})
	config.update_state(command='toggle_pinned',tag='#'+todo['group'])
Esempio n. 28
0
def open_url(content):
    config.update_state(command='open_url')
    call(['open', content])