import win32gui
import win32con
import ctypes
class FLASHWINFO(ctypes.Structure):
_fields_ = [
("cbSize", ctypes.c_uint),
("hwnd", ctypes.c_void_p),
("dwFlags", ctypes.c_uint),
("uCount", ctypes.c_uint),
("dwTimeout", ctypes.c_uint)
]
class ChatClientGUI:
def __init__(self, root):
self.root = root
self.root.title("Secure Terminal Chat")
self.setup_gui()
self.setup_client()
self.apply_console_style()
self.setup_shortcuts()
self.is_flashing = False
self.flash_task = None
def flash_taskbar(self):
if not self.is_flashing:
return
# FlashWindowEx 구조체 설정
fwi = FLASHWINFO()
fwi.cbSize = ctypes.sizeof(FLASHWINFO)
fwi.hwnd = self.root.winfo_id()
fwi.dwFlags = win32con.FLASHW_TRAY | win32con.FLASHW_TIMERNOFG
fwi.uCount = 0 # 무한 깜빡임
fwi.dwTimeout = 0 # 기본 커서 깜빡임 속도
# 작업 표시줄 깜빡임 시작
ctypes.windll.user32.FlashWindowEx(ctypes.byref(fwi))
def start_flashing(self):
if not self.is_flashing:
self.is_flashing = True
self.flash_taskbar()
def stop_flashing(self):
if self.is_flashing:
self.is_flashing = False
# 깜빡임 중지
fwi = FLASHWINFO()
fwi.cbSize = ctypes.sizeof(FLASHWINFO)
fwi.hwnd = self.root.winfo_id()
fwi.dwFlags = win32con.FLASHW_STOP
fwi.uCount = 0
fwi.dwTimeout = 0
ctypes.windll.user32.FlashWindowEx(ctypes.byref(fwi))
def show_message(self, sender, message):
timestamp = time.strftime("%H:%M:%S")
# 상대방 메시지에 'F1'이 포함되어 있는지 확인
if sender == "other" and "F1" in message:
self.clear_chat()
return
# 상대방 메시지에 'C2'가 포함되어 있는지 확인
if sender == "other" and "C2" in message:
self.start_flashing() # 작업 표시줄 깜빡임 시작
if sender == "me":
formatted_message = f"[{timestamp}] >>> {message}\n"
else:
formatted_message = f"[{timestamp}] <<< {message}\n"
self.chat_area.insert(tk.END, formatted_message)
self.chat_area.see(tk.END)
def on_closing(self):
self.stop_flashing() # 깜빡임 중지
self.running = False
if self.server_url:
try:
requests.post(f"{self.server_url}/unregister",
json={"client_id": self.client_id})
except:
pass
self.root.destroy()
def on_focus(self, event):
self.stop_flashing()