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

View file

@ -45,14 +45,19 @@ def getWebSocketHandler(central_command):
msg = json.loads(message)
if msg['action'] == 'init':
self.msgInit()
if msg['action'] == 'get_status':
elif msg['action'] == 'get_status':
self.msgStatus()
if msg['action'] == 'resume':
elif msg['action'] == 'resume':
self.msgResume(msg['hugvey'])
if msg['action'] == 'pause':
elif msg['action'] == 'pause':
self.msgPause(msg['hugvey'])
if msg['action'] == 'restart':
elif msg['action'] == 'restart':
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:
self.send({'alert': 'Invalid request: {}'.format(e)})
@ -89,6 +94,9 @@ def getWebSocketHandler(central_command):
def msgRestart(self, hv_id):
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
class NonCachingStaticFileHandler(tornado.web.StaticFileHandler):

View file

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

View file

@ -33,7 +33,14 @@
{{ hv.id }}
</h1>
<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 }}
<div v-if="hv.finished != false"><img class='icon' :src="'/images/icon-finished.svg'" title="Finished"> {{timer(hv,
'finished')}}</div>
@ -43,13 +50,13 @@
{{c}}
</div>
<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 }}
</div>
</div>
<div class='btn' v-if="hv.status == 'running'" @click="pause(hv.id)">Pause</div>
<div class='btn' v-if="hv.status == 'paused'" @click="resume(hv.id)">Resume</div>
<div class='btn' v-if="hv.status == 'finished'" @click="restart(hv.id)">Restart</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)">Resume</div>
<div class='btn' v-if="hv.status == 'finished'" @click="restart(hv)">Restart</div>
</div>
</div>
</div>

View file

@ -22,14 +22,21 @@ class Panopticon {
loadNarrative: function( code, file ) {
return panopticon.loadNarrative( code, file );
},
pause: function(hv_id) {
return panopticon.pause(hv_id);
pause: function(hv) {
hv.status = "loading";
return panopticon.pause(hv.id);
},
resume: function(hv_id) {
return panopticon.resume(hv_id);
resume: function(hv) {
hv.status = "loading";
return panopticon.resume(hv.id);
},
restart: function(hv_id) {
return panopticon.restart(hv_id);
restart: function(hv) {
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 ) {
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 } );
}
}