juxt 1.1.2__tar.gz → 1.2.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-1.1.2 → juxt-1.2.0}/PKG-INFO +7 -2
- {juxt-1.1.2 → juxt-1.2.0}/README.md +6 -1
- {juxt-1.1.2 → juxt-1.2.0}/juxt/__main__.py +39 -0
- {juxt-1.1.2 → juxt-1.2.0}/juxt/_version.py +2 -2
- {juxt-1.1.2 → juxt-1.2.0}/juxt/viewer.py +537 -31
- {juxt-1.1.2 → juxt-1.2.0}/.gitignore +0 -0
- {juxt-1.1.2 → juxt-1.2.0}/examples/sample_config.yaml +0 -0
- {juxt-1.1.2 → juxt-1.2.0}/juxt/__init__.py +0 -0
- {juxt-1.1.2 → juxt-1.2.0}/juxt/config.py +0 -0
- {juxt-1.1.2 → juxt-1.2.0}/juxt/detect.py +0 -0
- {juxt-1.1.2 → juxt-1.2.0}/juxt/loader.py +0 -0
- {juxt-1.1.2 → juxt-1.2.0}/juxt/settings.py +0 -0
- {juxt-1.1.2 → juxt-1.2.0}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: juxt
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
4
4
|
Summary: Fast desktop tool for navigating N-dimensional hypercubes of plots
|
|
5
5
|
Project-URL: Homepage, https://github.com/ColinMoldenhauer/juxt
|
|
6
6
|
Project-URL: Documentation, https://juxt.readthedocs.io
|
|
@@ -159,7 +159,12 @@ Press `:` to open the command bar (vim-style). Tab-completion narrows candidates
|
|
|
159
159
|
| `:fit height` / `:fit width` | fit to height or width |
|
|
160
160
|
| `:zoom N` | set zoom to N% |
|
|
161
161
|
| `:fullscreen` | toggle fullscreen |
|
|
162
|
-
| `:mode
|
|
162
|
+
| `:mode tap\|seek\|pin` | switch navigation mode |
|
|
163
|
+
| `:grid [AXIS]` | tile an axis into a grid of viewports |
|
|
164
|
+
| `:grid AXIS VAL …` | grid with a value subset |
|
|
165
|
+
| `:grid-layout NxM` | change grid layout without exiting |
|
|
166
|
+
| `:ungrid` | return to single-image view |
|
|
167
|
+
| `:grid-sharex` / `:grid-sharey` | toggle synchronized pan/zoom |
|
|
163
168
|
|
|
164
169
|
## Controls
|
|
165
170
|
|
|
@@ -126,7 +126,12 @@ Press `:` to open the command bar (vim-style). Tab-completion narrows candidates
|
|
|
126
126
|
| `:fit height` / `:fit width` | fit to height or width |
|
|
127
127
|
| `:zoom N` | set zoom to N% |
|
|
128
128
|
| `:fullscreen` | toggle fullscreen |
|
|
129
|
-
| `:mode
|
|
129
|
+
| `:mode tap\|seek\|pin` | switch navigation mode |
|
|
130
|
+
| `:grid [AXIS]` | tile an axis into a grid of viewports |
|
|
131
|
+
| `:grid AXIS VAL …` | grid with a value subset |
|
|
132
|
+
| `:grid-layout NxM` | change grid layout without exiting |
|
|
133
|
+
| `:ungrid` | return to single-image view |
|
|
134
|
+
| `:grid-sharex` / `:grid-sharey` | toggle synchronized pan/zoom |
|
|
130
135
|
|
|
131
136
|
## Controls
|
|
132
137
|
|
|
@@ -138,6 +138,13 @@ def _print_help() -> None:
|
|
|
138
138
|
--axis-v NAME lock ↑/↓ to this axis on startup
|
|
139
139
|
--squeeze drop axes with only one value
|
|
140
140
|
--name NAME session name shown in window title (default: template basename)
|
|
141
|
+
|
|
142
|
+
grid view
|
|
143
|
+
--grid AXIS enter grid view for AXIS on startup
|
|
144
|
+
--grid-values VAL ... show only these values in the grid (requires --grid)
|
|
145
|
+
--grid-layout NxM explicit grid layout, e.g. 2x3 (requires --grid)
|
|
146
|
+
--no-sharex disable synchronized horizontal pan/zoom in grid view
|
|
147
|
+
--no-sharey disable synchronized vertical pan/zoom in grid view
|
|
141
148
|
-h, --help show this message and exit
|
|
142
149
|
|
|
143
150
|
navigation modes (switch with :mode)
|
|
@@ -170,6 +177,14 @@ def _parse_args() -> argparse.Namespace:
|
|
|
170
177
|
p.add_argument("--axis-v", metavar="NAME", default=None)
|
|
171
178
|
p.add_argument("--squeeze", action="store_true", default=False)
|
|
172
179
|
p.add_argument("--name", metavar="NAME", default=None)
|
|
180
|
+
|
|
181
|
+
g = p.add_argument_group("grid view")
|
|
182
|
+
g.add_argument("--grid", metavar="AXIS", default=None)
|
|
183
|
+
g.add_argument("--grid-values", metavar="VAL", nargs="+", default=None)
|
|
184
|
+
g.add_argument("--grid-layout", metavar="NxM", default=None)
|
|
185
|
+
g.add_argument("--no-sharex", action="store_true", default=False)
|
|
186
|
+
g.add_argument("--no-sharey", action="store_true", default=False)
|
|
187
|
+
|
|
173
188
|
p.add_argument("-h", "--help", action=_HelpAction)
|
|
174
189
|
return p.parse_args()
|
|
175
190
|
|
|
@@ -372,6 +387,25 @@ def main():
|
|
|
372
387
|
if name and name not in axis_names:
|
|
373
388
|
print(f"Warning: {flag} {name!r} not found in axes {axis_names}", file=sys.stderr)
|
|
374
389
|
|
|
390
|
+
grid_layout: tuple[int, int] | None = None
|
|
391
|
+
if args.grid_layout:
|
|
392
|
+
import re as _re
|
|
393
|
+
m = _re.match(r'^(\d+)x(\d+)$', args.grid_layout, _re.IGNORECASE)
|
|
394
|
+
if not m:
|
|
395
|
+
print(f"Warning: --grid-layout {args.grid_layout!r} is not a valid NxM layout, ignoring",
|
|
396
|
+
file=sys.stderr)
|
|
397
|
+
else:
|
|
398
|
+
grid_layout = (int(m.group(1)), int(m.group(2)))
|
|
399
|
+
|
|
400
|
+
if args.grid and args.grid not in axis_names:
|
|
401
|
+
print(f"Warning: --grid {args.grid!r} not found in axes {axis_names}", file=sys.stderr)
|
|
402
|
+
|
|
403
|
+
if args.grid_values and not args.grid:
|
|
404
|
+
print("Warning: --grid-values has no effect without --grid", file=sys.stderr)
|
|
405
|
+
|
|
406
|
+
if args.grid_layout and not args.grid:
|
|
407
|
+
print("Warning: --grid-layout has no effect without --grid", file=sys.stderr)
|
|
408
|
+
|
|
375
409
|
window = MainWindow(
|
|
376
410
|
config, pixmaps,
|
|
377
411
|
watch=not args.no_watch,
|
|
@@ -384,6 +418,11 @@ def main():
|
|
|
384
418
|
session_name=args.name,
|
|
385
419
|
seek_greedy=settings.seek_greedy,
|
|
386
420
|
keybindings=settings.keybindings,
|
|
421
|
+
grid=args.grid,
|
|
422
|
+
grid_values=args.grid_values,
|
|
423
|
+
grid_layout=grid_layout,
|
|
424
|
+
grid_sharex=not args.no_sharex,
|
|
425
|
+
grid_sharey=not args.no_sharey,
|
|
387
426
|
)
|
|
388
427
|
window.move(_startup_screen.geometry().topLeft())
|
|
389
428
|
window.showMaximized()
|
|
@@ -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 = '1.
|
|
22
|
-
__version_tuple__ = version_tuple = (1,
|
|
21
|
+
__version__ = version = '1.2.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 2, 0)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -7,7 +7,7 @@ import threading
|
|
|
7
7
|
from enum import IntEnum
|
|
8
8
|
from typing import Literal
|
|
9
9
|
|
|
10
|
-
from PySide6.QtCore import Qt, QFileSystemWatcher, QRectF, QTimer, Signal
|
|
10
|
+
from PySide6.QtCore import QEvent, Qt, QFileSystemWatcher, QRectF, QTimer, Signal
|
|
11
11
|
from PySide6.QtGui import QColor, QKeyEvent, QPainter, QPixmap
|
|
12
12
|
from PySide6.QtWidgets import (
|
|
13
13
|
QApplication,
|
|
@@ -15,10 +15,13 @@ from PySide6.QtWidgets import (
|
|
|
15
15
|
QGraphicsPixmapItem,
|
|
16
16
|
QGraphicsScene,
|
|
17
17
|
QGraphicsView,
|
|
18
|
+
QGridLayout,
|
|
18
19
|
QLabel,
|
|
19
20
|
QMainWindow,
|
|
20
21
|
QSizePolicy,
|
|
22
|
+
QStackedWidget,
|
|
21
23
|
QTextEdit,
|
|
24
|
+
QWidget,
|
|
22
25
|
)
|
|
23
26
|
|
|
24
27
|
from .config import Config
|
|
@@ -139,6 +142,10 @@ _COMMANDS = [
|
|
|
139
142
|
"fit-height",
|
|
140
143
|
"fit-width",
|
|
141
144
|
"fullscreen",
|
|
145
|
+
"grid",
|
|
146
|
+
"grid-layout",
|
|
147
|
+
"grid-sharex",
|
|
148
|
+
"grid-sharey",
|
|
142
149
|
"info",
|
|
143
150
|
"mode",
|
|
144
151
|
"pattern",
|
|
@@ -147,6 +154,7 @@ _COMMANDS = [
|
|
|
147
154
|
"remove-axis",
|
|
148
155
|
"settings",
|
|
149
156
|
"remove-value",
|
|
157
|
+
"ungrid",
|
|
150
158
|
"watch",
|
|
151
159
|
"write",
|
|
152
160
|
"swap-axes",
|
|
@@ -166,6 +174,10 @@ _CMD_ARGS: dict[str, list[str]] = {
|
|
|
166
174
|
"axis-h": [],
|
|
167
175
|
"axis-v": [],
|
|
168
176
|
"change-key": [],
|
|
177
|
+
"grid": [],
|
|
178
|
+
"grid-layout": [],
|
|
179
|
+
"grid-sharex": ["on", "off"],
|
|
180
|
+
"grid-sharey": ["on", "off"],
|
|
169
181
|
"mode": ["tap", "seek", "pin"],
|
|
170
182
|
"pattern": [], # free-text path / template
|
|
171
183
|
"remove-axis": [],
|
|
@@ -181,29 +193,34 @@ _FREE_TEXT_ARGS = {"change-key", "pattern", "remove-axis", "remove-value", "writ
|
|
|
181
193
|
_SPINNER = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
|
|
182
194
|
|
|
183
195
|
_COMMAND_HELP: dict[str, str] = {
|
|
184
|
-
"axis-auto":
|
|
185
|
-
"change-key":
|
|
186
|
-
"copy-image":
|
|
187
|
-
"copy-path":
|
|
188
|
-
"axis-h":
|
|
189
|
-
"axis-v":
|
|
190
|
-
"fit":
|
|
191
|
-
"fit-height":
|
|
192
|
-
"fit-width":
|
|
193
|
-
"fullscreen":
|
|
194
|
-
"
|
|
195
|
-
"
|
|
196
|
-
"
|
|
197
|
-
"
|
|
198
|
-
"
|
|
199
|
-
"
|
|
200
|
-
"
|
|
196
|
+
"axis-auto": "restore dynamic axis-to-arrow assignment",
|
|
197
|
+
"change-key": "assign a key letter to an axis (e.g. change-key sensor x)",
|
|
198
|
+
"copy-image": "copy current image to clipboard",
|
|
199
|
+
"copy-path": "copy current image file path to clipboard",
|
|
200
|
+
"axis-h": "lock ←/→ to a named axis",
|
|
201
|
+
"axis-v": "lock ↑/↓ to a named axis",
|
|
202
|
+
"fit": "fit image to window",
|
|
203
|
+
"fit-height": "fit image height to viewport",
|
|
204
|
+
"fit-width": "fit image width to viewport",
|
|
205
|
+
"fullscreen": "toggle fullscreen",
|
|
206
|
+
"grid": "expand an axis into a tiled grid (e.g. grid sensor / grid sensor SMAP SMOS / grid sensor 2x2)",
|
|
207
|
+
"grid-layout": "change the grid layout without exiting (e.g. grid-layout 2x3)",
|
|
208
|
+
"grid-sharex": "toggle or set synchronized horizontal pan/zoom (on / off)",
|
|
209
|
+
"grid-sharey": "toggle or set synchronized vertical pan/zoom (on / off)",
|
|
210
|
+
"info": "toggle the info sidebar",
|
|
211
|
+
"mode": "switch navigation mode (tap / seek / pin)",
|
|
212
|
+
"pattern": "change the template / source path without restarting",
|
|
213
|
+
"quit": "quit juxt",
|
|
214
|
+
"reload": "re-detect axes and reload images",
|
|
215
|
+
"settings": "open ~/.juxt/settings.yaml in the default editor",
|
|
216
|
+
"remove-axis": "remove an axis (collapses to its current value)",
|
|
201
217
|
"remove-value": "remove a value from an axis (e.g. remove-value sensor SMAP)",
|
|
202
|
-
"
|
|
203
|
-
"
|
|
204
|
-
"
|
|
205
|
-
"
|
|
206
|
-
"
|
|
218
|
+
"ungrid": "return to single-image view",
|
|
219
|
+
"write": "write current config to a YAML file",
|
|
220
|
+
"swap-axes": "swap the ←/→ and ↑/↓ axis bindings",
|
|
221
|
+
"switch-last": "toggle between current and previous position",
|
|
222
|
+
"watch": "enable / disable / configure file watching",
|
|
223
|
+
"zoom": "set zoom level (e.g. zoom 150)",
|
|
207
224
|
}
|
|
208
225
|
|
|
209
226
|
|
|
@@ -277,11 +294,228 @@ def _window_title(config: "Config", session_name: str | None = None) -> str:
|
|
|
277
294
|
return f"juxt | {name}"
|
|
278
295
|
|
|
279
296
|
|
|
297
|
+
class _CellView(QGraphicsView):
|
|
298
|
+
"""Single-image viewport used inside GridWidget."""
|
|
299
|
+
|
|
300
|
+
zoomed = Signal(object) # emits self.transform() after a wheel-zoom
|
|
301
|
+
|
|
302
|
+
def __init__(self, label: str, parent=None):
|
|
303
|
+
scene = QGraphicsScene()
|
|
304
|
+
super().__init__(scene, parent)
|
|
305
|
+
self._scene = scene
|
|
306
|
+
self._item = QGraphicsPixmapItem()
|
|
307
|
+
self._item.setTransformationMode(Qt.SmoothTransformation)
|
|
308
|
+
scene.addItem(self._item)
|
|
309
|
+
self._fit: Literal["image", "height", "width"] | None = None
|
|
310
|
+
self._label_text = label
|
|
311
|
+
|
|
312
|
+
self.setDragMode(QGraphicsView.ScrollHandDrag)
|
|
313
|
+
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
|
|
314
|
+
self.setResizeAnchor(QGraphicsView.AnchorViewCenter)
|
|
315
|
+
self.setRenderHint(QPainter.SmoothPixmapTransform)
|
|
316
|
+
self.setBackgroundBrush(QColor(25, 25, 25))
|
|
317
|
+
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
318
|
+
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
319
|
+
self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
|
|
320
|
+
|
|
321
|
+
def set_pixmap(self, pm: QPixmap):
|
|
322
|
+
self._item.setPixmap(pm)
|
|
323
|
+
self._scene.setSceneRect(QRectF(pm.rect()))
|
|
324
|
+
if self._fit is not None:
|
|
325
|
+
getattr(self, f"fit_{self._fit}")()
|
|
326
|
+
|
|
327
|
+
def fit_image(self):
|
|
328
|
+
self.fitInView(self._scene.sceneRect(), Qt.KeepAspectRatio)
|
|
329
|
+
self._fit = "image"
|
|
330
|
+
|
|
331
|
+
def fit_height(self):
|
|
332
|
+
pm = self._item.pixmap()
|
|
333
|
+
if pm.isNull():
|
|
334
|
+
return
|
|
335
|
+
self.resetTransform()
|
|
336
|
+
self.scale(self.viewport().height() / pm.height(),
|
|
337
|
+
self.viewport().height() / pm.height())
|
|
338
|
+
self.centerOn(self._scene.sceneRect().center())
|
|
339
|
+
self._fit = "height"
|
|
340
|
+
|
|
341
|
+
def fit_width(self):
|
|
342
|
+
pm = self._item.pixmap()
|
|
343
|
+
if pm.isNull():
|
|
344
|
+
return
|
|
345
|
+
self.resetTransform()
|
|
346
|
+
self.scale(self.viewport().width() / pm.width(),
|
|
347
|
+
self.viewport().width() / pm.width())
|
|
348
|
+
self.centerOn(self._scene.sceneRect().center())
|
|
349
|
+
self._fit = "width"
|
|
350
|
+
|
|
351
|
+
def set_zoom(self, pct: float):
|
|
352
|
+
self._fit = None
|
|
353
|
+
self.resetTransform()
|
|
354
|
+
self.scale(pct / 100.0, pct / 100.0)
|
|
355
|
+
|
|
356
|
+
def reset_zoom(self):
|
|
357
|
+
self._fit = None
|
|
358
|
+
self.resetTransform()
|
|
359
|
+
|
|
360
|
+
def wheelEvent(self, event):
|
|
361
|
+
if event.modifiers() & Qt.ControlModifier:
|
|
362
|
+
factor = 1.15 ** (event.angleDelta().y() / 120)
|
|
363
|
+
self.scale(factor, factor)
|
|
364
|
+
self._fit = None
|
|
365
|
+
self.zoomed.emit(self.transform())
|
|
366
|
+
else:
|
|
367
|
+
super().wheelEvent(event)
|
|
368
|
+
|
|
369
|
+
def drawForeground(self, painter: QPainter, _rect):
|
|
370
|
+
if not self._label_text:
|
|
371
|
+
return
|
|
372
|
+
painter.save()
|
|
373
|
+
painter.resetTransform() # switch to viewport pixel coordinates
|
|
374
|
+
fm = painter.fontMetrics()
|
|
375
|
+
pad_x, pad_y, margin = 5, 2, 4
|
|
376
|
+
text_w = fm.horizontalAdvance(self._label_text)
|
|
377
|
+
text_h = fm.height()
|
|
378
|
+
bg = QRectF(margin, margin, text_w + 2 * pad_x, text_h + 2 * pad_y)
|
|
379
|
+
painter.fillRect(bg, QColor(0, 0, 0, 160))
|
|
380
|
+
painter.setPen(QColor(224, 224, 224))
|
|
381
|
+
painter.drawText(
|
|
382
|
+
int(bg.x() + pad_x),
|
|
383
|
+
int(bg.y() + pad_y + text_h - fm.descent()),
|
|
384
|
+
self._label_text,
|
|
385
|
+
)
|
|
386
|
+
painter.restore()
|
|
387
|
+
|
|
388
|
+
def mouseDoubleClickEvent(self, _event):
|
|
389
|
+
self.fit_image()
|
|
390
|
+
|
|
391
|
+
def resizeEvent(self, event):
|
|
392
|
+
super().resizeEvent(event)
|
|
393
|
+
if self._fit is not None:
|
|
394
|
+
getattr(self, f"fit_{self._fit}")()
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
class GridWidget(QWidget):
|
|
398
|
+
"""Grid of independent image viewports with optional scroll/zoom sync."""
|
|
399
|
+
|
|
400
|
+
def __init__(
|
|
401
|
+
self,
|
|
402
|
+
image_view: "ImageView",
|
|
403
|
+
rows: int,
|
|
404
|
+
cols: int,
|
|
405
|
+
labels: list[str],
|
|
406
|
+
sharex: bool,
|
|
407
|
+
sharey: bool,
|
|
408
|
+
):
|
|
409
|
+
super().__init__()
|
|
410
|
+
self._image_view = image_view
|
|
411
|
+
self._sharex = sharex
|
|
412
|
+
self._sharey = sharey
|
|
413
|
+
self._syncing = False
|
|
414
|
+
|
|
415
|
+
layout = QGridLayout(self)
|
|
416
|
+
layout.setSpacing(4)
|
|
417
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
418
|
+
self._cells: list[_CellView] = []
|
|
419
|
+
|
|
420
|
+
for i, label in enumerate(labels):
|
|
421
|
+
row, col = i // cols, i % cols
|
|
422
|
+
cell = _CellView(label)
|
|
423
|
+
layout.addWidget(cell, row, col)
|
|
424
|
+
self._cells.append(cell)
|
|
425
|
+
cell.horizontalScrollBar().valueChanged.connect(
|
|
426
|
+
lambda val, c=cell: self._on_hscroll(val, c)
|
|
427
|
+
)
|
|
428
|
+
cell.verticalScrollBar().valueChanged.connect(
|
|
429
|
+
lambda val, c=cell: self._on_vscroll(val, c)
|
|
430
|
+
)
|
|
431
|
+
cell.zoomed.connect(lambda t, c=cell: self._on_zoom(t, c))
|
|
432
|
+
|
|
433
|
+
# ── sync handlers ─────────────────────────────────────────────────────────
|
|
434
|
+
|
|
435
|
+
def _on_hscroll(self, val: int, source: _CellView):
|
|
436
|
+
if self._syncing or not self._sharex:
|
|
437
|
+
return
|
|
438
|
+
self._syncing = True
|
|
439
|
+
for cell in self._cells:
|
|
440
|
+
if cell is not source:
|
|
441
|
+
cell.horizontalScrollBar().setValue(val)
|
|
442
|
+
self._syncing = False
|
|
443
|
+
|
|
444
|
+
def _on_vscroll(self, val: int, source: _CellView):
|
|
445
|
+
if self._syncing or not self._sharey:
|
|
446
|
+
return
|
|
447
|
+
self._syncing = True
|
|
448
|
+
for cell in self._cells:
|
|
449
|
+
if cell is not source:
|
|
450
|
+
cell.verticalScrollBar().setValue(val)
|
|
451
|
+
self._syncing = False
|
|
452
|
+
|
|
453
|
+
def _on_zoom(self, transform, source: _CellView):
|
|
454
|
+
if self._syncing or (not self._sharex and not self._sharey):
|
|
455
|
+
return
|
|
456
|
+
self._syncing = True
|
|
457
|
+
h = source.horizontalScrollBar().value()
|
|
458
|
+
v = source.verticalScrollBar().value()
|
|
459
|
+
for cell in self._cells:
|
|
460
|
+
if cell is not source:
|
|
461
|
+
cell.setTransform(transform)
|
|
462
|
+
if self._sharex:
|
|
463
|
+
cell.horizontalScrollBar().setValue(h)
|
|
464
|
+
if self._sharey:
|
|
465
|
+
cell.verticalScrollBar().setValue(v)
|
|
466
|
+
self._syncing = False
|
|
467
|
+
|
|
468
|
+
# ── public API ────────────────────────────────────────────────────────────
|
|
469
|
+
|
|
470
|
+
def update_cells(self, base_pos: list, axis_idx: int, indices: list[int], pixmaps: dict):
|
|
471
|
+
for grid_i, vi in enumerate(indices):
|
|
472
|
+
if grid_i >= len(self._cells):
|
|
473
|
+
break
|
|
474
|
+
key = list(base_pos)
|
|
475
|
+
key[axis_idx] = vi
|
|
476
|
+
pm = pixmaps.get(tuple(key))
|
|
477
|
+
if pm and not pm.isNull():
|
|
478
|
+
self._cells[grid_i].set_pixmap(pm)
|
|
479
|
+
|
|
480
|
+
def fit_image(self):
|
|
481
|
+
for cell in self._cells:
|
|
482
|
+
cell.fit_image()
|
|
483
|
+
|
|
484
|
+
def fit_height(self):
|
|
485
|
+
for cell in self._cells:
|
|
486
|
+
cell.fit_height()
|
|
487
|
+
|
|
488
|
+
def fit_width(self):
|
|
489
|
+
for cell in self._cells:
|
|
490
|
+
cell.fit_width()
|
|
491
|
+
|
|
492
|
+
def set_zoom(self, pct: float):
|
|
493
|
+
for cell in self._cells:
|
|
494
|
+
cell.set_zoom(pct)
|
|
495
|
+
|
|
496
|
+
def reset_zoom(self):
|
|
497
|
+
for cell in self._cells:
|
|
498
|
+
cell.reset_zoom()
|
|
499
|
+
|
|
500
|
+
def set_sharex(self, val: bool):
|
|
501
|
+
self._sharex = val
|
|
502
|
+
|
|
503
|
+
def set_sharey(self, val: bool):
|
|
504
|
+
self._sharey = val
|
|
505
|
+
|
|
506
|
+
def keyPressEvent(self, event):
|
|
507
|
+
self._image_view.keyPressEvent(event)
|
|
508
|
+
|
|
509
|
+
def mouseDoubleClickEvent(self, _event):
|
|
510
|
+
self.fit_image()
|
|
511
|
+
|
|
512
|
+
|
|
280
513
|
class ImageView(QGraphicsView):
|
|
281
514
|
state_changed = Signal()
|
|
282
515
|
toggle_bar = Signal()
|
|
283
516
|
toggle_info = Signal()
|
|
284
517
|
config_changed = Signal() # emitted after reload/pattern successfully replaces config
|
|
518
|
+
grid_mode_changed = Signal(object) # emits GridWidget on enter, None on exit
|
|
285
519
|
_poll_result = Signal(object) # emitted from poll worker; carries list or Exception
|
|
286
520
|
_reload_result = Signal(object) # emitted from reload worker; carries tuple or Exception
|
|
287
521
|
_pattern_result = Signal(object) # emitted from pattern worker; carries dict or Exception
|
|
@@ -301,6 +535,11 @@ class ImageView(QGraphicsView):
|
|
|
301
535
|
axis_v: str | None = None,
|
|
302
536
|
seek_greedy: bool = True,
|
|
303
537
|
keybindings: dict[str, str] | None = None,
|
|
538
|
+
grid: str | None = None,
|
|
539
|
+
grid_values: list[str] | None = None,
|
|
540
|
+
grid_layout: tuple[int, int] | None = None,
|
|
541
|
+
grid_sharex: bool = True,
|
|
542
|
+
grid_sharey: bool = True,
|
|
304
543
|
):
|
|
305
544
|
self._scene = QGraphicsScene()
|
|
306
545
|
super().__init__(self._scene, parent)
|
|
@@ -378,6 +617,7 @@ class ImageView(QGraphicsView):
|
|
|
378
617
|
self._cmd: dict | None = None
|
|
379
618
|
|
|
380
619
|
self.setFocusPolicy(Qt.StrongFocus)
|
|
620
|
+
QApplication.instance().installEventFilter(self)
|
|
381
621
|
self.setDragMode(QGraphicsView.ScrollHandDrag)
|
|
382
622
|
self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
|
|
383
623
|
self.setResizeAnchor(QGraphicsView.AnchorViewCenter)
|
|
@@ -390,8 +630,26 @@ class ImageView(QGraphicsView):
|
|
|
390
630
|
self._item.setTransformationMode(Qt.SmoothTransformation)
|
|
391
631
|
self._scene.addItem(self._item)
|
|
392
632
|
|
|
633
|
+
# Grid-view state
|
|
634
|
+
self._grid_axis: int | None = None
|
|
635
|
+
self._grid_filter: list[int] | None = None # None = all values
|
|
636
|
+
self._grid_layout: tuple[int, int] | None = None # explicit (rows, cols)
|
|
637
|
+
self._grid_sharex: bool = grid_sharex
|
|
638
|
+
self._grid_sharey: bool = grid_sharey
|
|
639
|
+
self._grid_widget: GridWidget | None = None
|
|
640
|
+
|
|
393
641
|
self._refresh()
|
|
394
642
|
|
|
643
|
+
if grid and grid in self.axis_names:
|
|
644
|
+
axis_idx = self.axis_names.index(grid)
|
|
645
|
+
filter_indices: list[int] | None = None
|
|
646
|
+
if grid_values:
|
|
647
|
+
vals = self.axis_values[axis_idx]
|
|
648
|
+
filter_indices = [i for i, v in enumerate(vals) if v in grid_values] or None
|
|
649
|
+
log.debug("startup grid: axis=%r filter=%r layout=%r", grid, filter_indices, grid_layout)
|
|
650
|
+
# Defer until the event loop starts so MainWindow has connected grid_mode_changed
|
|
651
|
+
QTimer.singleShot(0, lambda: self._enter_grid(axis_idx, filter_indices, grid_layout))
|
|
652
|
+
|
|
395
653
|
if watch:
|
|
396
654
|
if config.remote is None:
|
|
397
655
|
self._start_watching(silent=True)
|
|
@@ -404,6 +662,9 @@ class ImageView(QGraphicsView):
|
|
|
404
662
|
return tuple(self.pos)
|
|
405
663
|
|
|
406
664
|
def _refresh(self):
|
|
665
|
+
if self._grid_axis is not None:
|
|
666
|
+
self._refresh_grid()
|
|
667
|
+
return
|
|
407
668
|
pm = self.pixmaps.get(self._key())
|
|
408
669
|
if pm:
|
|
409
670
|
self._item.setPixmap(pm)
|
|
@@ -411,6 +672,65 @@ class ImageView(QGraphicsView):
|
|
|
411
672
|
self.viewport().update()
|
|
412
673
|
self.state_changed.emit()
|
|
413
674
|
|
|
675
|
+
def _refresh_grid(self):
|
|
676
|
+
if self._grid_widget is None:
|
|
677
|
+
log.debug("_refresh_grid: no grid widget, skipping")
|
|
678
|
+
return
|
|
679
|
+
indices = (self._grid_filter if self._grid_filter is not None
|
|
680
|
+
else list(range(len(self.axis_values[self._grid_axis]))))
|
|
681
|
+
log.debug("_refresh_grid: axis=%d indices=%s pos=%s", self._grid_axis, indices, self.pos)
|
|
682
|
+
self._grid_widget.update_cells(self.pos, self._grid_axis, indices, self.pixmaps)
|
|
683
|
+
self.state_changed.emit()
|
|
684
|
+
|
|
685
|
+
def _enter_grid(self, axis_idx: int, filter_indices: list[int] | None, layout: tuple[int, int] | None):
|
|
686
|
+
import math
|
|
687
|
+
self._grid_axis = axis_idx
|
|
688
|
+
self._grid_filter = filter_indices
|
|
689
|
+
self._grid_layout = layout
|
|
690
|
+
|
|
691
|
+
all_vals = self.axis_values[axis_idx]
|
|
692
|
+
indices = filter_indices if filter_indices is not None else list(range(len(all_vals)))
|
|
693
|
+
n = len(indices)
|
|
694
|
+
log.debug("_enter_grid: axis=%r n=%d filter=%r layout=%r", self.axis_names[axis_idx], n, filter_indices, layout)
|
|
695
|
+
|
|
696
|
+
# Sample image dimensions for aspect-ratio-aware auto layout
|
|
697
|
+
img_w, img_h = 800, 600
|
|
698
|
+
for vi in indices:
|
|
699
|
+
key = list(self.pos)
|
|
700
|
+
key[axis_idx] = vi
|
|
701
|
+
pm = self.pixmaps.get(tuple(key))
|
|
702
|
+
if pm and not pm.isNull():
|
|
703
|
+
img_w, img_h = pm.width(), pm.height()
|
|
704
|
+
break
|
|
705
|
+
log.debug("_enter_grid: image size %dx%d", img_w, img_h)
|
|
706
|
+
|
|
707
|
+
if layout is not None:
|
|
708
|
+
rows, cols = layout
|
|
709
|
+
else:
|
|
710
|
+
vp = self.viewport()
|
|
711
|
+
vp_ar = vp.width() / max(1, vp.height())
|
|
712
|
+
cols, rows = min(
|
|
713
|
+
((c, math.ceil(n / c)) for c in range(1, n + 1)),
|
|
714
|
+
key=lambda cr: abs((cr[0] * img_w) / max(1, cr[1] * img_h) - vp_ar),
|
|
715
|
+
)
|
|
716
|
+
log.info("grid: axis=%r %d cells layout=%dx%d sharex=%s sharey=%s",
|
|
717
|
+
self.axis_names[axis_idx], n, rows, cols, self._grid_sharex, self._grid_sharey)
|
|
718
|
+
|
|
719
|
+
labels = [all_vals[vi] for vi in indices]
|
|
720
|
+
gw = GridWidget(self, rows, cols, labels, self._grid_sharex, self._grid_sharey)
|
|
721
|
+
self._grid_widget = gw
|
|
722
|
+
self._refresh_grid()
|
|
723
|
+
self.grid_mode_changed.emit(gw)
|
|
724
|
+
|
|
725
|
+
def _exit_grid(self):
|
|
726
|
+
log.info("grid: exiting grid mode (was axis=%r)", self.axis_names[self._grid_axis] if self._grid_axis is not None else None)
|
|
727
|
+
self._grid_axis = None
|
|
728
|
+
self._grid_filter = None
|
|
729
|
+
self._grid_layout = None
|
|
730
|
+
self._grid_widget = None
|
|
731
|
+
self.grid_mode_changed.emit(None)
|
|
732
|
+
self._refresh()
|
|
733
|
+
|
|
414
734
|
def _h_axis(self) -> int:
|
|
415
735
|
return self._locked_h if self._locked_h is not None else self.focus_stack[0]
|
|
416
736
|
|
|
@@ -551,9 +871,31 @@ class ImageView(QGraphicsView):
|
|
|
551
871
|
pool = _COMMANDS
|
|
552
872
|
else:
|
|
553
873
|
verb = self._cmd["verb"]
|
|
554
|
-
|
|
874
|
+
if verb in ("axis-h", "axis-v", "remove-axis"):
|
|
875
|
+
pool = list(self.axis_names)
|
|
876
|
+
elif verb == "grid":
|
|
877
|
+
return self._grid_cmd_candidates(self._cmd["query"])
|
|
878
|
+
else:
|
|
879
|
+
pool = _CMD_ARGS.get(verb, [])
|
|
555
880
|
return [c for c in pool if c.startswith(q)] if q else list(pool)
|
|
556
881
|
|
|
882
|
+
def _grid_cmd_candidates(self, query: str) -> list[str]:
|
|
883
|
+
"""Multi-token candidate list for the :grid arg phase (axis [val …] [NxM])."""
|
|
884
|
+
if " " not in query:
|
|
885
|
+
return [n for n in self.axis_names if n.lower().startswith(query.lower())] if query else list(self.axis_names)
|
|
886
|
+
tokens = query.split(" ")
|
|
887
|
+
axis_name = tokens[0]
|
|
888
|
+
axis_idx = next((i for i, n in enumerate(self.axis_names) if n.lower() == axis_name.lower()), None)
|
|
889
|
+
if axis_idx is None:
|
|
890
|
+
return []
|
|
891
|
+
all_vals = [str(v) for v in self.axis_values[axis_idx]]
|
|
892
|
+
partial = "" if query.endswith(" ") else tokens[-1]
|
|
893
|
+
used = set(t.lower() for t in (tokens[1:-1] if not query.endswith(" ") else tokens[1:]) if t)
|
|
894
|
+
remaining = [v for v in all_vals if v.lower() not in used]
|
|
895
|
+
if partial:
|
|
896
|
+
remaining = [v for v in remaining if v.lower().startswith(partial.lower())]
|
|
897
|
+
return remaining
|
|
898
|
+
|
|
557
899
|
def _cmd_handle_key(self, event: QKeyEvent) -> bool:
|
|
558
900
|
"""Handle input while command mode is active. Returns True if consumed."""
|
|
559
901
|
k = event.key()
|
|
@@ -602,8 +944,24 @@ class ImageView(QGraphicsView):
|
|
|
602
944
|
return True
|
|
603
945
|
|
|
604
946
|
if k == Qt.Key_Tab:
|
|
947
|
+
log.debug("_cmd_handle_key: Tab is_free=%s cmd=%s", is_free, self._cmd)
|
|
605
948
|
if is_free:
|
|
606
949
|
self._complete_path()
|
|
950
|
+
elif self._cmd.get("phase") == "arg" and self._cmd.get("verb") == "grid":
|
|
951
|
+
q = self._cmd["query"]
|
|
952
|
+
candidates = self._cmd_candidates()
|
|
953
|
+
cur = min(self._cmd["cursor"], len(candidates) - 1) if candidates else -1
|
|
954
|
+
log.debug(" grid tab: q=%r candidates=%s cur=%d", q, candidates, cur)
|
|
955
|
+
if cur >= 0:
|
|
956
|
+
if " " not in q:
|
|
957
|
+
self._cmd["query"] = candidates[cur] + " "
|
|
958
|
+
elif q.endswith(" "):
|
|
959
|
+
self._cmd["query"] = q + candidates[cur] + " "
|
|
960
|
+
else:
|
|
961
|
+
prefix = q.rsplit(" ", 1)[0]
|
|
962
|
+
self._cmd["query"] = prefix + " " + candidates[cur] + " "
|
|
963
|
+
self._cmd["cursor"] = 0
|
|
964
|
+
self.state_changed.emit()
|
|
607
965
|
return True
|
|
608
966
|
|
|
609
967
|
if k == Qt.Key_Right:
|
|
@@ -668,11 +1026,20 @@ class ImageView(QGraphicsView):
|
|
|
668
1026
|
self.state_changed.emit()
|
|
669
1027
|
else:
|
|
670
1028
|
verb = self._cmd["verb"]
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
1029
|
+
q = self._cmd["query"]
|
|
1030
|
+
cur = min(self._cmd["cursor"], len(candidates) - 1) if candidates else -1
|
|
1031
|
+
if verb == "grid" and " " in q:
|
|
1032
|
+
# multi-token: preserve already-typed tokens, complete last partial
|
|
1033
|
+
if q.endswith(" "):
|
|
1034
|
+
prefix = q.rstrip()
|
|
1035
|
+
selected = candidates[cur] if cur >= 0 else ""
|
|
1036
|
+
arg = f"{prefix} {selected}".strip() if selected else prefix
|
|
1037
|
+
else:
|
|
1038
|
+
prefix, partial = q.rsplit(" ", 1)
|
|
1039
|
+
selected = candidates[cur] if cur >= 0 else partial
|
|
1040
|
+
arg = f"{prefix} {selected}".strip()
|
|
1041
|
+
else:
|
|
1042
|
+
arg = candidates[cur] if cur >= 0 else q
|
|
676
1043
|
self._cmd = None
|
|
677
1044
|
self._cmd_execute(f"{verb} {arg}" if arg else verb)
|
|
678
1045
|
self.state_changed.emit()
|
|
@@ -820,6 +1187,80 @@ class ImageView(QGraphicsView):
|
|
|
820
1187
|
if self.prev is not None:
|
|
821
1188
|
self.pos, self.prev = self.prev, list(self.pos)
|
|
822
1189
|
self._refresh()
|
|
1190
|
+
elif verb == "grid":
|
|
1191
|
+
raw_args = parts[1:] if len(parts) > 1 else []
|
|
1192
|
+
|
|
1193
|
+
# Optional first token: axis name (case-insensitive)
|
|
1194
|
+
axis_idx = self._h_axis()
|
|
1195
|
+
if raw_args and raw_args[0].lower() in [n.lower() for n in self.axis_names]:
|
|
1196
|
+
axis_idx = next(i for i, n in enumerate(self.axis_names) if n.lower() == raw_args[0].lower())
|
|
1197
|
+
raw_args = raw_args[1:]
|
|
1198
|
+
|
|
1199
|
+
# Optional last token: NxM layout override
|
|
1200
|
+
layout: tuple[int, int] | None = None
|
|
1201
|
+
if raw_args and _re.match(r'^\d+x\d+$', raw_args[-1], _re.IGNORECASE):
|
|
1202
|
+
nr, nc = map(int, raw_args[-1].lower().split('x'))
|
|
1203
|
+
if nr < 1 or nc < 1:
|
|
1204
|
+
self._flash("layout rows and cols must be ≥ 1")
|
|
1205
|
+
return
|
|
1206
|
+
layout = (nr, nc)
|
|
1207
|
+
raw_args = raw_args[:-1]
|
|
1208
|
+
|
|
1209
|
+
# Remaining tokens: value subset (original-case match, case-insensitive)
|
|
1210
|
+
filter_indices: list[int] | None = None
|
|
1211
|
+
if raw_args:
|
|
1212
|
+
all_vals = self.axis_values[axis_idx]
|
|
1213
|
+
filter_indices = []
|
|
1214
|
+
for v in raw_args:
|
|
1215
|
+
match = next((i for i, val in enumerate(all_vals) if val.lower() == v.lower()), None)
|
|
1216
|
+
if match is None:
|
|
1217
|
+
self._flash(f"unknown value: {v!r}")
|
|
1218
|
+
return
|
|
1219
|
+
if match not in filter_indices:
|
|
1220
|
+
filter_indices.append(match)
|
|
1221
|
+
|
|
1222
|
+
self._enter_grid(axis_idx, filter_indices, layout)
|
|
1223
|
+
elif verb == "ungrid":
|
|
1224
|
+
if self._grid_axis is not None:
|
|
1225
|
+
self._exit_grid()
|
|
1226
|
+
elif verb == "grid-layout":
|
|
1227
|
+
if not args:
|
|
1228
|
+
self._flash("usage: grid-layout NxM (e.g. grid-layout 2x3)")
|
|
1229
|
+
return
|
|
1230
|
+
m = _re.match(r'^(\d+)x(\d+)$', args[0], _re.IGNORECASE)
|
|
1231
|
+
if not m:
|
|
1232
|
+
self._flash(f"invalid layout: {args[0]!r} (expected NxM)")
|
|
1233
|
+
return
|
|
1234
|
+
nr, nc = int(m.group(1)), int(m.group(2))
|
|
1235
|
+
if nr < 1 or nc < 1:
|
|
1236
|
+
self._flash("rows and cols must be ≥ 1")
|
|
1237
|
+
return
|
|
1238
|
+
if self._grid_axis is None:
|
|
1239
|
+
self._flash("not in grid mode")
|
|
1240
|
+
return
|
|
1241
|
+
self._enter_grid(self._grid_axis, self._grid_filter, (nr, nc))
|
|
1242
|
+
elif verb == "grid-sharex":
|
|
1243
|
+
if not args:
|
|
1244
|
+
self._grid_sharex = not self._grid_sharex
|
|
1245
|
+
elif args[0] == "on":
|
|
1246
|
+
self._grid_sharex = True
|
|
1247
|
+
elif args[0] == "off":
|
|
1248
|
+
self._grid_sharex = False
|
|
1249
|
+
if self._grid_widget is not None:
|
|
1250
|
+
self._grid_widget.set_sharex(self._grid_sharex)
|
|
1251
|
+
self._flash(f"sharex {'on' if self._grid_sharex else 'off'}")
|
|
1252
|
+
self.state_changed.emit()
|
|
1253
|
+
elif verb == "grid-sharey":
|
|
1254
|
+
if not args:
|
|
1255
|
+
self._grid_sharey = not self._grid_sharey
|
|
1256
|
+
elif args[0] == "on":
|
|
1257
|
+
self._grid_sharey = True
|
|
1258
|
+
elif args[0] == "off":
|
|
1259
|
+
self._grid_sharey = False
|
|
1260
|
+
if self._grid_widget is not None:
|
|
1261
|
+
self._grid_widget.set_sharey(self._grid_sharey)
|
|
1262
|
+
self._flash(f"sharey {'on' if self._grid_sharey else 'off'}")
|
|
1263
|
+
self.state_changed.emit()
|
|
823
1264
|
elif verb == "info":
|
|
824
1265
|
self.toggle_info.emit()
|
|
825
1266
|
elif verb == "remove-axis":
|
|
@@ -1202,6 +1643,10 @@ class ImageView(QGraphicsView):
|
|
|
1202
1643
|
old_locked_h_name = old_names[self._locked_h] if self._locked_h is not None and self._locked_h < len(old_names) else None
|
|
1203
1644
|
old_locked_v_name = old_names[self._locked_v] if self._locked_v is not None and self._locked_v < len(old_names) else None
|
|
1204
1645
|
|
|
1646
|
+
# Exit grid mode before replacing axes (axis indices will shift)
|
|
1647
|
+
if self._grid_axis is not None:
|
|
1648
|
+
self._exit_grid()
|
|
1649
|
+
|
|
1205
1650
|
self.config = new_config
|
|
1206
1651
|
self.pixmaps = new_pixmaps
|
|
1207
1652
|
self.axis_names = new_axis_names
|
|
@@ -1248,6 +1693,8 @@ class ImageView(QGraphicsView):
|
|
|
1248
1693
|
new_pos.append(0)
|
|
1249
1694
|
old_h_name = old_names[self._locked_h] if self._locked_h is not None and self._locked_h < len(old_names) else None
|
|
1250
1695
|
old_v_name = old_names[self._locked_v] if self._locked_v is not None and self._locked_v < len(old_names) else None
|
|
1696
|
+
if self._grid_axis is not None:
|
|
1697
|
+
self._exit_grid()
|
|
1251
1698
|
self.config = new_config
|
|
1252
1699
|
self.pixmaps = new_pixmaps
|
|
1253
1700
|
self.axis_names = new_axis_names
|
|
@@ -1681,6 +2128,8 @@ class ImageView(QGraphicsView):
|
|
|
1681
2128
|
self._remote_mtimes = new_mtimes
|
|
1682
2129
|
|
|
1683
2130
|
# Full viewer state reset (axes may be completely different)
|
|
2131
|
+
if self._grid_axis is not None:
|
|
2132
|
+
self._exit_grid()
|
|
1684
2133
|
self.config = new_config
|
|
1685
2134
|
self.pixmaps = new_pixmaps
|
|
1686
2135
|
self.axis_names = list(new_config.axes.keys())
|
|
@@ -1707,10 +2156,16 @@ class ImageView(QGraphicsView):
|
|
|
1707
2156
|
# ── public ────────────────────────────────────────────────────────────────
|
|
1708
2157
|
|
|
1709
2158
|
def fit_image(self):
|
|
2159
|
+
if self._grid_widget is not None:
|
|
2160
|
+
self._grid_widget.fit_image()
|
|
2161
|
+
return
|
|
1710
2162
|
self.fitInView(self._scene.sceneRect(), Qt.KeepAspectRatio)
|
|
1711
2163
|
self._fit = "image"
|
|
1712
2164
|
|
|
1713
2165
|
def fit_height(self):
|
|
2166
|
+
if self._grid_widget is not None:
|
|
2167
|
+
self._grid_widget.fit_height()
|
|
2168
|
+
return
|
|
1714
2169
|
pm = self._item.pixmap()
|
|
1715
2170
|
if pm.isNull():
|
|
1716
2171
|
return
|
|
@@ -1721,6 +2176,9 @@ class ImageView(QGraphicsView):
|
|
|
1721
2176
|
self._fit = "height"
|
|
1722
2177
|
|
|
1723
2178
|
def fit_width(self):
|
|
2179
|
+
if self._grid_widget is not None:
|
|
2180
|
+
self._grid_widget.fit_width()
|
|
2181
|
+
return
|
|
1724
2182
|
pm = self._item.pixmap()
|
|
1725
2183
|
if pm.isNull():
|
|
1726
2184
|
return
|
|
@@ -1731,16 +2189,35 @@ class ImageView(QGraphicsView):
|
|
|
1731
2189
|
self._fit = "width"
|
|
1732
2190
|
|
|
1733
2191
|
def reset_zoom(self):
|
|
2192
|
+
if self._grid_widget is not None:
|
|
2193
|
+
self._grid_widget.reset_zoom()
|
|
2194
|
+
return
|
|
1734
2195
|
self._fit = None
|
|
1735
2196
|
self.resetTransform()
|
|
1736
2197
|
|
|
1737
2198
|
def set_zoom(self, pct: float):
|
|
2199
|
+
if self._grid_widget is not None:
|
|
2200
|
+
self._grid_widget.set_zoom(pct)
|
|
2201
|
+
return
|
|
1738
2202
|
self._fit = None
|
|
1739
2203
|
self.resetTransform()
|
|
1740
2204
|
self.scale(pct / 100.0, pct / 100.0)
|
|
1741
2205
|
|
|
1742
2206
|
# ── Qt overrides ──────────────────────────────────────────────────────────
|
|
1743
2207
|
|
|
2208
|
+
def eventFilter(self, obj, event):
|
|
2209
|
+
# Tab is consumed by Qt's focus traversal before keyPressEvent sees it.
|
|
2210
|
+
# Intercept it at the application level so it reaches _cmd_handle_key
|
|
2211
|
+
# regardless of which widget currently holds focus (e.g. a _CellView in grid mode).
|
|
2212
|
+
# Only intercept during command mode — normal Tab behaviour is preserved elsewhere.
|
|
2213
|
+
if (event.type() == QEvent.Type.KeyPress
|
|
2214
|
+
and event.key() == Qt.Key_Tab
|
|
2215
|
+
and self._cmd is not None):
|
|
2216
|
+
log.debug("eventFilter: Tab intercepted (cmd=%s)", self._cmd)
|
|
2217
|
+
self._cmd_handle_key(event)
|
|
2218
|
+
return True
|
|
2219
|
+
return super().eventFilter(obj, event)
|
|
2220
|
+
|
|
1744
2221
|
def keyPressEvent(self, event: QKeyEvent):
|
|
1745
2222
|
k = event.key()
|
|
1746
2223
|
mods = event.modifiers()
|
|
@@ -1947,6 +2424,11 @@ class MainWindow(QMainWindow):
|
|
|
1947
2424
|
session_name: str | None = None,
|
|
1948
2425
|
seek_greedy: bool = True,
|
|
1949
2426
|
keybindings: dict[str, str] | None = None,
|
|
2427
|
+
grid: str | None = None,
|
|
2428
|
+
grid_values: list[str] | None = None,
|
|
2429
|
+
grid_layout: tuple[int, int] | None = None,
|
|
2430
|
+
grid_sharex: bool = True,
|
|
2431
|
+
grid_sharey: bool = True,
|
|
1950
2432
|
):
|
|
1951
2433
|
super().__init__()
|
|
1952
2434
|
self._session_name = session_name
|
|
@@ -1962,8 +2444,15 @@ class MainWindow(QMainWindow):
|
|
|
1962
2444
|
axis_v=axis_v,
|
|
1963
2445
|
seek_greedy=seek_greedy,
|
|
1964
2446
|
keybindings=keybindings,
|
|
2447
|
+
grid=grid,
|
|
2448
|
+
grid_values=grid_values,
|
|
2449
|
+
grid_layout=grid_layout,
|
|
2450
|
+
grid_sharex=grid_sharex,
|
|
2451
|
+
grid_sharey=grid_sharey,
|
|
1965
2452
|
)
|
|
1966
|
-
self.
|
|
2453
|
+
self._stack = QStackedWidget()
|
|
2454
|
+
self._stack.addWidget(self.view)
|
|
2455
|
+
self.setCentralWidget(self._stack)
|
|
1967
2456
|
|
|
1968
2457
|
bar = self.statusBar()
|
|
1969
2458
|
bar.setStyleSheet(
|
|
@@ -2008,6 +2497,7 @@ class MainWindow(QMainWindow):
|
|
|
2008
2497
|
self.view.config_changed.connect(
|
|
2009
2498
|
lambda: self.setWindowTitle(_window_title(self.view.config, self._session_name))
|
|
2010
2499
|
)
|
|
2500
|
+
self.view.grid_mode_changed.connect(self._on_grid_mode_changed)
|
|
2011
2501
|
|
|
2012
2502
|
self._bar_auto_shown = False
|
|
2013
2503
|
self._bar_hide_timer = QTimer(self)
|
|
@@ -2061,7 +2551,8 @@ class MainWindow(QMainWindow):
|
|
|
2061
2551
|
self._status_label.setText(v._flash_msg)
|
|
2062
2552
|
return
|
|
2063
2553
|
|
|
2064
|
-
|
|
2554
|
+
grid_str = f" grid:{v.axis_names[v._grid_axis]}" if v._grid_axis is not None else ""
|
|
2555
|
+
mode_str = f"[{v.nav_mode.label}{grid_str}]{' ●' if v._watching else ''}"
|
|
2065
2556
|
|
|
2066
2557
|
if v._cmd is not None:
|
|
2067
2558
|
candidates = v._cmd_candidates()
|
|
@@ -2180,6 +2671,21 @@ class MainWindow(QMainWindow):
|
|
|
2180
2671
|
self.view._initial_fit_done = True
|
|
2181
2672
|
QTimer.singleShot(0, self.view.fit_image)
|
|
2182
2673
|
|
|
2674
|
+
def _on_grid_mode_changed(self, grid_widget):
|
|
2675
|
+
if grid_widget is not None:
|
|
2676
|
+
self._stack.addWidget(grid_widget)
|
|
2677
|
+
self._stack.setCurrentWidget(grid_widget)
|
|
2678
|
+
grid_widget.setFocus()
|
|
2679
|
+
QTimer.singleShot(0, grid_widget.fit_image)
|
|
2680
|
+
else:
|
|
2681
|
+
old = self._stack.widget(1) if self._stack.count() > 1 else None
|
|
2682
|
+
self._stack.setCurrentWidget(self.view)
|
|
2683
|
+
if old is not None:
|
|
2684
|
+
self._stack.removeWidget(old)
|
|
2685
|
+
old.deleteLater()
|
|
2686
|
+
self.view.setFocus()
|
|
2687
|
+
QTimer.singleShot(0, self.view.fit_image)
|
|
2688
|
+
|
|
2183
2689
|
def _toggle_status_bar(self):
|
|
2184
2690
|
sb = self.statusBar()
|
|
2185
2691
|
self._bar_auto_shown = False
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|