Skip to content

Screen Manager

morphui.uix.screenmanager

MorphScreen(*widgets, **kwargs)

Bases: MorphDeclarativeBehavior, MorphColorThemeBehavior, MorphSurfaceLayerBehavior, MorphAutoSizingBehavior, Screen

A Screen that supports declarative child widgets via :class:~morphui.uix.behaviors.MorphDeclarativeBehavior.

This class combines the functionality of Kivy's Screen with several MorphUI behaviors to enhance its capabilities: - MorphDeclarativeBehavior: Enables declarative property binding. - MorphColorThemeBehavior: Integrates color theming capabilities. - MorphSurfaceLayerBehavior: Provides surface styling options.

Examples:

from morphui.app import MorphApp
from morphui.uix.label import MorphLabel
from morphui.uix.screenmanager import MorphScreen
from morphui.uix.screenmanager import MorphScreenManager

class MyApp(MorphApp):
    def build(self) -> MorphScreenManager:
        self.theme_manager.seed_color = 'Purple'
        sm = MorphScreenManager()
        sm.add_widget(MorphScreen(
            MorphLabel(
                text="Label 1",
                theme_style='primary'),
            name='screen1',
            theme_style='surface',))
        sm.add_widget(MorphScreen(
            MorphLabel(
                text="Label 2",
                theme_style='secondary',
                auto_size=True,),
            name='screen2',
            theme_style='surface',))
        return sm
MyApp().run()
Notes
  • The identity property of the screen can be set via the name keyword argument during instantiation for convenience and vice versa.
  • The minimum_height and minimum_width properties provide read-only access to the minimum dimensions required by the screen based on its child widgets.

minimum_height = AliasProperty(_get_minimum_height, None, bind=['children'], cache=True) class-attribute instance-attribute

The minimum height required by the screen based on its child widgets (read-only).

This property is automatically updated whenever the screen's children change.

:attr:minimum_height is an :class:~kivy.properties.AliasProperty that is read-only and bound to the screen's children.

minimum_width = AliasProperty(_get_minimum_width, None, bind=['children'], cache=True) class-attribute instance-attribute

The minimum width required by the screen based on its child widgets (read-only).

This property is automatically updated whenever the screen's children change.

:attr:minimum_width is an :class:~kivy.properties.AliasProperty that is read-only and bound to the screen's children.

MorphScreenManager(*widgets, **kwargs)

Bases: MorphDeclarativeBehavior, ScreenManager

A ScreenManager that supports declarative child widgets via :class:~morphui.uix.behaviors.MorphDeclarativeBehavior.

This class extends Kivy's ScreenManager by incorporating the MorphDeclarativeBehavior, allowing for declarative property binding for its child screens.

Examples:

from morphui.app import MorphApp
from morphui.uix.button import MorphButton
from morphui.uix.boxlayout import MorphBoxLayout
from morphui.uix.screenmanager import MorphScreen
from morphui.uix.screenmanager import MorphScreenManager

class MyApp(MorphApp):
    def build(self) -> MorphBoxLayout:
        self.theme_manager.seed_color = 'morphui_teal'

        self.main_layout = MorphBoxLayout(
            MorphScreenManager(
                MorphScreen(
                    MorphButton(
                        text="Go to Screen 2",
                        on_release=lambda x: self.change_screen('screen2'),),
                    name='screen1',),
                MorphScreen(
                    MorphButton(
                        text="Go to Screen 1",
                        on_release=lambda x: self.change_screen('screen1'),),
                    name='screen2',),
                identity='screen_manager',),
            identity='main_layout',
            orientation='vertical',)
        return self.main_layout

    def change_screen(self, name: str) -> None:
        sm = self.main_layout.identities.screen_manager
        sm.current = name

if __name__ == '__main__':
    MyApp().run()

minimum_width = AliasProperty(_get_minimum_width, None, bind=['current_screen'], cache=True) class-attribute instance-attribute

The minimum width required by the screen manager based on its current screen (read-only).

This property is automatically updated whenever the current screen changes. The minimum width is derived from the minimum_width property of the active screen.

:attr:minimum_width is an :class:~kivy.properties.AliasProperty that is read-only and bound to the current screen's minimum width.

minimum_height = AliasProperty(_get_minimum_height, None, bind=['current_screen'], cache=True) class-attribute instance-attribute

The minimum height required by the screen manager based on its current screen (read-only).

This property is automatically updated whenever the current screen changes. The minimum height is derived from the minimum_height property of the active screen.

:attr:minimum_height is an :class:~kivy.properties.AliasProperty that is read-only and bound to the current screen's minimum height.