Change language

This commit is contained in:
Ruben van de Ven 2019-01-25 11:59:03 +01:00
parent c66ca30a45
commit 46299d2dac
5 changed files with 53 additions and 21 deletions

View file

@ -339,17 +339,23 @@ class HugveyState(object):
if event['event'] == 'resume': if event['event'] == 'resume':
self.resume() self.resume()
if event['event'] == 'change_language':
self.setLanguage(event['lang_code'])
self.eventQueue = None self.eventQueue = None
def setLanguage(self, language_code): def setLanguage(self, language_code):
if language_code not in self.command.languages: if language_code not in self.command.languages:
raise Exception("Invalid language {}".format(language_code)) raise Exception("Invalid language {}".format(language_code))
self.logger.info(f"set language: {language_code}")
self.language_code = language_code self.language_code = language_code
self.google.setLanguage(language_code) self.google.setLanguage(language_code)
self.story.reset() self.restart()
self.story.setStoryData(self.command.languages[language_code])
# self.story.reset()
# self.story.setStoryData(self.command.languages[language_code])
def pause(self): def pause(self):
self.logger.info('Pause') self.logger.info('Pause')
@ -372,7 +378,7 @@ class HugveyState(object):
def restart(self): def restart(self):
self.logger.info('Restart') self.logger.info('Restart')
if self.story: if self.story:
self.story.reset() self.story.stop()
self.resume() self.resume()
self.isRunning.set() self.isRunning.set()

View file

@ -45,14 +45,19 @@ def getWebSocketHandler(central_command):
msg = json.loads(message) msg = json.loads(message)
if msg['action'] == 'init': if msg['action'] == 'init':
self.msgInit() self.msgInit()
if msg['action'] == 'get_status': elif msg['action'] == 'get_status':
self.msgStatus() self.msgStatus()
if msg['action'] == 'resume': elif msg['action'] == 'resume':
self.msgResume(msg['hugvey']) self.msgResume(msg['hugvey'])
if msg['action'] == 'pause': elif msg['action'] == 'pause':
self.msgPause(msg['hugvey']) self.msgPause(msg['hugvey'])
if msg['action'] == 'restart': elif msg['action'] == 'restart':
self.msgRestart(msg['hugvey']) self.msgRestart(msg['hugvey'])
elif msg['action'] == 'change_language':
self.msgChangeLanguage(msg['hugvey'], msg['lang_code'])
else:
self.send({'alert': 'Unknown request: {}'.format(message)})
logger.warn('Unknown request: {}'.format(message))
except Exception as e: except Exception as e:
self.send({'alert': 'Invalid request: {}'.format(e)}) self.send({'alert': 'Invalid request: {}'.format(e)})
@ -89,6 +94,9 @@ def getWebSocketHandler(central_command):
def msgRestart(self, hv_id): def msgRestart(self, hv_id):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'restart'}) central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'restart'})
def msgChangeLanguage(self, hv_id, lang_code):
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'change_language', 'lang_code': lang_code})
return WebSocketHandler return WebSocketHandler
class NonCachingStaticFileHandler(tornado.web.StaticFileHandler): class NonCachingStaticFileHandler(tornado.web.StaticFileHandler):

View file

@ -69,6 +69,7 @@ class GoogleVoiceClient(object):
while not self.toBeShutdown: while not self.toBeShutdown:
try: try:
self.isRunning.wait() self.isRunning.wait()
logger.info("Starting Google Voice")
self.speech_client = speech.SpeechClient() self.speech_client = speech.SpeechClient()
config = types.RecognitionConfig( config = types.RecognitionConfig(

View file

@ -33,7 +33,14 @@
{{ hv.id }} {{ hv.id }}
</h1> </h1>
<div class='status'>{{ hv.status }}</div> <div class='status'>{{ hv.status }}</div>
<div v-if="hv.status != 'off' && hv.status != 'gone'"> <div v-if="hv.status != 'off' && hv.status != 'gone' && hv.status != 'loading'">
<select v-model="hv.language" @change="change_lang(hv, hv.language)">
<option v-for="lang in languages" :title="lang.file"
:value="lang.code">
<span :class="['flag-icon', lang.code]"></span>
{{lang.code}}
</option>
</select>
{{ hv.language }} {{ hv.language }}
<div v-if="hv.finished != false"><img class='icon' :src="'/images/icon-finished.svg'" title="Finished"> {{timer(hv, <div v-if="hv.finished != false"><img class='icon' :src="'/images/icon-finished.svg'" title="Finished"> {{timer(hv,
'finished')}}</div> 'finished')}}</div>
@ -43,13 +50,13 @@
{{c}} {{c}}
</div> </div>
<div class='position'> <div class='position'>
<img class='icon' :src="'/images/icon-position.svg'" :title="key"> <img class='icon' src="/images/icon-position.svg" title="position">
{{ hv.msg }} {{ hv.msg }}
</div> </div>
</div> </div>
<div class='btn' v-if="hv.status == 'running'" @click="pause(hv.id)">Pause</div> <div class='btn' v-if="hv.status == 'running'" @click="pause(hv)">Pause</div>
<div class='btn' v-if="hv.status == 'paused'" @click="resume(hv.id)">Resume</div> <div class='btn' v-if="hv.status == 'paused'" @click="resume(hv)">Resume</div>
<div class='btn' v-if="hv.status == 'finished'" @click="restart(hv.id)">Restart</div> <div class='btn' v-if="hv.status == 'finished'" @click="restart(hv)">Restart</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -22,14 +22,21 @@ class Panopticon {
loadNarrative: function( code, file ) { loadNarrative: function( code, file ) {
return panopticon.loadNarrative( code, file ); return panopticon.loadNarrative( code, file );
}, },
pause: function(hv_id) { pause: function(hv) {
return panopticon.pause(hv_id); hv.status = "loading";
return panopticon.pause(hv.id);
}, },
resume: function(hv_id) { resume: function(hv) {
return panopticon.resume(hv_id); hv.status = "loading";
return panopticon.resume(hv.id);
}, },
restart: function(hv_id) { restart: function(hv) {
return panopticon.restart(hv_id); hv.status = "loading";
return panopticon.restart(hv.id);
},
change_lang: function(hv, lang_code) {
hv.status = "loading";
return panopticon.change_language(hv.id, lang_code);
} }
} }
} ); } );
@ -127,6 +134,9 @@ class Panopticon {
restart( hv_id ) { restart( hv_id ) {
this.send( { action: 'restart', hugvey: hv_id } ) this.send( { action: 'restart', hugvey: hv_id } )
} }
change_language( hv_id, lang_code ) {
this.send( { action: 'change_language', hugvey: hv_id, lang_code: lang_code } );
}
} }