Esempio n. 1
0
 def __init__(self):
     State.__init__(self, 'wait')
     self.timer = PoolingTimer(self.app.config.getfloat('WINDOW', 'animate_delay'))
     if self.app.config.getfloat('WINDOW', 'final_image_delay') < 0:
         self.final_display_timer = None
     else:
         self.final_display_timer = PoolingTimer(self.app.config.getfloat('WINDOW', 'final_image_delay'))
Esempio n. 2
0
    def entry_actions(self):
        animated = self.app.makers_pool.get()
        if self.app.config.getfloat('WINDOW', 'final_image_delay') < 0:
            self.final_display_timer = None
        else:
            self.final_display_timer = PoolingTimer(
                self.app.config.getfloat('WINDOW', 'final_image_delay'))

        if self.final_display_timer and self.final_display_timer.is_timeout():
            previous_picture = None
        elif self.app.config.getboolean('WINDOW', 'animate') and animated:
            self.app.previous_animated = itertools.cycle(animated)
            previous_picture = next(self.app.previous_animated)
            self.timer.timeout = self.app.config.getfloat(
                'WINDOW', 'animate_delay')
            self.timer.start()
        else:
            previous_picture = self.app.previous_picture

        self.app.window.show_intro(
            previous_picture,
            self.app.printer.is_installed()
            and self.app.nbr_duplicates < self.app.config.getint(
                'PRINTER', 'max_duplicates')
            and not self.app.printer_unavailable)
        self.app.window.set_print_number(len(self.app.printer.get_all_tasks()),
                                         self.app.printer_unavailable)

        self.app.led_capture.blink()
        if self.app.previous_picture_file and self.app.printer.is_installed(
        ) and not self.app.printer_unavailable:
            self.app.led_print.blink()
Esempio n. 3
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
        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

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

            pygame.event.pump()
            pygame.display.update()

        self._show_overlay(
            LANGUAGES.get(PiConfigParser.language,
                          LANGUAGES['en']).get('smile_message'), alpha)
        self._window.show_image(self._get_preview_image())
Esempio n. 4
0
    def preview_wait(self, timeout):
        """Wait the given time and refresh the preview.
        """
        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, timeout=timeout)
Esempio n. 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():
            self._window.show_image(self._get_preview_image())
            pygame.event.pump()
            pygame.display.update()

        self._show_overlay(LANGUAGES.get(PiConfigParser.language, LANGUAGES['en']).get('smile_message'), alpha)
        self._window.show_image(self._get_preview_image())
Esempio n. 6
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())
Esempio n. 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")

        overlay = None
        timer = PoolingTimer(timeout)
        while not timer.is_timeout():
            self.preview(self._window)
            remaining = int(timer.remaining() + 1)
            if not overlay or remaining != timeout:
                # Rebluid overlay only if remaining number has changed
                # overlay = self.get_overlay(image.size, str(remaining), alpha)
                timeout = remaining
Esempio n. 8
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)
Esempio n. 9
0
 def __init__(self, plugin_manager):
     self._pm = plugin_manager
     self.count = 0
     # Seconds to display the failed message
     self.failed_view_timer = PoolingTimer(2)
     # Seconds between each animated frame
     self.animated_frame_timer = PoolingTimer(0)
     # Seconds before going back to the start
     self.choose_timer = PoolingTimer(30)
     # Seconds to display the selected layout
     self.layout_timer = PoolingTimer(4)
     # Seconds to display the selected layout
     self.print_view_timer = PoolingTimer(0)
     # Seconds to display the selected layout
     self.finish_timer = PoolingTimer(0.5)
     # Seconds to display the selected layout
     self.filters_timer = PoolingTimer(5)
Esempio n. 10
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())
Esempio n. 11
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")
     rect = self._window.get_rect()
     size = (((rect.width + 31) // 32) * 32,
             ((rect.height + 15) // 16) * 16)
     image = Image.new('RGB', size, color=(0, 0, 0))
     overlay = None
     timer = PoolingTimer(timeout)
     while not timer.is_timeout():
         self.preview(self._window)
         remaining = int(timer.remaining() + 1)
         if not overlay or remaining != timeout:
             # Rebluid overlay only if remaining number has changed
             image = Image.new('RGB', size, color=(0, 0, 0))
             overlay = self.get_overlay(image.size, str(remaining), alpha)
             timeout = remaining
             image.paste(overlay, (0, 0), overlay)
             self._window.show_image(image)
Esempio n. 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())
Esempio n. 13
0
 def __init__(self, timeout):
     State.__init__(self, 'choose')
     self.timer = PoolingTimer(timeout)
Esempio n. 14
0
 def __init__(self, timeout):
     State.__init__(self, 'failsafe')
     self.timer = PoolingTimer(timeout)
Esempio n. 15
0
 def __init__(self, timeout):
     State.__init__(self, 'finish')
     self.timer = PoolingTimer(timeout)
Esempio n. 16
0
 def __init__(self):
     State.__init__(self, 'print')
     self.timer = PoolingTimer(self.app.config.getfloat('PRINTER', 'printer_delay'))
     self.printed = False
Esempio n. 17
0
 def __init__(self, plugin_manager):
     self._pm = plugin_manager
     self.factory_pool = PicturesFactoryPool()
     self.picture_destroy_timer = PoolingTimer(0)
     self.second_previous_picture = None
Esempio n. 18
0
    def __init__(self, config, plugin_manager):
        self._pm = plugin_manager
        self._config = config

        # Create directories where pictures are saved
        for savedir in config.gettuple('GENERAL', 'directory', 'path'):
            if osp.isdir(savedir) and config.getboolean('GENERAL', 'debug'):
                shutil.rmtree(savedir)
            if not osp.isdir(savedir):
                os.makedirs(savedir)

        # Prepare the pygame module for use
        os.environ['SDL_VIDEO_CENTERED'] = '1'
        pygame.init()

        # Create window of (width, height)
        init_size = self._config.gettyped('WINDOW', 'size')
        init_debug = self._config.getboolean('GENERAL', 'debug')
        init_color = self._config.gettyped('WINDOW', 'background')
        init_text_color = self._config.gettyped('WINDOW', 'text_color')
        if not isinstance(init_color, (tuple, list)):
            init_color = self._config.getpath('WINDOW', 'background')

        title = 'Pibooth v{}'.format(pibooth.__version__)
        if not isinstance(init_size, str):
            self._window = PtbWindow(title,
                                     init_size,
                                     color=init_color,
                                     text_color=init_text_color,
                                     debug=init_debug)
        else:
            self._window = PtbWindow(title,
                                     color=init_color,
                                     text_color=init_text_color,
                                     debug=init_debug)

        self._menu = None
        self._multipress_timer = PoolingTimer(
            config.getfloat('CONTROLS', 'multi_press_delay'), False)

        # Define states of the application
        self._machine = StateMachine(self._pm, self._config, self,
                                     self._window)
        self._machine.add_state('wait')
        self._machine.add_state('choose')
        self._machine.add_state('chosen')
        self._machine.add_state('preview')
        self._machine.add_state('capture')
        self._machine.add_state('processing')
        self._machine.add_state('filter')
        self._machine.add_state('print')
        self._machine.add_state('finish')

        # ---------------------------------------------------------------------
        # Variables shared with plugins
        # Change them may break plugins compatibility
        self.capture_nbr = None
        self.capture_date = None
        self.capture_choices = (4, 1)
        self.previous_picture = None
        self.previous_animated = None
        self.previous_picture_file = None

        self.count = Counters(self._config.join_path("counters.pickle"),
                              taken=0,
                              printed=0,
                              forgotten=0,
                              remaining_duplicates=self._config.getint(
                                  'PRINTER', 'max_duplicates'))

        self.camera = camera.get_camera(
            config.getint('CAMERA', 'iso'),
            config.gettyped('CAMERA', 'resolution'),
            config.getint('CAMERA', 'rotation'),
            config.getboolean('CAMERA', 'flip'),
            config.getboolean('CAMERA', 'delete_internal_memory'))

        self.buttons = ButtonBoard(
            capture="BOARD" + config.get('CONTROLS', 'picture_btn_pin'),
            printer="BOARD" + config.get('CONTROLS', 'print_btn_pin'),
            hold_time=config.getfloat('CONTROLS', 'debounce_delay'),
            pull_up=True)
        self.buttons.capture.when_held = self._on_button_capture_held
        self.buttons.printer.when_held = self._on_button_printer_held

        self.leds = LEDBoard(
            capture="BOARD" + config.get('CONTROLS', 'picture_led_pin'),
            printer="BOARD" + config.get('CONTROLS', 'print_led_pin'))

        self.printer = Printer(config.get('PRINTER', 'printer_name'),
                               config.getint('PRINTER', 'max_pages'),
                               self.count)
Esempio n. 19
0
 def __init__(self, timeout):
     State.__init__(self, 'chosen', 'capture')
     self.timer = PoolingTimer(timeout)
Esempio n. 20
0
 def __init__(self):
     State.__init__(self, 'wait')
     self.timer = PoolingTimer(self.app.config.getfloat('WINDOW', 'animate_delay'))