/
lemut
/
cifranet
Обзор
Документация
Войти
/
lemut
/
cifranet
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
aaa.py
50 строк
2 KB
lemut
first_commit
23 июл 2026, 11:49
23 июл 2026, 11:49
910f940
Код
Авторство
О чём код?
import dash from dash import dcc, html, Input, Output, State import dash_cytoscape as cyto import json app = dash.Dash(__name__) app.layout = html.Div([ html.Button("Read Screen Positions", id="btn-read", n_clicks=0), # Visual container to display the positions we read from the screen html.Pre(id="output-positions-display", style={'border': '1px solid #ccc', 'padding': '10px'}), cyto.Cytoscape( id='cytoscape-net', layout={'name': 'preset'}, style={'width': '100%', 'height': '400px'}, elements=[ {'data': {'id': 'A', 'label': 'Node A'}, 'position': {'x': 100, 'y': 100}}, {'data': {'id': 'B', 'label': 'Node B'}, 'position': {'x': 250, 'y': 200}}, {'data': {'id': 'A-B', 'source': 'A', 'target': 'B'}} ] ) ]) @app.callback( Output("output-positions-display", "children"), Input("btn-read", "n_clicks"), State("cytoscape-net", "elements"), # Crucial: State captures live screen coordinates prevent_initial_call=True ) def read_current_screen_positions(n_clicks, live_elements): # Dictionary to hold our parsed screen data screen_positions = {} # Loop through what is currently rendered on the screen for el in live_elements: # Check if the element is a node (only nodes contain 'position') if 'position' in el: node_id = el['data']['id'] current_x = el['position']['x'] current_y = el['position']['y'] screen_positions[node_id] = {'x': current_x, 'y': current_y} # Return as formatted text to display on screen return json.dumps(screen_positions, indent=2) if __name__ == '__main__': app.run(debug=True)