forked from teranex/kupfer-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguake.py
79 lines (60 loc) · 2.41 KB
/
guake.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
__kupfer_name__ = _("Guake")
__kupfer_actions__ = ("RunInCurrentTab", "RunInNewTab",)
__description__ = _("Execute commands in Guake")
__version__ = ""
__author__ = "Jeroen Budts"
import dbus
from kupfer import plugin_support, pretty, icons
from kupfer.objects import Action, TextLeaf, FileLeaf
from kupfer.obj.fileactions import is_good_executable
from gio.unix import DesktopAppInfo
from gio import FileIcon, File
plugin_support.check_dbus_connection()
def get_guake():
try:
bus = dbus.SessionBus()
dbusObj = bus.get_object('org.guake.RemoteControl', '/org/guake/RemoteControl')
return dbus.Interface(dbusObj, dbus_interface='org.guake.RemoteControl')
except dbus.exceptions.DBusException, err:
pretty.print_debug(err)
return None
class RunInCurrentTab (Action):
def __init__(self):
Action.__init__(self, _("Run in current Guake tab"))
def get_description(self):
return _("Run the command in the currently active Guake tab")
def get_gicon(self):
# TODO: this is probably not how it should be done...
return FileIcon(File('/usr/share/pixmaps/guake/guake.svg'))
# return DesktopAppInfo('guake.desktop').get_icon()
def activate(self, leaf):
get_guake().execute_command(leaf.object)
def item_types(self):
yield FileLeaf
yield TextLeaf
def valid_for_item(self, item):
if isinstance(item, FileLeaf):
return not item.is_dir() and item.is_valid() and is_good_executable(item)
return True
class RunInNewTab (Action):
def __init__(self):
Action.__init__(self, _("Run in new Guake tab"))
def get_description(self):
return _("Run the command in a new Guake tab")
# def get_gicon(self):
# TODO: this is probably not how it should be done...
# guake_icon = FileIcon(File('/usr/share/pixmaps/guake/guake.svg'))
# guake_icon = DesktopAppInfo('guake.desktop').get_icon()
# return icons.ComposedIconSmall(guake_icon, "add")
def get_icon_name(self):
return "add"
def activate(self, leaf):
get_guake().add_tab('~')
get_guake().execute_command(leaf.object)
def item_types(self):
yield FileLeaf
yield TextLeaf
def valid_for_item(self, item):
if isinstance(item, FileLeaf):
return not item.is_dir() and item.is_valid() and is_good_executable(item)
return True