嵌套的Scrollview在MapMarker的Bubble中不起作用

时间:2019-08-26 16:40:48

标签: python kivy scrollview mousewheel non-scrolling

在我当前的布局中,scrollview没有检测到鼠标的滚轮在任一方向上的滚动以向上或向下导航。您可以使用鼠标按钮单击并拖动,也可以使用鼠标的滚轮单击并拖动。

点击打印:

MyMap Down
MyBubble Down
MyBox Down
MyBoxes_Box Down
MyBoxes_Box2 Down
MyScroll2 Down
MyGrid2 Down
MyLabel2 Down

单击并拖动打印件:

MyMap Down
MyBubble Down
MyBox Down
MyBoxes_Box Down
MyBoxes_Box2 Down
MyScroll2 Down

如果仅在地图视图上方的滚动视图中使用鼠标滚轮,则会打印:

MyMap Down
<kivy.core.window.window_sdl2.WindowSDL object at 0x000002A4C1302458>

Kivy App的分层,显示RelativeLayout:

MyMap Down
<kivy.core.window.window_sdl2.WindowSDL object at 0x000001E26AA42458>
MyBubble Down
<kivy.uix.relativelayout.RelativeLayout object at 0x000001E278CE2458>
MyBox Down
<kivy.uix.bubble.BubbleContent object at 0x000001E278D51C10>
MyBoxes_Box Down
<__main__.MyBox object at 0x000001E278D51C78>
MyBoxes_Box1 Down
<__main__.MyBoxes_Box object at 0x000001E278D51CE0>
MyScroll1 Down
<__main__.MyBoxes_Box1 object at 0x000001E278D51D48>
MyGrid1 Down
<__main__.MyScroll1 object at 0x000001E278D51E18>
MyLabel1 Down
<__main__.MyGrid1 object at 0x000001E278D8B1E8>

我添加了一个on_touch_down事件,以帮助表明kivy正在检测scrollview小部件内的触摸,但同时也检测到所有父级小部件,我认为这与RelativeLayout有关,但是我在文档中尝试了很多东西,但遇到了麻烦。如果您插入并播放我的示例,则可以单击滚动视图/标签,然后单击并拖动滚动视图/标签以查看基于鼠标/单击行为发生的不同事件。我还添加了一个walk()命令,以显示添加气泡后,将为其所有子控件创建一个RelativeLayout,我相信这是touch.is_mouse_scrolling= 'scrollup'/'scrolldown'运动事件被吸收的地方MapView

如果有人可以帮助我解决这个问题,我将不胜感激!

from kivy.app import App
from kivy.core.window import Window
from kivy.garden.mapview import MapView, MapLayer, MapMarkerPopup, MarkerMapLayer
from kivy.uix.label import Label
from kivy.uix.bubble import Bubble
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.popup import Popup
from kivy.uix.modalview import ModalView
from kivy.uix.widget import Widget 
from kivy.uix.button import Button
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.widget import Widget
class MyScroll1(ScrollView):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyScroll1 Down')
            print (self.parent)
        return super(MyScroll1, self).on_touch_down(touch)
class MyScroll2(ScrollView):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyScroll2 Down')
        return super(MyScroll2, self).on_touch_down(touch)
class MyMarker(MapMarkerPopup):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyMarker Down\n')
        return super(MyMarker, self).on_touch_down(touch)
class MyMap(MapView):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyMap Down')
            print (self.parent)
        return super(MyMap, self).on_touch_down(touch)

class MyBubble(Bubble):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyBubble Down')
            print (self.parent)
        return super(MyBubble, self).on_touch_down(touch)
class MyBox(BoxLayout):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyBox Down')
            print (self.parent)
        return super(MyBox, self).on_touch_down(touch)
class MyBoxes_Box(BoxLayout):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyBoxes_Box Down')
            print (self.parent)
        return super(MyBoxes_Box, self).on_touch_down(touch)
class MyBoxes_Box1(BoxLayout):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyBoxes_Box1 Down')
            print (self.parent)
        return super(MyBoxes_Box1, self).on_touch_down(touch)
class MyBoxes_Box2(BoxLayout):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyBoxes_Box2 Down')
        return super(MyBoxes_Box2, self).on_touch_down(touch)
class MyBtn_Box(BoxLayout):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyBtn_Box Down')
        return super(MyBtn_Box, self).on_touch_down(touch)
class MyGrid1(GridLayout):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyGrid1 Down')
            print (self.parent)
        return super(MyGrid1, self).on_touch_down(touch)
class MyGrid2(GridLayout):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyGrid2 Down')
        return super(MyGrid2, self).on_touch_down(touch)
class MyLabel1(Label):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyLabel1 Down')
            print (self.parent, '\n')
        return super(MyLabel1, self).on_touch_down(touch)
class MyLabel2(Label):
    def on_touch_down(self, touch):
        if self.collide_point(touch.x, touch.y):
            print ('MyLabel2 Down\n')
        return super(MyLabel2, self).on_touch_down(touch)

class TestMapView(App):
    def build(self):
        lat = 30.6394
        lon = -100.057
        newMap = MyMap(zoom=5, lat=lat, lon=lon)
        newMap.map_source = 'osm'
        newMap.map_source.min_zoom = 2
        text1 = 'A bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\nA bunch of text1\n'
        text2 = 'A bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\nA bunch of text2\n'
        marker = MyMarker(id='marker', lat=lat,lon=lon, color= (128,0,0,1), popup_size= (1200,700))
        bubble = MyBubble(id='bubble')
        box = MyBox(id='box', orientation="vertical", padding="5dp", size_hint=(1,1))
        boxes_box = MyBoxes_Box(id='boxes_box', orientation="horizontal", size_hint=(1,.95))
        boxes_box1 = MyBoxes_Box1(id='boxes_box1', orientation="vertical", size_hint=(.5,1))
        boxes_box2 = MyBoxes_Box2(id='boxes_box2', orientation="vertical", size_hint=(.5,1))
        scroll_box1 = MyScroll1(size_hint=(1,.8))
        scroll_box2 = MyScroll2(size_hint=(1,.8))
        grid1 = MyGrid1(size_hint=(1,None), height=900, cols=1)
        grid2 = MyGrid2(size_hint=(1,None), height=900, cols=1)
        boxes_btn_box = MyBtn_Box(id='boxes_btn_box', orientation="horizontal", padding="5dp", size_hint=(1,.05))
        backs = Button(id='backs', text='Back', size_hint=(.4,1))
        nexts = Button(id='nexts', text='Next', size_hint=(.4,1))
        label1 = MyLabel1(id='l1', text="{}".format(text1), font_size=20, markup=True, halign="left")
        label2 = MyLabel2(id='l2', text="{}".format(text2), font_size=20, markup=True, halign="left")

                                            #MapMarkerPopup
        marker.add_widget(bubble)               #Bubble
        bubble.add_widget(box)                      #Box
        box.add_widget(boxes_box)                       #Boxes_Box
        boxes_box.add_widget(boxes_box1)                    #Boxes_Box1
        boxes_box1.add_widget(scroll_box1)                      #Scroll1
        scroll_box1.add_widget(grid1)                               #Grid1
        grid1.add_widget(label1)                                        #Label1
        boxes_box.add_widget(boxes_box2)                    #Boxes_Box2
        boxes_box2.add_widget(scroll_box2)                      #Scroll2
        scroll_box2.add_widget(grid2)                               #Grid2
        grid2.add_widget(label2)                                        #Label2
        box.add_widget(boxes_btn_box)                   #Button-Box
        boxes_btn_box.add_widget(backs)                     #Button
        boxes_btn_box.add_widget(nexts)                     #Button
        newMap.add_widget(marker)
        tree = [type(widget) for widget in bubble.walk()]
        print('\n', tree, '\n')
        return newMap

if __name__ == "__main__":
    TestMapView().run()

0 个答案:

没有答案