|
@@ -11,104 +11,6 @@ gi.require_version('Gtk', '3.0')
|
11
|
11
|
from gi.repository import Gtk, Gdk
|
12
|
12
|
|
13
|
13
|
|
14
|
|
-class GTKTrayInterface(GObject.GObject):
|
15
|
|
- __gsignals__ = {
|
16
|
|
- 'command' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
|
17
|
|
- (GObject.TYPE_STRING,))
|
18
|
|
- }
|
19
|
|
- idle_text = "Kaylee - Idle"
|
20
|
|
- listening_text = "Kaylee - Listening"
|
21
|
|
-
|
22
|
|
- def __init__(self, args, continuous):
|
23
|
|
- GObject.GObject.__init__(self)
|
24
|
|
- self.continuous = continuous
|
25
|
|
-
|
26
|
|
- self.statusicon = Gtk.StatusIcon()
|
27
|
|
- self.statusicon.set_title("Kaylee")
|
28
|
|
- self.statusicon.set_name("Kaylee")
|
29
|
|
- self.statusicon.set_tooltip_text(self.idle_text)
|
30
|
|
- self.statusicon.set_has_tooltip(True)
|
31
|
|
- self.statusicon.connect("activate", self.continuous_toggle)
|
32
|
|
- self.statusicon.connect("popup-menu", self.popup_menu)
|
33
|
|
-
|
34
|
|
- self.menu = Gtk.Menu()
|
35
|
|
- self.menu_listen = Gtk.MenuItem('Listen')
|
36
|
|
- self.menu_continuous = Gtk.CheckMenuItem('Continuous')
|
37
|
|
- self.menu_quit = Gtk.MenuItem('Quit')
|
38
|
|
- self.menu.append(self.menu_listen)
|
39
|
|
- self.menu.append(self.menu_continuous)
|
40
|
|
- self.menu.append(self.menu_quit)
|
41
|
|
- self.menu_listen.connect("activate", self.toggle_listen)
|
42
|
|
- self.menu_continuous.connect("toggled", self.toggle_continuous)
|
43
|
|
- self.menu_quit.connect("activate", self.quit)
|
44
|
|
- self.menu.show_all()
|
45
|
|
-
|
46
|
|
- def continuous_toggle(self, item):
|
47
|
|
- checked = self.menu_continuous.get_active()
|
48
|
|
- self.menu_continuous.set_active(not checked)
|
49
|
|
-
|
50
|
|
- def toggle_continuous(self, item):
|
51
|
|
- checked = self.menu_continuous.get_active()
|
52
|
|
- self.menu_listen.set_sensitive(not checked)
|
53
|
|
- if checked:
|
54
|
|
- self.menu_listen.set_label("Listen")
|
55
|
|
- self.emit('command', "continuous_listen")
|
56
|
|
- self.statusicon.set_tooltip_text(self.listening_text)
|
57
|
|
- self.set_icon_active()
|
58
|
|
- else:
|
59
|
|
- self.set_icon_inactive()
|
60
|
|
- self.statusicon.set_tooltip_text(self.idle_text)
|
61
|
|
- self.emit('command', "stop")
|
62
|
|
-
|
63
|
|
- def toggle_listen(self, item):
|
64
|
|
- val = self.menu_listen.get_label()
|
65
|
|
- if val == "Listen":
|
66
|
|
- self.set_icon_active()
|
67
|
|
- self.emit("command", "listen")
|
68
|
|
- self.menu_listen.set_label("Stop")
|
69
|
|
- self.statusicon.set_tooltip_text(self.listening_text)
|
70
|
|
- else:
|
71
|
|
- self.set_icon_inactive()
|
72
|
|
- self.menu_listen.set_label("Listen")
|
73
|
|
- self.emit("command", "stop")
|
74
|
|
- self.statusicon.set_tooltip_text(self.idle_text)
|
75
|
|
-
|
76
|
|
- def popup_menu(self, item, button, time):
|
77
|
|
- self.menu.popup(None, None, Gtk.StatusIcon.position_menu, item, button, time)
|
78
|
|
-
|
79
|
|
- def run(self):
|
80
|
|
- # Set the icon
|
81
|
|
- self.set_icon_inactive()
|
82
|
|
- if self.continuous:
|
83
|
|
- self.menu_continuous.set_active(True)
|
84
|
|
- self.set_icon_active()
|
85
|
|
- else:
|
86
|
|
- self.menu_continuous.set_active(False)
|
87
|
|
- self.statusicon.set_visible(True)
|
88
|
|
-
|
89
|
|
- def quit(self, item):
|
90
|
|
- self.statusicon.set_visible(False)
|
91
|
|
- self.emit("command", "quit")
|
92
|
|
-
|
93
|
|
- def finished(self, text):
|
94
|
|
- if not self.menu_continuous.get_active():
|
95
|
|
- self.menu_listen.set_label("Listen")
|
96
|
|
- self.set_icon_inactive()
|
97
|
|
- self.statusicon.set_tooltip_text(self.idle_text)
|
98
|
|
-
|
99
|
|
- def set_icon_active_asset(self, i):
|
100
|
|
- self.icon_active = i
|
101
|
|
-
|
102
|
|
- def set_icon_inactive_asset(self, i):
|
103
|
|
- self.icon_inactive = i
|
104
|
|
-
|
105
|
|
- def set_icon_active(self):
|
106
|
|
- self.statusicon.set_from_file(self.icon_active)
|
107
|
|
-
|
108
|
|
- def set_icon_inactive(self):
|
109
|
|
- self.statusicon.set_from_file(self.icon_inactive)
|
110
|
|
-
|
111
|
|
-
|
112
|
14
|
class GTKInterface(GObject.GObject):
|
113
|
15
|
__gsignals__ = {
|
114
|
16
|
'command': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
|