Mercurial > code > home > repos > light9
annotate light8/subediting.py @ 2148:2973ec5df7e4
add dep
author | drewp@bigasterisk.com |
---|---|
date | Wed, 17 May 2023 19:09:01 -0700 |
parents | ddd3c8f04640 |
children |
rev | line source |
---|---|
0 | 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 | |
53 | 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 |
0 | 14 """ |
15 def __init__(self,currentoutputlevels): | |
16 self.sub=None | |
17 self.currentoutputlevels = currentoutputlevels | |
53 | 18 self.widgets={} # subname : widget list |
19 self.oldcolors={} # widget : bgcolor | |
0 | 20 |
53 | 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 | |
0 | 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 | |
53 | 43 self.highlighteditsub() |
103
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
44 def highlighteditsub(self, color='red'): |
53 | 45 """based on how widgets got self.register'd, we highlight |
46 just the row that's being edited""" | |
0 | 47 |
53 | 48 # highlight that row only |
49 for n,wl in self.widgets.items(): | |
103
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
50 if n == self.sub.name: |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
51 self.colorsub(n, color) |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
52 else: |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
53 self.colorsub(n, 'restore') |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
54 |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
55 ''' |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
56 # highlight that row only |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
57 for n,wl in self.widgets.items(): |
53 | 58 if n==self.sub.name: |
59 for w in wl: | |
103
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
60 w.config(bg=color) |
53 | 61 else: |
62 for w in wl: | |
63 w.config(bg=self.oldcolors[w]) | |
103
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
64 ''' |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
65 def colorsub(self, name, color): |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
66 for w in self.widgets[name]: |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
67 if color == 'restore': |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
68 w.config(bg=self.oldcolors[w]) |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
69 else: |
ddd3c8f04640
more untested code, ready for production: colors for slider mapping
dmcc
parents:
53
diff
changeset
|
70 w.config(bg=color) |
53 | 71 |
0 | 72 # |
73 # next two methods are called by the Stage | |
74 # | |
75 def startlevelchange(self): | |
53 | 76 """stage is about to send some level changes. this method is |
77 called by the Stage.""" | |
0 | 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 | |
53 | 97 # print "subedit: level change",lightnames,delta |
0 | 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: | |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
42
diff
changeset
|
109 print "light '%s' isn't even in the patch! skipping" % l |
53 | 110 continue |
0 | 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 |