Created
May 11, 2018 15:50
-
-
Save cruor99/fa8e4c799ae091d319a09677a5d322cf to your computer and use it in GitHub Desktop.
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 kivy.app import App | |
from kivy.lang import Builder | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.properties import ObjectProperty | |
from kivy.uix.label import Label | |
from kivy.uix.recycleview import RecycleView | |
from kivy.clock import Clock | |
from kivy.uix.button import Button | |
kv = """ | |
<Row>: | |
id: row | |
canvas.before: | |
Color: | |
rgba: 0.5, 0.5, 0.5, 1 | |
Rectangle: | |
size: self.size | |
pos: self.pos | |
<Test>: | |
canvas: | |
Color: | |
rgba: 0.3, 0.3, 0.3, 1 | |
Rectangle: | |
size: self.size | |
pos: self.pos | |
orientation: 'vertical' | |
RecycleView: | |
id: rvlist | |
scroll_type: ['bars', 'content'] | |
scroll_wheel_distance: dp(114) | |
bar_width: dp(10) | |
viewclass: 'Row' | |
RecycleBoxLayout: | |
default_size: None, dp(56) | |
default_size_hint: 1, None | |
size_hint_y: None | |
height: self.minimum_height | |
orientation: 'vertical' | |
spacing: dp(2) | |
<TestRoot>: | |
Test: | |
pos_hint: {"center_x": .5, "center_y": .5} | |
""" | |
Builder.load_string(kv) | |
class Row(BoxLayout): | |
row_content = ObjectProperty() | |
def __init__(self,**kwargs): | |
super(Row, self).__init__(**kwargs) | |
Clock.schedule_once(self.finish_init,0) | |
def finish_init(self, dt): | |
for elt in self.row_content: | |
self.add_widget(Label(text = elt)) | |
self.bind(row_content = self.update_row) | |
def update_row(self, *args): | |
self.clear_widgets() | |
for elt in args[1]: | |
self.add_widget(Label(text = elt)) | |
def on_touch_down(self, touch): | |
super(Row, self).on_touch_down(touch) | |
if self.collide_point(*touch.pos): | |
print(self.row_content) | |
print(touch) | |
print(App.get_running_app().root_window.mouse_pos) | |
print(touch.spos) | |
spos_button = Button(text="SPOS", pos_hint={"x": touch.spos[0], "y": touch.spos[1]}, size_hint=(.1, .1)) | |
pos_button = Button(text="POS", pos=touch.pos, size_hint=(None, None)) | |
window_pos_button = Button(text="Window POS", pos=App.get_running_app().root_window.mouse_pos, size_hint=(None, None)) | |
App.get_running_app().root.add_widget(spos_button) | |
App.get_running_app().root.add_widget(pos_button) | |
App.get_running_app().root.add_widget(window_pos_button) | |
class Test(BoxLayout): | |
def __init__(self,**kwargs): | |
super(Test, self).__init__(**kwargs) | |
Clock.schedule_once(self.do_new_data) | |
def do_new_data(self, *args): | |
self.ids.rvlist.data = [{'row_content': [str(i) for i in range(5)]} for x in range(15)] | |
class TestRoot(FloatLayout): | |
pass | |
class TestApp(App): | |
def build(self): | |
return TestRoot() | |
if __name__ == '__main__': | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment