Mercurial > code > home > repos > light9
annotate light8/stage.py @ 44:6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
rmb adjusts levels
author | drewp |
---|---|
date | Sun, 07 Jul 2002 13:07:31 +0000 |
parents | 115636cca107 |
children | 71489bb71528 |
rev | line source |
---|---|
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
1 from Tkinter import * |
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 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
4 def printevent(ev): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
5 for k in dir(ev): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
6 if not k.startswith('__'): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
7 print k,getattr(ev,k) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
8 print "" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
9 |
0 | 10 |
14 | 11 textstyle={'font':'arial 7','fill':'white'} |
12 | |
13 | |
0 | 14 class Stage(Canvas): |
15 | |
16 """a fancy widget that shows light locations (and optionally their | |
17 aim locations on an image of the stage. you can select or | |
18 multiselect lights and drag them up or down to change their | |
19 brightness. | |
20 | |
21 ctrl-a is select all, | |
22 ctrl-shift-a or clicking on no light deselects all, | |
23 re-clicking a light with shift key down toggles whether it's in the selection. | |
24 ctrl-drag-rectangle deselects the lights in the rectangle, | |
25 shift-drag-rectangle selects the lights in the rectangle, | |
26 drag-rectangle selects only the lights in the rectangle. | |
27 | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
28 a light can be selected on its location point, its aim point |
0 | 29 (which may or may not be present), or its name. |
30 | |
31 lights should be able to be interactively 'locked', which blocks | |
32 them from being selected. | |
33 | |
17 | 34 API: |
35 __init__(parent,**kw) | |
36 put pass any canvas options you want | |
37 | |
38 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
|
39 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
|
40 canvas to the image size |
17 | 41 |
42 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
|
43 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
|
44 back to you in the callback (see below) |
17 | 45 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
46 setsubediting(se) |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
47 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
|
48 'levelchange' messages |
17 | 49 |
50 | |
0 | 51 """ |
52 def __init__(self,parent,**kw): | |
53 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
|
54 |
44
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("<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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 # 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
|
61 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
62 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
|
63 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
64 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
|
65 # 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
|
66 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
67 self.alllights=[] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
68 self.selectedlights=[] |
7 | 69 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
|
70 |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
71 self.subeditor=None |
7 | 72 |
73 def setimage(self,stageimage): | |
74 img = Image('photo',file=stageimage) | |
75 self.img=img # can't lose this! | |
76 print img.width() | |
77 self.create_image(0,0,anchor='nw',image=img) | |
78 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
|
79 |
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
80 def setsubediting(self,subeditor): |
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
81 self.subeditor = subeditor |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
82 # |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
83 # selection management |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
84 # |
7 | 85 def updateselectionboxes(self): |
86 "make selection boxes that match self.selectedlights" | |
87 self.delete("selectbox") | |
88 for l in self.selectedlights: | |
89 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
|
90 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
|
91 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
|
92 |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
93 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
|
94 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
|
95 self.updateselectionboxes() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
96 def clearselection(self): |
7 | 97 self.selectedlights=[] |
98 self.updateselectionboxes() | |
99 | |
100 def markfordynselection(self): | |
101 """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
|
102 self.origselection = self.selectedlights[:] |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
103 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
104 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
|
105 """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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 # 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
|
112 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
|
113 else: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
114 # 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
|
115 self.selectedlights = [l for l in self.origselection if l not in newlightnames] |
7 | 116 self.updateselectionboxes() |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
117 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
118 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
|
119 """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
|
120 if select: |
7 | 121 if lightname not in self.selectedlights: |
122 self.selectedlights.append(lightname) | |
123 elif lightname in self.selectedlights: | |
124 self.selectedlights.remove(lightname) | |
125 | |
126 self.updateselectionboxes() | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
127 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
128 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
129 # |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
130 # mouse handling |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
131 # |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
132 def press(self,ev): |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
133 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
138 button=ev.num |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
139 shifted=ev.state & 1 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 istouching=len(touching)>0 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
144 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
145 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
|
146 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
|
147 # 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
|
148 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
|
149 # 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
|
150 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
|
151 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
|
152 # 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
|
153 self.startrectangleselect() |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
154 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
155 else: |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
156 # 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
|
157 # toggle selection |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
158 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
|
159 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
|
160 # deselect |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
161 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
|
162 # 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
|
163 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
|
164 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
|
165 # 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
|
166 self.clearselection() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
167 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
|
168 # 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
|
169 self.startlevelchange() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
170 |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
171 else: |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
172 # 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
|
173 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
|
174 self.clearselection() |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
175 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
|
176 # and adjust levels now |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
177 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
|
178 |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
179 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
|
180 self.startlevelchange() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
181 |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
182 def motion(self,ev): |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
183 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
184 coords=(ev.x,ev.y) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
185 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
186 shifted=ev.state & 1 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
187 control=ev.state & 4 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
188 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
189 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
|
190 if (coords[0]-self.mousedownpos[0])**2+(coords[1]-self.mousedownpos[1])**2>self.halo**2: |
7 | 191 # 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
|
192 self.startrectangleselect() |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
193 |
7 | 194 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
195 if self.mode=='levelchange': |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
196 delta = (self.mousedownpos[1]-ev.y) |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
197 if self.subeditor: |
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
198 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
|
199 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
200 if self.mode=='rectangle': |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
201 sr = self.find_withtag('selectrect') |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
202 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
|
203 # 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
|
204 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
|
205 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
|
206 |
8 | 207 # 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
|
208 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
|
209 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
210 # 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
|
211 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
|
212 subtract=control) |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
213 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
214 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
|
215 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
|
216 if self.mode=='rectangle': |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
217 self.delete('selectrect') |
7 | 218 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
219 if self.mode=='deselect-or-rectangle': |
7 | 220 # they didn't move enough to promote the mode to level, so it's a deselect click |
221 self.clearselection() | |
0 | 222 |
44
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
223 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
|
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 # |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
227 # |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
228 |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
229 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
|
230 """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
|
231 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
|
232 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
|
233 self.mode='levelchange' |
37
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
234 if self.subeditor: |
115636cca107
subeditor begins to work - stage makes the right calls to subeditor now
drewp
parents:
17
diff
changeset
|
235 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
|
236 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
|
237 """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
|
238 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
|
239 self.markfordynselection() |
7 | 240 # |
241 # light names vs. canvas object tags | |
242 # | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
243 def nametag(self,name): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
244 "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
|
245 return name.replace(" ","__") |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
246 |
7 | 247 def tagtoname(self,tag): |
248 "finds the real light name for a tag written by nametag()" | |
249 return self.alllighttags[tag] | |
250 | |
251 # | |
252 # light methods | |
253 # | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
254 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
|
255 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
|
256 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
257 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
|
258 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
|
259 fill='red',tag=tags+" hotspot") |
7 | 260 if aim: |
261 self.create_oval(aim[0]-2,aim[1]-2, | |
262 aim[0]+2,aim[1]+2, | |
263 fill='red',tag=tags+" hotspot") | |
14 | 264 self.create_line(location[0],location[1],aim[0],aim[1],fill='lightblue', |
7 | 265 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
|
266 # shadow |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 # text |
14 | 271 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
|
272 |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
273 self.alllights.append(name) |
7 | 274 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
|
275 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
276 def getlightbboxes(self,tag): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
277 """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
|
278 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
|
279 bboxes=[] |
7 | 280 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
|
281 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
|
282 bboxes.append(self.bbox(o)) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
283 return bboxes |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
284 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
285 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
|
286 "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
|
287 lights=[] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
288 if enclosed: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
289 candidates = self.find_enclosed(*box) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
290 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
291 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
|
292 |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
293 for o in candidates: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
294 for t in self.gettags(o): |
7 | 295 if t.startswith("name_"): |
296 n = self.tagtoname(t[5:]) | |
297 if n and (n not in lights): | |
298 lights.append(n) | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
299 return lights |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
300 |
10 | 301 |
14 | 302 def createlights(s): |
303 s.setimage('guysanddolls.gif') | |
304 s.addlight('desk1',(46, 659), aim=(210, 381)) | |
305 s.addlight('marry1',(78, 661), aim=(398, 428)) | |
306 s.addlight('b13',(110, 661)) | |
307 s.addlight('hotbox1',(147, 657), aim=(402, 327)) | |
308 s.addlight('edge',(179, 651), aim=(116, 441)) | |
309 s.addlight('phone',(214, 652), aim=(651, 417)) | |
310 s.addlight('cuba1',(315, 656), aim=(559, 407)) | |
311 s.addlight('b22',(347, 661), aim=(247, 458)) | |
312 s.addlight('b23',(379, 661)) | |
313 s.addlight('b24',(417, 661)) | |
314 s.addlight('b25',(455, 658), aim=(520, 466)) | |
315 s.addlight('desk2',(490, 655), aim=(237, 375)) | |
316 s.addlight('rock',(571, 655), aim=(286, 304)) | |
317 s.addlight('b32',(606, 650)) | |
318 s.addlight('hotbox2',(637, 650), aim=(433, 337)) | |
319 s.addlight('b34',(671, 651)) | |
320 s.addlight('marry2',(703, 651), aim=(429, 426)) | |
321 s.addlight('cuba2',(733, 652), aim=(602, 408)) | |
322 | |
323 s.addlight('sidefill1',(115, 473),aim=(228, 423)) | |
324 s.addlight('sidefill2',(617, 475),aim=(526, 425)) | |
325 | |
326 s.addlight('cycright',(485, 164),(483, 109)) | |
327 s.addlight('cycleft',(330, 154),(333, 108)) | |
328 | |
329 s.addlight('upfill1',(275, 325),(262, 237)) | |
330 s.addlight('upfill2',(333, 326),(330, 229)) | |
331 s.addlight('upfill3',(473, 325),(454, 226)) | |
332 s.addlight('upfill4',(541, 325),(528, 223)) | |
333 | |
334 s.addlight('god',(369,549)) | |
335 | |
336 s.addlight('patio1',(42, 560),(12, 512)) | |
337 s.addlight('patio2',(675, 553),(793, 514)) | |
338 | |
339 s.addlight('hotback',(413, 476),(414, 396)) | |
10 | 340 |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
341 |
14 | 342 |
343 if __name__=='__main__': | |
344 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
|
345 root.tk_focusFollowsMouse() |
14 | 346 root.wm_geometry("+376+330") |
347 s=Stage(root) | |
348 s.setimage('guysanddolls.gif') | |
349 s.pack() | |
350 | |
351 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
|
352 |
6540879e336e
fixed Stage a lot: ctrl-drag subtracts from selection; ctrl-a/ctrl-A select all/none;
drewp
parents:
37
diff
changeset
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 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
|
359 |
14 | 360 root.mainloop() |
361 |