Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
elif menu and not menu.is_shown():
self.initialize()
menu = None
else:
self.state_machine.process(events)
pygame.display.update()
clock.tick(fps) # Ensure the program will never run at more than x frames per second
finally:
self.makers_pool.quit()
self.led_startup.quit()
self.led_preview.quit()
self.led_capture.quit()
self.led_print.quit()
GPIO.cleanup()
self.camera.quit()
self.printer.quit()
pygame.quit()
def __init__(self, config):
self.config = config
# Clean directory where pictures are saved
self.savedir = config.getpath('GENERAL', 'directory')
if not osp.isdir(self.savedir):
os.makedirs(self.savedir)
if osp.isdir(self.savedir) and config.getboolean('GENERAL', 'clear_on_startup'):
shutil.rmtree(self.savedir)
os.makedirs(self.savedir)
# Prepare GPIO, physical pins mode
GPIO.setmode(GPIO.BOARD)
# 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_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')
if not isinstance(init_size, str):
self.window = PtbWindow('Pibooth', init_size, color=init_color, text_color=init_text_color)
else:
def switch_off(self):
"""Switch off the LED.
"""
if threading.current_thread() != self._blinking_thread:
self._blinking_thread.unregister(self)
GPIO.output(self.pin, GPIO.LOW)
def __init__(self, pin, bouncetime=0.1):
self.pin = pin
# Use internal pull up/down resistors
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(self.pin, GPIO.FALLING,
callback=self.on_button_down,
bouncetime=int(bouncetime * 1000))
def __init__(self, pin):
self.pin = pin
GPIO.setup(pin, GPIO.OUT)