|
6 | 6 | from visualdialog import DialogBox |
7 | 7 |
|
8 | 8 |
|
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. |
16 | 37 | curses.curs_set(False) |
17 | 38 |
|
18 | 39 | # 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) |
22 | 43 |
|
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. |
26 | 45 |
|
27 | 46 | 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, |
53 | 64 | "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 |
55 | 67 |
|
56 | | - phoenix_wright.char_by_char(stdscr, |
| 68 | + phoenix_wright.char_by_char(win, |
57 | 69 | "You're lying April May !", |
58 | 70 | flash_screen=True, # A short luminous glow will be displayed before writing the text. |
59 | | - delay=0.03, |
| 71 | + delay=30, |
60 | 72 | text_attr=curses.A_BOLD) |
61 | 73 |
|
62 | | - april_may.char_by_char(stdscr, |
| 74 | + april_may.char_by_char(win, |
63 | 75 | "Arghh !", |
64 | | - delay=0.02, |
| 76 | + delay=30, |
65 | 77 | text_attr=curses.A_ITALIC) |
66 | 78 |
|
67 | | - miles_edgeworth.char_by_char(stdscr, |
| 79 | + miles_edgeworth.char_by_char(win, |
68 | 80 | "OBJECTION !", |
69 | 81 | flash_screen=True, |
70 | | - delay=0.03, |
| 82 | + delay=30, |
71 | 83 | text_attr=curses.A_BOLD) |
72 | 84 |
|
73 | | - miles_edgeworth.char_by_char(stdscr, |
| 85 | + miles_edgeworth.char_by_char(win, |
74 | 86 | "These accusations are irrelevant !", |
75 | | - delay=0.03) |
| 87 | + delay=30) |
76 | 88 |
|
77 | 89 |
|
78 | 90 | # Execution of main function. |
|
0 commit comments