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.4KB

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