Somewhat fancy voice command recognition software
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gtktrayui.py 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # This is part of Kaylee
  2. # -- this code is licensed GPLv3
  3. # Copyright 2015-2016 Clayton G. Hobbs
  4. # Portions Copyright 2013 Jezra
  5. import sys
  6. import gi
  7. from gi.repository import GObject
  8. # Gtk
  9. gi.require_version('Gtk', '3.0')
  10. from gi.repository import Gtk, Gdk
  11. class UI(GObject.GObject):
  12. __gsignals__ = {
  13. 'command' : (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,))
  14. }
  15. idle_text = "Kaylee - Idle"
  16. listening_text = "Kaylee - Listening"
  17. def __init__(self, args, continuous):
  18. GObject.GObject.__init__(self)
  19. self.continuous = continuous
  20. self.statusicon = Gtk.StatusIcon()
  21. self.statusicon.set_title("Kaylee")
  22. self.statusicon.set_name("Kaylee")
  23. self.statusicon.set_tooltip_text(self.idle_text)
  24. self.statusicon.set_has_tooltip(True)
  25. self.statusicon.connect("activate", self.continuous_toggle)
  26. self.statusicon.connect("popup-menu", self.popup_menu)
  27. self.menu = Gtk.Menu()
  28. self.menu_listen = Gtk.MenuItem('Listen')
  29. self.menu_continuous = Gtk.CheckMenuItem('Continuous')
  30. self.menu_quit = Gtk.MenuItem('Quit')
  31. self.menu.append(self.menu_listen)
  32. self.menu.append(self.menu_continuous)
  33. self.menu.append(self.menu_quit)
  34. self.menu_listen.connect("activate", self.toggle_listen)
  35. self.menu_continuous.connect("toggled", self.toggle_continuous)
  36. self.menu_quit.connect("activate", self.quit)
  37. self.menu.show_all()
  38. def continuous_toggle(self, item):
  39. checked = self.menu_continuous.get_active()
  40. self.menu_continuous.set_active(not checked)
  41. def toggle_continuous(self, item):
  42. checked = self.menu_continuous.get_active()
  43. self.menu_listen.set_sensitive(not checked)
  44. if checked:
  45. self.menu_listen.set_label("Listen")
  46. self.emit('command', "continuous_listen")
  47. self.statusicon.set_tooltip_text(self.listening_text)
  48. self.set_icon_active()
  49. else:
  50. self.set_icon_inactive()
  51. self.statusicon.set_tooltip_text(self.idle_text)
  52. self.emit('command', "continuous_stop")
  53. def toggle_listen(self, item):
  54. val = self.menu_listen.get_label()
  55. if val == "Listen":
  56. self.set_icon_active()
  57. self.emit("command", "listen")
  58. self.menu_listen.set_label("Stop")
  59. self.statusicon.set_tooltip_text(self.listening_text)
  60. else:
  61. self.set_icon_inactive()
  62. self.menu_listen.set_label("Listen")
  63. self.emit("command", "stop")
  64. self.statusicon.set_tooltip_text(self.idle_text)
  65. def popup_menu(self, item, button, time):
  66. self.menu.popup(None, None, Gtk.StatusIcon.position_menu, item, button, time)
  67. def run(self):
  68. # Set the icon
  69. self.set_icon_inactive()
  70. if self.continuous:
  71. self.menu_continuous.set_active(True)
  72. self.set_icon_active()
  73. else:
  74. self.menu_continuous.set_active(False)
  75. self.statusicon.set_visible(True)
  76. def quit(self, item):
  77. self.statusicon.set_visible(False)
  78. self.emit("command", "quit")
  79. def finished(self, text):
  80. if not self.menu_continuous.get_active():
  81. self.menu_listen.set_label("Listen")
  82. self.set_icon_inactive()
  83. self.statusicon.set_tooltip_text(self.idle_text)
  84. def set_icon_active_asset(self, i):
  85. self.icon_active = i
  86. def set_icon_inactive_asset(self, i):
  87. self.icon_inactive = i
  88. def set_icon_active(self):
  89. self.statusicon.set_from_file(self.icon_active)
  90. def set_icon_inactive(self):
  91. self.statusicon.set_from_file(self.icon_inactive)