...
[iramuteq] / tree.py
diff --git a/tree.py b/tree.py
index 11de21b..12627f4 100644 (file)
--- a/tree.py
+++ b/tree.py
@@ -11,13 +11,14 @@ import logging
 from openanalyse import OpenAnalyse
 from corpus import Corpus, copycorpus
 from tableau import Tableau, copymatrix
-from functions import DoConf, GetTxtProfile, TGen
+from functions import DoConf, GetTxtProfile, TGen, BugReport
 from profile_segment import ProfileSegment, ProfilType
 from search_tools import SearchFrame
 from dialog import PrefSimpleFile, PrefExport
 from layout import open_antiprofil, TgenLayout
 from guifunct import TGenFrame
 from textaslexico import TgenSpec
+from textreinert import TgenProf
 
 log = logging.getLogger('iramuteq.tree')
 
@@ -123,9 +124,11 @@ class LeftTree(CT.CustomTreeCtrl):
         imgmatroot = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'matroot.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['matrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'matrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['freq'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'frequences.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
+        self.ild['freqmulti'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'frequences.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['chi2'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'chi2.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['reinertmatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'reinertmatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['simimatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'simimatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
+        self.ild['simiclustermatrix'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'simimatrix.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.ild['proto'] = self.il.Add(wx.Image(os.path.join(self.parent.images_path,'proto.png'), wx.BITMAP_TYPE_PNG).Scale(16,16).ConvertToBitmap())
         self.SetImageList(self.il)
         
@@ -141,7 +144,7 @@ class LeftTree(CT.CustomTreeCtrl):
             self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal)
             self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded)
         
-        self.textroot = self.AppendItem(self.root, u'Corpus texte')
+        self.textroot = self.AppendItem(self.root, _(u'Textual corpus'))
         self.SetPyData(self.textroot, {'uuid': 'textroot'})
         self.SetItemImage(self.textroot, imgtextroot, CT.TreeItemIcon_Normal)
         self.SetItemImage(self.textroot, imgtextroot, CT.TreeItemIcon_Expanded)     
@@ -163,7 +166,7 @@ class LeftTree(CT.CustomTreeCtrl):
                     self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
                     self.SetItemImage(last, img, CT.TreeItemIcon_Expanded)
 
-        self.matroot = self.AppendItem(self.root, u'Matrices')
+        self.matroot = self.AppendItem(self.root, _(u'Matrix'))
         self.SetPyData(self.matroot, {'uuid': 'matroot'})
         self.SetItemImage(self.matroot, imgmatroot, CT.TreeItemIcon_Normal)
         self.SetItemImage(self.matroot, imgmatroot, CT.TreeItemIcon_Expanded)
@@ -391,11 +394,11 @@ class LeftTree(CT.CustomTreeCtrl):
                 stat = menu.Append(wx.ID_ANY, _(u"Statistics").decode('utf8'))
                 spec = menu.Append(wx.ID_ANY, _(u"Specificities and CA").decode('utf8'))
                 classification = wx.Menu()
-                reinert = classification.Append(wx.ID_ANY, _(u"Reinert method").decode('utf8'))
+                reinert = classification.Append(wx.ID_ANY, _(u"Reinert's Method").decode('utf8'))
                 #pam = classification.Append(wx.ID_ANY, u"Par matrice des distances")
                 menu.AppendMenu(-1, _(u"Clustering").decode('utf8'), classification)
-                simi = menu.Append(wx.ID_ANY, _(u"Similarities analysis").decode('utf8'))
-                wdc = menu.Append(wx.ID_ANY, _(u"Wordcloud").decode('utf8'))
+                simi = menu.Append(wx.ID_ANY, _(u"Similarities Analysis").decode('utf8'))
+                wdc = menu.Append(wx.ID_ANY, _(u"WordCloud").decode('utf8'))
                 subcorpus = wx.Menu()
                 subcorpusfrommeta = subcorpus.Append(wx.ID_ANY, _(u'Sub corpus from metadata').decode('utf8'))
                 subcorpusfromtheme = subcorpus.Append(wx.ID_ANY, _(u'Sub corpus from thematic').decode('utf8'))
@@ -443,6 +446,8 @@ class LeftTree(CT.CustomTreeCtrl):
     
                 profsr = menu.Append(wx.ID_ANY, _(u"Repeated segments profiles").decode('utf8'))
                 profgram = menu.Append(wx.ID_ANY, _(u"POS profiles").decode('utf8'))
+                tgen = menu.Append(wx.ID_ANY, _(u"Tgen Editor").decode('utf8'))
+                computetgen = menu.Append(wx.ID_ANY, _(u"Compute Tgen").decode('utf8'))
                 export_corpus = menu.Append(wx.ID_ANY, _(u"Export corpus").decode('utf8'))
                 colored = menu.Append(wx.ID_ANY, _(u"Colored corpus").decode('utf8'))
                 navig = menu.Append(wx.ID_ANY, _(u"Navigator").decode('utf8'))
@@ -454,6 +459,8 @@ class LeftTree(CT.CustomTreeCtrl):
                 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.OnTgenEditor, tgen)
+                self.Bind(wx.EVT_MENU, self.OnTgenCompute, computetgen)
                 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)
@@ -716,8 +723,11 @@ class LeftTree(CT.CustomTreeCtrl):
         else :
             self.page.parametres['tgenpath'] = tgenpath
             tgen = TGen(path = tgenpath, encoding = self.parent.syscoding)
-            self.page.parametres['etoiles'] = self.page.etoiles
-            TgenSpec(self.parent, corpus, self.page.parametres)
+            if self.page.parametres['type'] == 'spec' :
+                self.page.parametres['etoiles'] = self.page.etoiles
+                TgenSpec(self.parent, corpus, self.page.parametres)
+            elif self.page.parametres['type'] == 'alceste' :
+                TgenProf(self.parent, corpus, self.page.parametres, self.page.cluster_size)
             TgenLayout(self.page)
     
     def OnExportClasses(self, event):
@@ -740,7 +750,25 @@ class LeftTree(CT.CustomTreeCtrl):
     
     def OnRename(self, event):
         pydata = self.itemdict['pydata']
-        print pydata
+        if 'matrix_name' in pydata :
+            name = 'matrix_name'
+        elif 'corpus_name' in pydata :
+            name = 'corpus_name'
+        else :
+            name = 'name'
+        oldname = pydata[name]
+        dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', oldname)
+        if dlg.ShowModal() == wx.ID_OK:
+            newname = dlg.GetValue()
+            dlg.Destroy()
+            pydata[name] = newname
+            Totconf = DoConf(configfile=pydata['ira'])
+            conf = Totconf.getoptions()
+            conf[name] = newname
+            Totconf.makeoptions(Totconf.getsections(), [conf])
+            self.history.update(pydata)
+            self.SetItemText(self.current, newname)
+            self.EnsureVisible(self.current)
 
     def OnItemBackground(self, event):
 
@@ -969,6 +997,7 @@ class LeftTree(CT.CustomTreeCtrl):
         if select :
             self.history.addtab(item)
             self.SetItemBold(child, True)
+            self.SelectItem(child)
         
         #dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
 
@@ -1030,12 +1059,19 @@ class LeftTree(CT.CustomTreeCtrl):
             elif pydata['uuid'] in ['textroot', 'matroot'] :
                 pass
             else :
-                busy = wx.BusyInfo(_("Please wait..."), self.parent)
-                wx.SafeYield()
-                OpenAnalyse(self.parent, pydata)
-                del busy
-                self.SetItemBold(item, True)
-                self.OnSelChanged(pydata = pydata)
+                if os.path.exists(pydata['ira']) :
+                    busy = wx.BusyInfo(_("Please wait..."), self.parent)
+                    wx.SafeYield()
+                    try :
+                        OpenAnalyse(self.parent, pydata)
+                        del busy
+                        self.SetItemBold(item, True)
+                        self.OnSelChanged(pydata = pydata)
+                    except :
+                        del busy
+                        BugReport(self.ira)
+                else :
+                    wx.MessageBox(_(u"This file does not exist : %s" % pydata['ira']).decode('utf8'), 'Information', wx.ICON_EXCLAMATION | wx.STAY_ON_TOP )
         #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")