changeset 763:ffecebbdcc95

curvecalc serves the time you're hovering over Ignore-this: 1175a24abc1de8f6e995e925bb25caab
author drewp@bigasterisk.com
date Sat, 16 Jun 2012 02:53:49 +0000
parents 9e373ba54aa9
children 0300715a365f
files bin/curvecalc light9/networking.py
diffstat 2 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/bin/curvecalc	Sat Jun 16 02:00:43 2012 +0000
+++ b/bin/curvecalc	Sat Jun 16 02:53:49 2012 +0000
@@ -15,14 +15,14 @@
 gtk2reactor.install()
 from twisted.internet import reactor
 
-import time, textwrap, os, optparse, gtk, linecache, signal, traceback
+import time, textwrap, os, optparse, gtk, linecache, signal, traceback, json
 import louie as dispatcher 
 from rdflib import URIRef, Graph, Literal, RDF, RDFS
 import logging
 log = logging.getLogger()
 
 import run_local
-from light9 import showconfig, prof
+from light9 import showconfig, prof, networking
 from light9.curvecalc.curve import Curveset
 from light9.curvecalc import curveview 
 from light9.curvecalc.musicaccess import Music, currentlyPlayingSong
@@ -332,6 +332,24 @@
         log.debug("quitting now because of --startup-only")
         return
 
+    from twisted.web import server, resource
+    class Hover(resource.Resource):
+        isLeaf = True
+        def render_GET(self, request):
+            if request.path == '/hoverTime':
+                results = dispatcher.send("onPlayPause")
+                times = [t for listener, t in results if t is not None]
+                if not times:
+                    request.setResponseCode(404)
+                    return "not hovering over any time"
+                
+                return json.dumps({"song":song, "hoverTime" : times[0]})
+            raise NotImplementedError()
+
+    reactor.listenTCP(networking.curveCalc.port,
+                      server.Site(Hover()))
+
+
     prof.run(reactor.run, profile=False)
 
 main()
--- a/light9/networking.py	Sat Jun 16 02:00:43 2012 +0000
+++ b/light9/networking.py	Sat Jun 16 02:53:49 2012 +0000
@@ -34,4 +34,4 @@
 dmxServer = ServiceAddress(L9['dmxServer'])
 musicPlayer = ServiceAddress(L9['musicPlayer'])
 keyboardComposer = ServiceAddress(L9['keyboardComposer'])
-
+curveCalc = ServiceAddress(L9['curveCalc'])