comparison light8/subediting.py @ 0:45b12307c695

Initial revision
author drewp
date Wed, 03 Jul 2002 09:37:57 +0000
parents
children 02151923be45
comparison
equal deleted inserted replaced
-1:000000000000 0:45b12307c695
1
2 from Patch import get_dmx_channel
3
4 class Subediting:
5 """this class accepts input from Stage and edits subs. the
6 Subpanels have widgets to tell us what subs to edit and when to
7 save them. this Subediting object has no UI of its own.
8
9 20:41:10 drewp: there are some funny rules
10 20:41:37 drewp: if you drag a light that's in the sub you're editing, you'll adjust it from it's position in the sub (Even if that sub is not visialbe, or if the light is doing someting else)
11 20:41:57 drewp: but if you touch a light that wasnt in the sub, the current light brightness from the stage gets copied into the sub, and then you adjust frmo there
12 20:42:05 drewp: i dont know any other rules; but these seem odd
13 20:42:29 drewp: it may be necessary to highluight which lights are already in the sub, so you know what you're doing as soon as you click on one
14 """
15 def __init__(self,currentoutputlevels):
16 self.sub=None
17 self.currentoutputlevels = currentoutputlevels
18 self.widgets={} # subname : widget list
19 self.oldcolors={} # widget : bgcolor
20
21 def refresh(self):
22 self.sub=None # this wouldn't last even if we wanted it to;
23 # the Sub objects are rebuilt upon reload
24 self.widgets={}
25 self.oldcolors={}
26
27 def register(self,subname,widget):
28 """tell subediting about any widgets that should be highlighted
29 when a sub is being edited"""
30 if subname not in self.widgets:
31 self.widgets[subname]=[]
32 self.widgets[subname].append(widget)
33 self.oldcolors[widget] = widget.cget('bg')
34
35 def setsub(self,sub):
36 """sets which (one) sub object should the stage be editing.
37
38 this is called by widgets that are set up in the Subpanels interfaces.
39 """
40
41 print "subedit: editing ",sub.name
42 self.sub = sub
43 self.highlighteditsub()
44 def highlighteditsub(self, color='red'):
45 """based on how widgets got self.register'd, we highlight
46 just the row that's being edited"""
47
48 # highlight that row only
49 for n,wl in self.widgets.items():
50 if n == self.sub.name:
51 self.colorsub(n, color)
52 else:
53 self.colorsub(n, 'restore')
54
55 '''
56 # highlight that row only
57 for n,wl in self.widgets.items():
58 if n==self.sub.name:
59 for w in wl:
60 w.config(bg=color)
61 else:
62 for w in wl:
63 w.config(bg=self.oldcolors[w])
64 '''
65 def colorsub(self, name, color):
66 for w in self.widgets[name]:
67 if color == 'restore':
68 w.config(bg=self.oldcolors[w])
69 else:
70 w.config(bg=color)
71
72 #
73 # next two methods are called by the Stage
74 #
75 def startlevelchange(self):
76 """stage is about to send some level changes. this method is
77 called by the Stage."""
78 print "subedit: start-------"
79 if self.sub is None:
80 print "not editing any sub!"
81 return
82
83 self.startlevels = self.sub.getlevels()
84
85 def getcurrentlevel(self,lightname):
86 try:
87 ch = get_dmx_channel(lightname)
88 except ValueError:
89 return None
90 return self.currentoutputlevels[ch]
91
92 def levelchange(self,lightnames,delta):
93 """stage sends this message with its light names and a delta
94 0..1 measured from the last startlevelchange call. this method is
95 called by the Stage"""
96
97 # print "subedit: level change",lightnames,delta
98 if self.sub is None:
99 print "not editing any sub!"
100 return
101
102 updatelevels={}
103
104 for l in lightnames:
105 if l not in self.startlevels:
106 # level was not in the sub
107 cl = self.getcurrentlevel(l)
108 if cl is None:
109 print "light '%s' isn't even in the patch! skipping" % l
110 continue
111 print "copying current light level",cl,"into the sub"
112 self.startlevels[l] = cl
113
114 updatelevels[l] = min(100,max(0,self.startlevels[l]+delta))
115
116 self.sub.reviselevels(updatelevels)
117