Comments (2)
TODO:
Next
/Prev
/etc transitions set as callbacks.- Transitions which set in code. (AST?)
from aiogram_dialog.
Using diagram
:
from typing import List, Sequence, Tuple
from aiogram.dispatcher.filters.state import State
from diagrams import Diagram, Cluster, Edge
from diagrams.generic.device import Tablet
from aiogram_dialog import Dialog
from aiogram_dialog.widgets.kbd import Group, Back, Cancel, Start, SwitchTo, Next
def walk_keyboard(nodes, dialog, starts: List[Tuple[State, State]], current_state: State, keyboards: Sequence):
for kbd in keyboards:
if isinstance(kbd, Group):
walk_keyboard(nodes, dialog, starts, current_state, kbd.buttons)
elif isinstance(kbd, Start):
nodes[current_state] >> Edge(color="#338a3e") >> nodes[kbd.state]
elif isinstance(kbd, SwitchTo):
nodes[current_state] >> Edge() >> nodes[kbd.state]
elif isinstance(kbd, Next):
new_state = dialog.states[dialog.states.index(current_state) + 1]
nodes[current_state] >> Edge() >> nodes[new_state]
elif isinstance(kbd, Back):
new_state = dialog.states[dialog.states.index(current_state) - 1]
nodes[current_state] >> Edge(color="grey") >> nodes[new_state]
elif isinstance(kbd, Cancel):
for from_, to_ in starts:
if to_.group == current_state.group:
nodes[current_state] >> Edge(color="grey", style="dashed") >> nodes[from_]
def find_starts(current_state, keyboards: Sequence):
for kbd in keyboards:
if isinstance(kbd, Group):
yield from find_starts(current_state, kbd.buttons)
elif isinstance(kbd, Start):
yield current_state, kbd.state
def render(dialogs: List[Dialog]):
with Diagram('Aiogram Dialog', outformat="png", show=False):
nodes = {}
for dialog in dialogs:
with Cluster(dialog.states_group_name()):
for window in dialog.windows.values():
nodes[window.get_state()] = Tablet(label=window.get_state().state)
starts = []
for dialog in dialogs:
for window in dialog.windows.values():
starts.extend(find_starts(window.get_state(), [window.keyboard]))
for dialog in dialogs:
for window in dialog.windows.values():
walk_keyboard(nodes, dialog, starts, window.get_state(), [window.keyboard])
if __name__ == '__main__':
render([
# here put you dialogs
])
from aiogram_dialog.
Related Issues (20)
- ListGroup id HOT 1
- Window events
- ManagerRadio unchecked all HOT 1
- How to use old windows after restarting HOT 4
- show_mode in SwitchTo Widged
- Implementing Multiple Dynamic Counter Widgets with Text Parameters in aiogram-dialog HOT 1
- ShowMode in manager.start() doesn't work as expected by some users HOT 2
- Updating the examples.
- Launching a dialog with the transmission of dynamic data for the status of the checkbox buttons HOT 1
- Start calendar widget with scope Year HOT 1
- Calendar bug while selected date less than 1970 HOT 2
- How i can store data in state using FSMContext HOT 4
- Using payments HOT 1
- Coverage report falied on Jinja widgets HOT 1
- Handling InaccessibleMessage in get_media_id Function
- Best solution for creating different count of buttons
- LinkPreview widget HOT 1
- Reply for button on message HOT 3
- Multiselect и Select с предустановленным состоянием HOT 1
- New rendering protocol
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiogram_dialog.