Accordion and Scroll View

694 views
Skip to first unread message

jay

unread,
Feb 28, 2012, 3:11:46 AM2/28/12
to Kivy users support
Anybody have any luck getting a scroll view inside an Accordion?

The clipping of the views seems all screwed up..

accordion = Accordion(orientation='vertical')
accordion.width = 640
accordion.height = 640

for i in xrange(5):
item = AccordionItem(title='Title %d' % i)

scroll_view = ScrollView()
scroll_view.width = 640
scroll_view.height = 480

layout = Widget()

for j in xrange(5):
for k in xrange(5):
btn = Button(text=str(i), size=(64, 64),
size_hint=(None, None))
btn.x = j * 128
btn.y = k * 128
layout.add_widget(btn)

scroll_view.add_widget(layout)
item.add_widget(scroll_view)
accordion.add_widget(item)

self.add_widget(accordion)

Mathieu Virbel

unread,
Feb 28, 2012, 5:30:46 AM2/28/12
to kivy-...@googlegroups.com
Hi,

size_hint have the priority over size.
Setting width/height have no impact, since size_hint is still 1, 1.
If you want to use size, deactivate size_hint first.

In addition, read the scrollview to understand _how_ the child of the scrollview _must_ be managed.
The 'layout' of the scrollview was a widget, with size_hint 1, 1 => mean the children will have the same size of the scrollview => what do you want to scroll then?

I didn't test, but that might be better:

> accordion = Accordion(orientation='vertical', size_hint=(None, None), size=(640, 480))


>
> for i in xrange(5):
> item = AccordionItem(title='Title %d' % i)
>
> scroll_view = ScrollView()
>

> layout = GridLayout(cols=2, size_hint_y=None)
> layout.bind(height=layout.setter('minimum_height')


> for j in xrange(5):
> for k in xrange(5):
> btn = Button(text=str(i), size=(64, 64),
> size_hint=(None, None))
> btn.x = j * 128
> btn.y = k * 128
> layout.add_widget(btn)
>
> scroll_view.add_widget(layout)
> item.add_widget(scroll_view)
> accordion.add_widget(item)
>
> self.add_widget(accordion)

jay

unread,
Feb 28, 2012, 4:30:43 PM2/28/12
to Kivy users support
Thanks for the hint on size hint.. :)

but I don't think that was the problem.

I've attached some code you can just copy and paste right into a new
kivy app.

Everything seems to work, events are received correctly, the scroll
views scrolls and you can click the buttons.

Only one thing seems to be going wrong, and that is that the layouts
inside the scroll view are not "clipped" when their accordion item is
closed. This means you can see all 3 layouts at once.

I think it might just be a small fix, but unfortunately I only get to
work on kivy 2 days a week so I can't look any further into it this
week.

If you can think of and easy fix it would be a big help.


import kivy
kivy.require('1.0.8')

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.uix.gridlayout import GridLayout
from kivy.uix.accordion import Accordion, AccordionItem

class ScrollViewApp(App):

def build(self):

root = Accordion(orientation='vertical', size_hint=(None,
None))
root.size = (480, 320)
root.center = Window.center

for i in xrange(3):
item = AccordionItem(title='Title %d' % i)

layout = GridLayout(cols=5, spacing=32, size_hint=(None,
None))
layout.bind(minimum_height=layout.setter('height'))
layout.bind(minimum_width=layout.setter('width'))
for j in xrange(50):
btn = Button(text=str(i), size=(64, 64),
size_hint=(None, None))
layout.add_widget(btn)

# create a scroll view, with a size < size of the grid
scroll_view = ScrollView(size_hint=(None, None))
scroll_view.size = (480, 320)
scroll_view.center = Window.center
scroll_view.add_widget(layout)

item.add_widget(scroll_view)

root.add_widget(item)

return root

if __name__ == '__main__':

ScrollViewApp().run()




When you add the scroll view with the layout inside it instead you can
see all 5 layouts.

jay

unread,
Feb 28, 2012, 4:32:12 PM2/28/12
to Kivy users support
ugg.. please ignore that last part of the message after the source. it
was from an earlier draft.

matt radford

unread,
Apr 16, 2012, 1:11:22 AM4/16/12
to Kivy users support
I too am having this problem. which is a shame, because I think this
combo is really sexy!

- Matt

Mathieu Virbel

unread,
Apr 16, 2012, 5:44:08 AM4/16/12
to kivy-...@googlegroups.com
Guys,

You should open an issue when you hit such bug.
Just tested the snippet, and it look like a bug :)

Mathieu

>>> Le 28 f�vr. 2012 � 09:11, jay a �crit :

Mathieu Virbel

unread,
Apr 16, 2012, 10:25:20 AM4/16/12
to kivy-...@googlegroups.com
Ok, this issue showed a design bug inside Stencil instructions
implementation. This is now resolved in latest Kivy, you can pull / make
force and it will work :)

Mathieu

matt radford

unread,
Apr 16, 2012, 1:40:17 PM4/16/12
to Kivy users support
Love it! Thanks so much for the timely response!

Can't wait for the newest build then!


hey so when you say open an issue, where would I do that?

- Matt

Mathieu Virbel

unread,
Apr 16, 2012, 2:21:16 PM4/16/12
to kivy-...@googlegroups.com
Since the bug is resolved, no need to do it, but for the next, use github:
https://github.com/kivy/kivy/issues

And check our documentation about how to report an issue:
http://kivy.org/docs/contribute.html#reporting-an-issue

Mathieu

Reply all
Reply to author
Forward
0 new messages