juxt 0.2.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.2.0 → juxt-0.3.0}/PKG-INFO +1 -1
- juxt-0.3.0/juxt/__main__.py +116 -0
- {juxt-0.2.0 → juxt-0.3.0}/juxt/_version.py +2 -2
- juxt-0.3.0/juxt/detect.py +166 -0
- {juxt-0.2.0 → juxt-0.3.0}/juxt/viewer.py +238 -2
- juxt-0.2.0/juxt/__main__.py +0 -71
- {juxt-0.2.0 → juxt-0.3.0}/.gitignore +0 -0
- {juxt-0.2.0 → juxt-0.3.0}/README.md +0 -0
- {juxt-0.2.0 → juxt-0.3.0}/juxt/__init__.py +0 -0
- {juxt-0.2.0 → juxt-0.3.0}/juxt/config.py +0 -0
- {juxt-0.2.0 → juxt-0.3.0}/juxt/loader.py +0 -0
- {juxt-0.2.0 → juxt-0.3.0}/pyproject.toml +0 -0
- {juxt-0.2.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
|
|
@@ -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
|
|
@@ -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)
|
|
@@ -4,10 +4,39 @@ from enum import IntEnum
|
|
|
4
4
|
|
|
5
5
|
from PySide6.QtCore import Qt, QRectF, QTimer, Signal
|
|
6
6
|
from PySide6.QtGui import QColor, QKeyEvent, QPainter, QPixmap
|
|
7
|
-
from PySide6.QtWidgets import
|
|
7
|
+
from PySide6.QtWidgets import (
|
|
8
|
+
QApplication,
|
|
9
|
+
QGraphicsPixmapItem,
|
|
10
|
+
QGraphicsScene,
|
|
11
|
+
QGraphicsView,
|
|
12
|
+
QLabel,
|
|
13
|
+
QMainWindow,
|
|
14
|
+
)
|
|
8
15
|
|
|
9
16
|
from .config import Config
|
|
10
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
|
+
|
|
11
40
|
|
|
12
41
|
class NavMode(IntEnum):
|
|
13
42
|
TWIN = 0
|
|
@@ -54,6 +83,11 @@ class ImageView(QGraphicsView):
|
|
|
54
83
|
# value phase: {"phase": "value", "query": str, "axis_idx": int}
|
|
55
84
|
self._sel: dict | None = None
|
|
56
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
|
+
|
|
57
91
|
self.setFocusPolicy(Qt.StrongFocus)
|
|
58
92
|
self.setDragMode(QGraphicsView.ScrollHandDrag)
|
|
59
93
|
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
|
|
@@ -208,21 +242,179 @@ class ImageView(QGraphicsView):
|
|
|
208
242
|
|
|
209
243
|
return False
|
|
210
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
|
+
|
|
211
381
|
# ── public ────────────────────────────────────────────────────────────────
|
|
212
382
|
|
|
213
383
|
def fit_image(self):
|
|
214
384
|
self.fitInView(self._scene.sceneRect(), Qt.KeepAspectRatio)
|
|
215
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
|
+
|
|
216
404
|
def reset_zoom(self):
|
|
217
405
|
self.resetTransform()
|
|
218
406
|
|
|
407
|
+
def set_zoom(self, pct: float):
|
|
408
|
+
self.resetTransform()
|
|
409
|
+
self.scale(pct / 100.0, pct / 100.0)
|
|
410
|
+
|
|
219
411
|
# ── Qt overrides ──────────────────────────────────────────────────────────
|
|
220
412
|
|
|
221
413
|
def keyPressEvent(self, event: QKeyEvent):
|
|
222
414
|
k = event.key()
|
|
223
415
|
mods = event.modifiers()
|
|
224
416
|
|
|
225
|
-
#
|
|
417
|
+
# Truly global shortcuts — work in every state
|
|
226
418
|
if k == Qt.Key_H and mods == Qt.ControlModifier:
|
|
227
419
|
self.toggle_bar.emit()
|
|
228
420
|
return
|
|
@@ -231,6 +423,22 @@ class ImageView(QGraphicsView):
|
|
|
231
423
|
self._sel = None
|
|
232
424
|
self.state_changed.emit()
|
|
233
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
|
|
234
442
|
if k == Qt.Key_F and mods == Qt.NoModifier:
|
|
235
443
|
self.fit_image()
|
|
236
444
|
return
|
|
@@ -244,6 +452,12 @@ class ImageView(QGraphicsView):
|
|
|
244
452
|
super().keyPressEvent(event)
|
|
245
453
|
return
|
|
246
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
|
+
|
|
247
461
|
# Universal navigation keys (all modes)
|
|
248
462
|
if k == Qt.Key_Right:
|
|
249
463
|
self._navigate(self._h_axis(), 1)
|
|
@@ -367,6 +581,28 @@ class MainWindow(QMainWindow):
|
|
|
367
581
|
v = self.view
|
|
368
582
|
mode_str = f"[{v.nav_mode.label}]"
|
|
369
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
|
+
|
|
370
606
|
if v._sel is not None:
|
|
371
607
|
phase = v._sel["phase"]
|
|
372
608
|
query = v._sel["query"]
|
juxt-0.2.0/juxt/__main__.py
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
import sys
|
|
3
|
-
import warnings
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
from PySide6.QtCore import Qt
|
|
7
|
-
from PySide6.QtGui import QIcon
|
|
8
|
-
from PySide6.QtWidgets import QApplication, QProgressDialog
|
|
9
|
-
|
|
10
|
-
from .config import load_config
|
|
11
|
-
from .loader import preload
|
|
12
|
-
from .viewer import MainWindow
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def main():
|
|
16
|
-
if len(sys.argv) < 2:
|
|
17
|
-
print("Usage: juxt <config.yaml>")
|
|
18
|
-
sys.exit(1)
|
|
19
|
-
|
|
20
|
-
if sys.platform == "win32" and Path(sys.executable).stem.lower() in ("python", "pythonw"):
|
|
21
|
-
import ctypes
|
|
22
|
-
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("juxt")
|
|
23
|
-
|
|
24
|
-
app = QApplication(sys.argv)
|
|
25
|
-
app.setApplicationName("juxt")
|
|
26
|
-
_logo = Path(__file__).parent / "assets" / "logo_transparent.ico"
|
|
27
|
-
if not _logo.exists(): # fallback for editable installs
|
|
28
|
-
_logo = Path(__file__).parent.parent / "docs" / "assets" / "logo_transparent.ico"
|
|
29
|
-
app_icon = QIcon()
|
|
30
|
-
if _logo.exists():
|
|
31
|
-
app_icon = QIcon(str(_logo))
|
|
32
|
-
if app_icon.isNull():
|
|
33
|
-
warnings.warn(f"Icon file found but failed to load: {_logo}")
|
|
34
|
-
else:
|
|
35
|
-
app.setWindowIcon(app_icon)
|
|
36
|
-
else:
|
|
37
|
-
warnings.warn(f"No logo file found at {_logo}")
|
|
38
|
-
|
|
39
|
-
try:
|
|
40
|
-
config = load_config(sys.argv[1])
|
|
41
|
-
except Exception as e:
|
|
42
|
-
print(f"Error loading config: {e}", file=sys.stderr)
|
|
43
|
-
sys.exit(1)
|
|
44
|
-
|
|
45
|
-
total = 1
|
|
46
|
-
for vs in config.axes.values():
|
|
47
|
-
total *= len(vs)
|
|
48
|
-
|
|
49
|
-
progress = QProgressDialog("Loading images…", None, 0, total)
|
|
50
|
-
progress.setWindowTitle("juxt")
|
|
51
|
-
progress.setWindowModality(Qt.ApplicationModal)
|
|
52
|
-
progress.setMinimumDuration(0)
|
|
53
|
-
progress.setValue(0)
|
|
54
|
-
|
|
55
|
-
def on_progress(i: int, n: int):
|
|
56
|
-
progress.setValue(i)
|
|
57
|
-
app.processEvents()
|
|
58
|
-
|
|
59
|
-
pixmaps = preload(config.template, config.axes, on_progress)
|
|
60
|
-
progress.close()
|
|
61
|
-
|
|
62
|
-
window = MainWindow(config, pixmaps)
|
|
63
|
-
window.showMaximized()
|
|
64
|
-
app.processEvents()
|
|
65
|
-
if not app_icon.isNull():
|
|
66
|
-
window.setWindowIcon(app_icon)
|
|
67
|
-
sys.exit(app.exec())
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if __name__ == "__main__":
|
|
71
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|