77
88
99PASS_KEYS = (" " , "\n " )
10- HEIGHT , WIDTH = 37 , 7
10+ HEIGHT , WIDTH = 35 , 5
1111
1212
1313# It is preferable to create its own class derived from DialogBox for
1414# complex applications.
1515class CustomDialogBox (DialogBox ):
1616
1717 def __init__ (self ,
18+ win ,
1819 pos_x : int ,
1920 pos_y : int ,
2021 title : str ,
2122 title_colors_pair_nb : int ,
2223 ** 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 )
24+ DialogBox .__init__ (self ,
25+ pos_x ,
26+ pos_y ,
27+ HEIGHT ,
28+ WIDTH ,
29+ title ,
30+ title_colors_pair_nb ,
31+ global_win = win ,
32+ # Use a default window to display text.
33+ # Setting this parameter allows to avoid passing
34+ # `win` parameter to `char_by_char` and
35+ # `word_by_word` methods. Useful when dealing with
36+ # many `DialogBox` methods calls.
37+ ** kwargs )
3038
3139 # Definition of accepted key codes to pass a dialog.
3240 self .confirm_keys = PASS_KEYS
@@ -48,42 +56,40 @@ def main(win):
4856 center_x = max_x // 2 - HEIGHT // 2 # Calculation of center alignment.
4957 bottom_y = max_y - WIDTH - 4 # Calculation of bottom alignment.
5058
51- phoenix_wright = CustomDialogBox (left_x , bottom_y ,
59+ phoenix_wright = CustomDialogBox (win ,
60+ left_x , bottom_y ,
5261 "Phoenix" , # Title of dialog box.
5362 1 ) # Color pair used to colored title.
5463
55- april_may = CustomDialogBox (center_x , bottom_y ,
64+ april_may = CustomDialogBox (win ,
65+ center_x , bottom_y ,
5666 "April" ,
5767 2 )
5868
59- miles_edgeworth = CustomDialogBox (right_x , bottom_y ,
69+ miles_edgeworth = CustomDialogBox (win ,
70+ right_x , bottom_y ,
6071 "Edgeworth" ,
6172 3 )
6273
63- phoenix_wright .char_by_char (win ,
64- "This testimony is a pure invention !" ,
74+ phoenix_wright .char_by_char ("This testimony is a pure invention !" ,
6575 delay = 30 )
6676 # Set delay between writting each characters to 30 milliseconds
6777
68- phoenix_wright .char_by_char (win ,
69- "You're lying April May !" ,
78+ phoenix_wright .char_by_char ("You're lying April May !" ,
7079 flash_screen = True , # A short luminous glow will be displayed before writing the text.
7180 delay = 30 ,
7281 text_attr = curses .A_BOLD )
7382
74- april_may .char_by_char (win ,
75- "Arghh !" ,
83+ april_may .char_by_char ("Arghh !" ,
7684 delay = 30 ,
7785 text_attr = curses .A_ITALIC )
7886
79- miles_edgeworth .char_by_char (win ,
80- "OBJECTION !" ,
87+ miles_edgeworth .char_by_char ("OBJECTION !" ,
8188 flash_screen = True ,
8289 delay = 30 ,
8390 text_attr = curses .A_BOLD )
8491
85- miles_edgeworth .char_by_char (win ,
86- "These accusations are irrelevant !" ,
92+ miles_edgeworth .char_by_char ("These accusations are irrelevant !" ,
8793 delay = 30 )
8894
8995
0 commit comments