Beispiel #1
0
    def __init__(self, geom, color=pygame.Color('green')):
        """ Constructor.

        Parameters:
            geom:
                the bounding rectangle of the window
        """
        self._font = pygame.font.SysFont('Courier', 14, bold=False)
        self._lineheight = self._font.get_linesize()

        self._topleft = utils.Point(geom.topleft)
        self._childrect = pygame.Rect(0, 0, geom.w, geom.h)
        self._text_color = color

        if self.bkgnd_file:
            self._bkgnd = pygame.image.load(
                utils.make_resource_path(self.bkgnd_file)
            ).convert_alpha()
            self._bkgnd.set_clip(self._childrect)
        else:
            self._bkgnd = pygame.Surface( #pylint: disable=E1121,E1123
                geom.size,
                flags=pygame.SRCALPHA
            )
            self._bkgnd.fill((40, 40, 40, 220))
Beispiel #2
0
    def __init__(self, args):   #pylint: disable=W0621
        self._debug = args.debug

        log_level = logging.DEBUG if args.debug else logging.INFO
        self._log = logging.getLogger('app')
        self._log.setLevel(log_level)
        BeaconEventHandler._log.setLevel(log_level)

        self._wndgeom = args.geom
        self._window = pygame.display.set_mode(self._wndgeom.size)
        pygame.display.set_caption('Tracking beacons demo - by POBOT')

        wnd_icon = pygame.image.load(
            utils.make_resource_path('pobot-logo-right.png')
        ).convert_alpha()
        pygame.display.set_icon(wnd_icon)

        self._listen_port = args.listen_port

        self._ctrl_name = args.ctrl_name
        self._ctrl_host = args.ctrl_host
        self._ctrl_port = args.ctrl_port
        self._ctrl_socket = None
        self._ctrl_rfile = None

        self._logo = Logo(self._wndgeom.size)
        self._hud = Hud(pygame.Rect(
            (self._wndgeom.w - HUD_W) / 2, 10, HUD_W, HUD_H
        ))
        self._status = StatusLine(pygame.Rect(
            0, self._wndgeom.h - 20, self._wndgeom.w, 20
        ))
        self._help = None

        lg = math.sqrt(self._wndgeom.w * self._wndgeom.w + self._wndgeom.h * self._wndgeom.h)
        self._beacons = (
            Beacon(
                (Beacon.SIZE / 2, Beacon.SIZE / 2),
                (0, 90),
                'alpha',
                ray_length=lg,
                debug=args.debug
            ),
            Beacon(
                (self._wndgeom.w - Beacon.SIZE / 2, Beacon.SIZE / 2),
                (-90, 0),
                'beta',
                ray_length=lg,
                debug=args.debug
            )
        )

        self._origin = self._beacons[0].location
        self._target = Target()
        self._clock = pygame.time.Clock()
        self._beacon_listener = None
        self._use_2_sensors = args.use_2_sensors
Beispiel #3
0
 def __init__(self):
     raw_img = pygame.image.load(
         utils.make_resource_path('cartoon_robot.png')
     ).convert_alpha()
     raw_size = raw_img.get_size()
     scale = float(self.WIDTH) / raw_size[0]
     self._img = pygame.transform.smoothscale(
         raw_img,
         tuple(int(d * scale) for d in raw_size)
     )
     self._size = self._img.get_size()
     self._location = (0, 0)
     self._visible = False
     self._visible_since = None
Beispiel #4
0
    def _make_image(self, filename, size):
        """ Loads a graphic file and returns a ready to display image object of
        the indicated size.

        Parameters:
            filename:
                the graphic file name, which must be stored in the res/ dubdir
            size:
                the resulting image size (width)

        Returns:
            a PyGame image object
        """
        raw_img = pygame.image.load(utils.make_resource_path(filename)).convert_alpha()
        raw_size = raw_img.get_size()
        scale = size / raw_size[0]
        return pygame.transform.smoothscale(
            raw_img,
            tuple(int(d * scale) for d in raw_size)
        )
Beispiel #5
0
    def __init__(self, display_size):
        """ Constructor.

        Parameters:
            display_size:
                the size of the display size, for positionning the logo in
                one of its angles.
        """
        raw_logo = pygame.image.load(
            utils.make_resource_path('pobot-logo.png')
        ).convert_alpha()
        raw_size = raw_logo.get_size()
        scale = 120. / raw_size[0]
        self._img = pygame.transform.smoothscale(
            raw_logo,
            tuple(int(d * scale) for d in raw_size)
        )
        self._logo_pos = (
            display_size[0] - self._img.get_size()[0],
            display_size[1] - self._img.get_size()[1]
        )