mesLabels << self.trUtf8('Commande ') << self.trUtf8('Concept/Valeur ')
self.setHeaderLabels(mesLabels)
- self.setMinimumSize(QSize(400,500))
- #self.connect(self,SIGNAL('contextMenuRequested(QListWidgetItem *, const QPoint &, int)'),
- # self.handleContextMenu)
+ self.setMinimumSize(QSize(600,500))
+ self.setColumnWidth(0,300)
self.connect(self, SIGNAL("itemClicked ( QTreeWidgetItem * ,int) "), self.handleOnItem)
self.racine=self.item.itemNode(self,self.item)
self.node_selected=self.racine
self.racine.affichePanneau()
-# def handleContextMenu(self,itm,coord,col):
-# """
-# Private slot to show the context menu of the listview.
-#
-# @param itm the selected listview item (QListWidgetItem)
-# @param coord the position of the mouse pointer (QPoint)
-# @param col the column of the mouse pointer (int)
-# """
-# try:
-# if itm.menu:
-# itm.menu.popup(coord)
-# except:
-# pass
-#
+
+ def contextMenuEvent(self,event) :
+ print "contextMenuEvent"
+ coord=event.globalPos()
+ item= self.currentItem()
+ self.handleContextMenu(item,coord)
+
+ def handleContextMenu(self,item,coord):
+ """
+ Private slot to show the context menu of the listview.
+
+ @param itm the selected listview item (QListWidgetItem)
+ @param coord the position of the mouse pointer (QPoint)
+ Attention : existeMenu permet de savoir si un menu est associe a cet item
+ """
+ if item.existeMenu == 0 : return
+ if item.menu == None:
+ item.createPopUpMenu()
+ if item.menu != None:
+ item.menu.exec_(coord)
+
def handleOnItem(self,item,int):
item.affichePanneau()
try :
self.QWParent.affiche_infos(fr)
except:
pass
-#
-#
-# def supprime(self):
-# """ supprime tous les elements de l'arbre """
-# raise RuntimeError, 'Not implemented'
-# self.tree = None
-# self.racine = None
-# self.node_selected = None
-# self.item = None
-# self.scrolledcanvas = None
-# for child in self.children:
-# child.supprime()
-# self.children=[]
-#
-# def showEvent(self, event):
-# """ QT : pour afficher le 1er niveau d'arborescence de l''arbre"""
-# self.children[0].select()
-#
-# def update(self):
-# """ Update tous les elements de l'arbre """
-# for child in self.children:
-# child.update()
-#
-## type de noeud
-#COMMENT = "COMMENTAIRE"
-#PARAMETERS = "PARAMETRE"
-#
-#
+
+
+# type de noeud
+COMMENT = "COMMENTAIRE"
+PARAMETERS = "PARAMETRE"
+
class JDCNode(QTreeWidgetItem):
def __init__( self, treeParent, item):
self.item = item
self.setIcon(0,monIcone)
self.children = []
self.build_children()
+ self.menu=None
+ self.existeMenu=1
def build_children(self):
""" Construit la liste des enfants de self """
self.select()
+ def createPopUpMenu(self):
+ #implemente dans les noeuds derives si necessaire
+ self.existeMenu = 0
-# def paintCell(self, p, cg, column, width, alignment):
-# """
-# Overwritten class to set a different text color, if bold is true.
-#
-# @param p the painter (QPainter)
-# @param cg the color group (QColorGroup)
-# @param column the column (int)
-# @param width width of the cell (int)
-# @param alignment alignment of the cell (int)
-# """
-# _cg = QColorGroup(cg)
-# c = _cg.text()
-#
-# if self.bold and column == 0:
-# _cg.setColor(QColorGroup.Text, Qt.red)
-#
-# QListWidgetItem.paintCell(self, p, _cg, column, width, alignment)
-#
-# _cg.setColor(QColorGroup.Text, c)
-#
-#
+ def commentIt(self):
+ """
+ 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
+ # (commentariser) un commentaire.
+ try :
+ pos=self.treeParent.children.index(self)
+ commande_comment = self.item.get_objet_commentarise()
+ # On signale a l editeur du panel (le JDCDisplay) une modification
+ self.editor.init_modif()
+ self.treeParent.build_children()
+ self.treeParent.children[pos].select()
+ self.treeParent.children[pos].affichePanneau()
+ except Exception,e:
+ traceback.print_exc()
+ QMessageBox.critical( self.editor, "TOO BAD",str(e))
+
+ def unCommentIt(self):
+ """
+ Realise la decommentarisation de self
+ """
+ try :
+ pos=self.treeParent.children.index(self)
+ commande,nom = self.item.uncomment()
+ self.editor.init_modif()
+ self.treeParent.build_children()
+ self.treeParent.children[pos].select()
+ self.treeParent.children[pos].affichePanneau()
+ except Exception,e:
+ QMessageBox.critical( self.editor, "Erreur !",str(e))
+
+ def addComment( self, after=True ):
+ """
+ Ajoute un commentaire a l'interieur du JDC :
+ """
+ self.editor.init_modif()
+ if after:
+ pos = 'after'
+ else:
+ pos = 'before'
+ return self.append_brother( COMMENT, pos )
+
+ def addParameters( self, after=True ):
+ """
+ Ajoute un parametre a l'interieur du JDC :
+ """
+ self.editor.init_modif()
+ if after:
+ pos = 'after'
+ else:
+ pos = 'before'
+ return self.append_brother( PARAMETERS, pos )
+
-# def connect(self):
-# self.item.connect("add",self.onAdd,())
-# self.item.connect("supp",self.onSupp,())
-# self.item.connect("valid",self.onValid,())
-
-#
-# def commentIt(self):
-# """
-# 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
-# # (commentariser) un commentaire.
-# try :
-# pos=self.QWParent.children.index(self)
-# commande_comment = self.item.get_objet_commentarise()
-# # On signale au QWParent du panel (le JDCDisplay) une modification
-# self.QWParent.init_modif()
-# self.QWParent.children[pos].select()
-# except Exception,e:
-# traceback.print_exc()
-# QMessageBox.critical( self.QWParent, "TOO BAD",str(e))
-# return
-#
-# def unCommentIt(self):
-# """
-# Realise la decommentarisation de self
-# """
-# try :
-# pos=self.QWParent.children.index(self)
-# commande,nom = self.item.uncomment()
-# self.QWParent.init_modif()
-# self.QWParent.children[pos].select()
-# except Exception,e:
-# QMessageBox.critical( self.QWParent, "Erreur !",str(e))
-# return
-#
-# def addComment( self, after=True ):
-# """
-# Ajoute un commentaire a l'interieur du JDC :
-# """
-# self.QWParent.init_modif()
-# if after:
-# pos = 'after'
-# else:
-# pos = 'before'
-# return self.append_brother( COMMENT, pos )
-#
-# def addParameters( self, after=True ):
-# """
-# Ajoute un parametre a l'interieur du JDC :
-# """
-# self.QWParent.init_modif()
-# if after:
-# pos = 'after'
-# else:
-# pos = 'before'
-# return self.append_brother( PARAMETERS, pos )
-#
-#
-#
def select( self ):
"""
Rend le noeud courant (self) selectionne et deselectionne
def delete(self):
"""
Methode externe pour la destruction de l'objet associe au noeud
- La mise a jour des noeuds est faite par onSupp sur notification
"""
self.editor.init_modif()
index = self.treeParent.children.index(self) - 1
if ret == 0:return
self.treeParent.build_children()
- print index
brothers=self.treeParent.children
if brothers:
toselect=brothers[index]
self.update_node_texte()
- def onAdd(self,objet):
- #print "NODE onAdd : un objet a ete ajoute aux fils de l'item ",self.item.GetLabelText()
- old_nodes=self.children
- self.update_nodes()
- #self.select()
-
- def onSupp(self,objet):
- #print "NODE onSupp : un objet a ete supprime des fils de l'item ",self.item.object,objet
- old_nodes=self.children
- self.update_nodes()
- #self.select()
-
def update_node_valid(self):
"""Cette methode remet a jour la validite du noeud (icone)
Elle appelle isvalid
def update_nodes(self):
self.select()
-#
+
def update_texte(self):
""" Met a jour les noms des SD et valeurs des mots-cles """
#print "NODE update_texte", self.item.GetLabelText()
#
#
#
-#if __name__=='__main__':
-# from qt import *
-#
-#
+if __name__=='__main__':
+ from PyQt4 import *
+ from PyQt4.QtGui import *
+ from PyQt4.QtCore import *
+
+
# sys.path[:0]=['..','../Aster','../Aster/Cata' ]
-#
+
# app = QApplication(sys.argv)
-#
+
# fn = 'azAster.comm'
# jdcName = os.path.basename(fn)
# f=open(fn,'r')
# text=f.read()
# f.close()
# print 'text',text
+ print "afaire"
+
#
# from autre_analyse_cata import analyse_catalogue
# from Cata import cataSTA8
# -*- coding: utf-8 -*-
from PyQt4 import *
from PyQt4.QtGui import *
+from PyQt4.QtCore import *
#---------------------------#
class PopUpMenuNodePartiel :
#---------------------------#
def createPopUpMenu(self):
- return
- #menu
- self.menu = QPopupMenu(self.tree)
+ self.createActions()
+ self.menu = QMenu(self.tree)
#ss-menu Comment:
- self.commentMenu = QPopupMenu( self.menu )
- self.menu.insertItem( qApp.translate('Browser','Commentaire'), self.commentMenu )
- self.commentMenu.insertItem( 'après', self.addCommentAfter )
- self.commentMenu.insertItem( 'avant', self.addCommentBefore )
-
+ self.commentMenu=self.menu.addMenu('Commentaire')
+ self.commentMenu.addAction(self.CommApres)
+ self.commentMenu.addAction(self.CommAvant)
#ss-menu Parameters:
- self.parametersMenu = QPopupMenu( self.menu )
- self.parametersMenu.insertItem( 'après', self.addParametersAfter )
- self.parametersMenu.insertItem( 'avant', self.addParametersBefore )
+ self.paramMenu =self.menu.addMenu('Parametre')
+ self.paramMenu.addAction(self.ParamApres)
+ self.paramMenu.addAction(self.ParamAvant)
#items du menu
- self.menu.insertItem( qApp.translate('Browser','Supprimer'), self.delete )
- self.menu.insertItem( qApp.translate('Browser','Parametres'), self.parametersMenu )
-
+ self.menu.addAction(self.Supprime)
- def addCommentAfter(self):
- """
- """
- self.addComment()
+ def createActions(self):
+ self.CommApres = QAction('après',self.tree)
+ self.tree.connect(self.CommApres,SIGNAL("activated()"),self.addCommApres)
+ self.CommApres.setStatusTip("Insere un commentaire apres la commande ")
+ self.CommAvant = QAction('avant',self.tree)
+ self.tree.connect(self.CommAvant,SIGNAL("activated()"),self.addCommAvant)
+ self.CommAvant.setStatusTip("Insere un commentaire avant la commande ")
+
+ self.ParamApres = QAction('après',self.tree)
+ self.tree.connect(self.ParamApres,SIGNAL("activated()"),self.addParametersApres)
+ self.ParamApres.setStatusTip("Insere un parametre apres la commande ")
+ self.ParamAvant = QAction('avant',self.tree)
+ self.tree.connect(self.ParamAvant,SIGNAL("activated()"),self.addParametersAvant)
+ self.ParamAvant.setStatusTip("Insere un parametre avant la commande ")
- def addCommentBefore(self):
- """
- """
- self.addComment(False)
+ self.Supprime = QAction('Supprimer',self.tree)
+ self.tree.connect(self.Supprime,SIGNAL("activated()"),self.supprimeNoeud)
+ self.Supprime.setStatusTip("supprime le mot clef ")
- def addParametersAfter(self):
- """
- """
- self.addParameters()
+ def supprimeNoeud(self):
+ item= self.tree.currentItem()
+ item.delete()
- def addParametersBefore(self):
- """
- """
- self.addParameters(False)
+ def addParametersApres(self):
+ item= self.tree.currentItem()
+ item.addParameters(True)
+ def addParametersAvant(self):
+ item= self.tree.currentItem()
+ item.addParameters(False)
+
+ def addCommApres(self):
+ item= self.tree.currentItem()
+ item.addComment(True)
+
+ def addCommAvant(self):
+ item= self.tree.currentItem()
+ item.addComment(False)
#-----------------------------------------#
class PopUpMenuNode(PopUpMenuNodePartiel) :
#-----------------------------------------#
def createPopUpMenu(self):
- return
PopUpMenuNodePartiel.createPopUpMenu(self)
- self.commentMenu.insertItem( 'ce noeud', self.commentIt )
+ self.Commente = QAction('ce noeud',self.tree)
+ self.tree.connect(self.Commente,SIGNAL("activated()"),self.Commenter)
+ self.Commente.setStatusTip("commente le noeud ")
+ self.commentMenu.addAction(self.Commente)
+
+ def Commenter(self):
+ item= self.tree.currentItem()
+ item.commentIt()