Somewhat fancy voice command recognition software
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

GtkUI.py 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #This is part of Blather
  2. # -- this code is licensed GPLv3
  3. # Copyright 2013 Jezra
  4. import sys
  5. import gobject
  6. #Gtk
  7. import pygtk
  8. import gtk
  9. class UI(gobject.GObject):
  10. __gsignals__ = {
  11. 'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
  12. }
  13. def __init__(self,args, continuous):
  14. gobject.GObject.__init__(self)
  15. self.continuous = continuous
  16. #make a window
  17. self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  18. self.window.connect("delete_event", self.delete_event)
  19. #give the window a name
  20. self.window.set_title("BlatherGtk")
  21. self.window.set_resizable(False)
  22. layout = gtk.VBox()
  23. self.window.add(layout)
  24. #make a listen/stop button
  25. self.lsbutton = gtk.Button("Listen")
  26. layout.add(self.lsbutton)
  27. #make a continuous button
  28. self.ccheckbox = gtk.CheckButton("Continuous Listen")
  29. layout.add(self.ccheckbox)
  30. #connect the buttons
  31. self.lsbutton.connect("clicked",self.lsbutton_clicked)
  32. self.ccheckbox.connect("clicked",self.ccheckbox_clicked)
  33. #add a label to the UI to display the last command
  34. self.label = gtk.Label()
  35. layout.add(self.label)
  36. #create an accellerator group for this window
  37. accel = gtk.AccelGroup()
  38. #add the ctrl+q to quit
  39. accel.connect_group(gtk.keysyms.q, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE, self.accel_quit )
  40. #lock the group
  41. accel.lock()
  42. #add the group to the window
  43. self.window.add_accel_group(accel)
  44. def ccheckbox_clicked(self, widget):
  45. checked = self.ccheckbox.get_active()
  46. self.lsbutton.set_sensitive(not checked)
  47. if checked:
  48. self.lsbutton_stopped()
  49. self.emit('command', "continuous_listen")
  50. self.set_icon_active()
  51. else:
  52. self.emit('command', "continuous_stop")
  53. self.set_icon_inactive()
  54. def lsbutton_stopped(self):
  55. self.lsbutton.set_label("Listen")
  56. def lsbutton_clicked(self, button):
  57. val = self.lsbutton.get_label()
  58. if val == "Listen":
  59. self.emit("command", "listen")
  60. self.lsbutton.set_label("Stop")
  61. #clear the label
  62. self.label.set_text("")
  63. self.set_icon_active()
  64. else:
  65. self.lsbutton_stopped()
  66. self.emit("command", "stop")
  67. self.set_icon_inactive()
  68. def run(self):
  69. #set the default icon
  70. self.set_icon_inactive()
  71. self.window.show_all()
  72. if self.continuous:
  73. self.set_icon_active()
  74. self.ccheckbox.set_active(True)
  75. def accel_quit(self, accel_group, acceleratable, keyval, modifier):
  76. self.emit("command", "quit")
  77. def delete_event(self, x, y ):
  78. self.emit("command", "quit")
  79. def finished(self, text):
  80. #if the continuous isn't pressed
  81. if not self.ccheckbox.get_active():
  82. self.lsbutton_stopped()
  83. self.set_icon_inactive()
  84. self.label.set_text(text)
  85. def set_icon_active_asset(self, i):
  86. self.icon_active = i
  87. def set_icon_inactive_asset(self, i):
  88. self.icon_inactive = i
  89. def set_icon_active(self):
  90. gtk.window_set_default_icon_from_file(self.icon_active)
  91. def set_icon_inactive(self):
  92. gtk.window_set_default_icon_from_file(self.icon_inactive)