-
Notifications
You must be signed in to change notification settings - Fork 1
/
hotot.py
84 lines (60 loc) · 2.18 KB
/
hotot.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
__kupfer_name__ = _("Hotot")
__kupfer_actions__ = ("SendUpdate", "Show", "Quit", )
__description__ = _("Control Hotot")
__version__ = ""
__author__ = "Jeroen Budts"
import dbus
from kupfer.objects import Action, TextLeaf, AppLeaf
from kupfer import pretty, plugin_support, launch
plugin_support.check_dbus_connection()
def get_hotot():
try:
bus = dbus.SessionBus()
dbusObj = bus.get_object('org.hotot.service', '/org/hotot/service')
return dbus.Interface(dbusObj, dbus_interface='org.hotot.service')
except dbus.exceptions.DBusException, err:
pretty.print_debug(err)
return None
class SendUpdate (Action):
''' Create a Tweet with Hotot '''
def __init__(self):
Action.__init__(self, _("Send Update"))
def activate(self, leaf):
pretty.print_debug(__name__, leaf.object)
text = leaf.object.replace('"', '\\"')
pretty.print_debug(__name__, "SendUpdate: "+text)
get_hotot().update_status(text)
def item_types(self):
yield TextLeaf
def get_description(self):
return _("Send an update to Twitter with Hotot")
def get_icon_name(self):
return 'hotot'
def valid_for_item(self, item):
return get_hotot() != None
class HototAction (Action):
def __init__(self, action, func):
self.action = action
self.func = func
Action.__init__(self, _(action))
def get_description(self):
return _(self.action + ' the running Hotot instance')
def activate(self, leaf):
self.func()
def item_types(self):
yield AppLeaf
def valid_for_item(self, item):
return item.get_id() == 'hotot' and get_hotot() != None
class Show (HototAction):
def __init__(self):
HototAction.__init__(self, 'Show', lambda: get_hotot().show())
def get_icon_name(self):
return "go-jump"
def valid_for_item(self, item):
return super(Show, self).valid_for_item(item) \
and not launch.application_is_running('hotot')
class Quit (HototAction):
def __init__(self):
HototAction.__init__(self, 'Quit', lambda: get_hotot().quit())
def get_icon_name(self):
return "application-exit"