Debian Codegraph @

wxgeometrie/API/macros_construction.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 ##--------------------------------------#######
4 # Macros de construction #
5 ##--------------------------------------#######
6 # WxGeometrie
7 # Dynamic geometry, graph plotter, and more for french mathematic teachers.
8 # Copyright (C) 2005-2013 Nicolas Pourcelot
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24
25 import re
26 from .sauvegarde import FichierGEO
27
28
29
30
31 class Macro_construction(object):
32 """Lecteur de macros.
33
34 Lit et interprète le fichier de macro de construction.
35 """
36
37 def __init__(self, nom = None):
38 self.nom = nom
39 self.fichier = FichierGEO(type = "Macro de construction WxGeometrie", nom = nom or "")
40 self.figure = ""
41 pass
42
43 def ouvrir(self, path):
44 self.fichier.ouvrir(path)
45 if "Figure" in self.fichier:
46 self.figure = self.fichier.contenu["Figure"][0] # code python correspondant à la figure
47 else:
48 self.figure = ""
49
50 if "Parametres_macro" in self.fichier:
51 self.parametres = self.fichier.contenu["Parametres_macro"][0]
52 # self.nom = self.parametres["nom"][0].strip()
53 self.arguments = self.parametres["arguments"][0].strip().split(",") # arguments de la macro (ex: 3 points pour un triangle)
54 # self.decoration = self.parametres["decoration"][0].strip().split(",") # éléments ne devant pas être construits (texte de commentaire par exemple).
55
56 else: # par défaut, les arguments sont tous les points libres
57 self.arguments = []
58 for ligne in self.figure.split("\n"):
59 re_match = re.match("[A-Za-z_][A-Za-z0-9_]*[ ]*=[ ]*Point(", ligne)
60 if re_match:
61 self.arguments.append(re_match.group().split("=")[0].strip()) # on rajoute le nom du point
62 # self.decoration = ()
63
64
65 def enregistrer(self, path):
66 pass
67
68
69 # self.ouvrir(fichier)
70
71 # def ouvrir(self, path):
72 # pass