Skip to content

Commit 47e6836

Browse files
committed
Rename TextBox to BaseTextBox, add Numeric type hinting.
1 parent d1a73a2 commit 47e6836

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

doc/source/visualdialog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Text boxes
1010
TextBox
1111
-------
1212

13-
.. autoclass:: visualdialog.box.TextBox
13+
.. autoclass:: visualdialog.box.BaseTextBox
1414
:members:
1515
:undoc-members:
1616
:private-members:

visualdialog/box.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020
#
2121

22-
__all__ = ["TextBox"]
22+
__all__ = ["BaseTextBox"]
2323

2424
import curses
2525
import curses.textpad
@@ -29,6 +29,7 @@
2929
CursesKeyConstants,
3030
CursesTextAttributesConstant,
3131
CursesTextAttributesConstants,
32+
Numeric,
3233
TextAttributes)
3334

3435

@@ -47,7 +48,7 @@ def __str__(self):
4748
return f"text box was aborted by pressing the {self.key} key"
4849

4950

50-
class TextBox:
51+
class BaseTextBox:
5152
"""This class provides attributs and methods to manage a text box.
5253
5354
.. NOTE::
@@ -98,7 +99,7 @@ class TextBox:
9899
Waiting time in seconds after writing a character contained in
99100
``downtime_chars``.
100101
This defaults to ``0.6``.
101-
:type downtime_chars_delay: Union[int,float]
102+
:type downtime_chars_delay: Numeric
102103
"""
103104

104105
def __init__(
@@ -113,7 +114,7 @@ def __init__(
113114
CursesTextAttributesConstants] = curses.A_BOLD,
114115
downtime_chars: Union[Tuple[str],
115116
List[str]] = (",", ".", ":", ";", "!", "?"),
116-
downtime_chars_delay: Union[int, float] = .6):
117+
downtime_chars_delay: Numeric = .6):
117118
self.pos_x, self.pos_y = pos_x, pos_y
118119
self.length, self.width = length, width
119120

visualdialog/dialog.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
import time
2828
from typing import Callable, Dict, List, Optional, Tuple, Union
2929

30-
from .box import TextBox
30+
from .box import BaseTextBox
3131
from .utils import (CursesTextAttributesConstant,
3232
CursesTextAttributesConstants,
33+
Numeric,
3334
TextAttributes,
3435
_make_chunk)
3536

3637

37-
class DialogBox(TextBox):
38+
class DialogBox(BaseTextBox):
3839
"""This class provides methods and attributs to manage a dialog box.
3940
4041
:param end_dialog_indicator: Character that will be displayed in the
@@ -49,7 +50,7 @@ class DialogBox(TextBox):
4950
5051
.. NOTE::
5152
This class inherits all the methods and attributes of
52-
``TextBox``.
53+
``BaseTextBox``.
5354
5455
.. WARNING::
5556
Parameters ``downtime_chars`` and ``downtime_chars_delay`` do
@@ -109,8 +110,8 @@ def char_by_char(
109110
words_attr: Union[Dict[Tuple[str], CursesTextAttributesConstant],
110111
Dict[Tuple[str], CursesTextAttributesConstants]] = {},
111112
flash_screen: bool = False,
112-
delay: Union[int, float] = .04,
113-
random_delay: Union[Tuple[int, float], List[int, float]] = (0, 0),
113+
delay: Numeric = .04,
114+
random_delay: Union[Tuple[Numeric], List[Numeric]] = (0, 0),
114115
callback: Callable = lambda: None,
115116
cargs: Union[Tuple, List] = ()):
116117
"""Writes the given text character by character in the current
@@ -147,13 +148,13 @@ def char_by_char(
147148
148149
:param delay: Waiting time between the writing of each character
149150
of text in second. This defaults to ``0.04``.
150-
:type delay: Union[int, float]
151+
:type delay: Numeric
151152
152153
:param random_delay: Waiting time between the writing of each
153154
character in seconds where time waited is a random number
154155
generated in ``random_delay`` interval. This defaults to
155156
``(0, 0)``.
156-
:type random_delay: Union[tuple[int, float],list[int, float]]
157+
:type random_delay: Union[tuple[Numeric],list[Numeric]]
157158
158159
:param callback: Callable called after writing a character and
159160
the delay time has elapsed. This defaults to a lambda which
@@ -254,8 +255,8 @@ def word_by_word(
254255
words_attr: Union[Dict[Tuple[str], CursesTextAttributesConstant],
255256
Dict[Tuple[str], CursesTextAttributesConstants]] = {},
256257
flash_screen: bool = False,
257-
delay: Union[int, float] = .15,
258-
random_delay: Union[Tuple[int, float], List[int, float]] = (0, 0),
258+
delay: Numeric = .15,
259+
random_delay: Union[Tuple[Numeric], List[Numeric]] = (0, 0),
259260
callback: Callable = lambda: None,
260261
cargs: Union[Tuple, List] = ()):
261262
"""Writes the given text word by word at position in the current
@@ -296,13 +297,13 @@ def word_by_word(
296297
297298
:param delay: Waiting time between the writing of each word of
298299
``text`` in second. This defaults to ``0.15``.
299-
:type delay: Union[int, float]
300+
:type delay: Numeric
300301
301302
:param random_delay: Waiting time between the writing of each
302303
word in seconds where time waited is a random number
303304
generated in ``random_delay`` interval. This defaults to
304305
``(0, 0)``.
305-
:type random_delay: Union[tuple[int, float],list[int, float]]
306+
:type random_delay: Union[Tuple[Numeric], List[Numeric]]
306307
307308
:param callback: Callable called after writing a word and the
308309
delay time has elapsed. This defaults to a lambda which do

visualdialog/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
#
2020
#
2121

22-
from typing import Generator, List, Tuple, Union
22+
from typing import Generator, List, Tuple, TypeVar, Union
2323

2424

25+
Numeric = TypeVar("Numeric", int, float)
26+
2527
# curses text attribute constants are integers.
2628
# See https://docs.python.org/3/library/curses.html?#constants
2729
CursesTextAttributesConstant = int

0 commit comments

Comments
 (0)