Changeset - 533ac835083f
[Not reviewed]
default
0 1 0
drewp - 22 years ago 2002-07-07 05:14:46

some real lights
1 file changed with 21 insertions and 3 deletions:
0 comments (0 inline, 0 general)
light8/stage.py
Show inline comments
 
@@ -73,48 +73,49 @@ class Stage(Canvas):
 
    def replacedynselection(self,newlightnames):
 
        """as a dynamic selection changes, keep calling this function with the
 
        names of the lights in the dynamic selection. the original selection (at the time
 
        of markfordynselection) will be shown along with any new lights"""
 
        self.selectedlights = self.origselection + [l for l in newlightnames if l not in self.origselection]
 
        self.updateselectionboxes()
 

	
 
    def select(self,lightname,select=1,dyn=0): # select=0 for deselect
 
        if select:
 
            if lightname not in self.selectedlights:
 
                self.selectedlights.append(lightname)
 
        elif lightname in self.selectedlights:
 
            self.selectedlights.remove(lightname)
 

	
 
        self.updateselectionboxes()
 
                
 

	
 
    #
 
    # LMB click or drag
 
    #
 
    def leftpress(self,ev):
 
        
 
        self.lmbstate='pressed'
 
        self.lmbstart=(ev.x,ev.y)
 
        print "click at",self.lmbstart
 

	
 
        shifted=ev.state & 1
 
        control=ev.state & 4
 
        touching=self.findoverlappinglights((ev.x-self.halo,ev.y-self.halo,ev.x+self.halo,ev.y+self.halo))
 
        istouching=len(touching)>0
 

	
 
        if not istouching:
 
            # clicked in space
 
            if not shifted and not control and len(self.selectedlights)>0:
 
                # either a deselect (if no motion) or a level change (if motion)
 
                self.lmbstate = 'deselect-or-level'
 
            if shifted or control or len(self.selectedlights)==0:
 
                # with shift/control, add/subtract lights to selection
 
                self.lmbstate='rectangle'
 

	
 
        else:
 
            # clicked a selectable object
 
            # toggle selection
 
            if touching[0] in self.selectedlights:
 
                if shifted:
 
                    # deselect
 
                    self.select(touching[0],0)
 
                    # and do nothing else
 
                    self.lmbstate=None
 
@@ -219,29 +220,46 @@ class Stage(Canvas):
 
                bboxes.append(self.bbox(o))
 
        return bboxes
 

	
 
    def findoverlappinglights(self,box,enclosed=0):
 
        "returns all the different name_ tags for lights that are within (or enclosed by) the box"
 
        lights=[]
 
        if enclosed:
 
            candidates = self.find_enclosed(*box)
 
        else:
 
            candidates = self.find_overlapping(*box)
 
            
 
        for o in candidates:
 
            for t in self.gettags(o):
 
                if t.startswith("name_"):
 
                    n = self.tagtoname(t[5:])
 
                    if n and (n not in lights):
 
                        lights.append(n)
 
        return lights
 

	
 
root=Tk()
 
root.wm_geometry("+376+330")
 
s=Stage(root)
 
s.setimage('guysanddolls.gif')
 
s.pack()
 
s.addlight('drew',(330,640),(90,20))
 
s.addlight('house',(360,640))
 
s.addlight('barn',(390,640))
 

	
 
s.addlight('desk1',(46, 659),    aim=(210, 381))
 
s.addlight('marry1',(78, 661),   aim=(398, 428))
 
s.addlight('b13',(110, 661))   
 
s.addlight('hotbox1',(147, 657), aim=(402, 327))
 
s.addlight('edge',(179, 651),    aim=(116, 441))
 
s.addlight('phone',(214, 652),   aim=(651, 417))
 
s.addlight('cuba1',(315, 656),   aim=(559, 407))
 
s.addlight('b22',(347, 661),     aim=(247, 458))
 
s.addlight('b23',(379, 661))  
 
s.addlight('b24',(417, 661))  
 
s.addlight('b25',(455, 658),     aim=(520, 466))
 
s.addlight('desk2',(490, 655),   aim=(237, 375))
 
s.addlight('rock',(571, 655),    aim=(286, 304))
 
s.addlight('b32',(606, 650))  
 
s.addlight('hotbox2',(637, 650), aim=(433, 337))
 
s.addlight('b34',(671, 651))   
 
s.addlight('marry2',(703, 651),  aim=(429, 426))
 
s.addlight('cuba2',(733, 652),   aim=(602, 408))
 

	
 

	
 
root.mainloop()
0 comments (0 inline, 0 general)