Skip to content

Commit 09b01de

Browse files
authored
Visual-dialog 0.9
2 parents 3fd2355 + cc44069 commit 09b01de

25 files changed

+666
-687
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ This tree does not contain a description of all the files in the repository, onl
4949
│ ├── source/
5050
│ │ Contains images used in documentation.
5151
│ │ │
52-
│ │ ├── images/
53-
│ │ │ Contains images used in documentation.
54-
│ │ │
5552
│ │ ├── conf.py
5653
│ │ │ Sphinx's configuration file.
5754
│ │ │
@@ -79,10 +76,16 @@ This tree does not contain a description of all the files in the repository, onl
7976
│ ├── __init__.py
8077
│ │
8178
│ ├── box.py
82-
│ │ Contains the parent class TextBox which serves as a basis for the implementation of the other classes.
79+
│ │ Contains the parent class BaseTextBox which serves as a basis for the implementation of the other classes.
8380
│ │
8481
│ ├── dialog.py
85-
│ │ Contains the DialogBox class, which is the main class of the library.
82+
│ │ Contains DialogBox class, which is the main class provides by the library.
83+
│ │
84+
│ ├── error.py
85+
│ │ Contains exceptions raised by the library.
86+
│ │
87+
│ ├── type.py
88+
│ │ Contains custom type hinting used by the library.
8689
│ │
8790
│ └── utils.py
8891
│ Contains the classes and functions used but not related to the libriarie.

LICENSE

Lines changed: 161 additions & 335 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pip install sphinx sphinx_rtd_theme
6969

7070
### Hello world with **Visual-dialog**
7171

72-
```python3
72+
```py3
7373
import curses
7474

7575
from visualdialog import DialogBox
@@ -84,8 +84,8 @@ def main(win):
8484
textbox = DialogBox(x, y,
8585
height, width,
8686
title="Demo")
87-
textbox.char_by_char(win,
88-
"Hello world")
87+
textbox.char_by_char("Hello world",
88+
win)
8989

9090

9191
curses.wrapper(main)
@@ -126,8 +126,7 @@ You can also help by reporting **bugs**.
126126

127127
## License
128128

129-
Distributed under the **GPL-2.0 License**. See [license](LICENSE) for more information.
130-
129+
Distributed under the **LGPL-3.0 License**. See [license](LICENSE) for more information.
131130

132131
## Acknowledgements
133132

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/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/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/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: 2 additions & 2 deletions
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``:
@@ -32,7 +32,7 @@ Getting started
3232
---------------
3333

3434
- **First steps:**
35-
- **Examples:** Many examples are available in the `repository <https://github.com/Tim-ats-d/Visual-dialog/issues>`_.
35+
- **Examples:** Many examples are available in the `repository <https://github.com/Tim-ats-d/Visual-dialog/tree/main/examples>`_.
3636

3737
Getting help
3838
------------

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: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
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+
**Visual-dialog** 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 methods are public:
15+
16+
.. autoproperty:: position
17+
18+
.. autoproperty:: dimensions
19+
20+
.. automethod:: framing_box
21+
22+
.. automethod:: get_input
1623

1724
DialogBox
1825
---------
1926

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

examples/confrontation.py

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,40 @@
22
# A concrete example exploiting the possibilities of Visual-dialog.
33

44
import curses
5+
from functools import partial
56

67
from visualdialog import DialogBox
78

89

9-
PASS_KEYS = (" ", "\n")
10-
HEIGHT, WIDTH = 35, 6
10+
pass_keys = (" ", "\n")
11+
height, width = 35, 5
1112

1213

1314
# It is preferable to create its own class derived from DialogBox for
14-
# complex applications.
15-
class CustomDialogBox(DialogBox):
16-
17-
def __init__(self,
18-
pos_x: int,
19-
pos_y: int,
20-
title: str,
21-
title_colors_pair_nb: int,
22-
**kwargs):
23-
super().__init__(pos_x=pos_x,
24-
pos_y=pos_y,
25-
height=HEIGHT,
26-
width=WIDTH,
27-
title=title,
28-
title_colors_pair_nb=title_colors_pair_nb,
29-
**kwargs)
30-
31-
# Definition of accepted key codes to pass a dialog.
32-
self.confirm_keys = PASS_KEYS
15+
# complex applications (or an instance factory like here).
16+
def box_factory(win,
17+
x: int,
18+
y: int,
19+
title: int,
20+
title_colors_pair_nb: int,
21+
**kwargs) -> DialogBox:
22+
box = DialogBox(x, y,
23+
height, width,
24+
title, title_colors_pair_nb,
25+
global_win=win,
26+
# Use a default window to display text.
27+
# Setting this parameter allows to avoid passing `win`
28+
# parameter to `char_by_char` and `word_by_word` methods.
29+
# Useful when dealing with many `DialogBox` methods calls.
30+
**kwargs)
31+
32+
# Definition of accepted key codes to pass a dialog.
33+
box.confirm_keys = pass_keys
34+
# Definition of a partial objet to reduce verbosity and accelerate
35+
# the time it takes to write the text on the screen.
36+
box.char_by_char = partial(box.char_by_char, delay=30)
37+
38+
return box
3339

3440

3541
def main(win):
@@ -44,46 +50,44 @@ def main(win):
4450
max_y, max_x = win.getmaxyx() # Get height and width of the window.
4551

4652
left_x = 2 # Left alignment.
47-
right_x = max_x - HEIGHT - 4 # Calculation of right alignment.
48-
center_x = max_x//2 - HEIGHT//2 # Calculation of center alignment.
49-
bottom_y = max_y - WIDTH - 4 # Calculation of bottom alignment.
50-
51-
phoenix_wright = CustomDialogBox(left_x, bottom_y,
52-
"Phoenix", # Title of dialog box.
53-
1) # Color pair used to colored title.
54-
55-
april_may = CustomDialogBox(center_x, bottom_y,
56-
"April",
57-
2)
58-
59-
miles_edgeworth = CustomDialogBox(right_x, bottom_y,
60-
"Edgeworth",
61-
3)
62-
63-
phoenix_wright.char_by_char(win,
64-
"This testimony is a pure invention !",
53+
right_x = max_x - height - 4 # Calculation of right alignment.
54+
center_x = max_x//2 - height//2 # Calculation of center alignment.
55+
bottom_y = max_y - width - 4 # Calculation of bottom alignment.
56+
57+
phoenix_wright = box_factory(win,
58+
left_x, bottom_y,
59+
"Phoenix", # Title of dialog box.
60+
1) # Color pair used to colored title.
61+
62+
april_may = box_factory(win,
63+
center_x, bottom_y,
64+
"April",
65+
2)
66+
67+
miles_edgeworth = box_factory(win,
68+
right_x, bottom_y,
69+
"Edgeworth",
70+
3)
71+
72+
phoenix_wright.char_by_char("This testimony is a pure invention !",
6573
delay=30)
6674
# Set delay between writting each characters to 30 milliseconds
6775

68-
phoenix_wright.char_by_char(win,
69-
"You're lying April May !",
76+
phoenix_wright.char_by_char("You're lying April May !",
7077
flash_screen=True, # A short luminous glow will be displayed before writing the text.
7178
delay=30,
7279
text_attr=curses.A_BOLD)
7380

74-
april_may.char_by_char(win,
75-
"Arghh !",
81+
april_may.char_by_char("Arghh !",
7682
delay=30,
7783
text_attr=curses.A_ITALIC)
7884

79-
miles_edgeworth.char_by_char(win,
80-
"OBJECTION !",
85+
miles_edgeworth.char_by_char("OBJECTION !",
8186
flash_screen=True,
8287
delay=30,
8388
text_attr=curses.A_BOLD)
8489

85-
miles_edgeworth.char_by_char(win,
86-
"These accusations are irrelevant !",
90+
miles_edgeworth.char_by_char("These accusations are irrelevant !",
8791
delay=30)
8892

8993

examples/context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def main(win):
2121
with DialogBox(1, 1,
2222
30, 6) as db:
2323
db.confirm_keys.append("\n") # To match enter key.
24-
db.char_by_char(win,
25-
reply)
24+
db.char_by_char(reply, win)
2625

2726

2827
# Execution of main function.

examples/monologue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def main(win):
3434
# Iterate on each sentence contained in replys.
3535
for reply in replys:
3636
textbox.char_by_char(
37-
win,
3837
reply,
38+
win,
3939
2, # Display text colored with color pair 2.
4040
delay=40) # Set delay between writting each characters to 40 milliseconds.
4141

0 commit comments

Comments
 (0)