Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
openatelier:projet:calendrier_2026 [2026/01/05 11:57] emoc |
openatelier:projet:calendrier_2026 [2026/01/05 12:45] (Version actuelle) emoc [Typos pour Plotter] |
||
|---|---|---|---|
| Ligne 27: | Ligne 27: | ||
| python3 svg_calendrier_mensuel.py 31 mardi | python3 svg_calendrier_mensuel.py 31 mardi | ||
| </code> | </code> | ||
| + | |||
| + | <accordion> | ||
| + | <panel title="svg_calendrier_mensuel.py (cliquer pour afficher le code)"> | ||
| + | <code python svg_calendrier_mensuel.py> | ||
| + | #!/usr/bin/env python3 | ||
| + | |||
| + | # création d'un calendrier mensuel, sous forme de fichier SVG | ||
| + | # 7 colonnes (L, M, M, J, V, S, D) avec entête x 6 lignes | ||
| + | # utilisation : | ||
| + | # python3 calendrier.py nombre-de-jours-du-mois 1er-jour-du-mois | ||
| + | # python3 calendrier.py 31 jeudi | ||
| + | # le script demandera comment nommer le fichier SVG | ||
| + | # le but final est d'appliquer une police «Hershey» dans inkscape pour que le calendrier | ||
| + | # puisse être réalisé au plotter | ||
| + | # | ||
| + | # 23/12/2025 pierre@lesporteslogiques.net | ||
| + | # Debian 12 @ tenko, python 3.11.2 | ||
| + | |||
| + | import sys | ||
| + | |||
| + | # Colonnes du calendrier | ||
| + | JOURS = ["L", "M", "M", "J", "V", "S", "D"] | ||
| + | JOUR_INDEX = { | ||
| + | "lundi": 0, | ||
| + | "mardi": 1, | ||
| + | "mercredi": 2, | ||
| + | "jeudi": 3, | ||
| + | "vendredi": 4, | ||
| + | "samedi": 5, | ||
| + | "dimanche": 6, | ||
| + | } | ||
| + | |||
| + | def generate_calendar_svg(nb_days, first_day, filename): | ||
| + | if first_day not in JOUR_INDEX: | ||
| + | raise ValueError("Jour invalide.") | ||
| + | |||
| + | start_col = JOUR_INDEX[first_day] | ||
| + | |||
| + | # Dimensions | ||
| + | cols = 7 | ||
| + | rows = 6 | ||
| + | cell_width = 30 | ||
| + | cell_height = 22 | ||
| + | header_height = 36 | ||
| + | |||
| + | width = cols * cell_width | ||
| + | height = header_height + rows * cell_height | ||
| + | |||
| + | # Taille maximale des chiffres | ||
| + | day_font_size = int(cell_height * 0.6) | ||
| + | |||
| + | svg = [] | ||
| + | svg.append(f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}">') | ||
| + | svg.append('<rect width="100%" height="100%" fill="white"/>') | ||
| + | |||
| + | # En-têtes | ||
| + | for col, label in enumerate(JOURS): | ||
| + | x = col * cell_widthc helloworld.txt | ||
| + | svg.append( | ||
| + | f'<text x="{x + cell_width/2}" y="{header_height/2 + 8}" ' | ||
| + | f'text-anchor="end" font-size="{day_font_size}" font-family="Arial" font-weight="bold">{label}</text>' | ||
| + | ) | ||
| + | |||
| + | # Placement des jours | ||
| + | day = 1 | ||
| + | for cell in range(start_col, start_col + nb_days): | ||
| + | row = cell // cols | ||
| + | col = cell % cols | ||
| + | |||
| + | x = col * cell_width + cell_width / 2 | ||
| + | y = header_height + row * cell_height + cell_height / 2 + day_font_size / 3 | ||
| + | |||
| + | svg.append( | ||
| + | f'<text x="{x}" y="{y}" text-anchor="end" ' | ||
| + | f'font-size="{day_font_size}" font-family="Arial" font-weight="bold">{day}</text>' | ||
| + | ) | ||
| + | day += 1 | ||
| + | |||
| + | svg.append("</svg>") | ||
| + | |||
| + | with open(filename, "w", encoding="utf-8") as f: | ||
| + | f.write("\n".join(svg)) | ||
| + | |||
| + | if __name__ == "__main__": | ||
| + | if len(sys.argv) != 3: | ||
| + | print("Usage : python3 calendrier.py <nb_jours> <jour_1er>") | ||
| + | sys.exit(1) | ||
| + | |||
| + | nb_jours = int(sys.argv[1]) | ||
| + | jour_1er = sys.argv[2].lower() | ||
| + | |||
| + | filename = input("Nom du fichier SVG à créer (ex: calendrier.svg) : ").strip() | ||
| + | if not filename.endswith(".svg"): | ||
| + | filename += ".svg" | ||
| + | |||
| + | generate_calendar_svg(nb_jours, jour_1er, filename) | ||
| + | print(f"Fichier '{filename}' généré.") | ||
| + | </code> | ||
| + | </panel> | ||
| + | </accordion> | ||
| + | |||
| + | ===== Typos pour Plotter ===== | ||
| + | |||
| + | Chaque calendrier est modifié dans inkscape en utilisant les polices de texte de type «Hershey» (cf. https://en.wikipedia.org/wiki/Hershey_fonts). Ces fontes ont pour caractéristiques d'être définies par un tracé central composé de lignes droites (et non pas un contour comme pour les fontes classiques) | ||
| + | |||
| + | Manip : sélectionner tout le texte, puis « extension/texte/texte Hershey », dans ce cas, c'est la police «HersheySans1» qui est utilisée. | ||
| + | |||
| + | |||
| + | |||
| + | |||