Somewhat fancy voice command recognition software
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

GtkTrayUI.py 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import sys
  2. import gobject
  3. import pygtk
  4. import gtk
  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.status_icon_position_menu, button, time, item)
  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 )