Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.lang import Builder
- from kivy.uix.behaviors import ButtonBehavior
- from kivy.uix.boxlayout import BoxLayout
- from kivy.properties import StringProperty
- from textwrap import dedent
- kv = """
- <PostUnit>
- orientation: 'vertical'
- size_hint_y: None
- height: self.minimum_height
- on_release: root.update_posts()
- canvas:
- Color:
- rgb: .8, .8, .8
- RoundedRectangle:
- size: self.size
- pos: self.pos
- BoxLayout:
- size_hint_y: None
- height: dp(40)
- padding: dp(10)
- Label:
- id: writer
- text: f'Writer : {root.writer}'
- color: 'black'
- text_size: self.size # text_size allows the alignment to be set
- halign: 'left'
- valign: 'middle'
- Label:
- id: writedate
- text: f'Write date : {root.date}'
- color: 'black'
- text_size: self.size
- halign: 'left'
- valign: 'middle'
- Label:
- id: content
- text: root.content
- color: 'black'
- size_hint_y: None
- height: self.texture_size[1] # scale widget with text size
- padding: dp(20)
- text_size: self.width, None # use text size to control wrapping
- halign: 'left'
- valign: 'middle'
- BoxLayout:
- orientation: 'vertical'
- Label:
- text: 'Example of ScrollView'
- size_hint_y: None
- height: dp(30)
- ScrollView:
- do_scroll_x: False
- do_scroll_y: True
- BoxLayout:
- id: body
- orientation: 'vertical'
- size_hint_y: None
- spacing: dp(5)
- height: self.minimum_height
- """
- # content from chatGPT, content and posts used for testing...
- c0 = dedent('Software development often requires meticulous attention to detail.'
- 'Every line of code contributes to the overall functionality, '
- 'and even a small bug can lead to significant issues.')
- c1 = dedent('Version control systems, such as Git, play a crucial role in modern software development.'
- 'They allow multiple developers to collaborate on a project simultaneously, '
- 'tracking changes and managing versions effectively. By using branches, developers '
- 'can work on new features or bug fixes in isolation, merging their changes into the '
- 'main codebase only when they are ready. This not only enhances collaboration but also ensures '
- 'that the codebase remains stable and reliable throughout the development lifecycle.')
- c2 = dedent("In addition to coding and testing, documentation is an essential aspect of software development."
- "Well-written documentation provides a clear roadmap for developers, enabling them to understand "
- "the system's architecture, dependencies, and usage. "
- "It also assists new team members in getting up to speed quickly, facilitating smoother onboarding."
- "Comprehensive documentation includes user guides, API references, and troubleshooting manuals, "
- "ensuring that end-users and developers alike can navigate and utilize the software effectively.")
- posts = [{'writer': 'Big Bob',
- 'date': '2020-20-20',
- 'content': c0},
- {'writer': 'Smart Sam',
- 'date': '2020-20-21',
- 'content': c1},
- {'writer': 'Modern Mary',
- 'date': '2020-20-22',
- 'content': c2},
- ] * 3
- class PostUnit(ButtonBehavior, BoxLayout): # use ButtonBehavior to add on_release
- writer = StringProperty() # kivy properties handle kwargs automatically
- date = StringProperty()
- content = StringProperty()
- def update_posts(self):
- print(f'A post from {self.writer} was pressed')
- class ShowScrollApp(App):
- def build(self):
- return Builder.load_string(kv)
- def on_start(self):
- # create some posts
- for post in posts:
- w = PostUnit(**post)
- self.root.ids.body.add_widget(w)
- ShowScrollApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement