annotate light9/dmxchanedit.py @ 210:f41004d5a507

factored out some networking, new show/ layout, curvecalc works
author drewp@bigasterisk.com
date Sun, 10 Apr 2005 20:54:14 +0000
parents 1a84c5e83d3e
children 2c02748847f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
1 """
45b12307c695 Initial revision
drewp
parents:
diff changeset
2
45b12307c695 Initial revision
drewp
parents:
diff changeset
3 widget to show all dmx channel levels and allow editing. levels might
45b12307c695 Initial revision
drewp
parents:
diff changeset
4 not actually match what dmxserver is outputting.
45b12307c695 Initial revision
drewp
parents:
diff changeset
5
45b12307c695 Initial revision
drewp
parents:
diff changeset
6 """
45b12307c695 Initial revision
drewp
parents:
diff changeset
7 from __future__ import nested_scopes,division
45b12307c695 Initial revision
drewp
parents:
diff changeset
8 import Tkinter as tk
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
9 import time
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
10 from light9 import Patch
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
11 from light9.uihelpers import make_frame, colorlabel, eventtoparent
201
e4a711d9a338 new dispatcher import
drewp
parents: 167
diff changeset
12 from dispatch import dispatcher
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
13
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
14 # this font makes each label take 16ms to create, so startup is slow.
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
15 # with default font, each labl takes about .5ms to create.
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
16 stdfont = ('Arial', 12)
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
17 import tkFont
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
18 # see replacement stdfont below
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
19
45b12307c695 Initial revision
drewp
parents:
diff changeset
20 class Onelevel(tk.Frame):
45b12307c695 Initial revision
drewp
parents:
diff changeset
21 """a name/level pair"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
22 def __init__(self, parent, channelnum):
45b12307c695 Initial revision
drewp
parents:
diff changeset
23 """channelnum is 1..68, like the real dmx"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 tk.Frame.__init__(self,parent)
45b12307c695 Initial revision
drewp
parents:
diff changeset
25
45b12307c695 Initial revision
drewp
parents:
diff changeset
26 self.channelnum=channelnum
45b12307c695 Initial revision
drewp
parents:
diff changeset
27 self.currentlevel=0 # the level we're displaying, 0..1
45b12307c695 Initial revision
drewp
parents:
diff changeset
28
45b12307c695 Initial revision
drewp
parents:
diff changeset
29 # 3 widgets, left-to-right:
45b12307c695 Initial revision
drewp
parents:
diff changeset
30
45b12307c695 Initial revision
drewp
parents:
diff changeset
31 # channel number -- will turn yellow when being altered
45b12307c695 Initial revision
drewp
parents:
diff changeset
32 self.num_lab = tk.Label(self, text=str(channelnum),
45b12307c695 Initial revision
drewp
parents:
diff changeset
33 width=3, bg='grey40',
45b12307c695 Initial revision
drewp
parents:
diff changeset
34 fg='white', font=stdfont,
45b12307c695 Initial revision
drewp
parents:
diff changeset
35 padx=0, pady=0, bd=0, height=1)
45b12307c695 Initial revision
drewp
parents:
diff changeset
36 self.num_lab.pack(side='left')
45b12307c695 Initial revision
drewp
parents:
diff changeset
37
45b12307c695 Initial revision
drewp
parents:
diff changeset
38 # text description of channel
45b12307c695 Initial revision
drewp
parents:
diff changeset
39 self.desc_lab=tk.Label(self, text=Patch.get_channel_name(channelnum),
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
40 width=14, font=stdfont,
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
41 anchor='w',
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
42 padx=0, pady=0, bd=0,
45b12307c695 Initial revision
drewp
parents:
diff changeset
43 height=1, bg='black', fg='white')
45b12307c695 Initial revision
drewp
parents:
diff changeset
44 self.desc_lab.pack(side='left')
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
45
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
46 # current level of channel, shows intensity with color
45b12307c695 Initial revision
drewp
parents:
diff changeset
47 self.level_lab = tk.Label(self, width=3, bg='lightBlue',
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
48 font=stdfont,
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
49 anchor='e',
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
50 padx=1, pady=0, bd=0, height=1)
45b12307c695 Initial revision
drewp
parents:
diff changeset
51 self.level_lab.pack(side='left')
45b12307c695 Initial revision
drewp
parents:
diff changeset
52
45b12307c695 Initial revision
drewp
parents:
diff changeset
53 self.setlevel(0)
45b12307c695 Initial revision
drewp
parents:
diff changeset
54 self.setupmousebindings()
45b12307c695 Initial revision
drewp
parents:
diff changeset
55
45b12307c695 Initial revision
drewp
parents:
diff changeset
56 def setupmousebindings(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
57 def b1down(ev):
45b12307c695 Initial revision
drewp
parents:
diff changeset
58 self.desc_lab.config(bg='cyan')
45b12307c695 Initial revision
drewp
parents:
diff changeset
59 self._start_y=ev.y
45b12307c695 Initial revision
drewp
parents:
diff changeset
60 self._start_lev=self.currentlevel
45b12307c695 Initial revision
drewp
parents:
diff changeset
61 def b1motion(ev):
45b12307c695 Initial revision
drewp
parents:
diff changeset
62 delta=self._start_y-ev.y
45b12307c695 Initial revision
drewp
parents:
diff changeset
63 self.changelevel(self._start_lev+delta*.005)
45b12307c695 Initial revision
drewp
parents:
diff changeset
64 def b1up(ev):
45b12307c695 Initial revision
drewp
parents:
diff changeset
65 self.desc_lab.config(bg='black')
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
66 def b3up(ev):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
67 self.changelevel(0.0)
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
68 def b3down(ev):
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
69 self.changelevel(1.0)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
70
45b12307c695 Initial revision
drewp
parents:
diff changeset
71 # make the buttons work in the child windows
45b12307c695 Initial revision
drewp
parents:
diff changeset
72 for w in self.winfo_children():
45b12307c695 Initial revision
drewp
parents:
diff changeset
73 for e,func in (('<ButtonPress-1>',b1down),
45b12307c695 Initial revision
drewp
parents:
diff changeset
74 ('<B1-Motion>',b1motion),
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
75 ('<ButtonRelease-1>',b1up),
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
76 ('<ButtonRelease-3>', b3up),
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
77 ('<ButtonPress-3>', b3down)):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
78 w.bind(e,func)
45b12307c695 Initial revision
drewp
parents:
diff changeset
79 # w.bind(e,lambda ev,e=e: eventtoparent(ev,e))
45b12307c695 Initial revision
drewp
parents:
diff changeset
80
45b12307c695 Initial revision
drewp
parents:
diff changeset
81 def colorlabel(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
82 """color the level label based on its own text (which is 0..100)"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
83 txt=self.level_lab['text'] or "0"
45b12307c695 Initial revision
drewp
parents:
diff changeset
84 lev=float(txt)/100
45b12307c695 Initial revision
drewp
parents:
diff changeset
85 low=(80,80,180)
45b12307c695 Initial revision
drewp
parents:
diff changeset
86 high=(255,55,050)
45b12307c695 Initial revision
drewp
parents:
diff changeset
87 out = [int(l+lev*(h-l)) for h,l in zip(high,low)]
45b12307c695 Initial revision
drewp
parents:
diff changeset
88 col="#%02X%02X%02X" % tuple(out)
45b12307c695 Initial revision
drewp
parents:
diff changeset
89 self.level_lab.config(bg=col)
45b12307c695 Initial revision
drewp
parents:
diff changeset
90
45b12307c695 Initial revision
drewp
parents:
diff changeset
91 def setlevel(self,newlev):
45b12307c695 Initial revision
drewp
parents:
diff changeset
92 """the main program is telling us to change our
45b12307c695 Initial revision
drewp
parents:
diff changeset
93 display. newlev is 0..1"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
94 self.currentlevel=newlev
45b12307c695 Initial revision
drewp
parents:
diff changeset
95 newlev="%d"%(newlev*100)
45b12307c695 Initial revision
drewp
parents:
diff changeset
96 olddisplay=self.level_lab.cget('text')
45b12307c695 Initial revision
drewp
parents:
diff changeset
97 if newlev!=olddisplay:
45b12307c695 Initial revision
drewp
parents:
diff changeset
98 self.level_lab.config(text=newlev)
45b12307c695 Initial revision
drewp
parents:
diff changeset
99 self.colorlabel()
45b12307c695 Initial revision
drewp
parents:
diff changeset
100
45b12307c695 Initial revision
drewp
parents:
diff changeset
101 def getlevel(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
102 """returns currently displayed level, 0..1"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
103 return self.currentlevel
45b12307c695 Initial revision
drewp
parents:
diff changeset
104
45b12307c695 Initial revision
drewp
parents:
diff changeset
105 def changelevel(self,newlev):
45b12307c695 Initial revision
drewp
parents:
diff changeset
106
45b12307c695 Initial revision
drewp
parents:
diff changeset
107 """the user is adjusting the level on this widget. the main
45b12307c695 Initial revision
drewp
parents:
diff changeset
108 program needs to hear about it. then the main program will
45b12307c695 Initial revision
drewp
parents:
diff changeset
109 call setlevel()"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
110
45b12307c695 Initial revision
drewp
parents:
diff changeset
111 dispatcher.send("levelchanged",channel=self.channelnum,newlevel=newlev)
45b12307c695 Initial revision
drewp
parents:
diff changeset
112
45b12307c695 Initial revision
drewp
parents:
diff changeset
113 class Levelbox(tk.Frame):
45b12307c695 Initial revision
drewp
parents:
diff changeset
114 def __init__(self, parent, num_channels=68):
45b12307c695 Initial revision
drewp
parents:
diff changeset
115 tk.Frame.__init__(self,parent)
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
116 global stdfont
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
117 stdfont = tkFont.Font(size=9)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
118 self.levels = [] # Onelevel objects
45b12307c695 Initial revision
drewp
parents:
diff changeset
119
45b12307c695 Initial revision
drewp
parents:
diff changeset
120 frames = (make_frame(self), make_frame(self))
45b12307c695 Initial revision
drewp
parents:
diff changeset
121
45b12307c695 Initial revision
drewp
parents:
diff changeset
122 for channel in range(1, num_channels+1):
45b12307c695 Initial revision
drewp
parents:
diff changeset
123
45b12307c695 Initial revision
drewp
parents:
diff changeset
124 # frame for this channel
45b12307c695 Initial revision
drewp
parents:
diff changeset
125 f = Onelevel(frames[channel > (num_channels/2)],channel)
45b12307c695 Initial revision
drewp
parents:
diff changeset
126
45b12307c695 Initial revision
drewp
parents:
diff changeset
127 self.levels.append(f)
45b12307c695 Initial revision
drewp
parents:
diff changeset
128 f.pack(side='top')
45b12307c695 Initial revision
drewp
parents:
diff changeset
129 #dispatcher.connect(setalevel,"setlevel")
45b12307c695 Initial revision
drewp
parents:
diff changeset
130
45b12307c695 Initial revision
drewp
parents:
diff changeset
131 def setlevels(self,newlevels):
45b12307c695 Initial revision
drewp
parents:
diff changeset
132 """sets levels to the new list of dmx levels (0..1). list can
45b12307c695 Initial revision
drewp
parents:
diff changeset
133 be any length"""
45b12307c695 Initial revision
drewp
parents:
diff changeset
134 for l,newlev in zip(self.levels,newlevels):
45b12307c695 Initial revision
drewp
parents:
diff changeset
135 l.setlevel(newlev)