Created
June 1, 2021 16:04
-
-
Save VICTORVICKIE/34b6904d7c246d5ac283b2b7593c9730 to your computer and use it in GitHub Desktop.
Kivy Advanced RecycleView
This file contains hidden or 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 kivymd.app import MDApp | |
from kivy.lang import Builder | |
from kivy.uix.recycleview import RecycleView | |
from kivy.properties import StringProperty | |
from kivy.uix.boxlayout import BoxLayout | |
from kivymd.theming import ThemableBehavior | |
from kivymd.uix.behaviors import RectangularRippleBehavior | |
from kivy.uix.behaviors import ButtonBehavior | |
from kivy.uix.floatlayout import FloatLayout | |
from kivymd.uix.screen import MDScreen | |
Builder.load_string(''' | |
<Label>: | |
color: 0, 0, 0, 1 | |
<SearchResults>: | |
AnchorLayout: | |
anchor_x : "right" | |
BoxLayout: | |
Label: | |
id: area_lbl | |
color: 0, 0, 0, 0.75 | |
text: root.area | |
size_hint_x: None | |
width: 1.5 * self.texture_size[0] | |
MDIcon: | |
id: chevron_icon | |
theme_text_color: "Custom" | |
text_color: 0, 0, 0, 0.5 | |
icon: "chevron-right" | |
size_hint_x: None | |
width: self.texture_size[0] | |
Label: | |
id: shop_lbl | |
text: root.shop | |
size_hint_x: None | |
width: 1.5 * self.texture_size[0] | |
Label: | |
size_hint_x: None | |
width: 1.5 * self.texture_size[0] | |
text: "\u20B9" + " " + root.balance | |
<SearchRV>: | |
key_viewclass: "viewclass" | |
key_size: "height" | |
RecycleBoxLayout: | |
padding: "10dp" | |
default_size: None, dp(58) | |
default_size_hint: 1, None | |
size_hint_y: None | |
height: self.minimum_height | |
orientation: "vertical" | |
''') | |
class SearchResults(ThemableBehavior, RectangularRippleBehavior, ButtonBehavior, BoxLayout): | |
area = StringProperty() | |
shop = StringProperty() | |
balance = StringProperty() | |
class SearchRV(RecycleView): | |
def __init__(self,**kwargs): | |
super().__init__(**kwargs) | |
self.data = [] | |
for num in range(1,101): | |
self.add_data(num) | |
def add_data(self, num): | |
self.data.append({ | |
"viewclass": "SearchResults", | |
"area": f"area {num}", | |
"shop": f"shop {num}", | |
"balance": str(num) | |
}) | |
class TestApp(MDApp): | |
def build(self): | |
screen = MDScreen(name="RV") | |
rv = SearchRV() | |
screen.add_widget(rv) | |
return screen | |
if __name__ == '__main__': | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment