Skip to content

Instantly share code, notes, and snippets.

@el3
Last active April 5, 2023 11:06
Show Gist options
  • Save el3/1a2ae71c947adaf455d42a254152663f to your computer and use it in GitHub Desktop.
Save el3/1a2ae71c947adaf455d42a254152663f to your computer and use it in GitHub Desktop.
Long text split by "\n" and put into labels, with line numbers, in recycleview
from kivy.app import App
from kivy.properties import ListProperty
from kivy.lang import Builder
long_text = 'This is an example to output a very long file as labels in a recycleboxlayout with line numbers and proper line breakings\n' * 1000 + " END"
KV = '''
<MyLabel@Label>:
halign: "left"
text_size: self.width, None
height: self.texture_size[1]+8
# plus 8 to ad some spacing between the next line
markup: True
RecycleView:
viewclass: 'MyLabel'
data: app.data
RecycleBoxLayout:
id: layout
default_size: None, None
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
'''
class ScrollApp(App):
data = ListProperty([{"text": "[color=3333ff]{}.[/color] {}".format(number,line)} for number,line in list(enumerate(long_text.split("\n")))])
def build(self):
return Builder.load_string(KV)
if __name__ == "__main__":
ScrollApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment