changeset 1164:65f0179a9254

subcomposer has a web ui with buttons for toggling lights Ignore-this: f8cf76c46d81eec86c8945a61f6a594d
author drewp@bigasterisk.com
date Sun, 15 Jun 2014 02:23:39 +0000
parents 9973d4623928
children 1131e987234d
files bin/subcomposer light9/networking.py light9/subcomposer/__init__.py light9/subcomposer/index.html light9/subcomposer/subcomposerweb.py
diffstat 4 files changed, 76 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/bin/subcomposer	Sun Jun 15 02:21:24 2014 +0000
+++ b/bin/subcomposer	Sun Jun 15 02:23:39 2014 +0000
@@ -39,6 +39,7 @@
 from light9.rdfdb.patch import Patch
 from light9.observable import Observable
 from light9.editchoice import EditChoice, Local
+from light9.subcomposer import subcomposerweb
 
 
 class Subcomposer(tk.Frame):
@@ -235,8 +236,11 @@
     if not opts.no_geometry:
         toplevelat("subcomposer - %s" % opts.session, root, graph, session)
 
+        
     sc = Subcomposer(root, graph, session)
     sc.pack()
+    
+    subcomposerweb.init(graph, session, sc.currentSub)
 
     tk.Label(root,text="Bindings: B1 adjust level; B2 set full; B3 instant bump",
              font="Helvetica -12 italic",anchor='w').pack(side='top',fill='x')
--- a/light9/networking.py	Sun Jun 15 02:21:24 2014 +0000
+++ b/light9/networking.py	Sun Jun 15 02:23:39 2014 +0000
@@ -44,5 +44,6 @@
 effectEval = ServiceAddress(L9['effectEval'])
 picamserve = ServiceAddress(L9['picamserve'])
 rdfdb = ServiceAddress(L9['rdfdb'])
+subComposer = ServiceAddress(L9['subComposer'])
 
 patchReceiverUpdateHost = ServiceAddress(L9['patchReceiverUpdateHost'])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/light9/subcomposer/index.html	Sun Jun 15 02:23:39 2014 +0000
@@ -0,0 +1,42 @@
+<!doctype html>
+<html>
+  <head>
+    <title>subcomposer</title>
+    <meta charset="utf-8" />
+    <style>
+     button {
+       min-width: 200px;
+       min-height: 50px;
+       display: block;
+     }
+    </style>
+  </head>
+  <body>
+    <div>Toggle channel in current sub</div>
+
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f1-blue">f1-blue</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f2">f2</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f3">f3</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f4-pool-l">f4-pool-l</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f5-fill">f5-fill</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/sharlyn">sharlyn</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f7">f7</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f8-fill">f8-fill</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f9-pool-r">f9-pool-r</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f10">f10</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f11-blue">f11-blue</button>
+    <button data-chan="http://light9.bigasterisk.com/theater/piedmont/channel/f12-purp">f12-purp</button>
+
+    <script src="static/jquery-2.1.1.min.js"></script>
+    <script>
+      $(document).on("click", "button", function (ev) {
+          var chan = ev.target.getAttribute('data-chan');
+          $.ajax({
+              type: 'POST',
+              url: 'toggle',
+              data: {chan: chan}
+          });
+      });
+    </script>
+  </body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/light9/subcomposer/subcomposerweb.py	Sun Jun 15 02:23:39 2014 +0000
@@ -0,0 +1,29 @@
+import logging
+import cyclone.web, cyclone.websocket, cyclone.httpclient
+from lib.cycloneerr import PrettyErrorHandler
+from light9 import networking
+from rdflib import URIRef, Literal
+from twisted.internet import reactor
+log = logging.getLogger('web')
+
+def init(graph, session, currentSub):
+    SFH = cyclone.web.StaticFileHandler
+    app = cyclone.web.Application(handlers=[
+        (r'/()', SFH,
+         {'path': 'light9/subcomposer', 'default_filename': 'index.html'}),
+        (r'/static/(.*)', SFH, {'path': 'static/'}),
+        (r'/toggle', Toggle),
+    ], debug=True, graph=graph, currentSub=currentSub)
+    reactor.listenTCP(networking.subComposer.port, app)
+    log.info("listening on %s" % networking.subComposer.port)
+
+class Toggle(PrettyErrorHandler, cyclone.web.RequestHandler):
+    def post(self):
+        chan = URIRef(self.get_argument('chan'))
+        log.info("toggle %r", chan)
+        sub = self.settings.currentSub()
+        
+        chanKey = Literal(chan.rsplit('/', 1)[1])
+        old = sub.get_levels().get(chanKey, 0)
+
+        sub.editLevel(chan, 0 if old else 1)