Last active
March 5, 2020 14:31
-
-
Save el3/63d7078cfc1002ca352e8173b0837ea7 to your computer and use it in GitHub Desktop.
Example on how to show a very long text in label in a recycleview. With colored line numbers.
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.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