Name | ductile-ui JSON |
Version |
0.4.0
JSON |
| download |
home_page | None |
Summary | A library provides declarative ui for discord.py |
upload_time | 2024-11-10 04:13:42 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | MIT License Copyright (c) 2023 sushi-chaaaan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
discord
discord.py
ductile
ductile-ui
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ductile-ui


A library provides declarative UI for [discord.py](https://github.com/Rapptz/discord.py).
## Features
- Declarative UI, inspired by [React](https://react.dev/).
- Component-oriented with State
- Fully typed
## Installation
**Python3.10 or higher is required**
**discord.py^2.2.0 is required; any compatibility under 2.1.x or 1.x is not guaranteed**
Using the latest stable release of discord.py is recommended
```bash
pip install ductile-ui
```
## Usage/Examples
You can define component as return value of `View.render()`.
To store state, use `State`.
```python
# This example requires the 'message_content' privileged intent to function.
import random
import discord
from discord.ext import commands
from ductile import State, View, ViewObject
from ductile.controller import MessageableController
from ductile.ui import Button
class Bot(commands.Bot):
def __init__(self) -> None:
super().__init__(command_prefix="!", intents=discord.Intents.all())
async def on_ready(self) -> None:
print(f"Logged in as {self.user}")
print("Ready!")
class CounterView(View):
def __init__(self) -> None:
super().__init__()
self.count = State(0, self)
def render(self) -> ViewObject:
e = discord.Embed(title="Counter", description=f"Count: {self.count.get_state()}")
async def handle_increment(interaction: discord.Interaction) -> None:
await interaction.response.defer()
self.count.set_state(lambda x: x + 1)
async def handle_decrement(interaction: discord.Interaction) -> None:
await interaction.response.defer()
self.count.set_state(lambda x: x - 1)
async def stop(interaction: discord.Interaction) -> None:
await interaction.response.defer()
self.stop()
# Define UI using ViewObject
return ViewObject(
embeds=[e],
components=[
Button("+1", style={"color": "blurple", "row": 0}, on_click=handle_increment),
Button("-1", style={"color": "blurple", "row": 0}, on_click=handle_decrement),
Button(
"random",
style={"color": "green", "row": 1},
# if you passed synchronous function to Button.on_click,
# library automatically calls `await interaction.response.defer()`.
on_click=lambda _: self.count.set_state(random.randint(0, 100)),
),
Button("stop", style={"color": "red", "row": 1}, on_click=stop),
],
)
bot = Bot()
@bot.command(name="counter")
async def send_counter(ctx: commands.Context) -> None:
controller = MessageableController(CounterView(), messageable=ctx.channel)
await controller.send()
timed_out, states = await controller.wait()
await ctx.send(f"Timed out: {timed_out}\nCount: {states['count']}")
bot.run("MY_COOL_BOT_TOKEN")
```
Raw data
{
"_id": null,
"home_page": null,
"name": "ductile-ui",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "discord, discord.py, ductile, ductile-ui",
"author": null,
"author_email": "sushichan044 <mail@sushichan.live>",
"download_url": "https://files.pythonhosted.org/packages/56/42/e2c648dc67b155e8c044212b5ba08d7a454343da127144cb1338d739b806/ductile_ui-0.4.0.tar.gz",
"platform": null,
"description": "\n# ductile-ui\n\n\n\n\nA library provides declarative UI for [discord.py](https://github.com/Rapptz/discord.py).\n\n## Features\n\n- Declarative UI, inspired by [React](https://react.dev/).\n- Component-oriented with State\n- Fully typed\n\n## Installation\n\n**Python3.10 or higher is required**\n\n**discord.py^2.2.0 is required; any compatibility under 2.1.x or 1.x is not guaranteed**\n\nUsing the latest stable release of discord.py is recommended\n\n```bash\n pip install ductile-ui\n```\n\n## Usage/Examples\n\nYou can define component as return value of `View.render()`.\nTo store state, use `State`.\n\n```python\n# This example requires the 'message_content' privileged intent to function.\n\n\nimport random\n\nimport discord\nfrom discord.ext import commands\nfrom ductile import State, View, ViewObject\nfrom ductile.controller import MessageableController\nfrom ductile.ui import Button\n\n\nclass Bot(commands.Bot):\n def __init__(self) -> None:\n super().__init__(command_prefix=\"!\", intents=discord.Intents.all())\n\n async def on_ready(self) -> None:\n print(f\"Logged in as {self.user}\")\n print(\"Ready!\")\n\n\nclass CounterView(View):\n def __init__(self) -> None:\n super().__init__()\n self.count = State(0, self)\n\n def render(self) -> ViewObject:\n e = discord.Embed(title=\"Counter\", description=f\"Count: {self.count.get_state()}\")\n\n async def handle_increment(interaction: discord.Interaction) -> None:\n await interaction.response.defer()\n self.count.set_state(lambda x: x + 1)\n\n async def handle_decrement(interaction: discord.Interaction) -> None:\n await interaction.response.defer()\n self.count.set_state(lambda x: x - 1)\n\n async def stop(interaction: discord.Interaction) -> None:\n await interaction.response.defer()\n self.stop()\n\n # Define UI using ViewObject\n return ViewObject(\n embeds=[e],\n components=[\n Button(\"+1\", style={\"color\": \"blurple\", \"row\": 0}, on_click=handle_increment),\n Button(\"-1\", style={\"color\": \"blurple\", \"row\": 0}, on_click=handle_decrement),\n Button(\n \"random\",\n style={\"color\": \"green\", \"row\": 1},\n # if you passed synchronous function to Button.on_click,\n # library automatically calls `await interaction.response.defer()`.\n on_click=lambda _: self.count.set_state(random.randint(0, 100)),\n ),\n Button(\"stop\", style={\"color\": \"red\", \"row\": 1}, on_click=stop),\n ],\n )\n\n\nbot = Bot()\n\n\n@bot.command(name=\"counter\")\nasync def send_counter(ctx: commands.Context) -> None:\n controller = MessageableController(CounterView(), messageable=ctx.channel)\n await controller.send()\n timed_out, states = await controller.wait()\n await ctx.send(f\"Timed out: {timed_out}\\nCount: {states['count']}\")\n\n\nbot.run(\"MY_COOL_BOT_TOKEN\")\n\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2023 sushi-chaaaan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "A library provides declarative ui for discord.py",
"version": "0.4.0",
"project_urls": {
"Issues": "https://github.com/sushi-chaaaan/ductile-ui/issues",
"Repository": "https://github.com/sushi-chaaaan/ductile-ui"
},
"split_keywords": [
"discord",
" discord.py",
" ductile",
" ductile-ui"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "27283f2eec0a7c67838b7e331c5c19290615cffce53f40b80c6a5a877b4753e6",
"md5": "5abb75e34762ee886d8cf725ec575d90",
"sha256": "cc47758700c8e716d8a81f935f5e5e4810ef8206efa565a1bbb857528107f895"
},
"downloads": -1,
"filename": "ductile_ui-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5abb75e34762ee886d8cf725ec575d90",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 22524,
"upload_time": "2024-11-10T04:13:41",
"upload_time_iso_8601": "2024-11-10T04:13:41.000426Z",
"url": "https://files.pythonhosted.org/packages/27/28/3f2eec0a7c67838b7e331c5c19290615cffce53f40b80c6a5a877b4753e6/ductile_ui-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "5642e2c648dc67b155e8c044212b5ba08d7a454343da127144cb1338d739b806",
"md5": "aa11f6e090e2f605d08715c92751fd59",
"sha256": "7c4a85773bafb964abd989873d0d8fdafb527455d14653a15bb03e65726a42c9"
},
"downloads": -1,
"filename": "ductile_ui-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "aa11f6e090e2f605d08715c92751fd59",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 58809,
"upload_time": "2024-11-10T04:13:42",
"upload_time_iso_8601": "2024-11-10T04:13:42.993985Z",
"url": "https://files.pythonhosted.org/packages/56/42/e2c648dc67b155e8c044212b5ba08d7a454343da127144cb1338d739b806/ductile_ui-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-10 04:13:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sushi-chaaaan",
"github_project": "ductile-ui",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ductile-ui"
}