Skip to content

Commit 6c1ba81

Browse files
committed
Initial commit
0 parents  commit 6c1ba81

40 files changed

+12930
-0
lines changed

.codespellrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[codespell]
2+
skip = **/package-lock.json,**/*.umd.js,**/*.umd.js.map
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Test and Release
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
pre-commit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.10"
18+
19+
# Install and run pre-commit
20+
- run: |
21+
pip install pre-commit
22+
pre-commit install
23+
pre-commit run --all-files
24+
25+
pytest:
26+
name: Pytest ${{ matrix.config.name }}
27+
runs-on: ${{ matrix.config.os }}
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
python-version: ["3.9"]
32+
config:
33+
- {
34+
name: "Linux",
35+
os: ubuntu-latest
36+
}
37+
# - {
38+
# name: "MacOSX",
39+
# os: macos-latest
40+
# }
41+
# - {
42+
# name: "Windows",
43+
# os: windows-latest
44+
# }
45+
46+
defaults:
47+
run:
48+
shell: bash
49+
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
54+
- name: Set up Python ${{ matrix.python-version }}
55+
uses: actions/setup-python@v5
56+
with:
57+
python-version: ${{ matrix.python-version }}
58+
59+
- name: Install and Run Tests
60+
run: |
61+
pip install .
62+
pip install -r tests/requirements.txt
63+
pytest -s ./tests
64+
65+
test-npm-build:
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v4
71+
72+
- name: Set Up Node
73+
uses: actions/setup-node@v4
74+
with:
75+
node-version: 18
76+
77+
- name: Build Vue Components
78+
run: |
79+
cd vue-components
80+
npm ci
81+
npm run build
82+
83+
release:
84+
needs: [
85+
pre-commit,
86+
pytest,
87+
test-npm-build,
88+
]
89+
runs-on: ubuntu-latest
90+
if: github.event_name == 'push'
91+
environment: release
92+
permissions:
93+
id-token: write # IMPORTANT: mandatory for trusted publishing
94+
contents: write # IMPORTANT: mandatory for making GitHub Releases
95+
96+
steps:
97+
- name: Checkout
98+
uses: actions/checkout@v4
99+
with:
100+
fetch-depth: 0
101+
102+
- name: Set Up Node
103+
uses: actions/setup-node@v4
104+
with:
105+
node-version: 18
106+
107+
- name: Build Vue Components
108+
working-directory: vue-components
109+
run: |
110+
npm ci
111+
npm run build
112+
113+
- name: Python Semantic Release
114+
id: release
115+
uses: python-semantic-release/python-semantic-release@master
116+
with:
117+
github_token: ${{ secrets.GITHUB_TOKEN }}
118+
119+
# https://docs.pypi.org/trusted-publishers/using-a-publisher/
120+
- name: Publish package distributions to PyPI
121+
if: steps.release.outputs.released == 'true'
122+
uses: pypa/gh-action-pypi-publish@release/v1
123+

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.DS_Store
2+
node_modules
3+
.venv
4+
.ruff_cache
5+
.pytest_cache
6+
7+
# local env files
8+
.env.local
9+
.env.*.local
10+
11+
# Log files
12+
npm-debug.log*
13+
yarn-debug.log*
14+
yarn-error.log*
15+
pnpm-debug.log*
16+
17+
# Editor directories and files
18+
.idea
19+
.vscode
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
__pycache__
27+
build
28+
dist
29+
*egg-info
30+
*pyc

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
repos:
2+
- repo: https://github.com/codespell-project/codespell
3+
rev: v2.1.0
4+
hooks:
5+
- id: codespell
6+
7+
- repo: https://github.com/astral-sh/ruff-pre-commit
8+
rev: v0.8.4
9+
hooks:
10+
- id: ruff
11+
- id: ruff-format

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
graft trame_image_tools/module/serve
2+
prune examples
3+
prune tests
4+
prune vue-components
5+
prune .github

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# `trame-image-tools`
2+
3+
A set of [`trame`](https://github.com/kitware/trame) widgets to create a zoom and pan 2D image environment, with interactive area selection widgets.
4+
5+
![demo_image](demo.png)
6+
7+
## Install
8+
```bash
9+
pip install trame-image-tools
10+
```
11+
12+
## Usage
13+
```python
14+
from trame_image_tools.widgets import (
15+
TrameImage,
16+
TrameImageRoi,
17+
TrameImageLine,
18+
TrameImageCircle,
19+
TrameImagePolygon,
20+
TrameImageGrid,
21+
)
22+
23+
with TrameImage(
24+
src="https://www.kitware.com/main/wp-content/uploads/2023/10/logo-trame.png",
25+
size=("size", [800, 210]),
26+
):
27+
TrameImageGrid(
28+
spacing=("grid_spacing", [50, 25]), # [x_tick_spacing, y_tick_spacing]
29+
)
30+
31+
TrameImageLine(
32+
v_model=("line", [200, 50, 300, 150]), # [x0, y0, x1, y1, ...]
33+
)
34+
35+
TrameImageRoi(
36+
v_model=("roi", [350, 50, 100, 100]), # [x, y, width, height]
37+
)
38+
39+
TrameImageCircle(
40+
v_model=("circle", [550, 100, 50]), # [x, y, radius]
41+
)
42+
43+
TrameImagePolygon(
44+
v_model=("polygon", [650, 90, 670, 150, 730, 150, 750, 90, 700, 50]), # [x0, y0, x1, y1, ...]
45+
)
46+
```

demo.png

87.8 KB
Loading

examples/example.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from trame.app import get_server
2+
from trame.widgets import html, client
3+
from trame.ui.html import DivLayout
4+
from trame_image_tools.widgets import (
5+
TrameImage,
6+
TrameImageRoi,
7+
TrameImageLine,
8+
TrameImageCircle,
9+
TrameImagePolygon,
10+
TrameImageGrid,
11+
)
12+
13+
14+
class ExampleApp:
15+
def __init__(self, server=None):
16+
self._server = get_server(server, client_type="vue3")
17+
self.ui = None
18+
self._build_ui()
19+
20+
@property
21+
def server(self):
22+
return self._server
23+
24+
@property
25+
def state(self):
26+
return self.server.state
27+
28+
@property
29+
def ctrl(self):
30+
return self.server.controller
31+
32+
def _build_ui(self):
33+
with DivLayout(self.server) as layout:
34+
self._ui = layout
35+
36+
layout.root.style = "height: 100%;"
37+
38+
client.Style("""
39+
html { height: 100%; overflow: hidden;}
40+
body { height: 100%; margin: 0;}
41+
#app { height: 100%; }
42+
""")
43+
44+
with html.Div(style="width: 100%; height: 100%; background-color: black;"):
45+
with TrameImage(
46+
src="https://www.kitware.com/main/wp-content/uploads/2023/10/logo-trame.png",
47+
size=("[800, 210]",),
48+
v_model_scale=("scale", 0.9),
49+
v_model_center=("center", [0.5, 0.5]),
50+
):
51+
TrameImageGrid(
52+
spacing=("grid_spacing", [50, 25]),
53+
)
54+
55+
TrameImageLine(
56+
v_model=("line", [200, 50, 300, 150]),
57+
color="lime",
58+
thickness=3,
59+
handle_size=12,
60+
)
61+
62+
TrameImageRoi(
63+
v_model=("roi", [350, 50, 100, 100]),
64+
border_color="yellow",
65+
border_size=3,
66+
handle_size=12,
67+
)
68+
69+
TrameImageCircle(
70+
v_model=("circle", [550, 100, 50]),
71+
border_color="cyan",
72+
border_size=3,
73+
handle_size=12,
74+
)
75+
76+
TrameImagePolygon(
77+
v_model=("polygon", [650, 90, 670, 150, 730, 150, 750, 90, 700, 50]),
78+
border_color="fuchsia",
79+
border_size=3,
80+
handle_size=12,
81+
)
82+
83+
html.Button(
84+
"Reset Camera",
85+
style="position: absolute; left: 1rem; top: 1rem;",
86+
click="scale = 0.9; center = [0.5, 0.5];",
87+
)
88+
89+
90+
def main(server=None, **kwargs):
91+
app = ExampleApp(server)
92+
app.server.start(**kwargs)
93+
94+
95+
if __name__ == "__main__":
96+
main()

0 commit comments

Comments
 (0)