Commit 5eecd8dd authored by Séverin Lemaignan's avatar Séverin Lemaignan
Browse files

WIP introducing pyRobots actions

parent e2936af0
import logging;logger = logging.getLogger("robots.activities.stories")
import time
from robots.concurrency import action
from flask import render_template
from constants import *
from flask_server import tablet_webserver
from story_parser import Story
story = Story("static/stories/susanne-and-ben/story.json")
assets = "/static/stories/susanne-and-ben/assets/"
@action
def start_activity(robot, tablet, progress):
tablet.setUrl("/stories")
progress = 0
for i in range(10):
time.sleep(1)
logger.info("Story progressing nicely. %s%% done" % progress)
progress+= 10
@tablet_webserver.route('/stories/<action>')
@tablet_webserver.route('/stories/')
def web_stories(action=None):
txt, actions = story.next(action)
# server.cmd_queue is injected by main.py upon Flask's thread creation
tablet_webserver.cmd_queue.put((TABLET, STORIES, (action,)))
return render_template('stories.html',
text = txt,
path = assets,
actions = actions)
......@@ -6,12 +6,23 @@ from Queue import Queue
from PySide2.QtCore import QUrl, QObject
from robots import GenericRobot
from constants import *
from websocketserver import TabletWebSocketServer
###########################################
# ACTIVITIES
from activities.stories import activity as stories
class Supervisor(QObject):
###########################################
class Supervisor(QObject, GenericRobot):
def __init__(self):
QObject.__init__(self)
#GenericRobot.__init__(self, actions = ["activities.stories"])
GenericRobot.__init__(self)
self.cmd_queue = Queue()
......@@ -19,6 +30,10 @@ class Supervisor(QObject):
# note that this server *must* run from the main thread (eg, the Qt app thread)
self.tablet = TabletWebSocketServer()
self.current_activity = None
self.current_activity_progress = 0 # 0% to 100%
def run(self):
while True:
......@@ -29,7 +44,19 @@ class Supervisor(QObject):
source, cmd, args = self.cmd_queue.get()
logger.info("GOT A %s CMD: %s (%s)" % (source, cmd, args))
if source == "CTRL":
if source == TABLET:
if cmd == STORIES:
self.tablet.setUrl("/stories")
self.current_activity_progress = 0
self.current_activity = stories.start_activity(
self,
self.tablet,
self.current_activity_progress)
if cmd == INTERRUPT:
pass
if source == CTRL:
self.tablet.setUrl("/")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment