diff --git a/README.md b/README.md index 64fd02b..78da27c 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,14 @@ No terminal commands are required for operators. 2. Every day: double-click the **XlsxClean** icon on the Desktop 3. In the app window: choose **Set**, **Ink color**, enter **Serial**, click **Create datasheet** -`Setup.bat` creates `.venv` with uv, installs the package, and adds the Desktop shortcut. +`Setup.bat` creates `.venv` with uv, installs the package, and adds the Desktop shortcut +(using the modern icon in `desktop\xlsx-clean.ico`). The shortcut runs `desktop\XlsxClean.vbs` and opens one dedicated window (via pywebview). Closing that window stops the app. +When you **Create** with the **com** backend, Excel is maximized and brought to the front +after the new workbook is saved. + If something fails, use **`desktop\XlsxClean.bat`** instead — it shows a console with errors. To force the old “open in default browser” behavior for debugging: @@ -117,6 +121,7 @@ Windows CLI helper: `src\xlsx_clean\new_xslx.bat` | Path | Purpose | |------|---------| +| `desktop/xlsx-clean.ico` | Modern Windows Desktop / exe icon | | `desktop/Setup.bat` | Windows one-time setup via uv + Desktop shortcut | | `desktop/Install-DesktopShortcut.bat` | Create Desktop icon only (Windows) | | `desktop/XlsxClean.vbs` | Silent double-click launcher | diff --git a/desktop/build_windows_exe.bat b/desktop/build_windows_exe.bat index 65eb8c6..46377a9 100644 --- a/desktop/build_windows_exe.bat +++ b/desktop/build_windows_exe.bat @@ -48,11 +48,13 @@ echo Creating Desktop shortcut to the exe... powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "$desk=[Environment]::GetFolderPath('Desktop');" ^ "$lnk=Join-Path $desk 'XlsxClean.lnk';" ^ + "$ico=Join-Path '%CD%' 'desktop\xlsx-clean.ico';" ^ "$w=New-Object -ComObject WScript.Shell;" ^ "$s=$w.CreateShortcut($lnk);" ^ "$s.TargetPath='%EXE%';" ^ "$s.WorkingDirectory='%~dp0..\dist\XlsxClean';" ^ "$s.Description='Open xlsx-clean';" ^ + "if (Test-Path $ico) { $s.IconLocation = $ico };" ^ "$s.Save();" ^ "Write-Host Created $lnk" diff --git a/desktop/xlsx-clean.ico b/desktop/xlsx-clean.ico new file mode 100644 index 0000000..b8c90df Binary files /dev/null and b/desktop/xlsx-clean.ico differ diff --git a/desktop/xlsx-clean.png b/desktop/xlsx-clean.png new file mode 100644 index 0000000..3489509 Binary files /dev/null and b/desktop/xlsx-clean.png differ diff --git a/packaging/xlsx_clean.spec b/packaging/xlsx_clean.spec index ee861e0..93c51a0 100644 --- a/packaging/xlsx_clean.spec +++ b/packaging/xlsx_clean.spec @@ -71,6 +71,7 @@ exe = EXE( target_arch=None, codesign_identity=None, entitlements_file=None, + icon="desktop/xlsx-clean.ico", ) coll = COLLECT( diff --git a/src/xlsx_clean/com_backend.py b/src/xlsx_clean/com_backend.py index 05f031a..3040c03 100644 --- a/src/xlsx_clean/com_backend.py +++ b/src/xlsx_clean/com_backend.py @@ -5,6 +5,45 @@ from __future__ import annotations from pathlib import Path +def _bring_excel_to_front(excel, workbook) -> None: + """Maximize and force Excel ahead of other windows (e.g. NiceGUI).""" + import win32com.client as win32 + import win32con + import win32gui + + excel.Visible = True + excel.WindowState = win32.constants.xlMaximized + try: + workbook.Activate() + except Exception: + pass + try: + hwnd = int(excel.Hwnd) + win32gui.ShowWindow(hwnd, win32con.SW_RESTORE) + win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE) + # Allow SetForegroundWindow to succeed when another app has focus. + try: + import win32api + import win32process + + fg = win32gui.GetForegroundWindow() + fg_tid, _ = win32process.GetWindowThreadProcessId(fg) + our_tid = win32api.GetCurrentThreadId() + if fg_tid != our_tid: + win32process.AttachThreadInput(our_tid, fg_tid, True) + try: + win32gui.SetForegroundWindow(hwnd) + finally: + win32process.AttachThreadInput(our_tid, fg_tid, False) + else: + win32gui.SetForegroundWindow(hwnd) + except Exception: + win32gui.SetForegroundWindow(hwnd) + except Exception: + # Focus stealing can fail under some Windows policies; create still succeeded. + pass + + def clean_workbook_com( source: Path | str, destination: Path | str, @@ -60,5 +99,5 @@ def clean_workbook_com( worksheet.Range(a1).Value = batch_serial workbook.SaveAs(str(destination.resolve())) - if maximize: - excel.WindowState = win32.constants.xlMaximized + if maximize or visible: + _bring_excel_to_front(excel, workbook)