Files
@ 941cfe1e1691
Branch filter:
Location: light9/bin/lightsim
941cfe1e1691
3.2 KiB
text/plain
lightsim now reads levels from dmxserver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #!/usr/bin/python
from __future__ import division
import run_local
from rdflib import Literal, URIRef
from twisted.internet import reactor, tksupport
from twisted.internet.task import LoopingCall
from twisted.web.xmlrpc import Proxy
import xmlrpclib, sys, logging
log = logging.getLogger()
logging.basicConfig(format="%(asctime)s %(levelname)-5s %(name)s %(filename)s:%(lineno)d: %(message)s")
log.setLevel(logging.DEBUG)
import Tkinter as tk
from light9 import networking, Patch, showconfig, dmxclient, updatefreq
from light9.namespaces import L9
from louie import dispatcher
try:
from OpenGL import Tk as Togl
from OpenGL.GL import *
except ImportError:
sys.path.append("/usr/lib/python2.4/site-packages/OpenGL/Tk/linux2-tk8.4")
from OpenGL.GL import *
import Togl
from lightsim.openglsim import Surface
def poll(graph, serv, pollFreq):
pollFreq.update()
dispatcher.send("status", key="pollFreq", value=str(pollFreq))
d = serv.callRemote("currentlevels", dmxclient._id)
def received(dmxLevels):
level = {} # filename : level
for i, lev in enumerate(dmxLevels):
if lev == 0:
continue
try:
chan = Patch.get_channel_uri(Patch.get_channel_name(i + 1))
except KeyError:
continue
for lyr in graph.objects(chan, L9['previewLayer']):
for imgPath in graph.objects(lyr, L9['path']):
level[str(imgPath)] = lev
ogl.newLevels(levels=level)
d.addCallback(received)
return d
class StatusKeys(tk.Frame):
# watch out- this might be an accidental redo of what curvecalc
# has. Or, maybe CC should use this obj
def __init__(self, master):
tk.Frame.__init__(self, master)
dispatcher.connect(self.status, "status")
self.row = {} # key name : (Frame, value Label)
def status(self, key, value):
if key not in self.row:
f = tk.Frame(self)
f.pack(side='top')
tk.Label(f, text=key, font="arial 8").pack(side='left')
l = tk.Label(f, text=value, font="arial 8")
l.pack(side='left')
self.row[key] = (f, l)
else:
row, lab = self.row[key]
lab.config(text=value)
root = tk.Frame()
root.pack(expand=True, fill='both')
pollFreq = updatefreq.Updatefreq(samples=5)
graph = showconfig.getGraph()
filenames = []
for lyr in graph.objects(None, L9['previewLayer']):
for p in graph.objects(lyr, L9['path']):
filenames.append(str(p))
ogl = Surface(root, filenames, width=120, height=80, imgRescaleTo=128)
ogl.pack(side='top', expand=True, fill='both')
sk = StatusKeys(root)
sk.pack(side='top', fill='x')
serv = Proxy(networking.dmxServerUrl())
LoopingCall(poll, graph, serv, pollFreq).start(.1)
top = root.winfo_toplevel()
top.wm_title(dmxclient._id)
top.bind("<Control-Key-q>",lambda ev: reactor.stop)
top.bind("<Destroy>",lambda ev: reactor.stop)
top.protocol('WM_DELETE_WINDOW', reactor.stop)
tksupport.install(ogl, ms=20)
if 0:
import hotshot, hotshot.stats
p = hotshot.Profile("/tmp/pro")
p.runcall(reactor.run)
p.close()
hotshot.stats.load("/tmp/pro").sort_stats('time').print_stats()
else:
reactor.run()
|