Beispiel #1
0
def get_pygame_layout_image(text_color, bg_color, layout_number, size):
    """Generate the layout image with the corresponding text.

    :param text_color: RGB color for texts
    :type text_color: tuple
    :param layout_number: number of captures on the layout
    :type layout_number: int
    :param size: maximum size of the layout surface
    :type size: tuple

    :return: surface
    :rtype: :py:class:`pygame.Surface`
    """
    layout_image = get_pygame_image("layout{0}.png".format(layout_number),
                                    size, color=text_color, bg_color=bg_color)
    text = language.get_translated_text(str(layout_number))
    if text:
        rect = layout_image.get_rect()
        rect = pygame.Rect(rect.x + rect.width * 0.3 / 2,
                           rect.y + rect.height * 0.76,
                           rect.width * 0.7, rect.height * 0.20)
        text_font = fonts.get_pygame_font(text, fonts.CURRENT, rect.width, rect.height)
        surface = text_font.render(text, True, bg_color)
        layout_image.blit(surface, surface.get_rect(center=rect.center))
    return layout_image
Beispiel #2
0
 def resize_texts(self, rect=None, align='center'):
     """Update text surfaces.
     """
     self._texts = []
     text = get_translated_text(self._name)
     if text:
         self._write_text(text, rect, align)
Beispiel #3
0
 def write_text(self, pos=None):
     """Update text surfaces
     """
     self._texts = []
     text = get_translated_text(self._name)
     if text:
         if not pos:
             pos = self._rect.center
         rect_x = 0.9 * min(2 * pos[0], 2 * (self._rect.width - pos[0]))
         rect_y = 0.9 * min(2 * pos[1], 2 * (self._rect.height - pos[1]))
         text_font = get_pygame_font(text, fonts.CURRENT, rect_x, rect_y)
         surface = text_font.render(text, True, self._text_color)
         self._texts.append((surface, surface.get_rect(center=pos)))
Beispiel #4
0
 def resize_texts(self):
     """Update text surfaces.
     """
     IntroBackground.resize_texts(self)
     text = get_translated_text("intro_print")
     if text:
         rect = pygame.Rect(self._rect.width * 0.30 + self._text_border, 0,
                            self._rect.width * 0.20 - 2 * self._text_border,
                            self._rect.height * 0.3 - 2 * self._text_border)
         if self.arrow_location == ARROW_TOP:
             rect.top = self._rect.height * 0.08
         else:
             rect.bottom = self._rect.height - self._rect.height * 0.08
         self._write_text(text, rect)
Beispiel #5
0
    def preview_wait(self, timeout, alpha=80):
        """Wait the given time.
        """
        timeout = int(timeout)
        if timeout < 1:
            raise ValueError("Start time shall be greater than 0")

        timer = PoolingTimer(timeout)
        while not timer.is_timeout():
            updated_rect = self._window.show_image(self._get_preview_image())
            pygame.event.pump()
            if updated_rect:
                pygame.display.update(updated_rect)

        self._show_overlay(get_translated_text('smile'), alpha)
        self._window.show_image(self._get_preview_image())
Beispiel #6
0
    def preview_countdown(self, timeout, alpha=60):
        """Show a countdown of `timeout` seconds on the preview.
        Returns when the countdown is finished.
        """
        timeout = int(timeout)
        if timeout < 1:
            raise ValueError("Start time shall be greater than 0")
        if not self._cam.preview:
            raise EnvironmentError("Preview shall be started first")

        while timeout > 0:
            self._show_overlay(timeout, alpha)
            time.sleep(1)
            timeout -= 1
            self._hide_overlay()

        self._show_overlay(get_translated_text('smile'), alpha)
Beispiel #7
0
    def preview_countdown(self, timeout, alpha=60):
        """Show a countdown of `timeout` seconds on the preview.
        Returns when the countdown is finished.
        """
        timeout = int(timeout)
        if timeout < 1:
            raise ValueError("Start time shall be greater than 0")

        timer = PoolingTimer(timeout)
        while not timer.is_timeout():
            self.preview(self._window)
            remaining = int(timer.remaining() + 1)
            if not self._overlay or remaining != timeout:
                # Rebluid overlay only if remaining number has changed
                self._show_overlay(str(remaining), alpha)
                timeout = remaining

        self._show_overlay(get_translated_text('smile'), alpha)
Beispiel #8
0
 def write_text(self):
     """Update text surfaces
     """
     IntroBackground.write_text(self)
     text_size = 20 * self._rect.height // 400
     text_font = pictures.pygame.font.Font(fonts.CURRENT, text_size)
     text_strings = get_translated_text("intro_print").splitlines()
     delta_y = 0
     if self.arrow_location == ARROW_BOTTOM:
         text_strings = reversed(text_strings)
     for text_string in text_strings:
         surface = text_font.render(text_string, True, self._text_color)
         if self.arrow_location == ARROW_BOTTOM:
             pos_y = self._rect.height * 87 / 100 - delta_y
         else:
             pos_y = self._rect.height * 13 / 100 + delta_y
         pos = (self._rect.width * 45 / 100, pos_y)
         self._texts.append((surface, surface.get_rect(center=pos)))
         delta_y += surface.get_height()
Beispiel #9
0
 def resize_texts(self):
     """Update text surfaces.
     """
     IntroBackground.resize_texts(self)
     text = get_translated_text("intro_print")
     if text:
         if self.arrow_location == ARROW_HIDDEN or self.arrow_location == ARROW_BOTTOM:
             rect = pygame.Rect(
                 self._rect.width * 0.30 + self._text_border,
                 self._rect.height * 0.7,
                 self._rect.width * 0.20 - 2 * self._text_border,
                 self._rect.height * 0.3 - 2 * self._text_border)
         else:
             rect = pygame.Rect(
                 self._rect.width * 0.30 + self._text_border,
                 self._text_border,
                 self._rect.width * 0.20 - 2 * self._text_border,
                 self._rect.height * 0.3 - 2 * self._text_border)
         self._write_text(text, rect)
Beispiel #10
0
    def resize_texts(self):
        """Update text surfaces.
        """
        if self.arrow_location == ARROW_HIDDEN:
            rect = pygame.Rect(self._rect.width / 2 + self._text_border,
                               self._text_border,
                               self._rect.width / 2 - 2 * self._text_border,
                               self._rect.height - 2 * self._text_border)
            align = 'center'
        elif self.arrow_location == ARROW_BOTTOM:
            rect = pygame.Rect(self._rect.width / 2 + self._text_border,
                               self._text_border,
                               self._rect.width / 2 - 2 * self._text_border,
                               self._rect.height * 0.6 - self._text_border)
            align = 'bottom-center'
        elif self.arrow_location == ARROW_TOUCH:
            rect = pygame.Rect(self._rect.width / 2 + self._text_border,
                               self._text_border,
                               self._rect.width / 2 - 2 * self._text_border,
                               self._rect.height * 0.4 - self._text_border)
            align = 'bottom-center'
        else:
            rect = pygame.Rect(self._rect.width / 2 + self._text_border,
                               self._rect.height * 0.4,
                               self._rect.width / 2 - 2 * self._text_border,
                               self._rect.height * 0.6 - self._text_border)
            align = 'top-center'
        Background.resize_texts(self, rect, align)

        text = get_translated_text("print_forget")
        if text:
            rect = pygame.Rect(self._rect.width // 2, 0,
                               self._rect.width // 5 - 2 * self._text_border,
                               self._rect.height * 0.3 - 2 * self._text_border)
            if self.arrow_location == ARROW_TOP:
                rect.top = self._rect.height * 0.08
            else:
                rect.bottom = self._rect.height - self._rect.height * 0.08

            self._write_text(text, rect)
Beispiel #11
0
    def preview_countdown(self, timeout, alpha=80):
        """Show a countdown of `timeout` seconds on the preview.
        Returns when the countdown is finished.
        """
        timeout = int(timeout)
        if timeout < 1:
            raise ValueError("Start time shall be greater than 0")

        shown = False
        first_loop = True
        timer = PoolingTimer(timeout)
        while not timer.is_timeout():
            remaining = int(timer.remaining() + 1)
            if not self._overlay or remaining != timeout:
                # Rebluid overlay only if remaining number has changed
                self._show_overlay(str(remaining), alpha)
                timeout = remaining
                shown = False

            updated_rect = None
            if self._preview_compatible:
                updated_rect = self._window.show_image(
                    self._get_preview_image())
            elif not shown:
                updated_rect = self._window.show_image(
                    self._get_preview_image())
                shown = True  # Do not update dummy preview until next overlay update

            if first_loop:
                timer.start(
                )  # Because first preview capture is longer than others
                first_loop = False

            pygame.event.pump()
            if updated_rect:
                pygame.display.update(updated_rect)

        self._show_overlay(get_translated_text('smile'), alpha)
        self._window.show_image(self._get_preview_image())
Beispiel #12
0
    def preview_countdown(self, timeout, alpha=80):
        """Show a countdown of `timeout` seconds on the preview.
        Returns when the countdown is finished.
        """
        timeout = int(timeout)
        if timeout < 1:
            raise ValueError("Start time shall be greater than 0")

        timer = PoolingTimer(timeout)
        while not timer.is_timeout():
            remaining = int(timer.remaining() + 1)
            if self._overlay is None or remaining != timeout:
                # Rebluid overlay only if remaining number has changed
                self._show_overlay(str(remaining), alpha)
                timeout = remaining

            updated_rect = self._window.show_image(self._get_preview_image())
            pygame.event.pump()
            if updated_rect:
                pygame.display.update(updated_rect)

        self._show_overlay(get_translated_text('smile'), alpha)
        self._window.show_image(self._get_preview_image())
Beispiel #13
0
 def preview_wait(self, timeout, alpha=60):
     """Wait the given time.
     """
     time.sleep(timeout)
     self._show_overlay(get_translated_text('smile'), alpha)
def state_choose_enter(app, cfg):
    """Write translated text of choose message to buffer.
    """
    app.pimoroni_11x7.clear_and_write(message=get_translated_text('choose'))