Beispiel #1
0
 def setControlPoints(self,points):
     """function to set curve control points"""
     assert isinstance(points, types.ListType),"Illegal type for points"
     
     for (x,y) in points:
         assert  x in range(50,306),"coordinates are out of range,x should be in [50,305]"
         assert  y in range(20,276),"coordinates are out of range,y should be in [20,275]"
             
     self.oldpoints=[]
     self.controlpoints=[]
     self.reset()
     self.oldpoints=self.controlpoints=points
     self.controlpoints.sort()
     if self.controlpoints[0]!=self.startpoint:
         self.controlpoints.append(self.startpoint)
     if  self.controlpoints[-1]!=self.endpoint:
         self.controlpoints.append(self.endpoint)
     self.canvas.delete(self.curline)   
     self.controlpoints.sort()
     if self.Smooth:
         self.curline=self.canvas.create_line( self.controlpoints,smooth=1)
     else:
         self.curline=self.canvas.create_line( self.controlpoints)
     for p in self.controlpoints[1:-1]:
         self.curoval=self.canvas.create_oval(p[0]-2,p[1]-2,p[0]+2,p[1]+2,width=1,outline='black',fill='black')
         self.curovals.append(self.curoval)
     (self.curx,self.cury)=   self.controlpoints[-2] 
     self.history.append((deepCopySeq(self.oldpoints),self.d1scalewheel.get()))
     if self.continuous or self.mousebuttonup:
         self.newd1ramp=self.caluculate_ramp()
         self.callbacks.CallCallbacks(self.newd1ramp)
Beispiel #2
0
 def read( self,fileName):
     if self.history!=[]:
         if self.history[-1][1]!=self.d1scalewheel.get():
             self.history[-1]=(self.history[-1][0],self.d1scalewheel.get())
     fptr=open(fileName,"r")
     data=fptr.readlines()
     cpoints=data[0][:-1]
     sensitivity=data[1]
     self.d1scalewheel.set(eval(sensitivity))
     if len(cpoints)==0:
         return
     else:
         points=cpoints
     self.oldpoints=[]        
     self.reset()
     if hasattr(self,"curline"):
         self.canvas.delete(self.curline)
         for c in self.curovals:
             self.canvas.delete(c)
             self.curovals.remove(c)
         if hasattr(self,"curoval"):
             self.canvas.delete(self.curoval)
         self.curovals=[]
         if self.Smooth:
             self.curline=self.canvas.create_line(eval(points),smooth=1)
         else:
             self.curline=self.canvas.create_line(eval(points))
         self.readpoints=self.oldpoints=eval(points)[1:-1]
         for p in eval(points)[1:-1]:
             self.curoval=self.canvas.create_oval(p[0]-2,p[1]-2,p[0]+2,p[1]+2,width=1,outline='black',fill='black')
             self.curovals.append(self.curoval)
         (self.curx,self.cury) =eval(points)[-2]
         self.history.append((deepCopySeq(self.oldpoints),self.d1scalewheel.get()))
Beispiel #3
0
 def invertGraph(self):
     """This function is for inverting graph by reverse computing controlpoints"""
     if self.history!=[]:
         if self.history[-1][1]!=self.d1scalewheel.get():
             self.history[-1]=(self.history[-1][0],self.d1scalewheel.get())
     invert_points=[]
     #self.oldpoints=[]
     points=self.getControlPoints()
     if len(points)<2:
         points=[self.startpoint,self.endpoint]
     for p in points:
         if p[1] in range(20,276):
             y=275 -(p[1]-20)
             invert_points.append((p[0],y))
     self.reset()
     ###################################################
     #Some times start and end points are not deleted 
     #So for deleting them canvas.find_enclosed points at
     #startpoint and endpoint are caluculated(returns alist of
     #canvas objects present there) and if the coords of
     #any canvas objects matches with start or end point that gets deleted
     #####################################################             
     x = 50
     y = 275
     st_oval_1= self.canvas.find_enclosed(x-3,y-3,x+3,y+3)
     if st_oval_1:
         for so in st_oval_1:
             if so!=[]:
                 st_oval=so
                 st_oval_coords=self.canvas.coords(st_oval)
                 if (int(st_oval_coords[0]+2),int(st_oval_coords[1]+2))==self.startpoint: 
                     self.canvas.delete(st_oval)
                     if st_oval in self.curovals:
                         self.curovals.remove(st_oval)
     x = 305
     y = 20
     end_oval_1= self.canvas.find_enclosed(x-3,y-3,x+3,y+3)
     if end_oval_1:
         for eo in end_oval_1:
             if eo!=[]:
                 end_oval=eo
                 end_oval_coords=self.canvas.coords(end_oval)
                 if (int(end_oval_coords[0]+2),int(end_oval_coords[1]+2))==self.endpoint: 
                     self.canvas.delete(end_oval)
                     if end_oval in self.curovals:
                         self.curovals.remove(end_oval)
     self.canvas.delete(self.curline)
     if self.Smooth:
           self.curline=self.canvas.create_line(invert_points,smooth=1)  
     else:
             self.curline=self.canvas.create_line(invert_points)
     self.oldpoints=invert_points
     for p in invert_points:
         self.curoval=self.canvas.create_oval(p[0]-2,p[1]-2,p[0]+2,p[1]+2,width=1,outline='black',fill='black')
         self.curovals.append(self.curoval)
     (self.curx,self.cury) =invert_points[-2]    
     if self.continuous or self.mousebuttonup:
         self.newd1ramp=self.caluculate_ramp()
         self.callbacks.CallCallbacks([self.newd1ramp])
     self.history.append((deepCopySeq(self.oldpoints),self.d1scalewheel.get()))
Beispiel #4
0
 def defaultcurve_cb(self):
     """draws curve with default points"""
     if self.history!=[]:
         if self.history[-1][1]!=self.d1scalewheel.get():
             self.history[-1]=(self.history[-1][0],self.d1scalewheel.get())
     points=[]
     self.default_points=[]
     self.oldpoints=[]
     self.d1scalewheel.set(0.013)
     self.default_points=[(50,275),(88, 238), (101, 150), (154, 78), (75, 271),(305,20)]
     self.reset()
     self.canvas.delete(self.curline)
     self.default_points.sort()
     if self.Smooth:
         self.curline=self.canvas.create_line(self.default_points,smooth=1) 
     else:
             self.curline=self.canvas.create_line(self.default_points)
     self.oldpoints=self.default_points
     for p in self.default_points:
         self.curoval=self.canvas.create_oval(p[0]-2,p[1]-2,p[0]+2,p[1]+2,width=1,outline='black',fill='black')
         self.curovals.append(self.curoval)
     (self.curx,self.cury) =self.default_points[-2]    
     if self.continuous or self.mousebuttonup:
         self.newd1ramp=self.caluculate_ramp()
         self.callbacks.CallCallbacks(self.newd1ramp)
     self.history.append((deepCopySeq(self.oldpoints),self.d1scalewheel.get()))
     self.default_ramp= self.newd1ramp
Beispiel #5
0
 def OnCanvasMouseUp(self,event):
          
     CtlPoints=[]
     xcoords=[]
     ycoords=[]
     if hasattr(self,"curx"): 
         (self.ox,self.oy)=(self.curx,self.cury)
         if (self.ox,self.oy) not in self.oldpoints :#not in [self.startpoint,self.endpoint] :
             self.oldpoints.append((self.ox,self.oy))     
             if hasattr(self,"curoval"):
                 if self.curoval not in self.curovals:
                     self.curovals.append(self.curoval)
     
     if self.CLICK_NODRAG==1:
      #finding out points around the selected point
      for i in range(0,10):
         xcoords.append(self.OrgX-i)
         ycoords.append(self.OrgY-i)
         xcoords.append(self.OrgX+i)
         ycoords.append(self.OrgY+i)
         
      if xcoords!=[] and ycoords!=[]:
         for x in xcoords:
             for y in ycoords:
                 CtlPoints.append((x,y))
         
         for c in CtlPoints:
          if  c in self.oldpoints:
             ind=self.oldpoints.index(c)
             op=self.oldpoints[ind]
             if ind>0:
                 prev_oldpoint=self.oldpoints[ind-1]
             else:
                 prev_oldpoint=self.endpoint
             del self.oldpoints[ind]
             
             for co in self.curovals:
                 ov_point1=self.canvas.coords(co)
                 if len(ov_point1)!=0:
                     ov_point=(int(ov_point1[0]+2),int(ov_point1[1]+2))
                                 
                     if ov_point==c  and ov_point not in [self.startpoint,self.endpoint]:
                         self.canvas.delete(co)
                         self.curovals.remove(co) 
                         if hasattr(self,"curx"): 
                          if ov_point==(self.curx,self.cury):
                             (self.curx,self.cury)=prev_oldpoint
                                                         
                         self.draw()
     if  self.mousebuttonup:
         self.newd1ramp=self.caluculate_ramp()
         self.callbacks.CallCallbacks(self.newd1ramp)
     
     self.history.append((deepCopySeq(self.oldpoints),self.d1scalewheel.get()))