Skip to content

Instantly share code, notes, and snippets.

@kived
Created December 30, 2014 19:29
Show Gist options
  • Save kived/26b49b9486bab2333b60 to your computer and use it in GitHub Desktop.
Save kived/26b49b9486bab2333b60 to your computer and use it in GitHub Desktop.
Kivy: StackLayout test case
#import pydevd; pydevd.settrace('localhost', port=51514, suspend=False)
import sys
orientation = 'lr-tb'
if 'vertical' in sys.argv:
sys.argv.remove('vertical')
orientation = 'tb-lr'
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.stacklayout import StackLayout
from kivy.lang import Builder
# Buttons don't display properly when the size is too small, so
# we'll test by rendering rectangles instead
Builder.load_string('''
<-Button>:
canvas.before:
Color:
r: 1 if root.text in ('A', 'B') else 0
g: 1 if root.text in ('B', 'C') else 0
b: 1 if root.text in ('C', 'D') else 0
a: 1
Rectangle:
pos: self.pos
size: self.size
''')
class RootWidget(StackLayout):
def __init__(self, **kw):
super(RootWidget, self).__init__(orientation=orientation, **kw)
self.spacing = 80
self.padding = 80
open_size = .4
#open_size = 1./3.
size_full = (1, open_size) if orientation == 'lr-tb' else (open_size, 1)
size_half = (.5, open_size) if orientation == 'lr-tb' else (open_size, .5)
a = Button(text='A', size_hint=size_full)
b = Button(text='B', size_hint=size_half)
c = Button(text='C', size_hint=size_half)
d = Button(text='D', size_hint=size_full)
self.add_widget(a)
self.add_widget(b)
self.add_widget(c)
self.add_widget(d)
class GameApp(App):
def build(self):
rw = RootWidget()
return rw
if __name__ == '__main__':
GameApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment