Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dropselect not working properly with touchscreen #342

Closed
yagui opened this issue May 21, 2021 · 6 comments · Fixed by #348
Closed

dropselect not working properly with touchscreen #342

yagui opened this issue May 21, 2021 · 6 comments · Fixed by #348
Labels

Comments

@yagui
Copy link

yagui commented May 21, 2021

Environment information
Describe your environment information, such as:

  • SO: linux
  • python version: v3.7/3.8
  • pygame version: v2.0.1
  • pygame-menu version: v4.0.6

Describe the bug
with a touchscreen (having touchscreen=True and mouse_enabled=False in the initialization)
a) I can't scroll the option of a dropselect.
b) there is an exception when I touch the dropselect (either in the label or the drop area) when the dropselect has one or two item. With three or more items it doesn't raise the exception.
When there are one or two items, it fails to enter the condition in this line


I think because of the self.active
Doesn't happen if I'm working with the mouse, because with the mouse .is_scrolling() is never called.

Traceback (most recent call last):
  File "test.py", line 41, in <module>
    main()
  File "test.py", line 36, in main
    menu.mainloop(surface)
  File "/home/pi/touchenv/lib/python3.7/site-packages/pygame_menu/menu.py", line 2788, in mainloop
    self.update(pygame.event.get())
  File "/home/pi/touchenv/lib/python3.7/site-packages/pygame_menu/menu.py", line 2387, in update
    elif selected_widget is not None and selected_widget.update(events):
  File "/home/pi/touchenv/lib/python3.7/site-packages/pygame_menu/widgets/widget/dropselect.py", line 1179, in update
    self._drop_frame.get_scrollarea(inner=True).is_scrolling()):
AttributeError: 'NoneType' object has no attribute 'is_scrolling'

To Reproduce

import pygame, pygame_menu

SCREENWIDTH  = 800
SCREENHEIGHT = 480

def main():
    pygame.init()

    surface = pygame.display.set_mode((SCREENWIDTH, SCREENHEIGHT), pygame.FULLSCREEN)

    def test_1(select):
        sVal = select.get_value()
        items = select._items
        items.pop(items.index(sVal[0]))
        select._index = -1
        select.update_items(items)
        select.make_selection_drop()
        print('removed {} left'.format(len(items)))


    menu = pygame_menu.Menu('Test', SCREENWIDTH, SCREENHEIGHT,
                            theme = pygame_menu.themes.THEME_DARK,
                            onclose = pygame_menu.events.RESET,
                            touchscreen = True,
                            joystick_enabled = False,
                            mouse_enabled = False,
                            )

    S1 = menu.add.dropselect('Subject Id', items=[('a',),('b',),('c',),('d',),('e',),('f',)], dropselect_id='s0')
    #S1 = menu.add.dropselect('Subject Id', items=[('a',)], dropselect_id='s0')
    #S1 = menu.add.dropselect('Subject Id', items=[('a',),('b',)], dropselect_id='s0')
    #S1 = menu.add.dropselect('Subject Id', items=[('a',),('b',),('c',)], dropselect_id='s0')
    menu.add.button('One',test_1, S1)

    # Allows menu to be run
    menu.mainloop(surface)
    print(menu.get_input_data())
    return

if __name__ == "__main__":
    main()
@ppizarror
Copy link
Owner

ppizarror commented May 22, 2021

Hi, I've fixed the touch when there's 1 or 2 items (basically, when the drop frame is not scrollable). However, I was not able to test the scroll option. How are you scrolling? As far I'm concerned pygame does not let to scroll using touchscreen (for example that momentum scroll, or touch-and-drag) scrolling. These events should be emulated, and I guess that is hard.

I've tested the touch events using visual studio UWP simulator.
Animation2

@ppizarror
Copy link
Owner

I've merged to master as that PR has grown a lot. Let me know if there's any other issue you've encountered. I'm planning to release the new v4.0.7 soon.

@yagui
Copy link
Author

yagui commented May 24, 2021

I updated the library to the repo latest version but I'm still having this issue.
Regarding the scrolling, I think there is a problem in general with scrollbars. But it seems you are not getting that problem. I made another issue to discuss it.
Regarding the dropselect, it is working better but after deleting some items, when there is only 2 left ('e' and 'f' in the video), and I try to select one, if fails again.

Using the same example above, only changing test_1 function with the new methods

    def test_1(select):                                                                                                                                                                                 
        sVal = select.get_value()                                                                                                                                                                       
        items = select.get_items()                                                                                                                                                                      
        items.pop(items.index(sVal[0]))                                                                                                                                                                 
        select.update_items(items)                                                                                                                                                                      
        print('removed {} left'.format(len(items)))

video1

same error

Traceback (most recent call last):
  File "test.py", line 41, in <module>
    main()
  File "test.py", line 36, in main
    menu.mainloop(surface)
  File "/home/pi/touchenv/lib/python3.7/site-packages/pygame_menu/menu.py", line 2821, in mainloop
    self.update(pygame.event.get())
  File "/home/pi/touchenv/lib/python3.7/site-packages/pygame_menu/menu.py", line 2397, in update
    selected_widget.update(events):
  File "/home/pi/touchenv/lib/python3.7/site-packages/pygame_menu/widgets/widget/dropselect.py", line 1187, in update
    not self._drop_frame.get_scrollarea(inner=True).is_scrolling() and
AttributeError: 'NoneType' object has no attribute 'is_scrolling'

I can try to log all pygame events if you think it will help to track the bug.

@ppizarror
Copy link
Owner

Hi, I'll test this issue by emulating that deletion. Thanks also for providing such gifs

@ppizarror
Copy link
Owner

ppizarror commented May 24, 2021

I was able to reproduce the example; #348 fixes this issue. Let me know 😄

@yagui
Copy link
Author

yagui commented May 25, 2021

Working now, Thanks!! The scrollbar in the dropselect (merging #349 too) still doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants