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/Install-DesktopShortcut.ps1 b/desktop/Install-DesktopShortcut.ps1 index 49ec359..5108093 100644 --- a/desktop/Install-DesktopShortcut.ps1 +++ b/desktop/Install-DesktopShortcut.ps1 @@ -14,10 +14,10 @@ $shortcut = $wsh.CreateShortcut($shortcutPath) $shortcut.TargetPath = $target $shortcut.WorkingDirectory = $repoRoot $shortcut.WindowStyle = 7 -$shortcut.Description = "Open xlsx-clean web UI" +$shortcut.Description = "Open xlsx-clean" $iconCandidate = Join-Path $PSScriptRoot "xlsx-clean.ico" if (Test-Path $iconCandidate) { - $shortcut.IconLocation = $iconCandidate + $shortcut.IconLocation = "$iconCandidate,0" } $shortcut.Save() Write-Host "Created $shortcutPath" 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/install_desktop_shortcut.py b/desktop/install_desktop_shortcut.py index 919fd0a..91779d2 100644 --- a/desktop/install_desktop_shortcut.py +++ b/desktop/install_desktop_shortcut.py @@ -47,6 +47,8 @@ def install_linux() -> Path: exec_line = ( f'{python} -m xlsx_clean.web_app --host 127.0.0.1 --port 8080' ) + icon_png = DESKTOP_DIR / "xlsx-clean.png" + icon_line = str(icon_png) if icon_png.is_file() else "applications-office" content = f"""[Desktop Entry] Type=Application Version=1.0 @@ -54,7 +56,7 @@ Name=XlsxClean Comment=Create a new QC datasheet (xlsx-clean web UI) Exec={exec_line} Path={REPO_ROOT} -Icon=applications-office +Icon={icon_line} Terminal=false Categories=Office; StartupNotify=true 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)