|
@@ -8,7 +8,8 @@ import signal
|
8
|
8
|
import gobject
|
9
|
9
|
import os.path
|
10
|
10
|
import subprocess
|
11
|
|
-from Recognizer import Recognizer
|
|
11
|
+from optparse import OptionParser
|
|
12
|
+
|
12
|
13
|
|
13
|
14
|
#where are the files?
|
14
|
15
|
conf_dir = os.path.expanduser("~/.config/blather")
|
|
@@ -22,26 +23,30 @@ if not os.path.exists(lang_dir):
|
22
|
23
|
os.makedirs(lang_dir)
|
23
|
24
|
|
24
|
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
|
29
|
self.ui = None
|
|
30
|
+ ui_continuous_listen = False
|
27
|
31
|
self.continuous_listen = False
|
28
|
32
|
self.commands = {}
|
29
|
33
|
self.read_commands()
|
30
|
34
|
self.recognizer = Recognizer(lang_file, dic_file)
|
31
|
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
|
39
|
#import the ui from qt
|
36
|
40
|
from QtUI import UI
|
37
|
|
- elif args[1] == "-gtk":
|
|
41
|
+ elif opts.interface == "g":
|
38
|
42
|
from GtkUI import UI
|
39
|
43
|
else:
|
40
|
44
|
print "no GUI defined"
|
41
|
45
|
sys.exit()
|
42
|
|
- self.ui = UI(args)
|
|
46
|
+
|
|
47
|
+ self.ui = UI(args,opts.continuous)
|
43
|
48
|
self.ui.connect("command", self.process_command)
|
44
|
|
-
|
|
49
|
+
|
45
|
50
|
def read_commands(self):
|
46
|
51
|
#read the.commands file
|
47
|
52
|
file_lines = open(command_file)
|
|
@@ -105,8 +110,17 @@ class Blather:
|
105
|
110
|
self.quit()
|
106
|
111
|
|
107
|
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
|
122
|
#make our blather object
|
109
|
|
- blather = Blather(sys.argv)
|
|
123
|
+ blather = Blather(options)
|
110
|
124
|
#init gobject threads
|
111
|
125
|
gobject.threads_init()
|
112
|
126
|
#we want a main loop
|