Linter for inkscape extension

This commit is contained in:
Alex committed 2026-10-24 21:38:03 +02:00
1 parent 00e9ba3434
commit 247ecc3f5a
17 files changed
+1002 -249

No files matched your search

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
# coding=utf-8
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2026 Alex
"""
Generates the icon of the extension for inkscape.org: a disc filled with the
maze computed by dog_bandana_core (same function as the extension).
python docs/make_icon.py # docs/icon.svg + docs/icon.png (256 px)
"""
import math
import os
import subprocess
import sys
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(HERE))
from dog_bandana_core import polylines_to_d, turing_pattern # noqa: E402
SIZE = 256
INKSCAPE = [r"C:\Program Files\Inkscape\bin\inkscape.com", "/usr/bin/inkscape",
"/Applications/Inkscape.app/Contents/MacOS/inkscape"]
def main():
center, radius = SIZE / 2, SIZE / 2 - 8
ring = [(center + radius * math.cos(2 * math.pi * k / 180),
center + radius * math.sin(2 * math.pi * k / 180)) for k in range(180)]
period, width = 22, 10
lines = turing_pattern([ring], period, width, margin=6, seed=3, steps=80)
svg = ('<?xml version="1.0" encoding="UTF-8"?>\n'
'<svg xmlns="http://www.w3.org/2000/svg" width="{0}" height="{0}" '
'viewBox="0 0 {0} {0}">\n'
'<circle cx="{1}" cy="{1}" r="{2}" fill="#ffffff" stroke="#212529" '
'stroke-width="6"/>\n'
'<path d="{3}" fill="none" stroke="#212529" stroke-width="{4}" '
'stroke-linecap="round" stroke-linejoin="round"/>\n'
'</svg>\n').format(SIZE, center, radius, polylines_to_d(lines, 2), width)
svg_path = os.path.join(HERE, "icon.svg")
png_path = os.path.join(HERE, "icon.png")
with open(svg_path, "w", encoding="utf-8", newline="\n") as handle:
handle.write(svg)
print(svg_path)
exe = next((path for path in INKSCAPE if os.path.exists(path)), None)
if exe is None:
print("Inkscape not found: export {} by hand".format(svg_path))
return
subprocess.run([exe, svg_path, "--export-type=png", "--export-width={}".format(SIZE),
"--export-filename={}".format(png_path)],
check=True, stderr=subprocess.DEVNULL)
print(png_path)
if __name__ == "__main__":
main()
+37 -35
View File
@@ -1,18 +1,20 @@
#!/usr/bin/env python3
# coding=utf-8
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2026 Alex
"""
Genere le schema explicatif des parametres de l'extension.
Generates the diagram that explains the extension parameters.
python docs/schema_parametres.py # les deux versions
python docs/schema_parametres.py # both versions
python docs/schema_parametres.py fr # docs/parametres.svg + .png (README)
python docs/schema_parametres.py en # docs/parameters_en.svg
# + images/parameters_en.png (onglet
# « Help » de la boite de dialogue)
# + images/parameters_en.png ("Help"
# tab of the dialog)
Les formes sont calculees par dog_bandana_core (memes fonctions que l'extension),
le schema reste donc fidele au resultat reel. L'export PNG passe par
inkscape.com, qui attend la fin de l'export (contrairement au raccourci
Chocolatey « inkscape »).
Shapes are computed by dog_bandana_core (same functions as the extension),
so the diagram stays faithful to the actual result. PNG export goes through
inkscape.com, which waits for the export to finish (unlike the Chocolatey
"inkscape" shim).
"""
import math
@@ -26,21 +28,21 @@ sys.path.insert(0, ROOT)
import dog_bandana_core # noqa: E402
W, H = 1400, 1280 # 4 panneaux de 700 x 640
W, H = 1400, 1280 # 4 panels of 700 x 640
INK = "#343a40" # element principal
GHOST = "#dde1e5" # elements secondaires / voisins
DIM = "#d9480f" # cotes
DIM2 = "#1971c2" # cotes secondaires
EDGE = "#212529" # contour des formes
INK = "#343a40" # main element
GHOST = "#dde1e5" # secondary / neighbouring elements
DIM = "#d9480f" # dimensions
DIM2 = "#1971c2" # secondary dimensions
EDGE = "#212529" # shape outlines
FONT = "font-family:Arial,Helvetica,sans-serif"
INKSCAPE = [r"C:\Program Files\Inkscape\bin\inkscape.com", "/usr/bin/inkscape",
"/Applications/Inkscape.app/Contents/MacOS/inkscape"]
# Version par langue : textes, fichiers produits, largeur du PNG et agrandissement
# des textes (la version anglaise est affichee reduite dans la boite de dialogue :
# 900 px de large, textes x 1.25 pour rester lisibles).
# Version per language: texts, output files, PNG width and text scaling (the
# English version is shown reduced in the dialog: 900 px wide, texts x 1.25 to
# stay readable).
VERSIONS = {
"fr": {
"svg": os.path.join(HERE, "parametres.svg"),
@@ -103,7 +105,7 @@ VERSIONS = {
}
def _unit(angle):
"""Vecteur unitaire, angle en degres, sens anti-horaire a l'ecran (y vers le bas)."""
"""Unit vector, angle in degrees, counterclockwise on screen (y pointing down)."""
a = math.radians(angle)
return math.cos(a), -math.sin(a)
@@ -141,7 +143,7 @@ def text(x, y, s, size=17, color=INK, anchor="start", weight="normal", halo=True
def note(x, y, lines):
"""Legende de bas de panneau, derniere ligne sur la ligne de base `y`."""
"""Panel caption, last line on baseline `y`."""
step = 22 * FS
for k, line in enumerate(lines):
text(x, y - (len(lines) - 1 - k) * step, line, size=16, halo=False)
@@ -157,7 +159,7 @@ def arrow_head(tip, direction, color, size=9):
def dimension(p, q, offset, label, color=DIM, label_pos=0.5, label_shift=18, size=17):
"""Cote entre p et q, decalee de `offset` perpendiculairement."""
"""Dimension between p and q, shifted by `offset` perpendicularly."""
dx, dy = q[0] - p[0], q[1] - p[1]
length = math.hypot(dx, dy)
ux, uy = dx / length, dy / length
@@ -178,7 +180,7 @@ def dimension(p, q, offset, label, color=DIM, label_pos=0.5, label_shift=18, siz
def arc(center, radius, a0, a1, color, label=None, label_radius=None, size=16):
"""Arc de a0 a a1 degres (sens anti-horaire a l'ecran), fleche au bout."""
"""Arc from a0 to a1 degrees (counterclockwise on screen), arrow at the end."""
steps = 40
points = []
for k in range(steps + 1):
@@ -206,12 +208,12 @@ def panel_title(x, y, number, title):
# --------------------------------------------------------------------------
# Panneaux : un par parametre (ou groupe de parametres), numerotes 1 a 4.
# Motifs calcules par dog_bandana_core.turing_pattern, comme dans l'extension.
# Panels: one per parameter (or group of parameters), numbered 1 to 4.
# Patterns computed by dog_bandana_core.turing_pattern, as in the extension.
# --------------------------------------------------------------------------
def strokes(polylines, color, width):
"""Traits a bouts ronds, comme ceux produits par l'extension."""
"""Round-capped strokes, like those produced by the extension."""
for pl in polylines:
out.append('<polyline points="{}" fill="none" stroke="{}" stroke-width="{}" '
'stroke-linecap="round" stroke-linejoin="round"/>'.format(
@@ -230,7 +232,7 @@ def rect_ring(x0, y0, x1, y1):
def crossings(polylines, x):
"""Intersections des polylignes avec la verticale x : (y, pente, numero)."""
"""Crossings of the polylines with the vertical x: (y, slope, index)."""
found = []
for index, pl in enumerate(polylines):
for (ax, ay), (bx, by) in zip(pl, pl[1:]):
@@ -241,16 +243,16 @@ def crossings(polylines, x):
def panel_1():
"""Periode et epaisseur : cotes sur deux lignes voisines bien paralleles."""
"""Period and width: dimensions on two neighbouring, nearly parallel lines."""
period, width = 64, 28
region = rect_ring(60, 90, 640, 530)
def near(cuts, index, y):
return any(i == index and abs(cy - y) < 6 for cy, _s, i in cuts)
# Cherche deux lignes voisines presque horizontales sur une bonne longueur
# (verticales x - 70, x, x + 70), espacees d'environ une periode : les
# cotes tiennent dans l'espace blanc entre elles.
# Look for two neighbouring lines, nearly horizontal over a good length
# (verticals x - 70, x, x + 70), about one period apart: the dimensions
# fit in the white space between them.
best = None
for seed in range(1, 9):
lines = dog_bandana_core.turing_pattern([region], period, width, seed=seed,
@@ -272,12 +274,12 @@ def panel_1():
strokes([pl for k, pl in enumerate(lines) if k not in (i1, i2)], GHOST, width)
strokes([lines[i1], lines[i2]], INK, width)
outline([region], EDGE, 2)
# Periode : d'axe en axe ; epaisseur : bord a bord d'une meme ligne.
# Period: center to center; width: edge to edge of a single line.
for y in (y1, y2):
polyline([(x - 25, y), (x + 25, y)], DIM, 1.4, 'stroke-dasharray="4,3"')
dimension((x, y1), (x, y2), 0, "")
text(x + 12, (y1 + y2) / 2 + 6, T["period"], color=DIM, weight="bold")
# Epaisseur sur la ligne du bas, legende dessous (zone claire).
# Width on the lower line, label below it (clear area).
xw = x - 70
dimension((xw, y2 - width / 2), (xw, y2 + width / 2), 0, "", color=DIM2)
text(xw, y2 + width / 2 + 28, T["width"], color=DIM2, anchor="middle",
@@ -286,7 +288,7 @@ def panel_1():
def panel_2():
"""Iterations : meme graine, trois durees d'evolution."""
"""Iterations: same seed, three evolution times."""
ox = 700
panel_title(ox + 30, 50, 2, T["title2"])
size, gap = 190, 25
@@ -308,7 +310,7 @@ def panel_2():
def panel_3():
"""Bord de la forme : motif coupe (tissu decoupe) ou qui longe le bord."""
"""Shape edge: pattern cut (like fabric) or running along the edge."""
oy = 640
panel_title(30, oy + 50, 3, T["title3"])
for k, edge in enumerate(("cut", "follow")):
@@ -323,7 +325,7 @@ def panel_3():
def panel_4():
"""Marge : espace libre entre le bord et les traits."""
"""Margin: free space between the edge and the strokes."""
ox, oy = 700, 640
panel_title(ox + 30, oy + 50, 4, T["title4"])
margin, period, width = 40, 30, 14
@@ -342,7 +344,7 @@ def panel_4():
def export_png(svg_path, png_path, width):
exe = next((path for path in INKSCAPE if os.path.exists(path)), None)
if exe is None:
print("Inkscape introuvable : exporter {} a la main".format(svg_path))
print("Inkscape not found: export {} by hand".format(svg_path))
return
os.makedirs(os.path.dirname(png_path), exist_ok=True)
subprocess.run([exe, svg_path, "--export-type=png",