Advertisement
FoxboyPrower

KivyAlmostWorking

Jul 16th, 2019
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.86 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.lang import Builder
  3. from kivy.clock import Clock
  4. from kivy.uix.widget import Widget
  5. from kivy.uix.label import Label
  6. from kivy.uix.boxlayout import BoxLayout
  7. from kivy.properties import StringProperty
  8. from kivy.uix.textinput import TextInput
  9.  
  10. Builder.load_string('''
  11. <StretchingLabel>:
  12.    size_hint_y: None
  13.    text_size: self.width, None
  14.    height: self.texture_size[1]
  15.    group: 'test'
  16.    canvas.before:
  17.        Color:
  18.            rgba: .7, .7, .7, 1
  19.        Rectangle:
  20.            pos: self.pos
  21.            size: self.size
  22.  
  23. <MyLabelFrame>:
  24.    id: xLabel
  25.  
  26. <ContainerBox>:
  27.     orientation: 'horizontal'
  28.    Button:
  29.        text: 'h1'
  30.        group: 'test'
  31.    BoxLayout:
  32.         orientation: 'vertical'
  33.         size: root.size
  34.         pos: root.pos
  35.         Label:
  36.             text: 'Description'
  37.             size_hint_y: None
  38.             height: 30
  39.             bold: True
  40.        MyLabelFrame:
  41.        Label:
  42. ''')
  43.  
  44. class StretchingLabel(Label):
  45.     def __init__(self, **kwargs):
  46.         super(StretchingLabel, self).__init__(**kwargs)
  47.         #This is for debugging
  48.         Clock.schedule_once(lambda dt: print("StretchingLabel.init(): ", self.text), timeout=0.01)
  49.     def on_double_click(self, instance, p_ignoreme):
  50.         #This is also for debugging
  51.         print("StretchingLabel.on_double_click():", self.text)
  52.  
  53. class MyLabelFrame(Widget):
  54.     c_description = StringProperty(
  55.         'Lorem ipsum dolor sit amet, consectetur adipiscing elit. \n\nProin vitae turpis ornare urna elementum pharetra non et tortor. Curabitur semper mattis viverra. \nPellentesque et lobortis purus, eu ultricies est. Nulla varius ac dolor quis mattis. Pellentesque vel accumsan tellus. Donec a nunc urna. Nulla convallis dignissim leo, tempor sagittis orci sollicitudin aliquet. Duis efficitur ex vel auctor ultricies. Etiam feugiat hendrerit mauris suscipit gravida. Quisque lobortis vitae ligula eget tristique. Nullam a nulla id enim finibus elementum eu sit amet elit.')
  56.  
  57.     def __init__(self, **kwargs):
  58.         super(MyLabelFrame, self).__init__(**kwargs)
  59.         Clock.schedule_once(lambda dt: self.makeLabel(), timeout=2)
  60.  
  61.     def makeLabel(self):
  62.         c_label = StretchingLabel()
  63.         #c_label = StretchingLabel(pos=self.pos, width=self.width, text=self.c_description)
  64.         #HERE! This vvv does not seem to work for some reason.
  65.         self.bind(pos=c_label.setter('pos'), width=c_label.setter('width'), c_description=c_label.setter('text'))
  66.         #This vvv didn't work either.
  67.         #c_label.bind(pos=self.setter('pos'), width=self.setter('width'), text=self.setter('c_description'))
  68.         self.add_widget(c_label)
  69.  
  70. class ContainerBox(BoxLayout):
  71.     def __init__(self, **kwargs):
  72.         super(ContainerBox, self).__init__(**kwargs)
  73.  
  74. class Nested2App(App):
  75.     def build(self):
  76.         return ContainerBox()
  77.  
  78. if __name__ == '__main__':
  79.     Nested2App().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement