Skip to content

Commit 900b35d

Browse files
committed
Improve doc quality and add error.rst.
1 parent 133965b commit 900b35d

File tree

6 files changed

+50
-99
lines changed

6 files changed

+50
-99
lines changed

doc/source/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ API documentation
55
:maxdepth: 2
66

77
visualdialog.rst
8+
error.rst
89
utils.rst

doc/source/error.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Exceptions
2+
==========
3+
4+
**Visual-dialog** defined several exceptions raised by library.
5+
6+
.. autoexception:: visualdialog.error.ValueNotInBound
7+
8+
.. autoexception:: visualdialog.error.PanicError

doc/source/visualdialog.rst

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Text boxes
22
==========
33

44
.. important::
5-
This library provides two classes but only :class:`DialogBox` is destined to be instantiated.
5+
**Visual-dialog** provides two classes but only :class:`DialogBox` is destined to be instantiated.
66

77
BaseTextBox
88
-----------
@@ -11,15 +11,11 @@ BaseTextBox
1111

1212
.. automethod:: __init__
1313

14-
The following variables are instance attributes:
15-
16-
.. autoattribute:: confirm_keys
17-
1814
The following methods are public:
1915

20-
.. py:property:: position
16+
.. autoproperty:: position
2117

22-
.. py:property:: dimensions
18+
.. autoproperty:: dimensions
2319

2420
.. automethod:: framing_box
2521

visualdialog/box.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import curses
77
import curses.textpad
88
import functools
9-
from typing import Callable, List, Literal, Sequence, Tuple, Union
9+
from typing import Callable, List, Literal, Optional, Sequence, Tuple, Union
1010

1111
from .error import PanicError, ValueNotInBound
1212
from .type import CursesKey, CursesTextAttribute, CursesTextAttributes, CursesWindow
@@ -68,7 +68,7 @@ class BaseTextBox:
6868
:param title_colors_pair_nb:
6969
Number of the curses color pair that will be used to color the
7070
title. Zero corresponding to the pair of white color on black
71-
background initialized by ``curses``). This defaults to ``0``.
71+
background initialized by ``curses``. This defaults to ``0``.
7272
7373
:param title_text_attr:
7474
Dialog box title text attributes. It should be a single curses
@@ -85,7 +85,15 @@ class BaseTextBox:
8585
in ``downtime_chars``.
8686
This defaults to ``600``.
8787
88-
:ivar var2: initial value: par2
88+
:ivar key_detection: initial value: ["getkey", "getch", "get_wch"]:
89+
Keystroke acquisition ``curses`` method for
90+
:meth:`BaseTextBox.get_input`.
91+
92+
:ivar confirm_keys: initial value: [" "]:
93+
List of accepted key to skip dialog.
94+
95+
:ivar panic_keys: initial value: []:
96+
List of accepted key to raise :exc:`PanicError`.
8997
"""
9098
@value_checker
9199
def __init__(
@@ -94,7 +102,7 @@ def __init__(
94102
pos_y: int,
95103
height: int,
96104
width: int,
97-
title: str = "",
105+
title: Optional[str] = None,
98106
title_colors_pair_nb: int = 0,
99107
title_text_attr: Union[CursesTextAttribute,
100108
CursesTextAttributes] = curses.A_BOLD,
@@ -122,19 +130,9 @@ def __init__(
122130
self.downtime_chars = downtime_chars
123131
self.downtime_chars_delay = downtime_chars_delay
124132

125-
#: Keystroke acquisition ``curses`` method for
126-
#: :method:`BaseTextBox.get_input`.
127-
self.key_detection: Literal["getkey",
128-
"getch",
129-
"get_wch"] = "getkey"
130-
131-
#: List of accepted key to skip dialog.
132-
#: This defaults `[" "]`.
133+
self.key_detection: Literal["getkey", "getch", "get_wch"] = "getkey"
133134
self.confirm_keys: List[CursesKey] = [" "]
134-
135135
self.panic_keys: List[CursesKey] = []
136-
#: List of accepted key to raise :exception:PanicError.
137-
#: This defaults to an empty list.
138136

139137
@property
140138
def position(self) -> Tuple[int, int]:
@@ -199,7 +197,7 @@ def get_input(self, win: CursesWindow):
199197
``self.confirm_keys`` is not detected.
200198
201199
The method of key detection depends on the variable
202-
``self.key_detection_mode``.
200+
``self.key_detection``.
203201
204202
:param win: ``curses`` window object on which the method will
205203
have effect.

visualdialog/dialog.py

Lines changed: 15 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,7 @@ class DialogBox(BaseTextBox):
2525
can lead to an overflow of the dialog box frame. This defaults
2626
to ``"►"``.
2727
28-
<<<<<<< HEAD
29-
:key kwargs: Keyword arguments correspond to the instance attributes
30-
of :class:`BaseTextBox`.
31-
32-
.. NOTE::
33-
This class inherits of :class:`BaseTextBox`.
34-
=======
3528
:param args: Constructor arguments of :class:`BaseTextBox`.
36-
>>>>>>> 817377f (DialogBox.char_by_char and word_by_word nows return given text argument, start to improve doc.)
3729
3830
:param kwargs: Constructor keyword arguments of
3931
:class:`BaseTextBox`.
@@ -82,10 +74,7 @@ def __enter__(self) -> "DialogBox":
8274

8375
def __exit__(self, type, value, traceback):
8476
"""Return None."""
85-
<<<<<<< HEAD
8677
return None
87-
=======
88-
>>>>>>> 817377f (DialogBox.char_by_char and word_by_word nows return given text argument, start to improve doc.)
8978

9079
def char_by_char(self,
9180
win: CursesWindow,
@@ -143,42 +132,20 @@ def char_by_char(self,
143132
number generated in ``random_delay`` interval. This defaults
144133
to ``(0, 0)``.
145134
146-
:param callback: Iterable of callable called one by one after
135+
:param callbacks: Iterable of callable called one by one after
147136
writing a character and the delay time has elapsed. This
148137
defaults to an empty tuple.
149138
The arguments passed to the given callables are:
150-
- the current instance (``self``).
151-
- the character previously written.
152-
- the index of the character previously written in the
153-
word being written.
154-
155-
<<<<<<< HEAD
156-
:returns: ``text`` argument passed in parameter without any
157-
treatment.
158-
159-
.. NOTE::
160-
Method flow:
161-
- Calling ``framing_box`` method.
162-
- Flash screen depending ``flash_screen`` parameter.
163-
- Cutting text into line to stay within the dialog box
164-
frame.
165-
- Writing paragraph by paragraph.
166-
- Writing each line of the current paragraph.
167-
- Writing each word of line.
168-
- Writing each character of word and execute callbacks
169-
between.
170-
- Waits until a key contained in the class attribute
171-
``confirm_keys`` was pressed before writing the
172-
following paragraph.
173-
- Complete cleaning ``win``.
174-
175-
.. WARNING::
176-
=======
139+
140+
* the current instance (``self``).
141+
* the character previously written.
142+
* the index of the character previously written in the
143+
word being written.
144+
177145
.. note::
178146
See implementation for more informations on method flow.
179147
180148
.. note::
181-
>>>>>>> 817377f (DialogBox.char_by_char and word_by_word nows return given text argument, start to improve doc.)
182149
If the volume of text displayed is too large to be contained
183150
in a dialog box, text will be automatically cut into
184151
paragraphs using ``textwrap.wrap`` function. See
@@ -260,38 +227,18 @@ def word_by_word(self,
260227
generated in ``random_delay`` interval. This defaults to
261228
``(0, 0)``.
262229
263-
:param callback: Iterable of callable called one by one after
230+
:param callbacks: Iterable of callable called one by one after
264231
writing a word and the delay time has elapsed. This defaults
265232
to an empty tuple.
266233
The arguments passed to the given callables are:
267-
- the current instance (``self``).
268-
- the word previously written.
269-
270-
<<<<<<< HEAD
271-
:returns: ``text`` argument passed in parameter without any
272-
treatment.
273-
274-
.. NOTE::
275-
Method flow:
276-
- Calling ``framing_box`` method.
277-
- Flash screen depending ``flash_screen`` parameter.
278-
- Cutting text into line to stay within the dialog box
279-
frame.
280-
- Writing paragraph by paragraph.
281-
- Writing each line of the current paragraph.
282-
- Writing each word of line and execute callbacks between.
283-
- Waits until a key contained in the class attribute
284-
``confirm_keys`` was pressed before writing the
285-
following paragraph.
286-
- Complete cleaning ``win``.
287-
288-
.. WARNING::
289-
=======
234+
235+
* the current instance (``self``).
236+
* the word previously written.
237+
290238
.. note::
291239
See implementation for more informations on method flow.
292240
293241
.. note::
294-
>>>>>>> 817377f (DialogBox.char_by_char and word_by_word nows return given text argument, start to improve doc.)
295242
If the volume of text displayed is too large to be contained
296243
in a dialog box, text will be automatically cut into
297244
paragraphs using ``textwrap.wrap`` function. See
@@ -327,13 +274,13 @@ def _display_end_indicator(self,
327274
curses.A_BOLD,
328275
curses.A_BLINK)):
329276
"""Displays an end indicator in the lower right corner of
330-
textbox.
277+
text box.
331278
332279
:param win: ``curses`` window object on which the method
333280
will have effect.
334281
335-
:param text_attr: Text attributes of
336-
``end_indicator`` method. This defaults to
282+
:param text_attr: Text attributes used to display
283+
``end_indicator``. This defaults to
337284
``(curses.A_BOLD, curses.A_BLINK)``.
338285
"""
339286
if self.end_indicator_char:

visualdialog/error.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@
33

44
__all__ = ["PanicError", "ValueNotInBound"]
55

6-
from typing import Callable
7-
86
from .type import CursesKey
97

108

119
class ValueNotInBound(ValueError):
12-
"""Exception thrown when incorrect values are passed as parameters
13-
to the :class:`BaseTextBox` constructor.
10+
"""Base ``ValueError``.
11+
12+
Exception thrown when incorrect values are passed as parameters
13+
to the :class:`visualdialog.box.BaseTextBox` constructor.
1414
"""
1515
pass
1616

1717

1818
class PanicError(KeyboardInterrupt):
19-
"""Exception thrown when a key contained in
20-
:class:`BaseTextBox.panic_keys` is pressed.
19+
"""Base ``KeyboardInterrupt``.
20+
21+
Exception thrown when a key contained in
22+
:attr:`visualdialog.box.BaseTextBox.panic_keys` is pressed.
2123
2224
:param key: Key pressed that caused the exception to be thrown.
2325
"""
24-
def __init__(self,
25-
key: CursesKey):
26+
def __init__(self, key: CursesKey):
2627
self.key = key
2728

2829
def __str__(self) -> str:

0 commit comments

Comments
 (0)