/
main.py
64 lines (48 loc) · 1.65 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
'''
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.
'''
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
import os
import kivy
kivy.require('1.8.0')
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.
'''
container = ObjectProperty(None)
class EzsApp(App):
'''This is the app itself'''
def build(self):
'''This method loads the root.kv file automatically
:rtype: none
'''
# loading the content of root.kv
self.root = Builder.load_file('kv/root.kv')
def next_screen(self, screen):
'''Clear container and load the given screen object from file in kv
folder.
:param screen: name of the screen object made from the loaded .kv file
:type screen: str
:rtype: none
'''
filename = screen + '.kv'
# unload the content of the .kv file
# reason: it could have data from previous calls
Builder.unload_file('kv/' + filename)
# clear the container
self.root.container.clear_widgets()
# load the content of the .kv file
screen = Builder.load_file('kv/' + filename)
# add the content of the .kv file to the container
self.root.container.add_widget(screen)
if __name__ == '__main__':
'''Start the application'''
EzsApp().run()