Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@pibooth.hookimpl
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'))
@pibooth.hookimpl
def state_preview_do(self, cfg, app):
pygame.event.pump() # Before blocking actions
if cfg.getboolean('WINDOW', 'preview_countdown'):
app.camera.preview_countdown(cfg.getint('WINDOW', 'preview_delay'))
else:
app.camera.preview_wait(cfg.getint('WINDOW', 'preview_delay'))
@pibooth.hookimpl
def pibooth_cleanup(self, app):
app.camera.quit()
@pibooth.hookimpl
def state_chosen_enter(self, app, win):
with timeit("Show picture choice ({} captures selected)".format(app.capture_nbr)):
win.show_choice(app.capture_choices, selected=app.capture_nbr)
self.layout_timer.start()
@pibooth.hookimpl
def state_processing_exit(self, cfg, app):
app.count.remaining_duplicates = cfg.getint('PRINTER', 'max_duplicates')
# Do it here because 'print' state can be skipped
@pibooth.hookimpl
def state_capture_do(self, cfg, app, win):
effects = cfg.gettyped('PICTURE', 'captures_effects')
if not isinstance(effects, (list, tuple)):
# Same effect for all captures
effect = effects
elif len(effects) >= app.capture_nbr:
# Take the effect corresponding to the current capture
effect = effects[self.count]
else:
# Not possible
raise ValueError("Not enough effects defined for {} captures {}".format(
app.capture_nbr, effects))
with timeit("Take a capture"):
if cfg.getboolean('WINDOW', 'flash'):
with win.flash(2): # Manage the window here, have no choice
@pibooth.hookimpl
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)
@pibooth.hookimpl
def state_print_validate(self, app, win, events):
printed = app.find_print_event(events)
forgotten = app.find_capture_event(events)
if self.print_view_timer.is_timeout() or printed or forgotten:
if printed:
win.set_print_number(len(app.printer.get_all_tasks()), not app.printer.is_available())
return 'finish'
@pibooth.hookimpl
def state_wait_do(self, cfg, app):
if cfg.getfloat('WINDOW', 'final_image_delay') > 0 and self.picture_destroy_timer.is_timeout()\
and app.previous_picture_file:
self._reset_vars(app)
@pibooth.hookimpl
def state_choose_enter(self, app):
app.leds.blink(on_time=self.blink_time, off_time=self.blink_time)