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 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. def __init__(self,args, continuous):
  14. GObject.GObject.__init__(self)
  15. self.continuous = continuous
  16. # Make a window
  17. self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
  18. self.window.connect("delete_event", self.delete_event)
  19. # Give the window a name
  20. self.window.set_title("Kaylee")
  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(Gdk.keyval_from_name('q'), Gdk.ModifierType.CONTROL_MASK,
  40. Gtk.AccelFlags.VISIBLE, self.accel_quit)
  41. # Lock the group
  42. accel.lock()
  43. # Add the group to the window
  44. self.window.add_accel_group(accel)
  45. def ccheckbox_clicked(self, widget):
  46. checked = self.ccheckbox.get_active()
  47. self.lsbutton.set_sensitive(not checked)
  48. if checked:
  49. self.lsbutton_stopped()
  50. self.emit('command', "continuous_listen")
  51. self.set_icon_active()
  52. else:
  53. self.emit('command', "continuous_stop")
  54. self.set_icon_inactive()
  55. def lsbutton_stopped(self):
  56. self.lsbutton.set_label("Listen")
  57. def lsbutton_clicked(self, button):
  58. val = self.lsbutton.get_label()
  59. if val == "Listen":
  60. self.emit("command", "listen")
  61. self.lsbutton.set_label("Stop")
  62. # Clear the label
  63. self.label.set_text("")
  64. self.set_icon_active()
  65. else:
  66. self.lsbutton_stopped()
  67. self.emit("command", "stop")
  68. self.set_icon_inactive()
  69. def run(self):
  70. # Set the default icon
  71. self.set_icon_inactive()
  72. self.window.show_all()
  73. if self.continuous:
  74. self.set_icon_active()
  75. self.ccheckbox.set_active(True)
  76. def accel_quit(self, accel_group, acceleratable, keyval, modifier):
  77. self.emit("command", "quit")
  78. def delete_event(self, x, y):
  79. self.emit("command", "quit")
  80. def finished(self, text):
  81. # If the continuous isn't pressed
  82. if not self.ccheckbox.get_active():
  83. self.lsbutton_stopped()
  84. self.set_icon_inactive()
  85. self.label.set_text(text)
  86. def set_icon_active_asset(self, i):
  87. self.icon_active = i
  88. def set_icon_inactive_asset(self, i):
  89. self.icon_inactive = i
  90. def set_icon_active(self):
  91. Gtk.Window.set_default_icon_from_file(self.icon_active)
  92. def set_icon_inactive(self):
  93. Gtk.Window.set_default_icon_from_file(self.icon_inactive)