def create_graphic_agent(self, Position, Shape=None): " creates a graphic agent and returns the Q-reference " if Shape is None: Shape = self.DEFAULTSHAPE if Shape == 'ellipse': return self.addEllipse( 0, 0, Position.size, Position.size, QPen(QColor(EvolifeColourID(Position.colour)[1])), QBrush(QColor(EvolifeColourID(Position.colour)[1]), Qt.SolidPattern)) if Shape == 'rectangle': return self.addRect( 0, 0, Position.size, Position.size, QPen(QColor(EvolifeColourID(Position.colour)[1])), QBrush(QColor(EvolifeColourID(Position.colour)[1]), Qt.SolidPattern)) if Shape not in self.KnownShapes: if os.path.exists(Shape): # print('Existing shape: %s' % Shape) self.KnownShapes[Shape] = QPixmap(Shape) # loads the image if Shape in self.KnownShapes: agent = self.addPixmap(self.KnownShapes[Shape]) scale = float(Position.size) / agent.boundingRect().width() agent.scale(scale, scale) return agent error("Ground: unknown shape: %s" % Shape)
def __init__(self, image=None, width=1000, height=1000): QGraphicsScene.__init__(self, 0, 0, width, height) # calling the parent's constructor if image is not None and os.path.exists(str(image)): #print "Loading %s . . ." % image self.ScaledBoard = self.Board = QPixmap(image) # loads the image #error("Plot","Unable to find image %s" % image) self.fitSize = True else: # By default, a Scene has a graphic area (pixmap) on which one can draw self.ScaledBoard = self.Board = QPixmap(width, height) image_ID = EvolifeColourID(image, default=None) if image_ID is not None: self.Board.fill(QColor(image_ID[1])) elif image and image.startswith( '#'): # background colour given by code self.Board.fill(QColor(image)) else: # default # self.Board.fill(QColor("#F0B554")) self.Board.fill(QColor("#FFFFFF")) self.fitSize = False self.Canvas = self.addPixmap(self.ScaledBoard) self.W = int(self.width()) self.H = int(self.height()) self.FrameNumber = 0
def create_graphic_segment(self, Position, Segment): " creates a graphic segment and returns the Q-reference " Colour = EvolifeColourID(Segment.colour)[0] self.Pens[Colour].setWidth(Segment.size) Location1 = self.convert( Position.point()) # Translation into physical coordinates Location2 = self.convert( Segment.point()) # Translation into physical coordinates return self.addLine(Location1[0], Location1[1], Location2[0], Location2[1], self.Pens[Colour])
def move(self, Curve_designation, newpoint): " introduces a discontinuity in a curve " # one is tolerant about the meaning of Curve_designation Curve_id = EvolifeColourID(Curve_designation)[0] # print('moving to', Curve_designation, Curve_id, newpoint) try: ## self.drawTo(newpoint, Curve_id, Drawing=False) self.Curves[Curve_id].add(newpoint, Draw=False) except IndexError: error("Draw_Area: unknown Curve ID")
def plot(self, Curve_designation, newpoint, Width=3): " draws an additional segment on a curve " # one is tolerant about the meaning of Curve_designation Curve_id = EvolifeColourID(Curve_designation)[0] # print('plotting to', Curve_designation, Curve_id, newpoint) try: self.drawTo(newpoint, Width, Curve_id) # action on display self.Curves[Curve_id].add(newpoint) # memory # if Width != self.Curves[Curve_id].thick: print('changing thickness to', Width) self.Curves[Curve_id].thick = Width # update thickness except IndexError: error("Draw_Area: unknown Curve ID")
def __init__(self, image=None, width=400, height=300, legend=True): self.Legend = legend and (image == None or EvolifeColourID(image)[0]) self.Toric = False # says whether right (resp. top) edge # is supposed to touch left (resp. bottom) edge Draw_Area.__init__(self, image, width, height) self.set_margins(6, 6, 6, 6) #self.Board.fill(QColor(Qt.white)) self.Canvas.setPixmap(self.ScaledBoard) self.positions = dict() # positions of agents self.segments = dict() # line segments pointing out from agents self.shapes = dict() # shape of agents self.GraphicAgents = dict() # Q-references of agents self.KnownShapes = {}
def Process_graph_orders(self, BestPhenotype): for (CurveId, Point) in self.Obs.get_info('PlotOrders'): try: self.Curves.Curves[EvolifeColourID(CurveId)[0]].add(Point) except IndexError: error("Evolife_Batch: unknown curve ID")