pxv 1.0.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.
- pxv-1.0.0/LICENSE +116 -0
- pxv-1.0.0/PKG-INFO +115 -0
- pxv-1.0.0/README.md +86 -0
- pxv-1.0.0/pyproject.toml +58 -0
- pxv-1.0.0/src/pxv/__init__.py +7 -0
- pxv-1.0.0/src/pxv/app.py +276 -0
- pxv-1.0.0/src/pxv/canvas_view.py +229 -0
- pxv-1.0.0/src/pxv/commands.py +342 -0
- pxv-1.0.0/src/pxv/context_menu.py +59 -0
- pxv-1.0.0/src/pxv/dialogs.py +173 -0
- pxv-1.0.0/src/pxv/enhancement_dialog.py +167 -0
- pxv-1.0.0/src/pxv/enhancements.py +163 -0
- pxv-1.0.0/src/pxv/file_list.py +82 -0
- pxv-1.0.0/src/pxv/image_model.py +344 -0
pxv-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
CC0 1.0 Universal
|
|
2
|
+
|
|
3
|
+
Statement of Purpose
|
|
4
|
+
|
|
5
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
6
|
+
exclusive Copyright and Related Rights (defined below) upon the creator and
|
|
7
|
+
subsequent owner(s) (each and all, an "owner") of an original work of
|
|
8
|
+
authorship and/or a database (each, a "Work").
|
|
9
|
+
|
|
10
|
+
Certain owners wish to permanently relinquish those rights to a Work for the
|
|
11
|
+
purpose of contributing to a commons of creative, cultural and scientific
|
|
12
|
+
works ("Commons") that the public can reliably and without fear of later
|
|
13
|
+
claims of infringement build upon, modify, incorporate in other works, reuse
|
|
14
|
+
and redistribute as freely as possible in any form whatsoever and for any
|
|
15
|
+
purposes, including without limitation commercial purposes. These owners may
|
|
16
|
+
contribute to the Commons to promote the ideal of a free culture and the
|
|
17
|
+
further production of creative, cultural and scientific works, or to gain
|
|
18
|
+
reputation or greater distribution for their Work in part through the use and
|
|
19
|
+
efforts of others.
|
|
20
|
+
|
|
21
|
+
For these and/or other purposes and motivations, and without any expectation
|
|
22
|
+
of additional consideration or compensation, the person associating CC0 with a
|
|
23
|
+
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
|
24
|
+
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
|
25
|
+
and publicly distribute the Work under its terms, with knowledge of his or her
|
|
26
|
+
Copyright and Related Rights in the Work and the meaning and intended legal
|
|
27
|
+
effect of CC0 on those rights.
|
|
28
|
+
|
|
29
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
30
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
31
|
+
Related Rights"). Copyright and Related Rights include, but are not limited
|
|
32
|
+
to, the following:
|
|
33
|
+
|
|
34
|
+
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
|
35
|
+
and translate a Work;
|
|
36
|
+
|
|
37
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
38
|
+
|
|
39
|
+
iii. publicity and privacy rights pertaining to a person's image or likeness
|
|
40
|
+
depicted in a Work;
|
|
41
|
+
|
|
42
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
43
|
+
subject to the limitations in paragraph 4(a), below;
|
|
44
|
+
|
|
45
|
+
v. rights protecting the extraction, dissemination, use and reuse of data in
|
|
46
|
+
a Work;
|
|
47
|
+
|
|
48
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
49
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
50
|
+
protection of databases, and under any national implementation thereof,
|
|
51
|
+
including any amended or successor version of such directive); and
|
|
52
|
+
|
|
53
|
+
vii. other similar, equivalent or corresponding rights throughout the world
|
|
54
|
+
based on applicable law or treaty, and any national implementations thereof.
|
|
55
|
+
|
|
56
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
|
57
|
+
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
|
58
|
+
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
|
59
|
+
and Related Rights and associated claims and causes of action, whether now
|
|
60
|
+
known or unknown (including existing as well as future claims and causes of
|
|
61
|
+
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
|
62
|
+
duration provided by applicable law or treaty (including future time
|
|
63
|
+
extensions), (iii) in any current or future medium and for any number of
|
|
64
|
+
copies, and (iv) for any purpose whatsoever, including without limitation
|
|
65
|
+
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
|
66
|
+
the Waiver for the benefit of each member of the public at large and to the
|
|
67
|
+
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
|
68
|
+
shall not be subject to revocation, rescission, cancellation, termination, or
|
|
69
|
+
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
|
70
|
+
by the public as contemplated by Affirmer's express Statement of Purpose.
|
|
71
|
+
|
|
72
|
+
3. Public License Fallback. Should any part of the Waiver for any reason be
|
|
73
|
+
judged legally invalid or ineffective under applicable law, then the Waiver
|
|
74
|
+
shall be preserved to the maximum extent permitted taking into account
|
|
75
|
+
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
|
76
|
+
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
|
77
|
+
non transferable, non sublicensable, non exclusive, irrevocable and
|
|
78
|
+
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
|
79
|
+
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
|
80
|
+
provided by applicable law or treaty (including future time extensions), (iii)
|
|
81
|
+
in any current or future medium and for any number of copies, and (iv) for any
|
|
82
|
+
purpose whatsoever, including without limitation commercial, advertising or
|
|
83
|
+
promotional purposes (the "License"). The License shall be deemed effective as
|
|
84
|
+
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
|
85
|
+
License for any reason be judged legally invalid or ineffective under
|
|
86
|
+
applicable law, such partial invalidity or ineffectiveness shall not invalidate
|
|
87
|
+
the remainder of the License, and in such case Affirmer hereby affirms that he
|
|
88
|
+
or she will not (i) exercise any of his or her remaining Copyright and Related
|
|
89
|
+
Rights in the Work or (ii) assert any associated claims and causes of action
|
|
90
|
+
with respect to the Work, in either case contrary to Affirmer's express
|
|
91
|
+
Statement of Purpose.
|
|
92
|
+
|
|
93
|
+
4. Limitations and Disclaimers.
|
|
94
|
+
|
|
95
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
96
|
+
surrendered, licensed or otherwise affected by this document.
|
|
97
|
+
|
|
98
|
+
b. Affirmer offers the Work as-is and makes no representations or warranties
|
|
99
|
+
of any kind concerning the Work, express, implied, statutory or otherwise,
|
|
100
|
+
including without limitation warranties of title, merchantability, fitness
|
|
101
|
+
for a particular purpose, non infringement, or the absence of latent or
|
|
102
|
+
other defects, accuracy, or the present or absence of errors, whether or not
|
|
103
|
+
discoverable, all to the greatest extent permissible under applicable law.
|
|
104
|
+
|
|
105
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
106
|
+
that may apply to the Work or any use thereof, including without limitation
|
|
107
|
+
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
|
108
|
+
disclaims responsibility for obtaining any necessary consents, permissions or
|
|
109
|
+
other rights required for any use of the Work.
|
|
110
|
+
|
|
111
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
112
|
+
party to this document and has no duty or obligation with respect to this CC0
|
|
113
|
+
or use of the Work.
|
|
114
|
+
|
|
115
|
+
For more information, please see
|
|
116
|
+
<https://creativecommons.org/publicdomain/zero/1.0/>
|
pxv-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pxv
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A Python clone of the classic Unix xv image viewer
|
|
5
|
+
Keywords: image,viewer,xv,pillow,tkinter,graphics
|
|
6
|
+
Author: Sean Reifschneider
|
|
7
|
+
Author-email: Sean Reifschneider <sean@realgo.com>
|
|
8
|
+
License-Expression: CC0-1.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: X11 Applications
|
|
12
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Operating System :: MacOS
|
|
15
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Multimedia :: Graphics :: Viewers
|
|
23
|
+
Requires-Dist: pillow>=12.0
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Project-URL: Homepage, https://github.com/linsomniac/pxv
|
|
26
|
+
Project-URL: Repository, https://github.com/linsomniac/pxv
|
|
27
|
+
Project-URL: Issues, https://github.com/linsomniac/pxv/issues
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# pxv
|
|
31
|
+
|
|
32
|
+
A simple image viewer and manipulator built with Python/Pillow/Tkinter that takes inspiration from
|
|
33
|
+
the classic Unix [xv](http://www.trilon.com/xv/) image viewer.
|
|
34
|
+
|
|
35
|
+
## Quickstart
|
|
36
|
+
|
|
37
|
+
Run directly from the GitHub repo (requires [uv](https://docs.astral.sh/uv/)):
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
uvx --from git+https://github.com/linsomniac/pxv pxv photo.jpg
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or install locally:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
uv pip install git+https://github.com/linsomniac/pxv
|
|
47
|
+
pxv photo.jpg
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Pass files, directories, or nothing (opens a file dialog):
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
pxv image.png # single file
|
|
54
|
+
pxv *.jpg # multiple files
|
|
55
|
+
pxv ~/Photos/ # all images in a directory
|
|
56
|
+
pxv # open file dialog
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Keyboard Shortcuts
|
|
60
|
+
|
|
61
|
+
| Key | Action |
|
|
62
|
+
|-----|--------|
|
|
63
|
+
| `>` | Zoom in |
|
|
64
|
+
| `<` | Zoom out |
|
|
65
|
+
| `n` | Zoom to 1:1 (normal) |
|
|
66
|
+
| `Space` / `Right` | Next image |
|
|
67
|
+
| `Backspace` / `Left` | Previous image |
|
|
68
|
+
| `c` | Crop to selection |
|
|
69
|
+
| `e` | Enhancement dialog |
|
|
70
|
+
| `Ctrl+s` | Save as |
|
|
71
|
+
| `Escape` | Clear selection |
|
|
72
|
+
| `q` | Quit |
|
|
73
|
+
|
|
74
|
+
Right-click for additional options: rotate, flip, resize, grab (screenshot), print, and more.
|
|
75
|
+
|
|
76
|
+
## Enhancements
|
|
77
|
+
|
|
78
|
+
The enhancement dialog (`e`) provides real-time adjustment of:
|
|
79
|
+
|
|
80
|
+
- Brightness, contrast, gamma
|
|
81
|
+
- Sharpen, blur
|
|
82
|
+
- Saturation, hue rotation
|
|
83
|
+
- Per-channel RGB color balance
|
|
84
|
+
|
|
85
|
+
## Features
|
|
86
|
+
|
|
87
|
+
- XV-style window sizing: window grows/shrinks to fit the displayed image, capped at the current monitor's bounds
|
|
88
|
+
- Multi-monitor aware: detects per-monitor geometry via xrandr so windows don't span displays
|
|
89
|
+
- EXIF-aware orientation
|
|
90
|
+
- Rubber-band selection for cropping
|
|
91
|
+
- Wrap-around file navigation
|
|
92
|
+
- Supports PNG, JPEG, BMP, TIFF, GIF, WebP, PPM, PGM, PBM, ICO
|
|
93
|
+
|
|
94
|
+
## Requirements
|
|
95
|
+
|
|
96
|
+
- Python 3.10+
|
|
97
|
+
- Tkinter (usually included with Python; on Debian/Ubuntu: `sudo apt install python3-tk`)
|
|
98
|
+
- Pillow 12+
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
git clone https://github.com/linsomniac/pxv
|
|
104
|
+
cd pxv
|
|
105
|
+
uv sync
|
|
106
|
+
uv run pxv test_images/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Lint and type-check:
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
uv run ruff check src/
|
|
113
|
+
uv run ruff format --check src/
|
|
114
|
+
uv run mypy src/pxv/
|
|
115
|
+
```
|
pxv-1.0.0/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# pxv
|
|
2
|
+
|
|
3
|
+
A simple image viewer and manipulator built with Python/Pillow/Tkinter that takes inspiration from
|
|
4
|
+
the classic Unix [xv](http://www.trilon.com/xv/) image viewer.
|
|
5
|
+
|
|
6
|
+
## Quickstart
|
|
7
|
+
|
|
8
|
+
Run directly from the GitHub repo (requires [uv](https://docs.astral.sh/uv/)):
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
uvx --from git+https://github.com/linsomniac/pxv pxv photo.jpg
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Or install locally:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
uv pip install git+https://github.com/linsomniac/pxv
|
|
18
|
+
pxv photo.jpg
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Pass files, directories, or nothing (opens a file dialog):
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
pxv image.png # single file
|
|
25
|
+
pxv *.jpg # multiple files
|
|
26
|
+
pxv ~/Photos/ # all images in a directory
|
|
27
|
+
pxv # open file dialog
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Keyboard Shortcuts
|
|
31
|
+
|
|
32
|
+
| Key | Action |
|
|
33
|
+
|-----|--------|
|
|
34
|
+
| `>` | Zoom in |
|
|
35
|
+
| `<` | Zoom out |
|
|
36
|
+
| `n` | Zoom to 1:1 (normal) |
|
|
37
|
+
| `Space` / `Right` | Next image |
|
|
38
|
+
| `Backspace` / `Left` | Previous image |
|
|
39
|
+
| `c` | Crop to selection |
|
|
40
|
+
| `e` | Enhancement dialog |
|
|
41
|
+
| `Ctrl+s` | Save as |
|
|
42
|
+
| `Escape` | Clear selection |
|
|
43
|
+
| `q` | Quit |
|
|
44
|
+
|
|
45
|
+
Right-click for additional options: rotate, flip, resize, grab (screenshot), print, and more.
|
|
46
|
+
|
|
47
|
+
## Enhancements
|
|
48
|
+
|
|
49
|
+
The enhancement dialog (`e`) provides real-time adjustment of:
|
|
50
|
+
|
|
51
|
+
- Brightness, contrast, gamma
|
|
52
|
+
- Sharpen, blur
|
|
53
|
+
- Saturation, hue rotation
|
|
54
|
+
- Per-channel RGB color balance
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
- XV-style window sizing: window grows/shrinks to fit the displayed image, capped at the current monitor's bounds
|
|
59
|
+
- Multi-monitor aware: detects per-monitor geometry via xrandr so windows don't span displays
|
|
60
|
+
- EXIF-aware orientation
|
|
61
|
+
- Rubber-band selection for cropping
|
|
62
|
+
- Wrap-around file navigation
|
|
63
|
+
- Supports PNG, JPEG, BMP, TIFF, GIF, WebP, PPM, PGM, PBM, ICO
|
|
64
|
+
|
|
65
|
+
## Requirements
|
|
66
|
+
|
|
67
|
+
- Python 3.10+
|
|
68
|
+
- Tkinter (usually included with Python; on Debian/Ubuntu: `sudo apt install python3-tk`)
|
|
69
|
+
- Pillow 12+
|
|
70
|
+
|
|
71
|
+
## Development
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
git clone https://github.com/linsomniac/pxv
|
|
75
|
+
cd pxv
|
|
76
|
+
uv sync
|
|
77
|
+
uv run pxv test_images/
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Lint and type-check:
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
uv run ruff check src/
|
|
84
|
+
uv run ruff format --check src/
|
|
85
|
+
uv run mypy src/pxv/
|
|
86
|
+
```
|
pxv-1.0.0/pyproject.toml
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "pxv"
|
|
3
|
+
version = "1.0.0" # NOTE: Also update in src/pxv/__init__.py
|
|
4
|
+
description = "A Python clone of the classic Unix xv image viewer"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "CC0-1.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Sean Reifschneider", email = "sean@realgo.com" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"pillow>=12.0",
|
|
14
|
+
]
|
|
15
|
+
keywords = ["image", "viewer", "xv", "pillow", "tkinter", "graphics"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Environment :: X11 Applications",
|
|
19
|
+
"Intended Audience :: End Users/Desktop",
|
|
20
|
+
"Operating System :: POSIX :: Linux",
|
|
21
|
+
"Operating System :: MacOS",
|
|
22
|
+
"Operating System :: Microsoft :: Windows",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Topic :: Multimedia :: Graphics :: Viewers",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/linsomniac/pxv"
|
|
34
|
+
Repository = "https://github.com/linsomniac/pxv"
|
|
35
|
+
Issues = "https://github.com/linsomniac/pxv/issues"
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
pxv = "pxv:main"
|
|
39
|
+
|
|
40
|
+
[build-system]
|
|
41
|
+
requires = ["uv_build>=0.11.1,<0.12.0"]
|
|
42
|
+
build-backend = "uv_build"
|
|
43
|
+
|
|
44
|
+
[tool.ruff]
|
|
45
|
+
line-length = 99
|
|
46
|
+
|
|
47
|
+
[tool.mypy]
|
|
48
|
+
strict = true
|
|
49
|
+
|
|
50
|
+
[[tool.mypy.overrides]]
|
|
51
|
+
module = "PIL.*"
|
|
52
|
+
ignore_missing_imports = true
|
|
53
|
+
|
|
54
|
+
[dependency-groups]
|
|
55
|
+
dev = [
|
|
56
|
+
"mypy>=1.20.0",
|
|
57
|
+
"ruff>=0.15.9",
|
|
58
|
+
]
|
pxv-1.0.0/src/pxv/app.py
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"""Main application: creates the Tk root, wires all components together.
|
|
2
|
+
|
|
3
|
+
AIDEV-NOTE: All keyboard bindings are on the root window so they work regardless
|
|
4
|
+
of which widget has focus. The enhancement dialog binds its own widget-level events.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import re
|
|
11
|
+
import subprocess
|
|
12
|
+
import tkinter as tk
|
|
13
|
+
from typing import TYPE_CHECKING
|
|
14
|
+
|
|
15
|
+
from pxv import commands
|
|
16
|
+
from pxv.canvas_view import CanvasView
|
|
17
|
+
from pxv.context_menu import ContextMenu
|
|
18
|
+
from pxv.enhancements import EnhancementParams
|
|
19
|
+
from pxv.file_list import FileList, expand_paths
|
|
20
|
+
from pxv.image_model import ImageModel
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from pxv.enhancement_dialog import EnhancementDialog
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# AIDEV-NOTE: Tkinter's winfo_screenwidth/height returns the total virtual desktop
|
|
27
|
+
# across all monitors. These helpers use xrandr to detect individual monitor
|
|
28
|
+
# geometry so windows don't span multiple displays.
|
|
29
|
+
|
|
30
|
+
_cached_monitors: list[tuple[int, int, int, int]] | None = None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _parse_monitors() -> list[tuple[int, int, int, int]]:
|
|
34
|
+
"""Parse xrandr output to get connected monitor geometries.
|
|
35
|
+
|
|
36
|
+
Returns list of (width, height, x_offset, y_offset) tuples.
|
|
37
|
+
Result is cached for the process lifetime.
|
|
38
|
+
"""
|
|
39
|
+
global _cached_monitors
|
|
40
|
+
if _cached_monitors is not None:
|
|
41
|
+
return _cached_monitors
|
|
42
|
+
try:
|
|
43
|
+
output = subprocess.check_output(
|
|
44
|
+
["xrandr"], text=True, timeout=5, stderr=subprocess.DEVNULL
|
|
45
|
+
)
|
|
46
|
+
pattern = r"\bconnected\s+(?:primary\s+)?(\d+)x(\d+)\+(\d+)\+(\d+)"
|
|
47
|
+
_cached_monitors = [
|
|
48
|
+
(int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4)))
|
|
49
|
+
for m in re.finditer(pattern, output)
|
|
50
|
+
]
|
|
51
|
+
except Exception:
|
|
52
|
+
_cached_monitors = []
|
|
53
|
+
return _cached_monitors
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _get_monitor_size(root: tk.Tk) -> tuple[int, int]:
|
|
57
|
+
"""Get pixel dimensions of the monitor containing the window's center.
|
|
58
|
+
|
|
59
|
+
Falls back to winfo_screenwidth/height if xrandr is unavailable.
|
|
60
|
+
"""
|
|
61
|
+
monitors = _parse_monitors()
|
|
62
|
+
if monitors:
|
|
63
|
+
root.update_idletasks()
|
|
64
|
+
cx = root.winfo_x() + root.winfo_width() // 2
|
|
65
|
+
cy = root.winfo_y() + root.winfo_height() // 2
|
|
66
|
+
for mw, mh, mx, my in monitors:
|
|
67
|
+
if mx <= cx < mx + mw and my <= cy < my + mh:
|
|
68
|
+
return (mw, mh)
|
|
69
|
+
# Window center not in any monitor — use first
|
|
70
|
+
return (monitors[0][0], monitors[0][1])
|
|
71
|
+
return (root.winfo_screenwidth(), root.winfo_screenheight())
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class PxvApp:
|
|
75
|
+
"""Top-level application coordinator."""
|
|
76
|
+
|
|
77
|
+
def __init__(self, root: tk.Tk, file_list: FileList) -> None:
|
|
78
|
+
self.root = root
|
|
79
|
+
self.file_list = file_list
|
|
80
|
+
self.image_model = ImageModel()
|
|
81
|
+
self.enhancement_params = EnhancementParams()
|
|
82
|
+
|
|
83
|
+
# Will be set if the enhancement dialog is open
|
|
84
|
+
self.enhancement_dialog: EnhancementDialog | None = None
|
|
85
|
+
# AIDEV-NOTE: Toggles transparent-area compositing between white and black.
|
|
86
|
+
# Only affects display; saving always uses the true alpha channel.
|
|
87
|
+
self.dark_background: bool = False
|
|
88
|
+
|
|
89
|
+
# Create canvas view (passes right-click handler)
|
|
90
|
+
self.canvas_view = CanvasView(root, on_right_click=self._on_right_click)
|
|
91
|
+
|
|
92
|
+
# Context menu
|
|
93
|
+
self.context_menu = ContextMenu(root, self)
|
|
94
|
+
|
|
95
|
+
# Debounce for configure events
|
|
96
|
+
self._configure_after_id: str | None = None
|
|
97
|
+
# AIDEV-NOTE: Guard flag to prevent <Configure> feedback loop when we
|
|
98
|
+
# programmatically resize the window to match the image.
|
|
99
|
+
self._resizing_programmatically = False
|
|
100
|
+
self._deco_size: tuple[int, int] | None = None
|
|
101
|
+
|
|
102
|
+
self._bind_keys()
|
|
103
|
+
self._bind_configure()
|
|
104
|
+
|
|
105
|
+
def _get_decoration_size(self) -> tuple[int, int]:
|
|
106
|
+
"""Measure window decoration overhead (borders + title bar).
|
|
107
|
+
|
|
108
|
+
Caches the result after first successful measurement.
|
|
109
|
+
Returns conservative defaults if the window isn't mapped yet.
|
|
110
|
+
"""
|
|
111
|
+
if self._deco_size is not None:
|
|
112
|
+
return self._deco_size
|
|
113
|
+
self.root.update_idletasks()
|
|
114
|
+
border = self.root.winfo_rootx() - self.root.winfo_x()
|
|
115
|
+
titlebar = self.root.winfo_rooty() - self.root.winfo_y()
|
|
116
|
+
if border > 0 or titlebar > 0:
|
|
117
|
+
self._deco_size = (border * 2, titlebar + border)
|
|
118
|
+
return self._deco_size
|
|
119
|
+
# Conservative defaults for typical Linux WMs
|
|
120
|
+
return (8, 48)
|
|
121
|
+
|
|
122
|
+
def _get_max_image_size(self) -> tuple[int, int]:
|
|
123
|
+
"""Maximum image display size that fits on the current monitor."""
|
|
124
|
+
mon_w, mon_h = _get_monitor_size(self.root)
|
|
125
|
+
deco_w, deco_h = self._get_decoration_size()
|
|
126
|
+
return (mon_w - deco_w, mon_h - deco_h)
|
|
127
|
+
|
|
128
|
+
def _bind_keys(self) -> None:
|
|
129
|
+
self.root.bind("<Key-q>", lambda _: commands.cmd_quit(self))
|
|
130
|
+
self.root.bind("<Key-c>", lambda _: commands.cmd_crop(self))
|
|
131
|
+
self.root.bind("<Key-A>", lambda _: commands.cmd_autocrop(self))
|
|
132
|
+
self.root.bind("<Key-u>", lambda _: commands.cmd_uncrop(self))
|
|
133
|
+
self.root.bind("<Key-n>", lambda _: commands.cmd_zoom_normal(self))
|
|
134
|
+
self.root.bind("<Key-e>", lambda _: commands.cmd_enhancement_dialog(self))
|
|
135
|
+
self.root.bind("<Key-comma>", lambda _: commands.cmd_zoom_reduce(self))
|
|
136
|
+
self.root.bind("<Key-period>", lambda _: commands.cmd_zoom_increase(self))
|
|
137
|
+
self.root.bind("<greater>", lambda _: commands.cmd_zoom_double(self))
|
|
138
|
+
self.root.bind("<less>", lambda _: commands.cmd_zoom_halve(self))
|
|
139
|
+
self.root.bind("<Key-M>", lambda _: commands.cmd_zoom_max(self))
|
|
140
|
+
self.root.bind("<Key-D>", lambda _: commands.cmd_toggle_background(self))
|
|
141
|
+
self.root.bind("<Key-t>", lambda _: commands.cmd_rotate(self, 270))
|
|
142
|
+
self.root.bind("<Key-T>", lambda _: commands.cmd_rotate(self, 90))
|
|
143
|
+
self.root.bind("<Control-s>", lambda _: commands.cmd_save_as(self))
|
|
144
|
+
self.root.bind("<space>", lambda _: commands.cmd_next_image(self))
|
|
145
|
+
self.root.bind("<Right>", lambda _: commands.cmd_next_image(self))
|
|
146
|
+
self.root.bind("<BackSpace>", lambda _: commands.cmd_prev_image(self))
|
|
147
|
+
self.root.bind("<Left>", lambda _: commands.cmd_prev_image(self))
|
|
148
|
+
self.root.bind("<Escape>", lambda _: self.canvas_view.clear_selection())
|
|
149
|
+
self.root.bind("<question>", lambda _: commands.cmd_help(self))
|
|
150
|
+
|
|
151
|
+
def _bind_configure(self) -> None:
|
|
152
|
+
"""Debounced handler for window resize events."""
|
|
153
|
+
self.canvas_view.canvas.bind("<Configure>", self._on_configure)
|
|
154
|
+
|
|
155
|
+
def _on_configure(self, _event: tk.Event) -> None:
|
|
156
|
+
if self._resizing_programmatically:
|
|
157
|
+
return
|
|
158
|
+
if self._configure_after_id is not None:
|
|
159
|
+
self.root.after_cancel(self._configure_after_id)
|
|
160
|
+
self._configure_after_id = self.root.after(50, self._handle_resize)
|
|
161
|
+
|
|
162
|
+
def _handle_resize(self) -> None:
|
|
163
|
+
self._configure_after_id = None
|
|
164
|
+
if self.image_model.working_image is not None:
|
|
165
|
+
self._update_display()
|
|
166
|
+
|
|
167
|
+
def _on_right_click(self, event: tk.Event) -> None:
|
|
168
|
+
self.context_menu.show(event)
|
|
169
|
+
|
|
170
|
+
def load_current(self) -> None:
|
|
171
|
+
"""Load the current file from the file list."""
|
|
172
|
+
path = self.file_list.current()
|
|
173
|
+
if path is None:
|
|
174
|
+
return
|
|
175
|
+
try:
|
|
176
|
+
self.image_model.load(path)
|
|
177
|
+
except Exception as e:
|
|
178
|
+
from tkinter import messagebox
|
|
179
|
+
|
|
180
|
+
messagebox.showerror("Open Error", f"Could not open {path.name}:\n{e}")
|
|
181
|
+
return
|
|
182
|
+
|
|
183
|
+
self.enhancement_params.reset()
|
|
184
|
+
if self.enhancement_dialog is not None:
|
|
185
|
+
self.enhancement_dialog.sync_sliders_from_params()
|
|
186
|
+
self.canvas_view.clear_selection()
|
|
187
|
+
|
|
188
|
+
# Fit to current monitor on load
|
|
189
|
+
max_w, max_h = self._get_max_image_size()
|
|
190
|
+
img_size = self.image_model.get_working_size()
|
|
191
|
+
self.canvas_view.zoom_fit(img_size, (max_w, max_h))
|
|
192
|
+
|
|
193
|
+
self.refresh_display()
|
|
194
|
+
|
|
195
|
+
def _bg_color(self) -> tuple[int, int, int]:
|
|
196
|
+
return (0, 0, 0) if self.dark_background else (255, 255, 255)
|
|
197
|
+
|
|
198
|
+
def refresh_display(self) -> None:
|
|
199
|
+
"""Re-render the image with current zoom and enhancement params."""
|
|
200
|
+
display_img = self.image_model.get_display_image(
|
|
201
|
+
zoom=self.canvas_view.zoom,
|
|
202
|
+
params=self.enhancement_params,
|
|
203
|
+
bg_color=self._bg_color(),
|
|
204
|
+
)
|
|
205
|
+
if display_img is not None:
|
|
206
|
+
# AIDEV-NOTE: Resize window BEFORE display() so the canvas has correct
|
|
207
|
+
# dimensions when centering the image.
|
|
208
|
+
self._resize_window_to_image(display_img.width, display_img.height)
|
|
209
|
+
self.canvas_view.display(display_img)
|
|
210
|
+
self._update_title()
|
|
211
|
+
|
|
212
|
+
def _resize_window_to_image(self, img_w: int, img_h: int) -> None:
|
|
213
|
+
"""Resize the window to fit the displayed image, capped at monitor bounds."""
|
|
214
|
+
max_w, max_h = self._get_max_image_size()
|
|
215
|
+
win_w = min(img_w, max_w)
|
|
216
|
+
win_h = min(img_h, max_h)
|
|
217
|
+
self._resizing_programmatically = True
|
|
218
|
+
self.root.geometry(f"{win_w}x{win_h}")
|
|
219
|
+
self.root.update_idletasks()
|
|
220
|
+
self._resizing_programmatically = False
|
|
221
|
+
|
|
222
|
+
def _update_display(self) -> None:
|
|
223
|
+
"""Refresh display without changing zoom or window size (for resize events)."""
|
|
224
|
+
display_img = self.image_model.get_display_image(
|
|
225
|
+
zoom=self.canvas_view.zoom,
|
|
226
|
+
params=self.enhancement_params,
|
|
227
|
+
bg_color=self._bg_color(),
|
|
228
|
+
)
|
|
229
|
+
if display_img is not None:
|
|
230
|
+
self.canvas_view.display(display_img)
|
|
231
|
+
self._update_title()
|
|
232
|
+
|
|
233
|
+
def _update_title(self) -> None:
|
|
234
|
+
path = self.image_model.current_path
|
|
235
|
+
if path is not None:
|
|
236
|
+
name = path.name
|
|
237
|
+
pos = self.file_list.position_str()
|
|
238
|
+
w, h = self.image_model.get_working_size()
|
|
239
|
+
zoom_pct = int(self.canvas_view.zoom * 100)
|
|
240
|
+
self.root.title(f"pxv: {name} [{pos}] {w}x{h} ({zoom_pct}%)")
|
|
241
|
+
else:
|
|
242
|
+
self.root.title("pxv")
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def main() -> None:
|
|
246
|
+
"""Entry point: parse args, create app, run main loop."""
|
|
247
|
+
parser = argparse.ArgumentParser(description="pxv - A Python xv image viewer")
|
|
248
|
+
parser.add_argument("paths", nargs="*", help="Image files or directories to open")
|
|
249
|
+
args = parser.parse_args()
|
|
250
|
+
|
|
251
|
+
root = tk.Tk(className="pxv")
|
|
252
|
+
root.title("pxv")
|
|
253
|
+
root.configure(bg="black")
|
|
254
|
+
|
|
255
|
+
# Set initial window size — 75% of current monitor, capped at reasonable max
|
|
256
|
+
mon_w, mon_h = _get_monitor_size(root)
|
|
257
|
+
win_w = min(int(mon_w * 0.75), 1200)
|
|
258
|
+
win_h = min(int(mon_h * 0.75), 900)
|
|
259
|
+
root.geometry(f"{win_w}x{win_h}")
|
|
260
|
+
|
|
261
|
+
paths = expand_paths(args.paths)
|
|
262
|
+
file_list = FileList(paths)
|
|
263
|
+
app = PxvApp(root, file_list)
|
|
264
|
+
|
|
265
|
+
if file_list.count() > 0:
|
|
266
|
+
# Delay loading until after mainloop starts so canvas has real dimensions
|
|
267
|
+
root.after(50, app.load_current)
|
|
268
|
+
else:
|
|
269
|
+
# No files: show open dialog after startup
|
|
270
|
+
root.after(100, lambda: commands.cmd_open(app))
|
|
271
|
+
|
|
272
|
+
root.mainloop()
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
if __name__ == "__main__":
|
|
276
|
+
main()
|