Skip to content
Snippets Groups Projects
Commit f18f6b6d authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Used model properties to control the ScreenManager, moving presentation logic to the Kv.

parent a7a347f9
Branches
No related tags found
No related merge requests found
from kivy.app import App from kivy.app import App
from kivy.properties import BooleanProperty, StringProperty
# The following lines ensure that FirstScreen and SecondScreen are available for when the Kv code is loaded. # The following lines ensure that FirstScreen and SecondScreen are available for when the Kv code is loaded.
...@@ -12,13 +13,19 @@ from second_screen import SecondScreen # pylint: disable=unused-import ...@@ -12,13 +13,19 @@ from second_screen import SecondScreen # pylint: disable=unused-import
class TwoScreenApp(App): class TwoScreenApp(App):
advancing = BooleanProperty(True)
current_screen_name = StringProperty() # We must wait to select a screen until the app starts.
def open_first_screen(self): def open_first_screen(self):
self.root.transition.direction = 'right' self.advancing = True
self.root.current = 'first' self.current_screen_name = 'first'
def open_second_screen(self): def open_second_screen(self):
self.root.transition.direction = 'left' self.advancing = False
self.root.current = 'second' self.current_screen_name = 'second'
def on_start(self):
self.open_first_screen() # Once the app starts, we can select the starting screen.
if __name__ == '__main__': if __name__ == '__main__':
......
# We import the type of transition we want so that we can use it in the `transition` property below.
# Imports have three parts: #:import, the name we want to use in our code, and the fully qualified name.
#:import SlideTransition kivy.uix.screenmanager.SlideTransition
ScreenManager: ScreenManager:
transition: SlideTransition(direction='right' if app.advancing else 'left')
current: app.current_screen_name
FirstScreen: FirstScreen:
id: first
name: 'first' name: 'first'
SecondScreen: SecondScreen:
id: second
name: 'second' name: 'second'
message: 'This is a message!' # The app sends information to the custom widgets by setting their properties. message: 'This is a message!' # The app sends information to the custom widgets by setting their properties.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment