1
0
mirror of https://github.com/Luzifer/password.git synced 2024-09-20 02:42:57 +00:00
password/alfred-workflow/feedback.py
Knut Ahlers f54a262ded
Include workflow building into build process
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-09-22 16:25:25 +02:00

48 lines
1.5 KiB
Python
Executable File

#author: Peter Okma
import xml.etree.ElementTree as et
class Feedback():
"""Feeback used by Alfred Script Filter
Usage:
fb = Feedback()
fb.add_item('Hello', 'World')
fb.add_item('Foo', 'Bar')
print fb
"""
def __init__(self):
self.feedback = et.Element('items')
def __repr__(self):
"""XML representation used by Alfred
Returns:
XML string
"""
return et.tostring(self.feedback)
def add_item(self, title, subtitle="", arg="", valid="yes", autocomplete="", icon="icon.png"):
"""
Add item to alfred Feedback
Args:
title(str): the title displayed by Alfred
Keyword Args:
subtitle(str): the subtitle displayed by Alfred
arg(str): the value returned by alfred when item is selected
valid(str): whether or not the entry can be selected in Alfred to trigger an action
autcomplete(str): the text to be inserted if an invalid item is selected. This is only used if 'valid' is 'no'
icon(str): filename of icon that Alfred will display
"""
item = et.SubElement(self.feedback, 'item', uid=str(len(self.feedback)),
arg=arg, valid=valid, autocomplete=autocomplete)
_title = et.SubElement(item, 'title')
_title.text = title
_sub = et.SubElement(item, 'subtitle')
_sub.text = subtitle
_icon = et.SubElement(item, 'icon')
_icon.text = icon