Skip to content

Commit 15142df

Browse files
Copilotalebmorais
andcommitted
Consolidate ClienteWindows2 improvements into ClienteWindows and remove duplicate file
Co-authored-by: alebmorais <196795598+alebmorais@users.noreply.github.com>
1 parent a9ed161 commit 15142df

2 files changed

Lines changed: 38 additions & 946 deletions

File tree

ClienteWindows

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ import tkinter as tk
1313
from tkinter import messagebox, ttk
1414
from urllib import request as urllib_request
1515

16+
# Função utilitária para lidar com pausas sem depender de input() em ambientes
17+
# onde stdin pode não estar disponível (ex: execução por atalho ou como
18+
# aplicativo empacotado).
19+
def pause_for_user(prompt, delay_seconds=3):
20+
"""Exibe uma mensagem de pausa sem exigir entrada quando stdin não existe."""
21+
try:
22+
if sys.stdin and sys.stdin.isatty():
23+
input(prompt)
24+
return
25+
except (EOFError, RuntimeError):
26+
pass
27+
28+
# Ambiente não interativo: apenas informar e aguardar brevemente para que
29+
# o usuário leia a mensagem.
30+
message = prompt.strip() or "Pressione Enter para continuar..."
31+
print(message)
32+
time.sleep(max(delay_seconds, 0))
33+
1634
# Tentar importar bibliotecas opcionais
1735

1836
try:
@@ -107,15 +125,16 @@ class WindowsDesktopClient:
107125

108126
def setup_gui(self):
109127
"""Criar interface do cliente."""
128+
# Paleta comum para fallback/legado
110129
self.colors = {
111-
"bg_primary": "#1a237e",
112-
"bg_secondary": "#283593",
113-
"bg_accent": "#3f51b5",
114-
"text_primary": "#ffffff",
115-
"text_secondary": "#e8eaf6",
116-
"button_active": "#4caf50",
117-
"button_hover": "#66bb6a",
118-
"border": "#5c6bc0",
130+
"bg_primary": "#1a237e", # Azul escuro principal
131+
"bg_secondary": "#283593", # Azul médio
132+
"bg_accent": "#3f51b5", # Azul claro
133+
"text_primary": "#ffffff", # Branco
134+
"text_secondary": "#e8eaf6", # Branco levemente azulado
135+
"button_active": "#4caf50", # Verde
136+
"button_hover": "#66bb6a", # Verde claro
137+
"border": "#5c6bc0", # Azul para bordas
119138
}
120139

121140
pi_reachable = self.is_pi_reachable()
@@ -131,6 +150,7 @@ class WindowsDesktopClient:
131150
)
132151
return
133152

153+
# Necessário criar janela Tk para fallback ou interface legada
134154
self.root = tk.Tk()
135155
self.root.title("Automação Médica - Dr. Alessandra Morais")
136156
self.root.geometry("1000x700")
@@ -142,13 +162,15 @@ class WindowsDesktopClient:
142162
self.build_offline_screen()
143163
return
144164

165+
# Quando pywebview não está disponível, mantemos a UI Tk existente
145166
if not WEBVIEW_AVAILABLE:
146167
print(
147168
"pywebview não foi encontrado. Utilizando interface Tkinter tradicional."
148169
)
149170

150171
self.ui_mode = "legacy"
151172

173+
# Configurar estilo ttk apenas no modo legado
152174
style = ttk.Style()
153175
style.theme_use("clam")
154176
style.configure("Dark.TFrame", background=self.colors["bg_primary"])
@@ -182,7 +204,7 @@ class WindowsDesktopClient:
182204
self.root.bind("<F11>", lambda e: self.toggle_fullscreen())
183205

184206
def build_offline_screen(self):
185-
"""Exibir mensagem simples quando o Pi estiver offline."""
207+
"""Exibir tela simples informando ausência de conexão."""
186208
container = tk.Frame(self.root, bg=self.colors["bg_primary"])
187209
container.pack(expand=True, fill=tk.BOTH, padx=40, pady=40)
188210

@@ -197,12 +219,11 @@ class WindowsDesktopClient:
197219
)
198220
title.pack(pady=(0, 20))
199221

200-
self.fallback_status_var = tk.StringVar(
201-
value=(
202-
"Verifique se o Raspberry Pi está ligado e conectado à mesma rede. "
203-
"Depois, tente novamente."
204-
)
222+
instructions = (
223+
"Verifique se o Raspberry Pi está ligado e conectado à rede. "
224+
"Conecte o computador ao mesmo Wi-Fi ou cabo e tente novamente."
205225
)
226+
self.fallback_status_var = tk.StringVar(value=instructions)
206227
status_label = tk.Label(
207228
container,
208229
textvariable=self.fallback_status_var,
@@ -276,7 +297,7 @@ class WindowsDesktopClient:
276297
)
277298

278299
def _open_webview_after_fallback(self):
279-
"""Encerrar Tk e abrir a webview."""
300+
"""Encerrar a janela Tk e preparar a webview."""
280301
if not WEBVIEW_AVAILABLE:
281302
return
282303
self.pending_webview = True
@@ -892,15 +913,14 @@ def main():
892913
print(f" - {dep}")
893914
print("Para instalar: pip install " + " ".join(missing_deps))
894915
print("O cliente funcionará com funcionalidades limitadas.")
895-
input("Pressione Enter para continuar...")
916+
pause_for_user("Pressione Enter para continuar...")
896917

897918
# Iniciar cliente
898919
try:
899920
client = WindowsDesktopClient()
900921
client.run()
901922
except Exception as e:
902-
print(f"Erro ao iniciar cliente: {e}")
903-
input("Pressione Enter para sair...")
923+
print(f"Erro inesperado ao iniciar cliente: {type(e).__name__} - {e}")
904924

905925

906926
if __name__ == "__main__":

0 commit comments

Comments
 (0)