Created
December 1, 2015 18:15
-
-
Save clayote/c68d153e1520ecdf655a to your computer and use it in GitHub Desktop.
Trying to use a list comprehension for RecycleView data in kv.
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.lang import Builder | |
from kivy.properties import DictProperty, ListProperty, StringProperty | |
from kivy.uix.boxlayout import BoxLayout | |
class Viewclass(BoxLayout): | |
k = StringProperty() | |
v = StringProperty() | |
class RecycTest(BoxLayout): | |
data = DictProperty() | |
sorted_keys = ListProperty() | |
class RecycTestApp(App): | |
def build(self): | |
return RecycTest( | |
data={'spam': 'delicious', 'eggs': 'undelicious', 'ham': 'sickening'}, | |
sorted_keys=['ham', 'eggs', 'spam'] | |
) | |
Builder.load_string(""" | |
#:import RecycleView recycleview.RecycleView | |
<Viewclass>: | |
orientation: 'horizontal' | |
Label: | |
text: root.k | |
Label: | |
text: root.v | |
<RecycTest>: | |
RecycleView: | |
data: [{'index': i, 'viewclass': 'Viewclass', 'k': root.sorted_keys[i], 'v': root.data[root.sorted_keys[i]]} for i in xrange(len(root.sorted_keys))] | |
""") | |
if __name__ == '__main__': | |
RecycTestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment