Skip to content

Commit 6bdb3b7

Browse files
authored
VIsual-dialog 0.8
2 parents d6a8027 + 0a4ba07 commit 6bdb3b7

23 files changed

+627
-503
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Please push on the `dev` branch, any pull request on the `main` branch will be r
1717

1818
When you make a pull request make sure to:
1919

20-
* Test your code with `Python3.7` to be sure not to break compatability.
20+
* Test your code with `Python 3.8` to be sure not to break compatability.
2121
* Format your code according [PEP 8](https://www.python.org/dev/peps/pep-0008/). [PEP8 Check](https://github.com/quentinguidee/actions-pep8) will ensure that your code is correctly formatted .
2222
* Document your code with [reStructuredText](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html) if you add new functionality.
2323

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,11 @@
22
# Visual-dialog
33

44
<p align="center">
5-
<a href="#features">Features</a> •
6-
<a href="#installation">Installation</a> •
7-
<a href="#requirements">Requirements</a> •
8-
<a href="#documentation">Documentation</a> •
9-
<a href="#quick-start">Quick start</a> •
10-
<a href="#contributing">Contributing</a> •
11-
<a href="#license">License</a>
12-
</p>
13-
14-
<p align="center">
15-
<img width="400" src="https://user-images.githubusercontent.com/59396366/100594532-188c6900-32fa-11eb-8372-4796f53b122f.png" alt="Visual-dialog">
5+
<img width="300" src="https://user-images.githubusercontent.com/59396366/113866239-5f5d0480-97ad-11eb-879f-fa7d4098b689.png" alt="Visual-dialog">
166
<br>
17-
A library to make easier dialog box in terminal.
7+
A library to make easier dialog box in a terminal.
188
</p>
199

20-
This library is still under development. API can change.
21-
2210
## Features
2311

2412
📃 Automatic text scrolling.
@@ -27,6 +15,8 @@ This library is still under development. API can change.
2715

2816
⚙️ Hackable and configurable.
2917

18+
⚠️ This library is still under development. API can change.
19+
3020
## Installation
3121

3222
### Using pip
@@ -52,17 +42,29 @@ pip install .
5242

5343
## Requirements
5444

45+
### Python version
46+
47+
* [**Python 3.8**](https://www.python.org/downloads/) or more.
48+
5549
### Curses
5650

5751
**Visual-dialog** works with `curses` Python module. It is available in the standard **Python** library on **UNIX** but it doesn’t work out-of-the-box on **Windows**.
5852

59-
See [this explanations](https://www.devdungeon.com/content/curses-windows-python) to install `curses` on **Windows** (untested).
53+
To install `curses` on **Windows**, you need `windows-curses` module:
54+
55+
```sh
56+
pip install curses-windows
57+
```
58+
59+
### To build the documentation
6060

61-
### Other requirements
62-
* [**Python 3.7**](https://www.python.org/downloads/) or more.
6361
* [**Sphinx**](https://www.sphinx-doc.org/en/master/usage/installation.html) to generate the documentation of library.
6462
* [**sphinx-rtd-theme**](https://pypi.org/project/sphinx-rtd-theme/) used as documentation theme.
6563

64+
```sh
65+
pip install sphinx sphinx_rtd_theme
66+
```
67+
6668
## Quick-start
6769

6870
### Hello world with **Visual-dialog**
@@ -73,16 +75,16 @@ import curses
7375
from visualdialog import DialogBox
7476

7577

76-
x, y = (0, 0)
77-
height, width = (35, 6)
78+
x, y = 0, 0
79+
height, width = 35, 6
7880

79-
def main(stdscr):
81+
def main(win):
8082
curses.curs_set(False)
8183

8284
textbox = DialogBox(x, y,
8385
height, width,
8486
title="Demo")
85-
textbox.char_by_char(stdscr,
87+
textbox.char_by_char(win,
8688
"Hello world")
8789

8890

@@ -124,7 +126,7 @@ You can also help by reporting **bugs**.
124126

125127
## License
126128

127-
Distributed under the **GPL-2.0 License** . See [license](LICENSE) for more information.
129+
Distributed under the **GPL-2.0 License**. See [license](LICENSE) for more information.
128130

129131

130132
## Acknowledgements
4.58 KB
Loading

doc/source/faq.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ See the `dedicated example <https://github.com/Tim-ats-d/Visual-dialog/tree/main
1111
How can I continue to manage screen display while a DialogBox is writing text on the screen?
1212
--------------------------------------------------------------------------------------------
1313

14-
``char_by_char`` and ``word_by_word`` methods of ``DialogBox`` class accept a callback in parameter.
15-
You can also pass arguments to this callback via ``cargs`` parameter.
14+
``char_by_char`` and ``word_by_word`` methods of ``DialogBox`` class accept a ``callbacks`` in parameter.
15+
It must be a function iterable.
16+
You can use this behavior to perform multiple tasks while text scrolling.
1617

17-
The past callback is executed after downtime delay between character or word display.
18-
You can use this behavior to perform multiple tasks while ``DialogBox`` scrolling.
19-
20-
I am not satisfied with the behavior of DialogBox, how can I change it?
18+
I am not satisfied with the behavior of DialogBox, how can I change it?
2119
-----------------------------------------------------------------------
2220

2321
You can create your own derived class by inheriting from ``BaseTextBox``.

doc/source/index.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ Welcome to Visual-dialog's documentation
1111

1212
.. image:: _static/visual-dialog.png
1313
:align: center
14+
:width: 300
15+
:alt: Visual-dialog
1416

1517
**Features:**
1618

17-
- Automatic text scrolling.
18-
- Text coloring and formatting.
19-
- Hackable and configurable.
19+
- Automatic text scrolling.
20+
- Text coloring and formatting.
21+
- Hackable and configurable.
2022

2123
.. IMPORTANT::
2224
I recommend that you have some knowledge of Python ``curses`` module in order to use the library to its full potential.

doc/source/installation.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ Installation
44
Using PIP
55
---------
66

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

9-
python3 -m pip install git+git://github.com/Tim-ats-d/Visual-dialog
9+
.. code-block::
1010
11-
or update library to the latest version::
11+
pip install git+git://github.com/Tim-ats-d/Visual-dialog
1212
13-
python3 -m pip install git+git://github.com/Tim-ats-d/Visual-dialog --upgrade
13+
or update library to the latest version:
14+
15+
.. code-block::
16+
17+
pip install git+git://github.com/Tim-ats-d/Visual-dialog --upgrade

doc/source/requirements.rst

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
Requirements
22
============
33

4+
Python version
5+
--------------
6+
7+
- `Python 3.8 or more <https://www.python.org/downloads/>`_.
8+
49
Curses
510
------
611

712
**Visual-dialog** works with ``curses`` Python module.
813
It is available in the standard **Python** library on **UNIX** but it doesn't work out-of-the-box on **Windows**.
914

10-
See this explanations to install ``curses`` on **Windows** (untested).
15+
To install ``curses`` on **Windows**, you need ``windows-curses`` module:
16+
17+
.. code-block::
1118
12-
- https://www.devdungeon.com/content/curses-windows-python
19+
pip install curses-windows
1320
14-
Other requirements
15-
------------------
21+
To build the documentation
22+
--------------------------
1623

17-
- **Python 3.7** or more.
1824
- `Sphinx <https://www.sphinx-doc.org/en/master/usage/installation.html>`_ to generate the documentation of library.
1925
- `sphinx-rtd-theme <https://pypi.org/project/sphinx-rtd-theme/>`_ used as documentation theme.
26+
27+
.. code-block::
28+
29+
pip install sphinx sphinx_rtd_theme

doc/source/utils.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Utils
44
.. NOTE::
55
A sub-module of **Visual-dialog** (``visualdialog.utils``) contains
66
functions and classes used by the private API. The context manager
7-
``TextAttributes`` is used by the library to manage in a more
7+
``TextAttr`` is used by the library to manage in a more
88
pythonic way the textual ``curses`` attributes curses but you can
99
also use it in your programs.
1010

examples/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
This directory contains several examples of use of **Visual-dialog**.
44
They are classified below by order of difficulty (approximately).
55

6-
## [Monologue](monologue.py)
6+
## [`Monologue`](monologue.py)
77

88
A complete concrete example of how to use **Visual-dialog**.
99

10-
## [Word](word.py)
10+
## [`Word`](word.py)
1111

1212
An example of using ``word_by_word`` method from text boxes.
1313

14-
## [Text attributes](text_attributes.py)
14+
## [`Text attributes`](text_attributes.py)
1515

16-
An example showing the possibilities of text formatting in a text box.
16+
An example showing the possibilities of **text formatting** in a text box.
1717

18-
## [Context](contex.py)
18+
## [`Panic`](panic.py)
19+
20+
An example of the use of **panic keys**.
21+
22+
## [`Context`](context.py)
1923

2024
An example of how to use a text box as a **context manager**.
2125

22-
## [Confrontation](confrontation.py)
26+
## [`Confrontation`](confrontation.py)
2327

2428
A concrete example exploiting the possibilities of library.

examples/confrontation.py

Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,85 @@
66
from visualdialog import DialogBox
77

88

9-
# Definition of curses key constants.
10-
# 10 and 32 correspond to enter and space keys.
11-
PASS_DIALOG_KEY = (10, 32)
12-
13-
14-
def main(stdscr):
15-
# Makes the cursor invisible.
9+
PASS_KEYS = (" ", "\n")
10+
HEIGHT, WIDTH = 35, 6
11+
12+
13+
# 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
33+
34+
35+
def main(win):
36+
# Make the cursor invisible.
1637
curses.curs_set(False)
1738

1839
# Definition of several colors pairs.
19-
curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK)
20-
curses.init_pair(2, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
21-
curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK)
40+
curses.init_pair(1, curses.COLOR_BLUE, 0)
41+
curses.init_pair(2, curses.COLOR_MAGENTA, 0)
42+
curses.init_pair(3, curses.COLOR_RED, 0)
2243

23-
width, height = 6, 35 # Width and height (in character).
24-
25-
max_y, max_x = stdscr.getmaxyx()
44+
max_y, max_x = win.getmaxyx() # Get height and width of the window.
2645

2746
left_x = 2 # Left alignment.
28-
right_x = max_x - height - 4 # Calculation of right alignment.
29-
center_x = max_x//2 - height//2 # Calculation of center alignment.
30-
bottom_y = max_y - width - 4 # Calculation of bottom alignment.
31-
32-
phoenix_wright = DialogBox(left_x, bottom_y,
33-
height, width,
34-
title="Phoenix",
35-
title_colors_pair_nb=1) # Title and color_pair used to colored title.
36-
37-
april_may = DialogBox(center_x, bottom_y,
38-
height, width,
39-
title="April",
40-
title_colors_pair_nb=2)
41-
42-
miles_edgeworth = DialogBox(right_x, bottom_y,
43-
height, width,
44-
title="Edgeworth",
45-
title_colors_pair_nb=3)
46-
47-
# Definition of accepted key codes to pass a dialog.
48-
phoenix_wright.confirm_dialog_key = PASS_DIALOG_KEY
49-
april_may.confirm_dialog_key = PASS_DIALOG_KEY
50-
miles_edgeworth.confirm_dialog_key = PASS_DIALOG_KEY
51-
52-
phoenix_wright.char_by_char(stdscr,
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,
5364
"This testimony is a pure invention !",
54-
delay=0.03) # Set delay between writting each characters to 0.03 seconde.
65+
delay=30)
66+
# Set delay between writting each characters to 30 milliseconds
5567

56-
phoenix_wright.char_by_char(stdscr,
68+
phoenix_wright.char_by_char(win,
5769
"You're lying April May !",
5870
flash_screen=True, # A short luminous glow will be displayed before writing the text.
59-
delay=0.03,
71+
delay=30,
6072
text_attr=curses.A_BOLD)
6173

62-
april_may.char_by_char(stdscr,
74+
april_may.char_by_char(win,
6375
"Arghh !",
64-
delay=0.02,
76+
delay=30,
6577
text_attr=curses.A_ITALIC)
6678

67-
miles_edgeworth.char_by_char(stdscr,
79+
miles_edgeworth.char_by_char(win,
6880
"OBJECTION !",
6981
flash_screen=True,
70-
delay=0.03,
82+
delay=30,
7183
text_attr=curses.A_BOLD)
7284

73-
miles_edgeworth.char_by_char(stdscr,
85+
miles_edgeworth.char_by_char(win,
7486
"These accusations are irrelevant !",
75-
delay=0.03)
87+
delay=30)
7688

7789

7890
# Execution of main function.

0 commit comments

Comments
 (0)