-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeedback.py
58 lines (48 loc) · 1.79 KB
/
Feedback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# author: Peter Okma
import xml.etree.ElementTree as et
class Feedback:
"""Feedback 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).decode('utf-8')
def add_item(self, title, subtitle="", arg="", valid="yes", autocomplete="", icon="icon.png"):
"""
Add item to alfred Feedback
Args:
@param title: the title displayed by Alfred
Keyword Args:
@param subtitle: the subtitle displayed by Alfred
@param arg: the value returned by alfred when item is selected
@param valid: whether the entry can be selected in Alfred to trigger an action
@param autocomplete: the text to be inserted if an invalid item is selected.
This is only used if 'valid' is 'no'
@param icon: 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
def isEmpty(self):
"""
判断是否为空
@return:
"""
if len(self.feedback.findall(path="./")) == 0:
return True
else:
return False