image_carousel.py
import ui | |
images = [ui.Image.named(i) for i in 'Rabbit_Face|Mouse_Face|Cat_Face|Dog_Face|Octopus|Cow_Face'.split('|')] | |
def button_action(sender): | |
def animation(): | |
cv = sender.superview['view1'].subviews[0] | |
w = sender.superview['view1'].width | |
if sender.title == '>': | |
if cv.x > (-(len(images)-1)*w): | |
cv.x = (cv.x-w) | |
else: | |
if cv.x < 0: | |
cv.x = (cv.x+w) | |
ui.animate(animation, duration=3) | |
v = ui.load_view() | |
x, y, w, h = v['view1'].frame | |
cv = ui.View(frame=(0, 0,len(images)*w, h)) | |
v['view1'].add_subview(cv) | |
for i, img in enumerate(images): | |
imgview = ui.ImageView(frame=(i*w,0,w,h)) | |
imgview.image = img | |
cv.add_subview(imgview) | |
v.present('sheet') |
[ | |
{ | |
"class" : "View", | |
"attributes" : { | |
"background_color" : "RGBA(1.000000,1.000000,1.000000,1.000000)", | |
"tint_color" : "RGBA(0.000000,0.478000,1.000000,1.000000)", | |
"enabled" : true, | |
"border_color" : "RGBA(0.000000,0.000000,0.000000,1.000000)", | |
"flex" : "" | |
}, | |
"frame" : "{{0, 0}, {601, 561}}", | |
"selected" : false, | |
"nodes" : [ | |
{ | |
"class" : "View", | |
"attributes" : { | |
"class" : "View", | |
"name" : "view1", | |
"uuid" : "4FCFF461-1F7C-465E-B661-3C0AB28FA97A", | |
"frame" : "{{251, 231}, {100, 100}}" | |
}, | |
"frame" : "{{111, 52}, {345, 487}}", | |
"selected" : false, | |
"nodes" : [ | |
] | |
}, | |
{ | |
"class" : "Button", | |
"attributes" : { | |
"font_size" : 30, | |
"title" : ">", | |
"name" : "button1", | |
"action" : "button_action", | |
"class" : "Button", | |
"frame" : "{{261, 265}, {80, 32}}", | |
"uuid" : "88712823-1A24-45CE-B285-D524C2184A2E" | |
}, | |
"frame" : "{{483, 52}, {80, 487}}", | |
"selected" : true, | |
"nodes" : [ | |
] | |
}, | |
{ | |
"class" : "Button", | |
"attributes" : { | |
"font_size" : 30, | |
"title" : "<", | |
"name" : "button2", | |
"action" : "button_action", | |
"class" : "Button", | |
"frame" : "{{261, 265}, {80, 32}}", | |
"uuid" : "B42D28A5-AB6B-4A55-AC1B-C23E8CF945AA" | |
}, | |
"frame" : "{{6, 52}, {80, 487}}", | |
"selected" : false, | |
"nodes" : [ | |
] | |
} | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment