@@ -49,7 +49,7 @@ class SimpleESCMenu(_BaseMenu):
4949 """This class creates basic ESC menus."""
5050
5151 def __init__ (
52- self , data = None , select_callback = None , build_callback = None ,
52+ self , data = None , select_callback = None , build_callback = None , close_callback = None ,
5353 description = None , title = None , title_color = WHITE ):
5454 """Initialize the object.
5555
@@ -58,13 +58,15 @@ def __init__(
5858 :meth:`menus.base._BaseMenu.__init__`.
5959 :param callable|None build_callback: See
6060 :meth:`menus.base._BaseMenu.__init__`.
61+ :param callable|None close_callback: See
62+ :meth:`menus.base._BaseMenu.__init__`
6163 :param str|None description: A description that is displayed under the
6264 title.
6365 :param str|None title: A title that is displayed at the top of the
6466 menu.
6567 :param Color title_color: The color of the title.
6668 """
67- super ().__init__ (data , select_callback , build_callback )
69+ super ().__init__ (data , select_callback , build_callback , close_callback )
6870 self .description = description
6971 self .title = title
7072 self .title_color = title_color
@@ -109,7 +111,7 @@ def _get_menu_data(self, player_index):
109111 def _select (self , player_index , choice_index ):
110112 """See :meth:`menus.base._BaseMenu._select`."""
111113 if choice_index == 0 :
112- return None
114+ return self . _select_close ( player_index )
113115
114116 option = self ._player_pages [player_index ].options [choice_index ]
115117 if not option .selectable :
@@ -165,7 +167,7 @@ class PagedESCMenu(SimpleESCMenu, _PagedMenuBase):
165167 """
166168
167169 def __init__ (
168- self , data = None , select_callback = None , build_callback = None ,
170+ self , data = None , select_callback = None , build_callback = None , close_callback = None ,
169171 description = None , title = None , title_color = WHITE , fill = True ,
170172 parent_menu = None ):
171173 """Initialize the object.
@@ -175,6 +177,8 @@ def __init__(
175177 :meth:`menus.base._BaseMenu.__init__`.
176178 :param callable|None build_callback: See
177179 :meth:`menus.base._BaseMenu.__init__`.
180+ :param callable|None close_callback: See
181+ :meth:`menus.base._BaseMenu.__init__`.
178182 :param str|None description: See :meth:`SimpleESCMenu.__init__`.
179183 :param str|None title: See :meth:`SimpleESCMenu.__init__`.
180184 :param Color title_color: See :meth:`SimpleESCMenu.__init__`.
@@ -184,7 +188,7 @@ def __init__(
184188 hitting 'Back' on the first page.
185189 """
186190 super ().__init__ (
187- data , select_callback , build_callback ,
191+ data , select_callback , build_callback , close_callback ,
188192 description , title , title_color )
189193 self .fill = fill
190194 self .parent_menu = parent_menu
@@ -280,10 +284,9 @@ def _get_menu_data(self, player_index):
280284
281285 def _select (self , player_index , choice_index ):
282286 """See :meth:`menus.base._BaseMenu._select`."""
283- # Do nothing if the menu is being closed
284287 if choice_index == 0 :
285288 del self ._player_pages [player_index ]
286- return None
289+ return self . _select_close ( player_index )
287290
288291 # Get the player's current page
289292 page_index = self .get_player_page (player_index )
@@ -311,7 +314,7 @@ class ListESCMenu(PagedESCMenu):
311314 Navigation options are added automatically."""
312315
313316 def __init__ (
314- self , data = None , select_callback = None , build_callback = None ,
317+ self , data = None , select_callback = None , build_callback = None , close_callback = None ,
315318 description = None , title = None , title_color = WHITE , fill = True ,
316319 parent_menu = None , items_per_page = 5 ):
317320 """Initialize the object.
@@ -321,6 +324,8 @@ def __init__(
321324 :meth:`menus.base._BaseMenu.__init__`.
322325 :param callable|None build_callback: See
323326 :meth:`menus.base._BaseMenu.__init__`.
327+ :param callable|None close_callback: See
328+ :meth:`menus.base._BaseMenu.__init__`.
324329 :param str|None description: See :meth:`SimpleESCMenu.__init__`.
325330 :param str|None title: See :meth:`SimpleESCMenu.__init__`.
326331 :param Color title_color: See :meth:`SimpleESCMenu.__init__`.
@@ -329,7 +334,7 @@ def __init__(
329334 :param int items_per_page: Number of options that should be displayed
330335 on a single page (5 is the maximum).
331336 """
332- super ().__init__ (data , select_callback , build_callback , description ,
337+ super ().__init__ (data , select_callback , build_callback , close_callback , description ,
333338 title , title_color , fill , parent_menu )
334339 self .items_per_page = items_per_page
335340
0 commit comments