Skip to content

Commit

Permalink
fix kv path issue and clean up container example
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Oct 13, 2015
1 parent c3f3fbf commit bf2ffdd
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 70 deletions.
1 change: 0 additions & 1 deletion examples/android/compass/main.py
Expand Up @@ -65,4 +65,3 @@ def on_resume(self):

if __name__ == '__main__':
CompassApp().run()

18 changes: 8 additions & 10 deletions examples/container/kv/1.kv
Expand Up @@ -2,29 +2,27 @@
#:import datetime datetime

RootWidget:

# import container
# import container
container: container

# fill the container
# fill the container
BoxLayout:
id: container
orientation: 'vertical'
padding: 0
spacing: 3
orientation: 'vertical'
padding: 0
spacing: 3

Label:
Label:
text: 'screen-1'


BoxLayout:
orientation: 'horizontal'
padding: 0
spacing: 1
size_hint: 1,0.1
size_hint: 1, 0.1

# weiter button
Button:
size_hint: 0.2,1
size_hint: 0.2, 1
text: 'next'
on_release: app.next_screen('2')
18 changes: 8 additions & 10 deletions examples/container/kv/2.kv
Expand Up @@ -2,29 +2,27 @@
#:import datetime datetime

RootWidget:

# import container
# import container
container: container

# fill the container
# fill the container
BoxLayout:
id: container
orientation: 'vertical'
padding: 0
spacing: 3
orientation: 'vertical'
padding: 0
spacing: 3

Label:
Label:
text: 'screen-2'


BoxLayout:
orientation: 'horizontal'
padding: 0
spacing: 1
size_hint: 1,0.1
size_hint: 1, 0.1

# weiter button
Button:
size_hint: 0.2,1
size_hint: 0.2, 1
text: 'next'
on_release: app.next_screen('3')
18 changes: 8 additions & 10 deletions examples/container/kv/3.kv
Expand Up @@ -2,29 +2,27 @@
#:import datetime datetime

RootWidget:

# import container
# import container
container: container

# fill the container
# fill the container
BoxLayout:
id: container
orientation: 'vertical'
padding: 0
spacing: 3
orientation: 'vertical'
padding: 0
spacing: 3

Label:
Label:
text: 'screen-3'


BoxLayout:
orientation: 'horizontal'
padding: 0
spacing: 1
size_hint: 1,0.1
size_hint: 1, 0.1

# weiter button
Button:
size_hint: 0.2,1
size_hint: 0.2, 1
text: 'next'
on_release: app.next_screen('1')
48 changes: 24 additions & 24 deletions examples/container/kv/root.kv
@@ -1,32 +1,32 @@
#:kivy 1.8.0

RootWidget:
# import container
container: container
# import container
container: container

BoxLayout:
orientation: 'vertical'
padding: 0
spacing: 6
BoxLayout:
orientation: 'vertical'
padding: 0
spacing: 6

# bottom-left part:
BoxLayout:
orientation: 'horizontal'
padding: 0
spacing: 6
# bottom-left part:
BoxLayout:
orientation: 'horizontal'
padding: 0
spacing: 6

# bottom-left
BoxLayout:
size_hint: 0.12, 0.12
orientation: 'vertical'
padding: 0
spacing: 6
# bottom-left
BoxLayout:
size_hint: 0.12, 0.12
orientation: 'vertical'
padding: 0
spacing: 6

# option calibrate
Button:
text: 'Start'
on_release: app.next_screen('1')
# option calibrate
Button:
text: 'Start'
on_release: app.next_screen('1')

# create container (bottom-right)
BoxLayout:
id: container
# create container (bottom-right)
BoxLayout:
id: container
22 changes: 7 additions & 15 deletions examples/container/main.py
Expand Up @@ -28,19 +28,14 @@ class RootWidget(BoxLayout):
class EzsApp(App):

'''This is the app itself'''
# setting the path of our directory
path = os.path.abspath(os.path.dirname("."))
error = False

def build(self):
'''This method loads the root.kv file automatically
:rtype: none
'''
# loading the content of root.kv
self.root = Builder.load_file(os.path.join(self.path, 'kv', 'root.kv'))

return self.root
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
Expand All @@ -53,20 +48,17 @@ def next_screen(self, screen):

filename = screen + '.kv'
# unload the content of the .kv file
# reason: it could have data form previous calls
setattr(self, screen, Builder.unload_file(
os.path.join(self.path, 'kv', filename)))
# load the content of the .kv file
setattr(self, screen, Builder.load_file(
os.path.join(self.path, 'kv', filename)))
# 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(getattr(self, screen))
self.root.container.add_widget(screen)


if __name__ == '__main__':
'''Start the application'''

EZS = EzsApp()
EZS.run()
EzsApp().run()

0 comments on commit bf2ffdd

Please sign in to comment.