2015-03-06 10:06:15 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2015-03-10 10:39:51 +00:00
|
|
|
'''
|
|
|
|
Container Example
|
|
|
|
==============
|
|
|
|
|
|
|
|
This example shows how to add a container to our screen.
|
|
|
|
A container is simply an empty place on the screen which
|
|
|
|
could be filled with any other content from a .kv file.
|
|
|
|
'''
|
2015-03-06 10:06:15 +00:00
|
|
|
from kivy.app import App
|
|
|
|
from kivy.lang import Builder
|
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
2015-03-09 09:16:37 +00:00
|
|
|
from kivy.properties import ObjectProperty
|
2015-03-06 10:06:15 +00:00
|
|
|
|
2015-03-10 10:39:51 +00:00
|
|
|
import kivy
|
|
|
|
kivy.require('1.8.0')
|
2015-03-06 10:06:15 +00:00
|
|
|
|
|
|
|
|
2015-03-10 10:39:51 +00:00
|
|
|
class RootWidget(BoxLayout):
|
|
|
|
'''Create a controller that receives a custom widget from the kv lang file.
|
|
|
|
Add an action to be called from a kv file.
|
|
|
|
'''
|
2015-03-06 10:06:15 +00:00
|
|
|
|
|
|
|
container = ObjectProperty(None)
|
|
|
|
|
|
|
|
|
|
|
|
class EzsApp(App):
|
|
|
|
|
|
|
|
'''This is the app itself'''
|
|
|
|
|
|
|
|
def build(self):
|
|
|
|
'''This method loads the root.kv file automatically
|
|
|
|
|
|
|
|
:rtype: none
|
|
|
|
'''
|
2015-03-10 10:39:51 +00:00
|
|
|
# loading the content of root.kv
|
2015-10-13 20:43:07 +00:00
|
|
|
self.root = Builder.load_file('kv/root.kv')
|
2015-03-06 10:06:15 +00:00
|
|
|
|
|
|
|
def next_screen(self, screen):
|
2015-03-21 15:58:01 +00:00
|
|
|
'''Clear container and load the given screen object from file in kv
|
|
|
|
folder.
|
2015-03-06 10:06:15 +00:00
|
|
|
|
|
|
|
:param screen: name of the screen object made from the loaded .kv file
|
|
|
|
:type screen: str
|
|
|
|
:rtype: none
|
|
|
|
'''
|
|
|
|
|
|
|
|
filename = screen + '.kv'
|
2015-03-10 10:39:51 +00:00
|
|
|
# unload the content of the .kv file
|
2015-10-13 20:43:07 +00:00
|
|
|
# reason: it could have data from previous calls
|
|
|
|
Builder.unload_file('kv/' + filename)
|
2015-03-10 10:39:51 +00:00
|
|
|
# clear the container
|
2015-03-06 10:06:15 +00:00
|
|
|
self.root.container.clear_widgets()
|
2015-10-13 20:43:07 +00:00
|
|
|
# load the content of the .kv file
|
|
|
|
screen = Builder.load_file('kv/' + filename)
|
2015-03-10 10:39:51 +00:00
|
|
|
# add the content of the .kv file to the container
|
2015-10-13 20:43:07 +00:00
|
|
|
self.root.container.add_widget(screen)
|
2015-03-06 10:06:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
'''Start the application'''
|
|
|
|
|
2015-10-13 20:43:07 +00:00
|
|
|
EzsApp().run()
|