switch of 'lastRscript'
[iramuteq] / tree.py
diff --git a/tree.py b/tree.py
index 5b4b616..a4c3aa3 100644 (file)
--- a/tree.py
+++ b/tree.py
@@ -11,7 +11,7 @@ import logging
 from openanalyse import OpenAnalyse
 from corpus import Corpus, copycorpus
 from tableau import Tableau, copymatrix
-from functions import DoConf, GetTxtProfile, TGen, BugReport
+from functions import DoConf, GetTxtProfile, TGen, BugReport, open_folder
 from profile_segment import ProfileSegment, ProfilType
 from search_tools import SearchFrame
 from dialog import PrefSimpleFile, PrefExport
@@ -143,6 +143,13 @@ class LeftTree(CT.CustomTreeCtrl):
 
         self.history = parent.history
         self.h = self.history.history
+        
+        idopenfolder = wx.NewId()
+        accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL,  ord('E'),  idopenfolder)])
+        self.SetAcceleratorTable(accel_tbl)
+        
+        self.Bind(wx.EVT_MENU, self.OnOpenFolder, id=idopenfolder)
+        
         self.root = self.AddRoot("Iramuteq")
         
         if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
@@ -392,8 +399,18 @@ class LeftTree(CT.CustomTreeCtrl):
         
         if not item in [self.textroot, self.matroot] :
             menu = wx.Menu()
-            info = menu.Append(wx.ID_ANY, _(u"Informations").decode('utf8'))
-            rename = menu.Append(wx.ID_ANY, _(u"Rename").decode('utf8'))
+            info = wx.MenuItem(menu, wx.ID_ANY, _(u"Informations").decode('utf8'))
+            info.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_INFORMATION, size = (16,16)))
+            menu.AppendItem(info)
+            
+            rename = wx.MenuItem(menu, wx.ID_ANY, _(u"Rename").decode('utf8'))
+            rename.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_TIP, size = (16,16)))
+            menu.AppendItem(rename)
+            openfolder = wx.MenuItem(menu, wx.ID_ANY, _(u"Open directory").decode('utf8'))
+            openfolder.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FOLDER_OPEN, size = (16,16)))
+            menu.AppendItem(openfolder)           
+            
             menu.AppendSeparator()
     
             if 'corpus_name' in pydata :
@@ -451,8 +468,9 @@ class LeftTree(CT.CustomTreeCtrl):
                 self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
                 self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
     
-    
-            itemdelete = menu.Append(wx.ID_ANY, _(u"Delete from history").decode('utf8'))
+            itemdelete = wx.MenuItem(menu, wx.ID_ANY, _(u"Delete from history").decode('utf8'))
+            itemdelete.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_DELETE, size = (16,16)))
+            menu.AppendItem(itemdelete)
             #item11 = menu.Append(wx.ID_ANY, "Prepend An Item")
             #item12 = menu.Append(wx.ID_ANY, "Append An Item")
     
@@ -467,6 +485,7 @@ class LeftTree(CT.CustomTreeCtrl):
             self.Bind(wx.EVT_MENU, self.OnItemInfo, info)
             self.Bind(wx.EVT_MENU, self.OnRename, rename)
             self.Bind(wx.EVT_MENU, self.OnItemDelete, itemdelete)
+            self.Bind(wx.EVT_MENU, self.OnOpenFolder, openfolder)
             #self.Bind(wx.EVT_MENU, self.OnItemPrepend, item11)
             #self.Bind(wx.EVT_MENU, self.OnItemAppend, item12)
             
@@ -566,7 +585,7 @@ class LeftTree(CT.CustomTreeCtrl):
             self.page.corpus.export_corpus_classes(dial.fbb.GetValue(), alc = alc, lem = lem, uci = uci)
             msg = u"Fini !"
             dial.Destroy()
-            dlg = wx.MessageDialog(self.parent, msg, u"Export", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
+            dlg = wx.MessageDialog(self.parent, msg, u"Export", wx.OK | wx.ICON_INFORMATION)
             dlg.CenterOnParent()
             dlg.ShowModal()
             dlg.Destroy()
@@ -587,7 +606,7 @@ class LeftTree(CT.CustomTreeCtrl):
             with open(fileout, 'w') as f :
                 f.write(txt)
             msg = ' !\n'.join([_(u"Done").decode('utf8'), _(u"Open in a web browser ?").decode('utf8')])
-            dlg = wx.MessageDialog(self.parent, msg, u"Corpus en couleur", wx.NO | wx.YES | wx.NO_DEFAULT | wx.ICON_QUESTION)
+            dlg = wx.MessageDialog(self.parent, msg, u"Corpus en couleur", wx.NO | wx.YES | wx.ICON_QUESTION)
             dlg.CenterOnParent()
             if dlg.ShowModal() == wx.ID_YES :
                 webbrowser.open(fileout)
@@ -608,7 +627,7 @@ class LeftTree(CT.CustomTreeCtrl):
             dial.Destroy()
             self.page.corpus.get_stat_by_cluster(fileout)
             msg = u"Fini !"
-            dlg = wx.MessageDialog(self.parent, msg, _(u"Clusters statistics").decode('utf8'), wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
+            dlg = wx.MessageDialog(self.parent, msg, _(u"Clusters statistics").decode('utf8'), wx.OK | wx.ICON_INFORMATION)
             dlg.CenterOnParent()
             if dlg.ShowModal() == wx.ID_OK :
                 dlg.Destroy()        
@@ -636,7 +655,7 @@ class LeftTree(CT.CustomTreeCtrl):
             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"Report").decode('utf8'), wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
+            dlg = wx.MessageDialog(self.parent, msg, _(u"Report").decode('utf8'), wx.OK | wx.ICON_INFORMATION)
             dlg.CenterOnParent()
             dlg.ShowModal()
             dlg.Destroy()
@@ -680,7 +699,7 @@ class LeftTree(CT.CustomTreeCtrl):
         corpus = self.page.corpus
         tgenpath = os.path.join(self.page.parametres['pathout'], 'tgen.csv')        
         if not os.path.exists(tgenpath) :
-            message = wx.MessageDialog(self.parent, _(u"No TGen yet !"), style = wx.ICON_EXCLAMATION | wx.OK) 
+            message = wx.MessageDialog(self.parent, _(u"No TGen yet !").decode('utf8'), style = wx.ICON_EXCLAMATION | wx.OK) 
             message.ShowModal()
             message.Destroy()
         else :
@@ -720,7 +739,7 @@ class LeftTree(CT.CustomTreeCtrl):
         else :
             name = 'name'
         oldname = pydata[name]
-        dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', oldname)
+        dlg = wx.TextEntryDialog(self, _("New Name").decode('utf8'), _(u'Rename').decode('utf8'), oldname)
         if dlg.ShowModal() == wx.ID_OK:
             newname = dlg.GetValue()
             dlg.Destroy()
@@ -732,6 +751,12 @@ class LeftTree(CT.CustomTreeCtrl):
             self.history.update(pydata)
             self.SetItemText(self.current, newname)
             self.EnsureVisible(self.current)
+    
+    def OnOpenFolder(self, evt):
+        try :
+            open_folder(os.path.dirname(self.pydata['ira']))
+        except :
+            print 'cannot open folder %s' % self.pydata.get('ira', 'noirapath')
 
     def OnItemBackground(self, event):
 
@@ -1087,11 +1112,15 @@ class LeftTree(CT.CustomTreeCtrl):
 
         if pydata is not None :
             if 'corpus_name' in pydata or 'corpus' in pydata :
-                self.ira.ShowMenu('text', True)
                 self.ira.ShowMenu('matrix', False)
+                self.ira.ShowMenu('text', True)
             if 'matrix_name' in pydata or 'matrix' in pydata:
                 self.ira.ShowMenu('text', False)
-                self.ira.ShowMenu('matrix', True)                
+                self.ira.ShowMenu('matrix', True)
+            if 'uuid' in pydata :
+                if pydata['uuid'] in ['textroot', 'matroot'] :
+                    self.ira.ShowMenu('text', False)
+                    self.ira.ShowMenu('matrix', False)             
             self.pydata = pydata
             if pydata['uuid'] in self.parent.history.opened :
                 for i in range(self.parent.nb.GetPageCount()) :