juxt 0.1.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {juxt-0.1.0 → juxt-0.3.0}/PKG-INFO +5 -3
- {juxt-0.1.0 → juxt-0.3.0}/README.md +4 -2
- juxt-0.3.0/juxt/__main__.py +116 -0
- {juxt-0.1.0 → juxt-0.3.0}/juxt/_version.py +2 -2
- {juxt-0.1.0 → juxt-0.3.0}/juxt/config.py +16 -1
- juxt-0.3.0/juxt/detect.py +166 -0
- juxt-0.3.0/juxt/viewer.py +648 -0
- {juxt-0.1.0 → juxt-0.3.0}/pyproject.toml +4 -0
- juxt-0.1.0/juxt/__main__.py +0 -50
- juxt-0.1.0/juxt/viewer.py +0 -210
- {juxt-0.1.0 → juxt-0.3.0}/.gitignore +0 -0
- {juxt-0.1.0 → juxt-0.3.0}/juxt/__init__.py +0 -0
- {juxt-0.1.0 → juxt-0.3.0}/juxt/loader.py +0 -0
- {juxt-0.1.0 → juxt-0.3.0}/sample_config.yaml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: juxt
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Fast desktop tool for navigating N-dimensional hypercubes of geospatial plots
|
|
5
5
|
Project-URL: Homepage, https://github.com/ColinMoldenhauer/juxt
|
|
6
6
|
Project-URL: Documentation, https://juxt.readthedocs.io
|
|
@@ -26,9 +26,11 @@ Requires-Dist: mkdocs-include-markdown-plugin; extra == 'docs'
|
|
|
26
26
|
Requires-Dist: mkdocs-material; extra == 'docs'
|
|
27
27
|
Description-Content-Type: text/markdown
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
<p align="center">
|
|
30
|
+
<img src="docs/assets/logo_large_transparent.png" width="120" alt="juxt logo">
|
|
31
|
+
</p>
|
|
31
32
|
|
|
33
|
+
# juxt
|
|
32
34
|
*juxt* is clipped from *juxtapose* (Latin *juxta*, "beside") and shares its meaning with παραβολή (*parabolē*, "placing beside") — the Greek root of both *parable* and *parabola*.
|
|
33
35
|
|
|
34
36
|
`juxt` is a fast desktop tool for visually comparing geospatial plots across multiple parameter axes. Define axes (sensor, date, overpass, source, …) and flip through the resulting image hypercube with keyboard navigation.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/assets/logo_large_transparent.png" width="120" alt="juxt logo">
|
|
3
|
+
</p>
|
|
3
4
|
|
|
5
|
+
# juxt
|
|
4
6
|
*juxt* is clipped from *juxtapose* (Latin *juxta*, "beside") and shares its meaning with παραβολή (*parabolē*, "placing beside") — the Greek root of both *parable* and *parabola*.
|
|
5
7
|
|
|
6
8
|
`juxt` is a fast desktop tool for visually comparing geospatial plots across multiple parameter axes. Define axes (sensor, date, overpass, source, …) and flip through the resulting image hypercube with keyboard navigation.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import signal
|
|
3
|
+
import sys
|
|
4
|
+
import warnings
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from PySide6.QtCore import Qt, QTimer
|
|
8
|
+
from PySide6.QtGui import QIcon
|
|
9
|
+
from PySide6.QtWidgets import QApplication, QProgressDialog
|
|
10
|
+
|
|
11
|
+
from .config import load_config
|
|
12
|
+
from .detect import IMAGE_EXTENSIONS, detect_config, prompt_rename
|
|
13
|
+
from .loader import preload
|
|
14
|
+
from .viewer import MainWindow
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _force_focus(window):
|
|
18
|
+
"""Bring the window to the foreground even when launched from a terminal.
|
|
19
|
+
|
|
20
|
+
On Windows the OS blocks focus-stealing by default. The AttachThreadInput
|
|
21
|
+
trick borrows the foreground thread's lock so SetForegroundWindow succeeds.
|
|
22
|
+
On other platforms activateWindow/raise_ is sufficient.
|
|
23
|
+
"""
|
|
24
|
+
if sys.platform == "win32":
|
|
25
|
+
import ctypes
|
|
26
|
+
hwnd = int(window.winId())
|
|
27
|
+
fg_hwnd = ctypes.windll.user32.GetForegroundWindow()
|
|
28
|
+
fg_tid = ctypes.windll.user32.GetWindowThreadProcessId(fg_hwnd, None)
|
|
29
|
+
our_tid = ctypes.windll.kernel32.GetCurrentThreadId()
|
|
30
|
+
if fg_tid != our_tid:
|
|
31
|
+
ctypes.windll.user32.AttachThreadInput(fg_tid, our_tid, True)
|
|
32
|
+
ctypes.windll.user32.BringWindowToTop(hwnd)
|
|
33
|
+
ctypes.windll.user32.SetForegroundWindow(hwnd)
|
|
34
|
+
ctypes.windll.user32.AttachThreadInput(fg_tid, our_tid, False)
|
|
35
|
+
else:
|
|
36
|
+
window.activateWindow()
|
|
37
|
+
window.raise_()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def main():
|
|
41
|
+
arg = sys.argv[1] if len(sys.argv) >= 2 else "."
|
|
42
|
+
|
|
43
|
+
if sys.platform == "win32" and Path(sys.executable).stem.lower() in ("python", "pythonw"):
|
|
44
|
+
import ctypes
|
|
45
|
+
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("juxt")
|
|
46
|
+
|
|
47
|
+
app = QApplication(sys.argv)
|
|
48
|
+
app.setApplicationName("juxt")
|
|
49
|
+
_logo = Path(__file__).parent / "assets" / "logo_transparent.ico"
|
|
50
|
+
if not _logo.exists(): # fallback for editable installs
|
|
51
|
+
_logo = Path(__file__).parent.parent / "docs" / "assets" / "logo_transparent.ico"
|
|
52
|
+
app_icon = QIcon()
|
|
53
|
+
if _logo.exists():
|
|
54
|
+
app_icon = QIcon(str(_logo))
|
|
55
|
+
if app_icon.isNull():
|
|
56
|
+
warnings.warn(f"Icon file found but failed to load: {_logo}")
|
|
57
|
+
else:
|
|
58
|
+
app.setWindowIcon(app_icon)
|
|
59
|
+
else:
|
|
60
|
+
warnings.warn(f"No logo file found at {_logo}")
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
path = Path(arg)
|
|
64
|
+
if path.is_dir():
|
|
65
|
+
n_images = sum(
|
|
66
|
+
1 for f in path.iterdir()
|
|
67
|
+
if f.is_file() and f.suffix.lower() in IMAGE_EXTENSIONS
|
|
68
|
+
)
|
|
69
|
+
config, sep = detect_config(path)
|
|
70
|
+
config = prompt_rename(config, n_images, sep)
|
|
71
|
+
elif path.suffix.lower() in (".yaml", ".yml"):
|
|
72
|
+
config = load_config(arg)
|
|
73
|
+
else:
|
|
74
|
+
print(f"Error: {arg!r} is not a directory or YAML config file", file=sys.stderr)
|
|
75
|
+
sys.exit(1)
|
|
76
|
+
except Exception as e:
|
|
77
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
78
|
+
sys.exit(1)
|
|
79
|
+
|
|
80
|
+
total = 1
|
|
81
|
+
for vs in config.axes.values():
|
|
82
|
+
total *= len(vs)
|
|
83
|
+
|
|
84
|
+
progress = QProgressDialog("Loading images…", None, 0, total)
|
|
85
|
+
progress.setWindowTitle("juxt")
|
|
86
|
+
progress.setWindowModality(Qt.ApplicationModal)
|
|
87
|
+
progress.setMinimumDuration(0)
|
|
88
|
+
progress.setValue(0)
|
|
89
|
+
|
|
90
|
+
def on_progress(i: int, n: int):
|
|
91
|
+
progress.setValue(i)
|
|
92
|
+
app.processEvents()
|
|
93
|
+
|
|
94
|
+
pixmaps = preload(config.template, config.axes, on_progress)
|
|
95
|
+
progress.close()
|
|
96
|
+
|
|
97
|
+
window = MainWindow(config, pixmaps)
|
|
98
|
+
window.showMaximized()
|
|
99
|
+
app.processEvents()
|
|
100
|
+
if not app_icon.isNull():
|
|
101
|
+
window.setWindowIcon(app_icon)
|
|
102
|
+
_force_focus(window)
|
|
103
|
+
|
|
104
|
+
# Qt's C++ event loop blocks Python signal delivery. Install a handler
|
|
105
|
+
# that calls app.quit(), and tick a no-op timer so Python wakes up
|
|
106
|
+
# periodically and can actually invoke it.
|
|
107
|
+
signal.signal(signal.SIGINT, lambda *_: app.quit())
|
|
108
|
+
sigint_tick = QTimer()
|
|
109
|
+
sigint_tick.timeout.connect(lambda: None)
|
|
110
|
+
sigint_tick.start(200)
|
|
111
|
+
|
|
112
|
+
sys.exit(app.exec())
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
if __name__ == "__main__":
|
|
116
|
+
main()
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.
|
|
22
|
-
__version_tuple__ = version_tuple = (0,
|
|
21
|
+
__version__ = version = '0.3.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 3, 0)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -9,6 +9,7 @@ class Config:
|
|
|
9
9
|
template: str
|
|
10
10
|
axes: dict[str, list[str]] # ordered; all values are strings
|
|
11
11
|
keys: dict[str, str] # letter -> axis_name
|
|
12
|
+
mode: int = 2 # NavMode value (0=twin, 1=multi-select, 2=case-sensitive)
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
def _auto_discover(directory: str, separator: str) -> tuple[str, dict[str, list[str]]]:
|
|
@@ -76,4 +77,18 @@ def load_config(path: str) -> Config:
|
|
|
76
77
|
keys_cfg = data.get("keys", {})
|
|
77
78
|
keys = {str(k): str(v) for k, v in keys_cfg.items()} if keys_cfg else _auto_keys(axes)
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
mode = _parse_mode(data.get("mode", 2))
|
|
81
|
+
|
|
82
|
+
return Config(template=template, axes=axes, keys=keys, mode=mode)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _parse_mode(value) -> int:
|
|
86
|
+
if isinstance(value, int):
|
|
87
|
+
if 0 <= value <= 2:
|
|
88
|
+
return value
|
|
89
|
+
raise ValueError(f"mode must be 0–2, got {value}")
|
|
90
|
+
s = str(value).lower().replace("-", "_").replace(" ", "_")
|
|
91
|
+
table = {"0": 0, "twin": 0, "1": 1, "multi_select": 1, "2": 2, "case_sensitive": 2}
|
|
92
|
+
if s not in table:
|
|
93
|
+
raise ValueError(f"Unknown mode {value!r}; choose twin/multi-select/case-sensitive or 0/1/2")
|
|
94
|
+
return table[s]
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""Auto-detect image axes from a directory without a config file."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from .config import Config, _auto_keys
|
|
7
|
+
|
|
8
|
+
IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".tif", ".tiff", ".bmp", ".gif", ".webp"}
|
|
9
|
+
_CANDIDATE_SEPS = ["_", "-", ".", " "]
|
|
10
|
+
_MAX_VALS = 3
|
|
11
|
+
|
|
12
|
+
# Cyan, yellow, green, magenta, blue — readable on both light and dark terminals
|
|
13
|
+
_PALETTE = ["\033[96m", "\033[93m", "\033[92m", "\033[95m", "\033[94m"]
|
|
14
|
+
_RESET = "\033[0m"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _score(parts_list: list[list[str]]) -> int:
|
|
18
|
+
"""Count columns with more than one distinct value (higher = better split)."""
|
|
19
|
+
if not parts_list or len({len(p) for p in parts_list}) > 1:
|
|
20
|
+
return 0
|
|
21
|
+
n = len(parts_list[0])
|
|
22
|
+
return sum(1 for i in range(n) if len({p[i] for p in parts_list}) > 1)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def detect_config(directory: str | Path, separator: str | None = None) -> tuple[Config, str]:
|
|
26
|
+
"""Build a Config by analysing image filenames in *directory*.
|
|
27
|
+
|
|
28
|
+
If *separator* is None, tries common separators and picks whichever produces
|
|
29
|
+
the most variable columns. Raises ValueError if no usable pattern is found.
|
|
30
|
+
|
|
31
|
+
Returns (config, separator) so callers can display the detected separator.
|
|
32
|
+
"""
|
|
33
|
+
directory = Path(directory)
|
|
34
|
+
files = sorted(
|
|
35
|
+
f for f in directory.iterdir()
|
|
36
|
+
if f.is_file() and f.suffix.lower() in IMAGE_EXTENSIONS
|
|
37
|
+
)
|
|
38
|
+
if not files:
|
|
39
|
+
raise ValueError(f"No image files found in {str(directory)!r}")
|
|
40
|
+
|
|
41
|
+
stems = [f.stem for f in files]
|
|
42
|
+
|
|
43
|
+
if separator is None:
|
|
44
|
+
best_sep, best_score = "_", -1
|
|
45
|
+
for sep in _CANDIDATE_SEPS:
|
|
46
|
+
score = _score([s.split(sep) for s in stems])
|
|
47
|
+
if score > best_score:
|
|
48
|
+
best_score, best_sep = score, sep
|
|
49
|
+
separator = best_sep
|
|
50
|
+
|
|
51
|
+
ext = files[0].suffix
|
|
52
|
+
parts_list = [s.split(separator) for s in stems]
|
|
53
|
+
n_cols = len(parts_list[0])
|
|
54
|
+
if any(len(p) != n_cols for p in parts_list):
|
|
55
|
+
raise ValueError(
|
|
56
|
+
f"Filenames have inconsistent number of parts when split on {separator!r}"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
axes: dict[str, list[str]] = {}
|
|
60
|
+
col_axis: dict[int, str] = {}
|
|
61
|
+
for i in range(n_cols):
|
|
62
|
+
values = list(dict.fromkeys(p[i] for p in parts_list))
|
|
63
|
+
if len(values) > 1:
|
|
64
|
+
name = f"axis_{i}"
|
|
65
|
+
axes[name] = values
|
|
66
|
+
col_axis[i] = name
|
|
67
|
+
|
|
68
|
+
if not axes:
|
|
69
|
+
raise ValueError(
|
|
70
|
+
"No variable columns found — all filenames look identical after splitting"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
template_parts = [
|
|
74
|
+
f"{{{col_axis[i]}}}" if i in col_axis else parts_list[0][i]
|
|
75
|
+
for i in range(n_cols)
|
|
76
|
+
]
|
|
77
|
+
template = str(directory / (separator.join(template_parts) + ext))
|
|
78
|
+
|
|
79
|
+
return Config(template=template, axes=axes, keys=_auto_keys(axes)), separator
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _render_pattern(
|
|
83
|
+
orig_template: str,
|
|
84
|
+
all_axes: dict[str, list[str]],
|
|
85
|
+
resolved: dict[str, str | None],
|
|
86
|
+
axis_colors: dict[str, str],
|
|
87
|
+
) -> str:
|
|
88
|
+
"""Render the pattern for display.
|
|
89
|
+
|
|
90
|
+
Pending axes → colored {v1|v2|v3|...}
|
|
91
|
+
Named axes → colored {name}
|
|
92
|
+
Ignored axes → plain fixed value
|
|
93
|
+
"""
|
|
94
|
+
result = orig_template
|
|
95
|
+
for auto_name, values in all_axes.items():
|
|
96
|
+
color = axis_colors.get(auto_name, "")
|
|
97
|
+
reset = _RESET if color else ""
|
|
98
|
+
if auto_name not in resolved:
|
|
99
|
+
if len(values) <= _MAX_VALS:
|
|
100
|
+
inline = "{" + "|".join(values) + "}"
|
|
101
|
+
else:
|
|
102
|
+
inline = "{" + "|".join(values[:_MAX_VALS]) + "|...}"
|
|
103
|
+
result = result.replace(f"{{{auto_name}}}", f"{color}{inline}{reset}")
|
|
104
|
+
elif resolved[auto_name] is not None:
|
|
105
|
+
result = result.replace(f"{{{auto_name}}}", f"{color}{{{resolved[auto_name]}}}{reset}")
|
|
106
|
+
else:
|
|
107
|
+
result = result.replace(f"{{{auto_name}}}", values[0])
|
|
108
|
+
return result
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def prompt_rename(config: Config, n_files: int, separator: str) -> Config:
|
|
112
|
+
"""Interactively rename or ignore each auto-detected axis.
|
|
113
|
+
|
|
114
|
+
Prints an initial colored pattern overview, then for each axis shows its
|
|
115
|
+
values, reads a name (or Enter to ignore), and prints the updated pattern
|
|
116
|
+
as feedback. Raises ValueError if every axis is ignored.
|
|
117
|
+
"""
|
|
118
|
+
use_col = sys.stdout.isatty()
|
|
119
|
+
axis_colors: dict[str, str] = (
|
|
120
|
+
{name: _PALETTE[i % len(_PALETTE)] for i, name in enumerate(config.axes)}
|
|
121
|
+
if use_col else {}
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
print(f"\nDetected {n_files} image{'s' if n_files != 1 else ''} — separator {separator!r}\n")
|
|
125
|
+
print(f" {_render_pattern(config.template, config.axes, {}, axis_colors)}\n")
|
|
126
|
+
|
|
127
|
+
new_axes: dict[str, list[str]] = {}
|
|
128
|
+
used_names: set[str] = set()
|
|
129
|
+
template = config.template
|
|
130
|
+
resolved: dict[str, str | None] = {}
|
|
131
|
+
|
|
132
|
+
for auto_name, values in config.axes.items():
|
|
133
|
+
color = axis_colors.get(auto_name, "")
|
|
134
|
+
reset = _RESET if color else ""
|
|
135
|
+
|
|
136
|
+
if len(values) <= _MAX_VALS:
|
|
137
|
+
vals_display = " ".join(values)
|
|
138
|
+
else:
|
|
139
|
+
vals_display = " ".join(values[:_MAX_VALS]) + f" … ({len(values)} total)"
|
|
140
|
+
print(f" {color}{auto_name}{reset}: {vals_display}")
|
|
141
|
+
|
|
142
|
+
try:
|
|
143
|
+
answer = input(" name (Enter to ignore): ").strip()
|
|
144
|
+
except EOFError:
|
|
145
|
+
answer = ""
|
|
146
|
+
|
|
147
|
+
if answer:
|
|
148
|
+
if answer in used_names:
|
|
149
|
+
raise ValueError(f"Duplicate axis name {answer!r}")
|
|
150
|
+
used_names.add(answer)
|
|
151
|
+
new_axes[answer] = values
|
|
152
|
+
resolved[auto_name] = answer
|
|
153
|
+
template = template.replace(f"{{{auto_name}}}", f"{{{answer}}}")
|
|
154
|
+
print(f" → {color}{answer!r}{reset}")
|
|
155
|
+
else:
|
|
156
|
+
fixed = values[0]
|
|
157
|
+
resolved[auto_name] = None
|
|
158
|
+
template = template.replace(f"{{{auto_name}}}", fixed)
|
|
159
|
+
print(f" → ignored (fixed to {fixed!r})")
|
|
160
|
+
|
|
161
|
+
print(f" {_render_pattern(config.template, config.axes, resolved, axis_colors)}\n")
|
|
162
|
+
|
|
163
|
+
if not new_axes:
|
|
164
|
+
raise ValueError("All axes were ignored — nothing to navigate")
|
|
165
|
+
|
|
166
|
+
return Config(template=template, axes=new_axes, keys=_auto_keys(new_axes), mode=config.mode)
|
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from enum import IntEnum
|
|
4
|
+
|
|
5
|
+
from PySide6.QtCore import Qt, QRectF, QTimer, Signal
|
|
6
|
+
from PySide6.QtGui import QColor, QKeyEvent, QPainter, QPixmap
|
|
7
|
+
from PySide6.QtWidgets import (
|
|
8
|
+
QApplication,
|
|
9
|
+
QGraphicsPixmapItem,
|
|
10
|
+
QGraphicsScene,
|
|
11
|
+
QGraphicsView,
|
|
12
|
+
QLabel,
|
|
13
|
+
QMainWindow,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
from .config import Config
|
|
17
|
+
|
|
18
|
+
_COMMANDS = [
|
|
19
|
+
"fit",
|
|
20
|
+
"fit-height",
|
|
21
|
+
"fit-width",
|
|
22
|
+
"fullscreen",
|
|
23
|
+
"mode",
|
|
24
|
+
"quit",
|
|
25
|
+
"switch-last",
|
|
26
|
+
"zoom",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
_ALIASES: dict[str, str] = {
|
|
30
|
+
"q": "quit",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Discrete argument options for commands that take a value.
|
|
34
|
+
# Commands absent from this dict take no arguments (or free-text only).
|
|
35
|
+
_CMD_ARGS: dict[str, list[str]] = {
|
|
36
|
+
"mode": ["twin", "multi-select", "case-sensitive"],
|
|
37
|
+
"zoom": ["50", "75", "100", "150", "200"],
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class NavMode(IntEnum):
|
|
42
|
+
TWIN = 0
|
|
43
|
+
MULTI_SELECT = 1
|
|
44
|
+
CASE_SENSITIVE = 2
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def label(self) -> str:
|
|
48
|
+
return ("twin", "multi-select", "case-sensitive")[self]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ImageView(QGraphicsView):
|
|
52
|
+
state_changed = Signal()
|
|
53
|
+
toggle_bar = Signal()
|
|
54
|
+
|
|
55
|
+
def __init__(self, config: Config, pixmaps: dict[tuple, QPixmap], parent=None):
|
|
56
|
+
self._scene = QGraphicsScene()
|
|
57
|
+
super().__init__(self._scene, parent)
|
|
58
|
+
|
|
59
|
+
self.config = config
|
|
60
|
+
self.pixmaps = pixmaps
|
|
61
|
+
self.axis_names = list(config.axes.keys())
|
|
62
|
+
self.axis_values = list(config.axes.values())
|
|
63
|
+
self.n_axes = len(self.axis_names)
|
|
64
|
+
|
|
65
|
+
self.pos: list[int] = [0] * self.n_axes
|
|
66
|
+
self.prev: list[int] | None = None
|
|
67
|
+
|
|
68
|
+
# Most recently focused axis first; focus_stack[0] → ←/→, [1] → ↑/↓
|
|
69
|
+
self.focus_stack: list[int] = list(range(self.n_axes))
|
|
70
|
+
|
|
71
|
+
# letter → axis index
|
|
72
|
+
self.key_to_axis: dict[str, int] = {
|
|
73
|
+
ch: self.axis_names.index(name)
|
|
74
|
+
for ch, name in config.keys.items()
|
|
75
|
+
if name in self.axis_names
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
self.nav_mode = NavMode(config.mode)
|
|
79
|
+
|
|
80
|
+
# Active incremental-search state (value picker and multi-select).
|
|
81
|
+
# None = no active selection
|
|
82
|
+
# axis phase: {"phase": "axis", "query": str}
|
|
83
|
+
# value phase: {"phase": "value", "query": str, "axis_idx": int}
|
|
84
|
+
self._sel: dict | None = None
|
|
85
|
+
|
|
86
|
+
# Active command-mode state; None = not in command mode.
|
|
87
|
+
# verb phase: {"phase": "verb", "query": str, "cursor": int}
|
|
88
|
+
# arg phase: {"phase": "arg", "verb": str, "query": str, "cursor": int}
|
|
89
|
+
self._cmd: dict | None = None
|
|
90
|
+
|
|
91
|
+
self.setFocusPolicy(Qt.StrongFocus)
|
|
92
|
+
self.setDragMode(QGraphicsView.ScrollHandDrag)
|
|
93
|
+
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
|
|
94
|
+
self.setResizeAnchor(QGraphicsView.AnchorViewCenter)
|
|
95
|
+
self.setRenderHint(QPainter.SmoothPixmapTransform)
|
|
96
|
+
self.setBackgroundBrush(QColor(25, 25, 25))
|
|
97
|
+
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
98
|
+
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
99
|
+
|
|
100
|
+
self._item = QGraphicsPixmapItem()
|
|
101
|
+
self._item.setTransformationMode(Qt.SmoothTransformation)
|
|
102
|
+
self._scene.addItem(self._item)
|
|
103
|
+
|
|
104
|
+
self._refresh()
|
|
105
|
+
|
|
106
|
+
# ── internal helpers ──────────────────────────────────────────────────────
|
|
107
|
+
|
|
108
|
+
def _key(self) -> tuple:
|
|
109
|
+
return tuple(self.pos)
|
|
110
|
+
|
|
111
|
+
def _refresh(self):
|
|
112
|
+
pm = self.pixmaps.get(self._key())
|
|
113
|
+
if pm:
|
|
114
|
+
self._item.setPixmap(pm)
|
|
115
|
+
self._scene.setSceneRect(QRectF(pm.rect()))
|
|
116
|
+
self.viewport().update()
|
|
117
|
+
self.state_changed.emit()
|
|
118
|
+
|
|
119
|
+
def _h_axis(self) -> int:
|
|
120
|
+
return self.focus_stack[0]
|
|
121
|
+
|
|
122
|
+
def _v_axis(self) -> int | None:
|
|
123
|
+
return self.focus_stack[1] if len(self.focus_stack) >= 2 else None
|
|
124
|
+
|
|
125
|
+
def _navigate(self, axis: int, delta: int):
|
|
126
|
+
n = len(self.axis_values[axis])
|
|
127
|
+
self.prev = list(self.pos)
|
|
128
|
+
self.pos[axis] = (self.pos[axis] + delta) % n
|
|
129
|
+
self._refresh()
|
|
130
|
+
|
|
131
|
+
def _focus(self, axis: int):
|
|
132
|
+
if axis in self.focus_stack:
|
|
133
|
+
self.focus_stack.remove(axis)
|
|
134
|
+
self.focus_stack.insert(0, axis)
|
|
135
|
+
|
|
136
|
+
# ── incremental-search (value picker / multi-select) ─────────────────────
|
|
137
|
+
|
|
138
|
+
def _sel_candidates(self) -> list[str]:
|
|
139
|
+
"""Items matching the current query by case-insensitive prefix."""
|
|
140
|
+
assert self._sel is not None
|
|
141
|
+
q = self._sel["query"]
|
|
142
|
+
if self._sel["phase"] == "axis":
|
|
143
|
+
return [n for n in self.axis_names if n.lower().startswith(q)]
|
|
144
|
+
return [v for v in self.axis_values[self._sel["axis_idx"]] if v.lower().startswith(q)]
|
|
145
|
+
|
|
146
|
+
def _sel_open_axis(self, initial: str = ""):
|
|
147
|
+
"""Enter axis-selection phase (mode 1 entry point)."""
|
|
148
|
+
self._sel = {"phase": "axis", "query": initial.lower(), "cursor": 0}
|
|
149
|
+
self._sel_try_commit()
|
|
150
|
+
|
|
151
|
+
def _sel_open_value(self, axis_idx: int, initial: str = ""):
|
|
152
|
+
"""Enter value-selection phase for a known axis (ctrl+letter entry point)."""
|
|
153
|
+
self._focus(axis_idx)
|
|
154
|
+
self._sel = {"phase": "value", "query": initial.lower(), "axis_idx": axis_idx, "cursor": 0}
|
|
155
|
+
self._sel_try_commit()
|
|
156
|
+
|
|
157
|
+
def _sel_try_commit(self):
|
|
158
|
+
"""Auto-commit when exactly one candidate remains (greedy match).
|
|
159
|
+
|
|
160
|
+
NOTE: the greedy auto-confirm behaviour is a candidate for a
|
|
161
|
+
user-configurable flag (require explicit Enter instead).
|
|
162
|
+
"""
|
|
163
|
+
candidates = self._sel_candidates()
|
|
164
|
+
if len(candidates) == 1:
|
|
165
|
+
self._sel_commit(candidates[0])
|
|
166
|
+
else:
|
|
167
|
+
# Clamp cursor in case the candidate list shrank
|
|
168
|
+
n = len(candidates)
|
|
169
|
+
self._sel["cursor"] = min(self._sel["cursor"], n - 1) if n else 0
|
|
170
|
+
self.state_changed.emit()
|
|
171
|
+
|
|
172
|
+
def _sel_commit(self, value: str):
|
|
173
|
+
if self._sel["phase"] == "axis":
|
|
174
|
+
axis_idx = self.axis_names.index(value)
|
|
175
|
+
self._focus(axis_idx)
|
|
176
|
+
self._sel = {"phase": "value", "query": "", "axis_idx": axis_idx, "cursor": 0}
|
|
177
|
+
self._sel_try_commit()
|
|
178
|
+
else:
|
|
179
|
+
axis_idx = self._sel["axis_idx"]
|
|
180
|
+
self.prev = list(self.pos)
|
|
181
|
+
self.pos[axis_idx] = self.axis_values[axis_idx].index(value)
|
|
182
|
+
self._sel = None
|
|
183
|
+
self._refresh()
|
|
184
|
+
|
|
185
|
+
def _sel_handle_key(self, event: QKeyEvent) -> bool:
|
|
186
|
+
"""Handle input while a selection is active. Returns True if consumed."""
|
|
187
|
+
k = event.key()
|
|
188
|
+
|
|
189
|
+
if k == Qt.Key_Escape:
|
|
190
|
+
self._sel = None
|
|
191
|
+
self.state_changed.emit()
|
|
192
|
+
return True
|
|
193
|
+
|
|
194
|
+
if k == Qt.Key_Backspace:
|
|
195
|
+
q = self._sel["query"]
|
|
196
|
+
if q:
|
|
197
|
+
self._sel["query"] = q[:-1]
|
|
198
|
+
self._sel["cursor"] = 0
|
|
199
|
+
self.state_changed.emit()
|
|
200
|
+
elif self._sel["phase"] == "value":
|
|
201
|
+
# backspace on empty value query → back to axis search
|
|
202
|
+
self._sel = {"phase": "axis", "query": "", "cursor": 0}
|
|
203
|
+
self.state_changed.emit()
|
|
204
|
+
else:
|
|
205
|
+
self._sel = None
|
|
206
|
+
self.state_changed.emit()
|
|
207
|
+
return True
|
|
208
|
+
|
|
209
|
+
if k == Qt.Key_Right:
|
|
210
|
+
candidates = self._sel_candidates()
|
|
211
|
+
if candidates:
|
|
212
|
+
self._sel["cursor"] = (self._sel["cursor"] + 1) % len(candidates)
|
|
213
|
+
self.state_changed.emit()
|
|
214
|
+
return True
|
|
215
|
+
|
|
216
|
+
if k == Qt.Key_Left:
|
|
217
|
+
candidates = self._sel_candidates()
|
|
218
|
+
if candidates:
|
|
219
|
+
self._sel["cursor"] = (self._sel["cursor"] - 1) % len(candidates)
|
|
220
|
+
self.state_changed.emit()
|
|
221
|
+
return True
|
|
222
|
+
|
|
223
|
+
if Qt.Key_1 <= k <= Qt.Key_9:
|
|
224
|
+
idx = k - Qt.Key_1
|
|
225
|
+
candidates = self._sel_candidates()
|
|
226
|
+
if idx < len(candidates):
|
|
227
|
+
self._sel_commit(candidates[idx])
|
|
228
|
+
return True
|
|
229
|
+
|
|
230
|
+
if k in (Qt.Key_Return, Qt.Key_Enter):
|
|
231
|
+
candidates = self._sel_candidates()
|
|
232
|
+
if candidates:
|
|
233
|
+
self._sel_commit(candidates[self._sel["cursor"]])
|
|
234
|
+
return True
|
|
235
|
+
|
|
236
|
+
ch = event.text()
|
|
237
|
+
if ch and ch.isprintable():
|
|
238
|
+
self._sel["query"] += ch.lower()
|
|
239
|
+
self._sel["cursor"] = 0
|
|
240
|
+
self._sel_try_commit()
|
|
241
|
+
return True
|
|
242
|
+
|
|
243
|
+
return False
|
|
244
|
+
|
|
245
|
+
# ── command mode ─────────────────────────────────────────────────────────
|
|
246
|
+
|
|
247
|
+
def _cmd_candidates(self) -> list[str]:
|
|
248
|
+
assert self._cmd is not None
|
|
249
|
+
q = self._cmd["query"].strip()
|
|
250
|
+
if self._cmd["phase"] == "verb":
|
|
251
|
+
if q in _ALIASES:
|
|
252
|
+
return [_ALIASES[q]]
|
|
253
|
+
pool = _COMMANDS
|
|
254
|
+
else:
|
|
255
|
+
pool = _CMD_ARGS.get(self._cmd["verb"], [])
|
|
256
|
+
return [c for c in pool if c.startswith(q)] if q else list(pool)
|
|
257
|
+
|
|
258
|
+
def _cmd_handle_key(self, event: QKeyEvent) -> bool:
|
|
259
|
+
"""Handle input while command mode is active. Returns True if consumed."""
|
|
260
|
+
k = event.key()
|
|
261
|
+
|
|
262
|
+
if k == Qt.Key_Escape:
|
|
263
|
+
self._cmd = None
|
|
264
|
+
self.state_changed.emit()
|
|
265
|
+
return True
|
|
266
|
+
|
|
267
|
+
if k == Qt.Key_Backspace:
|
|
268
|
+
if self._cmd["query"]:
|
|
269
|
+
self._cmd["query"] = self._cmd["query"][:-1]
|
|
270
|
+
self._cmd["cursor"] = 0
|
|
271
|
+
elif self._cmd["phase"] == "arg":
|
|
272
|
+
verb = self._cmd["verb"]
|
|
273
|
+
self._cmd = {"phase": "verb", "query": verb, "cursor": 0}
|
|
274
|
+
candidates = self._cmd_candidates()
|
|
275
|
+
if verb in candidates:
|
|
276
|
+
self._cmd["cursor"] = candidates.index(verb)
|
|
277
|
+
else:
|
|
278
|
+
self._cmd = None
|
|
279
|
+
self.state_changed.emit()
|
|
280
|
+
return True
|
|
281
|
+
|
|
282
|
+
if k == Qt.Key_Right:
|
|
283
|
+
candidates = self._cmd_candidates()
|
|
284
|
+
if candidates:
|
|
285
|
+
self._cmd["cursor"] = (self._cmd["cursor"] + 1) % len(candidates)
|
|
286
|
+
self.state_changed.emit()
|
|
287
|
+
return True
|
|
288
|
+
|
|
289
|
+
if k == Qt.Key_Left:
|
|
290
|
+
candidates = self._cmd_candidates()
|
|
291
|
+
if candidates:
|
|
292
|
+
self._cmd["cursor"] = (self._cmd["cursor"] - 1) % len(candidates)
|
|
293
|
+
self.state_changed.emit()
|
|
294
|
+
return True
|
|
295
|
+
|
|
296
|
+
if k in (Qt.Key_Return, Qt.Key_Enter):
|
|
297
|
+
candidates = self._cmd_candidates()
|
|
298
|
+
if self._cmd["phase"] == "verb":
|
|
299
|
+
if not candidates:
|
|
300
|
+
self._cmd = None
|
|
301
|
+
self.state_changed.emit()
|
|
302
|
+
return True
|
|
303
|
+
verb = candidates[min(self._cmd["cursor"], len(candidates) - 1)]
|
|
304
|
+
if verb in _CMD_ARGS:
|
|
305
|
+
self._cmd = {"phase": "arg", "verb": verb, "query": "", "cursor": 0}
|
|
306
|
+
self.state_changed.emit()
|
|
307
|
+
else:
|
|
308
|
+
self._cmd = None
|
|
309
|
+
self._cmd_execute(verb)
|
|
310
|
+
self.state_changed.emit()
|
|
311
|
+
else:
|
|
312
|
+
verb = self._cmd["verb"]
|
|
313
|
+
arg = (
|
|
314
|
+
candidates[min(self._cmd["cursor"], len(candidates) - 1)]
|
|
315
|
+
if candidates
|
|
316
|
+
else self._cmd["query"]
|
|
317
|
+
)
|
|
318
|
+
self._cmd = None
|
|
319
|
+
self._cmd_execute(f"{verb} {arg}" if arg else verb)
|
|
320
|
+
self.state_changed.emit()
|
|
321
|
+
return True
|
|
322
|
+
|
|
323
|
+
ch = event.text()
|
|
324
|
+
if ch and ch.isprintable():
|
|
325
|
+
self._cmd["query"] += ch.lower()
|
|
326
|
+
self._cmd["cursor"] = 0
|
|
327
|
+
self.state_changed.emit()
|
|
328
|
+
return True
|
|
329
|
+
|
|
330
|
+
return False
|
|
331
|
+
|
|
332
|
+
def _cmd_execute(self, cmd: str):
|
|
333
|
+
parts = cmd.strip().split()
|
|
334
|
+
if not parts:
|
|
335
|
+
return
|
|
336
|
+
verb = _ALIASES.get(parts[0].lower(), parts[0].lower())
|
|
337
|
+
args = [a.lower() for a in parts[1:]]
|
|
338
|
+
|
|
339
|
+
if verb == "quit":
|
|
340
|
+
QApplication.instance().quit()
|
|
341
|
+
elif verb == "fit":
|
|
342
|
+
sub = args[0] if args else ""
|
|
343
|
+
if sub in ("height", "h"):
|
|
344
|
+
self.fit_height()
|
|
345
|
+
elif sub in ("width", "w"):
|
|
346
|
+
self.fit_width()
|
|
347
|
+
else:
|
|
348
|
+
self.fit_image()
|
|
349
|
+
elif verb == "fit-height":
|
|
350
|
+
self.fit_height()
|
|
351
|
+
elif verb == "fit-width":
|
|
352
|
+
self.fit_width()
|
|
353
|
+
elif verb == "zoom":
|
|
354
|
+
if args:
|
|
355
|
+
try:
|
|
356
|
+
self.set_zoom(float(args[0]))
|
|
357
|
+
except ValueError:
|
|
358
|
+
pass
|
|
359
|
+
elif verb == "fullscreen":
|
|
360
|
+
win = self.window()
|
|
361
|
+
if win.isFullScreen():
|
|
362
|
+
win.showMaximized()
|
|
363
|
+
else:
|
|
364
|
+
win.showFullScreen()
|
|
365
|
+
elif verb == "mode":
|
|
366
|
+
if args:
|
|
367
|
+
arg = args[0]
|
|
368
|
+
if arg in ("0", "twin"):
|
|
369
|
+
self.nav_mode = NavMode.TWIN
|
|
370
|
+
elif arg in ("1", "multi", "multi-select"):
|
|
371
|
+
self.nav_mode = NavMode.MULTI_SELECT
|
|
372
|
+
elif arg in ("2", "case", "case-sensitive"):
|
|
373
|
+
self.nav_mode = NavMode.CASE_SENSITIVE
|
|
374
|
+
self._sel = None
|
|
375
|
+
self.state_changed.emit()
|
|
376
|
+
elif verb == "switch-last":
|
|
377
|
+
if self.prev is not None:
|
|
378
|
+
self.pos, self.prev = self.prev, list(self.pos)
|
|
379
|
+
self._refresh()
|
|
380
|
+
|
|
381
|
+
# ── public ────────────────────────────────────────────────────────────────
|
|
382
|
+
|
|
383
|
+
def fit_image(self):
|
|
384
|
+
self.fitInView(self._scene.sceneRect(), Qt.KeepAspectRatio)
|
|
385
|
+
|
|
386
|
+
def fit_height(self):
|
|
387
|
+
pm = self._item.pixmap()
|
|
388
|
+
if pm.isNull():
|
|
389
|
+
return
|
|
390
|
+
factor = self.viewport().height() / pm.height()
|
|
391
|
+
self.resetTransform()
|
|
392
|
+
self.scale(factor, factor)
|
|
393
|
+
self.centerOn(self._scene.sceneRect().center())
|
|
394
|
+
|
|
395
|
+
def fit_width(self):
|
|
396
|
+
pm = self._item.pixmap()
|
|
397
|
+
if pm.isNull():
|
|
398
|
+
return
|
|
399
|
+
factor = self.viewport().width() / pm.width()
|
|
400
|
+
self.resetTransform()
|
|
401
|
+
self.scale(factor, factor)
|
|
402
|
+
self.centerOn(self._scene.sceneRect().center())
|
|
403
|
+
|
|
404
|
+
def reset_zoom(self):
|
|
405
|
+
self.resetTransform()
|
|
406
|
+
|
|
407
|
+
def set_zoom(self, pct: float):
|
|
408
|
+
self.resetTransform()
|
|
409
|
+
self.scale(pct / 100.0, pct / 100.0)
|
|
410
|
+
|
|
411
|
+
# ── Qt overrides ──────────────────────────────────────────────────────────
|
|
412
|
+
|
|
413
|
+
def keyPressEvent(self, event: QKeyEvent):
|
|
414
|
+
k = event.key()
|
|
415
|
+
mods = event.modifiers()
|
|
416
|
+
|
|
417
|
+
# Truly global shortcuts — work in every state
|
|
418
|
+
if k == Qt.Key_H and mods == Qt.ControlModifier:
|
|
419
|
+
self.toggle_bar.emit()
|
|
420
|
+
return
|
|
421
|
+
if k == Qt.Key_M and mods == Qt.ControlModifier:
|
|
422
|
+
self.nav_mode = NavMode((self.nav_mode + 1) % len(NavMode))
|
|
423
|
+
self._sel = None
|
|
424
|
+
self.state_changed.emit()
|
|
425
|
+
return
|
|
426
|
+
|
|
427
|
+
# Ctrl+C cancels any active command or selection mode
|
|
428
|
+
if k == Qt.Key_C and mods == Qt.ControlModifier:
|
|
429
|
+
if self._cmd is not None or self._sel is not None:
|
|
430
|
+
self._cmd = None
|
|
431
|
+
self._sel = None
|
|
432
|
+
self.state_changed.emit()
|
|
433
|
+
return
|
|
434
|
+
|
|
435
|
+
# Command mode intercepts all input while active
|
|
436
|
+
if self._cmd is not None:
|
|
437
|
+
if not self._cmd_handle_key(event):
|
|
438
|
+
super().keyPressEvent(event)
|
|
439
|
+
return
|
|
440
|
+
|
|
441
|
+
# Semi-global shortcuts — work in normal mode and selection mode
|
|
442
|
+
if k == Qt.Key_F and mods == Qt.NoModifier:
|
|
443
|
+
self.fit_image()
|
|
444
|
+
return
|
|
445
|
+
if k == Qt.Key_0 and mods == Qt.NoModifier:
|
|
446
|
+
self.reset_zoom()
|
|
447
|
+
return
|
|
448
|
+
|
|
449
|
+
# Incremental-search intercepts everything while active
|
|
450
|
+
if self._sel is not None:
|
|
451
|
+
if not self._sel_handle_key(event):
|
|
452
|
+
super().keyPressEvent(event)
|
|
453
|
+
return
|
|
454
|
+
|
|
455
|
+
# Colon opens command mode
|
|
456
|
+
if event.text() == ":":
|
|
457
|
+
self._cmd = {"phase": "verb", "query": "", "cursor": 0}
|
|
458
|
+
self.state_changed.emit()
|
|
459
|
+
return
|
|
460
|
+
|
|
461
|
+
# Universal navigation keys (all modes)
|
|
462
|
+
if k == Qt.Key_Right:
|
|
463
|
+
self._navigate(self._h_axis(), 1)
|
|
464
|
+
return
|
|
465
|
+
if k == Qt.Key_Left:
|
|
466
|
+
self._navigate(self._h_axis(), -1)
|
|
467
|
+
return
|
|
468
|
+
if k == Qt.Key_Down:
|
|
469
|
+
v = self._v_axis()
|
|
470
|
+
if v is not None:
|
|
471
|
+
self._navigate(v, 1)
|
|
472
|
+
return
|
|
473
|
+
if k == Qt.Key_Up:
|
|
474
|
+
v = self._v_axis()
|
|
475
|
+
if v is not None:
|
|
476
|
+
self._navigate(v, -1)
|
|
477
|
+
return
|
|
478
|
+
if k == Qt.Key_Space:
|
|
479
|
+
if self.prev is not None:
|
|
480
|
+
self.pos, self.prev = self.prev, list(self.pos)
|
|
481
|
+
self._refresh()
|
|
482
|
+
return
|
|
483
|
+
if k == Qt.Key_Home:
|
|
484
|
+
self.prev = list(self.pos)
|
|
485
|
+
self.pos[self._h_axis()] = 0
|
|
486
|
+
self._refresh()
|
|
487
|
+
return
|
|
488
|
+
if k == Qt.Key_End:
|
|
489
|
+
h = self._h_axis()
|
|
490
|
+
self.prev = list(self.pos)
|
|
491
|
+
self.pos[h] = len(self.axis_values[h]) - 1
|
|
492
|
+
self._refresh()
|
|
493
|
+
return
|
|
494
|
+
if Qt.Key_1 <= k <= Qt.Key_9:
|
|
495
|
+
idx = k - Qt.Key_1
|
|
496
|
+
h = self._h_axis()
|
|
497
|
+
if idx < len(self.axis_values[h]):
|
|
498
|
+
self.prev = list(self.pos)
|
|
499
|
+
self.pos[h] = idx
|
|
500
|
+
self._refresh()
|
|
501
|
+
return
|
|
502
|
+
if k in (Qt.Key_Return, Qt.Key_Enter):
|
|
503
|
+
win = self.window()
|
|
504
|
+
if win.isFullScreen():
|
|
505
|
+
win.showMaximized()
|
|
506
|
+
else:
|
|
507
|
+
win.showFullScreen()
|
|
508
|
+
return
|
|
509
|
+
if k == Qt.Key_Escape:
|
|
510
|
+
win = self.window()
|
|
511
|
+
if win.isFullScreen():
|
|
512
|
+
win.showMaximized()
|
|
513
|
+
return
|
|
514
|
+
|
|
515
|
+
# Mode-specific letter handling
|
|
516
|
+
ch = event.text()
|
|
517
|
+
ch_lower = ch.lower()
|
|
518
|
+
|
|
519
|
+
if self.nav_mode == NavMode.TWIN:
|
|
520
|
+
if mods == Qt.ControlModifier and ch_lower in self.key_to_axis:
|
|
521
|
+
self._sel_open_value(self.key_to_axis[ch_lower])
|
|
522
|
+
elif mods == Qt.NoModifier and ch_lower in self.key_to_axis:
|
|
523
|
+
self._focus(self.key_to_axis[ch_lower])
|
|
524
|
+
self.state_changed.emit()
|
|
525
|
+
else:
|
|
526
|
+
super().keyPressEvent(event)
|
|
527
|
+
|
|
528
|
+
elif self.nav_mode == NavMode.MULTI_SELECT:
|
|
529
|
+
if mods == Qt.NoModifier and ch.isalpha():
|
|
530
|
+
self._sel_open_axis(ch)
|
|
531
|
+
else:
|
|
532
|
+
super().keyPressEvent(event)
|
|
533
|
+
|
|
534
|
+
elif self.nav_mode == NavMode.CASE_SENSITIVE:
|
|
535
|
+
if mods == Qt.ControlModifier and ch_lower in self.key_to_axis:
|
|
536
|
+
self._sel_open_value(self.key_to_axis[ch_lower])
|
|
537
|
+
elif ch_lower in self.key_to_axis and mods in (Qt.NoModifier, Qt.ShiftModifier):
|
|
538
|
+
axis = self.key_to_axis[ch_lower]
|
|
539
|
+
delta = -1 if ch.isupper() else 1
|
|
540
|
+
self._focus(axis)
|
|
541
|
+
self._navigate(axis, delta)
|
|
542
|
+
else:
|
|
543
|
+
super().keyPressEvent(event)
|
|
544
|
+
|
|
545
|
+
def mouseDoubleClickEvent(self, event):
|
|
546
|
+
self.fit_image()
|
|
547
|
+
|
|
548
|
+
def wheelEvent(self, event):
|
|
549
|
+
factor = 1.15 if event.angleDelta().y() > 0 else 1 / 1.15
|
|
550
|
+
self.scale(factor, factor)
|
|
551
|
+
|
|
552
|
+
def resizeEvent(self, event):
|
|
553
|
+
super().resizeEvent(event)
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
class MainWindow(QMainWindow):
|
|
557
|
+
def __init__(self, config: Config, pixmaps: dict):
|
|
558
|
+
super().__init__()
|
|
559
|
+
self.setWindowTitle("juxt")
|
|
560
|
+
self.view = ImageView(config, pixmaps, self)
|
|
561
|
+
self.setCentralWidget(self.view)
|
|
562
|
+
|
|
563
|
+
bar = self.statusBar()
|
|
564
|
+
bar.setStyleSheet(
|
|
565
|
+
"QStatusBar { background: #1a1a1a; color: #e0e0e0; "
|
|
566
|
+
"font-family: 'Courier New', monospace; font-size: 9pt; "
|
|
567
|
+
"border-top: 1px solid #333; }"
|
|
568
|
+
"QStatusBar::item { border: none; }"
|
|
569
|
+
)
|
|
570
|
+
self._status_label = QLabel()
|
|
571
|
+
self._status_label.setStyleSheet("color: #e0e0e0; padding: 2px 8px;")
|
|
572
|
+
bar.addWidget(self._status_label, 1)
|
|
573
|
+
|
|
574
|
+
self.view.state_changed.connect(self._update_status)
|
|
575
|
+
self.view.toggle_bar.connect(self._toggle_status_bar)
|
|
576
|
+
|
|
577
|
+
self._update_status()
|
|
578
|
+
QTimer.singleShot(0, self.view.fit_image)
|
|
579
|
+
|
|
580
|
+
def _update_status(self):
|
|
581
|
+
v = self.view
|
|
582
|
+
mode_str = f"[{v.nav_mode.label}]"
|
|
583
|
+
|
|
584
|
+
if v._cmd is not None:
|
|
585
|
+
candidates = v._cmd_candidates()
|
|
586
|
+
cursor = min(v._cmd["cursor"], len(candidates) - 1) if candidates else 0
|
|
587
|
+
query = v._cmd["query"]
|
|
588
|
+
if v._cmd["phase"] == "verb":
|
|
589
|
+
prompt = f":{query}▌"
|
|
590
|
+
hide = False
|
|
591
|
+
else:
|
|
592
|
+
prompt = f":{v._cmd['verb']} {query}▌"
|
|
593
|
+
hide = False
|
|
594
|
+
if candidates and not hide:
|
|
595
|
+
cand_str = " ".join(
|
|
596
|
+
f"[{c}]" if i == cursor else c
|
|
597
|
+
for i, c in enumerate(candidates)
|
|
598
|
+
)
|
|
599
|
+
self._status_label.setText(f"{prompt} → {cand_str}")
|
|
600
|
+
elif not candidates and v._cmd["phase"] == "verb" and query:
|
|
601
|
+
self._status_label.setText(f"{prompt} (unknown command)")
|
|
602
|
+
else:
|
|
603
|
+
self._status_label.setText(prompt)
|
|
604
|
+
return
|
|
605
|
+
|
|
606
|
+
if v._sel is not None:
|
|
607
|
+
phase = v._sel["phase"]
|
|
608
|
+
query = v._sel["query"]
|
|
609
|
+
cursor = v._sel["cursor"]
|
|
610
|
+
candidates = v._sel_candidates()
|
|
611
|
+
if phase == "axis":
|
|
612
|
+
prompt = f"axis? {query}▌"
|
|
613
|
+
else:
|
|
614
|
+
axis_name = v.axis_names[v._sel["axis_idx"]]
|
|
615
|
+
prompt = f"{axis_name}? {query}▌"
|
|
616
|
+
if candidates:
|
|
617
|
+
cand_str = " ".join(
|
|
618
|
+
f"[{c}]" if i == cursor else c
|
|
619
|
+
for i, c in enumerate(candidates)
|
|
620
|
+
)
|
|
621
|
+
else:
|
|
622
|
+
cand_str = "(no match)"
|
|
623
|
+
self._status_label.setText(f"{mode_str} | {prompt} → {cand_str}")
|
|
624
|
+
return
|
|
625
|
+
|
|
626
|
+
h_idx = v._h_axis()
|
|
627
|
+
v_idx = v._v_axis()
|
|
628
|
+
|
|
629
|
+
coord_str = " ".join(
|
|
630
|
+
f"{name}={v.axis_values[i][v.pos[i]]}"
|
|
631
|
+
for i, name in enumerate(v.axis_names)
|
|
632
|
+
)
|
|
633
|
+
h_name = v.axis_names[h_idx]
|
|
634
|
+
v_name = v.axis_names[v_idx] if v_idx is not None else "—"
|
|
635
|
+
bind_str = f"→/← {h_name} ↑/↓ {v_name}"
|
|
636
|
+
key_hints = " ".join(
|
|
637
|
+
f"[{ch}] {v.axis_names[v.key_to_axis[ch]]}"
|
|
638
|
+
for ch in sorted(v.key_to_axis)
|
|
639
|
+
)
|
|
640
|
+
|
|
641
|
+
parts = [mode_str, coord_str, bind_str]
|
|
642
|
+
if key_hints:
|
|
643
|
+
parts.append(key_hints)
|
|
644
|
+
self._status_label.setText(" | ".join(parts))
|
|
645
|
+
|
|
646
|
+
def _toggle_status_bar(self):
|
|
647
|
+
sb = self.statusBar()
|
|
648
|
+
sb.setVisible(not sb.isVisible())
|
|
@@ -53,6 +53,10 @@ version-file = "juxt/_version.py"
|
|
|
53
53
|
[tool.hatch.build.targets.wheel]
|
|
54
54
|
packages = ["juxt"]
|
|
55
55
|
|
|
56
|
+
[tool.hatch.build.targets.wheel.force-include]
|
|
57
|
+
"docs/assets/logo_large_transparent.png" = "juxt/assets/logo_large_transparent.png"
|
|
58
|
+
"docs/assets/logo_transparent.png" = "juxt/assets/logo_transparent.png"
|
|
59
|
+
|
|
56
60
|
[tool.hatch.build.targets.sdist]
|
|
57
61
|
include = [
|
|
58
62
|
"juxt/",
|
juxt-0.1.0/juxt/__main__.py
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
import sys
|
|
3
|
-
from itertools import product
|
|
4
|
-
|
|
5
|
-
from PySide6.QtCore import Qt
|
|
6
|
-
from PySide6.QtWidgets import QApplication, QProgressDialog
|
|
7
|
-
|
|
8
|
-
from .config import load_config
|
|
9
|
-
from .loader import preload
|
|
10
|
-
from .viewer import MainWindow
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def main():
|
|
14
|
-
if len(sys.argv) < 2:
|
|
15
|
-
print("Usage: juxt <config.yaml>")
|
|
16
|
-
sys.exit(1)
|
|
17
|
-
|
|
18
|
-
app = QApplication(sys.argv)
|
|
19
|
-
app.setApplicationName("juxt")
|
|
20
|
-
|
|
21
|
-
try:
|
|
22
|
-
config = load_config(sys.argv[1])
|
|
23
|
-
except Exception as e:
|
|
24
|
-
print(f"Error loading config: {e}", file=sys.stderr)
|
|
25
|
-
sys.exit(1)
|
|
26
|
-
|
|
27
|
-
total = 1
|
|
28
|
-
for vs in config.axes.values():
|
|
29
|
-
total *= len(vs)
|
|
30
|
-
|
|
31
|
-
progress = QProgressDialog("Loading images…", None, 0, total)
|
|
32
|
-
progress.setWindowTitle("juxt")
|
|
33
|
-
progress.setWindowModality(Qt.ApplicationModal)
|
|
34
|
-
progress.setMinimumDuration(0)
|
|
35
|
-
progress.setValue(0)
|
|
36
|
-
|
|
37
|
-
def on_progress(i: int, n: int):
|
|
38
|
-
progress.setValue(i)
|
|
39
|
-
app.processEvents()
|
|
40
|
-
|
|
41
|
-
pixmaps = preload(config.template, config.axes, on_progress)
|
|
42
|
-
progress.close()
|
|
43
|
-
|
|
44
|
-
window = MainWindow(config, pixmaps)
|
|
45
|
-
window.show()
|
|
46
|
-
sys.exit(app.exec())
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if __name__ == "__main__":
|
|
50
|
-
main()
|
juxt-0.1.0/juxt/viewer.py
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from PySide6.QtCore import Qt, QRectF, QTimer
|
|
4
|
-
from PySide6.QtGui import QColor, QFont, QKeyEvent, QPainter, QPixmap
|
|
5
|
-
from PySide6.QtWidgets import QGraphicsPixmapItem, QGraphicsScene, QGraphicsView, QMainWindow
|
|
6
|
-
|
|
7
|
-
from .config import Config
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class ImageView(QGraphicsView):
|
|
11
|
-
def __init__(self, config: Config, pixmaps: dict[tuple, QPixmap], parent=None):
|
|
12
|
-
self._scene = QGraphicsScene()
|
|
13
|
-
super().__init__(self._scene, parent)
|
|
14
|
-
|
|
15
|
-
self.config = config
|
|
16
|
-
self.pixmaps = pixmaps
|
|
17
|
-
self.axis_names = list(config.axes.keys())
|
|
18
|
-
self.axis_values = list(config.axes.values())
|
|
19
|
-
self.n_axes = len(self.axis_names)
|
|
20
|
-
|
|
21
|
-
# Current position (indices) and previous for spacebar toggle
|
|
22
|
-
self.pos: list[int] = [0] * self.n_axes
|
|
23
|
-
self.prev: list[int] | None = None
|
|
24
|
-
|
|
25
|
-
# Focus stack: axis indices, most recently focused first.
|
|
26
|
-
# pos[focus_stack[0]] is cycled by →/←; pos[focus_stack[1]] by ↑/↓.
|
|
27
|
-
self.focus_stack: list[int] = list(range(self.n_axes))
|
|
28
|
-
|
|
29
|
-
# letter → axis index
|
|
30
|
-
self.key_to_axis: dict[str, int] = {
|
|
31
|
-
ch: self.axis_names.index(name)
|
|
32
|
-
for ch, name in config.keys.items()
|
|
33
|
-
if name in self.axis_names
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
self._overlay_on = True
|
|
37
|
-
|
|
38
|
-
self.setFocusPolicy(Qt.StrongFocus)
|
|
39
|
-
self.setDragMode(QGraphicsView.ScrollHandDrag)
|
|
40
|
-
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
|
|
41
|
-
self.setResizeAnchor(QGraphicsView.AnchorViewCenter)
|
|
42
|
-
self.setRenderHint(QPainter.SmoothPixmapTransform)
|
|
43
|
-
self.setBackgroundBrush(QColor(25, 25, 25))
|
|
44
|
-
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
45
|
-
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
46
|
-
|
|
47
|
-
self._item = QGraphicsPixmapItem()
|
|
48
|
-
self._item.setTransformationMode(Qt.SmoothTransformation)
|
|
49
|
-
self._scene.addItem(self._item)
|
|
50
|
-
|
|
51
|
-
self._refresh()
|
|
52
|
-
|
|
53
|
-
# ── internal helpers ──────────────────────────────────────────────────────
|
|
54
|
-
|
|
55
|
-
def _key(self) -> tuple:
|
|
56
|
-
return tuple(self.pos)
|
|
57
|
-
|
|
58
|
-
def _refresh(self):
|
|
59
|
-
pm = self.pixmaps.get(self._key())
|
|
60
|
-
if pm:
|
|
61
|
-
self._item.setPixmap(pm)
|
|
62
|
-
self._scene.setSceneRect(QRectF(pm.rect()))
|
|
63
|
-
self.viewport().update()
|
|
64
|
-
|
|
65
|
-
def _h_axis(self) -> int:
|
|
66
|
-
return self.focus_stack[0]
|
|
67
|
-
|
|
68
|
-
def _v_axis(self) -> int | None:
|
|
69
|
-
return self.focus_stack[1] if len(self.focus_stack) >= 2 else None
|
|
70
|
-
|
|
71
|
-
def _navigate(self, axis: int, delta: int):
|
|
72
|
-
n = len(self.axis_values[axis])
|
|
73
|
-
self.prev = list(self.pos)
|
|
74
|
-
self.pos[axis] = (self.pos[axis] + delta) % n
|
|
75
|
-
self._refresh()
|
|
76
|
-
|
|
77
|
-
def _focus(self, axis: int):
|
|
78
|
-
if axis in self.focus_stack:
|
|
79
|
-
self.focus_stack.remove(axis)
|
|
80
|
-
self.focus_stack.insert(0, axis)
|
|
81
|
-
self.viewport().update()
|
|
82
|
-
|
|
83
|
-
# ── public ────────────────────────────────────────────────────────────────
|
|
84
|
-
|
|
85
|
-
def fit_image(self):
|
|
86
|
-
self.fitInView(self._scene.sceneRect(), Qt.KeepAspectRatio)
|
|
87
|
-
|
|
88
|
-
def reset_zoom(self):
|
|
89
|
-
self.resetTransform()
|
|
90
|
-
|
|
91
|
-
# ── Qt overrides ──────────────────────────────────────────────────────────
|
|
92
|
-
|
|
93
|
-
def keyPressEvent(self, event: QKeyEvent):
|
|
94
|
-
k = event.key()
|
|
95
|
-
|
|
96
|
-
if k == Qt.Key_Right:
|
|
97
|
-
self._navigate(self._h_axis(), 1)
|
|
98
|
-
elif k == Qt.Key_Left:
|
|
99
|
-
self._navigate(self._h_axis(), -1)
|
|
100
|
-
elif k == Qt.Key_Down:
|
|
101
|
-
v = self._v_axis()
|
|
102
|
-
if v is not None:
|
|
103
|
-
self._navigate(v, 1)
|
|
104
|
-
elif k == Qt.Key_Up:
|
|
105
|
-
v = self._v_axis()
|
|
106
|
-
if v is not None:
|
|
107
|
-
self._navigate(v, -1)
|
|
108
|
-
elif k == Qt.Key_Space:
|
|
109
|
-
if self.prev is not None:
|
|
110
|
-
self.pos, self.prev = self.prev, list(self.pos)
|
|
111
|
-
self._refresh()
|
|
112
|
-
elif k == Qt.Key_Home:
|
|
113
|
-
self.prev = list(self.pos)
|
|
114
|
-
self.pos[self._h_axis()] = 0
|
|
115
|
-
self._refresh()
|
|
116
|
-
elif k == Qt.Key_End:
|
|
117
|
-
h = self._h_axis()
|
|
118
|
-
self.prev = list(self.pos)
|
|
119
|
-
self.pos[h] = len(self.axis_values[h]) - 1
|
|
120
|
-
self._refresh()
|
|
121
|
-
elif Qt.Key_1 <= k <= Qt.Key_9:
|
|
122
|
-
idx = k - Qt.Key_1 # 0-based
|
|
123
|
-
h = self._h_axis()
|
|
124
|
-
if idx < len(self.axis_values[h]):
|
|
125
|
-
self.prev = list(self.pos)
|
|
126
|
-
self.pos[h] = idx
|
|
127
|
-
self._refresh()
|
|
128
|
-
elif k == Qt.Key_F:
|
|
129
|
-
self.fit_image()
|
|
130
|
-
elif k == Qt.Key_0:
|
|
131
|
-
self.reset_zoom()
|
|
132
|
-
elif k == Qt.Key_H:
|
|
133
|
-
self._overlay_on = not self._overlay_on
|
|
134
|
-
self.viewport().update()
|
|
135
|
-
else:
|
|
136
|
-
ch = event.text().lower()
|
|
137
|
-
if ch in self.key_to_axis:
|
|
138
|
-
self._focus(self.key_to_axis[ch])
|
|
139
|
-
else:
|
|
140
|
-
super().keyPressEvent(event)
|
|
141
|
-
|
|
142
|
-
def mouseDoubleClickEvent(self, event):
|
|
143
|
-
self.fit_image()
|
|
144
|
-
|
|
145
|
-
def wheelEvent(self, event):
|
|
146
|
-
factor = 1.15 if event.angleDelta().y() > 0 else 1 / 1.15
|
|
147
|
-
self.scale(factor, factor)
|
|
148
|
-
|
|
149
|
-
def resizeEvent(self, event):
|
|
150
|
-
super().resizeEvent(event)
|
|
151
|
-
|
|
152
|
-
def drawForeground(self, painter: QPainter, rect):
|
|
153
|
-
"""Draw status overlay in viewport coordinates (immune to pan/zoom)."""
|
|
154
|
-
if not self._overlay_on:
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
painter.save()
|
|
158
|
-
painter.resetTransform()
|
|
159
|
-
painter.setClipping(False)
|
|
160
|
-
|
|
161
|
-
font = QFont("Courier New" if __import__("sys").platform == "win32" else "monospace", 10)
|
|
162
|
-
painter.setFont(font)
|
|
163
|
-
fm = painter.fontMetrics()
|
|
164
|
-
|
|
165
|
-
h_idx = self._h_axis()
|
|
166
|
-
v_idx = self._v_axis()
|
|
167
|
-
|
|
168
|
-
# Line 1: current coordinate values
|
|
169
|
-
coord_str = " ".join(
|
|
170
|
-
f"{name}={self.axis_values[i][self.pos[i]]}"
|
|
171
|
-
for i, name in enumerate(self.axis_names)
|
|
172
|
-
)
|
|
173
|
-
|
|
174
|
-
# Line 2: arrow bindings
|
|
175
|
-
h_name = self.axis_names[h_idx]
|
|
176
|
-
v_name = self.axis_names[v_idx] if v_idx is not None else "—"
|
|
177
|
-
bind_str = f"→/← {h_name} ↑/↓ {v_name}"
|
|
178
|
-
|
|
179
|
-
# Line 3: key hints
|
|
180
|
-
key_hints = " ".join(
|
|
181
|
-
f"[{ch}] {self.axis_names[self.key_to_axis[ch]]}"
|
|
182
|
-
for ch in sorted(self.key_to_axis)
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
lines = [coord_str, bind_str]
|
|
186
|
-
if key_hints:
|
|
187
|
-
lines.append(key_hints)
|
|
188
|
-
|
|
189
|
-
margin = 8
|
|
190
|
-
pad = 6
|
|
191
|
-
line_h = fm.height() + 2
|
|
192
|
-
box_w = max(fm.horizontalAdvance(l) for l in lines) + pad * 2
|
|
193
|
-
box_h = line_h * len(lines) + pad * 2 - 2
|
|
194
|
-
|
|
195
|
-
painter.fillRect(margin, margin, box_w, box_h, QColor(0, 0, 0, 170))
|
|
196
|
-
painter.setPen(QColor(255, 255, 255))
|
|
197
|
-
for j, line in enumerate(lines):
|
|
198
|
-
painter.drawText(margin + pad, margin + pad + fm.ascent() + j * line_h, line)
|
|
199
|
-
|
|
200
|
-
painter.restore()
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
class MainWindow(QMainWindow):
|
|
204
|
-
def __init__(self, config: Config, pixmaps: dict):
|
|
205
|
-
super().__init__()
|
|
206
|
-
self.setWindowTitle("juxt")
|
|
207
|
-
self.view = ImageView(config, pixmaps, self)
|
|
208
|
-
self.setCentralWidget(self.view)
|
|
209
|
-
self.resize(1280, 860)
|
|
210
|
-
QTimer.singleShot(0, self.view.fit_image)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|