|
@@ -9,7 +9,10 @@ import gobject
|
9
|
9
|
import os.path
|
10
|
10
|
import subprocess
|
11
|
11
|
from optparse import OptionParser
|
12
|
|
-
|
|
12
|
+try:
|
|
13
|
+ import yaml
|
|
14
|
+except:
|
|
15
|
+ print "YAML is not supported. ~/.config/blather/options.yaml will not function"
|
13
|
16
|
|
14
|
17
|
#where are the files?
|
15
|
18
|
conf_dir = os.path.expanduser("~/.config/blather")
|
|
@@ -17,6 +20,7 @@ lang_dir = os.path.join(conf_dir, "language")
|
17
|
20
|
command_file = os.path.join(conf_dir, "commands.conf")
|
18
|
21
|
strings_file = os.path.join(conf_dir, "sentences.corpus")
|
19
|
22
|
history_file = os.path.join(conf_dir, "blather.history")
|
|
23
|
+opt_file = os.path.join(conf_dir, "options.yaml")
|
20
|
24
|
lang_file = os.path.join(lang_dir,'lm')
|
21
|
25
|
dic_file = os.path.join(lang_dir,'dic')
|
22
|
26
|
#make the lang_dir if it doesn't exist
|
|
@@ -28,8 +32,7 @@ class Blather:
|
28
|
32
|
#import the recognizer so Gst doesn't clobber our -h
|
29
|
33
|
from Recognizer import Recognizer
|
30
|
34
|
self.ui = None
|
31
|
|
- #keep track of the opts
|
32
|
|
- self.opts = opts
|
|
35
|
+ self.options = {}
|
33
|
36
|
ui_continuous_listen = False
|
34
|
37
|
self.continuous_listen = False
|
35
|
38
|
self.commands = {}
|
|
@@ -37,27 +40,40 @@ class Blather:
|
37
|
40
|
self.recognizer = Recognizer(lang_file, dic_file, opts.microphone )
|
38
|
41
|
self.recognizer.connect('finished',self.recognizer_finished)
|
39
|
42
|
|
40
|
|
- if opts.interface != None:
|
41
|
|
- if opts.interface == "q":
|
42
|
|
- #import the ui from qt
|
|
43
|
+ #load the options file
|
|
44
|
+ self.load_options()
|
|
45
|
+ #merge the opts
|
|
46
|
+ for k,v in opts.__dict__.items():
|
|
47
|
+ if not k in self.options:
|
|
48
|
+ self.options[k] = v
|
|
49
|
+
|
|
50
|
+ print "Using Options: ", self.options
|
|
51
|
+
|
|
52
|
+ if self.options['interface'] != None:
|
|
53
|
+ if self.options['interface'] == "q":
|
43
|
54
|
from QtUI import UI
|
44
|
|
- elif opts.interface == "g":
|
|
55
|
+ elif self.options['interface'] == "g":
|
45
|
56
|
from GtkUI import UI
|
|
57
|
+ elif self.options['interface'] == "gt":
|
|
58
|
+ from GtkTrayUI import UI
|
46
|
59
|
else:
|
47
|
60
|
print "no GUI defined"
|
48
|
61
|
sys.exit()
|
49
|
62
|
|
50
|
|
- self.ui = UI(args,opts.continuous)
|
|
63
|
+ self.ui = UI(args, self.options['continuous'])
|
51
|
64
|
self.ui.connect("command", self.process_command)
|
52
|
65
|
#can we load the icon resource?
|
53
|
66
|
icon = self.load_resource("icon.png")
|
54
|
67
|
if icon:
|
55
|
|
- self.ui.set_icon(icon)
|
|
68
|
+ self.ui.set_icon_active_asset(icon)
|
|
69
|
+ #can we load the icon_inactive resource?
|
|
70
|
+ icon_inactive = self.load_resource("icon_inactive.png")
|
|
71
|
+ if icon_inactive:
|
|
72
|
+ self.ui.set_icon_inactive_asset(icon_inactive)
|
56
|
73
|
|
57
|
|
- if self.opts.history:
|
|
74
|
+ if self.options['history']:
|
58
|
75
|
self.history = []
|
59
|
76
|
|
60
|
|
-
|
61
|
77
|
def read_commands(self):
|
62
|
78
|
#read the.commands file
|
63
|
79
|
file_lines = open(command_file)
|
|
@@ -76,10 +92,20 @@ class Blather:
|
76
|
92
|
#close the strings file
|
77
|
93
|
strings.close()
|
78
|
94
|
|
|
95
|
+ def load_options(self):
|
|
96
|
+ #is there an opt file?
|
|
97
|
+ try:
|
|
98
|
+ opt_fh = open(opt_file)
|
|
99
|
+ text = opt_fh.read()
|
|
100
|
+ self.options = yaml.load(text)
|
|
101
|
+ except:
|
|
102
|
+ pass
|
|
103
|
+
|
|
104
|
+
|
79
|
105
|
def log_history(self,text):
|
80
|
|
- if self.opts.history:
|
|
106
|
+ if self.options['history']:
|
81
|
107
|
self.history.append(text)
|
82
|
|
- if len(self.history) > self.opts.history:
|
|
108
|
+ if len(self.history) > self.options['history']:
|
83
|
109
|
#pop off the first item
|
84
|
110
|
self.history.pop(0)
|
85
|
111
|
|
|
@@ -148,7 +174,7 @@ if __name__ == "__main__":
|
148
|
174
|
parser = OptionParser()
|
149
|
175
|
parser.add_option("-i", "--interface", type="string", dest="interface",
|
150
|
176
|
action='store',
|
151
|
|
- help="Interface to use (if any). 'q' for Qt, 'g' for GTK")
|
|
177
|
+ help="Interface to use (if any). 'q' for Qt, 'g' for GTK, 'gt' for GTK system tray icon")
|
152
|
178
|
parser.add_option("-c", "--continuous",
|
153
|
179
|
action="store_true", dest="continuous", default=False,
|
154
|
180
|
help="starts interface with 'continuous' listen enabled")
|