Scrolling with non-sdl window providers

28 views
Skip to first unread message

Andrew Freitas

unread,
Jan 20, 2017, 3:41:17 PM1/20/17
to Kivy users support
Hello,

I'm working on an application that uses a nested scrolling interface. The top container scrolls horizontally and its children scroll vertically. I've been using the ScrollView widget to achieve this and gotten it to work, but only when using the SDL2 window provider. Here's the code that creates both the horizontal and vertical ScrollViews:

class ScrollingModal(ModalView):
    def __init__(self, direction, view, reload_fn, **kwargs):
        ModalView.__init__(self, **kwargs)
        container = BoxLayout(orientation='vertical', size_hint=(0.95, 0.95))
        self.add_widget(container)

        container.add_widget(Button(text='X', on_press=self.dismiss, size_hint=(0.0375, 0.05), pos_hint={'right': 1}))
        self.view = view
        if direction == 'horizontal':
            scroller = ScrollView(do_scroll_y=False)
            self.view.bind(minimum_width=self.view.setter('width'))
        else:
            scroller = ScrollView(do_scroll_x=False)
            self.view.bind(minimum_height=self.view.setter('height'))
        scroller.add_widget(self.view)
        self.bind(size=reload_fn)
        self.bind(on_open=reload_fn)
        container.add_widget(scroller)

The technique of binding the view's minimum_height is taken directly from the documentation page (https://kivy.org/docs/api-kivy.uix.scrollview.html), and I applied it to the minimum_width property to get horizontal scrolling. As I said, this worked initially, but when we tested on another machine that wasn't using SDL2, we get the following error:

self.view.bind(minimum_width=self.view.setter('width'))
File "kivy\_event.pyx", line 438, in kivy._event.EventDispatcher.bind (kivy\_event.c:6026)
KeyError: 'minimum_width'

After some digging in the kivy source code on github, it appears the minimum_width property is only available with SDL2 (https://github.com/kivy/kivy/blob/master/kivy/core/window/__init__.py#L215). So is there another way to get horizontal scrolling working across all window providers? Or is there another way to achieve the same effect?

Thanks,
Andrew

Alexander Taylor

unread,
Jan 21, 2017, 10:51:50 AM1/21/17
to Kivy users support
The minimum_width you linked is a property of the Window itself. This is only supported with the SDL2 Window class, but it doesn't affect the widgets, they have the same behaviour with any backend.

In your error, it looks more like whatever 'view' is doesn't have a minimum_width property, regardless of the windowing backend.

Andrew Freitas

unread,
Jan 22, 2017, 2:16:38 PM1/22/17
to Kivy users support
Thanks for replying. There are only 2 places we're using this widget. In both cases the 'view' is a BoxLayout which definitely has a minimum_width property:

ScrollingModal.__init__(self,
                       
direction='horizontal',
                       
view=BoxLayout(orientation='horizontal', size_hint=(None, 1)),
                       
reload_fn=self.reload,
                       
size_hint=(.95, .95),
                       
auto_dismiss=False)


self.selector_view = BoxLayout(orientation='vertical', size_hint=(1, None))
self.selector = ScrollingModal(direction='vertical',
                               
view= self.selector_view,
                               
reload_fn=self.reload,
                               
size_hint=(0.75, 0.75))

The first of these is the one that threw the error, though that may just be because it was the first instantiation of the widget in the application.

In attempting to rule out the window provider as the cause I'm trying to reproduce the error by running the app with pygame, but I'm running on a linux machine with sdl2 already installed so 'pygame' doesn't even make it into the list of available window providers at startup (https://github.com/kivy/kivy/blob/master/kivy/core/window/__init__.py#L1766). Do you have any other suggestions for how to debug this? What I pasted above is pretty much the extent of the error message.

Thanks,
Andrew

Alexander Taylor

unread,
Jan 22, 2017, 2:18:13 PM1/22/17
to kivy-...@googlegroups.com
BoxLayout only has a minimum_width property as of Kivy 1.9.2, the
current dev version. What version are you using?
> <https://kivy.org/docs/api-kivy.uix.scrollview.html>), and I
> applied it to the minimum_width property to get horizontal
> scrolling. As I said, this worked initially, but when we tested
> on another machine that wasn't using SDL2, we get the following
> error:
>
> |
> self.view.bind(minimum_width=self.view.setter('width'))
> File"kivy\_event.pyx",line
> 438,inkivy._event.EventDispatcher.bind (kivy\_event.c:6026)
> KeyError:'minimum_width'
> |
>
> After some digging in the kivy source code on github, it appears
> the minimum_width property is only available with SDL2
> (https://github.com/kivy/kivy/blob/master/kivy/core/window/__init__.py#L215
> <https://github.com/kivy/kivy/blob/master/kivy/core/window/__init__.py#L215>).
> So is there another way to get horizontal scrolling working
> across all window providers? Or is there another way to achieve
> the same effect?
>
> Thanks,
> Andrew
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Kivy users support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/kivy-users/4AgP8emrV7E/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> kivy-users+...@googlegroups.com
> <mailto:kivy-users+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


signature.asc

Andrew Freitas

unread,
Jan 22, 2017, 8:20:36 PM1/22/17
to Kivy users support
That explains it. I'm using the latest from kivy master (which is 1.9.2) I got one of our other devs to try it out:

] [Kivy        ] v1.9.1
[INFO              ] [Python      ] v2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)]
[INFO              ] [Factory     ] 179 symbols loaded
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_gif, img_sdl2 (img_pil, img_ffpyplayer ignored)
    [INFO              ] [OSC         ] using <thread> for socket
[INFO              ] [Window      ] Provider: sdl2
[INFO              ] [GL          ] GLEW initialization succeeded
[INFO              ] [GL          ] OpenGL version <4.4.0 - Build 20.19.15.4424>
[INFO              ] [GL          ] OpenGL vendor <Intel>
[INFO              ] [GL          ] OpenGL renderer <Intel(R) HD Graphics 400>
[INFO              ] [GL          ] OpenGL parsed version: 4, 4
[INFO              ] [GL          ] Shading version <4.40 - Build 20.19.15.4424>
[INFO              ] [GL          ] Texture max size <16384>
[INFO              ] [GL          ] Texture max units <32>
[INFO              ] [Shader      ] fragment shader: <WARNING: 0:7: '' :  #version directive missing>
[INFO              ] [Shader      ] vertex shader: <WARNING: 0:7: '' :  #version directive missing>
[INFO              ] [Window      ] auto add sdl2 input provider
[INFO              ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO              ] [Text        ] Provider: sdl2
 Traceback (most recent call last):
   File "kivyTB.py", line 14, in <module>
     app.run()
   File "C:\Python27\lib\site-packages\kivy\app.py", line 802, in run
     root = self.build()
   File "kivyTB.py", line 10, in build
     return EternalCrusadeWidget(api)
   File "C:\Users\noobiemcfoob\Dropbox\db\bwroot\repos\eternal_crusade\EternalCrusade\EternalCrusadeWidget.py", line 121, in __init__
     self.ac  = AbilityCards(world)
   File "C:\Users\noobiemcfoob\Dropbox\db\bwroot\repos\eternal_crusade\EternalCrusade\AbilityCards.py", line 37, in __init__
     auto_dismiss=False)
   File "C:\Users\noobiemcfoob\Dropbox\db\bwroot\repos\eternal_crusade\EternalCrusade\AbilityCards.py", line 20, in __init__
     self.view.bind(minimum_width=self.view.setter('width'))
   File "kivy\_event.pyx", line 438, in kivy._event.EventDispatcher.bind (kivy\_event.c:6026)
 KeyError: 'minimum_width'

v1.9.1 as you can see.

Thanks for your help, I'll see what I can do about getting all of us on the latest version.
Reply all
Reply to author
Forward
0 new messages