From c66ca30a452391f707e9dd7565c625fa1254c85b Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 25 Jan 2019 11:17:10 +0100 Subject: [PATCH] Restart functions + stylings --- hugvey/central_command.py | 30 ++++++++++---- hugvey/story.py | 4 +- www/css/styles.css | 36 +++++++--------- www/images/icon-position.svg | 1 + www/index.html | 8 +++- www/scss/styles.scss | 80 +++++++++++++++++++++--------------- 6 files changed, 94 insertions(+), 65 deletions(-) create mode 100644 www/images/icon-position.svg diff --git a/hugvey/central_command.py b/hugvey/central_command.py index 15fa758..cdf2524 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -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: diff --git a/hugvey/story.py b/hugvey/story.py index 6d70f76..bb893d1 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -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 diff --git a/www/css/styles.css b/www/css/styles.css index d8af211..06f6332 100644 --- a/www/css/styles.css +++ b/www/css/styles.css @@ -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; diff --git a/www/images/icon-position.svg b/www/images/icon-position.svg new file mode 100644 index 0000000..d3d94f0 --- /dev/null +++ b/www/images/icon-position.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/www/index.html b/www/index.html index 5df9e66..b15474e 100644 --- a/www/index.html +++ b/www/index.html @@ -34,14 +34,18 @@
{{ hv.status }}
- {{ hv.language }} / {{ hv.msg }} + {{ hv.language }}
{{timer(hv, 'finished')}}
-
+
{{c}}
+
+ + {{ hv.msg }} +
Pause
Resume
diff --git a/www/scss/styles.scss b/www/scss/styles.scss index 5967404..0ae32d5 100644 --- a/www/scss/styles.scss +++ b/www/scss/styles.scss @@ -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; + } + + .status{ + font-sytle: italic; + color: gray; + position: absolute; + top: 10px; + right: 5px; } -// &.hugvey--on{ - h1 { - position: absolute; - left: 5px; - top: 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; +// } } }