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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. else:
  51. self.emit('command', "continuous_stop")
  52. def lsbutton_stopped(self):
  53. self.lsbutton.set_label("Listen")
  54. def lsbutton_clicked(self, button):
  55. val = self.lsbutton.get_label()
  56. if val == "Listen":
  57. self.emit("command", "listen")
  58. self.lsbutton.set_label("Stop")
  59. #clear the label
  60. self.label.set_text("")
  61. else:
  62. self.lsbutton_stopped()
  63. self.emit("command", "stop")
  64. def run(self):
  65. self.window.show_all()
  66. if self.continuous:
  67. self.ccheckbox.set_active(True)
  68. def accel_quit(self, accel_group, acceleratable, keyval, modifier):
  69. self.emit("command", "quit")
  70. def delete_event(self, x, y ):
  71. self.emit("command", "quit")
  72. def finished(self, text):
  73. print text
  74. #if the continuous isn't pressed
  75. if not self.ccheckbox.get_active():
  76. self.lsbutton_stopped()
  77. self.label.set_text(text)
  78. def set_icon(self, icon):
  79. gtk.window_set_default_icon_from_file(icon)