From: pascale.noyret Date: Thu, 12 Mar 2015 14:41:49 +0000 (+0100) Subject: Formatage en Ligen X-Git-Tag: demande7818^0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=22eca2594d29642afbd06d048ad303b079619fa0;p=tools%2Feficas.git Formatage en Ligen --- diff --git a/InterfaceQT4/browser.py b/InterfaceQT4/browser.py index bc9516bd..54018b4a 100644 --- a/InterfaceQT4/browser.py +++ b/InterfaceQT4/browser.py @@ -478,7 +478,7 @@ class JDCNode(QTreeWidgetItem): Déclenche la copie de l'objet item avec pour cible l'objet passé en argument : node_selected """ - #print 'je passe dans doPaste' + print 'je passe dans doPaste' objet_a_copier = self.item.get_copie_objet() child=node_selected.doPasteCommande(objet_a_copier,pos) return child diff --git a/InterfaceQT4/editor.py b/InterfaceQT4/editor.py index 285a2bdb..33c5fb65 100644 --- a/InterfaceQT4/editor.py +++ b/InterfaceQT4/editor.py @@ -662,9 +662,9 @@ class JDCEditor(QSplitter): self.appliEficas.trUtf8('Wrapper Files (*.xml);;''All Files (*)')) return fichier - #----------------------------------# - def writeFile(self, fn, txt = None): - #----------------------------------# + #---------------------------------------------------------------# + def writeFile(self, fn, txt = None, formatLigne="beautifie"): + #---------------------------------------------------------------# """ Public slot to write the text to a file. @@ -675,7 +675,7 @@ class JDCEditor(QSplitter): fn = unicode(fn) if txt == None : - txt = self.get_text_JDC(self.format) + txt = self.get_text_JDC(self.format,formatLigne=formatLigne) eol = '\n' if len(txt) >= len(eol): if txt[-len(eol):] != eol: @@ -696,15 +696,15 @@ class JDCEditor(QSplitter): .arg(unicode(fn)).arg(str(why))) return 0 - #-------------------------------------# - def get_text_JDC(self,format,pourRun=0): - #-------------------------------------# + #---------------------------------------------------------------# + def get_text_JDC(self,format,pourRun=0,formatLigne="beautifie"): + #---------------------------------------------------------------# if self.code == "MAP" and not(generator.plugins.has_key(format)): format = "MAP" if generator.plugins.has_key(format): # Le generateur existe on l'utilise self.generator=generator.plugins[format]() try : - jdc_formate=self.generator.gener(self.jdc,format='beautifie',config=self.appliEficas.CONFIGURATION) + jdc_formate=self.generator.gener(self.jdc,format=formatLigne,config=self.appliEficas.CONFIGURATION) if pourRun : jdc_formate=self.generator.textePourRun except ValueError,e: QMessageBox.critical(self, tr("Erreur a la generation"),str(e)) @@ -981,9 +981,9 @@ class JDCEditor(QSplitter): #else : pass - #-----------------------------------------# - def saveFile(self, path = None, saveas= 0): - #-----------------------------------------# + #-------------------------------------------------------------# + def saveFile(self, path = None, saveas= 0, formatLigne="beautifie"): + #-------------------------------------------------------------# """ Public slot to save the text to a file. @@ -1017,7 +1017,7 @@ class JDCEditor(QSplitter): fn = unicode(QDir.convertSeparators(fn)) newName = fn - if not (self.writeFile(fn)): return (0, None) + if not (self.writeFile(fn,formatLigne=formatLigne)): return (0, None) self.fichier = fn self.modified = False if self.fileInfo is None or saveas: @@ -1039,8 +1039,14 @@ class JDCEditor(QSplitter): return (1, self.fichier) # #----------------------------------------------# - def saveFileAs(self, path = None,fileName=None): + def sauveLigneFile(self): #----------------------------------------------# + self.modified=1 + return self.saveFile(formatLigne="Ligne") + + #---------------------------------------------------------------# + def saveFileAs(self, path = None,fileName=None): + #---------------------------------------------------------------# """ Public slot to save a file with a new name. @@ -1052,7 +1058,7 @@ class JDCEditor(QSplitter): self.fichier = fileName self.modified=1 return self.saveFile() - return self.saveFile(path,1) + return self.saveFile(path,1,"beautifie") diff --git a/InterfaceQT4/qtEficas.py b/InterfaceQT4/qtEficas.py index d0d9e01d..70cc8b62 100644 --- a/InterfaceQT4/qtEficas.py +++ b/InterfaceQT4/qtEficas.py @@ -222,6 +222,7 @@ class Appli(Ui_Eficas,QMainWindow): self.menuOptions.addAction(self.actionLecteur_Pdf) self.menuOptions.setTitle(tr("Options")) + self.menuFichier.addAction(self.actionSauveLigne) def CARMEL3D(self): #if self.salome == 0 : return @@ -355,10 +356,13 @@ class Appli(Ui_Eficas,QMainWindow): self.actionTraduitV10V11.setObjectName("actionTraduitV10V11") self.actionTraduitV9V10.setText(tr("TraduitV9V10")) self.actionTraduitV10V11.setText(tr("TraduitV10V11")) + self.actionSauveLigne = QAction(self) + self.actionSauveLigne.setText(tr("Sauve Format Ligne")) self.connect(self.actionParametres_Eficas,SIGNAL("activated()"),self.optionEditeur) self.connect(self.actionLecteur_Pdf,SIGNAL("activated()"),self.optionPdf) self.connect(self.actionTraduitV9V10,SIGNAL("activated()"),self.traductionV9V10) self.connect(self.actionTraduitV10V11,SIGNAL("activated()"),self.traductionV10V11) + self.connect(self.actionSauveLigne,SIGNAL("activated()"),self.sauveLigne) # Pour Carmel self.actionChercheGrpMaille = QAction(self) @@ -584,6 +588,9 @@ class Appli(Ui_Eficas,QMainWindow): if msg != "": QMessageBox.warning(self, tr(u"Erreur"), msg) + def sauveLigne(self): + return self.viewmanager.sauveLigneCurrentEditor() + def fileSave(self): return self.viewmanager.saveCurrentEditor() diff --git a/InterfaceQT4/viewManager.py b/InterfaceQT4/viewManager.py index a6350a08..344cc330 100644 --- a/InterfaceQT4/viewManager.py +++ b/InterfaceQT4/viewManager.py @@ -185,6 +185,23 @@ class MyTabview: if index < 0 : return self.dict_editors[index].viewJdcPy() + def sauveLigneCurrentEditor(self): + index=self.myQtab.currentIndex() + if index < 0 : return + editor=self.dict_editors[index] + if editor in self.doubles.keys() : + QMessageBox.warning( + None, + tr("Fichier Duplique"), + tr("Le fichier ne sera pas sauvegarde."), + tr("&Annuler")) + return + ok, newName = editor.sauveLigneFile() + if ok : + fileName=os.path.basename(unicode(newName)) + self.myQtab.setTabText(index,fileName) + return ok + def saveCurrentEditor(self): index=self.myQtab.currentIndex() if index < 0 : return diff --git a/generator/Formatage.py b/generator/Formatage.py index 431345d7..d229d7ea 100644 --- a/generator/Formatage.py +++ b/generator/Formatage.py @@ -281,3 +281,28 @@ class Formatage : s=s+'\n'+texte return s + +class FormatageLigne(Formatage) : + def __init__(self,l_jdc,code=None,mode=None,sep='=',l_max="**"): + Formatage.__init__(self,l_jdc,code=None,mode=None,sep='=',l_max="**") + + def formate_jdc(self): + texte1=Formatage.formate_jdc(self) + newText="" + lignes=texte1.split("\n") + texte="" + pattern_debut_blanc = re.compile(r"^ \s*.*") + pattern_commentaire = re.compile(r"^\s*#.*") + pattern_vide=re.compile(r"\s*^$") + for l in lignes : + if pattern_commentaire.match(l) or pattern_vide.match(l): + newText+=l+"\n" + continue + if not pattern_debut_blanc.match(l) : texte=l + else : texte+=re.sub(r'^ \s*',' ',l) + if texte[-1]==";" : + newText+=texte+"\n" + texte="" + return newText + + diff --git a/generator/generator_python.py b/generator/generator_python.py index 74a00a27..10ebc590 100644 --- a/generator/generator_python.py +++ b/generator/generator_python.py @@ -30,8 +30,12 @@ from Noyau.N_utils import repr_float import Accas import Extensions from Extensions.parametre import ITEM_PARAMETRE -from Formatage import Formatage +from Formatage import Formatage +from Formatage import FormatageLigne from Extensions.param2 import Formula +from Extensions.eficas_exception import EficasException +from Extensions.i18n import tr + def entryPoint(): """ @@ -92,6 +96,7 @@ class PythonGenerator: """ self.appli=obj.get_jdc_root().appli #self.appli=obj.appli + print format liste= self.generator(obj) if format == 'brut': self.text=liste @@ -100,8 +105,11 @@ class PythonGenerator: elif format == 'beautifie': jdc_formate = Formatage(liste,mode='.py') self.text=jdc_formate.formate_jdc() + elif format == 'Ligne': + jdc_formate = FormatageLigne(liste,mode='.py') + self.text=jdc_formate.formate_jdc() else: - raise "Format pas implemente : "+format + raise EficasException(tr("Format non implemente ") +format) return self.text def generator(self,obj): @@ -152,7 +160,7 @@ class PythonGenerator: elif isinstance(obj,Formula): return self.generFormula(obj) else: - raise "Type d'objet non prevu",obj + raise EficasException(tr("Type d'objet non prevu") +obj) def generJDC(self,obj): """