11
11
from .action_row import ActionRow
12
12
from .button import Button
13
13
from .file import File
14
- from .item import Item , ItemCallbackType
14
+ from .item import ViewItem , ItemCallbackType
15
15
from .media_gallery import MediaGallery
16
16
from .section import Section
17
17
from .select import Select
32
32
V = TypeVar ("V" , bound = "DesignerView" , covariant = True )
33
33
34
34
35
- class Container (Item [V ]):
35
+ class Container (ViewItem [V ]):
36
36
"""Represents a UI Container.
37
37
38
38
The current items supported are as follows:
@@ -48,7 +48,7 @@ class Container(Item[V]):
48
48
49
49
Parameters
50
50
----------
51
- *items: :class:`Item `
51
+ *items: :class:`ViewItem `
52
52
The initial items in this container.
53
53
colour: Union[:class:`Colour`, :class:`int`]
54
54
The accent colour of the container. Aliased to ``color`` as well.
@@ -75,15 +75,15 @@ def __init_subclass__(cls) -> None:
75
75
76
76
def __init__ (
77
77
self ,
78
- * items : Item ,
78
+ * items : ViewItem ,
79
79
colour : int | Colour | None = None ,
80
80
color : int | Colour | None = None ,
81
81
spoiler : bool = False ,
82
82
id : int | None = None ,
83
83
):
84
84
super ().__init__ ()
85
85
86
- self .items : list [Item ] = []
86
+ self .items : list [ViewItem ] = []
87
87
88
88
self ._underlying = ContainerComponent ._raw_construct (
89
89
type = ComponentType .container ,
@@ -96,30 +96,30 @@ def __init__(
96
96
for i in items :
97
97
self .add_item (i )
98
98
99
- def _add_component_from_item (self , item : Item ):
99
+ def _add_component_from_item (self , item : ViewItem ):
100
100
self ._underlying .components .append (item ._underlying )
101
101
102
- def _set_components (self , items : list [Item ]):
102
+ def _set_components (self , items : list [ViewItem ]):
103
103
self ._underlying .components .clear ()
104
104
for item in items :
105
105
self ._add_component_from_item (item )
106
106
107
- def add_item (self , item : Item ) -> Self :
107
+ def add_item (self , item : ViewItem ) -> Self :
108
108
"""Adds an item to the container.
109
109
110
110
Parameters
111
111
----------
112
- item: :class:`Item `
112
+ item: :class:`ViewItem `
113
113
The item to add to the container.
114
114
115
115
Raises
116
116
------
117
117
TypeError
118
- An :class:`Item ` was not passed.
118
+ A :class:`ViewItem ` was not passed.
119
119
"""
120
120
121
- if not isinstance (item , Item ):
122
- raise TypeError (f"expected Item not { item .__class__ !r} " )
121
+ if not isinstance (item , ViewItem ):
122
+ raise TypeError (f"expected ViewItem not { item .__class__ !r} " )
123
123
124
124
if isinstance (item , (Button , Select )):
125
125
raise TypeError (
@@ -135,12 +135,12 @@ def add_item(self, item: Item) -> Self:
135
135
self ._add_component_from_item (item )
136
136
return self
137
137
138
- def remove_item (self , item : Item | str | int ) -> Self :
138
+ def remove_item (self , item : ViewItem | str | int ) -> Self :
139
139
"""Removes an item from the container. If an int or str is passed, it will remove by Item :attr:`id` or ``custom_id`` respectively.
140
140
141
141
Parameters
142
142
----------
143
- item: Union[:class:`Item `, :class:`int`, :class:`str`]
143
+ item: Union[:class:`ViewItem `, :class:`int`, :class:`str`]
144
144
The item, ``id``, or item ``custom_id`` to remove from the container.
145
145
"""
146
146
@@ -155,7 +155,7 @@ def remove_item(self, item: Item | str | int) -> Self:
155
155
pass
156
156
return self
157
157
158
- def get_item (self , id : str | int ) -> Item | None :
158
+ def get_item (self , id : str | int ) -> ViewItem | None :
159
159
"""Get an item from this container. Roughly equivalent to `utils.get(container.items, ...)`.
160
160
If an ``int`` is provided, the item will be retrieved by ``id``, otherwise by ``custom_id``.
161
161
This method will also search for nested items.
@@ -167,7 +167,7 @@ def get_item(self, id: str | int) -> Item | None:
167
167
168
168
Returns
169
169
-------
170
- Optional[:class:`Item `]
170
+ Optional[:class:`ViewItem `]
171
171
The item with the matching ``id`` or ``custom_id`` if it exists.
172
172
"""
173
173
if not id :
@@ -183,7 +183,7 @@ def get_item(self, id: str | int) -> Item | None:
183
183
184
184
def add_row (
185
185
self ,
186
- * items : Item ,
186
+ * items : ViewItem ,
187
187
id : int | None = None ,
188
188
) -> Self :
189
189
"""Adds an :class:`ActionRow` to the container.
@@ -204,8 +204,8 @@ def add_row(
204
204
205
205
def add_section (
206
206
self ,
207
- * items : Item ,
208
- accessory : Item ,
207
+ * items : ViewItem ,
208
+ accessory : ViewItem ,
209
209
id : int | None = None ,
210
210
) -> Self :
211
211
"""Adds a :class:`Section` to the container.
@@ -215,10 +215,10 @@ def add_section(
215
215
216
216
Parameters
217
217
----------
218
- *items: :class:`Item `
218
+ *items: :class:`ViewItem `
219
219
The items contained in this section, up to 3.
220
220
Currently only supports :class:`~discord.ui.TextDisplay`.
221
- accessory: Optional[:class:`Item `]
221
+ accessory: Optional[:class:`ViewItem `]
222
222
The section's accessory. This is displayed in the top right of the section.
223
223
Currently only supports :class:`~discord.ui.Button` and :class:`~discord.ui.Thumbnail`.
224
224
id: Optional[:class:`int`]
@@ -246,7 +246,7 @@ def add_text(self, content: str, id: int | None = None) -> Self:
246
246
247
247
def add_gallery (
248
248
self ,
249
- * items : Item ,
249
+ * items : ViewItem ,
250
250
id : int | None = None ,
251
251
) -> Self :
252
252
"""Adds a :class:`MediaGallery` to the container.
@@ -338,7 +338,7 @@ def colour(self, value: int | Colour | None): # type: ignore
338
338
339
339
color = colour
340
340
341
- @Item .view .setter
341
+ @ViewItem .view .setter
342
342
def view (self , value ):
343
343
self ._view = value
344
344
for item in self .items :
@@ -365,13 +365,13 @@ def refresh_component(self, component: ContainerComponent) -> None:
365
365
x .refresh_component (y )
366
366
i += 1
367
367
368
- def disable_all_items (self , * , exclusions : list [Item ] | None = None ) -> Self :
368
+ def disable_all_items (self , * , exclusions : list [ViewItem ] | None = None ) -> Self :
369
369
"""
370
370
Disables all buttons and select menus in the container.
371
371
372
372
Parameters
373
373
----------
374
- exclusions: Optional[List[:class:`Item `]]
374
+ exclusions: Optional[List[:class:`ViewItem `]]
375
375
A list of items in `self.items` to not disable from the view.
376
376
"""
377
377
for item in self .walk_items ():
@@ -381,13 +381,13 @@ def disable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
381
381
item .disabled = True
382
382
return self
383
383
384
- def enable_all_items (self , * , exclusions : list [Item ] | None = None ) -> Self :
384
+ def enable_all_items (self , * , exclusions : list [ViewItem ] | None = None ) -> Self :
385
385
"""
386
386
Enables all buttons and select menus in the container.
387
387
388
388
Parameters
389
389
----------
390
- exclusions: Optional[List[:class:`Item `]]
390
+ exclusions: Optional[List[:class:`ViewItem `]]
391
391
A list of items in `self.items` to not enable from the view.
392
392
"""
393
393
for item in self .walk_items ():
@@ -397,7 +397,7 @@ def enable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
397
397
item .disabled = False
398
398
return self
399
399
400
- def walk_items (self ) -> Iterator [Item ]:
400
+ def walk_items (self ) -> Iterator [ViewItem ]:
401
401
for item in self .items :
402
402
if hasattr (item , "walk_items" ):
403
403
yield from item .walk_items ()
0 commit comments