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
hv = self.hugveys[hv_id]
if not hv.story:
status['status'] = 'off'
return status
status['status'] = hv.getStatus()
status['language'] = hv.language_code
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.loop = asyncio.new_event_loop()
self.isConfigured = False
self.isRunning = threading.Event()
self.isRunning = asyncio.Event(loop=self.loop)
self.eventQueue = None
self.language_code = 'en-GB'
self.story = Story(self)
self.story.setStoryData(self.command.languages[self.language_code])
self.story = None
self.streamer = None
self.status = self.STATE_PAUSE
self.google = None
@ -352,7 +355,8 @@ class HugveyState(object):
self.logger.info('Pause')
if self.google:
self.google.pause()
self.story.pause()
if self.story:
self.story.pause()
self.isRunning.clear()
self.status = self.STATE_PAUSE
@ -360,13 +364,15 @@ class HugveyState(object):
self.logger.info('Resume')
if self.google:
self.google.resume()
self.story.resume()
if self.story:
self.story.resume()
self.isRunning.set()
self.status = self.STATE_RUNNING
def restart(self):
self.logger.info('Restart')
self.story.reset()
if self.story:
self.story.reset()
self.resume()
self.isRunning.set()
@ -374,12 +380,22 @@ class HugveyState(object):
'''Status to 'gone' as in, shutdown/crashed/whatever
'''
self.pause()
if self.story:
self.story.stop()
self.logger.info('Gone')
self.status = self.STATE_GONE
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):
if not self.streamer:

View file

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

View file

@ -38,7 +38,7 @@ img.icon {
overflow-y: scroll; }
#status > div {
width: 33.3333333%;
height: 150px;
height: 200px;
border: solid 1px;
box-sizing: border-box;
position: relative; }
@ -61,39 +61,31 @@ img.icon {
#status .hugvey h1 {
text-align: center;
margin: 0;
font-weight: normal; }
#status .hugvey h1 {
font-weight: normal;
position: absolute;
left: 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 {
background-image: linear-gradient(to top, #575d74, #3572a5); }
#status .hugvey.hugvey--off::after {
content: 'off';
font-style: italic;
color: gray;
#status .hugvey.hugvey--off .status {
text-align: center; }
#status .hugvey.hugvey--gone {
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 {
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 {
background-image: linear-gradient(to top, #888a85, #35a589); }
#status .hugvey.hugvey--finished::after {
content: 'disconnected';
font-style: italic;
color: gray;
text-align: center; }
#status .hugvey.hugvey--finished .status {
color: darkgreen; }
#story {
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>
<div class='status'>{{ hv.status }}</div>
<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,
'finished')}}</div>
<div class='counts'>
<div class='stats'>
<div class='count' v-for="c, key in hv.counts">
<img class='icon' :src="'/images/icon-' + key + '.svg'" :title="key">
{{c}}
</div>
<div class='position'>
<img class='icon' :src="'/images/icon-position.svg'" :title="key">
{{ 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>

View file

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