How to use the pibooth.utils.LOGGER function in pibooth

To help you get started, we’ve selected a few pibooth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github werdeil / pibooth / pibooth / booth.py View on Github external
def do_actions(self, events):
        if self.app.config.getboolean('WINDOW', 'animate') and self.app.previous_animated and self.timer.is_timeout():
            previous_picture = next(self.app.previous_animated)
            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.timer.start()
        else:
            previous_picture = self.app.previous_picture

        if self.app.find_print_event(events) and self.app.previous_picture_file and self.app.printer.is_installed():

            if self.app.nbr_duplicates >= self.app.config.getint('PRINTER', 'max_duplicates'):
                LOGGER.warning("Too many duplicates sent to the printer (%s max)",
                               self.app.config.getint('PRINTER', 'max_duplicates'))
                return

            elif self.app.printer_unavailable:
                LOGGER.warning("Maximum number of printed pages reached (%s/%s max)", self.app.printer.nbr_printed,
                               self.app.config.getint('PRINTER', 'max_pages'))
                return

            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
github werdeil / pibooth / pibooth / plugins / printer_plugin.py View on Github external
def state_wait_do(self, cfg, app, events):
        if app.find_print_event(events) and app.previous_picture_file and app.printer.is_installed():

            if app.count.remaining_duplicates < 0:
                LOGGER.warning("Too many duplicates sent to the printer (%s max)",
                               cfg.getint('PRINTER', 'max_duplicates'))
                return

            elif not app.printer.is_available():
                LOGGER.warning("Maximum number of printed pages reached (%s/%s max)", app.count.printed,
                               cfg.getint('PRINTER', 'max_pages'))
                return

            with timeit("Send final picture to printer"):
                app.printer.print_file(app.previous_picture_file,
                                       cfg.getint('PRINTER', 'pictures_per_page'))
                app.count.printed += 1

            app.count.remaining_duplicates -= 1
github werdeil / pibooth / pibooth / booth.py View on Github external
event = self._menu.create_back_event()
                LOGGER.debug("BUTTONDOWN: generate MENU-ESC event")
            else:
                event = pygame.event.Event(BUTTONDOWN, capture=1, printer=1,
                                           button=self.buttons)
                LOGGER.debug("BUTTONDOWN: generate DOUBLE buttons event")
        else:
            # capture was held but printer not pressed
            if self._menu and self._menu.is_shown():
                # Convert HW button events to keyboard events for menu
                event = self._menu.create_next_event()
                LOGGER.debug("BUTTONDOWN: generate MENU-NEXT event")
            else:
                event = pygame.event.Event(BUTTONDOWN, capture=1, printer=0,
                                           button=self.buttons.capture)
                LOGGER.debug("BUTTONDOWN: generate CAPTURE button event")
        pygame.event.post(event)
github werdeil / pibooth / pibooth / plugins / __init__.py View on Github external
def load_plugins(plugin_manager, *paths):
    """Register the core plugins and load those from the given paths.

    note:: by default hooks are called in LIFO registered order thus
           plugins register order is important.

    :param plugin_manager: plugins manager instance
    :type plugin_manager: :py:class:`pluggy.PluginManager`
    :param paths: list of Python module paths to load
    :type paths: str
    """
    plugins = []
    for path in paths:
        plugin = load_module(path)
        if plugin:
            LOGGER.debug("Plugin found at '%s'", path)
            plugins.append(plugin)

    plugins += [LightsPlugin(plugin_manager),  # Last called
                ViewPlugin(plugin_manager),
                PrinterPlugin(plugin_manager),
                PicturePlugin(plugin_manager),
                CameraPlugin(plugin_manager)]  # First called

    for plugin in plugins:
        plugin_manager.register(plugin)

    # Check that each hookimpl is defined in the hookspec
    # except for hookimpl with kwarg 'optionalhook=True'.
    plugin_manager.check_pending()
github werdeil / pibooth / pibooth / states.py View on Github external
def set_state(self, state_name):
        """Change state machine's active state
        """
        try:
            # Perform any exit actions of the current state
            if self.active_state is not None:
                self.active_state.exit_actions()
        except Exception as ex:
            if self.failsafe_state and self.active_state != self.failsafe_state:
                LOGGER.error(str(ex))
                if BlockConsoleHandler.is_debug():
                    traceback.print_exc()
                state_name = self.failsafe_state.name
            else:
                raise

        if state_name not in self.states:
            raise ValueError('"{}" not in registered states...'.format(state_name))

        # Switch to the new state and perform its entry actions
        LOGGER.debug("Activate state '%s'", state_name)
        self.active_state = self.states[state_name]

        try:
            self.active_state.entry_actions()
        except Exception as ex:
github werdeil / pibooth / pibooth / printer.py View on Github external
return  # CUPS is not installed

        if not name or name.lower() == 'default':
            self.name = self._conn.getDefault()
            if not self.name and self._conn.getPrinters():
                self.name = list(self._conn.getPrinters().keys())[0]  # Take first one
        elif name in self._conn.getPrinters():
            self.name = name

        if not self.name:
            if name.lower() == 'default':
                LOGGER.warning("No printer configured in CUPS (see http://localhost:631)")
            else:
                LOGGER.warning("No printer named '%s' in CUPS (see http://localhost:631)", name)
        else:
            LOGGER.info("Connected to printer '%s'", self.name)
github werdeil / pibooth / pibooth / plugins / camera_plugin.py View on Github external
def state_preview_enter(self, cfg, app, win):
        LOGGER.info("Show preview before next capture")
        if not app.capture_nbr:
            app.capture_nbr = app.capture_choices[0]
        if not app.capture_date:
            app.capture_date = time.strftime("%Y-%m-%d-%H-%M-%S")
        app.camera.preview(win)