hi
I have an app, and I whant that when tab-6 is opened and another program starts, the app should close …
I can’t manage to make it with chatgpt.
How could I do this?
# Nombre del proceso asociado a PokerStars
nombre_del_proceso_pokerstars = 'PokerStars.exe'
# Diseño del sidebar
sidebar = html.Div(
[
html.H2("Poker Utils", className="display-4", style=SIDEBAR_STYLE),
html.Hr(),
html.P("The edge", className="lead", style=SIDEBAR_STYLE),
dbc.Nav(
[
dbc.NavLink("Dropdown", id='navlink-tab1', href="/", active="exact"),
dbc.NavLink("All players report", id='navlink-tab2', href="/page-2", active="exact"),
dbc.NavLink("1 player report", id='navlink-tab3', href="/page-6", active="exact"),
dbc.NavLink("Utils", id='navlink-tab4', href="/page-1", active="exact"),
dbc.NavLink("EV winnings", id='navlink-tab5', href="/page-3", active="exact"),
dbc.NavLink("Ranges", id='navlink-tab6', href="/page-7", active="exact"),
# dbc.NavLink("Solved Preflop", id='navlink-tab7', href="/page-4", active="exact"),
dbc.NavLink("Contact", id='navlink-tab8', href="/page-5", active="exact"),
],
vertical=True,
pills=True,
style=SIDEBAR_STYLE,
),
],
style=SIDEBAR_STYLE,
)
# Diseño del contenido principal
content = html.Div(id='page-content', style=SIDEBAR_STYLE)
# Diseño de la aplicación completa
app.layout = html.Div([dcc.Location(id='url'), sidebar, content])
# Callback para ocultar la pestaña específica si PokerStars está en ejecución y cerrar la aplicación si la pestaña ya está abierta
@app.callback(
[Output('navlink-tab6', 'hidden'),
Output('url', 'pathname')],
Input('url', 'pathname'),
prevent_initial_call=True
)
def update_navlink_tab6(pathname):
# Obtén el estado de PokerStars
pokerstars_abierto = check_pokerstars()
# Redirecciona a la página de cierre si "Ranges" está abierta y PokerStars se inicia
if pathname == '/page-7' and pokerstars_abierto:
sys.modules[__name__].__dict__['_exit_code'] = 1
return True, '/shutdown'
# Oculta la pestaña "Ranges" si PokerStars está en ejecución
hidden = pokerstars_abierto
new_pathname = pathname
if pathname == '/page-7' and pokerstars_abierto:
# Redirecciona a la página de inicio si "Ranges" está abierta y PokerStars se inicia
new_pathname = '/'
return hidden, new_pathname
# Página de cierre
shutdown_page = html.Div([
html.H2("La aplicación se cerrará debido a la ejecución de PokerStars."),
html.P("Por favor, cierre la pestaña del navegador."),
])
# Función para verificar si PokerStars está abierto
def check_pokerstars():
if platform.system() == 'Windows':
# En Windows, verifica si el proceso PokerStars.exe está en ejecución
for process in psutil.process_iter(['pid', 'name']):
if nombre_del_proceso_pokerstars.lower() in process.info['name'].lower():
return True
else:
# Puedes ajustar la lógica para otros sistemas operativos si es necesario
return False