X-Git-Url: http://iramuteq.org/git?p=iramuteq;a=blobdiff_plain;f=layout.py;h=8cfcd962ed5ce26ee61cc3f3d3595411bf3e07c7;hp=9611dbb85f92a0c995f49a26aef0aec33f9637d6;hb=ad8fe486b34f1cee918ea8564bf909e30cd25328;hpb=be2de22859c8f59abe9e1082981e4c3a62e9b7ca diff --git a/layout.py b/layout.py index 9611dbb..8cfcd96 100644 --- a/layout.py +++ b/layout.py @@ -6,8 +6,11 @@ import os import wx -#import wx.lib.agw.aui as aui -import agw.aui as aui +import wx.lib.hyperlink as hl +if wx.__version__ >= '2.11' : + import wx.lib.agw.aui as aui +else : + import aui from chemins import ConstructPathOut, ChdTxtPathOut, FFF, ffr, PathOut, StatTxtPathOut, simipath from ConfigParser import ConfigParser from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf, indices_simi, check_Rresult, progressbar @@ -21,12 +24,11 @@ from Liste import * from search_tools import SearchFrame from dialog import PrefGraph, PrefExport, PrefSimpleFile, PrefDendro from guifunct import SelectColumn, PrepSimi -from corpusNG import Corpus +from corpus import Corpus import datetime import sys import tempfile import shutil -#import webbrowser import codecs import logging @@ -59,7 +61,11 @@ class GraphPanelAfc(wx.Panel): todel = [] 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))) + filename, ext = os.path.splitext(list_graph[i][0]) + if ext == '.svg' : + self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, os.path.join(self.dirout,list_graph[i][0]), URL=os.path.join(self.dirout,list_graph[i][0]))) + else : + 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 : @@ -89,6 +95,7 @@ class GraphPanelAfc(wx.Panel): 'facteur' : [1,2,3], 'alpha' : 10, 'clnb' : clnb, + 'svg' : 0, } self.__set_properties() @@ -100,7 +107,6 @@ 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) @@ -129,17 +135,11 @@ class GraphPanelAfc(wx.Panel): oldlab.Destroy() oldbut = self.buts.pop(image_id) oldbut.Show(False) - #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)] for i, but in enumerate(self.buts) : but.SetName(`i`) 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.sizer_1.Destroy() - #self.sizer_2.Destroy() - #self.sizer_3.Destroy() - #self.__do_layout() self.sizer_3.Fit(self.panel_1) self.Layout() else : @@ -155,6 +155,10 @@ class GraphPanelAfc(wx.Panel): dial.CenterOnParent() val = dial.ShowModal() if val == wx.ID_OK : + if dial.choix_format.GetSelection() == 0 : + svg = 0 + else : + svg = 1 self.param = {'typegraph' : dial.choicetype.GetSelection(), 'width' : dial.spin1.GetValue(), 'height' : dial.spin2.GetValue(), @@ -177,7 +181,8 @@ class GraphPanelAfc(wx.Panel): 'facteur' : [dial.spin_f1.GetValue(),dial.spin_f2.GetValue(), dial.spin_f3.GetValue()], 'clnb' : self.clnb, 'film' : str(dial.film.GetValue()).upper(), - 'alpha' : dial.slider_sphere.GetValue() + 'alpha' : dial.slider_sphere.GetValue(), + 'svg' : svg } self.nb.parent = self.ira self.DictPathOut = self.Dict @@ -190,12 +195,6 @@ 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 +=""" @@ -205,9 +204,8 @@ class GraphPanelAfc(wx.Panel): """ txt += write_afc_graph(self) filetmp = tempfile.mktemp() - file = open(filetmp,'w') - file.write(txt) - file.close() + with open(filetmp, 'w') as f : + f.write(txt) pid = exec_rcode(self.ira.RPath, filetmp) check_Rresult(self.ira, pid) if self.param['typegraph'] == 0 : @@ -226,9 +224,15 @@ class GraphPanelAfc(wx.Panel): 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) - self.list_graph.append([self.fileout, txt]) + if self.param['svg'] : + filename, ext = os.path.splitext(self.fileout) + self.fileout = filename + '.svg' + self.list_graph.append([os.path.basename(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))) + if not self.param['svg'] : + self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(self.fileout, wx.BITMAP_TYPE_ANY))) + else : + self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, self.fileout, URL=self.fileout)) 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) @@ -246,7 +250,7 @@ class GraphPanel(wx.ScrolledWindow): self.Dict = dico self.txt = txt self.parent = parent - self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier")) + self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.FONTWEIGHT_BOLD, 0, "courier")) self.labels = [] self.listimg = [] self.dirout = os.path.dirname(self.Dict['ira']) @@ -301,16 +305,16 @@ class OpenCHDS(): Profile = DictPathOut['PROFILE_OUT'] AntiProfile = DictPathOut['ANTIPRO_OUT'] + self.encoding = self.corpus.parametres['syscoding'] if isinstance(self.corpus, Corpus) : - self.encoding = self.corpus.parametres['syscoding'] self.corpus.make_ucecl_from_R(self.pathout['uce']) - elif 'tableau' in dir(gparent) : - self.encoding = gparent.tableau.parametres['syscoding'] + corpname = self.corpus.parametres['corpus_name'] + else : + corpname = self.corpus.parametres['name'] clnb = parametres['clnb'] dlg = progressbar(self, maxi = 4 + clnb) self.clnb = clnb - corpname = self.corpus.parametres['corpus_name'] print 'lecture des profils' dlg.Update(2, u'lecture des profils') @@ -334,12 +338,14 @@ class OpenCHDS(): if isinstance(self.corpus, Corpus) : panel.corpus = self.corpus - panel.dictpathout = self.DictPathOut - panel.pathout = self.DictPathOut - panel.parent = self.parent - panel.DictProfile = self.DictProfile - panel.cluster_size = self.cluster_size - panel.debtext = self.debtext + else : + panel.tableau = self.corpus + panel.dictpathout = self.DictPathOut + panel.pathout = self.DictPathOut + panel.parent = self.parent + panel.DictProfile = self.DictProfile + panel.cluster_size = self.cluster_size + panel.debtext = self.debtext # self.ID_rapport = wx.NewId() # #rap_img = wx.Image(os.path.join(self.parent.images_path,'icone_rap_16.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap() @@ -363,8 +369,11 @@ class OpenCHDS(): if isinstance(self.corpus, Corpus) : panel.TabChdSim.corpus = corpus panel.TabChdSim.corpus.dictpathout = self.DictPathOut - panel.parametres = self.parametres - self.panel = panel + else : + panel.TabChdSim.tableau = corpus + panel.TabChdSim.tableau.dictpathout = self.DictPathOut + panel.parametres = self.parametres + self.panel = panel self.notenb = self.parent.nb.GetPageCount() @@ -540,7 +549,7 @@ class OpenCHDS(): -def PrintRapport(self, corpus, parametres, txt = True): +def PrintRapport(self, corpus, parametres, istxt = True): #if sys.platform == 'win32': # sep = '\r\n' #else: @@ -552,10 +561,10 @@ def PrintRapport(self, corpus, parametres, txt = True): """ % datetime.datetime.now().ctime() - totocc = corpus.gettotocc() - if txt : - txt += u'nombre d\'uci: %i%s' % (corpus.getucinb(), sep) - txt += u'nombre d\'uce: %i%s' % (corpus.getucenb(), sep) + if istxt : + totocc = corpus.gettotocc() + txt += u'nombre de textes: %i%s' % (corpus.getucinb(), sep) + txt += u'nombre de segments de textes: %i%s' % (corpus.getucenb(), sep) txt += u'nombre de formes: %i%s' % (len(corpus.formes), sep) txt += u'nombre d\'occurrences: %i%s' % (totocc, sep) txt += u'moyenne d\'occurrences par forme: %f%s' % (float(totocc) / float(len(self.corpus.formes)), sep) @@ -565,31 +574,28 @@ def PrintRapport(self, corpus, parametres, txt = True): txt += u'nombre de formes actives de fréquence >= %i: %i%s' % (parametres['eff_min_forme'], parametres['nbactives'], sep) txt += u'moyenne d\'occurrences par uce :%f%s' % (float(totocc) / float(corpus.getucenb()), sep) if 'tailleuc1' in parametres : - if parametres['classif_mode'] != 0 : - txt += u'taille uc1 : %i\n' % parametres['tailleuc1'] - else: - txt += u'taille uc1 / uc2: %i / %i - %i / %i%s' % (parametres['tailleuc1'], parametres['tailleuc2'], parametres['lenuc1'], parametres['lenuc2'], sep) - elif not txt : + if parametres['classif_mode'] == 0 : + txt += u'taille rst1 / rst2: %i / %i - %i / %i%s' % (parametres['tailleuc1'], parametres['tailleuc2'], parametres['lenuc1'], parametres['lenuc2'], sep) + else : self.Ucenb = self.nbind txt += u'nombre d\'individus : %i%s' % (self.nbind, sep) txt += u'nombre de classes : %i%s' % (self.clnb, sep) - if txt : + if istxt : txt += u'nombre de classes : %i%s' % (parametres['clnb'], sep) if parametres['classif_mode'] == 0 or parametres['classif_mode'] == 1 : - txt += u'%i uce classées sur %i (%.2f%%)%s' % (sum([len(cl) for cl in corpus.lc]), corpus.getucenb(), (float(sum([len(cl) for cl in corpus.lc])) / float(corpus.getucenb())) * 100, sep) + txt += u'%i segments classés sur %i (%.2f%%)%s' % (sum([len(cl) for cl in corpus.lc]), corpus.getucenb(), (float(sum([len(cl) for cl in corpus.lc])) / float(corpus.getucenb())) * 100, sep) elif self.parametres['classif_mode'] == 2 : - txt += u'%i uci classées sur %i (%.2f%%)%s' % (sum([len(cl) for cl in corpus.lc]), corpus.getucinb(), (float(sum([len(cl) for cl in corpus.lc]))) / float(corpus.getucinb()) * 100, sep) - elif analyse == 'quest' : + txt += u'%i textes classés sur %i (%.2f%%)%s' % (sum([len(cl) for cl in corpus.lc]), corpus.getucinb(), (float(sum([len(cl) for cl in corpus.lc]))) / float(corpus.getucinb()) * 100, sep) + else : txt += u'%i uce classées sur %i (%.2f%%)%s' % (self.ucecla, self.Ucenb, (float(self.ucecla) / float(self.Ucenb)) * 100, sep) txt += """ ########################### temps d'analyse : %s ########################### -""" % parametres['time'] - file = open(self.pathout['pre_rapport'], 'w') - file.write(txt) - file.close() +""" % parametres.get('time', '') + with open(self.pathout['pre_rapport'], 'w') as f : + f.write(txt) class dolexlayout : def __init__(self, ira, corpus, parametres): @@ -683,12 +689,13 @@ class GraphPanelDendro(wx.Panel): self.dirout = os.path.dirname(self.dictpathout['ira']) self.list_graph = list_graph self.parent = self.GetParent()#parent - self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier")) + self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Arial")) self.labels = [] self.listimg = [] self.tabchd = self.parent.GetParent() self.ira = self.tabchd.GetParent() self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL) + self.panel_1.SetBackgroundColour('white') self.deb = wx.StaticText(self.panel_1, -1, txt) dendro_img = wx.Image(os.path.join(self.ira.images_path,'but_dendro.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap() self.butdendro = wx.BitmapButton(self, -1, dendro_img)