Last active
June 11, 2019 13:59
-
-
Save gottadiveintopython/15e4565269c5268e739f9697cbfaefe9 to your computer and use it in GitHub Desktop.
A tool for testing Carousel. It can dynamically change the properties.
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.lang import Builder | |
from kivy.factory import Factory | |
from kivy.app import runTouchApp | |
KV_CODE = ''' | |
#:import random random | |
#:import Button kivy.uix.button.Button | |
<DebugCarousel@Carousel>: | |
canvas.before: | |
Clear: # clear the instructions inherited from StencilView | |
canvas.after: | |
Clear: # clear the instructions inherited from StencilView | |
Color: | |
rgba: 1, 1, 1, 1 | |
Line: | |
dash_offset: 4 | |
dash_length: 2 | |
rectangle: [*self.pos, *self.size, ] | |
<Separator@Widget>: | |
size: 1, 1 | |
canvas: | |
Color: | |
rgb: 1, 0, 1 | |
Rectangle: | |
pos: self.pos | |
size: self.size | |
BoxLayout: | |
BoxLayout: | |
size_hint_x: .2 | |
size_hint_min_x: 200 | |
orientation: 'vertical' | |
Label: | |
text: 'direction' | |
color: 0, 1, 0, 1 | |
BoxLayout: | |
CheckBox: | |
group: 'direction' | |
on_active: carousel.direction = 'left' | |
Label: | |
text: 'left' | |
BoxLayout: | |
CheckBox: | |
group: 'direction' | |
on_active: carousel.direction = 'right' | |
Label: | |
text: 'right' | |
BoxLayout: | |
CheckBox: | |
group: 'direction' | |
on_active: carousel.direction = 'top' | |
Label: | |
text: 'top' | |
BoxLayout: | |
CheckBox: | |
group: 'direction' | |
on_active: carousel.direction = 'bottom' | |
Label: | |
text: 'bottom' | |
Separator: | |
size_hint_y: None | |
Label: | |
text: 'loop' | |
color: 0, 1, 0, 1 | |
Switch: | |
id: loop_switch | |
active: True | |
Separator: | |
size_hint_y: None | |
height: 1 | |
Label: | |
text: 'len(slides) == {}'.format(int(slider.value)) | |
color: 0, 1, 0, 1 | |
Slider: | |
id: slider | |
min: 0 | |
max: 4 | |
step: 1 | |
value: 0 | |
Separator: | |
size_hint_y: None | |
height: 1 | |
Label: | |
text: 'methods' | |
color: 0, 1, 0, 1 | |
Button: | |
text: 'load_slide(not current_slide)' | |
on_press: | |
slides = carousel.slides[:] | |
slides.remove(carousel.current_slide) | |
carousel.load_slide(random.choice(slides)) | |
Button: | |
text: 'load_slide(current_slide)' | |
on_press: carousel.load_slide(carousel.current_slide) | |
Button: | |
text: 'load_next()' | |
on_press: carousel.load_next() | |
Button: | |
text: 'load_previous()' | |
on_press: carousel.load_previous() | |
Separator: | |
size_hint_x: None | |
FloatLayout: | |
DebugCarousel: | |
id: carousel | |
size_hint: .2, .2 | |
pos_hint: {'center': (.5, .5, ), } | |
loop: loop_switch.active | |
''' | |
root = Builder.load_string(KV_CODE) | |
carousel = root.ids.carousel | |
carousel.bind(index=lambda __, value: print('index:', value)) | |
def update_carousels_slides(slider, value): | |
from kivy.uix.button import Button | |
carousel.clear_widgets() | |
for i in range(int(value)): | |
carousel.add_widget(Button(text=str(i), font_size=50)) | |
slider = root.ids.slider | |
slider.bind(value=update_carousels_slides) | |
slider.value = 2 | |
runTouchApp(root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment