@@ -151,11 +151,6 @@ class View:
151
151
timeout: Optional[:class:`float`]
152
152
Timeout in seconds from last interaction with the UI before no longer accepting input.
153
153
If ``None`` then there is no timeout.
154
-
155
- Attributes
156
- ------------
157
- children: List[:class:`Item`]
158
- The list of children attached to this view.
159
154
"""
160
155
161
156
__discord_ui_view__ : ClassVar [bool ] = True
@@ -186,16 +181,16 @@ def _init_children(self) -> List[Item[Self]]:
186
181
187
182
def __init__ (self , * , timeout : Optional [float ] = 180.0 ):
188
183
self .__timeout = timeout
189
- self .children : List [Item [Self ]] = self ._init_children ()
190
- self .__weights = _ViewWeights (self .children )
184
+ self ._children : List [Item [Self ]] = self ._init_children ()
185
+ self .__weights = _ViewWeights (self ._children )
191
186
self .id : str = os .urandom (16 ).hex ()
192
187
self .__cancel_callback : Optional [Callable [[View ], None ]] = None
193
188
self .__timeout_expiry : Optional [float ] = None
194
189
self .__timeout_task : Optional [asyncio .Task [None ]] = None
195
190
self .__stopped : asyncio .Future [bool ] = asyncio .get_running_loop ().create_future ()
196
191
197
192
def __repr__ (self ) -> str :
198
- return f'<{ self .__class__ .__name__ } timeout={ self .timeout } children={ len (self .children )} >'
193
+ return f'<{ self .__class__ .__name__ } timeout={ self .timeout } children={ len (self ._children )} >'
199
194
200
195
async def __timeout_task_impl (self ) -> None :
201
196
while True :
@@ -218,7 +213,7 @@ def to_components(self) -> List[Dict[str, Any]]:
218
213
def key (item : Item ) -> int :
219
214
return item ._rendered_row or 0
220
215
221
- children = sorted (self .children , key = key )
216
+ children = sorted (self ._children , key = key )
222
217
components : List [Dict [str , Any ]] = []
223
218
for _ , group in groupby (children , key = key ):
224
219
children = [item .to_component_dict () for item in group ]
@@ -257,6 +252,11 @@ def timeout(self, value: Optional[float]) -> None:
257
252
258
253
self .__timeout = value
259
254
255
+ @property
256
+ def children (self ) -> List [Item [Self ]]:
257
+ """List[:class:`Item`]: The list of children attached to this view."""
258
+ return self ._children .copy ()
259
+
260
260
@classmethod
261
261
def from_message (cls , message : Message , / , * , timeout : Optional [float ] = 180.0 ) -> View :
262
262
"""Converts a message's components into a :class:`View`.
@@ -304,7 +304,7 @@ def add_item(self, item: Item[Any]) -> Self:
304
304
or the row the item is trying to be added to is full.
305
305
"""
306
306
307
- if len (self .children ) > 25 :
307
+ if len (self ._children ) > 25 :
308
308
raise ValueError ('maximum number of children exceeded' )
309
309
310
310
if not isinstance (item , Item ):
@@ -313,7 +313,7 @@ def add_item(self, item: Item[Any]) -> Self:
313
313
self .__weights .add_item (item )
314
314
315
315
item ._view = self
316
- self .children .append (item )
316
+ self ._children .append (item )
317
317
return self
318
318
319
319
def remove_item (self , item : Item [Any ]) -> Self :
@@ -329,7 +329,7 @@ def remove_item(self, item: Item[Any]) -> Self:
329
329
"""
330
330
331
331
try :
332
- self .children .remove (item )
332
+ self ._children .remove (item )
333
333
except ValueError :
334
334
pass
335
335
else :
@@ -342,7 +342,7 @@ def clear_items(self) -> Self:
342
342
This function returns the class instance to allow for fluent-style
343
343
chaining.
344
344
"""
345
- self .children .clear ()
345
+ self ._children .clear ()
346
346
self .__weights .clear ()
347
347
return self
348
348
@@ -445,7 +445,7 @@ def _refresh(self, components: List[Component]) -> None:
445
445
# fmt: off
446
446
old_state : Dict [Tuple [int , str ], Item [Any ]] = {
447
447
(item .type .value , item .custom_id ): item # type: ignore
448
- for item in self .children
448
+ for item in self ._children
449
449
if item .is_dispatchable ()
450
450
}
451
451
# fmt: on
@@ -459,7 +459,7 @@ def _refresh(self, components: List[Component]) -> None:
459
459
older ._refresh_component (component )
460
460
children .append (older )
461
461
462
- self .children = children
462
+ self ._children = children
463
463
464
464
def stop (self ) -> None :
465
465
"""Stops listening to interaction events from this view.
@@ -492,7 +492,7 @@ def is_persistent(self) -> bool:
492
492
A persistent view has all their components with a set ``custom_id`` and
493
493
a :attr:`timeout` set to ``None``.
494
494
"""
495
- return self .timeout is None and all (item .is_persistent () for item in self .children )
495
+ return self .timeout is None and all (item .is_persistent () for item in self ._children )
496
496
497
497
async def wait (self ) -> bool :
498
498
"""Waits until the view has finished interacting.
@@ -547,7 +547,7 @@ def add_view(self, view: View, message_id: Optional[int] = None) -> None:
547
547
548
548
self .__verify_integrity ()
549
549
550
- for item in view .children :
550
+ for item in view ._children :
551
551
if item .is_dispatchable ():
552
552
self ._views [(item .type .value , message_id , item .custom_id )] = (view , item ) # type: ignore
553
553
@@ -559,7 +559,7 @@ def remove_view(self, view: View) -> None:
559
559
self ._modals .pop (view .custom_id , None ) # type: ignore
560
560
return
561
561
562
- for item in view .children :
562
+ for item in view ._children :
563
563
if item .is_dispatchable ():
564
564
self ._views .pop ((item .type .value , item .custom_id ), None ) # type: ignore
565
565
0 commit comments