X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=InterfaceQT4%2Fbrowser.py;h=35d45b08b2fdb8b9c6920dbc01c8d8a65324a230;hb=38922a3cfdcc76f6983b987de74706c54f562168;hp=7761a6c373863c9713df5f8c11b2bcfa0a6a264c;hpb=3738234cffc29643bbfffde64a15ef9231e4ed7d;p=tools%2Feficas.git diff --git a/InterfaceQT4/browser.py b/InterfaceQT4/browser.py index 7761a6c3..35d45b08 100644 --- a/InterfaceQT4/browser.py +++ b/InterfaceQT4/browser.py @@ -18,17 +18,26 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -import string,re +from __future__ import absolute_import +from __future__ import print_function +try : + from builtins import str + from builtins import range +except : pass +import re import types,sys,os import traceback -import typeNode -import pdb -from PyQt4 import * -from PyQt4.QtGui import * -from PyQt4.QtCore import * +from . import typeNode +#import pdb + +import six +from six.moves import range +from PyQt5.QtWidgets import QTreeWidget , QTreeWidgetItem, QApplication, QMessageBox +from PyQt5.QtGui import QIcon +from PyQt5.QtCore import Qt from Extensions.i18n import tr -from gereRegles import GereRegles -from monChoixCommande import MonChoixCommande +from .gereRegles import GereRegles +from .monChoixCommande import MonChoixCommande class JDCTree( QTreeWidget,GereRegles ): def __init__( self, jdc_item, QWParent): @@ -56,9 +65,9 @@ class JDCTree( QTreeWidget,GereRegles ): self.itemCourrant=None - self.connect(self, SIGNAL("itemClicked ( QTreeWidgetItem * ,int) "), self.handleOnItem) - self.connect(self, SIGNAL("itemCollapsed ( QTreeWidgetItem *) "), self.handleCollapsedItem) - self.connect(self, SIGNAL("itemExpanded ( QTreeWidgetItem *) "), self.handleExpandedItem) + self.itemClicked.connect(self.handleOnItem) + self.itemCollapsed.connect(self.handleCollapsedItem) + self.itemExpanded.connect(self.handleExpandedItem) #PNPNPN verifier dans quel cas on se trouve : affiche l arbre ou la commande self.node_selected=self.racine @@ -67,14 +76,14 @@ class JDCTree( QTreeWidget,GereRegles ): self.inhibeExpand=False #print "self.editor.afficheCommandesPliees", self.editor.afficheCommandesPliees if self.racine.children !=[] : - - + #self.editor.initSplitterSizes(3) if self.editor.afficheCommandesPliees : self.racine.children[0].plieToutEtReaffiche() else : self.racine.children[0].deplieToutEtReaffiche() - - self.racine.children[0].fenetre.donnePremier() - else : self.racine.affichePanneau() + else : + #self.editor.initSplitterSizes(2) + self.racine.affichePanneau() + #print self.editor.splitter.sizes() #PNPNPN #pdb.set_trace() @@ -121,44 +130,59 @@ class JDCTree( QTreeWidget,GereRegles ): def handleExpandedItem(self,item): #print "handleExpandedItem pour ", item.item.nom, self.inhibeExpand + #import traceback + #traceback.print_stack() if self.inhibeExpand == True : return + self.inhibeExpand = True itemParent=item while not (hasattr (itemParent,'getPanel')) : if itemParent.plie==True : itemParent.setDeplie() itemParent=itemParent.treeParent if self.tree.node_selected != itemParent : item.setExpanded(True) + self.inhibeExpand = False return item.deplieToutEtReaffiche() + self.inhibeExpand = False def handleOnItem(self,item,int): #print "je passe dans handleOnItem pour ",self, item.item.nom, item, item.item - self.inhibeExpand == True + + from InterfaceQT4 import composimp + self.inhibeExpand = True self.itemCourrant=item itemParent=item + while not (hasattr (itemParent,'getPanel')) : if itemParent.plie==True : itemParent.setDeplie() itemParent=itemParent.treeParent + if itemParent.fenetre != self.editor.fenetreCentraleAffichee : + + estUneFeuille=(isinstance(item,composimp.Node)) # il faut afficher le parent - if self.editor.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item) - else : itemParent.affichePanneau() + #print "estUneFeuille", estUneFeuille + #print "afficheCommandesPliees", self.editor.afficheCommandesPliees + if estUneFeuille : itemParent.affichePanneau() + elif self.editor.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item) + else : itemParent.affichePanneau() - from InterfaceQT4 import composimp - if (isinstance(item,composimp.Node)) : item.fenetre.rendVisible() + elif (isinstance(item,composimp.Node)) and item.fenetre : item.fenetre.rendVisible() elif itemParent!=item: - #self.tree.handleExpandedItem(item) + self.tree.handleExpandedItem(item) #item.fenetre.donnePremier() - print 'il faut afficher le 1er' + #item.fenetre.rendActif() + #print 'il faut afficher le 1er' + try : fr = item.item.get_fr() - if self.editor: self.editor.labelCommentaire.setText(unicode(fr)) + if self.editor: self.editor.affiche_commentaire(six.text_type(fr)) except: pass item.select() - self.inhibeExpand == False + self.inhibeExpand = False #print "je mets inhibeExpand a false handleOnItem" @@ -183,27 +207,30 @@ class JDCNode(QTreeWidgetItem,GereRegles): self.appliEficas = treeParent.appliEficas self.JESUISOFF=0 self.childrenComplete=[] + from InterfaceQT4 import compocomm from InterfaceQT4 import compoparam from InterfaceQT4 import composimp if (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire") - elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=self.appliEficas.trUtf8(str(item.GetLabelText()[0])) - else: name = self.appliEficas.trUtf8(str(tr( item.nom))+" :") - value = self.appliEficas.trUtf8(str( item.GetText() ) ) + elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=tr(str(item.GetLabelText()[0])) + else: name = tr(str(tr( item.nom))+" :") + value = tr(str( item.GetText() ) ) - mesColonnes=QStringList() - if self.editor.enteteQTree=='complet': mesColonnes << name << value - else : mesColonnes << name + if self.editor.enteteQTree=='complet':mesColonnes=(name,value) + else : mesColonnes=(name,) if self.treeParent.plie==True : self.plie = True self.appartientAUnNoeudPlie=True + if self.treeParent.item.isMCList() : self.appartientAUnNoeudPlie = self.treeParent.appartientAUnNoeudPlie else : self.plie = False self.appartientAUnNoeudPlie = False + #if item.nom == "POUTRE" :print "creation d'un noeud : ", item, " ",item.nom,"", self.treeParent, self.appartientAUnNoeudPlie , self.plie + if ancien and itemExpand : self.plie = False if ancien and not itemExpand : self.plie = True if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False @@ -217,15 +244,18 @@ class JDCNode(QTreeWidgetItem,GereRegles): self.treeParent.childrenComplete.append(self) self.treeParent=self.treeParent.vraiParent self.treeParent.childrenComplete.append(self) - if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : + + + if (isinstance(self,compobloc.Node) or (isinstance(self,compomclist.Node) and self.item.isMCList()) or ( hasattr(self.item.parent,'inhibeValidator') and isinstance(self,compomclist.Node) and self.item.parent.inhibeValidator)) : + # Le dernier or ne sert que lorsqu'on est en train de creer une liste par les validator QTreeWidgetItem.__init__(self,None,mesColonnes) else : QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes) - self.setToolTip(0,QString(self.item.get_fr())) - self.setToolTip(1,QString(self.item.get_fr())) + self.setToolTip(0,self.item.get_fr()) + self.setToolTip(1,self.item.get_fr()) + repIcon=self.appliEficas.repIcon - repIcon=QString(self.appliEficas.repIcon) monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png") self.setIcon(0,monIcone) @@ -261,7 +291,6 @@ class JDCNode(QTreeWidgetItem,GereRegles): else : self.listeItemExpanded.append(enfant.item) for enfant in self.childrenComplete : - p=enfant.vraiParent parent=enfant.treeParent parent.removeChild(enfant) enfant.JESUISOFF=1 @@ -280,7 +309,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): nouvelItem=item.itemNode(self,item,itemExpand,ancien) self.children.append(nouvelItem) - #print "fin *********** build_children ",self,self.item, self.item.nom + #print "fin *********** build_children ",self,self.item, self.item.nom, self.children def chercheNoeudCorrespondant(self,objSimp): @@ -291,17 +320,21 @@ class JDCNode(QTreeWidgetItem,GereRegles): def affichePanneau(self) : - #print " affichePanneau " , self.item.nom - if self.item.isactif(): + #if self.editor.code == 'ASTER' and not(self.item.isactif()) : + # posera des pb si un code decide d appeler FIN un mot clef + # on resoudera a ce moment la + # pour l instant pas de poussiere sous le tapis + if not(self.item.isactif()) : + from .monWidgetInactif import MonWidgetInactif + self.fenetre = MonWidgetInactif(self,self.editor) + else: itemParent=self while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent if itemParent!=self : itemParent.affichePanneau() return self.fenetre=self.getPanel() - else: - from monInactifPanel import PanelInactif - self.fenetre = PanelInactif(self,self.editor) + #self.editor.restoreSplitterSizes() for indiceWidget in range(self.editor.widgetCentraleLayout.count()): widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget) @@ -309,21 +342,20 @@ class JDCNode(QTreeWidgetItem,GereRegles): # ceinture et bretelle #print 'old fenetre = ',self.editor.fenetreCentraleAffichee if self.editor.fenetreCentraleAffichee != None : - #print "j enleve ", self.editor.fenetreCentraleAffichee, self.editor.fenetreCentraleAffichee.node.item.nom self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee) + self.editor.fenetreCentraleAffichee.setParent(None) self.editor.fenetreCentraleAffichee.close() + self.editor.fenetreCentraleAffichee.deleteLater() self.editor.widgetCentraleLayout.addWidget(self.fenetre) - #print "j ajoute ", self.fenetre, self.fenetre.node.item.nom + #print ("j ajoute ", self.fenetre, self.fenetre.node.item.nom) self.editor.fenetreCentraleAffichee=self.fenetre self.tree.node_selected= self if self.editor.first : - self.editor.splitter.setSizes((400,1400,400)) if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False self.tree.inhibeExpand=True self.tree.expandItem(self) - self.select() self.tree.inhibeExpand=False #print "fin de affichePanneau", self.item.nom #print "______________________________" @@ -337,7 +369,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): """ Cette methode a pour but de commentariser la commande pointee par self """ - # On traite par une exception le cas ou l'utilisateur final cherche a désactiver + # On traite par une exception le cas ou l'utilisateur final cherche a desactiver # (commentariser) un commentaire. try : pos=self.treeParent.children.index(self) @@ -347,7 +379,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): self.treeParent.build_children() self.treeParent.children[pos].select() self.treeParent.children[pos].affichePanneau() - except Exception,e: + except Exception as e: traceback.print_exc() QMessageBox.critical( self.editor, "TOO BAD",str(e)) @@ -362,7 +394,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): self.treeParent.build_children() self.treeParent.children[pos].select() self.treeParent.children[pos].affichePanneau() - except Exception,e: + except Exception as e: QMessageBox.critical( self.editor, "Erreur !",str(e)) def addComment( self, after=True ): @@ -392,9 +424,9 @@ class JDCNode(QTreeWidgetItem,GereRegles): Rend le noeud courant (self) selectionne et deselectionne tous les autres """ + #print "select pour", self.item.nom for item in self.tree.selectedItems() : item.setSelected(0) - self.setSelected( True ) self.tree.setCurrentItem( self ) #------------------------------------------------------------------ @@ -412,13 +444,19 @@ class JDCNode(QTreeWidgetItem,GereRegles): from InterfaceQT4 import compojdc if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos) : return 0 - index = self.treeParent.children.index(self) - if pos == 'before': index = index - elif pos == 'after': index = index +1 - else: - print unicode(pos), tr(" n'est pas un index valide pour append_brother") - return 0 - return self.treeParent.append_child(name,pos=index,plier=plier) + if self.treeParent != self.vraiParent : + index = self.vraiParent.children.index(self) + if pos == 'before': index = index + elif pos == 'after': index = index +1 + return self.vraiParent.append_child(name,pos=index,plier=plier) + else : + index = self.treeParent.children.index(self) + if pos == 'before': index = index + elif pos == 'after': index = index +1 + else: + print(six.text_type(pos), tr(" n'est pas un index valide pour append_brother")) + return 0 + return self.treeParent.append_child(name,pos=index,plier=plier) def verifiePosition(self,name,pos,aLaRacine=False): if name not in self.editor.Classement_Commandes_Ds_Arbre : return True @@ -464,7 +502,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): index = 0 elif pos == 'last': index = len(self.children) - elif type(pos) == types.IntType : + elif type(pos) == int : # position fixee index = pos elif type(pos) == types.InstanceType: @@ -481,7 +519,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): if not verifiePosition : return 0 self.tree.inhibeExpand=True - obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add' + obj=self.item.additem(name,index) # emet le signal 'add' if obj is None:obj=0 if obj == 0:return 0 try : @@ -491,7 +529,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): except : child=self.children[index] self.tree.inhibeExpand=False - #print " fin append child" + #print (" fin append child") return child def deplace(self): @@ -520,6 +558,12 @@ class JDCNode(QTreeWidgetItem,GereRegles): if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index] else: toselect=self.treeParent if recalcule : jdc.recalcule_etat_correlation() + if ret==0 : + if self.treeParent.childrenComplete : + notdeleted=self.treeParent.childrenComplete[index+1] + notdeleted.select() + else : + toselect.select() from InterfaceQT4 import compojdc # cas ou on detruit dans l arbre sans affichage if isinstance(self.treeParent,compojdc.Node) : @@ -547,7 +591,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud) if index < 0 : index =0 - # Cas ou on détruit dans une ETape + # Cas ou on detruit dans une ETape if index == 9999 : parentPosition=self.treeParent while not(isinstance(parentPosition, compojdc.Node)): @@ -568,7 +612,14 @@ class JDCNode(QTreeWidgetItem,GereRegles): def onValid(self): #print "onValid pour ", self.item.nom - if hasattr(self,'fenetre') and self.fenetre: self.fenetre.setValide() + if self.JESUISOFF==1 : return + if hasattr(self,'fenetre') and self.fenetre: + try : + self.fenetre.setValide() + except : + # print "onValid pour ", self.item.nom, self,'pb' + pass + if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid(): self.item.jdc.recalcule_etat_correlation() if hasattr(self.item,'forceRecalcul'): @@ -597,29 +648,27 @@ class JDCNode(QTreeWidgetItem,GereRegles): - def update_node_valid(self): """Cette methode remet a jour la validite du noeud (icone) Elle appelle isvalid """ - repIcon=QString(self.appliEficas.repIcon) + repIcon=self.appliEficas.repIcon monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png") self.setIcon(0,monIcone) def update_node_label(self): """ Met a jour le label du noeud """ + pass #print "NODE update_node_label", self.item.GetLabelText() - labeltext,fonte,couleur = self.item.GetLabelText() + #labeltext,fonte,couleur = self.item.GetLabelText() # PNPN a reflechir #self.setText(0, labeltext) def update_node_label_in_blue(self): - if hasattr(self.appliEficas,'noeudColore'): - self.appliEficas.noeudColore.setTextColor( 0,Qt.black) - self.appliEficas.noeudColore.update_node_label() - self.setTextColor( 0,Qt.blue ) + if hasattr(self.appliEficas,'noeudColore'): self.appliEficas.noeudColore.setForeground(0,Qt.black) + self.setForeground(0,Qt.blue) labeltext,fonte,couleur = self.item.GetLabelText() self.setText(0, labeltext) self.appliEficas.noeudColore=self @@ -691,8 +740,8 @@ class JDCNode(QTreeWidgetItem,GereRegles): def doPaste(self,node_selected,pos='after'): """ - Déclenche la copie de l'objet item avec pour cible - l'objet passé en argument : node_selected + Declenche la copie de l'objet item avec pour cible + l'objet passe en argument : node_selected """ #print 'je passe dans doPaste' objet_a_copier = self.item.get_copie_objet() @@ -701,11 +750,12 @@ class JDCNode(QTreeWidgetItem,GereRegles): def doPasteCommande(self,objet_a_copier,pos='after'): """ - Réalise la copie de l'objet passé en argument qui est nécessairement + Realise la copie de l'objet passe en argument qui est necessairement une commande """ child=None try : + #if 1 : child = self.append_brother(objet_a_copier,pos) except : pass @@ -713,7 +763,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): def doPastePremier(self,objet_a_copier): """ - Réalise la copie de l'objet passé en argument (objet_a_copier) + Realise la copie de l'objet passe en argument (objet_a_copier) """ objet = objet_a_copier.item.get_copie_objet() child = self.append_child(objet,pos='first') @@ -721,6 +771,12 @@ class JDCNode(QTreeWidgetItem,GereRegles): def plieToutEtReafficheSaufItem(self, itemADeplier): #print "je suis dans plieToutEtReaffiche", self.item.get_nom() + self.inhibeExpand=True + from InterfaceQT4 import compojdc + if (isinstance(self, compojdc.Node)) : + self.affichePanneau() + self.inhibeExpand=False + return self.editor.deplier = False for item in self.children : # il ne faut pas plier les blocs @@ -728,13 +784,14 @@ class JDCNode(QTreeWidgetItem,GereRegles): if (isinstance(item,compobloc.Node)) : continue item.setPlie() if item==itemADeplier : - print itemADeplier.item.nom itemADeplier.setDeplie() - self.affichePanneau() + self.inhibeExpand=False def plieToutEtReaffiche(self): - #print "je suis dans plieToutEtReaffiche", self.item.get_nom() + from InterfaceQT4 import compojdc + if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return + self.inhibeExpand=True self.editor.deplier = False for item in self.children : # il ne faut pas plier les blocs @@ -752,7 +809,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): def setPlie(self): #print "je mets inhibeExpand a true dans setPlie" #print "je suis dans plieTout", self.item.get_nom() - import compojdc + from . import compojdc if self.fenetre == self.editor.fenetreCentraleAffichee and isinstance(self.treeParent,compojdc.Node): return self.tree.inhibeExpand=True @@ -788,6 +845,7 @@ class JDCNode(QTreeWidgetItem,GereRegles): niveauPere=niveauPere.treeParent for c in self.children : c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie + #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0], "mis a la valeur ", niveauPere.appartientAUnNoeudPlie c.setExpanded(False) # on affiche un niveau de plus @@ -829,7 +887,9 @@ class JDCNode(QTreeWidgetItem,GereRegles): if i.item.object== cherche : node=i break - if node : node.affichePanneau() + if node : + node.affichePanneau() + node.select() def selectApres(self): i=self.item.jdc.etapes.index(self.item.object) @@ -842,4 +902,16 @@ class JDCNode(QTreeWidgetItem,GereRegles): if i.item.object== cherche : node=i break - if node : node.affichePanneau() + if node : + node.affichePanneau() + node.select() + + def ouvreLesNoeudsDsLArbre(self): + return + self.inhibeExpand = True + for i in range(self.childCount()): + self.child(i).inhibeExpand=True + self.child(i).setExpanded(True) + self.child(i).ouvreLesNoeudsDsLArbre() + self.child(i).inhibeExpand=False + self.inhibeExpand = False