Restart functions + stylings

This commit is contained in:
Ruben van de Ven 2019-01-25 11:17:10 +01:00
parent a1f66a6a01
commit c66ca30a45
6 changed files with 94 additions and 65 deletions

View File

@ -84,6 +84,10 @@ class CentralCommand(object):
return status return status
hv = self.hugveys[hv_id] hv = self.hugveys[hv_id]
if not hv.story:
status['status'] = 'off'
return status
status['status'] = hv.getStatus() status['status'] = hv.getStatus()
status['language'] = hv.language_code status['language'] = hv.language_code
status['msg'] = hv.story.currentMessage.id if hv.story.currentMessage else None status['msg'] = hv.story.currentMessage.id if hv.story.currentMessage else None
@ -250,11 +254,10 @@ class HugveyState(object):
self.logger = logging.getLogger(f"hugvey{self.id}") self.logger = logging.getLogger(f"hugvey{self.id}")
self.loop = asyncio.new_event_loop() self.loop = asyncio.new_event_loop()
self.isConfigured = False self.isConfigured = False
self.isRunning = threading.Event() self.isRunning = asyncio.Event(loop=self.loop)
self.eventQueue = None self.eventQueue = None
self.language_code = 'en-GB' self.language_code = 'en-GB'
self.story = Story(self) self.story = None
self.story.setStoryData(self.command.languages[self.language_code])
self.streamer = None self.streamer = None
self.status = self.STATE_PAUSE self.status = self.STATE_PAUSE
self.google = None self.google = None
@ -352,6 +355,7 @@ class HugveyState(object):
self.logger.info('Pause') self.logger.info('Pause')
if self.google: if self.google:
self.google.pause() self.google.pause()
if self.story:
self.story.pause() self.story.pause()
self.isRunning.clear() self.isRunning.clear()
self.status = self.STATE_PAUSE self.status = self.STATE_PAUSE
@ -360,12 +364,14 @@ class HugveyState(object):
self.logger.info('Resume') self.logger.info('Resume')
if self.google: if self.google:
self.google.resume() self.google.resume()
if self.story:
self.story.resume() self.story.resume()
self.isRunning.set() self.isRunning.set()
self.status = self.STATE_RUNNING self.status = self.STATE_RUNNING
def restart(self): def restart(self):
self.logger.info('Restart') self.logger.info('Restart')
if self.story:
self.story.reset() self.story.reset()
self.resume() self.resume()
self.isRunning.set() self.isRunning.set()
@ -374,12 +380,22 @@ class HugveyState(object):
'''Status to 'gone' as in, shutdown/crashed/whatever '''Status to 'gone' as in, shutdown/crashed/whatever
''' '''
self.pause() self.pause()
if self.story:
self.story.stop()
self.logger.info('Gone') self.logger.info('Gone')
self.status = self.STATE_GONE self.status = self.STATE_GONE
async def playStory(self): async def playStory(self):
await self.story.start() while self.notShuttingDown:
await self.isRunning.wait()
# new story instance on each run
self.story = Story(self)
self.story.setStoryData(self.command.languages[self.language_code])
await self.story.run()
# self.story = None
def getStreamer(self): def getStreamer(self):
if not self.streamer: if not self.streamer:

View File

@ -1,6 +1,5 @@
import json import json
import time import time
import threading
import logging import logging
import asyncio import asyncio
@ -215,6 +214,7 @@ class Story(object):
self.log = [] # all nodes/elements that are triggered self.log = [] # all nodes/elements that are triggered
self.currentMessage = None self.currentMessage = None
self.timer = Stopwatch() self.timer = Stopwatch()
self.isRunning = False
def pause(self): def pause(self):
logger.debug('pause hugvey') logger.debug('pause hugvey')
@ -428,7 +428,7 @@ class Story(object):
else: else:
return self.directionsPerMsg[self.currentMessage.id] return self.directionsPerMsg[self.currentMessage.id]
async def start(self): async def run(self):
logger.info("Starting story") logger.info("Starting story")
self.timer.reset() self.timer.reset()
self.isRunning = True self.isRunning = True

View File

@ -38,7 +38,7 @@ img.icon {
overflow-y: scroll; } overflow-y: scroll; }
#status > div { #status > div {
width: 33.3333333%; width: 33.3333333%;
height: 150px; height: 200px;
border: solid 1px; border: solid 1px;
box-sizing: border-box; box-sizing: border-box;
position: relative; } position: relative; }
@ -61,39 +61,31 @@ img.icon {
#status .hugvey h1 { #status .hugvey h1 {
text-align: center; text-align: center;
margin: 0; margin: 0;
font-weight: normal; } font-weight: normal;
#status .hugvey h1 {
position: absolute; position: absolute;
left: 5px; left: 5px;
top: 5px; } top: 5px; }
#status .hugvey .status {
font-sytle: italic;
color: gray;
position: absolute;
top: 10px;
right: 5px; }
#status .hugvey .stats .count {
display: inline-block;
margin-right: 10px; }
#status .hugvey.hugvey--off { #status .hugvey.hugvey--off {
background-image: linear-gradient(to top, #575d74, #3572a5); } background-image: linear-gradient(to top, #575d74, #3572a5); }
#status .hugvey.hugvey--off::after { #status .hugvey.hugvey--off .status {
content: 'off';
font-style: italic;
color: gray;
text-align: center; } text-align: center; }
#status .hugvey.hugvey--gone { #status .hugvey.hugvey--gone {
background-image: linear-gradient(to top, orange, #ce5c00); } background-image: linear-gradient(to top, orange, #ce5c00); }
#status .hugvey.hugvey--gone::after {
content: 'disconnected';
font-style: italic;
color: gray;
text-align: center; }
#status .hugvey.hugvey--paused { #status .hugvey.hugvey--paused {
background-image: linear-gradient(to top, #888a85, #555753); } background-image: linear-gradient(to top, #888a85, #555753); }
#status .hugvey.hugvey--paused::after {
content: 'disconnected';
font-style: italic;
color: gray;
text-align: center; }
#status .hugvey.hugvey--finished { #status .hugvey.hugvey--finished {
background-image: linear-gradient(to top, #888a85, #35a589); } background-image: linear-gradient(to top, #888a85, #35a589); }
#status .hugvey.hugvey--finished::after { #status .hugvey.hugvey--finished .status {
content: 'disconnected'; color: darkgreen; }
font-style: italic;
color: gray;
text-align: center; }
#story { #story {
position: relative; position: relative;

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M172.268 501.67C26.97 291.031 0 269.413 0 192 0 85.961 85.961 0 192 0s192 85.961 192 192c0 77.413-26.97 99.031-172.268 309.67-9.535 13.774-29.93 13.773-39.464 0zM192 272c44.183 0 80-35.817 80-80s-35.817-80-80-80-80 35.817-80 80 35.817 80 80 80z"/></svg>

After

Width:  |  Height:  |  Size: 324 B

View File

@ -34,14 +34,18 @@
</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.language }} / {{ hv.msg }} {{ 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>
<div class='counts'> <div class='stats'>
<div class='count' v-for="c, key in hv.counts"> <div class='count' v-for="c, key in hv.counts">
<img class='icon' :src="'/images/icon-' + key + '.svg'" :title="key"> <img class='icon' :src="'/images/icon-' + key + '.svg'" :title="key">
{{c}} {{c}}
</div> </div>
<div class='position'>
<img class='icon' :src="'/images/icon-position.svg'" :title="key">
{{ hv.msg }}
</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.id)">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.id)">Resume</div>

View File

@ -53,7 +53,7 @@ img.icon{
& > div{ & > div{
width: 33.3333333%; width: 33.3333333%;
height: 150px; height: 200px;
border: solid 1px; border: solid 1px;
box-sizing: border-box; box-sizing: border-box;
position: relative; position: relative;
@ -87,58 +87,74 @@ img.icon{
text-align: center; text-align: center;
margin: 0; margin: 0;
font-weight: normal; font-weight: normal;
}
// &.hugvey--on{
h1 {
position: absolute; position: absolute;
left: 5px; left: 5px;
top: 5px; top: 5px;
} }
// }
.status{
font-sytle: italic;
color: gray;
position: absolute;
top: 10px;
right: 5px;
}
.stats{
.count{
display: inline-block;
margin-right: 10px;
}
}
&.hugvey--off{ &.hugvey--off{
background-image: linear-gradient(to top, #575d74, #3572a5); background-image: linear-gradient(to top, #575d74, #3572a5);
&::after{ .status{
content: 'off';
font-style: italic;
color: gray;
text-align:center; text-align:center;
// font-size: 30pt;
} }
// &::after{
// content: 'off';
// font-style: italic;
// color: gray;
// text-align:center;
// // font-size: 30pt;
// }
} }
&.hugvey--gone{ &.hugvey--gone{
background-image: linear-gradient(to top, orange, rgb(206, 92, 0)); background-image: linear-gradient(to top, orange, rgb(206, 92, 0));
&::after{ // &::after{
content: 'disconnected'; // content: 'disconnected';
font-style: italic; // font-style: italic;
color: gray; // color: gray;
text-align:center; // text-align:center;
// font-size: 30pt; // // font-size: 30pt;
} // }
} }
&.hugvey--paused{ &.hugvey--paused{
background-image: linear-gradient(to top, rgb(136, 138, 133), rgb(85, 87, 83)); background-image: linear-gradient(to top, rgb(136, 138, 133), rgb(85, 87, 83));
&::after{ // &::after{
content: 'disconnected'; // content: 'disconnected';
font-style: italic; // font-style: italic;
color: gray; // color: gray;
text-align:center; // text-align:center;
// font-size: 30pt; // // font-size: 30pt;
} // }
} }
&.hugvey--finished{ &.hugvey--finished{
background-image: linear-gradient(to top, rgb(136, 138, 133), #35a589); background-image: linear-gradient(to top, rgb(136, 138, 133), #35a589);
&::after{ .status{
content: 'disconnected'; color: darkgreen;
font-style: italic;
color: gray;
text-align:center;
// font-size: 30pt;
} }
// &::after{
// content: 'disconnected';
// font-style: italic;
// color: gray;
// text-align:center;
// // font-size: 30pt;
// }
} }
} }