示例#1
0
class StatePrint(State):
    def __init__(self):
        State.__init__(self, 'print', 'finish')
        self.timer = PoolingTimer(
            self.app.config.getfloat('PRINTER', 'printer_delay'))
        self.printed = False

    def entry_actions(self):
        self.printed = False
        if self.timer.timeout == 0:
            return  # Don't show print state

        with timeit("Display the merged picture"):
            self.app.window.show_print(self.app.previous_picture)
        self.app.led_print.blink()
        self.timer.start()

    def do_actions(self, events):
        if self.timer.timeout == 0:
            return  # Don't show print state

        if self.app.find_print_event(
                events) and self.app.previous_picture_file:
            with timeit("Send final picture to printer"):
                self.app.led_print.switch_on()
                self.app.printer.print_file(self.app.previous_picture_file)
            time.sleep(1)
            self.app.led_print.blink()
            self.printed = True

    def validate_transition(self, events):
        if self.timer.is_timeout() or self.printed:
            return self.next_name
示例#2
0
文件: booth.py 项目: swibrow/pibooth
 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'))
示例#3
0
class StatePrint(State):
    def __init__(self):
        State.__init__(self, 'print')
        self.timer = PoolingTimer(
            self.app.config.getfloat('PRINTER', 'printer_delay'))
        self.printed = False

    def entry_actions(self):
        self.printed = False

        with timeit("Display the final picture"):
            self.app.window.set_print_number(
                len(self.app.printer.get_all_tasks()),
                self.app.printer_unavailable)
            self.app.window.show_print(
                self.app.previous_picture,
                self.app.config.getboolean('SERVER', 'show_qr_on_screen'),
                self.app.previous_picture_qr_file_inverted)

        self.app.led_print.blink()
        # Reset timeout in case of settings changed
        self.timer.timeout = self.app.config.getfloat('PRINTER',
                                                      'printer_delay')
        self.timer.start()

    def do_actions(self, events):
        if self.app.find_print_qr_event(events):
            # print qr code:
            if self.app.qr_printer.nbr_printed == 0:
                LOGGER.info("print qr code now")
                self.app.qr_printer.print_file(
                    self.app.previous_picture_qr_file_print, 1)

        elif self.app.find_print_event(
                events) and self.app.previous_print_picture_file:

            with timeit("Send final picture to printer"):
                self.app.led_print.switch_on()
                print_value = self.app.config.get('SERVER', 'print_qr_code')
                if print_value == "Picture" or print_value == "Picture and Qr Code":
                    self.app.printer.print_file(
                        self.app.previous_print_picture_file,
                        self.app.config.getint('PRINTER', 'pictures_per_page'))
                if print_value == "Qr Code" or print_value == "Picture and Qr Code":
                    self.app.printer.print_file(
                        self.app.previous_picture_qr_file,
                        self.app.config.getint('PRINTER', 'pictures_per_page'))

            time.sleep(1)  # Just to let the LED switched on
            self.app.nbr_duplicates += 1
            self.app.led_print.blink()
            self.printed = True

    def validate_transition(self, events):
        if self.timer.is_timeout() or self.printed:
            if self.printed:
                self.app.window.set_print_number(
                    len(self.app.printer.get_all_tasks()),
                    self.app.printer_unavailable)
            return 'finish'
示例#4
0
文件: booth.py 项目: jpgreth/pibooth
class StatePrint(State):

    def __init__(self):
        State.__init__(self, 'print')
        self.timer = PoolingTimer(self.app.config.getfloat('PRINTER', 'printer_delay'))
        self.printed = False

    def entry_actions(self):
        self.printed = False
        with timeit("Display the merged picture"):
            self.app.window.show_print(self.app.previous_picture)
        self.app.led_print.blink()
        self.timer.start()

    def do_actions(self, events):
        if self.app.find_print_event(events) and self.app.previous_picture_file:

            with timeit("Send final picture to printer"):
                self.app.led_print.switch_on()
                self.app.printer.print_file(self.app.previous_picture_file,
                                            self.app.config.getint('PRINTER', 'nbr_copies'))

            time.sleep(2)  # Just to let the LED switched on
            self.app.nbr_printed += 1
            self.app.led_print.blink()
            self.printed = True

    def validate_transition(self, events):
        if self.timer.is_timeout() or self.printed:
            return 'finish'
示例#5
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()
示例#6
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())
示例#7
0
文件: camera.py 项目: nicog2/pibooth
    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)
示例#8
0
文件: booth.py 项目: nicog2/pibooth
class StateFinish(State):
    def __init__(self, timeout):
        State.__init__(self, 'finish')
        self.timer = PoolingTimer(timeout)

    def entry_actions(self):
        self.app.window.show_finished()
        self.timer.start()

    def validate_transition(self, events):
        if self.timer.is_timeout():
            return 'wait'
示例#9
0
文件: opencv.py 项目: vdubuk/pibooth
    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())
示例#10
0
文件: booth.py 项目: nicog2/pibooth
class StateFailSafe(State):
    def __init__(self, timeout):
        State.__init__(self, 'failsafe')
        self.timer = PoolingTimer(timeout)

    def entry_actions(self):
        self.app.dirname = None
        self.app.nbr_captures = None
        self.app.nbr_printed = 0
        self.app.camera.drop_captures()  # Flush previous captures
        self.app.window.show_oops()
        self.timer.start()

    def validate_transition(self, events):
        if self.timer.is_timeout():
            return 'wait'
示例#11
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())
示例#12
0
class StateChosen(State):
    def __init__(self, timeout):
        State.__init__(self, 'chosen', 'capture')
        self.timer = PoolingTimer(timeout)

    def entry_actions(self):
        with timeit("Set {} picture(s) mode".format(self.app.max_captures)):
            self.app.window.show_choice(self.app.max_captures)
        self.timer.start()

    def exit_actions(self):
        self.app.led_picture.switch_off()
        self.app.led_print.switch_off()

    def validate_transition(self, events):
        if self.timer.is_timeout():
            return self.next_name
示例#13
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
示例#14
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)
示例#15
0
文件: booth.py 项目: jpgreth/pibooth
class StateChosen(State):

    def __init__(self, timeout):
        State.__init__(self, 'chosen')
        self.timer = PoolingTimer(timeout)

    def entry_actions(self):
        with timeit("Show picture choice ({} pictures selected)".format(self.app.nbr_captures)):
            self.app.window.show_choice(self.app.capture_choices, selected=self.app.nbr_captures)
        self.timer.start()

    def exit_actions(self):
        self.app.led_picture.switch_off()
        self.app.led_print.switch_off()

    def validate_transition(self, events):
        if self.timer.is_timeout():
            return 'capture'
示例#16
0
class StateChoose(State):
    def __init__(self, timeout):
        State.__init__(self, 'choose', 'chosen')
        self.timer = PoolingTimer(timeout)

    def entry_actions(self):
        with timeit("Show picture choice (no default set)"):
            self.app.window.show_choice()
        self.app.max_captures = None
        self.app.led_picture.blink()
        self.app.led_print.blink()
        self.timer.start()

    def do_actions(self, events):
        event = self.app.find_choice_event(events)
        if event:
            if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
                self.app.max_captures = self.app.config.getint(
                    'PICTURE', 'captures')
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
                self.app.max_captures = 1
            elif event.pin == self.app.button_picture:
                self.app.max_captures = self.app.config.getint(
                    'PICTURE', 'captures')
            elif event.pin == self.app.button_print:
                self.app.max_captures = 1

    def exit_actions(self):
        if self.app.max_captures == self.app.config.getint(
                'PICTURE', 'captures'):
            self.app.led_picture.switch_on()
            self.app.led_print.switch_off()
        elif self.app.max_captures == 1:
            self.app.led_print.switch_on()
            self.app.led_picture.switch_off()
        else:
            self.app.led_print.switch_off()
            self.app.led_picture.switch_off()

    def validate_transition(self, events):
        if self.app.max_captures:
            return self.next_name
        elif self.timer.is_timeout():
            return "wait"
示例#17
0
class StatePrint(State):
    def __init__(self):
        State.__init__(self, 'print')
        self.timer = PoolingTimer(
            self.app.config.getfloat('PRINTER', 'printer_delay'))
        self.printed = False

    def entry_actions(self):
        self.printed = False

        with timeit("Display the final picture"):
            self.app.window.set_print_number(
                len(self.app.printer.get_all_tasks()),
                self.app.printer_unavailable)
            self.app.window.show_print(self.app.previous_picture)

        self.app.led_print.blink()
        # Reset timeout in case of settings changed
        self.timer.timeout = self.app.config.getfloat('PRINTER',
                                                      'printer_delay')
        self.timer.start()

    def do_actions(self, events):
        if self.app.find_print_event(
                events) and self.app.previous_picture_file:

            with timeit("Send final picture to printer"):
                self.app.led_print.switch_on()
                self.app.printer.print_file(
                    self.app.previous_picture_file,
                    self.app.config.getint('PRINTER', 'pictures_per_page'))

            time.sleep(1)  # Just to let the LED switched on
            self.app.nbr_duplicates += 1
            self.app.led_print.blink()
            self.printed = True

    def validate_transition(self, events):
        if self.timer.is_timeout() or self.printed:
            if self.printed:
                self.app.window.set_print_number(
                    len(self.app.printer.get_all_tasks()),
                    self.app.printer_unavailable)
            return 'finish'
示例#18
0
文件: ptb.py 项目: xuhui/pibooth
class StateChoose(State):

    def __init__(self, timeout):
        State.__init__(self, 'choose')
        self.timer = PoolingTimer(timeout)

    def entry_actions(self):
        with timeit("Show picture choice (nothing selected)"):
            self.app.window.show_choice(self.app.capt_choices)
        self.app.nbr_captures = None
        self.app.led_picture.blink()
        self.app.led_print.blink()
        self.timer.start()

    def do_actions(self, events):
        event = self.app.find_choice_event(events)
        if event:
            if (event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT) \
                    or (event.type == BUTTON_DOWN and event.pin == self.app.button_picture):
                self.app.nbr_captures = self.app.capt_choices[0]
            elif (event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT) \
                    or (event.type == BUTTON_DOWN and event.pin == self.app.button_print):
                self.app.nbr_captures = self.app.capt_choices[1]

    def exit_actions(self):
        if self.app.nbr_captures == self.app.capt_choices[0]:
            self.app.led_picture.switch_on()
            self.app.led_print.switch_off()
        elif self.app.nbr_captures == self.app.capt_choices[1]:
            self.app.led_print.switch_on()
            self.app.led_picture.switch_off()
        else:
            self.app.led_print.switch_off()
            self.app.led_picture.switch_off()

    def validate_transition(self, events):
        if self.app.nbr_captures:
            return 'chosen'
        elif self.timer.is_timeout():
            return 'wait'
示例#19
0
class StateChoose(State):

    def __init__(self, timeout):
        State.__init__(self, 'choose')
        self.timer = PoolingTimer(timeout)

    def entry_actions(self):
        with timeit("Show picture choice (nothing selected)"):
            self.app.window.set_print_number(0)  # Hide printer status
            self.app.window.show_choice(self.app.capture_choices)
        self.app.capture_nbr = None
        self.app.led_capture.blink()
        self.app.led_print.blink()
        self.timer.start()

    def do_actions(self, events):
        event = self.app.find_choice_event(events)
        if event:
            if event.key == pygame.K_LEFT:
                self.app.capture_nbr = self.app.capture_choices[0]
            elif event.key == pygame.K_RIGHT:
                self.app.capture_nbr = self.app.capture_choices[1]

    def exit_actions(self):
        if self.app.capture_nbr == self.app.capture_choices[0]:
            self.app.led_capture.switch_on()
            self.app.led_print.switch_off()
        elif self.app.capture_nbr == self.app.capture_choices[1]:
            self.app.led_print.switch_on()
            self.app.led_capture.switch_off()
        else:
            self.app.led_print.switch_off()
            self.app.led_capture.switch_off()

    def validate_transition(self, events):
        if self.app.capture_nbr:
            return 'chosen'
        elif self.timer.is_timeout():
            return 'wait'
示例#20
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)
示例#21
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())
示例#22
0
class StateFailSafe(State):
    def __init__(self, timeout):
        State.__init__(self, 'failsafe')
        self.timer = PoolingTimer(timeout)

    def entry_actions(self):
        self.app.dirname = None
        self.app.capture_nbr = None
        self.app.nbr_duplicates = 0
        self.app.previous_animated = []
        self.previous_picture = None
        self.previous_picture_file = None
        self.previous_print_picture_file = None
        self.web_upload_sucessful = False
        self.previous_print_picture_file_qith_qr = None
        self.previous_picture_qr_file = None
        self.previous_picture_qr_file_inverted = None
        self.app.camera.drop_captures()  # Flush previous captures
        self.app.window.show_oops()
        self.timer.start()

    def validate_transition(self, events):
        if self.timer.is_timeout():
            return 'wait'
示例#23
0
文件: gphoto.py 项目: jo-ei/pibooth
    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())
示例#24
0
文件: booth.py 项目: jpgreth/pibooth
 def __init__(self, timeout):
     State.__init__(self, 'choose')
     self.timer = PoolingTimer(timeout)
示例#25
0
文件: booth.py 项目: jpgreth/pibooth
 def __init__(self, timeout):
     State.__init__(self, 'failsafe')
     self.timer = PoolingTimer(timeout)
示例#26
0
文件: booth.py 项目: jpgreth/pibooth
 def __init__(self, timeout):
     State.__init__(self, 'finish')
     self.timer = PoolingTimer(timeout)
示例#27
0
文件: booth.py 项目: jpgreth/pibooth
 def __init__(self):
     State.__init__(self, 'print')
     self.timer = PoolingTimer(self.app.config.getfloat('PRINTER', 'printer_delay'))
     self.printed = False
示例#28
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
示例#29
0
class PicturePlugin(object):
    """Plugin to build the final picture.
    """
    def __init__(self, plugin_manager):
        self._pm = plugin_manager
        self.factory_pool = PicturesFactoryPool()
        self.picture_destroy_timer = PoolingTimer(0)
        self.second_previous_picture = None

    def _reset_vars(self, app):
        """Destroy final picture (can not be used anymore).
        """
        self.factory_pool.clear()
        app.previous_picture = None
        app.previous_animated = None
        app.previous_picture_file = None

    @pibooth.hookimpl(hookwrapper=True)
    def pibooth_setup_picture_factory(self, cfg, opt_index, factory):

        outcome = yield  # all corresponding hookimpls are invoked here
        factory = outcome.get_result() or factory

        factory.set_margin(cfg.getint('PICTURE', 'margin_thick'))

        backgrounds = cfg.gettuple('PICTURE', 'backgrounds', ('color', 'path'),
                                   2)
        factory.set_background(backgrounds[opt_index])

        overlays = cfg.gettuple('PICTURE', 'overlays', 'path', 2)
        if overlays[opt_index]:
            factory.set_overlay(overlays[opt_index])

        texts = [
            cfg.get('PICTURE', 'footer_text1').strip('"'),
            cfg.get('PICTURE', 'footer_text2').strip('"')
        ]
        colors = cfg.gettuple('PICTURE', 'text_colors', 'color', len(texts))
        text_fonts = cfg.gettuple('PICTURE', 'text_fonts', str, len(texts))
        alignments = cfg.gettuple('PICTURE', 'text_alignments', str,
                                  len(texts))
        if any(elem != '' for elem in texts):
            for params in zip(texts, text_fonts, colors, alignments):
                factory.add_text(*params)

        if cfg.getboolean('PICTURE', 'captures_cropping'):
            factory.set_cropping()

        if cfg.getboolean('GENERAL', 'debug'):
            factory.set_outlines()

        outcome.force_result(factory)

    @pibooth.hookimpl
    def pibooth_cleanup(self):
        self.factory_pool.quit()

    @pibooth.hookimpl
    def state_failsafe_enter(self, app):
        self._reset_vars(app)

    @pibooth.hookimpl
    def state_wait_enter(self, cfg, app):
        animated = self.factory_pool.get()
        if cfg.getfloat('WINDOW', 'wait_image_delay') == 0:
            # Do it here to avoid a transient display of the picture
            self._reset_vars(app)
        elif animated:
            app.previous_animated = itertools.cycle(animated)

        # Reset timeout in case of settings changed
        self.picture_destroy_timer.timeout = max(
            0, cfg.getfloat('WINDOW', 'wait_image_delay'))
        self.picture_destroy_timer.start()

    @pibooth.hookimpl
    def state_wait_do(self, cfg, app):
        if cfg.getfloat('WINDOW', 'wait_image_delay') > 0 and self.picture_destroy_timer.is_timeout()\
                and app.previous_picture_file:
            self._reset_vars(app)

    @pibooth.hookimpl
    def state_processing_enter(self, app):
        self.second_previous_picture = app.previous_picture
        self._reset_vars(app)

    @pibooth.hookimpl
    def state_processing_do(self, cfg, app):
        idx = app.capture_choices.index(app.capture_nbr)

        with timeit("Saving raw captures"):
            captures = app.camera.get_captures()

            for savedir in cfg.gettuple('GENERAL', 'directory', 'path'):
                rawdir = osp.join(savedir, "raw", app.capture_date)
                os.makedirs(rawdir)

                for capture in captures:
                    count = captures.index(capture)
                    capture.save(
                        osp.join(rawdir, "pibooth{:03}.jpg".format(count)))

        with timeit("Creating the final picture"):
            default_factory = get_picture_factory(
                captures, cfg.get('PICTURE', 'orientation'))
            factory = self._pm.hook.pibooth_setup_picture_factory(
                cfg=cfg, opt_index=idx, factory=default_factory)
            app.previous_picture = factory.build()

        for savedir in cfg.gettuple('GENERAL', 'directory', 'path'):
            app.previous_picture_file = osp.join(savedir, app.picture_filename)
            factory.save(app.previous_picture_file)

        if cfg.getboolean('WINDOW', 'animate') and app.capture_nbr > 1:
            with timeit("Asyncronously generate pictures for animation"):
                for capture in captures:
                    default_factory = get_picture_factory(
                        (capture, ),
                        cfg.get('PICTURE', 'orientation'),
                        force_pil=True,
                        dpi=200)
                    factory = self._pm.hook.pibooth_setup_picture_factory(
                        cfg=cfg, opt_index=idx, factory=default_factory)
                    factory.set_margin(factory._margin //
                                       3)  # 1/3 since DPI is divided by 3
                    self.factory_pool.add(factory)

    @pibooth.hookimpl
    def state_processing_exit(self, app):
        app.count.taken += 1  # Do it here because 'print' state can be skipped

    @pibooth.hookimpl
    def state_print_do(self, cfg, app, events):
        if app.find_capture_event(events):

            with timeit("Moving the picture in the forget folder"):

                for savedir in cfg.gettuple('GENERAL', 'directory', 'path'):
                    forgetdir = osp.join(savedir, "forget")
                    if not osp.isdir(forgetdir):
                        os.makedirs(forgetdir)
                    os.rename(osp.join(savedir, app.picture_filename),
                              osp.join(forgetdir, app.picture_filename))

            self._reset_vars(app)
            app.count.forgotten += 1
            app.previous_picture = self.second_previous_picture

            # Deactivate the print function for the backuped picture
            # as we don't known how many times it has already been printed
            app.count.remaining_duplicates = 0
示例#30
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)