Mercurial > code > home > repos > light9
annotate light8/stage.py @ 59:001646cd5349
all mousewheel events everywhere will now pass up the tree to be caught by
all mousewheel events everywhere will now pass up the tree to be caught by
higher widgets. if things get slow, this might be the problem
author | drewp |
---|---|
date | Tue, 09 Jul 2002 07:36:29 +0000 |
parents | 032b2b67bc10 |
children | 2f2eb802e93d |
rev | line source |
---|---|
51
71489bb71528
- Meet Fader. He is going to grow up and be a crossfader some day
dmcc
parents:
44
diff
changeset
|
1 from Tix import * |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
2 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
3 def printevent(ev): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
4 for k in dir(ev): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
5 if not k.startswith('__'): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
6 print k,getattr(ev,k) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
7 print "" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
8 |
53 | 9 textstyle={'font':'arial 9','fill':'white'} |
14 | 10 |
0 | 11 class Stage(Canvas): |
12 | |
13 """a fancy widget that shows light locations (and optionally their | |
14 aim locations on an image of the stage. you can select or | |
15 multiselect lights and drag them up or down to change their | |
16 brightness. | |
17 | |
18 ctrl-a is select all, | |
19 ctrl-shift-a or clicking on no light deselects all, | |
20 re-clicking a light with shift key down toggles whether it's in the selection. | |
21 ctrl-drag-rectangle deselects the lights in the rectangle, | |
22 shift-drag-rectangle selects the lights in the rectangle, | |
23 drag-rectangle selects only the lights in the rectangle. | |
24 | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
25 a light can be selected on its location point, its aim point |
0 | 26 (which may or may not be present), or its name. |
27 | |
28 lights should be able to be interactively 'locked', which blocks | |
29 them from being selected. | |
30 | |
17 | 31 API: |
32 __init__(parent,**kw) | |
33 put pass any canvas options you want | |
34 | |
35 setimage(stageimage) | |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
36 sets image to given filename (ppm, gif, etc) and resizes the |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
37 canvas to the image size |
17 | 38 |
39 addlight(name, location, aim=None) | |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
40 location and aim are pixel coord tuples. name will be passed |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
41 back to you in the callback (see below) |
17 | 42 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
43 setsubediting(se) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
44 give a subediting object to receive the 'startlevelchange' and |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
45 'levelchange' messages |
17 | 46 |
47 | |
0 | 48 """ |
49 def __init__(self,parent,**kw): | |
50 Canvas.__init__(self,parent,**kw) | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
51 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
52 self.bind("<ButtonPress>", self.press) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
53 self.bind("<Motion>", self.motion) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
54 self.bind("<ButtonRelease>", self.release) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
55 self.bind("<Control-Key-a>", lambda ev: self.selectall()) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
56 self.bind("<Control-Key-A>", lambda ev: self.clearselection()) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
57 # self.bind("<Control-Shift-Key-a>",self.handlecontrol_a) |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
58 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
59 self.halo=11 # search radius for clicked items |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
60 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
61 self.mode=None # as you perform with the mouse, this goes |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
62 # from None to 'pressed','rectangle','levelchange', etc |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
63 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
64 self.alllights=[] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
65 self.selectedlights=[] |
7 | 66 self.alllighttags={} # tag: name lookup |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
67 |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
68 self.subeditor=None |
7 | 69 |
70 def setimage(self,stageimage): | |
71 img = Image('photo',file=stageimage) | |
72 self.img=img # can't lose this! | |
73 print img.width() | |
74 self.create_image(0,0,anchor='nw',image=img) | |
75 self.config(width=img.width(),height=img.height()) | |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
76 |
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
77 def setsubediting(self,subeditor): |
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
78 self.subeditor = subeditor |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
79 # |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
80 # selection management |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
81 # |
7 | 82 def updateselectionboxes(self): |
83 "make selection boxes that match self.selectedlights" | |
84 self.delete("selectbox") | |
85 for l in self.selectedlights: | |
86 for c in self.getlightbboxes(l): | |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
87 self.create_rectangle(c[0]-2,c[1]-2,c[2]+2,c[3]+2, |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
88 outline='red',tag="selectbox") |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
89 |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
90 def selectall(self): |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
91 self.selectedlights= self.alllights[:] |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
92 self.updateselectionboxes() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
93 def clearselection(self): |
7 | 94 self.selectedlights=[] |
95 self.updateselectionboxes() | |
96 | |
97 def markfordynselection(self): | |
98 """call this before calls to replacedynselection""" | |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
99 self.origselection = self.selectedlights[:] |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
100 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
101 def replacedynselection(self,newlightnames,subtract=0): |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
102 """as a dynamic selection changes, keep calling this function |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
103 with the names of the lights in the dynamic selection. the |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
104 original selection (at the time of markfordynselection) will |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
105 be shown along with any new lights. if subtract=1, the selection will |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
106 be shown MINUS the newlights.""" |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
107 if subtract==0: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
108 # orig selection plus any newlights that weren't in the orig selection |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
109 self.selectedlights = self.origselection[:] + [l for l in newlightnames if l not in self.origselection] |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
110 else: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
111 # orig selection lights except those that are in the newlightnames list |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
112 self.selectedlights = [l for l in self.origselection if l not in newlightnames] |
7 | 113 self.updateselectionboxes() |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
114 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
115 def select(self,lightname,select=1): # select=0 for deselect |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
116 """select or deselect (select=0) a light by name""" |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
117 if select: |
7 | 118 if lightname not in self.selectedlights: |
119 self.selectedlights.append(lightname) | |
120 elif lightname in self.selectedlights: | |
121 self.selectedlights.remove(lightname) | |
122 | |
123 self.updateselectionboxes() | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
124 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
125 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
126 # |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
127 # mouse handling |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
128 # |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
129 def press(self,ev): |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
130 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
131 self.mode='pressed' |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
132 self.mousedownpos=(ev.x,ev.y) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
133 print "click at",self.mousedownpos |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
134 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
135 button=ev.num |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
136 shifted=ev.state & 1 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
137 control=ev.state & 4 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
138 touching=self.findoverlappinglights((ev.x-self.halo,ev.y-self.halo, |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
139 ev.x+self.halo,ev.y+self.halo)) |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
140 istouching=len(touching)>0 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
141 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
142 if button==1: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
143 if not istouching: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
144 # clicked in space |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
145 if not shifted and not control and len(self.selectedlights)>0: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
146 # either a deselect (if no motion) or a level change (if motion) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
147 self.mode = 'deselect-or-rectangle' |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
148 if shifted or control or len(self.selectedlights)==0: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
149 # with shift/control, add/subtract lights to selection |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
150 self.startrectangleselect() |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
151 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
152 else: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
153 # clicked a selectable object |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
154 # toggle selection |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
155 if touching[0] in self.selectedlights: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
156 if shifted or control: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
157 # deselect |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
158 self.select(touching[0],0) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
159 # and do nothing else |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
160 self.mode=None |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
161 if not shifted: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
162 # select only this light |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
163 self.clearselection() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
164 self.select(touching[0]) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
165 # and adjust its level |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
166 self.startlevelchange() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
167 |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
168 else: |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
169 # clicked a light that wasn't selected |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
170 if not shifted: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
171 self.clearselection() |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
172 self.select(touching[0]) |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
173 # and adjust levels now |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
174 self.startlevelchange() |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
175 |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
176 if button==3: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
177 self.startlevelchange() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
178 |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
179 def motion(self,ev): |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
180 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
181 coords=(ev.x,ev.y) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
182 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
183 shifted=ev.state & 1 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
184 control=ev.state & 4 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
185 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
186 if self.mode=='deselect-or-rectangle': |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
187 if (coords[0]-self.mousedownpos[0])**2+(coords[1]-self.mousedownpos[1])**2>self.halo**2: |
53 | 188 if not shifted and not control: |
189 self.clearselection() | |
7 | 190 # they moved enough, it's a level change |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
191 self.startrectangleselect() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
192 |
7 | 193 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
194 if self.mode=='levelchange': |
53 | 195 delta = 1.5 * (self.mousedownpos[1]-ev.y) |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
196 if self.subeditor: |
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
197 self.subeditor.levelchange(self.selectedlights,delta) |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
198 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
199 if self.mode=='rectangle': |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
200 sr = self.find_withtag('selectrect') |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
201 if not sr: |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
202 # make the selection rectangle |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
203 sr=self.create_rectangle( self.mousedownpos[0],self.mousedownpos[1],coords[0],coords[1], |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
204 outlinestipple='gray50',outline='yellow',tag='selectrect') |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
205 |
8 | 206 # move rectangle with mouse |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
207 self.coords(sr,*(self.mousedownpos+coords)) |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
208 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
209 # redo the dynselection with the new rectangle |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
210 self.replacedynselection(self.findoverlappinglights((self.mousedownpos+coords),1), |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
211 subtract=control) |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
212 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
213 def release(self,ev): |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
214 if self.mode: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
215 if self.mode=='rectangle': |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
216 self.delete('selectrect') |
7 | 217 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
218 if self.mode=='deselect-or-rectangle': |
7 | 219 # they didn't move enough to promote the mode to level, so it's a deselect click |
220 self.clearselection() | |
0 | 221 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
222 self.mode=None |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
223 |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
224 # |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
225 # |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
226 # |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
227 |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
228 def startlevelchange(self): |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
229 """sets mode to levelchange AND notifies subeditor. this |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
230 should be done exactly once (per mouse drag), when you first |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
231 decide the mode is levelchange""" |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
232 self.mode='levelchange' |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
233 if self.subeditor: |
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
234 self.subeditor.startlevelchange() |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
235 def startrectangleselect(self): |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
236 """sets mode to rectangle AND checkpoints the current selection""" |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
237 self.mode='rectangle' |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
238 self.markfordynselection() |
7 | 239 # |
240 # light names vs. canvas object tags | |
241 # | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
242 def nametag(self,name): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
243 "returns a safe version of the name that won't match other names" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
244 return name.replace(" ","__") |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
245 |
7 | 246 def tagtoname(self,tag): |
247 "finds the real light name for a tag written by nametag()" | |
248 return self.alllighttags[tag] | |
249 | |
250 # | |
251 # light methods | |
252 # | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
253 def addlight(self,name,location,aim=None): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
254 tags='light selectable name_%s' % self.nametag(name) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
255 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
256 self.create_oval(location[0]-2,location[1]-2, |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
257 location[0]+2,location[1]+2, |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
258 fill='red',tag=tags+" hotspot") |
7 | 259 if aim: |
260 self.create_oval(aim[0]-2,aim[1]-2, | |
261 aim[0]+2,aim[1]+2, | |
262 fill='red',tag=tags+" hotspot") | |
14 | 263 self.create_line(location[0],location[1],aim[0],aim[1],fill='lightblue', |
7 | 264 arrow='last',arrowshape="9 15 6",tag='light') |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
265 # shadow |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
266 self.create_text(location[0]-1,location[1]+6, |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
267 anchor='n',text=name,fill='black', |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
268 tag=tags,**dict([(k,v) for k,v in textstyle.items() if k!='fill'])) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
269 # text |
14 | 270 self.create_text(location[0],location[1]+5,anchor='n',text=name,tag=tags,**textstyle) |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
271 |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
272 self.alllights.append(name) |
7 | 273 self.alllighttags[self.nametag(name)]=name |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
274 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
275 def getlightbboxes(self,tag): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
276 """returns a list of bboxes for a light with a given name_ tag. the selection |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
277 mechanism draws around these bboxes to show that a light is selected""" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
278 bboxes=[] |
7 | 279 for o in self.find_withtag("name_%s" % self.nametag(tag)): |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
280 if 'hotspot' in self.gettags(o): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
281 bboxes.append(self.bbox(o)) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
282 return bboxes |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
283 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
284 def findoverlappinglights(self,box,enclosed=0): |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
285 "returns all the different names for lights that are within (or enclosed by) the box" |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
286 lights=[] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
287 if enclosed: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
288 candidates = self.find_enclosed(*box) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
289 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
290 candidates = self.find_overlapping(*box) |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
291 |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
292 for o in candidates: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
293 for t in self.gettags(o): |
7 | 294 if t.startswith("name_"): |
295 n = self.tagtoname(t[5:]) | |
296 if n and (n not in lights): | |
297 lights.append(n) | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
298 return lights |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
299 |
10 | 300 |
14 | 301 def createlights(s): |
302 s.setimage('guysanddolls.gif') | |
303 s.addlight('desk1',(46, 659), aim=(210, 381)) | |
304 s.addlight('marry1',(78, 661), aim=(398, 428)) | |
305 s.addlight('b13',(110, 661)) | |
306 s.addlight('hotbox1',(147, 657), aim=(402, 327)) | |
307 s.addlight('edge',(179, 651), aim=(116, 441)) | |
308 s.addlight('phone',(214, 652), aim=(651, 417)) | |
309 s.addlight('cuba1',(315, 656), aim=(559, 407)) | |
310 s.addlight('b22',(347, 661), aim=(247, 458)) | |
311 s.addlight('b23',(379, 661)) | |
312 s.addlight('b24',(417, 661)) | |
313 s.addlight('b25',(455, 658), aim=(520, 466)) | |
314 s.addlight('desk2',(490, 655), aim=(237, 375)) | |
315 s.addlight('rock',(571, 655), aim=(286, 304)) | |
316 s.addlight('b32',(606, 650)) | |
317 s.addlight('hotbox2',(637, 650), aim=(433, 337)) | |
318 s.addlight('b34',(671, 651)) | |
319 s.addlight('marry2',(703, 651), aim=(429, 426)) | |
320 s.addlight('cuba2',(733, 652), aim=(602, 408)) | |
321 | |
322 s.addlight('sidefill1',(115, 473),aim=(228, 423)) | |
323 s.addlight('sidefill2',(617, 475),aim=(526, 425)) | |
324 | |
325 s.addlight('cycright',(485, 164),(483, 109)) | |
326 s.addlight('cycleft',(330, 154),(333, 108)) | |
327 | |
328 s.addlight('upfill1',(275, 325),(262, 237)) | |
329 s.addlight('upfill2',(333, 326),(330, 229)) | |
330 s.addlight('upfill3',(473, 325),(454, 226)) | |
331 s.addlight('upfill4',(541, 325),(528, 223)) | |
332 | |
333 s.addlight('god',(369,549)) | |
334 | |
335 s.addlight('patio1',(42, 560),(12, 512)) | |
336 s.addlight('patio2',(675, 553),(793, 514)) | |
337 | |
338 s.addlight('hotback',(413, 476),(414, 396)) | |
10 | 339 |
53 | 340 s.addlight('main 2',(120, 563) ,aim=(241, 472)) |
341 s.addlight('main 3',(162, 562) ,aim=(140, 425)) | |
342 s.addlight('main 4',(208, 560) ,aim=(342, 423)) | |
343 s.addlight('main 5',(259, 558) ,aim=(433, 450)) | |
344 s.addlight('main 7',(494, 551) ,aim=(420, 458)) | |
345 s.addlight('main 8',(528, 554) ,aim=(503, 477)) | |
346 s.addlight('main 9',(559, 554) ,aim=(544, 479)) | |
347 s.addlight('main 10',(597, 556),aim=(339, 444)) | |
348 s.addlight('main 11',(636, 556),aim=(449, 409)) | |
349 | |
350 s.addlight('sidepost2', (785, 609)) | |
351 s.addlight('sidepost1', (8, 613)) | |
352 | |
353 | |
354 | |
355 | |
356 | |
357 | |
358 | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
359 |
14 | 360 |
361 if __name__=='__main__': | |
362 root=Tk() | |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
363 root.tk_focusFollowsMouse() |
14 | 364 root.wm_geometry("+376+330") |
365 s=Stage(root) | |
366 s.setimage('guysanddolls.gif') | |
367 s.pack() | |
368 | |
369 createlights(s) | |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
370 |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
371 class subediting_standin: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
372 def startlevelchange(self): |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
373 print "start lev change" |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
374 def levelchange(self,lights,delta): |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
375 print "change",lights,delta |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
376 s.setsubediting(subediting_standin()) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
377 |
14 | 378 root.mainloop() |
379 |