X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=tree.py;h=65907054c1d5e236eb49025537481265a4b7cbca;hp=ef324e06f2820948919038116633435dfe36437c;hb=5d84083b41b807307732adb78e1be7fd3e3ff004;hpb=d33694ef233bd4a28e69d88e9eef3c5c129442fe diff --git a/tree.py b/tree.py index ef324e0..6590705 100644 --- a/tree.py +++ b/tree.py @@ -10,7 +10,7 @@ import webbrowser import wx.lib.agw.customtreectrl as CT import logging from openanalyse import OpenAnalyse -from corpusNG import Corpus, copycorpus +from corpus import Corpus, copycorpus from functions import DoConf, GetTxtProfile from profile_segment import ProfileSegment, ProfilType from search_tools import SearchFrame @@ -114,7 +114,7 @@ class LeftTree(CT.CustomTreeCtrl): 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) @@ -129,11 +129,17 @@ class LeftTree(CT.CustomTreeCtrl): 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) @@ -244,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) @@ -252,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): @@ -319,19 +340,19 @@ 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 : + 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) @@ -343,9 +364,7 @@ class LeftTree(CT.CustomTreeCtrl): 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) @@ -354,6 +373,17 @@ class LeftTree(CT.CustomTreeCtrl): 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") @@ -401,7 +431,7 @@ class LeftTree(CT.CustomTreeCtrl): 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()) @@ -501,6 +531,22 @@ class LeftTree(CT.CustomTreeCtrl): 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): colourdata = wx.ColourData() @@ -623,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() @@ -654,21 +700,24 @@ class LeftTree(CT.CustomTreeCtrl): dlg.Destroy() def AddAnalyse(self, parametres, itemParent = None, bold = True) : - uuid = parametres['corpus'] - 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']) + 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) @@ -733,18 +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) - self.OnSelChanged(pydata = pydata) + 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")