Add XVIIx64.exe to LTspice exes

This commit is contained in:
Peter 2023-11-25 13:33:24 +08:00
parent db2adcb15e
commit f076170341
2 changed files with 13 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,3 +1,4 @@
import logging
import os import os
from typing import List from typing import List
import win32gui import win32gui
@ -11,6 +12,8 @@ data = None
rpc.connect() rpc.connect()
logging.basicConfig(level=logging.INFO)
def find_active_processes(name: str) -> List[int]: def find_active_processes(name: str) -> List[int]:
processes = [] processes = []
@ -23,7 +26,8 @@ def find_active_processes(name: str) -> List[int]:
return processes return processes
LTSPICE_NAME = "LTSPICE.exe" LTSPICE_NAME_0 = "LTSPICE.exe"
LTSPICE_NAME_1 = "XVIIx64.exe"
last_state = {} last_state = {}
last_program = {"pid": None, "path": None} last_program = {"pid": None, "path": None}
@ -101,8 +105,8 @@ def handle_ltspice(title: str) -> None:
} }
if state != last_state: if state != last_state:
print("UPDATED!") logging.info(f"update rpc! {state['details']}")
print(filename, file, ext) logging.info(f"{filename=} {file=} {ext=}")
rpc.update( rpc.update(
**state, **state,
start=int(time.time()), start=int(time.time()),
@ -117,16 +121,18 @@ def handle_ltspice(title: str) -> None:
def main() -> None: def main() -> None:
global last_program global last_program
WINDOW_HANDLERS = { WINDOW_HANDLERS = {
LTSPICE_NAME: handle_ltspice, LTSPICE_NAME_0: handle_ltspice,
LTSPICE_NAME_1: handle_ltspice,
} }
while True: while True:
time.sleep(3)
foreground_hwnd = win32gui.GetForegroundWindow() foreground_hwnd = win32gui.GetForegroundWindow()
pid = win32process.GetWindowThreadProcessId(foreground_hwnd) pid = win32process.GetWindowThreadProcessId(foreground_hwnd)
if pid[-1] >= 0: if pid[-1] >= 0:
try: try:
active_process = psutil.Process(pid[-1]) active_process = psutil.Process(pid[-1])
if active_process.name() in WINDOW_HANDLERS.keys(): if active_process.name() in WINDOW_HANDLERS.keys():
logging.info(pid[-1])
logging.info(active_process.name())
handler = WINDOW_HANDLERS[active_process.name()] handler = WINDOW_HANDLERS[active_process.name()]
if handler(win32gui.GetWindowText(foreground_hwnd)): if handler(win32gui.GetWindowText(foreground_hwnd)):
last_program = { last_program = {
@ -139,8 +145,9 @@ def main() -> None:
"pid" "pid"
] not in find_active_processes(last_program["path"]): ] not in find_active_processes(last_program["path"]):
last_program = {"pid": None, "path": None} last_program = {"pid": None, "path": None}
print("Clear RPC - program closed") logging.info("Clear RPC - program closed")
rpc.clear() rpc.clear()
time.sleep(3)
if __name__ == "__main__": if __name__ == "__main__":