Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Separate Screens
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ryan Thomas
Separate Screens
Commits
f18f6b6d
Commit
f18f6b6d
authored
3 years ago
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Used model properties to control the ScreenManager, moving presentation logic to the Kv.
parent
a7a347f9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+11
-4
11 additions, 4 deletions
main.py
twoscreen.kv
+7
-2
7 additions, 2 deletions
twoscreen.kv
with
18 additions
and
6 deletions
main.py
+
11
−
4
View file @
f18f6b6d
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__
'
:
...
...
This diff is collapsed.
Click to expand it.
twoscreen.kv
+
7
−
2
View file @
f18f6b6d
# 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.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment