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

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