def attachHead(self, origin, target): tx, ty = map(float, target) sx, sy = tx-20, ty ex, ey = tx, ty+20 ox, oy = map(float, origin) _p = gnomecanvas.path_def_new([(MO, sx, sy), (L, tx, ty), (L, ex, ey), ]) self.head = self.canvas.root().add("GnomeCanvasBpath", width_pixels=5, cap_style=gtk.gdk.CAP_ROUND, outline_color=self.color, ) self.head.set_bpath(_p) if oy != ty: # negate the y axis due to stupid display coordinates leg_ratio = (tx-ox)/(oy-ty) tip_angle = atan(leg_ratio) else: # avoid zerodivisionerror... if tx > ox: tip_angle = pi/2 else: tip_angle = 3*pi/2 correction_angle = pi/4 - tip_angle # flip 180 degrees if arrow is pointing down if ty > oy: correction_angle = correction_angle + pi affines = affineRotationForAngle(correction_angle, tx, ty) self.head.affine_relative(affines) self.head.move(-tx, -ty)
def createBpath( self, aDescriptor ): pathDef = aDescriptor[SD_SPECIFIC][SPEC_POINTS] aGdkColor = self.getGdkColor( aDescriptor ) outlineColor = self.getOutlineColor( ) aBpath = self.theRoot.add( gnomecanvas.CanvasBpath, outline_color_gdk = outlineColor, fill_color_gdk = aGdkColor ) aBpath.set_bpath(gnomecanvas.path_def_new( pathDef ) ) self.setOutlineWidth( aDescriptor, aBpath ) self.addHandlers( aBpath, aDescriptor[ SD_NAME ] ) self.shapeMap[ aDescriptor[ SD_NAME ] ] = aBpath
def createShaft(self, origin, target): pd = gnomecanvas.path_def_new([(MO, origin[0], origin[1]), (L, target[0], target[1])]) self.shaft = self.canvas.root().add("GnomeCanvasBpath", width_pixels=5, cap_style=gtk.gdk.CAP_ROUND, outline_color=self.color) self.shaft.set_bpath(pd)
def createShaft(self, origin, target): pd = gnomecanvas.path_def_new([(MO, origin[0], origin[1]), (L, target[0], target[1])]) self.shaft = self.canvas.root().add("GnomeCanvasBpath", width_pixels=5, cap_style=gtk.gdk.CAP_ROUND, outline_color=self.color) self.shaft.set_bpath(pd)
def createPathObject( path ): repr = [] last_pos = ( 0, 0 ) for item in path: if item[ 0 ] == base.MOVE_TO: if item[ 1 ]: pos = ( last_pos[ 0 ] + item[ 2 ], last_pos[ 1 ] + item[ 3 ] ) else: pos = item[ 2: 4 ] repr.append( ( gnomecanvas.MOVETO, pos[ 0 ], pos[ 1 ] ) ) last_pos = pos elif item[ 0 ] == base.LINE_TO: if item[ 1 ]: pos = ( last_pos[ 0 ] + item[ 2 ], last_pos[ 1 ] + item[ 3 ] ) else: pos = item[ 2: 4 ] repr.append( ( gnomecanvas.LINETO, pos[ 0 ], pos[ 1 ] ) ) last_pos = pos elif item[ 0 ] == base.CURVE_TO: if len( item ) >= 6: cp = item[ 6: ] else: cp = item[ 4: ] if item[ 1 ]: pos = ( last_pos[ 0 ] + item[ 2 ], last_pos[ 1 ] + item[ 3 ] ) repr.append( ( gnomecanvas.CURVETO, last_pos[ 0 ] + item[ 4 ], last_pos[ 1 ] + item[ 5 ], last_pos[ 0 ] + cp[ 0 ], last_pos[ 1 ] + cp[ 1 ], pos[ 0 ], pos[ 1 ] ) ) else: pos = item[ 2: 4 ] repr.append( ( gnomecanvas.CURVETO, item[ 4 ], item[ 5 ], cp[ 0 ], cp[ 1 ], pos[ 0 ], pos[ 1 ] ) ) last_pos = pos elif item[ 0 ] == base.CLOSE: repr.append( ( gnomecanvas.END, ) ) return gnomecanvas.path_def_new( repr )
def createBpath(self, aDescriptor): pathDef = aDescriptor[SD_SPECIFIC][SPEC_POINTS] aGdkColor = self.getGdkColor(aDescriptor) outlineColor = self.getOutlineColor() aBpath = self.theRoot.add(gnomecanvas.CanvasBpath, outline_color_gdk=outlineColor, fill_color_gdk=aGdkColor) aBpath.set_bpath(gnomecanvas.path_def_new(pathDef)) self.setOutlineWidth(aDescriptor, aBpath) self.addHandlers(aBpath, aDescriptor[SD_NAME]) self.shapeMap[aDescriptor[SD_NAME]] = aBpath
def resizeBpath(self, aDescriptor): pathDef = aDescriptor[SD_SPECIFIC][SPEC_POINTS] aBpath = self.shapeMap[aDescriptor[SD_NAME]] self.setOutlineWidth(aDescriptor, aBpath) newPathDef = [] for anArtPath in pathDef: newArtPath = [anArtPath[0]] for i in range(0, (len(anArtPath) - 1) / 2): x, y = aBpath.w2i(anArtPath[i * 2 + 1], anArtPath[i * 2 + 2]) newArtPath.extend([x, y]) newArtPath = tuple(newArtPath) newPathDef.append(newArtPath) aBpath.set_bpath(gnomecanvas.path_def_new(newPathDef))
def resizeBpath( self, aDescriptor ): pathDef = aDescriptor[SD_SPECIFIC][SPEC_POINTS] aBpath = self.shapeMap[ aDescriptor[ SD_NAME ] ] self.setOutlineWidth( aDescriptor, aBpath ) newPathDef = [] for anArtPath in pathDef: newArtPath=[ anArtPath[0]] for i in range(0,(len(anArtPath) - 1 )/2): x,y = aBpath.w2i(anArtPath[i*2+1], anArtPath[i*2+2] ) newArtPath.extend( [x,y] ) newArtPath = tuple(newArtPath) newPathDef.append( newArtPath ) aBpath.set_bpath(gnomecanvas.path_def_new( newPathDef ) )
def createBpath(self, aDescriptor): aSpecific= aDescriptor[SD_SPECIFIC] # get pathdef pathdef= aSpecific[BPATH_PATHDEF] pd = gnomecanvas.path_def_new(pathdef) aGdkColor = self.getGdkColor( aDescriptor ) #cheCk: 1starg > the Bpath, 2ndarg > Bpath width(def 3), 3rdarg > Color of Bpath(def black) bpath = self.theRoot.add(gnomecanvas.CanvasBpath, width_units=3, outline_color_gdk = aGdkColor) bpath.set_bpath(pd) self.addHandlers( bpath, aDescriptor[ SD_NAME ] ) self.shapeMap[ aDescriptor[ SD_NAME ] ] = bpath
def createBpath(self, aDescriptor): aSpecific = aDescriptor[SD_SPECIFIC] # get pathdef pathdef = aSpecific[BPATH_PATHDEF] pd = gnomecanvas.path_def_new(pathdef) aGdkColor = self.getGdkColor(aDescriptor) #cheCk: 1starg > the Bpath, 2ndarg > Bpath width(def 3), 3rdarg > Color of Bpath(def black) bpath = self.theRoot.add(gnomecanvas.CanvasBpath, width_units=3, outline_color_gdk=aGdkColor) bpath.set_bpath(pd) self.addHandlers(bpath, aDescriptor[SD_NAME]) self.shapeMap[aDescriptor[SD_NAME]] = bpath
def attachHead(self, origin, target): tx, ty = map(float, target) sx, sy = tx - 20, ty ex, ey = tx, ty + 20 ox, oy = map(float, origin) _p = gnomecanvas.path_def_new([ (MO, sx, sy), (L, tx, ty), (L, ex, ey), ]) self.head = self.canvas.root().add( "GnomeCanvasBpath", width_pixels=5, cap_style=gtk.gdk.CAP_ROUND, outline_color=self.color, ) self.head.set_bpath(_p) if oy != ty: # negate the y axis due to stupid display coordinates leg_ratio = (tx - ox) / (oy - ty) tip_angle = atan(leg_ratio) else: # avoid zerodivisionerror... if tx > ox: tip_angle = pi / 2 else: tip_angle = 3 * pi / 2 correction_angle = pi / 4 - tip_angle # flip 180 degrees if arrow is pointing down if ty > oy: correction_angle = correction_angle + pi affines = affineRotationForAngle(correction_angle, tx, ty) self.head.affine_relative(affines) self.head.move(-tx, -ty)
def redrawBpath( self, aDescriptor ): aShape = self.shapeMap[ aDescriptor[ SD_NAME ] ] pathdef = aDescriptor[ SD_SPECIFIC ][BPATH_PATHDEF] pd=gnomecanvas.path_def_new(pathdef) aShape.set_bpath(pd)
def redrawBpath(self, aDescriptor): aShape = self.shapeMap[aDescriptor[SD_NAME]] pathdef = aDescriptor[SD_SPECIFIC][BPATH_PATHDEF] pd = gnomecanvas.path_def_new(pathdef) aShape.set_bpath(pd)
def render_path(self, path): commands = [(gnomecanvas.MOVETO_OPEN, path[0][0], path[0][1])] commands += [(gnomecanvas.LINETO, x, y) for x, y in path[1:]] path_def = gnomecanvas.path_def_new(commands) self.bpath.set_bpath(path_def)