Beispiel #1
0
    def main_loop(self):
        """Run the main game loop.
        """
        try:
            clock = pygame.time.Clock()
            self.led_startup.switch_on()
            self.initialize()
            menu = None
            fps = 40

            while True:
                events = list(pygame.event.get())

                if self.find_quit_event(events):
                    break

                if self.find_fullscreen_event(events):
                    self.window.toggle_fullscreen()

                event = self.find_resize_event(events)
                if event:
                    self.window.resize(event.size)

                if not menu and self.find_settings_event(events):
                    menu = PiConfigMenu(self.window, self.config, fps)
                    menu.show()

                if menu and menu.is_shown():
                    # Convert HW button events to keyboard events for menu
                    if self.find_settings_event(events, BUTTON_DOWN):
                        events.insert(0, menu.create_back_event())
                    if self.find_capture_event(events, BUTTON_DOWN):
                        events.insert(0, menu.create_next_event())
                    elif self.find_print_event(events, BUTTON_DOWN):
                        events.insert(0, menu.create_click_event())

                    menu.process(events)
                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()
Beispiel #2
0
    def main_loop(self):
        """Run the main game loop.
        """
        try:
            clock = pygame.time.Clock()
            self._initialize()
            self._plugin_manager.hook.pibooth_startup(app=self)
            menu = None
            fps = 40

            while True:
                events = list(pygame.event.get())

                if self.find_quit_event(events):
                    break

                if self.find_fullscreen_event(events):
                    self._window.toggle_fullscreen()

                event = self.find_resize_event(events)
                if event:
                    self._window.resize(event.size)

                if not menu and self.find_settings_event(events):
                    menu = PiConfigMenu(self._window,
                                        self._config,
                                        fps,
                                        version=pibooth.__version__)
                    menu.show()

                if menu and menu.is_shown():
                    # Convert HW button events to keyboard events for menu
                    if self.find_settings_event(events, BUTTON_DOWN):
                        events.insert(0, menu.create_back_event())
                    if self.find_capture_event(events, BUTTON_DOWN):
                        events.insert(0, menu.create_next_event())
                    elif self.find_print_event(events, BUTTON_DOWN):
                        events.insert(0, menu.create_click_event())
                    menu.process(events)
                elif menu and not menu.is_shown():
                    self._initialize()
                    menu = None
                else:
                    self._machine.process(events)

                pygame.display.update()
                clock.tick(
                    fps
                )  # Ensure the program will never run at more than <fps> frames per second

        finally:
            self._plugin_manager.hook.pibooth_cleanup(app=self)
            pygame.quit()