X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=layout.py;h=3f9dfe0878b07729879c24aba6f287ed56770ef4;hp=669b2781f82cf403218715b175ab0abfffd361de;hb=655d1e1ab00740c37712f476dc89dff7965c2161;hpb=0bb1e9556fdbb07e171b663ffcea149692a8a49f diff --git a/layout.py b/layout.py index 669b278..3f9dfe0 100644 --- a/layout.py +++ b/layout.py @@ -45,6 +45,8 @@ class GraphPanelAfc(wx.Panel): self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier")) self.labels = [] self.listimg = [] + self.buts = [] + self.list_graph = list_graph self.TabCHD = self.parent.GetParent() self.nb = self.TabCHD.GetParent() self.ira = self.nb.GetParent() @@ -53,10 +55,15 @@ class GraphPanelAfc(wx.Panel): self.butafc = wx.BitmapButton(self, -1, afc_img) self.Bind(wx.EVT_BUTTON, self.afc_graph, self.butafc) self.dirout = os.path.dirname(self.Dict['ira']) + b = 0 for i in range(0,len(list_graph)): if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) : self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY))) self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1])) + self.buts.append(wx.Button(self.panel_1, wx.ID_DELETE, name = `i - b`)) + else : + self.list_graph.pop(i) + b += 1 self.param = { 'typegraph' : 0, 'width' : 800, @@ -65,8 +72,10 @@ class GraphPanelAfc(wx.Panel): 'qui' : 0, 'do_select_nb' : 0, 'do_select_chi' : 0, + 'do_select_chi_classe' : 0, 'select_nb' : 50, 'select_chi' : 4, + 'nbchic' : 30, 'over' : 0, 'cex_txt' : 0, 'txt_min' : 5, @@ -89,6 +98,7 @@ class GraphPanelAfc(wx.Panel): self.panel_1.SetScrollRate(20, 20) def __do_layout(self): + log.info('do layout') self.sizer_1 = wx.BoxSizer(wx.VERTICAL) self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL) self.sizer_3 = wx.BoxSizer(wx.VERTICAL) @@ -96,10 +106,37 @@ class GraphPanelAfc(wx.Panel): for i in range(0, len(self.listimg)): self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0) self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + self.sizer_3.Add(self.buts[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + self.Bind(wx.EVT_BUTTON, self.on_delete_image, self.buts[i]) self.panel_1.SetSizer(self.sizer_3) self.sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0) self.SetSizer(self.sizer_2) + def on_delete_image(self, event) : + image_id = int(event.GetEventObject().GetName()) + image_path = self.list_graph[image_id][0] + message = 'This file will be delete : %s.\nAre you sure ?' % os.path.join(self.dirout, image_path) + dial = wx.MessageDialog(self, message, style = wx.YES_NO) + res = dial.ShowModal() + if res == wx.ID_YES : + dial.Destroy() + log.info('delete image %i' % image_id) + oldimg = self.listimg.pop(image_id) + oldimg.Destroy() + oldlab = self.labels.pop(image_id) + oldlab.Destroy() + No = [but.Destroy() for but in self.buts] + self.buts = [wx.Button(self.panel_1, wx.ID_DELETE, name = `i`) for i, img in enumerate(self.listimg)] + todel = self.list_graph.pop(image_id) + os.remove(os.path.join(self.dirout, todel[0])) + print_liste(self.Dict[self.itempath], self.list_graph) + self.__do_layout() + self.sizer_3.Fit(self.panel_1) + self.Layout() + else : + dial.Destroy() + + def afc_graph(self,event): #dirout = os.path.dirname(self.Dict['ira']) while os.path.exists(os.path.join(self.dirout,'graph_afc_'+str(self.afcnb)+'.png')): @@ -116,8 +153,10 @@ class GraphPanelAfc(wx.Panel): 'qui' : dial.choice2.GetSelection(), 'do_select_nb' : dial.check1.GetValue(), 'do_select_chi' : dial.check2.GetValue(), + 'do_select_chi_classe' : dial.check_chic.GetValue(), 'select_nb' : dial.spin_nb.GetValue(), 'select_chi' : dial.spin_chi.GetValue(), + 'nbchic' : dial.spin_nbchic.GetValue(), 'over' : dial.check3.GetValue(), 'cex_txt' : dial.check4.GetValue(), 'txt_min' : dial.spin_min.GetValue(), @@ -142,6 +181,12 @@ class GraphPanelAfc(wx.Panel): afc <- afcf afc_table <- afcf_table chistabletot <- specfp + infp <- which(is.infinite(chistabletot) & chistabletot > 0) + infm <- which(is.infinite(chistabletot) & chistabletot < 0) + chistabletot[infp] <- 0 + chistabletot[infm] <- 0 + chistabletot[infp] <- max(chistabletot) + 1 + chistabletot[infm] <- min(chistabletot) - 1 """ elif self.itempath == 'liste_graph_afct' : txt +=""" @@ -171,11 +216,15 @@ class GraphPanelAfc(wx.Panel): if self.param['over'] : txt += u' - Eviter les recouvrements' if self.param['cex_txt'] : txt += u' - taille du texte proportionnel à la masse' if self.param['tchi'] : txt += u' - taille du texte proportionnel au chi2 d\'association' - list_graph = read_list_file(self.DictPathOut[self.itempath], self.coding) - list_graph.append([self.fileout, txt]) - print_liste(self.DictPathOut[self.itempath], list_graph) - self.sizer_3.Add(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(self.fileout, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0) - self.sizer_3.Add(wx.StaticText(self.panel_1,-1, txt), 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + #list_graph = read_list_file(self.DictPathOut[self.itempath], self.coding) + self.list_graph.append([self.fileout, txt]) + print_liste(self.DictPathOut[self.itempath], self.list_graph) + self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(self.fileout, wx.BITMAP_TYPE_ANY))) + self.sizer_3.Add( self.listimg[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + self.labels.append(wx.StaticText(self.panel_1,-1, txt)) + self.sizer_3.Add(self.labels[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + self.buts.append(wx.Button(self.panel_1, wx.ID_DELETE, name = `len(self.list_graph) - 1`)) + self.sizer_3.Add(self.buts[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0) self.sizer_3.Fit(self.panel_1) self.Layout() @@ -227,6 +276,7 @@ class OpenCHDS(): self.pathout.basefiles(ChdTxtPathOut) DictPathOut = self.pathout self.DictPathOut = DictPathOut + self.dictpathout = DictPathOut self.parent = parent Profile = DictPathOut['PROFILE_OUT'] @@ -258,8 +308,8 @@ class OpenCHDS(): DictProfile = ReadProfileAsDico(self, Profile, Alceste, self.encoding) self.DictProfile = DictProfile - print 'lecture des antiprofils' - DictAnti = ReadProfileAsDico(self, AntiProfile, Alceste, self.encoding) + #print 'lecture des antiprofils' + #DictAnti = ReadProfileAsDico(self, AntiProfile, Alceste, self.encoding) panel = wx.Panel(parent, -1) sizer1 = wx.BoxSizer(wx.VERTICAL) @@ -341,7 +391,7 @@ class OpenCHDS(): panel.ProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition) panel.ProfNB.SetArtProvider(aui.ChromeTabArt()) #self.ProfNB.SetTabCtrlHeight(100) - panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition) + #panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition) if os.path.exists(DictPathOut['prof_seg']) : prof_seg = ReadProfileAsDico(self, DictPathOut['prof_seg'], False, self.encoding) self.prof_seg_nb = aui.AuiNotebook(panel, -1, wx.DefaultPosition) @@ -349,18 +399,17 @@ class OpenCHDS(): dlg.Update(3+i, 'Classe %i' %(i+1)) ind = '/'.join(DictProfile[str(i + 1)][0][0:2]) indpour = ' - '.join([ind, DictProfile[str(i + 1)][0][2]]) - print 'construction liste classe %i' % i self.tabprofile = ProfListctrlPanel(self.parent, self, DictProfile[str(i + 1)], Alceste, i + 1) - self.tabantiprofile = ProfListctrlPanel(self.parent, self, DictAnti[str(i + 1)], Alceste, i + 1) + #self.tabantiprofile = ProfListctrlPanel(self.parent, self, DictAnti[str(i + 1)], Alceste, i + 1) panel.ProfNB.AddPage(self.tabprofile, 'classe %s %s(%s%%)' % (str(i + 1), sep, indpour)) - panel.AntiProfNB.AddPage(self.tabantiprofile, 'classe %s' % str(i + 1)) + #panel.AntiProfNB.AddPage(self.tabantiprofile, 'classe %s' % str(i + 1)) if os.path.exists(DictPathOut['prof_seg']) : self.tab_prof_seg = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1) self.prof_seg_nb.AddPage(self.tab_prof_seg, 'classe %i' % (i + 1)) if clnb > 2 : self.TabAFC = aui.AuiNotebook(panel.TabChdSim, -1, wx.DefaultPosition) - + log.info('read AFC') list_graph=read_list_file(DictPathOut['liste_graph_afc'], self.encoding) self.tabAFCGraph = GraphPanelAfc(self.TabAFC, DictPathOut, list_graph, self.clnb, coding=self.encoding) self.TabAFC.AddPage(self.tabAFCGraph, 'AFC') @@ -368,13 +417,13 @@ class OpenCHDS(): if os.path.exists(self.DictPathOut['afc_facteur']) : dictrow, first = ReadList(self.DictPathOut['afc_facteur'], self.encoding) self.TabAFC_facteur = ListForSpec(self.parent, parametres, dictrow, first) - dictrow, first = ReadList(self.DictPathOut['afc_row'], self.encoding) - self.TabAFC_ligne = ListForSpec(self.parent, self.parametres, dictrow, first) - dictrow, first = ReadList(self.DictPathOut['afc_col'], self.encoding) - self.TabAFC_colonne = ListForSpec(parent, self.parametres, dictrow, first) + #dictrow, first = ReadList(self.DictPathOut['afc_row'], self.encoding) + #self.TabAFC_ligne = ListForSpec(self.parent, self.parametres, dictrow, first) + #dictrow, first = ReadList(self.DictPathOut['afc_col'], self.encoding) + #self.TabAFC_colonne = ListForSpec(parent, self.parametres, dictrow, first) self.TabAFC.AddPage(self.TabAFC_facteur, 'Facteurs') - self.TabAFC.AddPage(self.TabAFC_colonne, u'Colonnes') - self.TabAFC.AddPage(self.TabAFC_ligne, u'Lignes') + #self.TabAFC.AddPage(self.TabAFC_colonne, u'Colonnes') + #self.TabAFC.AddPage(self.TabAFC_ligne, u'Lignes') sizer_3 = wx.BoxSizer(wx.VERTICAL) self.parent.nb_panel_2 = wx.Panel(panel.TabChdSim, -1) @@ -387,7 +436,7 @@ class OpenCHDS(): self.parent.Bind(wx.EVT_BUTTON, self.onsimi, self.parent.button_simi) panel.TabChdSim.AddPage(panel.ProfNB, 'Profils') - panel.TabChdSim.AddPage(panel.AntiProfNB, 'Antiprofils') + #panel.TabChdSim.AddPage(panel.AntiProfNB, 'Antiprofils') dlg.Update(4 + self.clnb, 'Affichage...') if clnb > 2 : panel.TabChdSim.AddPage(self.TabAFC, 'AFC') @@ -456,11 +505,13 @@ class OpenCHDS(): dlg.Destroy() def onprofseg(self, event): - try : + #try : + print 'plus de bug profseg' + print self.parametres corpus = self.parent.nb.GetPage(self.parent.nb.GetSelection()).corpus - ProfileSegment(self.parent,corpus) - except : - BugReport(self.parent) + ProfileSegment(self.parent, self.dictpathout, self.parametres, corpus) + #except : + # BugReport(self.parent) def onproftype(self, event): try : @@ -612,7 +663,7 @@ class dolexlayout : class StatLayout: def __init__(self, ira, corpus, parametres): - self.pathout = PathOut(dirout = os.path.dirname(parametres['pathout'])) + self.pathout = PathOut(dirout = parametres['pathout']) self.corpus = corpus self.ira = ira self.read_result() @@ -758,21 +809,7 @@ class GraphPanelDendro(wx.Panel): self.make_param(dial) self.make_dendro() -class WordCloudLayout: - def __init__(self, ira, parent, filename): - self.dictpathout = parent.corpus.dictpathout - self.pathout = os.path.dirname(filename) - self.corpus = parent.corpus - # self.read_result() - self.Tab = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition) - list_graph = [['nuage_1.png', 'Nuage']] - self.TabStatTot = GraphPanel(ira.nb, self.dictpathout, list_graph) - #self.TabStatTot.write(self.result['glob']) - self.Tab.AddPage(self.TabStatTot, 'Nuage') - self.Tab.corpus = parent.corpus - ira.nb.AddPage(self.Tab, 'WordCloud %s' % parent.conf.get('wordcloud','corpus_name')) - ira.nb.SetSelection(ira.nb.GetPageCount() - 1) - ira.ShowAPane("Tab_content") + class OpenCorpus : def __init__(self, ira, parametres) : @@ -911,6 +948,28 @@ class DefaultTextLayout : def dolayout(self) : log.info('no layout yet') +class WordCloudLayout(DefaultTextLayout): + def dolayout(self): + #self.dictpathout = parent.corpus.dictpathout + #self.pathout = os.path.dirname(filename) + #self.corpus = parent.corpus + # self.read_result() + self.pathout.basefiles(simipath) + self.Tab = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition) +# if os.path.exists(self.pathout['liste_graph']) : +# list_graph = read_list_file(self.pathout['liste_graph']) +# else : +# list_graph = [['','']] + list_graph = [['nuage_1.png', 'Nuage']] + self.TabStatTot = GraphPanel(self.ira.nb, self.pathout, list_graph) + #self.TabStatTot.write(self.result['glob']) + self.Tab.AddPage(self.TabStatTot, 'Nuage') + self.Tab.corpus = self.corpus + self.Tab.parametres = self.parametres + self.ira.nb.AddPage(self.Tab, 'WordCloud %s' % self.parametres.get('corpus_name','corpus_name')) + self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1) + self.ira.ShowAPane("Tab_content") + class SimiLayout(DefaultTextLayout) : def dolayout(self) : self.pathout.basefiles(simipath) @@ -941,29 +1000,32 @@ class SimiLayout(DefaultTextLayout) : if self.actives is None : with codecs.open(self.pathout['actives.csv'], 'r', self.parametres['encoding']) as f : self.actives = f.read() - self.actives = [act for act in self.actives.splitlines()] + self.actives = self.actives.splitlines()#[act for act in self.actives.splitlines()] dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)]) - SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], selected = selected) - prep = PrepSimi(self.ira, self.parametres, indices_simi) - self.parametres = prep.parametres - script = PrintSimiScript(self) - script.make_script() - pid = exec_rcode(self.ira.RPath, script.scriptout, wait = True) - check_Rresult(self.ira, pid) - if self.parametres['type_graph'] == 1: - if os.path.exists(self.pathout['liste_graph']): - graph_simi = read_list_file(self.pathout['liste_graph']) - graph_simi.append([os.path.basename(script.filename), script.txtgraph]) - else : - graph_simi = [[os.path.basename(script.filename), script.txtgraph]] - print_liste(self.pathout['liste_graph'], graph_simi) - DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira']) - if self.parametres['type_graph'] == 1: - self.graphpan.sizer_3.Add(wx.StaticBitmap(self.graphpan.panel_1, -1, wx.Bitmap(script.filename, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0) - self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1, script.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0) - self.graphpan.sizer_3.Fit(self.graphpan.panel_1) - self.graphpan.Layout() - self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL)) + #res = SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], selected = selected, dlg = True) + #if res.ok : + prep = PrepSimi(self.ira, self, self.parametres,self.pathout['selected.csv'], self.actives, indices_simi, wordlist = dictcol, selected = selected) + if prep.val == wx.ID_OK : + self.parametres = prep.parametres + + script = PrintSimiScript(self) + script.make_script() + pid = exec_rcode(self.ira.RPath, script.scriptout, wait = True) + check_Rresult(self.ira, pid) + if self.parametres['type_graph'] == 1: + if os.path.exists(self.pathout['liste_graph']): + graph_simi = read_list_file(self.pathout['liste_graph']) + graph_simi.append([os.path.basename(script.filename), script.txtgraph]) + else : + graph_simi = [[os.path.basename(script.filename), script.txtgraph]] + print_liste(self.pathout['liste_graph'], graph_simi) + DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira']) + if self.parametres['type_graph'] == 1: + self.graphpan.sizer_3.Add(wx.StaticBitmap(self.graphpan.panel_1, -1, wx.Bitmap(script.filename, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1, script.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0) + self.graphpan.sizer_3.Fit(self.graphpan.panel_1) + self.graphpan.Layout() + self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL)) def export(self, evt) : pass