Skip to content

Commit f82257d

Browse files
committed
Merge branch 'dev' of https://github.com/Tim-ats-d/Visual-dialog into dev
2 parents 6a9b11a + 505d4a0 commit f82257d

File tree

7 files changed

+33
-30
lines changed

7 files changed

+33
-30
lines changed

examples/confrontation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
PASS_KEYS = (" ", "\n")
10-
HEIGHT, WIDTH = 35, 6
10+
HEIGHT, WIDTH = 37, 7
1111

1212

1313
# It is preferable to create its own class derived from DialogBox for

examples/monologue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def main(win):
2323
curses.init_pair(2, curses.COLOR_CYAN, 0)
2424

2525
textbox = DialogBox(1, 1, # Position 1;1 in win.
26-
30, 5, # Height and width of textbox.
26+
30, 6, # Height and width of textbox.
2727
"Tim-ats", # Title of textbox.
2828
1) # Curses color_pair used to colored title.
2929

visualdialog/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
"""A library to make easier dialog box in terminal."""
32

43
__version__ = 0.8

visualdialog/box.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55

66
import curses
77
import curses.textpad
8-
from typing import List, Literal, Sequence, Tuple, Union
8+
from typing import Callable, List, Literal, Sequence, Tuple, Union
99

1010
from .error import PanicError, ValueNotInBound
1111
from .type import CursesKey, CursesTextAttribute, CursesTextAttributes, CursesWindow
1212
from .utils import TextAttr, to_tuple
1313

1414

15-
MINIMUM_BOX_WIDTH = 4
16-
17-
1815
def value_checker(initializer: Callable) -> Callable:
19-
"""A decorator which checks if the arguments passed to
20-
``BaseTextBox`` initializer are consistent.
16+
"""A decorator which ensures that correct values are passed to
17+
``BaseTextBox`` initializer to avoid unexpected behavior.
2118
"""
2219
def __init__(self,
2320
pos_x, pos_y,
2421
height, width,
2522
title,
2623
*args, **kwargs):
27-
minimum_box_height = len(title) + 5
24+
minimum_box_width = 4
25+
26+
title_box_borders_total_height = 5
27+
minimum_box_height = len(title) + title_box_borders_total_height
2828

29-
if width < MINIMUM_BOX_WIDTH:
30-
raise ValueNotInBound("ne peut pas faire moins de 4 de hauteur")
31-
elif minimum_box_height > height:
32-
raise ValueNotInBound("ne peut pas faire plus de len(title) + 5")
29+
if width < minimum_box_width:
30+
raise ValueNotInBound(f"width must be less than {minimum_box_width}")
31+
elif height < minimum_box_height:
32+
raise ValueNotInBound("height must be less than len(title) + 5")
3333

3434
initializer(self,
3535
pos_x, pos_y,
@@ -102,18 +102,17 @@ def __init__(
102102

103103
self.title_offsetting_y = 2 if title else 0
104104

105-
# Compensation for the left border of the dialog box.
105+
# Compensation for left and upper borders of text box.
106106
self.text_pos_x = pos_x + 2
107-
# Compensation for the upper border of the dialog box.
108107
self.text_pos_y = pos_y + self.title_offsetting_y + 1
109108

109+
# Text margins.
110110
self.nb_char_max_line = height - 5
111111
self.nb_lines_max = width - 3
112112

113113
self.title = title
114114
if title:
115115
self.title_colors = curses.color_pair(title_colors_pair_nb)
116-
# Test if only one argument is passed instead of a sequence.
117116
self.title_text_attr = to_tuple(title_text_attr)
118117

119118
self.downtime_chars = downtime_chars
@@ -154,30 +153,31 @@ def dimensions(self) -> Tuple[int]:
154153
def framing_box(self, win: CursesWindow):
155154
"""Display dialog box borders and his title.
156155
157-
If attribute ``self.title`` is empty doesn't display the title.
156+
If attribute ``self.title`` is empty doesn't display the title
157+
box.
158158
159159
:param win: ``curses`` window object on which the method will
160160
have effect.
161161
"""
162-
title_length = len(self.title) + 4
162+
title_height = len(self.title) + 4
163163
title_width = 2
164164

165-
# Displays the title and the title box.
165+
# Display title and title box.
166166
if self.title:
167167
attr = (self.title_colors, *self.title_text_attr)
168168

169169
curses.textpad.rectangle(win,
170170
self.pos_y,
171171
self.pos_x + 1,
172172
self.pos_y + title_width,
173-
self.pos_x + title_length)
173+
self.pos_x + title_height)
174174

175175
with TextAttr(win, *attr):
176176
win.addstr(self.pos_y + 1,
177177
self.pos_x + 3,
178178
self.title)
179179

180-
# Displays the borders of the dialog box.
180+
# Display borders of text box.
181181
curses.textpad.rectangle(win,
182182
self.pos_y + self.title_offsetting_y,
183183
self.pos_x,

visualdialog/dialog.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DialogBox(BaseTextBox):
2727
of ``TextBox``.
2828
2929
.. NOTE::
30-
This class inherits from ``BaseTextBox``.
30+
This class inherits of ``BaseTextBox``.
3131
3232
.. NOTE::
3333
This class is a context manager.
@@ -360,7 +360,10 @@ def _one_by_one(self,
360360
delay: int,
361361
random_delay: Sequence[int],
362362
callbacks: Iterable[Callable]):
363-
# Test if only one argument is passed instead of a tuple.
363+
"""This method offers a general purpose API to display text
364+
regardless of whether it is written word by word or character by
365+
character.
366+
"""
364367
text_attr = to_tuple(text_attr)
365368

366369
colors_pair = curses.color_pair(colors_pair_nb)
@@ -400,5 +403,3 @@ def _one_by_one(self,
400403

401404
self._display_end_indicator(win)
402405
self.get_input(win)
403-
404-

visualdialog/error.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# error.py
22
# 2020 Timéo Arnouts <[email protected]>
33

4-
__all__ = ["PanicError"]
4+
__all__ = ["PanicError", "ValueNotInBound"]
55

66
from typing import Callable
77

88
from .type import CursesKey
99

1010

1111
class ValueNotInBound(ValueError):
12-
"""Exception thrown when when incorrect values are passed as
13-
parameters to the ``BaseTextBox`` constructor.
12+
"""Exception thrown when incorrect values are passed as parameters
13+
to the ``BaseTextBox`` constructor.
1414
"""
15-
...
15+
pass
1616

1717

1818
class PanicError(KeyboardInterrupt):

visualdialog/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def chunked(seq: Sequence,
2424
def to_tuple(obj: Union[object, Sequence]) -> Union[Tuple, Sequence]:
2525
"""Check if the given object is a sequence, if so returns it,
2626
otherwise returns it as a tuple.
27+
28+
This function is mainly used to work with sequences even if only one
29+
argument is passed.
2730
"""
2831
if isinstance(obj, Sequence):
2932
return obj

0 commit comments

Comments
 (0)