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