def test_screen_data_with_execute_loop(self):
        self._prepare()
        screen = ScreenData(self.ui_screen, execute_new_loop=True)
        self._screen_check(screen, self.ui_screen, None, True)

        screen2 = ScreenData(self.ui_screen, execute_new_loop=False)
        self._screen_check(screen2, self.ui_screen, None, False)
    def test_screen_data_with_args(self):
        self._prepare()
        screen = ScreenData(ui_screen=self.ui_screen, args=1)
        self._screen_check(screen, self.ui_screen, 1, False)

        array = [2, "a"]
        screen2 = ScreenData(ui_screen=self.ui_screen, args=array)
        self._screen_check(screen2, self.ui_screen, array, False)
    def test_stack_dump(self):
        stack = ScreenStack()

        stack.append(ScreenData(TestScreen1()))
        stack.append(ScreenData(TestScreen2()))

        dump = stack.dump_stack()
        dump = dump.replace('\n', '')
        self.assertRegex(dump, r"TestScreen2.*TestScreen1")
示例#4
0
    def test_stack_dump(self):
        stack = ScreenStack()

        stack.append(ScreenData(ScreenMock1()))
        stack.append(ScreenData(ScreenMock2()))

        dump = stack.dump_stack()
        dump = dump.replace('\n', '')
        self.assertRegex(dump, r"ScreenMock2.*ScreenMock1")
    def test_add_first(self):
        stack = ScreenStack()

        screen_data = ScreenData(None)
        stack.add_first(screen_data)
        self.assertEqual(stack.pop(False), screen_data)

        # Add new Screen data to the end
        new_screen_data = ScreenData(None)
        stack.add_first(new_screen_data)
        # First the old screen data should be there
        self.assertEqual(stack.pop(), screen_data)
        # Second should be the new screen data
        self.assertEqual(stack.pop(), new_screen_data)
    def test_size(self):
        stack = ScreenStack()
        self.assertEqual(stack.size(), 0)

        stack.append(ScreenData(None))
        self.assertEqual(stack.size(), 1)

        stack.append(ScreenData(None))
        self.assertEqual(stack.size(), 2)

        # Remove from stack
        stack.pop()
        self.assertEqual(stack.size(), 1)
        stack.pop()
        self.assertEqual(stack.size(), 0)

        # Add first when stack has items
        stack.append(ScreenData(None))
        stack.append(ScreenData(None))
        self.assertEqual(stack.size(), 2)
        stack.add_first(ScreenData(None))
        self.assertEqual(stack.size(), 3)
    def push_screen(self, ui_screen, args=None):
        """Schedules a screen to show, but keeps the current one in stack to
        return to, when the new one is closed.

        :param ui_screen: screen to show
        :type ui_screen: UIScreen instance
        :param args: optional argument
        :type args: anything
        """
        log.debug("Pushing screen %s to stack", ui_screen)
        screen = ScreenData(ui_screen, args, False)
        self._screen_stack.append(screen)
        self.redraw()
    def test_pop(self):
        stack = ScreenStack()
        with self.assertRaises(ScreenStackEmptyException):
            stack.pop()

        with self.assertRaises(ScreenStackEmptyException):
            stack.pop(False)

        # stack.pop(True) will remove the item
        stack.append(ScreenData(None))
        stack.pop(True)
        with self.assertRaises(ScreenStackEmptyException):
            stack.pop()

        # stack.pop() should behave the same as stack.pop(True)
        stack.append(ScreenData(None))
        stack.pop()
        with self.assertRaises(ScreenStackEmptyException):
            stack.pop()

        stack.append(ScreenData(None))
        stack.pop(False)
        stack.pop(True)
    def schedule_screen(self, ui_screen, args=None):
        """Add screen to the bottom of the stack.

        This is mostly useful at the beginning to prepare the first screen hierarchy to display.

        :param ui_screen: screen to show
        :type ui_screen: UIScreen instance
        :param args: optional argument, please see switch_screen for details
        :type args: anything
        """
        log.debug("Scheduling screen %s", ui_screen)
        screen = ScreenData(ui_screen, args)
        self._screen_stack.add_first(screen)
        self._redraw_on_first_scheduled_screen()
    def push_screen_modal(self, ui_screen, args=None):
        """Starts a new screen right away, so the caller can collect data back.

        When the new screen is closed, the caller is redisplayed.

        This method does not return until the new screen is closed.

        :param ui_screen: screen to show
        :type ui_screen: UIScreen instance
        :param args: optional argument, please see switch_screen for details
        :type args: anything
        """
        log.debug("Pushing modal screen %s to stack", ui_screen)
        screen = ScreenData(ui_screen, args, True)
        self._screen_stack.append(screen)
        # only new events will be processed now
        # the old one will wait after this event loop will be closed
        self._event_loop.execute_new_loop(RenderScreenSignal(self))
    def replace_screen(self, ui_screen, args=None):
        """Schedules a screen to replace the current one.

        :param ui_screen: screen to show
        :type ui_screen: instance of UIScreen
        :param args: optional argument to pass to ui's refresh and setup methods
                     (can be used to select what item should be displayed or so)
        :type args: anything
        """
        log.debug("Replacing screen %s", ui_screen)
        try:
            execute_new_loop = self._screen_stack.pop().execute_new_loop
        except ScreenStackEmptyException:  # pylint: disable=try-except-raise
            raise ScreenStackEmptyException("Switch screen is not possible when there is no "
                                            "screen scheduled!")

        # we have to keep the old_loop value so we stop
        # dialog's mainloop if it ever uses switch_screen
        screen = ScreenData(ui_screen, args, execute_new_loop)
        self._screen_stack.append(screen)
        self.redraw()
 def test_is_empty(self):
     stack = ScreenStack()
     self.assertTrue(stack.empty())
     stack.append(ScreenData(None))
     self.assertFalse(stack.empty())
 def test_append_screen(self):
     stack = ScreenStack()
     stack.append(ScreenData(None))
 def test_screen_data_with_args_and_execute_loop(self):
     self._prepare()
     screen = ScreenData(self.ui_screen, "test", True)
     self._screen_check(screen, self.ui_screen, "test", True)
 def test_screen_data(self):
     self._prepare()
     screen = ScreenData(self.ui_screen)
     self._screen_check(screen, self.ui_screen, None, False)