Skip to content

Commit 64f3c4f

Browse files
authored
more
1 parent 3a8bb10 commit 64f3c4f

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

discord/ui/action_row.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ..utils import find, get
1111
from .button import Button
1212
from .file import File
13-
from .item import Item, ItemCallbackType
13+
from .item import ViewItem, ItemCallbackType
1414
from .select import Select
1515

1616
__all__ = ("ActionRow",)
@@ -28,7 +28,7 @@
2828
V = TypeVar("V", bound="DesignerView", covariant=True)
2929

3030

31-
class ActionRow(Item[V]):
31+
class ActionRow(ViewItem[V]):
3232
"""Represents a UI Action Row used in :class:`discord.ui.DesignerView`.
3333
3434
The items supported are as follows:
@@ -40,7 +40,7 @@ class ActionRow(Item[V]):
4040
4141
Parameters
4242
----------
43-
*items: :class:`Item`
43+
*items: :class:`ViewItem`
4444
The initial items in this action row.
4545
id: Optional[:class:`int`]
4646
The action's ID.
@@ -64,12 +64,12 @@ def __init_subclass__(cls) -> None:
6464

6565
def __init__(
6666
self,
67-
*items: Item,
67+
*items: ViewItem,
6868
id: int | None = None,
6969
):
7070
super().__init__()
7171

72-
self.children: list[Item] = []
72+
self.children: list[ViewItem] = []
7373

7474
self._underlying = ActionRowComponent._raw_construct(
7575
type=ComponentType.action_row,
@@ -78,7 +78,7 @@ def __init__(
7878
)
7979

8080
for func in self.__row_children_items__:
81-
item: Item = func.__discord_ui_model_type__(
81+
item: ViewItem = func.__discord_ui_model_type__(
8282
**func.__discord_ui_model_kwargs__
8383
)
8484
item.callback = partial(func, self, item)
@@ -87,26 +87,26 @@ def __init__(
8787
for i in items:
8888
self.add_item(i)
8989

90-
def _add_component_from_item(self, item: Item):
90+
def _add_component_from_item(self, item: ViewItem):
9191
self._underlying.children.append(item._underlying)
9292

93-
def _set_components(self, items: list[Item]):
93+
def _set_components(self, items: list[ViewItem]):
9494
self._underlying.children.clear()
9595
for item in items:
9696
self._add_component_from_item(item)
9797

98-
def add_item(self, item: Item) -> Self:
98+
def add_item(self, item: ViewItem) -> Self:
9999
"""Adds an item to the action row.
100100
101101
Parameters
102102
----------
103-
item: :class:`Item`
103+
item: :class:`ViewItem`
104104
The item to add to the action row.
105105
106106
Raises
107107
------
108108
TypeError
109-
An :class:`Item` was not passed.
109+
A :class:`ViewItem` was not passed.
110110
"""
111111

112112
if not isinstance(item, (Select, Button)):
@@ -123,12 +123,12 @@ def add_item(self, item: Item) -> Self:
123123
self._add_component_from_item(item)
124124
return self
125125

126-
def remove_item(self, item: Item | str | int) -> Self:
126+
def remove_item(self, item: ViewItem | str | int) -> Self:
127127
"""Removes an item from the action row. If an int or str is passed, it will remove by Item :attr:`id` or ``custom_id`` respectively.
128128
129129
Parameters
130130
----------
131-
item: Union[:class:`Item`, :class:`int`, :class:`str`]
131+
item: Union[:class:`ViewItem`, :class:`int`, :class:`str`]
132132
The item, ``id``, or item ``custom_id`` to remove from the action row.
133133
"""
134134

@@ -140,7 +140,7 @@ def remove_item(self, item: Item | str | int) -> Self:
140140
pass
141141
return self
142142

143-
def get_item(self, id: str | int) -> Item | None:
143+
def get_item(self, id: str | int) -> ViewItem | None:
144144
"""Get an item from this action row. Roughly equivalent to `utils.get(row.children, ...)`.
145145
If an ``int`` is provided, the item will be retrieved by ``id``, otherwise by ``custom_id``.
146146
@@ -151,7 +151,7 @@ def get_item(self, id: str | int) -> Item | None:
151151
152152
Returns
153153
-------
154-
Optional[:class:`Item`]
154+
Optional[:class:`ViewItem`]
155155
The item with the matching ``id`` or ``custom_id`` if it exists.
156156
"""
157157
if not id:
@@ -327,7 +327,7 @@ def add_select(
327327

328328
return self.add_item(select)
329329

330-
@Item.view.setter
330+
@ViewItem.view.setter
331331
def view(self, value):
332332
self._view = value
333333
for item in self.children:
@@ -352,27 +352,27 @@ def refresh_component(self, component: ActionRowComponent) -> None:
352352
x.refresh_component(y)
353353
i += 1
354354

355-
def disable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
355+
def disable_all_items(self, *, exclusions: list[ViewItem] | None = None) -> Self:
356356
"""
357357
Disables all items in the row.
358358
359359
Parameters
360360
----------
361-
exclusions: Optional[List[:class:`Item`]]
361+
exclusions: Optional[List[:class:`ViewItem`]]
362362
A list of items in `self.children` to not disable.
363363
"""
364364
for item in self.walk_items():
365365
if exclusions is None or item not in exclusions:
366366
item.disabled = True
367367
return self
368368

369-
def enable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
369+
def enable_all_items(self, *, exclusions: list[ViewItem] | None = None) -> Self:
370370
"""
371371
Enables all items in the row.
372372
373373
Parameters
374374
----------
375-
exclusions: Optional[List[:class:`Item`]]
375+
exclusions: Optional[List[:class:`ViewItem`]]
376376
A list of items in `self.children` to not enable.
377377
"""
378378
for item in self.walk_items():
@@ -388,7 +388,7 @@ def width(self):
388388
t += 1 if item._underlying.type is ComponentType.button else 5
389389
return t
390390

391-
def walk_items(self) -> Iterator[Item]:
391+
def walk_items(self) -> Iterator[ViewItem]:
392392
yield from self.children
393393

394394
def to_component_dict(self) -> ActionRowPayload:

discord/ui/label.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class Label(ModalItem[M]):
4040
4141
Parameters
4242
----------
43-
item: :class:`Item`
44-
The initial item in this label.
43+
item: :class:`ModalItem`
44+
The initial item attached to this label.
4545
label: :class:`str`
4646
The label text. Must be 45 characters or fewer.
4747
description: Optional[:class:`str`]
@@ -60,14 +60,14 @@ class Label(ModalItem[M]):
6060
def __init__(
6161
self,
6262
label: str,
63-
item: Item = None,
63+
item: ModalItem = None,
6464
*,
6565
description: str | None = None,
6666
id: int | None = None,
6767
):
6868
super().__init__()
6969

70-
self.item: Item = None
70+
self.item: ModalItem = None
7171

7272
self._underlying = LabelComponent._raw_construct(
7373
type=ComponentType.label,
@@ -80,26 +80,32 @@ def __init__(
8080
if item:
8181
self.set_item(item)
8282

83-
def _set_component_from_item(self, item: Item):
83+
@ModalItem.modal.setter
84+
def modal(self, value):
85+
self._modal = value
86+
if self.item:
87+
self.item.modal = value
88+
89+
def _set_component_from_item(self, item: ModalItem):
8490
self._underlying.component = item._underlying
8591

86-
def set_item(self, item: Item) -> Self:
92+
def set_item(self, item: ModalItem) -> Self:
8793
"""Set this label's item.
8894
8995
Parameters
9096
----------
91-
item: Union[:class:`Item`, :class:`InputText`]
97+
item: Union[:class:`ModalItem`, :class:`InputText`]
9298
The item to set.
9399
Currently only supports :class:`~discord.ui.Select` and :class:`~discord.ui.InputText`.
94100
95101
Raises
96102
------
97103
TypeError
98-
An :class:`Item` was not passed.
104+
A :class:`ModalItem` was not passed.
99105
"""
100106

101-
if not isinstance(item, (Item, InputText)):
102-
raise TypeError(f"expected Item not {item.__class__!r}")
107+
if not isinstance(item, ModalItem):
108+
raise TypeError(f"expected ModalItem not {item.__class__!r}")
103109
if isinstance(item, InputText) and item.label:
104110
raise ValueError(f"InputText.label cannot be set inside Label")
105111
if self.view:
@@ -110,7 +116,7 @@ def set_item(self, item: Item) -> Self:
110116
self._set_component_from_item(item)
111117
return self
112118

113-
def get_item(self, id: str | int) -> Item | None:
119+
def get_item(self, id: str | int) -> ModalItem | None:
114120
"""Get the item from this label if it matches the provided id.
115121
If an ``int`` is provided, the item will match by ``id``, otherwise by ``custom_id``.
116122
@@ -121,7 +127,7 @@ def get_item(self, id: str | int) -> Item | None:
121127
122128
Returns
123129
-------
124-
Optional[:class:`Item`]
130+
Optional[:class:`ModalItem`]
125131
The item if its ``id`` or ``custom_id`` matches.
126132
"""
127133
if not id:
@@ -330,7 +336,7 @@ def refresh_component(self, component: LabelComponent) -> None:
330336
self._underlying = component
331337
self.item.refresh_component(component.component)
332338

333-
def walk_items(self) -> Iterator[Item]:
339+
def walk_items(self) -> Iterator[ModalItem]:
334340
yield from [self.item]
335341

336342
def to_component_dict(self) -> LabelPayload:

0 commit comments

Comments
 (0)