Python kivy.uix.screenmanager.Screen() Examples

The following are 9 code examples of kivy.uix.screenmanager.Screen(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module kivy.uix.screenmanager , or try the search function .
Example #1
Source File: __init__.py    From kivystudio with MIT License 6 votes vote down vote up
def add_widget(self, widget, title=''):
        if len(self.children) > 1:
            tab = TerminalTab()
            tab.text=title
            tab.name=title
            tab.bind(state=self.tab_state)
            self.tab_container.add_widget(tab)
            Clock.schedule_once(lambda dt: setattr(tab, 'state', 'down'))
            screen = Screen(name=title)
            screen.add_widget(widget)
            self.manager.add_widget(screen)
        else:
            super(TerminalSpace, self).add_widget(widget) 
Example #2
Source File: test_core.py    From pypercard with MIT License 6 votes vote down vote up
def test_card_screen_with_background_colour():
    """
    If a background colour is set for the card, ensure this is correctly
    configured for the layout associated with the card's screen.
    """
    mock_screen_manager = mock.MagicMock()
    data_store = {"foo": "bar"}
    card = Card("title", background="red")
    mock_layout = mock.MagicMock()
    with mock.patch(
        "pypercard.core.BoxLayout", return_value=mock_layout
    ), mock.patch("pypercard.core.Screen"), mock.patch(
        "pypercard.core.Color"
    ) as mock_colour, mock.patch(
        "pypercard.core.Rectangle"
    ) as mock_rectangle:
        card.screen(mock_screen_manager, data_store)
        mock_layout.bind.assert_called_once_with(
            size=card._update_rect, pos=card._update_rect
        )
        mock_colour.assert_called_once_with(1.0, 0.0, 0.0, 1.0)  # "red"
        mock_rectangle.assert_called_once_with(
            size=mock_layout.size, pos=mock_layout.pos
        )
        assert card.rect == mock_rectangle() 
Example #3
Source File: test_core.py    From pypercard with MIT License 6 votes vote down vote up
def test_card_screen_with_background_image():
    """
    If a background image is set for the card, ensure this is correctly
    configured for the layout associated with the card's screen.
    """
    mock_screen_manager = mock.MagicMock()
    data_store = {"foo": "bar"}
    card = Card("title", background="image.png")
    mock_layout = mock.MagicMock()
    with mock.patch(
        "pypercard.core.BoxLayout", return_value=mock_layout
    ), mock.patch("pypercard.core.Screen"), mock.patch(
        "pypercard.core.Rectangle"
    ) as mock_rectangle:
        card.screen(mock_screen_manager, data_store)
        mock_rectangle.assert_called_once_with(
            source="image.png", size=mock_layout.size, pos=mock_layout.pos
        ) 
Example #4
Source File: __init__.py    From kivystudio with MIT License 5 votes vote down vote up
def add_widget(self, widget):
        screen = Screen()
        screen.add_widget(widget)
        super(EmulatorScreens, self).add_widget(screen) 
Example #5
Source File: filechooser.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def add_widget(self, widget, **kwargs):
        if widget is self._progress:
            super(FileChooser, self).add_widget(widget, **kwargs)
        elif hasattr(widget, 'VIEWNAME'):
            name = widget.VIEWNAME + 'view'
            screen = Screen(name=name)
            widget.controller = self
            screen.add_widget(widget)
            self.manager.add_widget(screen)

            self.trigger_update_view()
        else:
            raise ValueError(
                'widget must be a FileChooserLayout,'
                ' not %s' % type(widget).__name__) 
Example #6
Source File: filechooser.py    From Tickeys-linux with MIT License 5 votes vote down vote up
def add_widget(self, widget, **kwargs):
        if widget is self._progress:
            super(FileChooser, self).add_widget(widget, **kwargs)
        elif hasattr(widget, 'VIEWNAME'):
            name = widget.VIEWNAME + 'view'
            screen = Screen(name=name)
            widget.controller = self
            screen.add_widget(widget)
            self.manager.add_widget(screen)

            self.trigger_update_view()
        else:
            raise ValueError(
                'widget must be a FileChooserLayout,'
                ' not %s' % type(widget).__name__) 
Example #7
Source File: widget_mgr.py    From deepdiy with MIT License 5 votes vote down vote up
def add_widget_to_window(self,ins,type,id):
		if id=='resource_tree':
			self.ids.resource_tree.add_widget(ins)
		elif type=='processing':
			screen=Screen(name=id)
			screen.add_widget(ins)
			self.ids.processing_screens.add_widget(screen)
			self.add_munu_button(id)
		elif type=='display':
			screen=Screen(name=id)
			screen.add_widget(ins)
			self.ids.display_screens.add_widget(screen) 
Example #8
Source File: test_core.py    From pypercard with MIT License 5 votes vote down vote up
def test_card_screen_empty():
    """
    Ensure a relatively empty card results in the expected Screen object and
    the passed in ScreenManager instance and data_store is set for the card.
    """
    mock_screen_manager = mock.MagicMock()
    data_store = {"foo": "bar"}
    card = Card("title")
    result = card.screen(mock_screen_manager, data_store)
    assert card.screen_manager == mock_screen_manager
    assert card.data_store == data_store
    assert isinstance(result, Screen) 
Example #9
Source File: core.py    From pypercard with MIT License 4 votes vote down vote up
def screen(self, screen_manager, data_store):
        """
        Return a screen instance containing all the necessary UI items that
        have been associated with the expected event handlers.

        :param kivy.uix.screenmanager.ScreenManager screen_manager: The UI
            stack of screens which controls which card is to be displayed.
        :param dict data_store: A dictionary containing application state.
        :return: A graphical representation of the card.
        """
        # References to app related objects.
        self.screen_manager = screen_manager
        self.data_store = data_store
        # The Kivy Screen instance used to draw the UI.
        screen = Screen(name=self.title)
        # Bind event handlers to life-cycle events.
        screen.bind(on_enter=self._enter)
        screen.bind(on_pre_enter=self._pre_enter)
        screen.bind(on_pre_leave=self._leave)
        # The main layout that defines how UI elements are drawn.
        self.layout = BoxLayout(orientation="vertical")
        screen.add_widget(self.layout)
        # The sound player for this card.
        self.player = None
        # Text font size for the Screen instance.
        self.font_size = "{}sp".format(self.text_size)
        if self.form:
            self._draw_form()
        elif self.text:
            self._draw_text()
        else:
            # For padding purposes.
            self.layout.add_widget(Label(text=" "))
        if self.sound:
            self.player = SoundLoader.load(self.sound)
            self.player.loop = self.sound_repeat
        if self.background:
            self.layout.bind(size=self._update_rect, pos=self._update_rect)
            with self.layout.canvas.before:
                if isinstance(self.background, tuple):
                    Color(*self.background)
                    self.rect = Rectangle(
                        size=self.layout.size, pos=self.layout.pos
                    )
                else:
                    self.rect = Rectangle(
                        source=self.background,
                        size=self.layout.size,
                        pos=self.layout.pos,
                    )
        if self.buttons:
            self._draw_buttons()
        return screen