Skip to content

Instantly share code, notes, and snippets.

@tito
Created March 26, 2016 16:27
Show Gist options
  • Save tito/41e65329bc1dd8b62d75 to your computer and use it in GitHub Desktop.
Save tito/41e65329bc1dd8b62d75 to your computer and use it in GitHub Desktop.
# coding=utf-8
from kivy.properties import ListProperty
from kivy.lang import Builder
from kivy.app import App
from random import randint
RV = """
#:import RecycleView kivy.garden.recycleview.RecycleView
GridLayout:
cols: 1
BoxLayout:
size_hint_y: None
height: "48dp"
Button:
text: "Data 1"
on_release: app.push_data_1()
Button:
text: "Data 2"
on_release: app.push_data_2()
RecycleView:
key_viewclass: "viewclass"
default_size: "24sp"
data: app.data
<Data1Item@GridLayout>:
rows: 1
row: [0] * 10
Label:
text: str(root.row[0])
Label:
text: str(root.row[1])
Label:
text: str(root.row[2])
Label:
text: str(root.row[3])
Label:
text: str(root.row[4])
Label:
text: str(root.row[5])
<Data2Item@GridLayout>:
rows: 1
row: [0, 0, 0]
Label:
text: str(root.row[0])
Label:
text: str(root.row[1])
Label:
text: str(root.row[2])
"""
class TestApp(App):
data = ListProperty()
def build(self):
return Builder.load_string(RV)
def push_data_1(self):
indices = range(5)
freqs = [randint(0., 50.) for x in indices]
powers = [randint(0., 50.) for x in indices]
ch_powers = [randint(0., 50.) for x in indices]
ch_noises = [randint(0., 50.) for x in indices]
osnr = [randint(0., 50.) for x in indices]
rows = zip(indices, freqs, powers, ch_powers, ch_noises, osnr)
self.data = [{"viewclass": "Data1Item", "row": row} for row in rows]
def push_data_2(self):
indices = range(70)
freqs = [randint(0., 50.) for x in indices]
powers = [randint(0., 50.) for x in indices]
rows = zip(indices, freqs, powers)
self.data = [{"viewclass": "Data2Item", "row": row} for row in rows]
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment