Kivy Dropdown Doesn't Detect Touch At Bottom

Viewed 28

I'm using a custom DropDown with the max_height attribute in my project. This works as expected when using the mouse wheel only to select an item. But when adding scroll_type: ['bars'] in the kv string, a selection is not detected for the bottom part of the DropDown.

Screenshot

I've tried using a larger main button(Label) and larger buttons for the DropDown items, but the field that goes unselected doesn't grow. It appears to be the same amount of pixels regardless of widget size.

Is there an attribute where you can adjust the area it looks at for a touch? Or am I missing something more obvious?

import kivy
from kivy.lang import Builder
from kivy.app import App
from kivy.properties import StringProperty, DictProperty, ObjectProperty
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.dropdown import DropDown
from kivy.factory import Factory

kivy.require('2.0.0')

Builder.load_string('''
#:kivy 2.0.0
#:import Factory kivy.factory.Factory
#:import ScrollEffect kivy.effects.scroll.ScrollEffect


<DropDownTrigger@Button>:
    size_hint: None, None
    size: '30dp', '30dp'
    text: 'X'

<DropDownItem@Button>:
    label_id: 0
    size_hint_y: None
    height: '30dp'
    text_size: self.size
    valign: 'middle'

<DropDownMainLabel@Label>:
    label_id: 0
    size_hint_y: None
    height: '30dp'
    text_size: self.size
    valign: 'middle'

<EntryDropDown>:
    trigger_button_width: 30
    max_height: '150dp'
    auto_width: False
    width: root.mainbutton.width + root.trigger_button_width
    bar_width: '20dp'
    effect_cls: ScrollEffect
    scroll_type: ['bars']

<LabelColumn>:
    data: {}
    cols: 1
    GridLayout:
        canvas.before:
            Color:
                rgba: .62, .67, .76, 0.5
            Rectangle:
                pos: self.pos
                size: self.size
        size_hint: None, None
        size: '200dp', self.minimum_height
        cols: 1
        Label:
            size_hint: None, None
            size: self.texture_size
            text: root.top_label_text
        GridLayout:
            rows: 1
            size_hint_y: None
            height: '30dp'
            DropDownMainLabel:
                id: selection_label
                label_id: (root.data).get('label_id', -1)
                text: (root.labels).get(self.label_id, '')
                on_label_id: root.data['label_id'] = self.label_id
            DropDownTrigger:
                id: trigger_button
                on_release:
                    Factory.EntryDropDown(mainbutton=selection_label,
                    labels=root.labels).open(selection_label)

''')


class LabelColumn(GridLayout):
    labels = DictProperty()
    top_label_text = StringProperty()


class EntryDropDown(DropDown):
    mainbutton = ObjectProperty()
    labels = DictProperty()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        for label_id, label_name in self.labels.items():  
            btn = Factory.DropDownItem(text=label_name)
            btn.label_id = label_id
            btn.bind(on_release=lambda btn: self.select(btn))
            self.add_widget(btn)

        self.bind(on_select=lambda x, btn: self.set_selections(btn))

    def set_selections(self, selected_button): 
        self.mainbutton.text = selected_button.text
        self.mainbutton.label_id = selected_button.label_id


class TestingApp(App):

    def build(self):
        return LabelColumn(
            top_label_text='Dropdown',
            labels={
                48: 'Product 48',
                49: 'Product 49',
                51: 'Product 51',
                56: 'Product 56',
                57: 'Product 57',
                58: 'Product 58',
                64: 'Product 64',
                68: 'Product 68'},)


if __name__ == '__main__':
    TestingApp().run()
0 Answers
Related