Salome HOME
CCAR: creation V1_13a1 a partir de la branche Liv-V1_12
[tools/eficas.git] / Editeur / panels.py
index 843ccc42bfb6b3519b623c8a3bde47a86e5fe14b..636473a1ae0e852fbbf4a1fbd261bc02c8bb290c 100644 (file)
@@ -23,6 +23,7 @@ import os
 from Tkinter import *
 import Pmw
 import time
+import traceback
 
 import widgets
 from widgets import ListeChoix
@@ -32,6 +33,7 @@ import options
 
 SEPARATEUR = '-'*30
 
+
 class Panel(Frame) :
   """
   Classe servant de classe mère à toutes celles représentant les
@@ -49,6 +51,14 @@ class Panel(Frame) :
       self.place(x=0,y=0,relheight=1,relwidth=1)
       self.creer_boutons()
       self.init()
+      global panneauCommande
+      panneauCommande=self
+
+  #def __del__(self):
+  #    print "__del__",self
+
+  def update_panel(self):
+      """Methode appele pour demander une mise a jour du panneau"""
 
   def destroy(self):
       Frame.destroy(self)
@@ -71,9 +81,9 @@ class Panel(Frame) :
       # On termine la suppression de facon brutale (objets Tk et non Tk)
       for k in self.__dict__.keys():
          # il est plus prudent de ne pas détruire le lien sur le Node
-        # si on voulait mettre l'attribut node à None, il faudrait
-        # que tous les appels à node.parent.select() apparaissent après
-        # toutes les autres actions liées au panel (node.item.isglobal(), ...)
+         # si on voulait mettre l'attribut node à None, il faudrait
+         # que tous les appels à node.parent.select() apparaissent après
+         # toutes les autres actions liées au panel (node.item.isglobal(), ...)
          if k != 'node' : setattr(self,k,None)
 
   def creer_boutons(self):
@@ -82,30 +92,29 @@ class Panel(Frame) :
       (à droite sous les onglets )
       """
       self.fr_but = Frame(self,height=30)
-      self.fr_but.pack(side='bottom',fill='x')
-      self.bouton_com = Button(self.fr_but,
-                               text = 'Commentariser',
-                               command = self.ajout_commentaire,
-                               width=14)
-      self.bouton_sup = Button(self.fr_but,
-                               text = "Supprimer",
-                               command=self.supprimer,
-                               width=14)
-      self.bouton_doc = Button(self.fr_but,
-                               text="Documentation",
-                               command=self.visu_doc,
-                               width=14)
-      self.bouton_cata = Button(self.fr_but,
-                                text = "Catalogue",
-                                command = self.show_catalogue,
-                                width=14)
+      self.fr_but.pack(side='bottom')
+      #self.fr_but.pack(side='bottom',fill='x')
+      #self.bouton_com = Button(self.fr_but, text = 'Commentariser', command = self.ajout_commentaire, width=14)
+      #self.bouton_sup = Button(self.fr_but, text = "Supprimer", command=self.supprimer, width=14)
+      #self.bouton_doc = Button(self.fr_but, text="Documentation", command=self.visu_doc, width=14)
+      #self.bouton_cata = Button(self.fr_but, text = "Catalogue", command = self.show_catalogue, width=14)
+      self.bouton_com = Button(self.fr_but, text = 'Commentariser', command = self.ajout_commentaire)
+      self.bouton_sup = Button(self.fr_but, text = "Supprimer", command=self.supprimer)
+      self.bouton_doc = Button(self.fr_but, text="Documentation", command=self.visu_doc)
+      self.bouton_cata = Button(self.fr_but, text = "Catalogue", command = self.show_catalogue)
+
       if self.parent.appli.CONFIGURATION.isdeveloppeur == 'OUI':
-          self.bouton_sup.place(relx=0.25,rely = 0.5,relheight = 0.8,anchor='center')
-          self.bouton_cata.place(relx=0.5,rely = 0.5,relheight = 0.8,anchor='center')
-          self.bouton_doc.place(relx=0.75,rely = 0.5,relheight = 0.8,anchor='center')
+          self.bouton_sup.pack(side='left',padx=5, pady=5)
+          self.bouton_cata.pack(side='left',padx=5, pady=5)
+          self.bouton_doc.pack(side='right',padx=5, pady=5)
+          #self.bouton_sup.place(relx=0.25,rely = 0.5,relheight = 0.8,anchor='center')
+          #self.bouton_cata.place(relx=0.5,rely = 0.5,relheight = 0.8,anchor='center')
+          #self.bouton_doc.place(relx=0.75,rely = 0.5,relheight = 0.8,anchor='center')
       else:
-          self.bouton_sup.place(relx=0.3,rely = 0.5,relheight = 0.8,anchor='center')
-          self.bouton_doc.place(relx=0.7,rely = 0.5,relheight = 0.8,anchor='center')
+          self.bouton_sup.pack(side='left',padx=5, pady=5)
+          self.bouton_doc.pack(side='right',padx=5, pady=5)
+          #self.bouton_sup.place(relx=0.3,rely = 0.5,relheight = 0.8,anchor='center')
+          #self.bouton_doc.place(relx=0.7,rely = 0.5,relheight = 0.8,anchor='center')
 
   def show_catalogue(self):
       try:
@@ -197,7 +206,7 @@ class Panel(Frame) :
       Suppression du noeud courant
       """
       # On signale au parent du panel (le JDCDisplay) une modification 
-      if self.parent.modified == 'n' : self.parent.init_modif()
+      self.parent.init_modif()
       self.node.delete()
       
   def affiche(self):
@@ -238,6 +247,9 @@ class Panel(Frame) :
       if name == SEPARATEUR:return
       if self.parent.modified == 'n' : self.parent.init_modif()
       if name != "COMMENTAIRE":
+          #parent=self.node.parent
+          #new_obj = parent.item.append_child(name,self.node.item.getObject())
+          #parent.children[parent.children.index(self.node)+1].select()
           new_node = self.node.append_brother(name,'after')
       else :
           new_node = self.ajout_commentaire()
@@ -247,6 +259,8 @@ class Panel(Frame) :
       if name == SEPARATEUR:return
       if self.parent.modified == 'n' : self.parent.init_modif()
       if name != "COMMENTAIRE":
+          #new_obj = self.node.item.append_child(name,'first')
+          #self.node.children[0].select()
           new_node = self.node.append_child(name,'first')
       else :
           new_node = self.ajout_commentaire_first()
@@ -255,6 +269,8 @@ class OngletPanel(Panel) :
   """ Cette classe est virtuelle et doit être dérivée
       Elle contient les principales méthodes d'affichage des différents onglets"""
 
+  global panelbind
+
   def raisecmd(self,page):
       self.nb.page(page).focus_set()
       if page == 'Concept':
@@ -268,15 +284,44 @@ class OngletPanel(Panel) :
           except:
               pass
 
+  def creebind(self):
+       self.nb.bind_all("<F1>",lambda e,s=self,num=0:s.commande_up(num))
+       self.nb.bind_all("<F2>",lambda e,s=self,num=1:s.commande_up(num))
+       self.nb.bind_all("<F3>",lambda e,s=self,num=2:s.commande_up(num))
+       self.nb.bind_all("<F4>",lambda e,s=self,num=3:s.commande_up(num))
+       OngletPanel.panelbind=self.nb
+
+  def enlevebind(self):
+       if not hasattr(OngletPanel,"panelbind"):
+          return
+       if OngletPanel.panelbind == None:
+          return
+       try:
+           OngletPanel.panelbind.unbind_all("<F1>")
+           OngletPanel.panelbind.unbind_all("<F2>")
+           OngletPanel.panelbind.unbind_all("<F3>")
+           OngletPanel.panelbind.unbind_all("<F4>")
+       except:
+           pass
+       OngletPanel.panelbind = None
+
+  def commande_up(self,num):
+      #print "commande_up de panels pour ", num
+      try :
+        OngletPanel.panelbind.selectpage(num)
+        pageNew=OngletPanel.panelbind.page(num)
+        pageNew.focus_set()
+      except :
+        pass
 
   def affiche(self):
       page=self.nb.getcurselection()
       self.nb.page(page).focus_set()
       if page == 'Concept':
           try:
-#            _any est un pointeur sur entry
-#            component est une methode de pmw 
-#            a priori, jamais ok
+#              _any est un pointeur sur entry
+#              component est une methode de pmw 
+#              a priori, jamais ok
               self._any.component('entry').focus_set()
           except:
               pass
@@ -296,7 +341,10 @@ class OngletPanel(Panel) :
       self._any = Entry(page,relief='sunken')
       self._any.place(relx=0.35,rely=0.4,relwidth=0.5)
       self._any.bind("<Return>",lambda e,s=self:s.execConcept())
+      self._any.bind("<KP_Enter>",lambda e,s=self:s.execConcept())
       self._any.insert(0,self.node.item.GetText())
+      self.but_ok=Button(page,text = "Valider",command=self.execConcept)
+      self.but_ok.place(relx=0.35,rely=0.8, relwidth=0.35)
       type_sd = self.node.item.get_type_sd_prod()
       if type_sd :
           txt = "L'opérateur courant retourne un objet de type %s" %type_sd
@@ -309,6 +357,7 @@ class OngletPanel(Panel) :
       page.bind("<Button-3>", lambda e,s=self,a=bulle_aide : s.parent.appli.affiche_aide(e,a))
       page.bind("<ButtonRelease-3>",self.parent.appli.efface_aide)
         
+
   def makeMoclesPage(self,page):
       """
       Crée la page qui affiche la liste des mots-clés que l'on peut
@@ -320,13 +369,16 @@ class OngletPanel(Panel) :
       liste_commandes = (("<Enter>",self.selectMC),
                          ("<Leave>",self.deselectMC),
                          ("<Double-Button-1>",self.defMC))
-      Liste = ListeChoix(self,page,liste_mc,liste_commandes = liste_commandes,titre = "Mots-clés permis")
+      Liste = ListeChoix(self,page,liste_mc,liste_commandes = liste_commandes,titre = "Mots-clés permis",optionReturn="oui")
       Liste.affiche_liste()
       # aide associée au panneau
       bulle_aide="""Double-cliquez sur le mot-clé que vous voulez ajouter à
       la commande en cours d'édition"""
       Liste.MCbox.bind("<Button-3>", lambda e,s=self,a=bulle_aide : s.parent.appli.affiche_aide(e,a))
       Liste.MCbox.bind("<ButtonRelease-3>",self.parent.appli.efface_aide)
+      if len(liste_mc) > 0 :
+         Liste.surligne(liste_mc[0])
+      self.Liste=Liste
 
   def makeCommentairePage(self,page):
       label = Label(page,text = "Insérer un commentaire :")
@@ -352,19 +404,22 @@ class OngletPanel(Panel) :
       if options.affichage_commandes == "alphabetic":
          liste_cmd = self.get_liste_cmd()
          Liste = ListeChoix(self,frame2,liste_cmd,liste_commandes = liste_commandes,
-                                   filtre='oui',titre = "Commandes")
+                                   filtre='oui',titre = "Commandes",optionReturn="oui")
       else:
-         liste_groupes=self.node.item.object.niveau.definition.liste_groupes
-         dict_groupes=self.node.item.object.niveau.definition.dict_groupes
+         liste_commandes=liste_commandes+(("<Return>",self.defCmd),)
+         liste_groupes,dict_groupes=self.get_groups()
          Liste = ListeChoixParGroupes(self,frame2,liste_groupes,dict_groupes,
                                       liste_commandes = liste_commandes,
-                                      filtre='oui',titre = "Commandes")
+                                      filtre='oui',titre = "Commandes",optionReturn="oui")
       Liste.affiche_liste()
       self.command_entry=Liste.entry
       # aide associée au panneau
       bulle_aide="""Double-cliquez sur la commande que vous voulez ajouter au jeu de commandes"""
       Liste.MCbox.bind("<Button-3>", lambda e,s=self,a=bulle_aide : s.parent.appli.affiche_aide(e,a))
       Liste.MCbox.bind("<ButtonRelease-3>",self.parent.appli.efface_aide)
+      self.liste_command=Liste
+      global panneauCommande
+      panneauCommande=self
 
   def makeJDCPage(self,page):
       """
@@ -376,13 +431,13 @@ class OngletPanel(Panel) :
       if options.affichage_commandes == "alphabetic":
          liste_cmd = self.get_liste_cmd()
          Liste = ListeChoix(self,page,liste_cmd,liste_commandes = liste_commandes,
-                            filtre='oui',titre = "Commandes")
+                            filtre='oui',titre = "Commandes",optionReturn="oui")
       else:
-         liste_groupes=self.node.item.object.niveau.definition.liste_groupes
-         dict_groupes=self.node.item.object.niveau.definition.dict_groupes
+         liste_commandes=liste_commandes+(("<Return>",self.defCmdFirst),)
+         liste_groupes,dict_groupes=self.get_groups()
          Liste = ListeChoixParGroupes(self,page,liste_groupes,dict_groupes,
                                       liste_commandes = liste_commandes,
-                                      filtre='oui',titre = "Commandes")
+                                      filtre='oui',titre = "Commandes",optionReturn="oui")
       Liste.affiche_liste()
        # aide associée au panneau
       bulle_aide="""Double-cliquez sur la commande que vous voulez ajouter au jeu de commandes"""
@@ -426,11 +481,9 @@ class OngletPanel(Panel) :
       # les frame ...
       self.frame_comment = Frame(page,bd=1,relief='raised')
       self.frame_param   = Frame(page,bd=1,relief='raised')
-      #self.frame_eval    = Frame(page,bd=1,relief='raised')
       self.frame_boutons = Frame(page,bd=1,relief='raised')
       self.frame_comment.place(relx=0,rely=0,relwidth=1,relheight=0.40)
       self.frame_param.place(relx=0,rely=0.40,relwidth=1,relheight=0.40)
-      #self.frame_eval.place(relx=0,rely=0.56,relwidth=1,relheight=0.28)
       self.frame_boutons.place(relx=0,rely=0.84,relwidth=1,relheight=0.16)
       # remplissage de la frame commentaire
       Label(self.frame_comment,text = "Insérer un commentaire :").place(relx=0.1,rely=0.5,anchor='w')
@@ -440,8 +493,8 @@ class OngletPanel(Panel) :
       but_comment_apres = Button(self.frame_comment,
                                  text = "APRES "+self.node.item.get_nom(),
                                  command = self.ajout_commentaire)
-      but_comment_avant.place(relx=0.6,rely=0.3,anchor='w',relwidth=0.3)
-      but_comment_apres.place(relx=0.6,rely=0.7,anchor='w',relwidth=0.3)
+      but_comment_avant.place(relx=0.45,rely=0.3,anchor='w',relwidth=0.45)
+      but_comment_apres.place(relx=0.45,rely=0.7,anchor='w',relwidth=0.45)
       # remplissage de la frame paramètre
       Label(self.frame_param,text = "Insérer un paramètre :").place(relx=0.1,rely=0.5,anchor='w')
       but_param_avant = Button(self.frame_param,
@@ -450,19 +503,8 @@ class OngletPanel(Panel) :
       but_param_apres = Button(self.frame_param,
                                  text = "APRES "+self.node.item.get_nom(),
                                  command = self.ajout_parametre)
-      but_param_avant.place(relx=0.6,rely=0.3,anchor='w',relwidth=0.3)
-      but_param_apres.place(relx=0.6,rely=0.7,anchor='w',relwidth=0.3)
-      # remplissage de la frame eval
-      #Label(self.frame_eval,text="Insérer un paramètre EVAL :").place(relx=0.1,rely=0.5,anchor='w')
-          #Label(self.frame_eval,text='Non encore disponible').place(relx=0.6,rely=0.5,anchor='w')
-      #but_eval_avant = Button(self.frame_eval,
-      #                        text = "AVANT "+self.node.item.get_nom(),
-      #                        command = lambda s=self :s.ajout_parametre_eval(ind = 'before'))
-      #but_eval_apres = Button(self.frame_eval,
-      #                        text = "APRES "+self.node.item.get_nom(),
-      #                        command = self.ajout_parametre_eval)
-      #but_eval_avant.place(relx=0.6,rely=0.3,anchor='w',relwidth=0.3)
-      #but_eval_apres.place(relx=0.6,rely=0.7,anchor='w',relwidth=0.3)      
+      but_param_avant.place(relx=0.45,rely=0.3,anchor='w',relwidth=0.45)
+      but_param_apres.place(relx=0.45,rely=0.7,anchor='w',relwidth=0.45)
       # remplissage de la frame boutons
       Button(self.frame_boutons,
              text="Commentariser toute la commande",
@@ -471,12 +513,14 @@ class OngletPanel(Panel) :
   def deselectMC(self,name):
       self.parent.appli.affiche_infos('')
     
-  def get_liste_cmd_old(self):
-      listeCmd = self.cata.listCmd()
-      return listeCmd
+  def get_groups(self):
+      jdc=self.node.item.object.get_jdc_root()
+      return jdc.get_groups()
 
   def get_liste_cmd(self):
-      listeCmd = self.node.item.object.niveau.definition.get_liste_cmd()
+      #print "get_liste_cmd",self.node.item.object
+      jdc=self.node.item.object.get_jdc_root()
+      listeCmd = jdc.get_liste_cmd()
       return listeCmd
 
   def deselectCmd(self,name):
@@ -494,8 +538,8 @@ class OngletPanel(Panel) :
       if nom == '' : return # si pas de nom, on ressort sans rien faire ...
       if self.parent.modified == 'n' : self.parent.init_modif()
       test,mess = self.node.item.nomme_sd(nom)
-      self.node.verif()
-      self.node.racine.update()
+      #self.node.verif()
+      #self.node.racine.update()
       self.parent.appli.affiche_infos(mess)
   
   def changed(self):
@@ -508,11 +552,16 @@ class OngletPanel(Panel) :
     # On traite par une exception le cas où l'utilisateur final cherche à désactiver
     # (commentariser) un commentaire.
     try :
+        pos=self.node.parent.children.index(self.node)
         commande_comment = self.node.item.get_objet_commentarise()
-        self.parent.appli.bureau.JDCDisplay_courant.ReplaceObjectNode(self.node,commande_comment,None)
+        # On signale au parent du panel (le JDCDisplay) une modification
+        self.parent.init_modif()
+        self.node.parent.children[pos].select()
     except Exception,e:
+        traceback.print_exc()
         widgets.showerror("TOO BAD",str(e))
     return
+
       
 class Panel_Inactif(Panel):
   """