Ejemplo n.º 1
0
    def on_paint(self,e=None):
        """
        Paint event handler. Reads the turtle reports and draws graphics
        accordingly.
        """
        turtle_reports=dumpqueue.dump_queue(self.turtle_queue)
        dc=wx.GCDC(wx.MemoryDC(self.bitmap))
        for turtle_report in turtle_reports:
            

            for animal in turtle_report:
                if animal.pen_down is True:
                    try:
                        
                        oldanimal = self.animals[turtle_report.index(animal)]
                        dc.SetPen(AnimalImage.get_pen(*animal.get_pen_parametres()))
                        dc.DrawLinePoint(\
                           from_my_pos(oldanimal.position),from_my_pos(animal.position))
                    except IndexError, e:
                        print e
                if animal.clear is True:
                    brush=wx.Brush("black")
                    dc.SetBackground(brush)
                    dc.Clear()
            self.animals = turtle_report
Ejemplo n.º 2
0
    def on_paint(self,e=None):
        """
        Paint event handler. Reads the turtle reports and draws graphics
        accordingly.
        """
        turtle_reports=dumpqueue.dump_queue(self.turtle_queue)
        dc=wx.GCDC(wx.MemoryDC(self.bitmap))
        for turtle_report in turtle_reports:
            #print(turtle_report.__dict__)
            if turtle_report.pen_down is True:
                dc.SetPen(turtle_report.give_pen())
                dc.DrawLinePoint(from_my_pos(self.turtle.pos),from_my_pos(turtle_report.pos))
            if turtle_report.clear is True:
                brush=wx.Brush("black")
                dc.SetBackground(brush)
                dc.Clear()

            self.turtle = turtle_report
        del dc
        if len(turtle_reports) > 0: self.Refresh()


        dc=wx.PaintDC(self)
        widget_size = Vector(self.GetSize())
        top_left_corner = (-BITMAP_SIZE+widget_size) / 2.0

        # Draw the bitmap:
        dc.DrawBitmap(self.bitmap, *top_left_corner)

        # Draw the turtle:
        if self.turtle.visible:
            new_pos = top_left_corner + from_my_pos(self.turtle.pos)
            draw_bitmap_to_dc_rotated(dc, self.TURTLE_IMAGE, from_my_angle(self.turtle.orientation), new_pos)
        dc.Destroy()
Ejemplo n.º 3
0
    def on_paint(self,e=None):
        """
        Paint event handler. Reads the turtle reports and draws graphics
        accordingly.
        """
        turtle_reports=dumpqueue.dump_queue(self.turtle_queue)
        dc=wx.GCDC(wx.MemoryDC(self.bitmap))
        for turtle_report in turtle_reports:
            #print(turtle_report.__dict__)
            if turtle_report.pen_down is True:
                dc.SetPen(turtle_report.give_pen())
                dc.DrawLinePoint(from_my_pos(self.turtle.pos),from_my_pos(turtle_report.pos))
            if turtle_report.clear is True:
                brush=wx.Brush("black")
                dc.SetBackground(brush)
                dc.Clear()

            self.turtle = turtle_report
        del dc
        if len(turtle_reports) > 0: self.Refresh()


        dc=wx.PaintDC(self)
        widget_size = Vector(self.GetSize())
        top_left_corner = (-BITMAP_SIZE+widget_size) / 2.0

        # Draw the bitmap:
        dc.DrawBitmap(self.bitmap, *top_left_corner)

        # Draw the turtle:
        if self.turtle.visible:
            new_pos = top_left_corner + from_my_pos(self.turtle.pos)
            draw_bitmap_to_dc_rotated(dc, self.TURTLE_IMAGE, from_my_angle(self.turtle.orientation), new_pos)
        dc.Destroy()
Ejemplo n.º 4
0
    def on_paint(self,e=None):
        """
        Paint event handler. Reads the mcg reports and draws graphics
        accordingly.
        """
        mcg_reports=dumpqueue.dump_queue(self.mcg_queue)
        dc=wx.GCDC(wx.MemoryDC(self.bitmap))
        dc.SetDeviceOrigin(self.Origin[0],self.Origin[1])
        dc.SetUserScale(self.Scale,-self.Scale)
        dc.SetBrush(self.Brush)
        dc.SetPen(self.Pen)
        #dc.ComputeScaleAndOrigin()
        for mcg_report in mcg_reports:
            #time.sleep(.01)
            if mcg_report.comando == "clear":
                dc.SetDeviceOrigin(0,0)
                dc.SetUserScale(1,1)
                #dc.ComputeScaleAndOrigin()
                brush=wx.Brush("black", wx.SOLID)
                dc.SetBackground(brush)
                dc.Clear()
                dc.SetDeviceOrigin(self.Origin[0],self.Origin[1])
                dc.SetUserScale(self.Scale,-self.Scale)
                #dc.ComputeScaleAndOrigin()
            elif mcg_report.comando == "SetPen":
                self.Pen = mcg_report.give_pen()
                dc.SetPen(self.Pen)
            elif mcg_report.comando == "SetBrush":
                self.Brush = mcg_report.give_brush()
                dc.SetBrush(self.Brush)
            elif mcg_report.comando == "SetDeviceOrigin":
                self.Origin=(mcg_report.arg[0],mcg_report.arg[1])
            elif mcg_report.comando == "SetUserScale":
                self.Scale = mcg_report.arg
            elif mcg_report.comando == "DrawRotatedText":
                dc.SetPen(mcg_report.give_pen())
                dc.SetFont(mcg_report.give_font())
                dc.DrawRotatedText(mcg_report.arg[0],mcg_report.arg[1],mcg_report.arg[2],mcg_report.arg[3])
            elif mcg_report.comando == "DrawText":
                dc.SetPen(mcg_report.give_pen())
                dc.SetFont(mcg_report.give_font())
                dc.DrawText(mcg_report.arg[0],mcg_report.arg[1],mcg_report.arg[2])
            elif mcg_report.comando == "DrawEllipse":
                dc.DrawEllipse(mcg_report.arg[0],mcg_report.arg[1],mcg_report.arg[2],mcg_report.arg[3])
            elif mcg_report.comando == "DrawEllipseList":
                dc.DrawEllipseList(mcg_report.arg,mcg_report.give_pen(),mcg_report.give_brush())
            elif mcg_report.comando == "DrawArcPoint":
                dc.DrawArcPoint(mcg_report.arg[0],mcg_report.arg[1],mcg_report.arg[2])
            elif mcg_report.comando == "DrawPointList":
                dc.SetPen(mcg_report.give_pen())
                dc.DrawPointList(mcg_report.arg)
            elif mcg_report.comando == "DrawCirclePoint":
                dc.SetPen(mcg_report.give_pen())
                dc.SetBrush(mcg_report.give_brush())
                dc.DrawCirclePoint(mcg_report.arg[0],mcg_report.arg[1])
            elif mcg_report.comando == "DrawPolygon":
                dc.DrawPolygon(mcg_report.arg)
            elif mcg_report.comando == "DrawPolygonList":
                dc.DrawPolygonList(mcg_report.arg,mcg_report.give_pen(),mcg_report.give_brush())
            elif mcg_report.comando == "DrawPolygonListC":
                dc.SetBrush(wx.Brush("red",wx.TRANSPARENT))
                for face in mcg_report.arg:
                    dc.SetPen(wx.Pen(face[0],1,wx.SOLID))
                    dc.DrawPolygon(face[1])
            elif mcg_report.comando == "DrawPolygonListB":
                for face in mcg_report.arg:
                    dc.SetBrush(wx.Brush(face[0],wx.SOLID))
                    dc.DrawPolygon(face[1])
            elif mcg_report.comando == "DrawLineList":
                dc.DrawLineList(mcg_report.arg)
            elif mcg_report.comando == "DrawLinePoint":
                dc.SetPen(mcg_report.give_pen())
                dc.DrawLinePoint(mcg_report.arg[0],mcg_report.arg[1])
            elif mcg_report.comando == "DrawPointPoint":
                dc.DrawPointPoint(mcg_report.arg)
            elif mcg_report.comando == "DrawSpline":
                dc.DrawSpline(mcg_report.arg)
            self.mcg = mcg_report

        del dc
        if len(mcg_reports) > 0:
            self.Refresh()


        dc=wx.PaintDC(self)
        widget_size = Vector(self.GetSize())
        top_left_corner =(-BITMAP_SIZE+widget_size)/2.0
        # Draw the bitmap:
        dc.DrawBitmap(self.bitmap, *top_left_corner)

        dc.Destroy()