mirror of
https://github.com/Paillat-dev/pycord-reactive-views.git
synced 2026-01-02 01:06:18 +00:00
🐛 Fix color_select.py example not changing embed color
This commit is contained in:
0
examples/__init__.py
Normal file
0
examples/__init__.py
Normal file
@@ -1,9 +1,9 @@
|
||||
# ruff: noqa: INP001
|
||||
import os
|
||||
|
||||
import discord
|
||||
from dotenv import load_dotenv
|
||||
from pycord_reactive_views import ReactiveSelect, ReactiveValue, ReactiveView
|
||||
from typing_extensions import override
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@@ -71,6 +71,7 @@ class ColourSelector(ReactiveView):
|
||||
async def _colour_select_callback(self, interaction: discord.Interaction) -> None:
|
||||
await interaction.response.defer()
|
||||
self.colour = self.colour_select.values[0] # pyright: ignore[reportAttributeAccessIssue]
|
||||
self.shade = colors[self.colour][0]
|
||||
await self.update()
|
||||
|
||||
async def _shade_select_callback(self, interaction: discord.Interaction) -> None:
|
||||
@@ -79,6 +80,7 @@ class ColourSelector(ReactiveView):
|
||||
self.shade = discord.Colour(selected_shade)
|
||||
await self.update()
|
||||
|
||||
@override
|
||||
async def _get_embed(self) -> discord.Embed | None:
|
||||
return discord.Embed(
|
||||
title=f"{self.colour.capitalize()} {self.shade}",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# ruff: noqa: INP001
|
||||
import os
|
||||
|
||||
import discord
|
||||
@@ -26,7 +25,7 @@ class Counter(ReactiveView):
|
||||
self.reset_button = ReactiveButton(
|
||||
label="Reset",
|
||||
style=discord.ButtonStyle.danger,
|
||||
disabled=ReactiveValue(lambda: self.counter == 0, True),
|
||||
disabled=ReactiveValue(lambda: self.counter == 0, default=True),
|
||||
)
|
||||
self.counter_button.callback = self._increment
|
||||
self.reset_button.callback = self._reset
|
||||
|
||||
27
pdm.lock
generated
27
pdm.lock
generated
@@ -5,7 +5,7 @@
|
||||
groups = ["default", "dev"]
|
||||
strategy = ["inherit_metadata"]
|
||||
lock_version = "4.5.0"
|
||||
content_hash = "sha256:1a06a79ce3191daacd59b5096b1f90dad50b7f13b23462948321967ec7ee3452"
|
||||
content_hash = "sha256:2bf683c8627b675d845d2bda3fab0d83e6faaa92c70ffae1b35dea62c124475f"
|
||||
|
||||
[[metadata.targets]]
|
||||
requires_python = "==3.11.4"
|
||||
@@ -16,6 +16,7 @@ version = "2.3.4"
|
||||
requires_python = "<4.0,>=3.8"
|
||||
summary = "Happy Eyeballs for asyncio"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
files = [
|
||||
{file = "aiohappyeyeballs-2.3.4-py3-none-any.whl", hash = "sha256:40a16ceffcf1fc9e142fd488123b2e218abc4188cf12ac20c67200e1579baa42"},
|
||||
{file = "aiohappyeyeballs-2.3.4.tar.gz", hash = "sha256:7e1ae8399c320a8adec76f6c919ed5ceae6edd4c3672f4d9eae2b27e37c80ff6"},
|
||||
@@ -27,6 +28,7 @@ version = "3.10.0"
|
||||
requires_python = ">=3.8"
|
||||
summary = "Async http client/server framework (asyncio)"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
dependencies = [
|
||||
"aiohappyeyeballs>=2.3.0",
|
||||
"aiosignal>=1.1.2",
|
||||
@@ -61,6 +63,7 @@ version = "1.3.1"
|
||||
requires_python = ">=3.7"
|
||||
summary = "aiosignal: a list of registered asynchronous callbacks"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
dependencies = [
|
||||
"frozenlist>=1.1.0",
|
||||
]
|
||||
@@ -75,6 +78,7 @@ version = "23.2.0"
|
||||
requires_python = ">=3.7"
|
||||
summary = "Classes Without Boilerplate"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
dependencies = [
|
||||
"importlib-metadata; python_version < \"3.8\"",
|
||||
]
|
||||
@@ -89,6 +93,7 @@ version = "1.15.1"
|
||||
requires_python = ">=3.8"
|
||||
summary = "static type checking for Python (but based)"
|
||||
groups = ["dev"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
dependencies = [
|
||||
"nodejs-wheel-binaries>=20.13.1",
|
||||
]
|
||||
@@ -103,6 +108,7 @@ version = "1.4.1"
|
||||
requires_python = ">=3.8"
|
||||
summary = "A list-like structure which implements collections.abc.MutableSequence"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
files = [
|
||||
{file = "frozenlist-1.4.1-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:a0cb6f11204443f27a1628b0e460f37fb30f624be6051d490fa7d7e26d4af3d0"},
|
||||
{file = "frozenlist-1.4.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:b46c8ae3a8f1f41a0d2ef350c0b6e65822d80772fe46b653ab6b6274f61d4a49"},
|
||||
@@ -129,6 +135,7 @@ version = "3.7"
|
||||
requires_python = ">=3.5"
|
||||
summary = "Internationalized Domain Names in Applications (IDNA)"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
files = [
|
||||
{file = "idna-3.7-py3-none-any.whl", hash = "sha256:82fee1fc78add43492d3a1898bfa6d8a904cc97d8427f683ed8e798d07761aa0"},
|
||||
{file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"},
|
||||
@@ -140,6 +147,7 @@ version = "6.0.5"
|
||||
requires_python = ">=3.7"
|
||||
summary = "multidict implementation"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
files = [
|
||||
{file = "multidict-6.0.5-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:f285e862d2f153a70586579c15c44656f888806ed0e5b56b64489afe4a2dbfba"},
|
||||
{file = "multidict-6.0.5-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:53689bb4e102200a4fafa9de9c7c3c212ab40a7ab2c8e474491914d2305f187e"},
|
||||
@@ -166,6 +174,7 @@ version = "20.16.0"
|
||||
requires_python = ">=3.7"
|
||||
summary = "unoffical Node.js package"
|
||||
groups = ["dev"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
files = [
|
||||
{file = "nodejs_wheel_binaries-20.16.0-py2.py3-none-macosx_10_15_x86_64.whl", hash = "sha256:5f36c3e2ad9d76505e685811ff838c69163a820bf424e96ed7cff40d845ee394"},
|
||||
{file = "nodejs_wheel_binaries-20.16.0-py2.py3-none-macosx_11_0_arm64.whl", hash = "sha256:8e23925f2fbe60a8439742de2a58e08b16a8e14235d066663b9f8d9c1d99026a"},
|
||||
@@ -182,6 +191,7 @@ version = "2.6.0"
|
||||
requires_python = ">=3.8"
|
||||
summary = "A Python wrapper for the Discord API"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
dependencies = [
|
||||
"aiohttp<4.0,>=3.6.0",
|
||||
"typing-extensions<5,>=4; python_version < \"3.11\"",
|
||||
@@ -197,6 +207,7 @@ version = "1.0.1"
|
||||
requires_python = ">=3.8"
|
||||
summary = "Read key-value pairs from a .env file and set them as environment variables"
|
||||
groups = ["dev"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
files = [
|
||||
{file = "python-dotenv-1.0.1.tar.gz", hash = "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca"},
|
||||
{file = "python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a"},
|
||||
@@ -208,6 +219,7 @@ version = "0.5.6"
|
||||
requires_python = ">=3.7"
|
||||
summary = "An extremely fast Python linter and code formatter, written in Rust."
|
||||
groups = ["dev"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
files = [
|
||||
{file = "ruff-0.5.6-py3-none-linux_armv6l.whl", hash = "sha256:a0ef5930799a05522985b9cec8290b185952f3fcd86c1772c3bdbd732667fdcd"},
|
||||
{file = "ruff-0.5.6-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:b652dc14f6ef5d1552821e006f747802cc32d98d5509349e168f6bf0ee9f8f42"},
|
||||
@@ -229,12 +241,25 @@ files = [
|
||||
{file = "ruff-0.5.6.tar.gz", hash = "sha256:07c9e3c2a8e1fe377dd460371c3462671a728c981c3205a5217291422209f642"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typing-extensions"
|
||||
version = "4.12.2"
|
||||
requires_python = ">=3.8"
|
||||
summary = "Backported and Experimental Type Hints for Python 3.8+"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
files = [
|
||||
{file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"},
|
||||
{file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yarl"
|
||||
version = "1.9.4"
|
||||
requires_python = ">=3.7"
|
||||
summary = "Yet another URL library"
|
||||
groups = ["default"]
|
||||
marker = "python_full_version == \"3.11.4\""
|
||||
dependencies = [
|
||||
"idna>=2.0",
|
||||
"multidict>=4.0",
|
||||
|
||||
@@ -20,6 +20,7 @@ classifiers = [
|
||||
requires-python = ">=3.11"
|
||||
dependencies = [
|
||||
"py-cord>=2.6.0",
|
||||
"typing-extensions<5,>=4.4.0",
|
||||
]
|
||||
version = "0.1.0"
|
||||
license = {text = "MIT"}
|
||||
@@ -110,7 +111,9 @@ ignore = [
|
||||
"ISC001", # Single line implicit string concatenation ("hi" "hey" -> "hihey")
|
||||
"ISC002", # Multi line implicit string concatenation
|
||||
|
||||
"DOC501"
|
||||
"DOC501",
|
||||
"DOC201",
|
||||
"PLR6301"
|
||||
]
|
||||
|
||||
[tool.ruff.lint.isort]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from collections.abc import Awaitable, Callable
|
||||
from inspect import isawaitable
|
||||
from typing import TypeGuard, TypeVar, Generic
|
||||
from typing import Generic, TypeGuard, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from typing import Self
|
||||
|
||||
import discord
|
||||
from typing_extensions import override
|
||||
|
||||
from .components import ReactiveButton
|
||||
from .components import Reactive
|
||||
|
||||
|
||||
class ReactiveView(discord.ui.View):
|
||||
@@ -15,10 +16,11 @@ class ReactiveView(discord.ui.View):
|
||||
disable_on_timeout: bool = False,
|
||||
):
|
||||
super().__init__(timeout=timeout, disable_on_timeout=disable_on_timeout)
|
||||
self._reactives: list[ReactiveButton] = []
|
||||
self._reactives: list[Reactive] = []
|
||||
|
||||
@override
|
||||
def add_item(self, item: discord.ui.Item[Self]) -> None:
|
||||
if isinstance(item, ReactiveButton):
|
||||
if isinstance(item, Reactive):
|
||||
self._reactives.append(item)
|
||||
super().add_item(item)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user