Files @ 8b3f7f5656f4
Branch filter:

Location: light9/bin/vidref - annotation

Drew Perttula
try to pretty up the zoom/layout change code
Ignore-this: f8ef1cecc4802b0d9befb49301501521
#!bin/python
from run_local import log
import sys
sys.path.append('/usr/lib/python2.7/dist-packages') # For gtk
from twisted.internet import gtk2reactor
gtk2reactor.install()
from twisted.internet import reactor, defer
import gobject
gobject.threads_init()
import gtk
import sys, logging, optparse, json
import cyclone.web, cyclone.httpclient, cyclone.websocket
from light9 import networking, showconfig
from light9.vidref.main import Gui
from light9.vidref.replay import snapshotDir
from light9.rdfdb.syncedgraph import SyncedGraph

 # find replay dirs correctly. show multiple
 # replays. trash. reorder/pin. dump takes that are too short; they're
 # just from seeking

parser = optparse.OptionParser()
parser.add_option("-v", "--verbose", action="store_true",
                  help="logging.DEBUG")
(options, args) = parser.parse_args()


log.setLevel(logging.DEBUG if options.verbose else logging.INFO)

class Snapshot(cyclone.web.RequestHandler):
    @defer.inlineCallbacks
    def post(self):
        # save next pic
        # return /snapshot/path
        try:
            outputFilename = yield self.settings.gui.snapshot()

            assert outputFilename.startswith(snapshotDir())
            out = networking.vidref.path(
                "snapshot/%s" % outputFilename[len(snapshotDir()):].lstrip('/'))
            
            self.write(json.dumps({'snapshot': out}))
            self.set_header("Location", out)
            self.set_status(303)
        except Exception as e:
            import traceback
            traceback.print_exc()
            raise

class SnapshotPic(cyclone.web.StaticFileHandler):
    pass


class Time(cyclone.web.RequestHandler):
    def put(self):
        body = json.loads(self.request.body)
        t = body['t']
        source = body['source']
        self.settings.gui.incomingTime(t, source)
        self.set_status(202)


graph = SyncedGraph(networking.rdfdb.url, "vidref")

gui = Gui(graph)

port = networking.vidref.port
reactor.listenTCP(port, cyclone.web.Application(handlers=[
    (r'/()', cyclone.web.StaticFileHandler,
     {'path': 'light9/vidref', 'default_filename': 'vidref.html'}),
    (r'/snapshot', Snapshot),
    (r'/snapshot/(.*)', SnapshotPic, {"path": snapshotDir()}),
    (r'/time', Time),
    ], debug=True, gui=gui))
log.info("serving on %s" % port)

reactor.run()