forked from beeware/toga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialogs.py
56 lines (40 loc) · 2.03 KB
/
dialogs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pytest
from toga_iOS.libs import NSDate, NSRunLoop
class DialogsMixin:
@property
def dialog_view_controller(self):
return self.app.current_window._impl.native.rootViewController
def _setup_alert_dialog(self, dialog, action_index):
# Install an overridden show method that invokes the original,
# but then closes the open dialog.
orig_show = dialog._impl.show
def automated_show(host_window, future):
orig_show(host_window, future)
# Inject a small pause without blocking the event loop
NSRunLoop.currentRunLoop.runUntilDate(
NSDate.dateWithTimeIntervalSinceNow(1.0 if self.app.run_slow else 0.2)
)
# Close the dialog and trigger the completion handler
self.dialog_view_controller.dismissViewControllerAnimated(
False, completion=None
)
dialog._impl.native.actions[action_index].handler(dialog._impl.native)
dialog._impl.show = automated_show
def setup_info_dialog_result(self, dialog):
self._setup_alert_dialog(dialog, 0)
def setup_question_dialog_result(self, dialog, result):
self._setup_alert_dialog(dialog, 0 if result else 1)
def setup_confirm_dialog_result(self, dialog, result):
self._setup_alert_dialog(dialog, 0 if result else 1)
def setup_error_dialog_result(self, dialog):
self._setup_alert_dialog(dialog, 0)
def setup_stack_trace_dialog_result(self, dialog, result):
pytest.skip("Stack Trace dialog not implemented on iOS")
def setup_save_file_dialog_result(self, dialog, result):
pytest.skip("Save File dialog not implemented on iOS")
def setup_open_file_dialog_result(self, dialog, result, multiple_select):
pytest.skip("Open File dialog not implemented on iOS")
def setup_select_folder_dialog_result(self, dialog, result, multiple_select):
pytest.skip("Select Folder dialog not implemented on iOS")
def is_modal_dialog(self, dialog):
return True