Skip to content

Commit e3ecece

Browse files
committed
Allow to disable concurrency check for all UIScreen inputs
Right now it is possible to disable concurrency check for InputHandler. However, this class is created on demand in the InputManager used by the UIScreen which means that a users are not able to disable concurrency_check without re-implementation of the InputManager and InputHandler which is really cumbersome. To solve this I'm adding a new property to InputManager and enable obtaining the InputManager instance from the UIScreen. The concurrency check shouldn't be disabled if you don't have a strong reason to do it. It was implemented because without the check it's really hard to debug when multiple screens are asking for the input at once. The main reason to disable it is for error reporting after the application has crashed. Related: rhbz#1807491
1 parent 033650e commit e3ecece

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

simpleline/render/screen/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ def title(self, title):
8888
"""
8989
self._title = title
9090

91+
@property
92+
def input_manager(self):
93+
"""Get input manager.
94+
95+
The input manager could be used to tweak input settings.
96+
"""
97+
return self._input_manager
98+
9199
@property
92100
def password_func(self):
93101
"""Get password function.

simpleline/render/screen/input_manager.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, ui_screen):
4747
self._ui_screen = ui_screen
4848
self._input_error_counter = 0
4949
self._input_error_threshold = 5
50+
self._skip_concurrency_check = False
5051
self._input_args = None
5152

5253
@property
@@ -63,6 +64,25 @@ def input_error_threshold_exceeded(self):
6364
errors = self._input_error_counter % self._input_error_threshold
6465
return errors == 0
6566

67+
@property
68+
def skip_concurrency_check(self):
69+
"""Should the concurrency check be skipped?
70+
71+
:returns bool: True if the check should be skipped.
72+
"""
73+
return self._skip_concurrency_check
74+
75+
@skip_concurrency_check.setter
76+
def skip_concurrency_check(self, value):
77+
"""Set if the concurrency check should be skipped when asking for user input.
78+
79+
WARNING: Use this option with caution. When the concurrency check is disabled you
80+
can easily get to unexpected behavior which is hard to debug.
81+
82+
:param bool value: True to skip the concurrency check.
83+
"""
84+
self._skip_concurrency_check = value
85+
6686
def get_input_blocking(self, message, hidden):
6787
"""Get blocking input from the user.
6888
@@ -79,6 +99,7 @@ def get_input_blocking(self, message, hidden):
7999
else:
80100
handler = InputHandler(source=self)
81101

102+
handler.skip_concurrency_check = self._skip_concurrency_check
82103
handler.get_input(message)
83104
handler.wait_on_input()
84105
return handler.value
@@ -102,6 +123,7 @@ def get_input(self, args=None):
102123
if self._ui_screen.password_func:
103124
handler.set_pass_func(self._ui_screen.password_func)
104125

126+
handler.skip_concurrency_check = self._skip_concurrency_check
105127
handler.set_callback(self.process_input)
106128
handler.get_input(prompt)
107129

0 commit comments

Comments
 (0)