From 5005ec101d779505f01ca6edf3fa370c7d84563c Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Sat, 26 Mar 2022 15:46:58 +0530 Subject: [PATCH 01/14] Add `disable_all_items` in `View` --- discord/ui/view.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/discord/ui/view.py b/discord/ui/view.py index dfd3d8893c..7e5da0856a 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -467,6 +467,20 @@ async def wait(self) -> bool: """ return await self.__stopped + def disable_all_items(self, *, exclusions: Optional[List[int]]) -> None: + """ + Disables all items in the view. + + Parameters + ----------- + + exclusions: + Optional[List[:class:`int`]] A list of item indexes in `self.children` to not disable from the view. + """ + for i in range(len(self.children)): + if exceptions is None or i not in exceptions: + self.children[i].disabled + class ViewStore: def __init__(self, state: ConnectionState): From 72a820d49353365cc55e278af9d97a5014c4df93 Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Sat, 26 Mar 2022 15:51:45 +0530 Subject: [PATCH 02/14] Update view.py --- discord/ui/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 7e5da0856a..0dc20ff089 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -478,7 +478,7 @@ def disable_all_items(self, *, exclusions: Optional[List[int]]) -> None: Optional[List[:class:`int`]] A list of item indexes in `self.children` to not disable from the view. """ for i in range(len(self.children)): - if exceptions is None or i not in exceptions: + if exclusions is None or i not in exclusions: self.children[i].disabled From fc284e066ddcf8a8643335970b776baf032b40af Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Mon, 28 Mar 2022 22:50:42 +0530 Subject: [PATCH 03/14] add suggested changes Co-authored-by: Middledot <78228142+Middledot@users.noreply.github.com> --- discord/ui/view.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 0dc20ff089..6de8008932 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -473,9 +473,8 @@ def disable_all_items(self, *, exclusions: Optional[List[int]]) -> None: Parameters ----------- - - exclusions: - Optional[List[:class:`int`]] A list of item indexes in `self.children` to not disable from the view. + exclusions: Optional[List[:class:`int`]] + A list of item indexes in `self.children` to not disable from the view. """ for i in range(len(self.children)): if exclusions is None or i not in exclusions: From 64f5d947297c9b01871b110a198e72ded07c3f50 Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Mon, 11 Apr 2022 13:47:52 +0530 Subject: [PATCH 04/14] fix: add suggested changes Co-authored-by: krittick --- discord/ui/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 6de8008932..abb818a5f0 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -478,7 +478,7 @@ def disable_all_items(self, *, exclusions: Optional[List[int]]) -> None: """ for i in range(len(self.children)): if exclusions is None or i not in exclusions: - self.children[i].disabled + self.children[i].disabled = True class ViewStore: From cbef3fc57473b2faeb638644c6cacc787679487f Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Tue, 12 Apr 2022 14:08:43 +0530 Subject: [PATCH 05/14] feat: add supporr for Item object in `exclusions` --- discord/ui/view.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index abb818a5f0..6f70dc316c 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -467,18 +467,20 @@ async def wait(self) -> bool: """ return await self.__stopped - def disable_all_items(self, *, exclusions: Optional[List[int]]) -> None: + def disable_all_items(self, *, exclusions: Optional[List[Union[int, View.Item]]) -> None: """ Disables all items in the view. Parameters ----------- - exclusions: Optional[List[:class:`int`]] - A list of item indexes in `self.children` to not disable from the view. + exclusions: Optional[List[Union[:class:`int`, :class:`View.Item`]]] + A list of items or indexes in `self.children` to not disable from the view. """ - for i in range(len(self.children)): - if exclusions is None or i not in exclusions: + for i in exclusions: + if isinstance(i, int): self.children[i].disabled = True + elif isinstance(i, discord.ui.Item): + i.disabled = True class ViewStore: From 91d7a1dabda5d1b59d7e16480f0755f0dd744af8 Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Tue, 12 Apr 2022 14:10:10 +0530 Subject: [PATCH 06/14] fix: typehint --- discord/ui/view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 6f70dc316c..b5ae89f804 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -473,13 +473,13 @@ def disable_all_items(self, *, exclusions: Optional[List[Union[int, View.Item]]) Parameters ----------- - exclusions: Optional[List[Union[:class:`int`, :class:`View.Item`]]] + exclusions: Optional[List[Union[:class:`int`, :class:`ui.Item`]]] A list of items or indexes in `self.children` to not disable from the view. """ for i in exclusions: if isinstance(i, int): self.children[i].disabled = True - elif isinstance(i, discord.ui.Item): + elif isinstance(i, Item): i.disabled = True From faa21437e70a0087c5d70309843a307574605d87 Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Tue, 12 Apr 2022 14:13:35 +0530 Subject: [PATCH 07/14] fix: parenthesis --- discord/ui/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index b5ae89f804..d1a1218d59 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -467,7 +467,7 @@ async def wait(self) -> bool: """ return await self.__stopped - def disable_all_items(self, *, exclusions: Optional[List[Union[int, View.Item]]) -> None: + def disable_all_items(self, *, exclusions: Optional[List[Union[int, View.Item]]]) -> None: """ Disables all items in the view. From 85c9b58e92155b6223cae055389c681d09a08000 Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Tue, 12 Apr 2022 20:17:31 +0530 Subject: [PATCH 08/14] feat: add more checks in `View.disable_all_items` --- discord/ui/view.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index d1a1218d59..efeacd9d89 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -478,9 +478,12 @@ def disable_all_items(self, *, exclusions: Optional[List[Union[int, View.Item]]] """ for i in exclusions: if isinstance(i, int): - self.children[i].disabled = True + if not self.children[i].disabled: + self.children[i].disabled = True elif isinstance(i, Item): - i.disabled = True + if hasattr(i, "disabled"): + if not i.disabled: + i.disabled = True class ViewStore: From 78d634950edb990cfd3b5b10f4a9829f1ef7d5b8 Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Tue, 12 Apr 2022 20:24:59 +0530 Subject: [PATCH 09/14] fix: typehint --- discord/ui/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index efeacd9d89..5f6f3a3448 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -467,7 +467,7 @@ async def wait(self) -> bool: """ return await self.__stopped - def disable_all_items(self, *, exclusions: Optional[List[Union[int, View.Item]]]) -> None: + def disable_all_items(self, *, exclusions: Optional[List[Union[int, Item]]]) -> None: """ Disables all items in the view. From e63cf161b0d228009c7d2c0730790531d9eadccb Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Thu, 21 Apr 2022 22:05:32 +0530 Subject: [PATCH 10/14] feat: remove `int` from `exclusions` --- discord/ui/view.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 0bdf054494..244a8c937a 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -465,23 +465,18 @@ async def wait(self) -> bool: """ return await self.__stopped - def disable_all_items(self, *, exclusions: Optional[List[Union[int, Item]]]) -> None: + def disable_all_items(self, *, exclusions: Optional[List[Item]]) -> None: """ Disables all items in the view. Parameters ----------- - exclusions: Optional[List[Union[:class:`int`, :class:`ui.Item`]]] - A list of items or indexes in `self.children` to not disable from the view. + exclusions: Optional[List[:class:`ui.Item`]] + A list of items in `self.children` to not disable from the view. """ - for i in exclusions: - if isinstance(i, int): - if not self.children[i].disabled: - self.children[i].disabled = True - elif isinstance(i, Item): - if hasattr(i, "disabled"): - if not i.disabled: - i.disabled = True + for child in self.children: + for i in exclusions: + child.disabled = True if child != i class ViewStore: From 630e7c0bfb8703e8517d3f2dccd539959eebd847 Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Thu, 21 Apr 2022 22:08:57 +0530 Subject: [PATCH 11/14] fix: code fixes --- discord/ui/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 244a8c937a..452a79b583 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -476,7 +476,7 @@ def disable_all_items(self, *, exclusions: Optional[List[Item]]) -> None: """ for child in self.children: for i in exclusions: - child.disabled = True if child != i + child.disabled = True if child != i else None class ViewStore: From 0a69fe859fce06ae512bfecf02d67696cfe1b63c Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Thu, 21 Apr 2022 20:51:48 +0200 Subject: [PATCH 12/14] Update discord/ui/view.py Co-authored-by: plun1331 <49261529+plun1331@users.noreply.github.com> --- discord/ui/view.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 452a79b583..25b56d402d 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -475,8 +475,8 @@ def disable_all_items(self, *, exclusions: Optional[List[Item]]) -> None: A list of items in `self.children` to not disable from the view. """ for child in self.children: - for i in exclusions: - child.disabled = True if child != i else None + if child not in exclusions: + child.disabled = True class ViewStore: From 667a9e1663ff3fdb21e20bd64f600c01fcde9c6f Mon Sep 17 00:00:00 2001 From: 27Saumya <64534496+27Saumya@users.noreply.github.com> Date: Tue, 26 Apr 2022 14:31:34 +0530 Subject: [PATCH 13/14] fix: `exclusions` param -> optional --- discord/ui/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index 25b56d402d..acfd3b540b 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -465,7 +465,7 @@ async def wait(self) -> bool: """ return await self.__stopped - def disable_all_items(self, *, exclusions: Optional[List[Item]]) -> None: + def disable_all_items(self, *, exclusions: Optional[List[Item]] = None) -> None: """ Disables all items in the view. From 58a8827051cc3b9d1806a801d572a73b9012f5be Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Thu, 28 Apr 2022 23:50:23 +0200 Subject: [PATCH 14/14] Update discord/ui/view.py Co-authored-by: plun1331 <49261529+plun1331@users.noreply.github.com> --- discord/ui/view.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index acfd3b540b..70e7c675dc 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -475,7 +475,7 @@ def disable_all_items(self, *, exclusions: Optional[List[Item]] = None) -> None: A list of items in `self.children` to not disable from the view. """ for child in self.children: - if child not in exclusions: + if exclusions is None or child not in exclusions: child.disabled = True