Merge pull request #7 from s-diaco/cursor/icon-excel-focus-b26a

Add modern Desktop icon and bring Excel to front
This commit is contained in:
2026-08-08 12:38:56 +03:30
committed by GitHub
8 changed files with 55 additions and 6 deletions

View File

@@ -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 |

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

BIN
desktop/xlsx-clean.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
desktop/xlsx-clean.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -71,6 +71,7 @@ exe = EXE(
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon="desktop/xlsx-clean.ico",
)
coll = COLLECT(

View File

@@ -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)