[MouseFox logo]
The MouseFox Project
Join The Community Discord Server
[Discord logo]
Edit on GitHub

kvex.widgets.screen

Home of ScreenManager and XScreen.

 1"""Home of `ScreenManager` and `XScreen`."""
 2
 3from typing import Literal
 4from .. import kivy as kv
 5from .widget import XWidget
 6
 7
 8class XScreen(XWidget, kv.Screen):
 9    """Screen."""
10
11
12class XScreenManager(XWidget, kv.ScreenManager):
13    """ScreenManager with custom transition behavior."""
14
15    def add_screen(self, name: str, widget: kv.Widget) -> XScreen:
16        """Create and add a screen from a widget."""
17        screen = XScreen(name=name)
18        screen.add_widget(widget)
19        self.add_widget(screen)
20        return screen
21
22    def screen_direction(self, name: str, /) -> Literal["left", "right"]:
23        """Compare index of a screen by name to the current screen.
24
25        Useful for setting transition direction:
26        ```python3
27        sm = XScreenManager()
28        sm.transition.direction = sm.screen_direction("screen_name")
29        sm.current = "screen_name"
30        ```
31        """
32        old_index = self.screen_names.index(self.current)
33        new_index = self.screen_names.index(name)
34        return "left" if old_index < new_index else "right"
35
36    @property
37    def mid_transition(self) -> bool:
38        """If there is a transition in progress."""
39        return 0 < self.current_screen.transition_progress < 1
40
41    @classmethod
42    def from_widgets(cls, widgets: dict[str, XWidget], **kwargs) -> "XScreenManager":
43        """Create an XScreenManager from a dictionary of screen names and widgets."""
44        sm = cls(**kwargs)
45        for n, w in widgets.items():
46            screen = XScreen(name=n)
47            screen.add_widget(w)
48            sm.add_widget(screen)
49        return sm
50
51
52__all__ = (
53    "XScreenManager",
54    "XScreen",
55)
class XScreenManager(kvex.widgets.widget.XWidget, kivy.uix.screenmanager.ScreenManager):
13class XScreenManager(XWidget, kv.ScreenManager):
14    """ScreenManager with custom transition behavior."""
15
16    def add_screen(self, name: str, widget: kv.Widget) -> XScreen:
17        """Create and add a screen from a widget."""
18        screen = XScreen(name=name)
19        screen.add_widget(widget)
20        self.add_widget(screen)
21        return screen
22
23    def screen_direction(self, name: str, /) -> Literal["left", "right"]:
24        """Compare index of a screen by name to the current screen.
25
26        Useful for setting transition direction:
27        ```python3
28        sm = XScreenManager()
29        sm.transition.direction = sm.screen_direction("screen_name")
30        sm.current = "screen_name"
31        ```
32        """
33        old_index = self.screen_names.index(self.current)
34        new_index = self.screen_names.index(name)
35        return "left" if old_index < new_index else "right"
36
37    @property
38    def mid_transition(self) -> bool:
39        """If there is a transition in progress."""
40        return 0 < self.current_screen.transition_progress < 1
41
42    @classmethod
43    def from_widgets(cls, widgets: dict[str, XWidget], **kwargs) -> "XScreenManager":
44        """Create an XScreenManager from a dictionary of screen names and widgets."""
45        sm = cls(**kwargs)
46        for n, w in widgets.items():
47            screen = XScreen(name=n)
48            screen.add_widget(w)
49            sm.add_widget(screen)
50        return sm

ScreenManager with custom transition behavior.

def add_screen( self, name: str, widget: kivy.uix.widget.Widget) -> kvex.widgets.screen.XScreen:
16    def add_screen(self, name: str, widget: kv.Widget) -> XScreen:
17        """Create and add a screen from a widget."""
18        screen = XScreen(name=name)
19        screen.add_widget(widget)
20        self.add_widget(screen)
21        return screen

Create and add a screen from a widget.

def screen_direction(self, name: str, /) -> Literal['left', 'right']:
23    def screen_direction(self, name: str, /) -> Literal["left", "right"]:
24        """Compare index of a screen by name to the current screen.
25
26        Useful for setting transition direction:
27        ```python3
28        sm = XScreenManager()
29        sm.transition.direction = sm.screen_direction("screen_name")
30        sm.current = "screen_name"
31        ```
32        """
33        old_index = self.screen_names.index(self.current)
34        new_index = self.screen_names.index(name)
35        return "left" if old_index < new_index else "right"

Compare index of a screen by name to the current screen.

Useful for setting transition direction:

sm = XScreenManager()
sm.transition.direction = sm.screen_direction("screen_name")
sm.current = "screen_name"
mid_transition: bool

If there is a transition in progress.

@classmethod
def from_widgets( cls, widgets: dict[str, kvex.widgets.widget.XWidget], **kwargs) -> kvex.widgets.screen.XScreenManager:
42    @classmethod
43    def from_widgets(cls, widgets: dict[str, XWidget], **kwargs) -> "XScreenManager":
44        """Create an XScreenManager from a dictionary of screen names and widgets."""
45        sm = cls(**kwargs)
46        for n, w in widgets.items():
47            screen = XScreen(name=n)
48            screen.add_widget(w)
49            sm.add_widget(screen)
50        return sm

Create an XScreenManager from a dictionary of screen names and widgets.

Inherited Members
kivy.uix.screenmanager.ScreenManager
ScreenManager
current
transition
screens
current_screen
screen_names
add_widget
remove_widget
clear_widgets
real_add_widget
real_remove_widget
on_current
get_screen
has_screen
next
previous
switch_to
on_motion
on_touch_down
on_touch_move
on_touch_up
kivy.uix.floatlayout.FloatLayout
do_layout
kivy.uix.layout.Layout
layout_hint_with_bounds
kivy.uix.widget.Widget
proxy_ref
apply_class_lang_rules
collide_point
collide_widget
on_kv_post
register_for_motion_event
unregister_for_motion_event
export_to_png
export_as_image
get_root_window
get_parent_window
walk
walk_reverse
to_widget
to_window
to_parent
to_local
get_window_matrix
x
y
width
height
pos
size
get_right
set_right
right
get_top
set_top
top
get_center_x
set_center_x
center_x
get_center_y
set_center_y
center_y
center
cls
children
parent
size_hint_x
size_hint_y
size_hint
pos_hint
size_hint_min_x
size_hint_min_y
size_hint_min
size_hint_max_x
size_hint_max_y
size_hint_max
ids
opacity
on_opacity
canvas
get_disabled
set_disabled
inc_disabled
dec_disabled
disabled
motion_filter
kivy._event.EventDispatcher
register_event_type
unregister_event_types
unregister_event_type
is_event_type
bind
unbind
fbind
funbind
unbind_uid
get_property_observers
events
dispatch
dispatch_generic
dispatch_children
setter
getter
property
properties
create_property
apply_property
class XScreen(kvex.widgets.widget.XWidget, kivy.uix.screenmanager.Screen):
 9class XScreen(XWidget, kv.Screen):
10    """Screen."""

Screen.

Inherited Members
kivy.uix.relativelayout.RelativeLayout
RelativeLayout
do_layout
to_parent
to_local
on_motion
on_touch_down
on_touch_move
on_touch_up
kivy.uix.screenmanager.Screen
name
manager
transition_progress
transition_state
on_pre_enter
on_enter
on_pre_leave
on_leave
kivy.uix.floatlayout.FloatLayout
add_widget
remove_widget
kivy.uix.layout.Layout
layout_hint_with_bounds
kivy.uix.widget.Widget
proxy_ref
apply_class_lang_rules
collide_point
collide_widget
on_kv_post
clear_widgets
register_for_motion_event
unregister_for_motion_event
export_to_png
export_as_image
get_root_window
get_parent_window
walk
walk_reverse
to_widget
to_window
get_window_matrix
x
y
width
height
pos
size
get_right
set_right
right
get_top
set_top
top
get_center_x
set_center_x
center_x
get_center_y
set_center_y
center_y
center
cls
children
parent
size_hint_x
size_hint_y
size_hint
pos_hint
size_hint_min_x
size_hint_min_y
size_hint_min
size_hint_max_x
size_hint_max_y
size_hint_max
ids
opacity
on_opacity
canvas
get_disabled
set_disabled
inc_disabled
dec_disabled
disabled
motion_filter
kivy._event.EventDispatcher
register_event_type
unregister_event_types
unregister_event_type
is_event_type
bind
unbind
fbind
funbind
unbind_uid
get_property_observers
events
dispatch
dispatch_generic
dispatch_children
setter
getter
property
properties
create_property
apply_property