...
[iramuteq] / tree.py
diff --git a/tree.py b/tree.py
index aac691a..6590705 100644 (file)
--- a/tree.py
+++ b/tree.py
@@ -5,15 +5,84 @@
 #Lisense: GNU GPL
 
 import wx
+import os
+import webbrowser
 import wx.lib.agw.customtreectrl as CT
 import logging
 from openanalyse import OpenAnalyse
-from corpusNG import Corpus, copycorpus
-from functions import DoConf
-
+from corpus import Corpus, copycorpus
+from functions import DoConf, GetTxtProfile
+from profile_segment import ProfileSegment, ProfilType
+from search_tools import SearchFrame
+from dialog import PrefSimpleFile, PrefExport
+from layout import open_antiprofil
 
 log = logging.getLogger('iramuteq.tree')
-#from agw import customtreectrl as CT
+
+class InfoDialog ( wx.Dialog ):
+    
+    def __init__( self, parent, txt, parametres ):
+        wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Informations", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
+        if len(parametres) > 30 :
+            nb = 4
+        else :
+            nb = 2       
+        self.SetSizeHintsSz( wx.Size( 500,200 ), wx.DefaultSize )
+        
+        bSizer1 = wx.BoxSizer( wx.VERTICAL )
+        
+        self.m_panel2 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
+        bSizer2 = wx.BoxSizer( wx.VERTICAL )
+        
+        self.m_staticText4 = wx.StaticText( self.m_panel2, wx.ID_ANY, txt, wx.DefaultPosition, wx.DefaultSize, 0 )
+        self.m_staticText4.Wrap( -1 )
+        bSizer2.Add( self.m_staticText4, 0, wx.ALL, 5 )
+        
+        
+        self.m_panel2.SetSizer( bSizer2 )
+        self.m_panel2.Layout()
+        bSizer2.Fit( self.m_panel2 )
+        bSizer1.Add( self.m_panel2, 0, wx.EXPAND |wx.ALL, 5 )
+        
+        self.m_panel1 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
+
+        fgSizer1 = wx.FlexGridSizer( 0, nb, 0, 0 )
+        fgSizer1.SetFlexibleDirection( wx.BOTH )
+        fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
+        
+        txtctrl = []
+        for val in parametres :
+            fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[0], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
+            #fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
+            txtctrl.append( wx.TextCtrl( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, (450, 20), wx.TE_READONLY ) )
+            txtctrl[-1].SetBackgroundColour('#DDE8EB')
+            #wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
+            fgSizer1.Add( txtctrl[-1], 0, wx.ALL|wx.EXPAND, 0)
+            #fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND |wx.ALL, 0)
+            #fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND|wx.ALL, 0)
+
+        self.m_panel1.SetSizer( fgSizer1 )
+        self.m_panel1.Layout()
+        fgSizer1.Fit( self.m_panel1 )
+        bSizer1.Add( self.m_panel1, 0, wx.EXPAND|wx.ALL, 3 )
+        
+        m_sdbSizer1 = wx.StdDialogButtonSizer()
+        self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK )
+        m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
+        m_sdbSizer1.Realize();
+        
+        bSizer1.Add( m_sdbSizer1, 0, wx.EXPAND, 5 )
+        
+        
+        self.SetSizer( bSizer1 )
+        self.Layout()
+        bSizer1.Fit( self )
+        
+        self.Centre( wx.BOTH )
+    
+    def __del__( self ):
+        pass
+
 
 class LeftTree(CT.CustomTreeCtrl):
 
@@ -39,94 +108,37 @@ class LeftTree(CT.CustomTreeCtrl):
         
         il = wx.ImageList(16, 16)
 
-#        for items in ArtIDs[1:-1]:
-#            bmp = wx.ArtProvider_GetBitmap(eval(items), wx.ART_TOOLBAR, (16, 16))
-#            il.Add(bmp)
-
-#        smileidx = il.Add(images.Smiles.GetBitmap())
-#        numicons = il.GetImageCount()
-
-        self.AssignImageList(il)
         self.count = 0
         self.log = log
 
         self.history = parent.history
         self.h = self.history.history
         self.root = self.AddRoot("Iramuteq")
-
+        
         if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
             self.SetPyData(self.root, None)
             self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal)
             self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded)
 
-        #textctrl = wx.TextCtrl(self, -1, "I Am A Simple\nMultiline wx.TexCtrl", style=wx.TE_MULTILINE)
-        #self.gauge = wx.Gauge(self, -1, 50, style=wx.GA_HORIZONTAL|wx.GA_SMOOTH)
-        #self.gauge.SetValue(0)
-        #combobox = wx.ComboBox(self, -1, choices=["That", "Was", "A", "Nice", "Holyday!"], style=wx.CB_READONLY|wx.CB_DROPDOWN)
-
-        #textctrl.Bind(wx.EVT_CHAR, self.OnTextCtrl)
-        #combobox.Bind(wx.EVT_COMBOBOX, self.OnComboBox)
-        #lenArtIds = len(ArtIDs) - 2
-        for x in range(len(self.h)) :
-            if 'corpus_name' in self.h[self.history.order[x]] :
-                key = 'corpus_name'
-            else :
-                key = 'name'
-            child = self.AppendItem(self.root, self.h[self.history.order[x]][key])
-            #if x == 1:
-            #    child = self.AppendItem(self.root, "Item %d" % x + "\nHello World\nHappy wxPython-ing!")
-            #    self.SetItemBold(child, True)
-            #else:
-            #    child = self.AppendItem(self.root, "Item %d" % x)
-            self.SetPyData(child, self.h[self.history.order[x]])
+        for corpus in self.h :
+            child = self.AppendItem(self.root, corpus['corpus_name'])
+            self.SetPyData(child, corpus)
             self.SetItemImage(child, 24, CT.TreeItemIcon_Normal)
             self.SetItemImage(child, 13, CT.TreeItemIcon_Expanded)
 
-            #if random.randint(0, 3) == 0:
-            #    self.SetItemLeftImage(child, random.randint(0, lenArtIds))
-
-            #for y in range(5):
-            #    if y == 0 and x == 1:
-            #        last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), ct_type=2, wnd=self.gauge)
-            #    elif y == 1 and x == 2:
-            #        last = self.AppendItem(child, "Item %d-%s" % (x, chr(ord("a")+y)), ct_type=1, wnd=textctrl)
-            #        if random.randint(0, 3) == 1:
-            #            self.SetItem3State(last, True)
-            #            
-            #    elif 2 < y < 4:
-            #        last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
-            #    elif y == 4 and x == 1:
-            #        last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), wnd=combobox)
-            #    else:
-            if 'corpus_name' in self.h[self.history.order[x]] :
-                if 'analyses' in self.h[self.history.order[x]] :
-                    for y in self.h[self.history.order[x]]['analyses'] :
-                        last = self.AppendItem(child, y['name'], ct_type=0)
-                            
-                        self.SetPyData(last, y)
-                        self.SetItemImage(last, 24, CT.TreeItemIcon_Normal)
-                        self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
-    
-            #    if random.randint(0, 3) == 0:
-            #        self.SetItemLeftImage(last, random.randint(0, lenArtIds))
-                    
-            #for z in range(len(self.history[x]) - 1):
-
-#                if z > 2:
-#                    item = self.AppendItem(last,  "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=0)
-#                    #if random.randint(0, 3) == 1:
-#                    #    self.SetItem3State(item, True)
-#                elif 0 < z <= 2:
-#                    item = self.AppendItem(last,  "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=0)
-#                elif z == 0:
-#                    item = self.AppendItem(last,  "item %d-%s-%d" % (x, chr(ord("a")+y), z))
-#                    #self.SetItemHyperText(item, True)
-#                self.SetPyData(item, None)
-#                self.SetItemImage(item, 28, CT.TreeItemIcon_Normal)
-#                self.SetItemImage(item, 28, CT.TreeItemIcon_Selected)
-
-             #       if random.randint(0, 3) == 0:
-             #           self.SetItemLeftImage(item, random.randint(0, lenArtIds))
+            if 'analyses' in corpus :
+                for y in corpus['analyses'] :
+                    last = self.AppendItem(child, y['name'], ct_type=0)
+                    self.SetPyData(last, y)
+                    self.SetItemImage(last, 24, CT.TreeItemIcon_Normal)
+                    self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
+
+        for matrix in self.history.matrix :
+            last = self.AppendItem(self.root, matrix['name'])
+            self.SetPyData(last, matrix)
+            self.SetItemImage(last, 24, CT.TreeItemIcon_Normal)
+            self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
+
 
         self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
         #self.Bind(wx.EVT_IDLE, self.OnIdle)
@@ -145,8 +157,8 @@ class LeftTree(CT.CustomTreeCtrl):
         mainframe = wx.GetTopLevelParent(self)
         
         if not hasattr(mainframe, "leftpanel"):
-            self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded)
-            self.Bind(CT.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed)
+            #self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded)
+            #self.Bind(CT.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed)
             self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
             self.Bind(CT.EVT_TREE_SEL_CHANGING, self.OnSelChanging)
             self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
@@ -238,7 +250,7 @@ class LeftTree(CT.CustomTreeCtrl):
             self.CloseItem(child, uuid)
             child, cookie = self.GetNextChild(itemParent, cookie)
 
-    def GiveFocus(self, itemParent = None, uuid = None) :
+    def GiveFocus(self, itemParent = None, uuid = None, bold = False) :
         if itemParent is None :
             itemParent = self.root
         child, cookie = self.GetFirstChild(itemParent)
@@ -246,9 +258,24 @@ class LeftTree(CT.CustomTreeCtrl):
             pydata = self.GetPyData(child)
             if pydata['uuid'] == uuid :
                 self.SelectItem(child)
-                break
+                if bold :
+                    self.SetItemBold(child, True)
+                return
+            self.GiveFocus(child, uuid, bold)
+            child, cookie = self.GetNextChild(itemParent, cookie)
+
+    def IsInTree(self, itemParent = None, uuid = None) :
+        if itemParent is None :
+            itemParent = self.root
+        child, cookie = self.GetFirstChild(itemParent)
+        while child :
+            pydata = self.GetPyData(child)
+            if pydata['uuid'] == uuid :
+                return True
             self.GiveFocus(child, uuid)
             child, cookie = self.GetNextChild(itemParent, cookie)
+        return False
+
 
     def OnRightDown(self, event):
         
@@ -297,6 +324,7 @@ class LeftTree(CT.CustomTreeCtrl):
         itemtype = self.GetItemType(item)
         text = self.GetItemText(item)
         pydata = self.GetPyData(item)
+        self.pydata = pydata
         
         self.current = item
         self.itemdict = {"ishtml": ishtml, "back": back, "fore": fore, "isbold": isbold,
@@ -312,16 +340,51 @@ class LeftTree(CT.CustomTreeCtrl):
             stat = menu.Append(wx.ID_ANY, u"Statistiques")
             spec = menu.Append(wx.ID_ANY, u"Spécificté et AFC")
             classification = wx.Menu()
-            alceste = classification.Append(wx.ID_ANY, u"Méthode ALCESTE")
-            pam = classification.Append(wx.ID_ANY, u"Par matrice des distances")
+            alceste = classification.Append(wx.ID_ANY, u"Méthode GNEPA")
+            #pam = classification.Append(wx.ID_ANY, u"Par matrice des distances")
             menu.AppendMenu(-1, u"Classification", classification)
             simi = menu.Append(wx.ID_ANY, u"Analyse de similitude")
+            wdc = menu.Append(wx.ID_ANY, u"Nuage de mots")
             menu.AppendSeparator()
             self.Bind(wx.EVT_MENU, self.OnAlceste, alceste)
-            self.Bind(wx.EVT_MENU, self.OnPam, pam)
+            #self.Bind(wx.EVT_MENU, self.OnPam, pam)
             self.Bind(wx.EVT_MENU, self.OnStat, stat)
             self.Bind(wx.EVT_MENU, self.OnSpec, spec)
             self.Bind(wx.EVT_MENU, self.OnSimiTxt, simi)
+            self.Bind(wx.EVT_MENU, self.OnWordCloud, wdc)
+        elif pydata.get('type', False) == 'alceste' and pydata['uuid'] in self.parent.history.opened :
+            openmenu = wx.Menu()
+            antipro = openmenu.Append(wx.ID_ANY, u"antiprofils")
+            menu.AppendMenu(wx.ID_ANY, u"Ouvrir...", openmenu)
+
+            profsr = menu.Append(wx.ID_ANY, u"Profils des segments répétés")
+            profgram = menu.Append(wx.ID_ANY, u"Profils des types")
+            export_corpus = menu.Append(wx.ID_ANY, u"Exporter le corpus")
+            colored = menu.Append(wx.ID_ANY, u"Corpus en couleur")
+            navig = menu.Append(wx.ID_ANY, u"Outil de navigation")
+            statclasse = menu.Append(wx.ID_ANY, u"Statistiques par classe")
+            rapport = menu.Append(wx.ID_ANY, u"Rapport")
+            menu.AppendSeparator()
+            self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
+            self.Bind(wx.EVT_MENU, self.OnProfSR, profsr)
+            self.Bind(wx.EVT_MENU, self.OnProfGram, profgram)
+            self.Bind(wx.EVT_MENU, self.OnExportCorpus, export_corpus)
+            self.Bind(wx.EVT_MENU, self.OnColored, colored)
+            self.Bind(wx.EVT_MENU, self.OnNavig, navig)
+            self.Bind(wx.EVT_MENU, self.StatClasse, statclasse)
+            self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
+        elif pydata.get('type', False) == 'stat'  and pydata['uuid'] in self.parent.history.opened :
+            export_dictionary =  menu.Append(wx.ID_ANY, u"Exporter le dictionnaire")
+            export_lems =  menu.Append(wx.ID_ANY, u"Exporter le dictionnaire des lemmes")
+            self.Bind(wx.EVT_MENU, self.OnExportDictionary, export_dictionary)
+            self.Bind(wx.EVT_MENU, self.OnExportLems, export_lems)
+            menu.AppendSeparator()
+        elif pydata.get('type', False) == 'gnepamatrix' and pydata['uuid'] in self.parent.history.opened :
+            openmenu = wx.Menu()
+            antipro = openmenu.Append(wx.ID_ANY, u"antiprofils")
+            menu.AppendMenu(wx.ID_ANY, u"Ouvrir...", openmenu)
+            self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
+
 
         itemdelete = menu.Append(wx.ID_ANY, "Supprimer de l'historique")
         if item == self.GetRootItem():
@@ -345,26 +408,144 @@ class LeftTree(CT.CustomTreeCtrl):
         self.PopupMenu(menu)
         menu.Destroy()
 
-    def getcorpus(self, itemdict):
-        if itemdict['pydata']['uuid'] in self.parent.history.openedcorpus :
-            return copycorpus(self.parent.history.openedcorpus[itemdict['pydata']['uuid']])
+    def getcorpus(self):
+        if self.pydata['uuid'] in self.parent.history.openedcorpus :
+            return copycorpus(self.parent.history.openedcorpus[self.pydata['uuid']])
+        elif 'corpus_name' in self.pydata :
+            return Corpus(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('corpus'), read = True)
         else :
-            return Corpus(self.parent, parametres = DoConf(itemdict['pydata']['ira']).getoptions('corpus'), read = True)
+            cuuid = self.pydata['corpus']
+            if cuuid in self.parent.history.openedcorpus :
+                return copycorpus(self.parent.history.openedcorpus[cuuid])
+            else :
+                irapath = self.parent.history.corpus[cuuid]['ira']
+                return Corpus(self.parent, parametres = DoConf(irapath).getoptions('corpus'), read = True)
 
     def OnSpec(self, evt) :
-        self.parent.OnTextSpec(evt, self.getcorpus(self.itemdict))
+        self.parent.OnTextSpec(evt, self.getcorpus())
 
     def OnStat(self, evt) :
-        self.parent.OnTextStat(evt, self.getcorpus(self.itemdict))
+        self.parent.OnTextStat(evt, self.getcorpus())
         
     def OnAlceste(self, evt) :
-        self.parent.OnTextAlceste(evt, self.getcorpus(self.itemdict))
+        self.parent.OnTextAlceste(evt, self.getcorpus())
 
     def OnPam(self, evt) :
-        print 'rien'
+        self.parent.OnPamSimple(evt, self.getcorpus())
 
     def OnSimiTxt(self, evt) :
-        self.parent.OnSimiTxt(evt, self.getcorpus(self.itemdict))
+        self.parent.OnSimiTxt(evt, self.getcorpus())
+
+    def OnWordCloud(self, evt) :
+        self.parent.OnWordCloud(evt, self.getcorpus())
+
+    def OnProfSR(self, evt) :
+        ProfileSegment(self.parent, self.page.dictpathout, self.page.parametres, self.page.corpus)
+
+    def OnProfGram(self, evt) :
+        ProfilType(self.parent, self.page.corpus, self.page.parametres)
+
+    def OnExportCorpus(self, evt) :
+        dial = PrefExport(self, self.parent)
+        dial.fbb.SetValue(os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'export_corpus.txt'))
+        dial.CenterOnParent()
+        res = dial.ShowModal()
+        if res == wx.ID_OK :
+            if dial.radio_type.GetSelection() == 0 : alc = True
+            else : alc = False
+            if dial.radio_lem.GetSelection() == 0 : lem = True
+            else : lem = False
+            self.page.corpus.export_corpus_classes(dial.fbb.GetValue(), alc = alc, lem = lem)
+            msg = u"Fini !"
+            dial.Destroy()
+            dlg = wx.MessageDialog(self.parent, msg, u"Export", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
+            dlg.CenterOnParent()
+            dlg.ShowModal()
+            dlg.Destroy()
+
+    def OnColored(self, evt) :
+        dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.html', 'title': 'Corpus en couleur'})
+        dial.fbb.SetValue(os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'corpus_couleur.html'))
+        dial.CenterOnParent()
+        res = dial.ShowModal()
+        if res == wx.ID_OK :
+            fileout = dial.fbb.GetValue()
+            dial.Destroy()
+            txt = self.page.corpus.make_colored_corpus()
+            with open(fileout, 'w') as f :
+                f.write(txt)
+            msg = u"Fini !\nVoulez-vous ouvrir le corpus dans votre navigateur ?"
+            dlg = wx.MessageDialog(self.parent, msg, u"Corpus en couleur", wx.NO | wx.YES | wx.NO_DEFAULT | wx.ICON_QUESTION)
+            dlg.CenterOnParent()
+            if dlg.ShowModal() == wx.ID_YES :
+                webbrowser.open(fileout)
+            dlg.Destroy()
+
+    def OnNavig(self, evt):
+        if 'FrameSearch' not in dir(self.page) :
+            self.page.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.page.corpus)
+        self.page.FrameSearch.Show()
+
+    def StatClasse(self, evt):
+        dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.csv', 'title': 'Stat par classe'})
+        dial.fbb.SetValue( os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'stat_par_classe.csv'))
+        dial.CenterOnParent()
+        res = dial.ShowModal()
+        if res == wx.ID_OK :
+            fileout = dial.fbb.GetValue()
+            dial.Destroy()
+            self.page.corpus.get_stat_by_cluster(fileout)
+            msg = u"Fini !"
+            dlg = wx.MessageDialog(self.parent, msg, u"Stat par classe", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
+            dlg.CenterOnParent()
+            if dlg.ShowModal() == wx.ID_OK :
+                dlg.Destroy()        
+
+    def OpenAntipro(self, evt) :
+        find = False
+        for i in range(0, self.page.TabChdSim.GetPageCount()) :
+            page = self.page.TabChdSim.GetPage(i)
+            if self.page.TabChdSim.GetPageText(i) == 'Antiprofils' :
+                self.page.TabChdSim.SetSelection(i)
+                find = True
+                break
+        if not find :
+            open_antiprofil(self.page, self.page.dictpathout['ANTIPRO_OUT'], self.parent.syscoding)
+            self.page.TabChdSim.SetSelection(self.page.TabChdSim.GetPageCount() - 1)
+
+    def OnRapport(self, evt) :
+        dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.txt', 'title': 'Rapport'})
+        dial.fbb.SetValue(self.page.dictpathout['rapport'])
+        dial.CenterOnParent()
+        res = dial.ShowModal()
+        if res == wx.ID_OK :
+            fileout = dial.fbb.GetValue()
+            dial.Destroy()
+            with open(fileout, 'w') as f :
+                f.write(self.page.debtext + '\n' + GetTxtProfile(self.page.DictProfile, self.page.cluster_size))
+            msg = u"Fini !"
+            dlg = wx.MessageDialog(self.parent, msg, u"Rapport", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
+            dlg.CenterOnParent()
+            dlg.ShowModal()
+            dlg.Destroy()
+        else :
+            dial.Destroy()
+
+    def OnExportDictionary(self, evt) :
+        corpus = self.page.corpus
+        corpus.export_dictionary(self.page.pathout['dictionary.csv'], self.parent.syscoding)
+        log.info('export dictionary %s' % self.page.pathout['dictionary.csv'])
+        dial = wx.MessageDialog(self.parent, self.page.pathout['dictionary.csv'], 'Export', wx.OK)
+        dial.ShowModal()
+        dial.Destroy()
+        
+    def OnExportLems(self, evt) :
+        corpus = self.page.corpus
+        corpus.export_lems(self.page.pathout['lemmes.csv'], self.parent.syscoding)
+        log.info('export lemmes %s' % self.page.pathout['lemmes.csv'])
+        dial = wx.MessageDialog(self.parent, self.page.pathout['lemmes.csv'], 'Export', wx.OK)
+        dial.ShowModal()
+        dial.Destroy()
 
     def OnItemBackground(self, event):
 
@@ -462,11 +643,14 @@ class LeftTree(CT.CustomTreeCtrl):
         numchildren = str(self.itemdict["children"])
         itemtype = self.itemdict["itemtype"]
         pydata = self.itemdict['pydata']
-        if 'analyses' in pydata :
-            toshow = dict([[val, pydata[val]] for val in pydata if val not in['analyses', 'isload']])
-        else :
-            toshow = pydata
-        pydata = DoConf().totext(toshow)
+        #if 'analyses' in pydata :
+        #    toshow = dict([[val, pydata[val]] for val in pydata if val not in['analyses', 'isload']])
+        #else :
+        toshow = pydata['ira']
+        toshow = DoConf(toshow).getoptions()
+        txt = DoConf().totext(toshow)
+        parametres = [val.split('\t\t:') for val in txt.splitlines()]
+        parametres.sort()
 
         if itemtype == 0:
             itemtype = "Normal"
@@ -475,12 +659,8 @@ class LeftTree(CT.CustomTreeCtrl):
         else:
             itemtype = "RadioButton"
 
-        strs = "Information On Selected Item:\n\n" + "Text: " + itemtext + "\n" \
-               "Number Of Children: " + numchildren + "\n" \
-               "Item Type: " + itemtype + "\n" \
-               "Item Data Type: " + pydata + "\n"
-
-        dlg = wx.MessageDialog(self, strs, "CustomTreeCtrlDemo Info", wx.OK | wx.ICON_INFORMATION)
+        dlg = InfoDialog(self, itemtext, parametres)
+        dlg.CenterOnParent()
         dlg.ShowModal()
         dlg.Destroy()
                 
@@ -489,7 +669,7 @@ class LeftTree(CT.CustomTreeCtrl):
     def OnItemDelete(self, event):
 
         strs = "Are You Sure You Want To Delete Item " + self.GetItemText(self.current) + "?"
-        dlg = wx.MessageDialog(None, strs, 'Deleting Item', wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_QUESTION)
+        dlg = wx.MessageDialog(None, strs, 'Deleting Item', wx.OK | wx.CANCEL | wx.ICON_QUESTION)
 
         if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
             dlg.Destroy()
@@ -499,9 +679,9 @@ class LeftTree(CT.CustomTreeCtrl):
         
         pydata = self.itemdict['pydata']
         if 'corpus_name' in pydata :
-            self.history.delete(pydata['uuid'], True)
+            self.history.delete(pydata, True)
         else :
-            self.history.delete(pydata['uuid'])
+            self.history.delete(pydata)
         self.DeleteChildren(self.current)
         self.Delete(self.current)
         self.current = None
@@ -519,23 +699,31 @@ class LeftTree(CT.CustomTreeCtrl):
 
         dlg.Destroy()
 
-    def AddAnalyse(self, parametres, itemParent = None) :
-        uuid = parametres['corpus']
-        if itemParent is None :
-            itemParent = self.root
-        child, cookie = self.GetFirstChild(itemParent)
-        while child :
-            pydata = self.GetPyData(child)
-            if pydata['uuid'] == uuid :
-                corpus = child
-                break
-            self.GiveFocus(child, uuid)
-            child, cookie = self.GetNextChild(itemParent, cookie)
-        item = self.AppendItem(corpus, parametres['name'])
+    def AddAnalyse(self, parametres, itemParent = None, bold = True) :
+        uuid = parametres.get('corpus', None)
+        if uuid is not None :
+            if itemParent is None :
+                itemParent = self.root
+            child, cookie = self.GetFirstChild(itemParent)
+            corpus = None
+            while child :
+                pydata = self.GetPyData(child)
+                if pydata['uuid'] == uuid :
+                    corpus = child
+                    break
+                self.GiveFocus(child, uuid)
+                child, cookie = self.GetNextChild(itemParent, cookie)
+            #item = self.AppendItem(child, parametres['name'])
+            if corpus is not None : 
+                item = self.AppendItem(corpus, parametres['name'])
+            else :
+                item = self.AppendItem(self.root, parametres['name'])
+        else :
+            item = self.AppendItem(self.root, parametres['name'])
         self.SetPyData(item, parametres)
         self.SetItemImage(item, 24, CT.TreeItemIcon_Normal)
         self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
-        self.SetItemBold(item, True)
+        self.SetItemBold(item, bold)
         
     def OnItemAppend(self, item):
         child = self.AppendItem(self.root, item['corpus_name'])
@@ -594,17 +782,19 @@ class LeftTree(CT.CustomTreeCtrl):
         
         pt = event.GetPosition()
         item, flags = self.HitTest(pt)
-        pydata = self.GetPyData(item)
-        if pydata['uuid'] in self.parent.history.opened :
-            for i in range(self.parent.nb.GetPageCount()) :
-                page = self.parent.nb.GetPage(i)
-                if 'parametres' in dir(page) :
-                    if page.parametres['uuid'] == pydata['uuid'] :
-                        self.parent.nb.SetSelection(i)
-                        break
-        else :
-            OpenAnalyse(self.parent, pydata)
-            self.SetItemBold(item, True)
+        if item is not None :
+            pydata = self.GetPyData(item)
+            if pydata['uuid'] in self.parent.history.opened :
+                for i in range(self.parent.nb.GetPageCount()) :
+                    page = self.parent.nb.GetPage(i)
+                    if 'parametres' in dir(page) :
+                        if page.parametres['uuid'] == pydata['uuid'] :
+                            self.parent.nb.SetSelection(i)
+                            break
+            else :
+                OpenAnalyse(self.parent, pydata)
+                self.SetItemBold(item, True)
+                self.OnSelChanged(pydata = pydata)
         #if item and (flags & CT.TREE_HITTEST_ONITEMLABEL):
         #    if self.GetAGWWindowStyleFlag() & CT.TR_EDIT_LABELS:
         #        self.log.info("OnLeftDClick: %s (manually starting label edit)"% self.GetItemText(item) + "\n")
@@ -650,26 +840,21 @@ class LeftTree(CT.CustomTreeCtrl):
         event.Skip()
 
         
-    def OnSelChanged(self, event):
-        item = event.GetItem()
-        pydata = self.GetPyData(item)
+    def OnSelChanged(self, event = None, pydata = None):
+        if event is not None :
+            item = event.GetItem()
+            pydata = self.GetPyData(item)
         if pydata is not None :
+            self.pydata = pydata
             if pydata['uuid'] in self.parent.history.opened :
                 for i in range(self.parent.nb.GetPageCount()) :
-                    page = self.parent.nb.GetPage(i)
-                    if 'parametres' in dir(page) :
-                        if page.parametres['uuid'] == pydata['uuid'] :
+                    self.page = self.parent.nb.GetPage(i)
+                    if 'parametres' in dir(self.page) :
+                        if self.page.parametres['uuid'] == pydata['uuid'] :
                             self.parent.nb.SetSelection(i)
                             break
-
-        #self.item = event.GetItem()
-        #if self.item:
-        #    self.
-            #self.log.info("OnSelChanged: %s" % self.GetItemText(self.item))
-        #    if wx.Platform == '__WXMSW__':
-               # self.log.info(", BoundingRect: %s" % self.GetBoundingRect(self.item, True) + "\n")
-       #        pass
-        event.Skip()
+        if event is not None :
+            event.Skip()
 
 
     def OnSelChanging(self, event):
@@ -682,7 +867,7 @@ class LeftTree(CT.CustomTreeCtrl):
                 olditemtext = "None"
             else:
                 olditemtext = self.GetItemText(olditem)
-            self.log.info("OnSelChanging: From %s" % olditemtext + " To %s" % self.GetItemText(item) + "\n")
+            #self.log.info("OnSelChanging: From %s" % olditemtext + " To %s" % self.GetItemText(item) + "\n")
                 
         event.Skip()