From f88be241f3755120e22ba14bd0d9e52f8825aa08 Mon Sep 17 00:00:00 2001 From: Brady James Garvin <bgarvin@cse.unl.edu> Date: Fri, 22 Mar 2019 10:41:44 -0500 Subject: [PATCH] Added explanatory comments. --- first_screen.kv | 4 ++-- first_screen.py | 2 +- main.py | 5 +++++ second_screen.kv | 4 ++-- second_screen.py | 4 ++-- twoscreen.kv | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/first_screen.kv b/first_screen.kv index 3c17584..08e2856 100644 --- a/first_screen.kv +++ b/first_screen.kv @@ -5,7 +5,7 @@ text: 'This is the first screen.' Button: text: 'This button prints a number.' - on_press: root.print_number() + on_press: root.print_number() # In a custom widget's Kv, `root` refers to the custom widget. Button: text: 'Change…' - on_press: app.open_second_screen() + on_press: app.open_second_screen() # But `app` still refers to the application object. diff --git a/first_screen.py b/first_screen.py index 4178e4a..8037d7b 100644 --- a/first_screen.py +++ b/first_screen.py @@ -3,7 +3,7 @@ from kivy.uix.screenmanager import Screen from kivy.properties import NumericProperty -Builder.load_file('first_screen.kv') +Builder.load_file('first_screen.kv') # Because this is not the main app Kv, we must load it explicitly. class FirstScreen(Screen): diff --git a/main.py b/main.py index 58f773d..b7ebfae 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,10 @@ from kivy.app import App +# The following lines ensure that FirstScreen and SecondScreen are available for when the Kv code is loaded. + +# Because neither PyCharm nor PyLint are aware of the associated Kv, we must disable their warnings about these widgets +# not being used. + # noinspection PyUnresolvedReferences from first_screen import FirstScreen # pylint: disable=unused-import # noinspection PyUnresolvedReferences diff --git a/second_screen.kv b/second_screen.kv index 00d033c..7fcb6f5 100644 --- a/second_screen.kv +++ b/second_screen.kv @@ -4,7 +4,7 @@ Label: text: 'This is the second screen.' Label: - text: root.message + text: root.message # In a custom widget's Kv, `root` refers to the custom widget. Button: text: 'Change…' - on_press: app.open_first_screen() + on_press: app.open_first_screen() # But `app` still refers to the application object. diff --git a/second_screen.py b/second_screen.py index aa3db0b..a516903 100644 --- a/second_screen.py +++ b/second_screen.py @@ -3,8 +3,8 @@ from kivy.uix.screenmanager import Screen from kivy.properties import StringProperty -Builder.load_file('second_screen.kv') +Builder.load_file('second_screen.kv') # Because this is not the main app Kv, we must load it explicitly. class SecondScreen(Screen): - message = StringProperty('Hello, World!') + message = StringProperty('Hello, World!') # This property is changed by twoscreen.kv. diff --git a/twoscreen.kv b/twoscreen.kv index 2b4c965..ca47926 100644 --- a/twoscreen.kv +++ b/twoscreen.kv @@ -5,4 +5,4 @@ ScreenManager: SecondScreen: id: second name: 'second' - message: 'This is a message!' + message: 'This is a message!' # The app sends information to the custom widgets by setting their properties. -- GitLab