-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make modal and dropdown consistent (kivy#6650)
* Dismiss popup only when down and up touch are outside. * Add tests. * Fix action bar test - click twice to close and then open. * Starting touch outside should always close, inside should never.
- Loading branch information
Showing
5 changed files
with
203 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from kivy.tests import async_run, UnitKivyApp | ||
|
||
|
||
def dropdown_app(): | ||
from kivy.app import App | ||
from kivy.uix.button import Button | ||
from kivy.uix.dropdown import DropDown | ||
from kivy.uix.label import Label | ||
|
||
class RootButton(Button): | ||
|
||
dropdown = None | ||
|
||
def on_touch_down(self, touch): | ||
assert self.dropdown.attach_to is None | ||
return super(RootButton, self).on_touch_down(touch) | ||
|
||
def on_touch_move(self, touch): | ||
assert self.dropdown.attach_to is None | ||
return super(RootButton, self).on_touch_move(touch) | ||
|
||
def on_touch_up(self, touch): | ||
assert self.dropdown.attach_to is None | ||
return super(RootButton, self).on_touch_up(touch) | ||
|
||
class TestApp(UnitKivyApp, App): | ||
def build(self): | ||
root = RootButton(text='Root') | ||
self.attach_widget = Label(text='Attached widget') | ||
root.add_widget(self.attach_widget) | ||
|
||
root.dropdown = self.dropdown = DropDown( | ||
auto_dismiss=True, min_state_time=0) | ||
self.inner_widget = w = Label( | ||
size_hint=(None, None), text='Dropdown') | ||
root.dropdown.add_widget(w) | ||
return root | ||
|
||
return TestApp() | ||
|
||
|
||
@async_run(app_cls_func=dropdown_app) | ||
async def test_dropdown_app(kivy_app): | ||
await kivy_app.wait_clock_frames(2) | ||
dropdown = kivy_app.dropdown | ||
button = kivy_app.root | ||
assert dropdown.attach_to is None | ||
|
||
kivy_app.attach_widget.size = button.width * 3 / 5, 2 | ||
kivy_app.attach_widget.top = button.height | ||
kivy_app.inner_widget.size = button.width * 3 / 5, button.height | ||
|
||
# just press button | ||
async for _ in kivy_app.do_touch_down_up(widget=button): | ||
pass | ||
async for _ in kivy_app.do_touch_drag(widget=button, dx=button.width / 4): | ||
pass | ||
|
||
# open dropdown | ||
dropdown.open(kivy_app.attach_widget) | ||
dropdown.pos = 0, 0 | ||
await kivy_app.wait_clock_frames(2) | ||
assert dropdown.attach_to is not None | ||
|
||
# press within dropdown area - should stay open | ||
async for _ in kivy_app.do_touch_down_up(widget=button): | ||
pass | ||
assert dropdown.attach_to is not None | ||
# start in dropdown but release outside - should stay open | ||
async for _ in kivy_app.do_touch_drag(widget=button, dx=button.width / 4): | ||
pass | ||
assert dropdown.attach_to is not None | ||
|
||
# start outside but release in dropdown - should close | ||
async for _ in kivy_app.do_touch_drag( | ||
pos=(button.center_x + button.width / 4, button.center_y), | ||
target_widget=button): | ||
pass | ||
assert dropdown.attach_to is None | ||
|
||
# open dropdown again | ||
dropdown.open(kivy_app.attach_widget) | ||
dropdown.pos = 0, 0 | ||
await kivy_app.wait_clock_frames(2) | ||
assert dropdown.attach_to is not None | ||
|
||
# press outside dropdown area to close it - should close | ||
async for _ in kivy_app.do_touch_down_up( | ||
pos=(button.center_x + button.width / 4, button.center_y)): | ||
pass | ||
assert dropdown.attach_to is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from kivy.tests import async_run, UnitKivyApp | ||
from math import isclose | ||
|
||
|
||
def modal_app(): | ||
from kivy.app import App | ||
from kivy.uix.button import Button | ||
from kivy.uix.modalview import ModalView | ||
|
||
class ModalButton(Button): | ||
|
||
modal = None | ||
|
||
def on_touch_down(self, touch): | ||
assert self.modal._window is None | ||
return super(ModalButton, self).on_touch_down(touch) | ||
|
||
def on_touch_move(self, touch): | ||
assert self.modal._window is None | ||
return super(ModalButton, self).on_touch_move(touch) | ||
|
||
def on_touch_up(self, touch): | ||
assert self.modal._window is None | ||
return super(ModalButton, self).on_touch_up(touch) | ||
|
||
class TestApp(UnitKivyApp, App): | ||
def build(self): | ||
root = ModalButton() | ||
root.modal = self.modal_view = ModalView( | ||
size_hint=(.2, .5), auto_dismiss=True) | ||
return root | ||
|
||
return TestApp() | ||
|
||
|
||
@async_run(app_cls_func=modal_app) | ||
async def test_modal_app(kivy_app): | ||
await kivy_app.wait_clock_frames(2) | ||
modal = kivy_app.modal_view | ||
button = kivy_app.root | ||
modal._anim_duration = 0 | ||
assert modal._window is None | ||
|
||
# just press button | ||
async for _ in kivy_app.do_touch_down_up(widget=button): | ||
pass | ||
async for _ in kivy_app.do_touch_drag(widget=button, dx=button.width / 4): | ||
pass | ||
|
||
# open modal | ||
modal.open() | ||
await kivy_app.wait_clock_frames(2) | ||
assert modal._window is not None | ||
assert isclose(modal.center_x, button.center_x, abs_tol=.1) | ||
assert isclose(modal.center_y, button.center_y, abs_tol=.1) | ||
|
||
# press within modal area - should stay open | ||
async for _ in kivy_app.do_touch_down_up(widget=button): | ||
pass | ||
assert modal._window is not None | ||
# start in modal but release outside - should stay open | ||
async for _ in kivy_app.do_touch_drag(widget=button, dx=button.width / 4): | ||
pass | ||
assert modal._window is not None | ||
|
||
# start outside but release in modal - should close | ||
async for _ in kivy_app.do_touch_drag( | ||
pos=(button.center_x + button.width / 4, button.center_y), | ||
target_widget=button): | ||
pass | ||
assert modal._window is None | ||
|
||
# open modal again | ||
modal.open() | ||
await kivy_app.wait_clock_frames(2) | ||
assert modal._window is not None | ||
|
||
# press outside modal area - should close | ||
async for _ in kivy_app.do_touch_down_up( | ||
pos=(button.center_x + button.width / 4, button.center_y)): | ||
pass | ||
assert modal._window is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters