annotate light8/stage.py @ 17:43aa1ee8b3a9

some comments and garbage cleanup
author drewp
date Sun, 07 Jul 2002 06:43:40 +0000
parents 95ba7e14d15a
children 115636cca107
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
10
14
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
11 textstyle={'font':'arial 7','fill':'white'}
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
12
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
13
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
14 class Stage(Canvas):
45b12307c695 Initial revision
drewp
parents:
diff changeset
15
45b12307c695 Initial revision
drewp
parents:
diff changeset
16 """a fancy widget that shows light locations (and optionally their
45b12307c695 Initial revision
drewp
parents:
diff changeset
17 aim locations on an image of the stage. you can select or
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 multiselect lights and drag them up or down to change their
45b12307c695 Initial revision
drewp
parents:
diff changeset
19 brightness.
45b12307c695 Initial revision
drewp
parents:
diff changeset
20
45b12307c695 Initial revision
drewp
parents:
diff changeset
21 ctrl-a is select all,
45b12307c695 Initial revision
drewp
parents:
diff changeset
22 ctrl-shift-a or clicking on no light deselects all,
45b12307c695 Initial revision
drewp
parents:
diff changeset
23 re-clicking a light with shift key down toggles whether it's in the selection.
45b12307c695 Initial revision
drewp
parents:
diff changeset
24 ctrl-drag-rectangle deselects the lights in the rectangle,
45b12307c695 Initial revision
drewp
parents:
diff changeset
25 shift-drag-rectangle selects the lights in the rectangle,
45b12307c695 Initial revision
drewp
parents:
diff changeset
26 drag-rectangle selects only the lights in the rectangle.
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
45b12307c695 Initial revision
drewp
parents:
diff changeset
29 (which may or may not be present), or its name.
45b12307c695 Initial revision
drewp
parents:
diff changeset
30
45b12307c695 Initial revision
drewp
parents:
diff changeset
31 lights should be able to be interactively 'locked', which blocks
45b12307c695 Initial revision
drewp
parents:
diff changeset
32 them from being selected.
45b12307c695 Initial revision
drewp
parents:
diff changeset
33
17
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
34 API:
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
35 __init__(parent,**kw)
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
36 put pass any canvas options you want
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
37
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
38 setimage(stageimage)
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
39 sets image to given filename (ppm, gif, etc) and resizes the canvas to the image size
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
40
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
41 addlight(name, location, aim=None)
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
42 location and aim are pixel coord tuples. name will be passed back to you in the callback (see below)
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
43
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
44 setlightchangecb(cb)
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
45 give a function which will be called like this: cb(list_of_light_names, delta)
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
46
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
47
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
48 """
45b12307c695 Initial revision
drewp
parents:
diff changeset
49 def __init__(self,parent,**kw):
45b12307c695 Initial revision
drewp
parents:
diff changeset
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
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
52 self.bind("<ButtonPress-1>", self.leftpress)
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
53 self.bind("<B1-Motion>", self.leftmotion)
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
54 self.bind("<ButtonRelease-1>", self.leftrelease)
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
55
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
56 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
57
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
58 self.lmbstate=None # as you perform with LMB, this goes from None to 'pressed','rectangle','levelchange'
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
59
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
60 self.alllights=[]
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
61 self.selectedlights=[]
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
62 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
63
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
64
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
65 def setimage(self,stageimage):
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
66 img = Image('photo',file=stageimage)
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
67 self.img=img # can't lose this!
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
68 print img.width()
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
69 self.create_image(0,0,anchor='nw',image=img)
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
70 self.config(width=img.width(),height=img.height())
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
71
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
72 #
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
73 # selection management
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
74 #
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
75 def updateselectionboxes(self):
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
76 "make selection boxes that match self.selectedlights"
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
77 self.delete("selectbox")
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
78 for l in self.selectedlights:
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
79 for c in self.getlightbboxes(l):
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
80 self.create_rectangle(c[0]-2,c[1]-2,c[2]+2,c[3]+2,outline='red',tag="selectbox")
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
81
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
82 def clearselection(self,dyn=0):
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
83 self.selectedlights=[]
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
84 self.updateselectionboxes()
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
85
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
86 def markfordynselection(self):
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
87 """call this before calls to replacedynselection"""
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
88 self.origselection = self.selectedlights
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
89
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
90 def replacedynselection(self,newlightnames):
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
91 """as a dynamic selection changes, keep calling this function with the
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
92 names of the lights in the dynamic selection. the original selection (at the time
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
93 of markfordynselection) will be shown along with any new lights"""
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
94 self.selectedlights = self.origselection + [l for l in newlightnames if l not in self.origselection]
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
95 self.updateselectionboxes()
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
96
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
97 def select(self,lightname,select=1,dyn=0): # select=0 for deselect
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
98 if select:
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
99 if lightname not in self.selectedlights:
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
100 self.selectedlights.append(lightname)
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
101 elif lightname in self.selectedlights:
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
102 self.selectedlights.remove(lightname)
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
103
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
104 self.updateselectionboxes()
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
105
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
106
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
107 #
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
108 # LMB click or drag
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
109 #
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
110 def leftpress(self,ev):
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
111
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
112 self.lmbstate='pressed'
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
113 self.lmbstart=(ev.x,ev.y)
10
533ac835083f some real lights
drewp
parents: 8
diff changeset
114 print "click at",self.lmbstart
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
115
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
116 shifted=ev.state & 1
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
117 control=ev.state & 4
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
118 touching=self.findoverlappinglights((ev.x-self.halo,ev.y-self.halo,ev.x+self.halo,ev.y+self.halo))
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
119 istouching=len(touching)>0
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
120
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
121 if not istouching:
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
122 # clicked in space
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
123 if not shifted and not control and len(self.selectedlights)>0:
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
124 # either a deselect (if no motion) or a level change (if motion)
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
125 self.lmbstate = 'deselect-or-level'
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
126 if shifted or control or len(self.selectedlights)==0:
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
127 # with shift/control, add/subtract lights to selection
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
128 self.lmbstate='rectangle'
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
129
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
130 else:
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
131 # clicked a selectable object
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
132 # toggle selection
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
133 if touching[0] in self.selectedlights:
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
134 if shifted:
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
135 # deselect
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
136 self.select(touching[0],0)
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
137 # and do nothing else
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
138 self.lmbstate=None
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
139 else:
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
140 # select only this light
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
141 self.clearselection()
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
142 self.select(touching[0])
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
143 # and adjust its level
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
144 self.lmbstate='levelchange'
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
145
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
146 else:
17
43aa1ee8b3a9 some comments and garbage cleanup
drewp
parents: 14
diff changeset
147 # clicked a light that wasn't selected
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
148 if not shifted:
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
149 self.clearselection()
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
150 self.select(touching[0])
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
151 # and adjust levels now
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
152 self.lmbstate='levelchange'
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
153
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
154 if self.lmbstate=='rectangle':
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
155 self.markfordynselection()
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
156 def leftmotion(self,ev):
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
157
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
158 coords=(ev.x,ev.y)
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
159
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
160 shifted=ev.state & 1
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
161 control=ev.state & 4
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
162
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
163 if self.lmbstate=='deselect-or-level':
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
164 if (coords[0]-self.lmbstart[0])**2+(coords[1]-self.lmbstart[1])**2>self.halo**2:
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
165 # they moved enough, it's a level change
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
166 self.lmbstate='levelchange'
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
167
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
168 if self.lmbstate=='levelchange':
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
169 delta = self.lmbstart[1]-ev.y
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
170 print "change by",delta
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
171
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
172 if self.lmbstate=='rectangle':
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
173 sr = self.find_withtag('selectrect')
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
174 if not sr:
8
6faae180d1c5 conv image to gif, clean up source formatting
drewp
parents: 7
diff changeset
175 sr=self.create_rectangle( self.lmbstart[0],self.lmbstart[1],coords[0],coords[1],
14
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
176 outlinestipple='gray50',outline='yellow',
8
6faae180d1c5 conv image to gif, clean up source formatting
drewp
parents: 7
diff changeset
177 tag='selectrect')
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
178
8
6faae180d1c5 conv image to gif, clean up source formatting
drewp
parents: 7
diff changeset
179 # move rectangle with mouse
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
180 self.coords(sr,*(self.lmbstart+coords))
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
181
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
182 # redo the dynselection with the new rectangle
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
183 self.replacedynselection([o for o in self.findoverlappinglights((self.lmbstart+coords),1)])
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
184
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
185 # need to handle ctrl
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
186
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
187 def leftrelease(self,ev):
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
188 if self.lmbstate:
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
189
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
190 if self.lmbstate=='rectangle':
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
191 self.delete('selectrect')
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
192
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
193 if self.lmbstate=='deselect-or-level':
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
194 # they didn't move enough to promote the mode to level, so it's a deselect click
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
195 self.clearselection()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
196
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
197 # all items that were in dynselection join the selection
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
198 # self.incorporatedynselection()
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
199
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
200 self.lmbstate=None
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
201
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
202 #
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
203 # light names vs. canvas object tags
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
204 #
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
205 def nametag(self,name):
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
206 "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
207 return name.replace(" ","__")
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
208
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
209 def tagtoname(self,tag):
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
210 "finds the real light name for a tag written by nametag()"
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
211 return self.alllighttags[tag]
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
212
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
213 #
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
214 # light methods
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
215 #
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
216 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
217 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
218
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
219 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
220 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
221 fill='red',tag=tags+" hotspot")
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
222 if aim:
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
223 self.create_oval(aim[0]-2,aim[1]-2,
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
224 aim[0]+2,aim[1]+2,
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
225 fill='red',tag=tags+" hotspot")
14
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
226 self.create_line(location[0],location[1],aim[0],aim[1],fill='lightblue',
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
227 arrow='last',arrowshape="9 15 6",tag='light')
14
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
228 self.create_text(location[0]-1,location[1]+6,anchor='n',text=name,fill='black',tag=tags,**dict([(k,v) for k,v in textstyle.items() if k!='fill']))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
229 self.create_text(location[0],location[1]+5,anchor='n',text=name,tag=tags,**textstyle)
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
230 self.alllights.append(name)
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
231 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
232
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
233 def getlightbboxes(self,tag):
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
234 """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
235 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
236 bboxes=[]
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
237 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
238 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
239 bboxes.append(self.bbox(o))
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
240 return bboxes
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
241
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
242 def findoverlappinglights(self,box,enclosed=0):
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
243 "returns all the different name_ tags for lights that are within (or enclosed by) the box"
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
244 lights=[]
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
245 if enclosed:
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
246 candidates = self.find_enclosed(*box)
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
247 else:
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
248 candidates = self.find_overlapping(*box)
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
249
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
250 for o in candidates:
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
251 for t in self.gettags(o):
7
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
252 if t.startswith("name_"):
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
253 n = self.tagtoname(t[5:])
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
254 if n and (n not in lights):
1b0266dd233a picking and dragging works pretty well (no ctrl yet)
drewp
parents: 6
diff changeset
255 lights.append(n)
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
256 return lights
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
257
10
533ac835083f some real lights
drewp
parents: 8
diff changeset
258
14
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
259 def createlights(s):
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
260 s.setimage('guysanddolls.gif')
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
261 s.addlight('desk1',(46, 659), aim=(210, 381))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
262 s.addlight('marry1',(78, 661), aim=(398, 428))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
263 s.addlight('b13',(110, 661))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
264 s.addlight('hotbox1',(147, 657), aim=(402, 327))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
265 s.addlight('edge',(179, 651), aim=(116, 441))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
266 s.addlight('phone',(214, 652), aim=(651, 417))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
267 s.addlight('cuba1',(315, 656), aim=(559, 407))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
268 s.addlight('b22',(347, 661), aim=(247, 458))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
269 s.addlight('b23',(379, 661))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
270 s.addlight('b24',(417, 661))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
271 s.addlight('b25',(455, 658), aim=(520, 466))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
272 s.addlight('desk2',(490, 655), aim=(237, 375))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
273 s.addlight('rock',(571, 655), aim=(286, 304))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
274 s.addlight('b32',(606, 650))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
275 s.addlight('hotbox2',(637, 650), aim=(433, 337))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
276 s.addlight('b34',(671, 651))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
277 s.addlight('marry2',(703, 651), aim=(429, 426))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
278 s.addlight('cuba2',(733, 652), aim=(602, 408))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
279
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
280 s.addlight('sidefill1',(115, 473),aim=(228, 423))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
281 s.addlight('sidefill2',(617, 475),aim=(526, 425))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
282
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
283 s.addlight('cycright',(485, 164),(483, 109))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
284 s.addlight('cycleft',(330, 154),(333, 108))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
285
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
286 s.addlight('upfill1',(275, 325),(262, 237))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
287 s.addlight('upfill2',(333, 326),(330, 229))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
288 s.addlight('upfill3',(473, 325),(454, 226))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
289 s.addlight('upfill4',(541, 325),(528, 223))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
290
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
291 s.addlight('god',(369,549))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
292
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
293 s.addlight('patio1',(42, 560),(12, 512))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
294 s.addlight('patio2',(675, 553),(793, 514))
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
295
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
296 s.addlight('hotback',(413, 476),(414, 396))
10
533ac835083f some real lights
drewp
parents: 8
diff changeset
297
6
119369e60da1 tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents: 5
diff changeset
298
14
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
299
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
300 if __name__=='__main__':
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
301 root=Tk()
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
302 root.wm_geometry("+376+330")
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
303 s=Stage(root)
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
304 s.setimage('guysanddolls.gif')
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
305 s.pack()
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
306
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
307 createlights(s)
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
308 root.mainloop()
95ba7e14d15a new colors
drewp
parents: 10
diff changeset
309