mocodoeditor 0.2.5__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.
- mocodoeditor-0.2.5/LICENSE +21 -0
- mocodoeditor-0.2.5/PKG-INFO +74 -0
- mocodoeditor-0.2.5/README.md +54 -0
- mocodoeditor-0.2.5/mocodoeditor/__init__.py +2 -0
- mocodoeditor-0.2.5/mocodoeditor/__main__.py +3 -0
- mocodoeditor-0.2.5/mocodoeditor/app.py +66 -0
- mocodoeditor-0.2.5/mocodoeditor/catalog.py +139 -0
- mocodoeditor-0.2.5/mocodoeditor/code_editor.py +104 -0
- mocodoeditor-0.2.5/mocodoeditor/constants.py +14 -0
- mocodoeditor-0.2.5/mocodoeditor/exports.py +106 -0
- mocodoeditor-0.2.5/mocodoeditor/external.py +33 -0
- mocodoeditor-0.2.5/mocodoeditor/find_bar.py +157 -0
- mocodoeditor-0.2.5/mocodoeditor/icons.py +44 -0
- mocodoeditor-0.2.5/mocodoeditor/main_window.py +850 -0
- mocodoeditor-0.2.5/mocodoeditor/mocodo.py +146 -0
- mocodoeditor-0.2.5/mocodoeditor/mocodoscan.py +130 -0
- mocodoeditor-0.2.5/mocodoeditor/options.py +89 -0
- mocodoeditor-0.2.5/mocodoeditor/panels.py +326 -0
- mocodoeditor-0.2.5/mocodoeditor/themes.py +67 -0
- mocodoeditor-0.2.5/mocodoeditor/version.py +2 -0
- mocodoeditor-0.2.5/mocodoeditor/views.py +108 -0
- mocodoeditor-0.2.5/mocodoeditor.egg-info/PKG-INFO +74 -0
- mocodoeditor-0.2.5/mocodoeditor.egg-info/SOURCES.txt +29 -0
- mocodoeditor-0.2.5/mocodoeditor.egg-info/dependency_links.txt +1 -0
- mocodoeditor-0.2.5/mocodoeditor.egg-info/entry_points.txt +2 -0
- mocodoeditor-0.2.5/mocodoeditor.egg-info/requires.txt +2 -0
- mocodoeditor-0.2.5/mocodoeditor.egg-info/top_level.txt +1 -0
- mocodoeditor-0.2.5/pyproject.toml +32 -0
- mocodoeditor-0.2.5/setup.cfg +4 -0
- mocodoeditor-0.2.5/tests/test_coloration.py +98 -0
- mocodoeditor-0.2.5/tests/test_mocodo.py +269 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Emmanuel Desmontils
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mocodoeditor
|
|
3
|
+
Version: 0.2.5
|
|
4
|
+
Summary: Éditeur de bureau pour Mocodo : le code à gauche, le MCD en direct à droite (PyQt6).
|
|
5
|
+
Author: Emmanuel Desmontils
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: mocodo,mcd,merise,editor,pyqt6
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: X11 Applications :: Qt
|
|
10
|
+
Classifier: Intended Audience :: Education
|
|
11
|
+
Classifier: Natural Language :: French
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Database
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: PyQt6>=6.8
|
|
18
|
+
Requires-Dist: mocodo>=4.3
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# MocodoEditor
|
|
22
|
+
|
|
23
|
+
Éditeur [Mocodo](https://www.mocodo.net) simple en deux panneaux : le **code à gauche**, le **MCD en direct à droite**.
|
|
24
|
+
Application de bureau Python/PyQt6, construite sur le modèle de PUMLEditor et SVGEditor.
|
|
25
|
+
|
|
26
|
+
📖 **[Mode d'emploi](MODE_EMPLOI.md)** : installation, écriture d'un MCD, retouches, options, sorties, raccourcis.
|
|
27
|
+
|
|
28
|
+
## Fonctionnement
|
|
29
|
+
|
|
30
|
+
Le texte est écrit dans un dossier temporaire puis traité par la commande `mocodo` (processus asynchrone, 600 ms après la dernière frappe) ; le SVG produit est affiché par `QSvgWidget`.
|
|
31
|
+
Si le texte est invalide, le dernier MCD valide reste affiché et le message de Mocodo est signalé dans la barre d'état.
|
|
32
|
+
|
|
33
|
+
- Un `params.json` placé dans le dossier du fichier est pris en compte (couleurs, formes, échelle…).
|
|
34
|
+
- Fichiers récents, rechargement après modification externe, rechercher/remplacer, thème clair/sombre, zoom / ajustement, exemples.
|
|
35
|
+
|
|
36
|
+
## Reprend les fonctionnalités de mocodo.net
|
|
37
|
+
|
|
38
|
+
- **Onglet Diagramme / Autres sorties / Erreurs** (⌘1, ⌘2, ⌘3). *Autres sorties* : schéma relationnel (Markdown, texte, LaTeX, HTML), scripts SQL, dictionnaire des données, UML, pattes de corbeau, notation de Chen, lien Mocodo en ligne, prompt pour une IA ; chacune se copie ou s'enregistre.
|
|
39
|
+
- **Menu Retouches** : Réarranger, Inverser, Éditer (casse, ASCII, cardinalités), Révéler (DF, CIF, rôles, types), Masquer (libellés génériques, faux texte, MCD d'entraînement), Décomposer. Le texte est réécrit par Mocodo ; Édition → Annuler revient en arrière.
|
|
40
|
+
- **Panneau Options** (⇧⌘O) : palette de couleurs, mode nuit, police et proportions, échelle, formats des cardinalités et des clés étrangères, etc. Les réglages laissés par défaut ne sont pas transmis, donc `params.json` garde la main.
|
|
41
|
+
- **Fichier** : exports PNG, SVG et PDF, impression, ouverture dans Mocodo en ligne.
|
|
42
|
+
|
|
43
|
+
## Prérequis
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install mocodo
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
La commande `mocodo` est cherchée dans le `PATH` puis dans les emplacements usuels ; **Édition → Chemin de Mocodo…** permet d'en choisir une autre.
|
|
50
|
+
|
|
51
|
+
## Lancement
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
55
|
+
pip install -r requirements.txt
|
|
56
|
+
python3 -m mocodoeditor [fichier.mcd]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Organisation
|
|
60
|
+
|
|
61
|
+
| Chemin | Rôle |
|
|
62
|
+
|---|---|
|
|
63
|
+
| `mocodoeditor/mocodo.py` | Localisation de Mocodo, exécution asynchrone (`Run`) |
|
|
64
|
+
| `mocodoeditor/catalog.py` | Retouches, sorties, palettes, formes et exemples (tables) |
|
|
65
|
+
| `mocodoeditor/options.py` | Réglages d'affichage transmis à Mocodo |
|
|
66
|
+
| `mocodoeditor/panels.py` | Panneau Options, onglets Autres sorties et Erreurs |
|
|
67
|
+
| `mocodoeditor/main_window.py` | Fenêtre principale (menus, fichiers, rendu, zoom, exports) |
|
|
68
|
+
| `mocodoeditor/themes.py` | Thèmes et coloration syntaxique Mocodo |
|
|
69
|
+
| `mocodoeditor/mocodoscan.py` | Découpage d'une ligne Mocodo en lexèmes (coloration), sans Qt |
|
|
70
|
+
| `mocodoeditor/exports.py` | Impression, export PNG et SVG |
|
|
71
|
+
| `mocodoeditor/code_editor.py`, `find_bar.py` | Éditeur à numéros de ligne, recherche/remplacement |
|
|
72
|
+
| `packaging/` | Construction du `.app` (py2app) |
|
|
73
|
+
| `MODE_EMPLOI.md` | Mode d'emploi |
|
|
74
|
+
| `tests/` | Tests (`python3 -I -m pytest -q tests`) |
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# MocodoEditor
|
|
2
|
+
|
|
3
|
+
Éditeur [Mocodo](https://www.mocodo.net) simple en deux panneaux : le **code à gauche**, le **MCD en direct à droite**.
|
|
4
|
+
Application de bureau Python/PyQt6, construite sur le modèle de PUMLEditor et SVGEditor.
|
|
5
|
+
|
|
6
|
+
📖 **[Mode d'emploi](MODE_EMPLOI.md)** : installation, écriture d'un MCD, retouches, options, sorties, raccourcis.
|
|
7
|
+
|
|
8
|
+
## Fonctionnement
|
|
9
|
+
|
|
10
|
+
Le texte est écrit dans un dossier temporaire puis traité par la commande `mocodo` (processus asynchrone, 600 ms après la dernière frappe) ; le SVG produit est affiché par `QSvgWidget`.
|
|
11
|
+
Si le texte est invalide, le dernier MCD valide reste affiché et le message de Mocodo est signalé dans la barre d'état.
|
|
12
|
+
|
|
13
|
+
- Un `params.json` placé dans le dossier du fichier est pris en compte (couleurs, formes, échelle…).
|
|
14
|
+
- Fichiers récents, rechargement après modification externe, rechercher/remplacer, thème clair/sombre, zoom / ajustement, exemples.
|
|
15
|
+
|
|
16
|
+
## Reprend les fonctionnalités de mocodo.net
|
|
17
|
+
|
|
18
|
+
- **Onglet Diagramme / Autres sorties / Erreurs** (⌘1, ⌘2, ⌘3). *Autres sorties* : schéma relationnel (Markdown, texte, LaTeX, HTML), scripts SQL, dictionnaire des données, UML, pattes de corbeau, notation de Chen, lien Mocodo en ligne, prompt pour une IA ; chacune se copie ou s'enregistre.
|
|
19
|
+
- **Menu Retouches** : Réarranger, Inverser, Éditer (casse, ASCII, cardinalités), Révéler (DF, CIF, rôles, types), Masquer (libellés génériques, faux texte, MCD d'entraînement), Décomposer. Le texte est réécrit par Mocodo ; Édition → Annuler revient en arrière.
|
|
20
|
+
- **Panneau Options** (⇧⌘O) : palette de couleurs, mode nuit, police et proportions, échelle, formats des cardinalités et des clés étrangères, etc. Les réglages laissés par défaut ne sont pas transmis, donc `params.json` garde la main.
|
|
21
|
+
- **Fichier** : exports PNG, SVG et PDF, impression, ouverture dans Mocodo en ligne.
|
|
22
|
+
|
|
23
|
+
## Prérequis
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install mocodo
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
La commande `mocodo` est cherchée dans le `PATH` puis dans les emplacements usuels ; **Édition → Chemin de Mocodo…** permet d'en choisir une autre.
|
|
30
|
+
|
|
31
|
+
## Lancement
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
35
|
+
pip install -r requirements.txt
|
|
36
|
+
python3 -m mocodoeditor [fichier.mcd]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Organisation
|
|
40
|
+
|
|
41
|
+
| Chemin | Rôle |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `mocodoeditor/mocodo.py` | Localisation de Mocodo, exécution asynchrone (`Run`) |
|
|
44
|
+
| `mocodoeditor/catalog.py` | Retouches, sorties, palettes, formes et exemples (tables) |
|
|
45
|
+
| `mocodoeditor/options.py` | Réglages d'affichage transmis à Mocodo |
|
|
46
|
+
| `mocodoeditor/panels.py` | Panneau Options, onglets Autres sorties et Erreurs |
|
|
47
|
+
| `mocodoeditor/main_window.py` | Fenêtre principale (menus, fichiers, rendu, zoom, exports) |
|
|
48
|
+
| `mocodoeditor/themes.py` | Thèmes et coloration syntaxique Mocodo |
|
|
49
|
+
| `mocodoeditor/mocodoscan.py` | Découpage d'une ligne Mocodo en lexèmes (coloration), sans Qt |
|
|
50
|
+
| `mocodoeditor/exports.py` | Impression, export PNG et SVG |
|
|
51
|
+
| `mocodoeditor/code_editor.py`, `find_bar.py` | Éditeur à numéros de ligne, recherche/remplacement |
|
|
52
|
+
| `packaging/` | Construction du `.app` (py2app) |
|
|
53
|
+
| `MODE_EMPLOI.md` | Mode d'emploi |
|
|
54
|
+
| `tests/` | Tests (`python3 -I -m pytest -q tests`) |
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Application : QApplication (ouverture depuis le Finder) et fonction main()."""
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from PyQt6.QtCore import QEvent
|
|
6
|
+
from PyQt6.QtGui import QFont
|
|
7
|
+
from PyQt6.QtWidgets import QApplication
|
|
8
|
+
|
|
9
|
+
from .constants import APP_NAME
|
|
10
|
+
from .main_window import MainWindow
|
|
11
|
+
from .version import __version__
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def set_macos_app_name(name):
|
|
15
|
+
"""Sous macOS, le menu de l'application s'appelle « Python » (nom du bundle de
|
|
16
|
+
l'interpréteur) ; on le renomme avant la création de QApplication.
|
|
17
|
+
Nécessite pyobjc (optionnel) : sans lui, le nom reste inchangé."""
|
|
18
|
+
if sys.platform != "darwin":
|
|
19
|
+
return
|
|
20
|
+
try:
|
|
21
|
+
from Foundation import NSBundle
|
|
22
|
+
except ImportError:
|
|
23
|
+
return
|
|
24
|
+
info = NSBundle.mainBundle().infoDictionary()
|
|
25
|
+
info["CFBundleName"] = name
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class MocodoApplication(QApplication):
|
|
29
|
+
"""Gère l'ouverture d'un fichier par Finder (double-clic, « Ouvrir avec »)."""
|
|
30
|
+
window: "MainWindow | None" = None
|
|
31
|
+
pending: str | None = None
|
|
32
|
+
|
|
33
|
+
def event(self, e):
|
|
34
|
+
if e.type() == QEvent.Type.FileOpen:
|
|
35
|
+
if self.window:
|
|
36
|
+
self.window.open_recent(e.file())
|
|
37
|
+
else: # l'événement peut arriver avant la création de la fenêtre
|
|
38
|
+
self.pending = e.file()
|
|
39
|
+
return True
|
|
40
|
+
return super().event(e)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def main():
|
|
44
|
+
if "--version" in sys.argv[1:]:
|
|
45
|
+
print(f"{APP_NAME} {__version__}")
|
|
46
|
+
sys.exit(0)
|
|
47
|
+
set_macos_app_name(APP_NAME)
|
|
48
|
+
app = MocodoApplication(sys.argv)
|
|
49
|
+
# les SVG produits demandent parfois « sans-serif », absente de macOS : évite une recherche coûteuse
|
|
50
|
+
if sys.platform == "darwin":
|
|
51
|
+
QFont.insertSubstitution("Sans-serif", "Helvetica Neue")
|
|
52
|
+
QFont.insertSubstitution("sans-serif", "Helvetica Neue")
|
|
53
|
+
else: # hors macOS, Fusion suit l'apparence clair/sombre demandée (Qt ≥ 6.8)
|
|
54
|
+
app.setStyle("Fusion")
|
|
55
|
+
app.setApplicationName(APP_NAME)
|
|
56
|
+
app.setApplicationVersion(__version__)
|
|
57
|
+
win = MainWindow()
|
|
58
|
+
app.window = win
|
|
59
|
+
win.show()
|
|
60
|
+
# fichier passé en argument ou reçu de Finder au démarrage
|
|
61
|
+
start = app.pending or next((a for a in sys.argv[1:] if Path(a).is_file()), None)
|
|
62
|
+
if start:
|
|
63
|
+
win.load_path(Path(start))
|
|
64
|
+
else: # sinon, le dernier fichier ouvert ; à défaut, le nouveau document par défaut
|
|
65
|
+
win.open_last_recent()
|
|
66
|
+
sys.exit(app.exec())
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Ce que Mocodo sait faire, sous forme de tables : retouches, sorties, palettes, formes, exemples.
|
|
2
|
+
|
|
3
|
+
Chaque retouche ou sortie est une liste d'arguments pour `mocodo -t` (voir `mocodo --help`)."""
|
|
4
|
+
|
|
5
|
+
# Retouches du texte (menu Retouches, comme l'onglet du même nom de mocodo.net) :
|
|
6
|
+
# (menu, [(libellé, arguments de -t)]). Un séparateur est noté (None, None).
|
|
7
|
+
ARRANGE_TIMEOUT = "timeout=20" # le Branch & Bound sans limite peut durer très longtemps
|
|
8
|
+
RETOUCHES = [
|
|
9
|
+
("Réarranger", [
|
|
10
|
+
("Sans contraintes", ["arrange:" + ARRANGE_TIMEOUT]),
|
|
11
|
+
("En privilégiant la largeur", ["arrange:wide," + ARRANGE_TIMEOUT]),
|
|
12
|
+
("Sur la grille actuelle", ["arrange:current," + ARRANGE_TIMEOUT]),
|
|
13
|
+
("Sur la plus petite grille équilibrée", ["arrange:balanced=0," + ARRANGE_TIMEOUT]),
|
|
14
|
+
("Sur la seconde plus petite grille équilibrée", ["arrange:balanced=1," + ARRANGE_TIMEOUT]),
|
|
15
|
+
("Avec l'algorithme génétique", ["arrange:algo=ga"]),
|
|
16
|
+
]),
|
|
17
|
+
("Inverser", [
|
|
18
|
+
("Horizontalement", ["flip:h"]),
|
|
19
|
+
("Verticalement", ["flip:v"]),
|
|
20
|
+
("Selon la première diagonale", ["flip:vhd"]),
|
|
21
|
+
("Selon la seconde diagonale", ["flip:d"]),
|
|
22
|
+
]),
|
|
23
|
+
("Éditer", [
|
|
24
|
+
("Libellés en camelCase", ["camel:labels"]),
|
|
25
|
+
("Libellés en PascalCase", ["pascal:labels"]),
|
|
26
|
+
("Libellés en snake_case", ["snake:labels"]),
|
|
27
|
+
("Libellés en ASCII", ["ascii:labels"]),
|
|
28
|
+
(None, None),
|
|
29
|
+
("Attributs en minuscules", ["lower:attrs"]),
|
|
30
|
+
("Noms des entités et des associations en majuscules", ["upper:boxes"]),
|
|
31
|
+
("Corriger les fautes de frappe dans les cardinalités", ["fix:cards"]),
|
|
32
|
+
("Tout normaliser (ASCII, minuscules, majuscules, cardinalités)",
|
|
33
|
+
["ascii:labels", "lower:attrs", "upper:boxes", "fix:cards"]),
|
|
34
|
+
]),
|
|
35
|
+
("Révéler", [
|
|
36
|
+
("Mettre des DF partout où c'est possible", ["create:dfs"]),
|
|
37
|
+
("Ajouter des flèches aux DF", ["add:df_arrows"]),
|
|
38
|
+
("Ajouter les CIF correspondant aux agrégats", ["add:cifs"]),
|
|
39
|
+
("Mettre comme rôles le nom des associations", ["add:roles"]),
|
|
40
|
+
(None, None),
|
|
41
|
+
("Mettre en évidence les types à remplir", ["create:types=TODO"]),
|
|
42
|
+
("Deviner les types à partir du nom des attributs", ["guess:types"]),
|
|
43
|
+
("Supprimer les types", ["delete:types"]),
|
|
44
|
+
(None, None),
|
|
45
|
+
("Réparer l'oubli d'entités référencées dans des associations", ["create:entities"]),
|
|
46
|
+
]),
|
|
47
|
+
("Masquer", [
|
|
48
|
+
("Remplacer les libellés par des libellés génériques numérotés", ["drown"]),
|
|
49
|
+
("Masquer les attributs et les cardinalités", ["empty"]),
|
|
50
|
+
("Remplir les types au hasard", ["randomize:types"]),
|
|
51
|
+
("Masquer avec du faux texte", ["obfuscate"]),
|
|
52
|
+
(None, None),
|
|
53
|
+
("Créer un MCD d'entraînement à la conversion en relationnel",
|
|
54
|
+
["grow:n=9,from_scratch,ent_attrs=3", "obfuscate:labels=en4", "create:roles", "lower:roles",
|
|
55
|
+
"arrange:" + ARRANGE_TIMEOUT]),
|
|
56
|
+
("Créer un MCD aléatoire avec des libellés génériques numérotés",
|
|
57
|
+
["grow:from_scratch", "drown", "arrange:" + ARRANGE_TIMEOUT]),
|
|
58
|
+
]),
|
|
59
|
+
("Décomposer", [
|
|
60
|
+
("Drainer les DF porteuses d'attributs", ["drain"]),
|
|
61
|
+
("Décomposer les DF ternaires et plus", ["split", "arrange:" + ARRANGE_TIMEOUT]),
|
|
62
|
+
("Décomposer les non-DF ternaires et plus", ["explode", "arrange:" + ARRANGE_TIMEOUT]),
|
|
63
|
+
("Décomposer les non-DF binaires porteuses d'attributs",
|
|
64
|
+
["explode:arity=2.5", "arrange:" + ARRANGE_TIMEOUT]),
|
|
65
|
+
("Décomposer toutes les non-DF binaires", ["explode:arity=2", "arrange:" + ARRANGE_TIMEOUT]),
|
|
66
|
+
]),
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
# Sorties textuelles (onglet « Autres sorties ») : (groupe, [(libellé, arguments de -t, extension)])
|
|
70
|
+
OUTPUTS = [
|
|
71
|
+
("Schéma relationnel", [
|
|
72
|
+
("Markdown", ["markdown"], ".md"), ("Texte", ["text"], ".txt"),
|
|
73
|
+
("LaTeX", ["latex"], ".tex"), ("HTML", ["html"], ".html"),
|
|
74
|
+
]),
|
|
75
|
+
("Script SQL", [
|
|
76
|
+
("MySQL / MariaDB", ["mysql"], ".sql"), ("PostgreSQL", ["postgresql"], ".sql"),
|
|
77
|
+
("SQLite", ["sqlite"], ".sql"), ("SQL Server", ["sqlserver"], ".sql"), ("Oracle", ["oracle"], ".sql"),
|
|
78
|
+
]),
|
|
79
|
+
("Dessin", [
|
|
80
|
+
("Dessin du MCD (SVG)", [], ".svg"),
|
|
81
|
+
]),
|
|
82
|
+
("Autres notations", [
|
|
83
|
+
("Dictionnaire des données", ["data_dict"], ".md"),
|
|
84
|
+
("Diagramme de classes UML (PlantUML)", ["uml"], ".puml"),
|
|
85
|
+
("Pattes de corbeau (Mermaid)", ["crow:mmd"], ".mmd"),
|
|
86
|
+
("Pattes de corbeau (Graphviz)", ["crow"], ".gv"),
|
|
87
|
+
("Notation de Chen avec attributs (Graphviz)", ["chen:attrs"], ".gv"),
|
|
88
|
+
]),
|
|
89
|
+
("Partage", [
|
|
90
|
+
("Lien vers Mocodo en ligne", ["share"], ".url"),
|
|
91
|
+
("Prompt pour une IA (avec cardinalités et types)", ["prompt:cards,types"], ".txt"),
|
|
92
|
+
]),
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
# Fichiers que Mocodo écrit toujours et qui ne sont pas le résultat d'une conversion.
|
|
96
|
+
SIDE_FILES = {"mcd.mcd", "mcd.svg", "mcd_geo.json", "mcd_static.svg", "params.json"}
|
|
97
|
+
|
|
98
|
+
PALETTES = ["bw", "wb", "gray", "blank", "ocean", "pond", "desert", "keepsake", "mondrian", "xinnian",
|
|
99
|
+
"dark", "dark-ocean", "dark-pond", "dark-desert"] + [f"brewer{s}{n}" for s in "+-" for n in range(1, 10)]
|
|
100
|
+
# Police non connue de Mocodo : le dessin est calculé avec les proportions d'Arial (voir `options.py`).
|
|
101
|
+
ATKINSON = "Atkinson Hyperlegible Next"
|
|
102
|
+
ATKINSON_MONO = "Atkinson Hyperlegible Mono"
|
|
103
|
+
# polices à chasse fixe proposées pour l'éditeur et les textes calculés (les absentes du Mac sont ignorées)
|
|
104
|
+
EDITOR_FONTS = [ATKINSON_MONO, "SF Mono", "Menlo", "Monaco", "Courier New"]
|
|
105
|
+
SHAPES = [ATKINSON, "copperplate", "arial", "georgia", "sans", "serif", "times", "trebuchet", "verdana", "mondrian", "xinnian"]
|
|
106
|
+
|
|
107
|
+
CARD_FORMATS = ["{min_card},{max_card}", "({min_card},{max_card})", "{min_card}..{max_card}", "{min_card}-{max_card}"]
|
|
108
|
+
FK_FORMATS = ["#{label}", "{label}#", "{label}"]
|
|
109
|
+
|
|
110
|
+
EXAMPLES = [
|
|
111
|
+
("Clients et commandes", """CLIENT: réf. client, nom, prénom, ville
|
|
112
|
+
PASSER, 0N CLIENT, 11 COMMANDE
|
|
113
|
+
COMMANDE: num. commande, date, montant
|
|
114
|
+
CONTENIR, 1N COMMANDE, 0N PRODUIT: quantité
|
|
115
|
+
PRODUIT: réf. produit, libellé, prix unitaire
|
|
116
|
+
"""),
|
|
117
|
+
("Bibliothèque", """ADHÉRENT: num. adhérent, nom, prénom
|
|
118
|
+
EMPRUNTER, 0N ADHÉRENT, 0N EXEMPLAIRE: date emprunt, date retour
|
|
119
|
+
EXEMPLAIRE: num. exemplaire, état
|
|
120
|
+
CORRESPONDRE, 11 EXEMPLAIRE, 0N LIVRE
|
|
121
|
+
LIVRE: ISBN, titre, année
|
|
122
|
+
ÉCRIRE, 1N LIVRE, 0N AUTEUR
|
|
123
|
+
AUTEUR: num. auteur, nom
|
|
124
|
+
"""),
|
|
125
|
+
("Employés et projets (tutoriel Mocodo)", """DÉPARTEMENT: num. département, nom département
|
|
126
|
+
EMPLOYER, 11 EMPLOYÉ, 1N DÉPARTEMENT
|
|
127
|
+
EMPLOYÉ: matricule, nom employé
|
|
128
|
+
TRAVAILLER, 0N EMPLOYÉ, 1N PROJET
|
|
129
|
+
PROJET: num. projet, nom projet
|
|
130
|
+
DIRIGER, 0N [responsable] EMPLOYÉ, 01 PROJET
|
|
131
|
+
"""),
|
|
132
|
+
("Association réflexive", """PIÈCE: réf. pièce, libellé pièce
|
|
133
|
+
COMPOSER, 0N [composée] PIÈCE, 0N [composante] PIÈCE: quantité
|
|
134
|
+
"""),
|
|
135
|
+
("Entité faible et dépendance fonctionnelle", """CHAMBRE: num. chambre, étage
|
|
136
|
+
DF, _11 CHAMBRE, 0N HÔTEL
|
|
137
|
+
HÔTEL: num. hôtel, nom, adresse
|
|
138
|
+
"""),
|
|
139
|
+
]
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Éditeur de code avec numéros de ligne et ligne courante mise en valeur."""
|
|
2
|
+
from PyQt6.QtCore import QRect, QSize, Qt
|
|
3
|
+
from PyQt6.QtGui import QColor, QFont, QPainter, QPalette, QTextFormat
|
|
4
|
+
from PyQt6.QtWidgets import QFrame, QPlainTextEdit, QTextEdit, QWidget
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class LineNumberArea(QWidget):
|
|
8
|
+
def __init__(self, editor):
|
|
9
|
+
super().__init__(editor)
|
|
10
|
+
self.editor = editor
|
|
11
|
+
|
|
12
|
+
def sizeHint(self):
|
|
13
|
+
return QSize(self.editor.number_area_width(), 0)
|
|
14
|
+
|
|
15
|
+
def paintEvent(self, event):
|
|
16
|
+
self.editor.paint_numbers(event)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CodeEditor(QPlainTextEdit):
|
|
20
|
+
"""QPlainTextEdit avec une marge de numéros de ligne, sans cadre, à fond uni."""
|
|
21
|
+
|
|
22
|
+
def __init__(self):
|
|
23
|
+
super().__init__()
|
|
24
|
+
self.setFrameShape(QFrame.Shape.NoFrame)
|
|
25
|
+
self.setCursorWidth(2)
|
|
26
|
+
self.document().setDocumentMargin(10)
|
|
27
|
+
self.number_area = LineNumberArea(self)
|
|
28
|
+
self.gutter_bg = QColor("#ffffff")
|
|
29
|
+
self.gutter_fg, self.gutter_fg_current = QColor("#a1a1a6"), QColor("#5a5a5f")
|
|
30
|
+
self.current_line_color = QColor("#f4f6fa")
|
|
31
|
+
self.blockCountChanged.connect(self.update_margin)
|
|
32
|
+
self.updateRequest.connect(self.update_numbers)
|
|
33
|
+
self.cursorPositionChanged.connect(self.highlight_current_line)
|
|
34
|
+
self.update_margin()
|
|
35
|
+
self.highlight_current_line()
|
|
36
|
+
|
|
37
|
+
def gutter_font(self):
|
|
38
|
+
font = QFont(self.font())
|
|
39
|
+
font.setPointSizeF(max(self.font().pointSizeF() - 2, 8))
|
|
40
|
+
return font
|
|
41
|
+
|
|
42
|
+
def number_area_width(self):
|
|
43
|
+
digits = max(2, len(str(max(1, self.blockCount()))))
|
|
44
|
+
return 22 + self.fontMetrics().horizontalAdvance("9") * digits
|
|
45
|
+
|
|
46
|
+
def setFont(self, font):
|
|
47
|
+
super().setFont(font)
|
|
48
|
+
self.update_margin()
|
|
49
|
+
|
|
50
|
+
def update_margin(self):
|
|
51
|
+
self.setViewportMargins(self.number_area_width(), 0, 0, 0)
|
|
52
|
+
|
|
53
|
+
def update_numbers(self, rect, dy):
|
|
54
|
+
if dy:
|
|
55
|
+
self.number_area.scroll(0, dy)
|
|
56
|
+
else:
|
|
57
|
+
self.number_area.update(0, rect.y(), self.number_area.width(), rect.height())
|
|
58
|
+
if rect.contains(self.viewport().rect()):
|
|
59
|
+
self.update_margin()
|
|
60
|
+
|
|
61
|
+
def resizeEvent(self, event):
|
|
62
|
+
super().resizeEvent(event)
|
|
63
|
+
cr = self.contentsRect()
|
|
64
|
+
self.number_area.setGeometry(QRect(cr.left(), cr.top(), self.number_area_width(), cr.height()))
|
|
65
|
+
|
|
66
|
+
def set_colors(self, theme):
|
|
67
|
+
"""Applique les couleurs du thème : fond et texte via la palette, le reste en direct."""
|
|
68
|
+
palette = self.palette()
|
|
69
|
+
palette.setColor(QPalette.ColorRole.Base, QColor(theme["editor_bg"]))
|
|
70
|
+
palette.setColor(QPalette.ColorRole.Text, QColor(theme["editor_fg"]))
|
|
71
|
+
self.setPalette(palette)
|
|
72
|
+
self.gutter_bg = QColor(theme["editor_bg"])
|
|
73
|
+
self.gutter_fg = QColor(theme["gutter_fg"])
|
|
74
|
+
self.gutter_fg_current = QColor(theme["gutter_fg_current"])
|
|
75
|
+
self.current_line_color = QColor(theme["current_line"])
|
|
76
|
+
self.highlight_current_line()
|
|
77
|
+
self.number_area.update()
|
|
78
|
+
|
|
79
|
+
def highlight_current_line(self):
|
|
80
|
+
selection = QTextEdit.ExtraSelection()
|
|
81
|
+
selection.format.setBackground(self.current_line_color)
|
|
82
|
+
selection.format.setProperty(QTextFormat.Property.FullWidthSelection, True)
|
|
83
|
+
selection.cursor = self.textCursor()
|
|
84
|
+
selection.cursor.clearSelection()
|
|
85
|
+
self.setExtraSelections([] if self.textCursor().hasSelection() else [selection])
|
|
86
|
+
self.number_area.update()
|
|
87
|
+
|
|
88
|
+
def paint_numbers(self, event):
|
|
89
|
+
painter = QPainter(self.number_area)
|
|
90
|
+
painter.fillRect(event.rect(), self.gutter_bg)
|
|
91
|
+
painter.setFont(self.gutter_font())
|
|
92
|
+
current = self.textCursor().blockNumber()
|
|
93
|
+
block = self.firstVisibleBlock()
|
|
94
|
+
top = round(self.blockBoundingGeometry(block).translated(self.contentOffset()).top())
|
|
95
|
+
while block.isValid() and top <= event.rect().bottom():
|
|
96
|
+
height = round(self.blockBoundingRect(block).height())
|
|
97
|
+
if block.isVisible() and top + height >= event.rect().top():
|
|
98
|
+
number = block.blockNumber()
|
|
99
|
+
painter.setPen(self.gutter_fg_current if number == current else self.gutter_fg)
|
|
100
|
+
painter.drawText(0, top, self.number_area.width() - 10, height,
|
|
101
|
+
Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter,
|
|
102
|
+
str(number + 1))
|
|
103
|
+
block = block.next()
|
|
104
|
+
top += height
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Constantes partagées."""
|
|
2
|
+
|
|
3
|
+
TEMPLATE = """% Exemple : un client passe des commandes (les lignes consécutives forment une rangée,
|
|
4
|
+
% une ligne vide commence une nouvelle rangée)
|
|
5
|
+
CLIENT: Réf. client, Nom, Prénom, Ville
|
|
6
|
+
PASSER, 0N CLIENT, 11 COMMANDE
|
|
7
|
+
COMMANDE: Num. commande, Date, Montant
|
|
8
|
+
CONTENIR, 1N COMMANDE, 0N PRODUIT: Quantité
|
|
9
|
+
PRODUIT: Réf. produit, Libellé, Prix unitaire
|
|
10
|
+
"""
|
|
11
|
+
APP_NAME = "MocodoEditor"
|
|
12
|
+
BLANK_SVG = b'<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1"/>'
|
|
13
|
+
MAX_RECENT = 8
|
|
14
|
+
FILTER = "Fichiers Mocodo (*.mcd);;Tous les fichiers (*)"
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Impression et exports (PNG, SVG) du dernier diagramme rendu par la fenêtre principale."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from PyQt6.QtCore import QByteArray, QMarginsF, QRectF, QSizeF, Qt
|
|
5
|
+
from PyQt6.QtGui import QImage, QPageLayout, QPageSize, QPainter, QPdfWriter
|
|
6
|
+
from PyQt6.QtPrintSupport import QPrintDialog, QPrinter
|
|
7
|
+
from PyQt6.QtSvg import QSvgRenderer
|
|
8
|
+
from PyQt6.QtWidgets import QDialog, QFileDialog, QMessageBox
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def print_diagram(win):
|
|
13
|
+
renderer = valid_renderer(win, "Impression impossible")
|
|
14
|
+
if not renderer:
|
|
15
|
+
return
|
|
16
|
+
printer = QPrinter(QPrinter.PrinterMode.HighResolution)
|
|
17
|
+
if QPrintDialog(printer, win).exec() == QDialog.DialogCode.Accepted:
|
|
18
|
+
paint_to_printer(renderer, printer)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def paint_to_printer(renderer, printer):
|
|
22
|
+
"""Dessine le SVG en haut de la page, à sa taille réelle (96 px = 1 pouce),
|
|
23
|
+
réduit si nécessaire pour tenir dans la zone imprimable."""
|
|
24
|
+
page = printer.pageRect(QPrinter.Unit.DevicePixel)
|
|
25
|
+
size = renderer.defaultSize()
|
|
26
|
+
scale = printer.resolution() / 96
|
|
27
|
+
scale = min(scale, page.width() / size.width(), page.height() / size.height())
|
|
28
|
+
w, h = size.width() * scale, size.height() * scale
|
|
29
|
+
painter = QPainter(printer)
|
|
30
|
+
renderer.render(painter, QRectF(page.x() + (page.width() - w) / 2, page.y(), w, h))
|
|
31
|
+
painter.end()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def valid_renderer(win, title):
|
|
35
|
+
if not win.last_svg:
|
|
36
|
+
QMessageBox.warning(win, title, "Aucun MCD n'a encore été rendu correctement.")
|
|
37
|
+
return None
|
|
38
|
+
renderer = QSvgRenderer(QByteArray(win.last_svg))
|
|
39
|
+
size = renderer.defaultSize()
|
|
40
|
+
if not renderer.isValid() or not size.isValid() or size.isEmpty():
|
|
41
|
+
QMessageBox.warning(win, title, "Le MCD rendu est invalide ou sans dimensions.")
|
|
42
|
+
return None
|
|
43
|
+
return renderer
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def export_png(win):
|
|
47
|
+
renderer = valid_renderer(win, "Export impossible")
|
|
48
|
+
if not renderer:
|
|
49
|
+
return
|
|
50
|
+
size = renderer.defaultSize()
|
|
51
|
+
default = str((win.path or Path("mcd")).with_suffix(".png"))
|
|
52
|
+
name, _ = QFileDialog.getSaveFileName(
|
|
53
|
+
win, "Exporter en PNG", default, "Images PNG (*.png)")
|
|
54
|
+
if not name:
|
|
55
|
+
return
|
|
56
|
+
if not Path(name).suffix:
|
|
57
|
+
name += ".png"
|
|
58
|
+
image = QImage(size, QImage.Format.Format_ARGB32)
|
|
59
|
+
image.fill(Qt.GlobalColor.transparent)
|
|
60
|
+
painter = QPainter(image)
|
|
61
|
+
renderer.render(painter)
|
|
62
|
+
painter.end()
|
|
63
|
+
if image.save(name, "PNG"):
|
|
64
|
+
win.statusBar().showMessage(f"Exporté : {name} ({size.width()}×{size.height()})", 5000)
|
|
65
|
+
else:
|
|
66
|
+
QMessageBox.critical(win, "Erreur", f"Écriture impossible :\n{name}")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def export_svg(win):
|
|
70
|
+
if not win.last_svg:
|
|
71
|
+
QMessageBox.warning(win, "Export impossible", "Aucun MCD n'a encore été rendu correctement.")
|
|
72
|
+
return
|
|
73
|
+
default = str((win.path or Path("mcd")).with_suffix(".svg"))
|
|
74
|
+
name, _ = QFileDialog.getSaveFileName(win, "Exporter en SVG", default, "Images SVG (*.svg)")
|
|
75
|
+
if not name:
|
|
76
|
+
return
|
|
77
|
+
if not Path(name).suffix:
|
|
78
|
+
name += ".svg"
|
|
79
|
+
try:
|
|
80
|
+
Path(name).write_bytes(win.last_svg)
|
|
81
|
+
except OSError as e:
|
|
82
|
+
QMessageBox.critical(win, "Erreur", f"Écriture impossible :\n{e}")
|
|
83
|
+
return
|
|
84
|
+
win.statusBar().showMessage(f"Exporté : {name}", 5000)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def export_pdf(win):
|
|
88
|
+
"""PDF vectoriel, à la taille du MCD (une page aux dimensions du dessin, sans marge)."""
|
|
89
|
+
renderer = valid_renderer(win, "Export impossible")
|
|
90
|
+
if not renderer:
|
|
91
|
+
return
|
|
92
|
+
default = str((win.path or Path("mcd")).with_suffix(".pdf"))
|
|
93
|
+
name, _ = QFileDialog.getSaveFileName(win, "Exporter en PDF", default, "Documents PDF (*.pdf)")
|
|
94
|
+
if not name:
|
|
95
|
+
return
|
|
96
|
+
if not Path(name).suffix:
|
|
97
|
+
name += ".pdf"
|
|
98
|
+
size = renderer.defaultSize()
|
|
99
|
+
writer = QPdfWriter(name)
|
|
100
|
+
writer.setResolution(96)
|
|
101
|
+
writer.setPageLayout(QPageLayout(QPageSize(QSizeF(size.width(), size.height()), QPageSize.Unit.Point),
|
|
102
|
+
QPageLayout.Orientation.Portrait, QMarginsF(0, 0, 0, 0)))
|
|
103
|
+
painter = QPainter(writer)
|
|
104
|
+
renderer.render(painter, QRectF(0, 0, writer.width(), writer.height()))
|
|
105
|
+
painter.end()
|
|
106
|
+
win.statusBar().showMessage(f"Exporté : {name}", 5000)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Ouverture d'un résultat dans une autre application de la même famille (PUMLEditor, SVGEditor)."""
|
|
2
|
+
import subprocess
|
|
3
|
+
import tempfile
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
# extension du résultat → (nom de l'application macOS, libellé du bouton)
|
|
7
|
+
EDITORS = {
|
|
8
|
+
".puml": ("PUMLEditor", "Ouvrir dans PUMLEditor"),
|
|
9
|
+
".svg": ("SVGEditor", "Ouvrir dans SVGEditor"),
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def open_in_editor(ext: str, content: str | bytes, stem: str = "mcd") -> str | None:
|
|
14
|
+
"""Écrit le résultat dans un fichier temporaire (`<stem><ext>`) et l'ouvre avec l'application associée à
|
|
15
|
+
l'extension. Retourne un message d'erreur, ou None si l'ouverture a été demandée."""
|
|
16
|
+
if ext not in EDITORS:
|
|
17
|
+
return f"Aucune application associée à « {ext} »."
|
|
18
|
+
app = EDITORS[ext][0]
|
|
19
|
+
folder = Path(tempfile.gettempdir()) / "MocodoEditor"
|
|
20
|
+
try:
|
|
21
|
+
folder.mkdir(exist_ok=True)
|
|
22
|
+
target = folder / f"{stem}{ext}"
|
|
23
|
+
if isinstance(content, str):
|
|
24
|
+
target.write_text(content, encoding="utf-8")
|
|
25
|
+
else:
|
|
26
|
+
target.write_bytes(content)
|
|
27
|
+
run = subprocess.run(["open", "-a", app, str(target)], capture_output=True, text=True, timeout=20)
|
|
28
|
+
except (OSError, subprocess.TimeoutExpired) as e:
|
|
29
|
+
return f"Ouverture impossible : {e}"
|
|
30
|
+
if run.returncode != 0:
|
|
31
|
+
return (f"{app} est introuvable (l'application doit être installée, par exemple dans /Applications).\n\n"
|
|
32
|
+
f"{run.stderr.strip()}")
|
|
33
|
+
return None
|