Browse Source

Implemented -i flag to select UI and -c flag to start UI in 'continuous listen' mode

giggity
Jezra 11 years ago
parent
commit
bb744e1556
4 changed files with 42 additions and 15 deletions
  1. 23
    9
      Blather.py
  2. 5
    2
      GtkUI.py
  3. 5
    1
      QtUI.py
  4. 9
    3
      README

+ 23
- 9
Blather.py View File

8
 import gobject
8
 import gobject
9
 import os.path
9
 import os.path
10
 import subprocess
10
 import subprocess
11
-from Recognizer import Recognizer
11
+from optparse import OptionParser
12
+
12
 
13
 
13
 #where are the files?
14
 #where are the files?
14
 conf_dir = os.path.expanduser("~/.config/blather")
15
 conf_dir = os.path.expanduser("~/.config/blather")
22
 	os.makedirs(lang_dir)
23
 	os.makedirs(lang_dir)
23
 
24
 
24
 class Blather:
25
 class Blather:
25
-	def __init__(self, args):
26
+	def __init__(self, opts):
27
+		#import the recognizer so Gst doesn't clobber our -h
28
+		from Recognizer import Recognizer
26
 		self.ui = None
29
 		self.ui = None
30
+		ui_continuous_listen = False
27
 		self.continuous_listen = False
31
 		self.continuous_listen = False
28
 		self.commands = {}
32
 		self.commands = {}
29
 		self.read_commands()
33
 		self.read_commands()
30
 		self.recognizer = Recognizer(lang_file, dic_file)
34
 		self.recognizer = Recognizer(lang_file, dic_file)
31
 		self.recognizer.connect('finished',self.recognizer_finished)
35
 		self.recognizer.connect('finished',self.recognizer_finished)
32
-		#is there an arg?
33
-		if len(args) > 1:
34
-			if args[1] == "-qt":
36
+		
37
+		if opts.interface != None:
38
+			if opts.interface == "q":
35
 				#import the ui from qt
39
 				#import the ui from qt
36
 				from QtUI import UI
40
 				from QtUI import UI
37
-			elif args[1] == "-gtk":
41
+			elif opts.interface == "g":
38
 				from GtkUI import UI
42
 				from GtkUI import UI
39
 			else:
43
 			else:
40
 				print "no GUI defined"
44
 				print "no GUI defined"
41
 				sys.exit()
45
 				sys.exit()
42
-			self.ui = UI(args)
46
+				
47
+			self.ui = UI(args,opts.continuous)
43
 			self.ui.connect("command", self.process_command)
48
 			self.ui.connect("command", self.process_command)
44
-
49
+					
45
 	def read_commands(self):
50
 	def read_commands(self):
46
 		#read the.commands file
51
 		#read the.commands file
47
 		file_lines = open(command_file)
52
 		file_lines = open(command_file)
105
 			self.quit()
110
 			self.quit()
106
 		
111
 		
107
 if __name__ == "__main__":
112
 if __name__ == "__main__":
113
+	parser = OptionParser()
114
+	parser.add_option("-i", "--interface",  type="string", dest="interface",
115
+		action='store',
116
+		help="Interface to use (if any). 'q' for Qt, 'g' for GTK")
117
+	parser.add_option("-c", "--continuous",
118
+		action="store_true", dest="continuous", default=False,
119
+		help="starts interface with 'continuous' listen enabled")
120
+
121
+	(options, args) = parser.parse_args()
108
 	#make our blather object
122
 	#make our blather object
109
-	blather = Blather(sys.argv)
123
+	blather = Blather(options)
110
 	#init gobject threads
124
 	#init gobject threads
111
 	gobject.threads_init()
125
 	gobject.threads_init()
112
 	#we want a main loop
126
 	#we want a main loop

+ 5
- 2
GtkUI.py View File

12
 		'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
12
 		'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
13
 	}
13
 	}
14
 	
14
 	
15
-	def __init__(self,args):
15
+	def __init__(self,args, continuous):
16
 		gobject.GObject.__init__(self)
16
 		gobject.GObject.__init__(self)
17
+		self.continuous = continuous
17
 		#make a window
18
 		#make a window
18
 		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
19
 		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
19
 		self.window.connect("delete_event", self.delete_event)
20
 		self.window.connect("delete_event", self.delete_event)
37
 		#add a label to the UI to display the last command
38
 		#add a label to the UI to display the last command
38
 		self.label = gtk.Label()
39
 		self.label = gtk.Label()
39
 		layout.add(self.label)
40
 		layout.add(self.label)
40
-	
41
+
41
 	def ccheckbox_clicked(self, widget):
42
 	def ccheckbox_clicked(self, widget):
42
 		checked = self.ccheckbox.get_active()
43
 		checked = self.ccheckbox.get_active()
43
 		self.lsbutton.set_sensitive(not checked)
44
 		self.lsbutton.set_sensitive(not checked)
63
 			
64
 			
64
 	def run(self):
65
 	def run(self):
65
 		self.window.show_all()
66
 		self.window.show_all()
67
+		if self.continuous:
68
+			self.ccheckbox.set_active(True)
66
 	
69
 	
67
 	def quit(self):
70
 	def quit(self):
68
 		pass
71
 		pass

+ 5
- 1
QtUI.py View File

13
 		'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
13
 		'command' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING,))
14
 	}
14
 	}
15
 	
15
 	
16
-	def __init__(self,args):
16
+	def __init__(self,args,continuous):
17
+		self.continuous = continuous
17
 		gobject.GObject.__init__(self)
18
 		gobject.GObject.__init__(self)
18
 		#start by making our app
19
 		#start by making our app
19
 		self.app = QApplication(args)
20
 		self.app = QApplication(args)
69
 			
70
 			
70
 	def run(self):
71
 	def run(self):
71
 		self.window.show()
72
 		self.window.show()
73
+		if self.continuous:
74
+			self.ccheckbox.setCheckState(Qt.Checked)
75
+			self.ccheckbox_clicked()
72
 		self.app.exec_()
76
 		self.app.exec_()
73
 		self.emit("command", "quit")
77
 		self.emit("command", "quit")
74
 	
78
 	

+ 9
- 3
README View File

15
 4. download the resulting XXXX.lm file to the ~/.config/blather/language directory and rename to file to 'lm'
15
 4. download the resulting XXXX.lm file to the ~/.config/blather/language directory and rename to file to 'lm'
16
 5. download the resulting XXXX.dic file to the ~/.config/blather/language directory and rename to file to 'dic'
16
 5. download the resulting XXXX.dic file to the ~/.config/blather/language directory and rename to file to 'dic'
17
 6. run Blather.py
17
 6. run Blather.py
18
-    * for Qt GUI, run Blather.py -qt
19
-    * for Gtk GUI, run Blather.py -gtk
18
+    * for Qt GUI, run Blather.py -i q
19
+    * for Gtk GUI, run Blather.py -i g
20
+    * to start a UI in 'continuous' listen mode, use the -c flag  
21
+
20
 7. start talking
22
 7. start talking
21
 
23
 
22
 ####Bonus
24
 ####Bonus
23
-once the sentences.corpus file has been created, run the language_updater.sh script to automate the process of creating and downloading language files.
25
+once the sentences.corpus file has been created, run the language_updater.sh script to automate the process of creating and downloading language files.
26
+
27
+**Example**  
28
+To run blather with the GTK UI and start in continuous listen mode:   
29
+./Blather.py -i g -c

Loading…
Cancel
Save