Changeset - 259436a06912
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 16 years ago 2009-06-29 02:03:38
drewp@bigasterisk.com
keyboardcomposer now receives http, not xmlrpc
Ignore-this: e16323501f57ec11731a5c9a1f19d0f6
2 files changed with 37 insertions and 13 deletions:
0 comments (0 inline, 0 general)
bin/keyboardcomposer
Show inline comments
 
#!/usr/bin/python
 

	
 
from __future__ import division, nested_scopes
 
import os, sys, time, subprocess
 
import cgi, os, sys, time, subprocess
 
from optparse import OptionParser
 

	
 
from twisted.internet import reactor, tksupport
 
from twisted.web import xmlrpc, server
 
from twisted.web import xmlrpc, server, resource
 
from Tix import *
 
import Tix as tk
 
import pickle
 

	
 
import run_local
 
from light9.Fadable import Fadable
 
from light9.Submaster import Submasters, sub_maxes
 
from light9.subclient import SubClient
 
from light9 import dmxclient, showconfig, networking, prof
 
from light9.uihelpers import toplevelat, bindkeys
 
from light9.namespaces import L9
 
from bcf2000 import BCF2000
 
@@ -350,36 +350,57 @@ class KeyboardComposer(Frame, SubClient)
 
            r.destroy()
 
        self.keyhints.destroy()
 
        self.buttonframe.destroy()
 
        self.draw_ui()
 
        # possibly paranoia (but possibly not)
 
        self.change_row(self.current_row)
 

	
 
    def alltozero(self):
 
        for name, subtk in self.name_to_subtk.items():
 
            if subtk.scale.scale_var.get() != 0:
 
                subtk.scale.fade(value=0.0, length=0)
 

	
 
class LevelServer(xmlrpc.XMLRPC):
 
# move to web lib
 
def postArgGetter(request):
 
    """return a function that takes arg names and returns string
 
    values. Supports args encoded in the url or in postdata. No
 
    support for repeated args."""
 
    # this is something nevow normally does for me
 
    request.content.seek(0)
 
    fields = cgi.FieldStorage(request.content, request.received_headers,
 
                              environ={'REQUEST_METHOD': 'POST'})
 
    def getArg(n):
 
        try:
 
            return request.args[n][0]
 
        except KeyError:
 
            return fields[n].value
 
    return getArg
 

	
 

	
 
class LevelServerHttp(resource.Resource):
 
    isLeaf = True
 
    def __init__(self,name_to_subtk):
 
        self.name_to_subtk = name_to_subtk
 

	
 
    def render_POST(self, request):
 
        arg = postArgGetter(request)
 
        
 
    def xmlrpc_fadesub(self,subname,level,secs):
 
        """submaster will fade to level in secs"""
 
        try:
 
            self.name_to_subtk[subname].scale.fade(level,secs)
 
            ret='ok'
 
        except Exception,e:
 
            ret=str(e)
 
        return ret
 
        if request.path == '/fadesub':
 
            # fadesub?subname=scoop&level=0&secs=.2
 
            self.name_to_subtk[arg('subname')].scale.fade(
 
                float(arg('level')),
 
                float(arg('secs')))
 
            return "set %s to %s" % (arg('subname'), arg('level'))
 
        else:
 
            raise NotImplementedError(repr(request))
 

	
 
class Sliders(BCF2000):
 
    def __init__(self, kc):
 
        BCF2000.__init__(self)
 
        self.kc = kc
 
    def valueIn(self, name, value):
 
        kc = self.kc
 
        if name.startswith("slider"):
 
            kc.hw_slider_moved(int(name[6:]) - 1, value / 127)
 
        elif name.startswith("button-upper"):
 
            kc.change_row(kc.current_row)
 
        elif name.startswith("button-lower"):
 
@@ -423,26 +444,26 @@ if __name__ == "__main__":
 
    startLevels = None
 
    if opts.nonpersistent:
 
        startLevels = {}
 
    kc = KeyboardComposer(tl, s, startLevels, hw_sliders=not opts.no_sliders)
 
    kc.pack(fill=BOTH, expand=1)
 

	
 
    for helpline in ["Bindings: B3 mute; C-l edit levels in subcomposer"]:
 
        tk.Label(root,text=helpline, font="Helvetica -12 italic",
 
                 anchor='w').pack(side='top',fill='x')
 

	
 
    import twisted.internet
 
    try:
 
        ls = LevelServer(kc.name_to_subtk)
 
        reactor.listenTCP(networking.kcPort(), server.Site(ls))
 
        reactor.listenTCP(networking.kcPort(),
 
                          server.Site(LevelServerHttp(kc.name_to_subtk)))
 
    except twisted.internet.error.CannotListenError, e:
 
        print "Can't (and won't!) start level server:"
 
        print e
 

	
 
    root.protocol('WM_DELETE_WINDOW', reactor.stop)
 
    if not opts.nonpersistent:
 
        reactor.addSystemEventTrigger('after', 'shutdown', kc.save)
 
    
 
    tksupport.install(root,ms=10)
 

	
 

	
 
#    prof.watchPoint("/usr/lib/python2.4/site-packages/rdflib-2.3.3-py2.4-linux-i686.egg/rdflib/Graph.py", 615)
light9/networking.py
Show inline comments
 
@@ -17,12 +17,15 @@ def musicUrl():
 
def musicPort():
 
    return 8040
 

	
 
def mpdServer():
 
    """servername, port"""
 
    return os.getenv('LIGHT9_MPD_SERVER', 'score'),6600
 

	
 
def kcPort():
 
    return 8050
 

	
 
def kcServer():
 
    return 'plus'
 

	
 
def keyboardComposerUrl():
 
    return "http://%s:%s" % (kcServer(), kcPort())
0 comments (0 inline, 0 general)