Skip to content

Commit 0058a8f

Browse files
committed
DialogBox.char_by_char and word_by_word nows return given text argument, improve doc.
1 parent 5d63825 commit 0058a8f

File tree

11 files changed

+149
-72
lines changed

11 files changed

+149
-72
lines changed

doc/source/conf.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@
5555
"display_version": True
5656
}
5757

58-
html_logo = "_static/visual-dialog.png"
59-
60-
latex_logo = "_static/visual-dialog.png"
61-
6258
latex_elements = {
6359
"pointsize": "12pt"
6460
}

doc/source/faq.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ You can use this behavior to perform multiple tasks while text scrolling.
1818
I am not satisfied with the behavior of DialogBox, how can I change it?
1919
-----------------------------------------------------------------------
2020

21-
You can create your own derived class by inheriting from ``BaseTextBox``.
22-
Additionally, you can override the methods of ``DialogBox``.
21+
You can create your own derived class by inheriting from :class:`BaseTextBox`.
22+
Additionally, you can override the methods of :class:`DialogBox`.

doc/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Welcome to Visual-dialog's documentation
2020
- Text coloring and formatting.
2121
- Hackable and configurable.
2222

23-
.. IMPORTANT::
23+
.. important::
2424
I recommend that you have some knowledge of Python ``curses`` module in order to use the library to its full potential.
2525

2626
Here several links to learn ``curses``:

doc/source/installation.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ Using PIP
66

77
Install **Visual-dialog** using ``pip`` (The lib is not yet available on **pypi**):
88

9-
.. code-block::
9+
.. code-block:: text
1010
1111
pip install git+git://github.com/Tim-ats-d/Visual-dialog
1212
1313
or update library to the latest version:
1414

15-
.. code-block::
15+
.. code-block:: text
1616
1717
pip install git+git://github.com/Tim-ats-d/Visual-dialog --upgrade
18+
19+
From source
20+
-----------
21+
22+
.. code-block:: text
23+
24+
git clone https://github.com/Tim-ats-d/Visual-dialog.git
25+
cd Visual-dialog
26+
pip install .
27+

doc/source/requirements.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Curses
1212
**Visual-dialog** works with ``curses`` Python module.
1313
It is available in the standard **Python** library on **UNIX** but it doesn't work out-of-the-box on **Windows**.
1414

15-
To install ``curses`` on **Windows**, you need ``windows-curses`` module:
15+
To install ``curses`` on **Windows**, you need `windows-curses <https://pypi.org/project/windows-curses/>`_ module:
1616

17-
.. code-block::
17+
.. code-block:: text
1818
1919
pip install curses-windows
2020
@@ -24,6 +24,6 @@ To build the documentation
2424
- `Sphinx <https://www.sphinx-doc.org/en/master/usage/installation.html>`_ to generate the documentation of library.
2525
- `sphinx-rtd-theme <https://pypi.org/project/sphinx-rtd-theme/>`_ used as documentation theme.
2626

27-
.. code-block::
27+
.. code-block:: text
2828
2929
pip install sphinx sphinx_rtd_theme

doc/source/utils.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Utils
22
=====
33

4-
.. NOTE::
4+
.. note::
55
A sub-module of **Visual-dialog** (``visualdialog.utils``) contains
66
functions and classes used by the private API. The context manager
77
``TextAttr`` is used by the library to manage in a more
@@ -16,5 +16,10 @@ Utils
1616
visualdialog.function(args)
1717

1818

19-
.. automodule:: visualdialog.utils
20-
:members:
19+
.. autoclass:: visualdialog.utils.TextAttr
20+
21+
.. automethod:: __init__
22+
23+
.. automethod:: __enter__
24+
25+
.. automethod:: __exit__

doc/source/visualdialog.rst

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
Text boxes
22
==========
33

4-
.. IMPORTANT::
5-
**Visual-dialog** contains two **modules**: ``visualdialog.box`` and ``visualdialog.dialog``.
6-
These two **modules** are both imported when you import ``visualdialog``.
4+
.. important::
5+
This library provides two classes but only :class:`DialogBox` is destined to be instantiated.
76

8-
Two **classes** are defined in these modules but only ``DialogBox`` is destined to be instantiated.
9-
10-
TextBox
11-
-------
7+
BaseTextBox
8+
-----------
129

1310
.. autoclass:: visualdialog.box.BaseTextBox
14-
:members:
15-
:undoc-members:
11+
12+
.. automethod:: __init__
13+
14+
The following variables are instance attributes:
15+
16+
.. autoattribute:: confirm_keys
17+
18+
The following methods are public:
19+
20+
.. autoattribute:: position
21+
22+
.. autoattribute:: dimensions
23+
24+
.. automethod:: framing_box
25+
26+
.. automethod:: get_input
1627

1728
DialogBox
1829
---------
1930

2031
.. autoclass:: visualdialog.dialog.DialogBox
21-
:undoc-members:
22-
:members:
32+
33+
.. automethod:: __init__
34+
35+
The following methods are public:
36+
37+
.. automethod:: __repr__
38+
39+
.. automethod:: __enter__
40+
41+
.. automethod:: __exit__
42+
43+
.. automethod:: char_by_char
44+
45+
.. automethod:: word_by_word

visualdialog/box.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import curses
77
import curses.textpad
8+
import functools
89
from typing import Callable, List, Literal, Sequence, Tuple, Union
910

1011
from .error import PanicError, ValueNotInBound
@@ -14,7 +15,7 @@
1415

1516
def value_checker(initializer: Callable) -> Callable:
1617
"""A decorator which ensures that correct values are passed to
17-
``BaseTextBox`` initializer to avoid unexpected behavior.
18+
:class:`BaseTextBox` initializer to avoid unexpected behavior.
1819
"""
1920
def __init__(self,
2021
pos_x, pos_y,
@@ -43,7 +44,7 @@ def __init__(self,
4344
class BaseTextBox:
4445
"""This class provides attributs and methods to manage a text box.
4546
46-
.. NOTE::
47+
.. note::
4748
This class provides a general API for text boxes, it is not
4849
intended to be instantiated.
4950
@@ -97,6 +98,7 @@ def __init__(
9798
CursesTextAttributes] = curses.A_BOLD,
9899
downtime_chars: Sequence[str] = (",", ".", ":", ";", "!", "?"),
99100
downtime_chars_delay: int = 600):
101+
"""Initializes instance of :class:`BaseTextBox`."""
100102
self.pos_x, self.pos_y = pos_x, pos_y
101103
self.height, self.width = height - 1, width - 1
102104

@@ -118,34 +120,46 @@ def __init__(
118120
self.downtime_chars = downtime_chars
119121
self.downtime_chars_delay = downtime_chars_delay
120122

121-
#: Keystroke acquisition curses method for BaseTextBox.get_input.
123+
#: Keystroke acquisition ``curses`` method for
124+
#: :method:`BaseTextBox.get_input`.
122125
self.key_detection: Literal["getkey",
123126
"getch",
124127
"get_wch"] = "getkey"
125128

126129
#: List of accepted key to skip dialog.
127-
#: This defaults to a list contains " ".
130+
#: This defaults `[" "]`.
128131
self.confirm_keys: List[CursesKey] = [" "]
129-
#: List of accepted key to raise PanicError.
130-
#: This defaults to an empty list.
132+
131133
self.panic_keys: List[CursesKey] = []
134+
#: List of accepted key to raise :exception:PanicError.
135+
#: This defaults to an empty list.
132136

133137
@property
134138
def position(self) -> Tuple[int, int]:
135-
"""Return a tuple contains x;y position of ``TextBox``.
139+
<<<<<<< HEAD
140+
"""Return a tuple contains x;y position of :class:`BaseTextBox`.
141+
=======
142+
"""A property that returns a tuple contains x;y position of
143+
:class:`BaseTextBox`.
144+
>>>>>>> 817377f (DialogBox.char_by_char and word_by_word nows return given text argument, start to improve doc.)
136145

137146
The position represents the x;y coordinates of the top left
138147
corner of text box.
139148

140-
:returns: x;y position of ``TextBox``.
149+
:returns: x;y position of :class:`BaseTextBox`.
141150
"""
142151
return self.pos_x, self.pos_y
143152
144153
@property
145154
def dimensions(self) -> Tuple[int, int]:
146-
"""Return a tuple contains dimensions of ``TextBox``.
147-
148-
:returns: Height and width of ``TextBox``.
155+
<<<<<<< HEAD
156+
"""Return a tuple contains dimensions of :class:`BaseTextBox`.
157+
=======
158+
"""A property that return a tuple contains dimensions of
159+
:class:`BaseTextBox`.
160+
>>>>>>> 817377f (DialogBox.char_by_char and word_by_word nows return given text argument, start to improve doc.)
161+
162+
:returns: Height and width of :class:`BaseTextBox`.
149163
"""
150164
return (self.height + 1,
151165
self.width + 1 + self.title_offsetting_y)
@@ -181,35 +195,23 @@ def framing_box(self, win: CursesWindow):
181195
curses.textpad.rectangle(win,
182196
self.pos_y + self.title_offsetting_y,
183197
self.pos_x,
184-
self.pos_y
185-
+ self.title_offsetting_y
186-
+ self.width,
198+
(self.pos_y
199+
+ self.title_offsetting_y
200+
+ self.width),
187201
self.pos_x + self.height)
188202

189203
def get_input(self, win: CursesWindow):
190204
"""Block execution as long as a key contained in
191205
``self.confirm_keys`` is not detected.
192206
193207
The method of key detection depends on the variable
194-
``self.key_detection_mode``. ``"key"`` will acquire the key as
195-
a character and ``"code"`` as a key code. This is default to
196-
``"key"``.
208+
``self.key_detection_mode``.
197209
198210
:param win: ``curses`` window object on which the method will
199211
have effect.
200212
201213
:raises PanicError: If a key contained in ``self.panic_keys`` is
202214
pressed.
203-
204-
.. NOTE::
205-
- This method uses ``window.getch`` method from ``curses``
206-
module. Please refer to `curses documentation
207-
<https://docs.python.org/3/library/curses.html?#curses.window.getch>`_
208-
for more informations.
209-
- This method uses ``window.getkey`` method from ``curses``
210-
module. Please refer to `curses documentation
211-
<https://docs.python.org/3/library/curses.html?#curses.window.getkey>`_
212-
for more informations.
213215
"""
214216
curses.flushinp()
215217

0 commit comments

Comments
 (0)