Created
August 14, 2015 17:50
-
-
Save Alan-FGR/c8e14994e7465398d5ed to your computer and use it in GitHub Desktop.
workaround for kivy gridlayout problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.uix.gridlayout import GridLayout | |
from kivy.uix.label import Label | |
from kivy.uix.image import Image | |
from kivy.app import Builder, App | |
from random import randint | |
from kivy.uix.stacklayout import StackLayout | |
from pygments.formatters import img | |
Builder.load_string(""" | |
<GridLayout>: | |
canvas: | |
Color: | |
rgba: 1,0,0,1 | |
Line: | |
rectangle: self.x+1,self.y+1,self.width-1,self.height-1 | |
<Image>: | |
canvas: | |
Color: | |
rgba: (0,1,0,0.3) | |
Rectangle: | |
pos: self.pos | |
size: self.size | |
<Label>: | |
size_hint: None,None | |
text_size: self.width, None | |
height: self.texture_size[1] | |
""") | |
class ACListEntry(StackLayout): | |
def __init__(self, **kwargs): | |
super(ACListEntry, self).__init__(size_hint_y=None, **kwargs) | |
self.bind(minimum_height = self.setter("height")) | |
img = Image(size_hint = (None,None), size = (60,60), source = "") | |
self.add_widget(img) | |
lbl = Label(text="TEST layout problem fds af dfsad fsd asdfs adfsad fdsf "*randint(1,6)) | |
self.add_widget(lbl) | |
#crappy workaround below | |
self.img = img | |
self.lbl = lbl | |
self.bind(width = self.workaround) | |
def workaround(self,_,w): | |
self.lbl.width = self.width-self.img.width | |
#end of crappy workaround | |
class MyApp(App): | |
def build(self): | |
mainlayout = GridLayout(cols=1) | |
for _ in xrange(5): | |
mainlayout.add_widget(ACListEntry()) | |
return mainlayout | |
MyApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment