Example #1
0
    def test_priorities(self):
        # show slide 1, p100
        slide1 = Slide(mc=self.mc, name='slide1', priority=100)
        self.mc.targets['window'].show_slide('slide1')
        self.assertEqual(self.mc.targets['window'].current_slide, slide1)

        # show slide 2, p0, it should not show
        slide2 = Slide(mc=self.mc, name='slide2', priority=0)
        self.mc.targets['window'].show_slide('slide2')
        self.assertEqual(self.mc.targets['window'].current_slide, slide1)

        # show slide 3, p200, it should show
        slide3 = Slide(mc=self.mc, name='slide3', config={}, priority=200)
        self.mc.targets['window'].show_slide('slide3')
        self.assertEqual(self.mc.targets['window'].current_slide, slide3)

        # show slide 4, p199, it should not show
        slide4 = Slide(mc=self.mc, name='slide4', config={}, priority=199)
        self.mc.targets['window'].show_slide('slide4')
        self.assertLess(slide4.priority,
                        self.mc.targets['window'].current_slide.priority)

        # confirm that slide 3 is still current
        self.assertEqual(self.mc.targets['window'].current_slide, slide3)

        # force slide 4 to show
        self.assertLess(slide4.priority,
                        self.mc.targets['window'].current_slide.priority)
        self.mc.targets['window'].show_slide('slide4', force=True)

        # slide should show
        self.assertEqual(self.mc.targets['window'].current_slide_name,
                         'slide4')
Example #2
0
    def test_current_slide_properties(self):
        # make sure we get the default blank slide
        self.assertEqual(self.mc.displays['window'].current_slide_name,
                         'window_blank')

        slide1 = Slide(mc=self.mc, name='slide1')
        self.mc.targets['default'].current_slide_name = 'slide1'

        # test display properties
        self.assertEqual(self.mc.displays['window'].current_slide, slide1)
        self.assertEqual(self.mc.displays['window'].current_slide_name,
                         'slide1')

        # test target properties
        self.assertEqual(self.mc.targets['window'].current_slide, slide1)
        self.assertEqual(self.mc.targets['window'].current_slide_name,
                         'slide1')

        # make sure showing a slide at the same priority replaces the current
        # one.
        slide2 = Slide(mc=self.mc, name='slide2')
        self.mc.targets['window'].show_slide('slide2')

        self.assertEqual(self.mc.targets['window'].current_slide, slide2)
        self.assertEqual(self.mc.targets['window'].current_slide_name,
                         'slide2')
        self.assertEqual(self.mc.displays['window'].current_slide_name,
                         'slide2')
        self.assertEqual(self.mc.displays['window'].current_slide, slide2)

        # test property setters for displays
        self.mc.targets['window'].current_slide_name = 'slide1'
        self.assertEqual(self.mc.targets['window'].current_slide, slide1)

        self.mc.targets['window'].current_slide_name = 'slide2'
        self.assertEqual(self.mc.targets['window'].current_slide, slide2)

        self.mc.targets['window'].current_slide = slide1
        self.assertEqual(self.mc.targets['window'].current_slide, slide1)

        # we need to wait a tick to remove the slide we just added
        self.advance_time()

        # now remove the current slide and make sure slide1 comes back
        self.mc.targets['window'].remove_slide(slide2)
        self.assertEqual(self.mc.targets['window'].current_slide, slide1)

        # add another slide so we have 3
        slide3 = Slide(mc=self.mc, name='slide3', config={})
        self.assertEqual(len(self.mc.targets['window'].slides), 3)

        # also test removing by name
        self.mc.targets['window'].remove_slide('slide1')
        self.assertEqual(self.mc.targets['window'].current_slide, slide3)
Example #3
0
    def add_slide(self, name: str, config: Optional[dict] = None, priority: int = 0,
                  key: Optional[str] = None, play_kwargs: Optional[dict] = None) -> "Slide":
        """Add a slide to this display.

        Add a slide to the list of slides managed by the display (or returns the existing
        slide with the specified name if it already exists).  This method just adds the
        slide.  It does not display it.

        Args:
            name: The slide name.
            config: The slide config.
            priority: The slide priority.
            key: Optional key.
            play_kwargs: Additional play kwargs.

        Returns:
            The Slide object.
        """
        # See if slide already exists.  If so, return it
        if self.has_screen(name):
            return self.get_screen(name)

        # Slide() creates a new slide and adds it to this screen manager (display)
        return Slide(mc=self.mc, name=name, target=self.name,
                     config=config, key=key, priority=priority,
                     play_kwargs=play_kwargs)
Example #4
0
    def test_background_color_and_opacity(self):
        slide = Slide(mc=self.mc,
                      name='slide6',
                      config=self.mc.slides['slide6'])
        self.advance_time()

        self.assertEqual(0.5, slide.canvas.opacity)
Example #5
0
    def test_priority_passed(self):
        slide = Slide(mc=self.mc,
                      name='slide1',
                      config=self.mc.slides['slide1'],
                      key='mode1',
                      priority=123)

        self.assertEqual(slide.priority, 123)
Example #6
0
    def test_key_by_name(self):
        slide = Slide(mc=self.mc,
                      name='slide1',
                      config=self.mc.slides['slide1'],
                      key='mode1',
                      priority=0)

        self.assertEqual(slide.key, 'mode1')
Example #7
0
    def add_slide(self, name, config=None, priority=0, key=None, play_kwargs=None):
        # Note this method just adds it. It doesn't show it.

        try:
            return self.get_screen(name)
        except ScreenManagerException:
            # Slide() created also adds it to this screen manager
            return Slide(mc=self.mc, name=name, target=self.name,
                         config=config, key=key, priority=priority,
                         play_kwargs=play_kwargs)
Example #8
0
    def test_widgets_from_config(self):
        slide = Slide(mc=self.mc,
                      name='slide1',
                      config=self.mc.slides['slide1'],
                      key='mode1',
                      priority=0)

        widget_tree = list()
        for s in slide.children[0].walk():
            widget_tree.append(s)

        # last widget is drawn last (on top), so the order should be flipped
        self.assertEqual(widget_tree[1].text, 'SLIDE TEST 1-3')
        self.assertEqual(widget_tree[2].text, 'SLIDE TEST 1-2')
        self.assertEqual(widget_tree[3].text, 'SLIDE TEST 1-1')
Example #9
0
    def test_widgets_from_config(self):
        slide = Slide(mc=self.mc,
                      name='slide1',
                      config=self.mc.slides['slide1'],
                      key='mode1',
                      priority=0)

        widget_tree = list()
        for s in slide.children:
            widget_tree.append(s.widget)

        # Widgets are drawn in order from the end of the children list to the beginning
        # so the order should be the same order as appears in the config file.
        self.assertEqual(widget_tree[0].text, 'SLIDE TEST 1-1')
        self.assertEqual(widget_tree[1].text, 'SLIDE TEST 1-2')
        self.assertEqual(widget_tree[2].text, 'SLIDE TEST 1-3')
Example #10
0
    def test_widgets_z_order_from_config(self):
        slide = Slide(mc=self.mc,
                      name='slide7',
                      config=self.mc.slides['slide7'],
                      key='mode1',
                      priority=0)

        widget_tree = list()
        for s in slide.children:
            widget_tree.append(s.widget)

        # Widgets are drawn in order from the end of the children list to the beginning.
        # The resulting child widget order should be the from highest z-order value in
        # the beginning of the list to lowest z-order value.  Ties should be broken by
        # the order the widgets appear in the config file.
        self.assertEqual(widget_tree[0].text, 'TEST Z-ORDER 100')
        self.assertEqual(widget_tree[1].text, 'TEST Z-ORDER 50-1')
        self.assertEqual(widget_tree[2].text, 'TEST Z-ORDER 50-2')
        self.assertEqual(widget_tree[3].text, 'TEST Z-ORDER 0')
Example #11
0
    def test_slide(self):
        slide = Slide(mc=self.mc, name='slide1', priority=100)

        self.assertEqual(slide.mc, self.mc)
        self.assertEqual(slide.name, 'slide1')
        self.assertEqual(slide.priority, 100)