Compare commits

..

13 Commits

Author SHA1 Message Date
Cursor Agent
ed2573d8e4 Require the combobox mousedown handler to call open().
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
The previous substring only checked that a mousedown listener exists.

Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 08:43:17 +00:00
Cursor Agent
9121200bfa Reopen combobox on input mousedown after selection.
Selecting an option closes the list without blurring the input, so a later
click never fires focus. Open the panel on mousedown as well.

Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 08:42:50 +00:00
Cursor Agent
31cd1783a1 Sync the ink combobox text as soon as the set's ink list rebuilds.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Previously the visible value stayed on the old ink until the box was
clicked, because rebuild only copied the select when the input was empty.

Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 08:18:11 +00:00
Cursor Agent
4fdccfb805 Place field labels in document flow above the inputs.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 08:05:22 +00:00
Cursor Agent
1b933d9042 Give field labels more clearance above the input borders.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 08:03:54 +00:00
Cursor Agent
97130034dd Sit field labels just above the boxes, clear of the border.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 08:02:27 +00:00
Cursor Agent
653d569149 Revert "Float field labels on focus or value, Material outlined style."
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
This reverts commit 757781f7a0.
2026-08-15 07:59:54 +00:00
Cursor Agent
757781f7a0 Float field labels on focus or value, Material outlined style.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Empty labels sit inside the box; they move up to the border when the
field is focused or has a value.

Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 07:53:44 +00:00
Cursor Agent
0d6c215fa7 Set field-label backgrounds to 50% opacity of the canvas color.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 07:45:46 +00:00
Cursor Agent
48d9356d10 Make floating field labels transparent so the grid shows through.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 07:37:45 +00:00
Cursor Agent
6d27bceb14 Stop the form panel from stretching so the graph-paper canvas shows through.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 07:32:25 +00:00
Cursor Agent
f2150f9243 Flatten GUI chrome so the form sits on the graph-paper canvas.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Remove the nested traffic-light window, drop desktop/demo.html, and keep
the OmniRoute grid visible behind the operator form in both themes.

Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 07:30:02 +00:00
Cursor Agent
95cc827a0a Restyle New QC Sheet GUI to match OmniRoute visual language.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Dark graph-paper canvas, coral-to-violet tokens, traffic-light card chrome, and a terminal-style status panel replace the teal Material form while keeping the Set/Ink/Serial workflow and pywebview bridge.

Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
2026-08-15 07:16:42 +00:00
2 changed files with 8 additions and 170 deletions

View File

@@ -2,78 +2,17 @@
from __future__ import annotations from __future__ import annotations
import logging
import shutil
import sys
from pathlib import Path from pathlib import Path
# Excel xlMaximized — avoid win32.constants when gen_py early-binding cache is corrupt.
_XL_MAXIMIZED = -4137
_log = logging.getLogger("xlsx_clean.create")
def _is_gen_py_cache_error(exc: BaseException) -> bool:
"""True for the known corrupt gen_py AttributeError (CLSIDTo*Map missing)."""
if not isinstance(exc, AttributeError):
return False
msg = str(exc)
return "CLSIDToClassMap" in msg or "CLSIDToPackageMap" in msg
def _clear_gen_py_cache() -> Path | None:
"""Remove win32com's generated typelib cache and drop it from sys.modules."""
import win32com
gen_path = Path(win32com.__gen_path__)
for name in [m for m in sys.modules if m.startswith("win32com.gen_py")]:
del sys.modules[name]
if gen_path.is_dir():
shutil.rmtree(gen_path, ignore_errors=True)
return gen_path
return None
def _excel_application():
"""Return Excel.Application, recovering from a corrupt win32com gen_py cache.
``gencache.EnsureDispatch`` writes early-binding wrappers under ``%TEMP%\\gen_py``.
Interrupted or partial writes leave modules without ``CLSIDToClassMap`` /
``CLSIDToPackageMap``; deleting that folder and retrying fixes it (same as the
manual workaround). Falls back to late-bound ``Dispatch`` if rebuild still fails.
"""
import win32com.client as win32
try:
return win32.gencache.EnsureDispatch("Excel.Application")
except AttributeError as exc:
if not _is_gen_py_cache_error(exc):
raise
cleared = _clear_gen_py_cache()
_log.warning(
"Corrupt win32com gen_py cache (%s); cleared %s and retrying",
exc,
cleared or "(missing)",
)
try:
return win32.gencache.EnsureDispatch("Excel.Application")
except AttributeError as retry_exc:
if not _is_gen_py_cache_error(retry_exc):
raise
_log.warning(
"EnsureDispatch still failing after cache clear (%s); using late-bound Dispatch",
retry_exc,
)
return win32.Dispatch("Excel.Application")
def _bring_excel_to_front(excel, workbook) -> None: def _bring_excel_to_front(excel, workbook) -> None:
"""Maximize and force Excel ahead of other windows (e.g. NiceGUI).""" """Maximize and force Excel ahead of other windows (e.g. NiceGUI)."""
import win32com.client as win32
import win32con import win32con
import win32gui import win32gui
excel.Visible = True excel.Visible = True
excel.WindowState = _XL_MAXIMIZED excel.WindowState = win32.constants.xlMaximized
try: try:
workbook.Activate() workbook.Activate()
except Exception: except Exception:
@@ -118,12 +57,16 @@ def clean_workbook_com(
maximize: bool = True, maximize: bool = True,
) -> None: ) -> None:
"""Clear/set cells via Excel COM, SaveAs destination, leave Excel open.""" """Clear/set cells via Excel COM, SaveAs destination, leave Excel open."""
# Lazy import so Linux never loads pywin32 (only needed if callers import helpers). # Lazy import so Linux never loads pywin32.
import win32com.client as win32
source = Path(source) source = Path(source)
destination = Path(destination) destination = Path(destination)
destination.parent.mkdir(parents=True, exist_ok=True) destination.parent.mkdir(parents=True, exist_ok=True)
excel = _excel_application() # AttributeError: ... has no attribute 'CLSIDToClassMap'
# https://stackoverflow.com/questions/52889704
excel = win32.gencache.EnsureDispatch("Excel.Application")
excel.Visible = visible excel.Visible = visible
workbook = excel.Workbooks.Open(str(source.resolve())) workbook = excel.Workbooks.Open(str(source.resolve()))

View File

@@ -1,105 +0,0 @@
"""Tests for win32com gen_py cache recovery (no real Excel required)."""
from __future__ import annotations
import sys
from types import ModuleType, SimpleNamespace
from unittest.mock import MagicMock, patch
import pytest
from xlsx_clean.com_backend import (
_clear_gen_py_cache,
_excel_application,
_is_gen_py_cache_error,
)
def _install_fake_win32com(*, ensure, dispatch=None, gen_path="/tmp/gen_py"):
"""Put fake win32com + win32com.client modules into sys.modules."""
win32com = ModuleType("win32com")
win32com.__gen_path__ = gen_path
client = ModuleType("win32com.client")
client.gencache = SimpleNamespace(EnsureDispatch=ensure)
client.Dispatch = dispatch if dispatch is not None else MagicMock()
return patch.dict(sys.modules, {"win32com": win32com, "win32com.client": client})
def test_is_gen_py_cache_error_matches_known_messages():
assert _is_gen_py_cache_error(
AttributeError(
"module 'win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9' "
"has no attribute 'CLSIDToPackageMap'"
)
)
assert _is_gen_py_cache_error(
AttributeError("... has no attribute 'CLSIDToClassMap'")
)
assert not _is_gen_py_cache_error(AttributeError("something else"))
assert not _is_gen_py_cache_error(RuntimeError("CLSIDToPackageMap"))
def test_clear_gen_py_cache_removes_modules_and_directory(tmp_path):
gen_root = tmp_path / "gen_py"
bad = gen_root / "00020813-0000-0000-C000-000000000046x0x1x9"
bad.mkdir(parents=True)
(bad / "__init__.py").write_text("# corrupt", encoding="utf-8")
mod_name = "win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9"
fake_mod = ModuleType(mod_name)
fake_win32com = ModuleType("win32com")
fake_win32com.__gen_path__ = str(gen_root)
with patch.dict(sys.modules, {"win32com": fake_win32com, mod_name: fake_mod}):
cleared = _clear_gen_py_cache()
assert cleared == gen_root
assert not gen_root.exists()
assert mod_name not in sys.modules
def test_excel_application_clears_cache_and_retries_ensure_dispatch():
excel = object()
ensure = MagicMock(
side_effect=[
AttributeError(
"module 'win32com.gen_py.00020813x0x1x9' has no attribute 'CLSIDToPackageMap'"
),
excel,
]
)
with (
_install_fake_win32com(ensure=ensure),
patch("xlsx_clean.com_backend._clear_gen_py_cache", return_value=None) as clear,
):
result = _excel_application()
assert result is excel
assert ensure.call_count == 2
clear.assert_called_once_with()
def test_excel_application_falls_back_to_dispatch_after_second_failure():
excel = object()
err = AttributeError("has no attribute 'CLSIDToClassMap'")
ensure = MagicMock(side_effect=[err, err])
dispatch = MagicMock(return_value=excel)
with (
_install_fake_win32com(ensure=ensure, dispatch=dispatch),
patch("xlsx_clean.com_backend._clear_gen_py_cache", return_value=None),
):
result = _excel_application()
assert result is excel
dispatch.assert_called_once_with("Excel.Application")
def test_excel_application_rethrows_unrelated_attribute_error():
ensure = MagicMock(side_effect=AttributeError("unrelated"))
with (
_install_fake_win32com(ensure=ensure),
pytest.raises(AttributeError, match="unrelated"),
):
_excel_application()