コード例 #1
0
def main():
    """Application entry point.
    """
    configure_logging()
    plugin_manager = create_plugin_manager()
    config = PiConfigParser("~/.config/pibooth/pibooth.cfg", plugin_manager)

    # Register plugins
    custom_paths = [p for p in config.gettuple('GENERAL', 'plugins', 'path') if p]
    load_plugins(plugin_manager, *custom_paths)

    # Update configuration with plugins ones
    plugin_manager.hook.pibooth_configure(cfg=config)

    for path in config.gettuple('GENERAL', 'directory', 'path'):
        regenerate_all_images(plugin_manager, config, path)
コード例 #2
0
    def __init__(self, config):
        self._config = config

        # Clean directory where pictures are saved
        savedir = config.getpath('GENERAL', 'directory')
        if not osp.isdir(savedir):
            os.makedirs(savedir)
        elif osp.isdir(savedir) and config.getboolean('GENERAL', 'debug'):
            shutil.rmtree(savedir)
            os.makedirs(savedir)

        # Prepare the pygame module for use
        os.environ['SDL_VIDEO_CENTERED'] = '1'
        pygame.init()
        # Dont catch mouse motion to avoid filling the queue during long actions
        pygame.event.set_blocked(pygame.MOUSEMOTION)

        # 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)

        # Create plugin manager and defined hooks specification
        self._plugin_manager = pluggy.PluginManager(
            hookspecs.hookspec.project_name)
        self._plugin_manager.add_hookspecs(hookspecs)
        self._plugin_manager.load_setuptools_entrypoints(
            hookspecs.hookspec.project_name)

        # Register plugins
        custom_paths = [
            p for p in self._config.gettuple('GENERAL', 'plugins', 'path') if p
        ]
        load_plugins(self._plugin_manager, *custom_paths)

        # Define states of the application
        self._machine = StateMachine(self._plugin_manager, 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('print')
        self._machine.add_state('finish')

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

        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.button_capture = Button(
            "BOARD" + config.get('CONTROLS', 'picture_btn_pin'),
            bounce_time=config.getfloat('CONTROLS', 'debounce_delay'),
            pull_up=True,
            hold_time=1)

        self.button_print = Button(
            "BOARD" + config.get('CONTROLS', 'print_btn_pin'),
            bounce_time=config.getfloat('CONTROLS', 'debounce_delay'),
            pull_up=True,
            hold_time=1)

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

        self.printer = PtbPrinter(config.get('PRINTER', 'printer_name'))
コード例 #3
0
ファイル: booth.py プロジェクト: romaingerardy/pibooth
def main():
    """Application entry point.
    """
    if hasattr(multiprocessing, 'set_start_method'):
        # Avoid use 'fork': safely forking a multithreaded process is problematic
        multiprocessing.set_start_method('spawn')

    parser = argparse.ArgumentParser(usage="%(prog)s [options]",
                                     description=pibooth.__doc__)

    parser.add_argument('--version',
                        action='version',
                        version=pibooth.__version__,
                        help=u"show program's version number and exit")

    parser.add_argument("--config",
                        action='store_true',
                        help=u"edit the current configuration and exit")

    parser.add_argument("--translate",
                        action='store_true',
                        help=u"edit the GUI translations and exit")

    parser.add_argument(
        "--reset",
        action='store_true',
        help=u"restore the default configuration/translations and exit")

    parser.add_argument("--fonts",
                        action='store_true',
                        help=u"display all available fonts and exit")

    parser.add_argument(
        "--nolog",
        action='store_true',
        default=False,
        help=
        u"don't save console output in a file (avoid filling the /tmp directory)"
    )

    group = parser.add_mutually_exclusive_group()
    group.add_argument("-v",
                       "--verbose",
                       dest='logging',
                       action='store_const',
                       const=logging.DEBUG,
                       help=u"report more information about operations",
                       default=logging.INFO)
    group.add_argument("-q",
                       "--quiet",
                       dest='logging',
                       action='store_const',
                       const=logging.WARNING,
                       help=u"report only errors and warnings",
                       default=logging.INFO)

    options, _args = parser.parse_known_args()

    if not options.nolog:
        filename = osp.join(tempfile.gettempdir(), 'pibooth.log')
    else:
        filename = None
    configure_logging(options.logging,
                      '[ %(levelname)-8s] %(name)-18s: %(message)s',
                      filename=filename)

    plugin_manager = create_plugin_manager()

    # Load the configuration and languages
    config = PiConfigParser("~/.config/pibooth/pibooth.cfg", plugin_manager)
    language.init(config.join_path("translations.cfg"), options.reset)

    # Register plugins
    custom_paths = [
        p for p in config.gettuple('GENERAL', 'plugins', 'path') if p
    ]
    load_plugins(plugin_manager, *custom_paths)
    LOGGER.info("Installed plugins: %s",
                ", ".join(list_plugin_names(plugin_manager)))

    # Update configuration with plugins ones
    plugin_manager.hook.pibooth_configure(cfg=config)

    # Ensure config files are present in case of first pibooth launch
    if not options.reset:
        if not osp.isfile(config.filename):
            config.save(default=True)
        plugin_manager.hook.pibooth_reset(cfg=config, hard=False)

    if options.config:
        LOGGER.info("Editing the pibooth configuration...")
        config.edit()
    elif options.translate:
        LOGGER.info("Editing the GUI translations...")
        language.edit()
    elif options.fonts:
        LOGGER.info("Listing all fonts available...")
        print_columns_words(get_available_fonts(), 3)
    elif options.reset:
        config.save(default=True)
        plugin_manager.hook.pibooth_reset(cfg=config, hard=True)
    else:
        LOGGER.info("Starting the photo booth application %s", GPIO_INFO)
        app = PiApplication(config, plugin_manager)
        app.main_loop()
コード例 #4
0
def main():
    """Application entry point.
    """
    parser = argparse.ArgumentParser(usage="%(prog)s [options]", description=pibooth.__doc__)

    parser.add_argument('--version', action='version', version=pibooth.__version__,
                        help=u"show program's version number and exit")

    parser.add_argument("--config", action='store_true',
                        help=u"edit the current configuration and exit")

    parser.add_argument("--translate", action='store_true',
                        help=u"edit the GUI translations and exit")

    parser.add_argument("--reset", action='store_true',
                        help=u"restore the default configuration/translations and exit")

    parser.add_argument("--fonts", action='store_true',
                        help=u"display all available fonts and exit")

    parser.add_argument("--log", default=None,
                        help=u"save logs output to the given file")

    group = parser.add_mutually_exclusive_group()
    group.add_argument("-v", "--verbose", dest='logging', action='store_const', const=logging.DEBUG,
                       help=u"report more information about operations", default=logging.INFO)
    group.add_argument("-q", "--quiet", dest='logging', action='store_const', const=logging.WARNING,
                       help=u"report only errors and warnings", default=logging.INFO)

    options, _args = parser.parse_known_args()

    configure_logging(options.logging, '[ %(levelname)-8s] %(name)-18s: %(message)s', filename=options.log)

    # Create plugin manager and defined hooks specification
    plugin_manager = pluggy.PluginManager(hookspecs.hookspec.project_name)
    plugin_manager.add_hookspecs(hookspecs)
    plugin_manager.load_setuptools_entrypoints(hookspecs.hookspec.project_name)

    # Load the configuration and languages
    config = PiConfigParser("~/.config/pibooth/pibooth.cfg", plugin_manager, options.reset)
    language.init("~/.config/pibooth/translations.cfg", options.reset)

    # Register plugins
    custom_paths = [p for p in config.gettuple('GENERAL', 'plugins', 'path') if p]
    load_plugins(plugin_manager, *custom_paths)
    LOGGER.info("Installed plugins: %s", ", ".join(list_plugin_names(plugin_manager)))

    # Update plugins configuration
    plugin_manager.hook.pibooth_configure(cfg=config)
    if not osp.isfile(config.filename):
        config.save()

    if options.config:
        LOGGER.info("Editing the pibooth configuration...")
        config.edit()
    elif options.translate:
        LOGGER.info("Editing the GUI translations...")
        language.edit()
    elif options.fonts:
        LOGGER.info("Listing all fonts available...")
        print_columns_words(get_available_fonts(), 3)
    elif options.reset:
        config.save()
    else:
        LOGGER.info("Starting the photo booth application %s", GPIO_INFO)
        app = PiApplication(config, plugin_manager)
        app.main_loop()