Metadata-Version: 2.4
Name: spriteviewer
Version: 0.3
Summary: PySide6 tile viewer for SVG icon sprites
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://github.com/svgforge/spriteviewer
Project-URL: Repository, https://github.com/svgforge/spriteviewer
Project-URL: Issues, https://github.com/svgforge/spriteviewer/issues
Keywords: svg,sprite,icons,viewer,pyside6,qt,desktop
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: X11 Applications :: Qt
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Multimedia :: Graphics :: Viewers
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PySide6>=6.12.0
Requires-Dist: defusedxml>=0.7.1
Requires-Dist: resvg-py>=0.5.0
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Dynamic: license-file

# SVG Sprite Viewer

[![CI][ci-badge]][ci-url] [![Release][release-badge]][release-url] [![License][license-badge]][license-url]
[![Python][python-badge]][python-url] [![PySide6][pyside-badge]][pyside-url] [![Linux][linux-badge]](#requirements) [![macOS][macos-badge]](#requirements) [![Windows][windows-badge]](#requirements)

A small, clean **[PySide6](https://doc.qt.io/qtforpython-6/)** desktop app that opens an
SVG sprite (e.g. `icons.svg`), extracts icons from `symbol`, `defs`, `stack`, and `view`
sprites, and presents them in a responsive tile grid.

![Sprite Viewer screenshot](docs/screenshot.png)

## Features

- Parses an SVG sprite and shows all icons as a tile grid; each icon's id is
  shown as a tooltip on hover
- Fast QtSvg (SVG Tiny) rendering by default, with optional full **SVG 1.1**
  via **resvg** (gradients, filters, masks, …) — switchable live from the
  toolbar and via the `--renderer` flag, so sprites like the Tango icon set
  render exactly (but slower).
- Toolbar dropdown to switch the icon size: 16, 32, 64, 128 or 256 px
- Icons are rendered asynchronously in the background, so the UI stays responsive
- Right-click → **Copy id** or **Copy SVG** puts the fragment id(s) or the
  standalone SVG code on the clipboard (works for single and multi-selection).
  You can select multiple icons with Ctrl + click.
- **Open Sprite** button in the status bar loads a different SVG sprite at runtime
- Status bar shows the selection / icon count
- Cross-platform, installable via a one-line installer or `pip`

## Requirements

- Python 3.10+
- PySide6 6.12+
- resvg-py 0.5+ (optional but recommended; falls back to QtSvg when missing)

## Quick start (from source)

```sh
python3 -m venv --system-site-packages .venv   # project-local virtualenv
.venv/bin/python -m pip install -r requirements.txt   # PySide6 + resvg-py
./main.py                                      # opens the default sprite at 64 px
./main.py --size 32                            # same sprite, sized 32 px
./main.py icons.svg --size 64                  # a different sprite file
./main.py --renderer qtsvg                     # fast QtSvg backend (default)
./main.py --renderer resvg                     # full SVG 1.1 (slower, higher fidelity)
```

`./main.py` automatically re-executes itself with `.venv/bin/python` when that
virtualenv exists, so icons always render with the full **resvg** feature set
(gradients, filters, …) instead of the reduced QtSvg fallback. Starting via
`.venv/bin/python main.py` (or an activated venv) works the same way.

### Command-line options

| Option | Values | Description |
|---|---|---|
| `-h`, `--help` | — | show help and exit |
| `-V`, `--version` | — | show the version and exit |
| `-S`, `--size` | `16`, `32`, `64`, `128`, `256` (default `64`) | icon edge length in pixels |
| `-R`, `--renderer` | `qtsvg` (default), `resvg`, `auto` | SVG rendering backend |

All forms work per GNU getopt: `-S 32`, `-S32`, `--size 32`, `--size=32`
(and the same for `--renderer`). The sprite path is purely positional and may
appear before, between or after the options (`--` ends option parsing).

- `qtsvg` (**default**) — Qt's built-in **SVG Tiny** renderer. Much **faster**,
  because it draws straight into the icon image through Qt's native, accelerated
  raster path (no PNG round-trip), but supports only a subset — gradients,
  filters, masks and other advanced features are dropped.
- `resvg` — full **SVG 1.1** via the [resvg](https://github.com/linebender/resvg)
  library: gradients, filters, masks, markers, … render exactly (e.g. the Tango
  icon set). It rasterises the complete spec and hands the result back as a PNG
  that still has to be decoded, so it is **noticeably slower** — especially with
  large sprites.
- `auto` — use **resvg** when installed, otherwise QtSvg.

**Rule of thumb:** for normal, simple icons (flat fills, paths, plain shapes)
keep the default `qtsvg`; reach for `resvg` only when the sprite relies on
gradients, filters, masks or other advanced SVG features.

**At runtime** the toolbar shows a **“Full SVG (resvg)”** checkbox (only when
`resvg-py` is installed). It switches the backend live and re-renders the
current sprite — unchecked means `qtsvg`. The `--renderer` flag sets the initial
state of that checkbox.

The optional `--size` flag accepts 16, 32, 64, 128 or 256 (default 64).

## Installation

### Recommended: dedicated installer

`install.py` installs the app (pip) and registers it in your desktop session:

```sh
python3 install.py
```

It installs into the first of these that works:

1. an active virtual environment,
2. the current user's site-packages (`pip --user`),
3. a dedicated venv under `~/.local/share/spriteviewer/venv`
   (standard for PEP 668 managed systems).

Afterwards the app is registered platform-dependent:

| Platform | Registration |
|---|---|
| **Linux** | `.desktop` entry + hicolor icon in `~/.local/share` |
| **macOS** | app bundle in `~/Applications/Sprite Viewer.app` |
| **Windows** | Start Menu shortcut |

System-wide installation (requires root/admin):

```sh
python3 install.py --system
```

### Via pip

```sh
pip install .
spriteviewer            # launch the installed command
```

## Usage

- **Tile thumbnails** load asynchronously and scale to the selected size.
- **Open Sprite** in the status bar lets you load another SVG sprite without
  restarting the app (a file picker opens where you last loaded from).
- **Right-click** an icon for the context menu: **Copy id** puts the SVG
  fragment id(s) on the clipboard, **Copy SVG** the complete, self-contained
  SVG document of the selected icon(s).
- **Multi-select** icons (Ctrl/Shift + click) to copy several at once.

Any SVG file passed as an argument is used as the sprite, which also lets you
hand it files from your file manager. `python -m spriteviewer` works the same
way as `./main.py`.

Compressed sprites are read transparently: gzip-packed files (`.svgz` or
`.svg.gz`) and zip archives containing a single `.svg` (`.svg.zip`) work
exactly like plain `.svg` files. A zip with several `.svg` members is rejected
with a clear error — an icon pack is not a sprite.

## Project structure

```
.
├── main.py                  # development entry point (adds src/, re-execs into .venv)
├── install.py               # cross-platform installer
├── pyproject.toml           # packaging + `spriteviewer` console script
├── requirements.txt         # runtime dependencies (PySide6, resvg-py)
├── spriteviewer.desktop     # desktop entry template (Linux)
├── docs/
│   └── screenshot.png
└── src/
    └── spriteviewer/        # the package (PEP 517 src layout)
        ├── __init__.py      # package exports
        ├── __main__.py      # `python -m spriteviewer`
        ├── app.py           # installed entry point / CLI parsing
        ├── icon_store.py    # sprite parsing + SVG rendering (resvg/QtSvg)
        ├── main_window.py   # toolbar, tile view, context menu
        ├── icons.svg        # bundled sprite (package data)
        └── spriteviewer.svg # bundled app icon (package data)
```

## License

GPL-3.0-or-later — see [LICENSE](LICENSE).

<!-- Badges -->
[ci-url]: https://github.com/svgforge/spriteviewer/actions/workflows/ci.yml
[ci-badge]: https://github.com/svgforge/spriteviewer/actions/workflows/ci.yml/badge.svg?branch=main

[release-url]: https://github.com/svgforge/spriteviewer/releases
[release-badge]: https://img.shields.io/github/v/release/svgforge/spriteviewer?label=release&sort=semver&color=2f6f4f

[license-url]: LICENSE
[license-badge]: https://img.shields.io/github/license/svgforge/spriteviewer?color=2f6f4f

[python-url]: https://www.python.org/
[python-badge]: https://img.shields.io/badge/python-3.10%2B-3776AB?logo=python&logoColor=white

[pyside-url]: https://doc.qt.io/qtforpython-6/
[pyside-badge]: https://img.shields.io/badge/PySide6-6.12%2B-41CD52?logo=qt&logoColor=white

[linux-badge]: https://img.shields.io/badge/Linux-FCC624?logo=linux&logoColor=black
[macos-badge]: https://img.shields.io/badge/macOS-000000?logo=apple&logoColor=white
[windows-badge]: https://img.shields.io/badge/Windows-0078D6
