Compare commits
2 Commits
95cc827a0a
...
cursor/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55ebc86b55 | ||
| fb9295ce65 |
@@ -1,324 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>New QC Sheet · 0.2.0</title>
|
|
||||||
<!--
|
|
||||||
Static UI mock of src/xlsx_clean/ui/index.html.
|
|
||||||
Demo only — no create-datasheet behavior.
|
|
||||||
-->
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
--primary: #e54d5e;
|
|
||||||
--accent-3: #a855f7;
|
|
||||||
--success: #22c55e;
|
|
||||||
--tl-red: #ff5f56;
|
|
||||||
--tl-yellow: #ffbd2e;
|
|
||||||
--tl-green: #27c93f;
|
|
||||||
--bg: #0b0e14;
|
|
||||||
--surface: #161b22;
|
|
||||||
--surface-2: #1c2230;
|
|
||||||
--border: rgba(255, 255, 255, 0.08);
|
|
||||||
--border-strong: rgba(255, 255, 255, 0.14);
|
|
||||||
--grid-line: rgba(255, 255, 255, 0.06);
|
|
||||||
--grid-size: 32px;
|
|
||||||
--text: #e6e6ef;
|
|
||||||
--text-muted: #8b8b9e;
|
|
||||||
--text-dim: #5a5a6e;
|
|
||||||
--grad-brand: linear-gradient(135deg, var(--primary), var(--accent-3));
|
|
||||||
--radius: 14px;
|
|
||||||
--radius-sm: 9px;
|
|
||||||
}
|
|
||||||
|
|
||||||
* { box-sizing: border-box; }
|
|
||||||
|
|
||||||
body {
|
|
||||||
min-height: 100vh;
|
|
||||||
margin: 0;
|
|
||||||
background: var(--bg);
|
|
||||||
color: var(--text);
|
|
||||||
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
|
|
||||||
font-size: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
body::before {
|
|
||||||
content: "";
|
|
||||||
position: fixed;
|
|
||||||
inset: 0;
|
|
||||||
z-index: -1;
|
|
||||||
pointer-events: none;
|
|
||||||
background-image:
|
|
||||||
linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
|
|
||||||
linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
|
|
||||||
background-size: var(--grid-size) var(--grid-size);
|
|
||||||
}
|
|
||||||
|
|
||||||
.page {
|
|
||||||
display: flex;
|
|
||||||
min-height: 100vh;
|
|
||||||
padding: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.panel {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
width: min(100%, 36rem);
|
|
||||||
margin: auto;
|
|
||||||
background: var(--surface);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
box-shadow: 0 24px 60px -28px rgb(0 0 0 / 55%);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.chrome {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
min-height: 40px;
|
|
||||||
padding: 0 14px;
|
|
||||||
background: var(--surface-2);
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.traffic {
|
|
||||||
display: flex;
|
|
||||||
gap: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.traffic span {
|
|
||||||
width: 10px;
|
|
||||||
height: 10px;
|
|
||||||
border-radius: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tl-red { background: var(--tl-red); }
|
|
||||||
.tl-yellow { background: var(--tl-yellow); }
|
|
||||||
.tl-green { background: var(--tl-green); }
|
|
||||||
|
|
||||||
.chrome-title {
|
|
||||||
flex: 1;
|
|
||||||
color: var(--text-muted);
|
|
||||||
font-family: ui-monospace, monospace;
|
|
||||||
font-size: 0.75rem;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.panel-body {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 22px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.eyebrow {
|
|
||||||
margin: 0 0 8px;
|
|
||||||
color: var(--primary);
|
|
||||||
font-size: 0.75rem;
|
|
||||||
font-weight: 700;
|
|
||||||
letter-spacing: 0.08em;
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
margin: 0;
|
|
||||||
font-size: 1.875rem;
|
|
||||||
font-weight: 700;
|
|
||||||
letter-spacing: -0.02em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.subtitle {
|
|
||||||
margin: 8px 0 22px;
|
|
||||||
color: var(--text-muted);
|
|
||||||
}
|
|
||||||
|
|
||||||
.fields { display: grid; gap: 18px; }
|
|
||||||
|
|
||||||
.field {
|
|
||||||
position: relative;
|
|
||||||
padding-top: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.field label {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 11px;
|
|
||||||
padding: 0 4px;
|
|
||||||
background: var(--surface);
|
|
||||||
color: var(--primary);
|
|
||||||
font-size: 0.75rem;
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.field select,
|
|
||||||
.field input {
|
|
||||||
width: 100%;
|
|
||||||
appearance: none;
|
|
||||||
border: 1px solid var(--border-strong);
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
background: var(--surface-2);
|
|
||||||
padding: 0.85rem 2.25rem 0.85rem 0.85rem;
|
|
||||||
font-size: 1rem;
|
|
||||||
color: var(--text);
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.field .chevron {
|
|
||||||
pointer-events: none;
|
|
||||||
position: absolute;
|
|
||||||
right: 0.85rem;
|
|
||||||
top: 50%;
|
|
||||||
transform: translateY(-50%);
|
|
||||||
color: var(--text-muted);
|
|
||||||
font-size: 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.divider {
|
|
||||||
height: 1px;
|
|
||||||
margin: 22px 0;
|
|
||||||
background: var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-primary {
|
|
||||||
width: 100%;
|
|
||||||
border: none;
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
background: var(--grad-brand);
|
|
||||||
color: #fff;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
font-weight: 700;
|
|
||||||
letter-spacing: 0.04em;
|
|
||||||
text-transform: uppercase;
|
|
||||||
padding: 0.85rem 1rem;
|
|
||||||
cursor: default;
|
|
||||||
}
|
|
||||||
|
|
||||||
.note {
|
|
||||||
margin: 0 0 16px;
|
|
||||||
color: var(--warning, #f59e0b);
|
|
||||||
font-size: 0.85rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal {
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
background: var(--bg);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal-bar {
|
|
||||||
padding: 6px 12px;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
color: var(--text-dim);
|
|
||||||
font-family: ui-monospace, monospace;
|
|
||||||
font-size: 0.7rem;
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status {
|
|
||||||
min-height: 48px;
|
|
||||||
padding: 12px;
|
|
||||||
color: var(--success);
|
|
||||||
font-family: ui-monospace, monospace;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status::before {
|
|
||||||
content: "$ ";
|
|
||||||
color: var(--primary);
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|
||||||
.version {
|
|
||||||
margin: 16px 0 0;
|
|
||||||
color: var(--text-dim);
|
|
||||||
font-family: ui-monospace, monospace;
|
|
||||||
font-size: 0.75rem;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<main class="page">
|
|
||||||
<section class="panel">
|
|
||||||
<div class="chrome">
|
|
||||||
<span class="traffic" aria-hidden="true">
|
|
||||||
<span class="tl-red"></span>
|
|
||||||
<span class="tl-yellow"></span>
|
|
||||||
<span class="tl-green"></span>
|
|
||||||
</span>
|
|
||||||
<span class="chrome-title">xlsx-clean — New QC Sheet</span>
|
|
||||||
</div>
|
|
||||||
<div class="panel-body">
|
|
||||||
<p class="eyebrow">QC datasheet</p>
|
|
||||||
<h1>New QC Sheet</h1>
|
|
||||||
<p class="subtitle">
|
|
||||||
Create a new QC datasheet from the latest matching workbook.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="fields">
|
|
||||||
<div class="field">
|
|
||||||
<label>Select Set</label>
|
|
||||||
<select aria-label="Select Set" tabindex="-1">
|
|
||||||
<option selected>Kimia Razi</option>
|
|
||||||
<option>inco</option>
|
|
||||||
</select>
|
|
||||||
<span class="chevron" aria-hidden="true">▾</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field">
|
|
||||||
<label>Select Ink Color</label>
|
|
||||||
<select aria-label="Select Ink Color" tabindex="-1">
|
|
||||||
<option selected>KRCY1100T Blue</option>
|
|
||||||
<option>KRBK1300T Black</option>
|
|
||||||
<option>KRBK1314T Black</option>
|
|
||||||
<option>KRBR1200T Brown</option>
|
|
||||||
<option>KRBG1600T Beige</option>
|
|
||||||
<option>KRHN1700T Honey</option>
|
|
||||||
<option>KRPK1500T Pink</option>
|
|
||||||
</select>
|
|
||||||
<span class="chevron" aria-hidden="true">▾</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field">
|
|
||||||
<label>Serial:</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="e.g. 1234/A"
|
|
||||||
value=""
|
|
||||||
aria-label="Serial"
|
|
||||||
tabindex="-1"
|
|
||||||
readonly
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field">
|
|
||||||
<label>Backend</label>
|
|
||||||
<select aria-label="Backend" tabindex="-1">
|
|
||||||
<option selected>ooxml</option>
|
|
||||||
<option>com</option>
|
|
||||||
</select>
|
|
||||||
<span class="chevron" aria-hidden="true">▾</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p class="note">
|
|
||||||
COM backend requires Windows with Microsoft Excel; use ooxml here.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="divider"></div>
|
|
||||||
<button type="button" class="btn-primary" tabindex="-1">
|
|
||||||
Create datasheet
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<div class="terminal" style="margin-top: 16px;">
|
|
||||||
<div class="terminal-bar">status</div>
|
|
||||||
<div class="status">Ready.</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p class="version">v0.2.0</p>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</main>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -2,17 +2,78 @@
|
|||||||
|
|
||||||
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 = win32.constants.xlMaximized
|
excel.WindowState = _XL_MAXIMIZED
|
||||||
try:
|
try:
|
||||||
workbook.Activate()
|
workbook.Activate()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -57,16 +118,12 @@ 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.
|
# Lazy import so Linux never loads pywin32 (only needed if callers import helpers).
|
||||||
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)
|
||||||
|
|
||||||
# AttributeError: ... has no attribute 'CLSIDToClassMap'
|
excel = _excel_application()
|
||||||
# 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()))
|
||||||
|
|||||||
@@ -39,9 +39,6 @@
|
|||||||
--success: #22c55e;
|
--success: #22c55e;
|
||||||
--warning: #f59e0b;
|
--warning: #f59e0b;
|
||||||
--error: #ef4444;
|
--error: #ef4444;
|
||||||
--tl-red: #ff5f56;
|
|
||||||
--tl-yellow: #ffbd2e;
|
|
||||||
--tl-green: #27c93f;
|
|
||||||
--bg: #0b0e14;
|
--bg: #0b0e14;
|
||||||
--bg-alt: #111520;
|
--bg-alt: #111520;
|
||||||
--surface: #161b22;
|
--surface: #161b22;
|
||||||
@@ -64,6 +61,7 @@
|
|||||||
--status-success: rgba(34, 197, 94, 0.12);
|
--status-success: rgba(34, 197, 94, 0.12);
|
||||||
--status-skipped: rgba(245, 158, 11, 0.12);
|
--status-skipped: rgba(245, 158, 11, 0.12);
|
||||||
--status-error: rgba(239, 68, 68, 0.12);
|
--status-error: rgba(239, 68, 68, 0.12);
|
||||||
|
--label-bg: rgba(11, 14, 20, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
html[data-theme="light"] {
|
html[data-theme="light"] {
|
||||||
@@ -81,6 +79,7 @@
|
|||||||
--status-success: rgba(34, 197, 94, 0.1);
|
--status-success: rgba(34, 197, 94, 0.1);
|
||||||
--status-skipped: rgba(245, 158, 11, 0.12);
|
--status-skipped: rgba(245, 158, 11, 0.12);
|
||||||
--status-error: rgba(239, 68, 68, 0.1);
|
--status-error: rgba(239, 68, 68, 0.1);
|
||||||
|
--label-bg: rgba(249, 249, 251, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
* { box-sizing: border-box; }
|
* { box-sizing: border-box; }
|
||||||
@@ -116,65 +115,31 @@
|
|||||||
|
|
||||||
.panel {
|
.panel {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1;
|
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: min(100%, 36rem);
|
width: min(100%, 36rem);
|
||||||
margin: auto;
|
margin: auto;
|
||||||
background: var(--surface);
|
background: transparent;
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius);
|
|
||||||
box-shadow: 0 24px 60px -28px rgb(0 0 0 / 55%);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.chrome {
|
.heading-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: flex-start;
|
||||||
gap: 10px;
|
justify-content: space-between;
|
||||||
min-height: 40px;
|
gap: 12px;
|
||||||
padding: 0 14px;
|
|
||||||
background: var(--surface-2);
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
}
|
|
||||||
|
|
||||||
.traffic {
|
|
||||||
display: flex;
|
|
||||||
gap: 6px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.traffic span {
|
|
||||||
width: 10px;
|
|
||||||
height: 10px;
|
|
||||||
border-radius: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tl-red { background: var(--tl-red); }
|
|
||||||
.tl-yellow { background: var(--tl-yellow); }
|
|
||||||
.tl-green { background: var(--tl-green); }
|
|
||||||
|
|
||||||
.chrome-title {
|
|
||||||
flex: 1;
|
|
||||||
color: var(--text-muted);
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-size: 0.75rem;
|
|
||||||
letter-spacing: 0.02em;
|
|
||||||
text-align: center;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.theme-toggle {
|
.theme-toggle {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
min-width: 52px;
|
min-width: 52px;
|
||||||
height: 28px;
|
height: 28px;
|
||||||
|
margin-top: 2px;
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
border: 1px solid var(--border);
|
border: 1px solid var(--border);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
background: var(--surface);
|
background: var(--surface-2);
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font: inherit;
|
font: inherit;
|
||||||
@@ -195,13 +160,6 @@
|
|||||||
outline-offset: 2px;
|
outline-offset: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.panel-body {
|
|
||||||
display: flex;
|
|
||||||
flex: 1;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 22px 22px 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.eyebrow {
|
.eyebrow {
|
||||||
margin: 0 0 8px;
|
margin: 0 0 8px;
|
||||||
color: var(--primary);
|
color: var(--primary);
|
||||||
@@ -230,27 +188,28 @@
|
|||||||
|
|
||||||
.field {
|
.field {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: block;
|
display: flex;
|
||||||
padding-top: 8px;
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.field-label {
|
.field-label {
|
||||||
position: absolute;
|
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
top: 0;
|
margin-left: 4px;
|
||||||
left: 11px;
|
|
||||||
padding: 0 4px;
|
padding: 0 4px;
|
||||||
background: var(--surface);
|
background: var(--label-bg);
|
||||||
color: var(--primary);
|
color: var(--primary);
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
line-height: 1rem;
|
line-height: 1.2;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
select, input {
|
select, input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
align-self: stretch;
|
||||||
min-height: 54px;
|
min-height: 54px;
|
||||||
padding: 16px 12px 6px;
|
padding: 16px 12px;
|
||||||
border: 1px solid var(--border-strong);
|
border: 1px solid var(--border-strong);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
outline: none;
|
outline: none;
|
||||||
@@ -282,11 +241,11 @@
|
|||||||
|
|
||||||
.combobox-caret {
|
.combobox-caret {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
|
||||||
right: 12px;
|
right: 12px;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
height: 54px;
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
@@ -378,28 +337,12 @@
|
|||||||
|
|
||||||
#create-button:disabled { cursor: not-allowed; opacity: 0.65; }
|
#create-button:disabled { cursor: not-allowed; opacity: 0.65; }
|
||||||
|
|
||||||
.terminal {
|
|
||||||
margin-top: 16px;
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: var(--radius-sm);
|
|
||||||
background: var(--bg);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.terminal-bar {
|
|
||||||
padding: 6px 12px;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
color: var(--text-dim);
|
|
||||||
font-family: var(--font-mono);
|
|
||||||
font-size: 0.7rem;
|
|
||||||
letter-spacing: 0.04em;
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status {
|
.status {
|
||||||
min-height: 48px;
|
min-height: 48px;
|
||||||
margin: 0;
|
margin-top: 16px;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
font-family: var(--font-mono);
|
font-family: var(--font-mono);
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
@@ -419,8 +362,7 @@
|
|||||||
.status-error { background: var(--status-error); color: var(--error); }
|
.status-error { background: var(--status-error); color: var(--error); }
|
||||||
|
|
||||||
.version {
|
.version {
|
||||||
margin: auto 0 0;
|
margin-top: 16px;
|
||||||
padding-top: 16px;
|
|
||||||
color: var(--text-dim);
|
color: var(--text-dim);
|
||||||
font-family: var(--font-mono);
|
font-family: var(--font-mono);
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
@@ -429,7 +371,6 @@
|
|||||||
|
|
||||||
@media (max-width: 480px) {
|
@media (max-width: 480px) {
|
||||||
.page { padding: 14px; }
|
.page { padding: 14px; }
|
||||||
.panel-body { padding: 18px 16px 14px; }
|
|
||||||
h1 { font-size: 1.5rem; }
|
h1 { font-size: 1.5rem; }
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -437,13 +378,11 @@
|
|||||||
<body>
|
<body>
|
||||||
<main class="page">
|
<main class="page">
|
||||||
<section class="panel" aria-labelledby="heading">
|
<section class="panel" aria-labelledby="heading">
|
||||||
<div class="chrome">
|
<div class="heading-row">
|
||||||
<span class="traffic" aria-hidden="true">
|
<div>
|
||||||
<span class="tl-red"></span>
|
<p class="eyebrow">QC datasheet</p>
|
||||||
<span class="tl-yellow"></span>
|
<h1 id="heading">New QC Sheet</h1>
|
||||||
<span class="tl-green"></span>
|
</div>
|
||||||
</span>
|
|
||||||
<span class="chrome-title">xlsx-clean — New QC Sheet</span>
|
|
||||||
<button
|
<button
|
||||||
id="theme-toggle"
|
id="theme-toggle"
|
||||||
class="theme-toggle"
|
class="theme-toggle"
|
||||||
@@ -453,9 +392,6 @@
|
|||||||
Aa
|
Aa
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
|
||||||
<p class="eyebrow">QC datasheet</p>
|
|
||||||
<h1 id="heading">New QC Sheet</h1>
|
|
||||||
<p class="subtitle">Create a new QC datasheet from the latest matching workbook.</p>
|
<p class="subtitle">Create a new QC datasheet from the latest matching workbook.</p>
|
||||||
|
|
||||||
<div class="fields">
|
<div class="fields">
|
||||||
@@ -503,12 +439,8 @@
|
|||||||
|
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<button id="create-button" type="button">Create datasheet</button>
|
<button id="create-button" type="button">Create datasheet</button>
|
||||||
<div class="terminal">
|
|
||||||
<div class="terminal-bar">status</div>
|
|
||||||
<div id="status" class="status status-ready" role="status">Loading configuration...</div>
|
<div id="status" class="status status-ready" role="status">Loading configuration...</div>
|
||||||
</div>
|
|
||||||
<p id="version" class="version"></p>
|
<p id="version" class="version"></p>
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@@ -659,14 +591,15 @@
|
|||||||
empty.textContent = "No matches";
|
empty.textContent = "No matches";
|
||||||
empty.hidden = true;
|
empty.hidden = true;
|
||||||
panelEl.append(empty);
|
panelEl.append(empty);
|
||||||
if (selectEl.value && !inputEl.value) {
|
inputEl.value = selectEl.value || "";
|
||||||
inputEl.value = selectEl.value;
|
|
||||||
}
|
|
||||||
inputDirty = false;
|
inputDirty = false;
|
||||||
syncDisabled();
|
syncDisabled();
|
||||||
};
|
};
|
||||||
|
|
||||||
inputEl.addEventListener("focus", open);
|
inputEl.addEventListener("focus", open);
|
||||||
|
inputEl.addEventListener("mousedown", () => {
|
||||||
|
open();
|
||||||
|
});
|
||||||
inputEl.addEventListener("input", () => {
|
inputEl.addEventListener("input", () => {
|
||||||
inputDirty = true;
|
inputDirty = true;
|
||||||
if (!openState) open();
|
if (!openState) open();
|
||||||
|
|||||||
105
tests/test_com_backend.py
Normal file
105
tests/test_com_backend.py
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
"""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()
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from xlsx_clean.paths import package_file
|
from xlsx_clean.paths import package_file
|
||||||
|
|
||||||
@@ -31,6 +32,8 @@ def test_ui_asset_exists_and_has_required_bridge_content():
|
|||||||
"get_inks(setDropdown.value)",
|
"get_inks(setDropdown.value)",
|
||||||
"api.create(",
|
"api.create(",
|
||||||
"finally",
|
"finally",
|
||||||
|
'inputEl.value = selectEl.value || ""',
|
||||||
|
'inputEl.addEventListener("mousedown", () => {\n open();\n });',
|
||||||
):
|
):
|
||||||
assert expected in content
|
assert expected in content
|
||||||
|
|
||||||
@@ -41,6 +44,9 @@ def test_ui_asset_exists_and_has_required_bridge_content():
|
|||||||
assert "#0b0e14" in content
|
assert "#0b0e14" in content
|
||||||
assert "#e54d5e" in content
|
assert "#e54d5e" in content
|
||||||
assert "background-size: var(--grid-size) var(--grid-size)" in content
|
assert "background-size: var(--grid-size) var(--grid-size)" in content
|
||||||
|
assert "background: transparent" in content
|
||||||
|
assert "tl-red" not in content
|
||||||
|
assert 'class="chrome"' not in content
|
||||||
StrictHtmlParser().feed(content)
|
StrictHtmlParser().feed(content)
|
||||||
|
|
||||||
|
|
||||||
@@ -51,3 +57,7 @@ def test_ui_font_sources_are_bundled_locally():
|
|||||||
assert font_urls == ["../fonts/Inter-Regular.ttf", "../fonts/Inter-Bold.ttf"]
|
assert font_urls == ["../fonts/Inter-Regular.ttf", "../fonts/Inter-Bold.ttf"]
|
||||||
for font_url in font_urls:
|
for font_url in font_urls:
|
||||||
assert (package_file("ui") / font_url).resolve().is_file()
|
assert (package_file("ui") / font_url).resolve().is_file()
|
||||||
|
|
||||||
|
|
||||||
|
def test_demo_html_is_not_shipped():
|
||||||
|
assert not Path("desktop/demo.html").exists()
|
||||||
|
|||||||
Reference in New Issue
Block a user