Exemple #1
0
    def __init__(self,
                 name,
                 scene: Node,
                 window_size: Tuple[int, int] = (640, 480),
                 fullscreen: bool = False):
        """
        Instantiates a new PyEngy app.

        :param name: The name of the app. Should be unique.
        :param scene: The scene for the app to handle.
        :param window_size: The size of the window.
        :param fullscreen: If true, will set to fullscreen. Otherwise will set to window.
        """
        # Create the app variables and thread
        self.name = name
        self._scene = scene
        self._stop_event = threading.Event()
        self._app = threading.Thread(target=self.__run_app,
                                     name=name,
                                     daemon=True)

        # Set window parameters
        self._screen = None
        self._window_size = window_size
        self._fullscreen = fullscreen
        self._background = None

        # Set defaults for execution variables
        reset_time(self.name)
        self._previous_time = 0.0
        self._current_time = 0.0
        self._logger = get_logger("", self.name)
        self._context = Context({})
    def test_reset_time_for_non_existing_app_sets_start_time_of_app_to_current_time(self):
        """
        - Given: Start time
        - When: Calling ``reset_time`` for a given app that does not exist.
        - Then: Should reset the app start time to current time.
        """
        reset_time("missing_app")

        self.assertEqual(EXPECTED_RESET_START_TIME, pyengy.util.time_utils.START_TIME["missing_app"])
    def test_reset_time_sets_start_time_to_current_time(self):
        """
        - Given: Start time
        - When: Calling ``reset_time`` for a given app.
        - Then: Should reset the start time to current time for given app.
        """
        reset_time("test_app")

        self.assertEqual(EXPECTED_RESET_START_TIME, pyengy.util.time_utils.START_TIME["test_app"])
        self.assertEqual(MOCK_START_TIME["default"], pyengy.util.time_utils.START_TIME["default"])
Exemple #4
0
    def start(self) -> None:
        """Starts the app. Does nothing if the app is already running."""
        if self._app.is_alive():
            self._logger.debug("Trying to start a running app \"{}\"".format(
                self.name))
            return

        # Reset the time of app
        reset_time(self.name)
        self._logger.debug("Starting app \"{}\"".format(self.name))
        self._previous_time = get_current_time(self.name)
        self._current_time = get_current_time(self.name)

        # Start the thread
        self._stop_event.clear()
        self._app.start()