Mercurial > code > home > repos > light9
annotate light8/stage.py @ 6:119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
author | drewp |
---|---|
date | Sun, 07 Jul 2002 03:47:18 +0000 |
parents | a76f775bb635 |
children | 1b0266dd233a |
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 |
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 | |
31 """ | |
32 def __init__(self,parent,**kw): | |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
33 if 'stageimage' in kw: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
34 stageimage=kw['stageimage'] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
35 del kw['stageimage'] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
36 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
37 stageimage=None |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
38 |
0 | 39 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
|
40 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
41 if stageimage: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
42 img = Image('photo',stageimage) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
43 self.create_image(0,0,anchor='nw',image=img) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
44 self.create_rectangle(5,5,50,50) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
45 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
50 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
|
51 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
52 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
|
53 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
54 self.alllights=[] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
55 self.selectedlights=[] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
56 |
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 # selection management |
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 def clearselection(self,dyn=0): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
61 if dyn: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
62 seltag="dynselection" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
63 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
64 seltag="selection" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
65 for o in self.find_withtag(seltag): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
66 self.select(o,0,dyn) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
67 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
68 def replacedynselection(self,newlightnames): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
69 for o in self.find_withtag('dynselection'): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
70 self.select(o,0,1) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
71 for o in newlightnames: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
72 self.select(o,1,1) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
73 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
74 def select(self,obj,select=1,dyn=0): # select=0 for deselect |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
75 if dyn: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
76 seltag="dynselection" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
77 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
78 seltag="selection" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
79 if select: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
80 print obj,"into selection" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
81 self.addtag_withtag(seltag,obj) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
82 for c in self.getlightbboxes(obj): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
83 self.create_rectangle(c[0]-2,c[1]-2,c[2]+2,c[3]+2,outline='red',tag="selectbox_%s"%obj) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
84 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
85 print obj,"out of select" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
86 self.dtag(obj,seltag) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
87 if 'selection' not in self.gettags(obj) and 'dynselection' not in self.gettags(obj): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
88 self.delete("selectbox_%s"%obj) |
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 incorporatedynselection(self): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
91 "put all dynselected objects in the regular selection" |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
92 for o in self.find_withtag('dynselection'): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
93 self.dtag(o,'dynselection') |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
94 self.addtag_withtag('selection',o) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
95 # no change for the graphics |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
96 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
97 # |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
98 # LMB click or drag |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
99 # |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
100 def leftpress(self,ev): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
101 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
102 self.lmbstate='pressed' |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
103 self.lmbstart=(ev.x,ev.y) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
104 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
105 shifted=ev.state & 1 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
106 control=ev.state & 4 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
107 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
|
108 istouching=len(touching)>0 |
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 if not istouching: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
111 # clicked in space |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
112 if not shifted and not control: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
113 # either a deselect (if no motion) or a level change (if motion) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
114 self.clearselection() |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
115 self.lmbstate='rectangle' |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
116 if shifted or control: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
117 # 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
|
118 self.lmbstate='rectangle' |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
119 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
120 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
121 # clicked a selectable object |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
122 # toggle selection |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
123 if 'selection' in self.gettags(touching[0]): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
124 if shifted: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
125 # deselect |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
126 self.select(touching[0],0) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
127 # and do nothing else |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
128 self.lmbstate=None |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
129 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
130 # select only this light |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
131 self.clearselection() |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
132 self.select(touching[0]) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
133 # and adjust its level |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
134 self.lmbstate='levelchange' |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
135 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
136 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
137 if not shifted: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
138 self.clearselection() |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
139 self.select(touching[0]) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
140 # and adjust levels now |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
141 self.lmbstate='levelchange' |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
142 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
143 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
144 def leftmotion(self,ev): |
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 coords=(ev.x,ev.y) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
147 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
148 shifted=ev.state & 1 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
149 control=ev.state & 4 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
150 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
151 if self.lmbstate=='levelchange': |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
152 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
|
153 print "change by",delta |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
154 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
155 if self.lmbstate=='rectangle': |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
156 sr = self.find_withtag('selectrect') |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
157 if not sr: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
158 sr=self.create_rectangle( self.lmbstart[0],self.lmbstart[1],coords[0],coords[1],tag='selectrect') |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
159 # sr=self.create_rectangle( *(self.lmbstart+coords), tag='selectrect' ) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
160 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
161 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
|
162 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
163 # 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
|
164 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
|
165 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
166 # need to handle ctrl |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
167 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
168 def leftrelease(self,ev): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
169 if self.lmbstate: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
170 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
171 if self.lmbstate=='rectangle': |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
172 self.delete('selectrect') |
0 | 173 |
6
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
174 # all items that were in dynselection join the selection |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
175 self.incorporatedynselection() |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
176 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
177 self.lmbstate=None |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
178 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
179 def nametag(self,name): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
180 "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
|
181 return name.replace(" ","__") |
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 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
|
184 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
185 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
|
186 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
187 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
|
188 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
|
189 fill='red',tag=tags+" hotspot") |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
190 self.create_text(location[0],location[1]+5,anchor='n',text=name,tag=tags) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
191 self.alllights.append(name) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
192 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
193 def getlightbboxes(self,tag): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
194 """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
|
195 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
|
196 bboxes=[] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
197 for o in self.find_withtag(tag): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
198 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
|
199 bboxes.append(self.bbox(o)) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
200 return bboxes |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
201 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
202 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
|
203 "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
|
204 lights=[] |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
205 if enclosed: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
206 candidates = self.find_enclosed(*box) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
207 else: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
208 candidates = self.find_overlapping(*box) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
209 for o in candidates: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
210 for t in self.gettags(o): |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
211 if t.startswith("name_") and t not in lights: |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
212 lights.append(t) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
213 return lights |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
214 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
215 root=Tk() |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
216 s=Stage(root,stageimage='guysanddolls.ppm') |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
217 s.addlight('drew',(80,80)) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
218 s.addlight('house',(150,80)) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
219 s.addlight('barn',(200,80)) |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
220 s.pack() |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
221 |
119369e60da1
tag-heavy selection management is getting hard - about to switch to python lists
drewp
parents:
5
diff
changeset
|
222 root.mainloop() |