X-Git-Url: http://www.iramuteq.org/git?a=blobdiff_plain;f=tabsimi.py;h=e8220373fac6f42edd09dbc6ad7d71b23bdc7f00;hb=refs%2Fheads%2F3.0;hp=081b2faebc244ba5eb3f51c2875cfb418a5aabaf;hpb=7007f89913612375b1f1d34c71193ba8257f5091;p=iramuteq diff --git a/tabsimi.py b/tabsimi.py index 081b2fa..e822037 100644 --- a/tabsimi.py +++ b/tabsimi.py @@ -1,40 +1,51 @@ -#!/bin/env python # -*- coding: utf-8 -*- #Author: Pierre Ratinaud -#Copyright (c) 2009-2010 Pierre Ratinaud -#Lisense: GNU/GPL +#Copyright (c) 2008-2020 Pierre Ratinaud +#modification pour python 3 : Laurent Mérat, 6x7 - mai 2020 +#License: GNU/GPL -from chemins import ConstructPathOut, simipath, ffr -from functions import print_liste, exec_rcode, read_list_file, check_Rresult, indices_simi, treat_var_mod -from dialog import SelectColDial, FreqDialog -from guifunct import PrefSimi -from analysematrix import AnalyseMatrix -from PrintRScript import PrintSimiScript -from listlex import * -import wx -#if wx.__version__ >= '2.11' : -# import wx.lib.agw.aui as aui -#else : -# import aui +#------------------------------------ +# import des modules python +#------------------------------------ import os import tempfile import datetime -from ConfigParser import RawConfigParser from time import sleep from uuid import uuid4 +import langue +langue.run() + +#------------------------------------ +# import des modules wx +#------------------------------------ +import wx + +#------------------------------------ +# import des fichiers du projet +#------------------------------------ +from chemins import ConstructPathOut, simipath, ffr, PathOut +from functions import print_liste, exec_rcode, read_list_file, check_Rresult, indices_simi, treat_var_mod, normpath_win32 +from dialog import SelectColDial, FreqDialog +from guifunct import PrefSimi +from analysematrix import AnalyseMatrix +from PrintRScript import PrintSimiScript +from listlex import * +from configparser import RawConfigParser + class DoSimi(AnalyseMatrix): - def __init__(self, parent, param = None, isopen = False, fromprof = False, pathout = False, filename ='', gparent = False, wordgraph = False, listactives = False, actives = False, cmd = False, openfromprof=False, tableau = None): -#------------------------------------------------------------------- - self.fromprof = fromprof - self.wordgraph = wordgraph - self.listactives = listactives - self.actives = actives - self.openfromprof = openfromprof - self.cmd = cmd - if param is not None and fromprof: - self.paramsimi = param + + def doparametres(self, dlg = None) : + self.fromprof = self.parametres.get('fromprof', False) + self.wordgraph = self.parametres.get('wordgraph', False) + self.listactives = self.parametres.get('listactives', False) + self.actives = self.parametres.get('actives', False) + self.openfromprof = self.parametres.get('openfromprof', False) + self.cmd = self.parametres.get('cmd', False) + self.dirout = self.parametres.get('pathout', False) + if self.fromprof: + self.paramsimi = self.parametres else : self.paramsimi = {'coeff' : 0, 'layout' : 2, @@ -70,39 +81,31 @@ class DoSimi(AnalyseMatrix): 'communities' : 0, } self.indices = indices_simi - #if fromprof : - # self.parent = parent.parent - # self.Source = parent - #else : - self.parent = parent self.Source = None - - self.RPath = self.parent.PathPath.get('PATHS', 'rpath') - if not isopen : - #if not fromprof : - # self.tableau = self.parent.tableau - #else : - # self.tableau = parent.tableau - if tableau is not None : - self.tableau = tableau - else : + if self.dirout : + self.pathout = PathOut(dirout = self.dirout) + if not self.parametres.get('isopen', False) : + if self.tableau is None : self.tableau = parent.tableau - self.tableau.parametre['mineff'] = 0 - if not fromprof : - dialcol = FreqDialog(self.parent, -1, self.tableau.get_colnames(), u"Sélectionnez les colonnes", size=(600, 250)) - dialcol.CenterOnParent() + self.tableau.parametres['mineff'] = 0 + if not self.fromprof : + dialcol = FreqDialog(self.parent, self.tableau.get_colnames(), _("Select columns"), size=(600, 250), showNA = False) + dialcol.CenterOnParent() res = dialcol.ShowModal() else : res = wx.ID_OK if res == wx.ID_OK : if not self.actives : - self.tableau.selected_col = dialcol.list_box_1.GetSelections() + self.tableau.selected_col = dialcol.m_listBox1.GetSelections() actives = self.tableau.getactlistfromselection(self.tableau.selected_col) else : actives = self.actives + if isinstance(actives, dict) : + actives = [[val, actives[val][0]] for val in actives] + self.tableau.actives = dict(actives) self.tableau.make_listactives() actives = dict([[i, val] for i, val in enumerate(actives)]) - self.dial = PrefSimi(parent, -1, self.paramsimi, self.indices, wordlist = actives) + self.dial = PrefSimi(self.parent, -1, self.paramsimi, self.indices, wordlist = actives) self.dial.CenterOnParent() self.val = self.dial.ShowModal() if self.val == wx.ID_OK : @@ -116,44 +119,44 @@ class DoSimi(AnalyseMatrix): self.column = [self.tableau.listactives.index(val) for val in indexes] self.column.sort() self.paramsimi = self.make_param() - self.parametres = self.paramsimi - self.parametres['type'] = 'simimatrix' - self.parametres['pathout'] = ConstructPathOut(self.tableau.parametre['filename'], 'SimiMatrix') - self.parametres['filename'] = self.tableau.parametres['filename'] + self.parametres.update(self.paramsimi) + #self.parametres['type'] = 'simimatrix' + if not self.pathout : + self.parametres['pathout'] = ConstructPathOut(self.parametres['pathout'], 'SimiMatrix') + else : + self.parametres['pathout'] = self.dirout + self.pathout.createdir(self.parametres['pathout']) + self.pathout.dirout = self.parametres['pathout'] self.dial.Destroy() - dlg = wx.ProgressDialog("Traitements", - "Veuillez patienter...", - maximum=4, - parent=self.parent, - style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME - ) - dlg.Center() - AnalyseMatrix.__init__(self, parent, self.tableau, self.paramsimi, dlg = dlg) + #self.doanalyse2() else : self.dial.Destroy() + self.parametres = None + return False else : dialcol.Destroy() + self.parametres = None + return False def doanalyse(self) : - self.pathout.basefiles(simipath) - with open(self.pathout['selected.csv'], 'w') as f : - f.write('\n'.join([`val` for val in self.column])) - + with open(normpath_win32(self.pathout['selected.csv']), 'w', encoding='utf8') as f : + f.write('\n'.join([repr(val) for val in self.column])) count = 1 keepGoing = self.dlg.Update(count) - #---------------------------------------------------------------- + #---------------------------------------------------------------- self.DictForme = {} self.Min = 10 self.Linecontent = [] - #-------------------------------------------------------- + #-------------------------------------------------------- count += 1 #if not self.fromprof : - #self.pathout = ConstructPathOut(self.tableau.parametre['filename'], 'Simi') + #self.pathout = ConstructPathOut(self.tableau.parametres['filename'], 'Simi') #self.DictPathOut = construct_simipath(self.pathout) - self.parent.tableau.dictpathout = self.pathout - self.dlg.Update(count, u"passage en O/1") - self.parent.tableau.make_01_from_selection(self.tableau.selected_col) + self.tableau.dictpathout = self.pathout + self.dlg.Update(count, "passage en O/1") + if not self.fromprof : + self.tableau.make_01_from_selection(self.tableau.selected_col) #self.Linecontent = parent.table #self.ListTo01Form() #else : @@ -165,15 +168,15 @@ class DoSimi(AnalyseMatrix): self.script.make_script() #self.PrintScript() count += 1 - self.dlg.Update(count, u"R...") + self.dlg.Update(count, "R...") #self.DoR(script.scriptout, dlg = self.dlg, message = 'R...') self.tmpfile = self.script.scriptout self.DoR(self.dlg) self.addgraph() - self.tableau.save_tableau(self.pathout['db']) + self.tableau.save_tableau(self.pathout['analyse.db']) #self.make_ira() - count += 1 - self.dlg.Update(count, u"") + #count += 1 + #self.dlg.Update(count, u"") self.dlg.Destroy() #self.dial.Destroy() #self.dolayout() @@ -181,36 +184,6 @@ class DoSimi(AnalyseMatrix): fromprof = True else: fromprof = False - #OpenAnalyse(self.parent, self.DictPathOut['ira'], False, simifromprof=fromprof) -# else : -# self.tableau = gparent.tableau -# if 'corpus' in dir(gparent) : -# self.Source = gparent -# self.tableau.parametre['mineff'] = 0 -# self.DictPathOut = construct_simipath(os.path.abspath(os.path.dirname(filename))) -# self.dolayout() -# self.paramsimi['first'] = False -# self.paramsimi['coeff'] = int(param.get('simi', 'indice')) -# self.paramsimi['layout'] = int(param.get('simi', 'layout')) -# self.paramsimi['seuil_ok'] = param.getboolean('simi', 'seuil_ok') -# self.paramsimi['seuil'] = int(param.get('simi', 'seuil')) -# if param.get('simi', 'wordgraph') == 'False' : -# self.wordgraph = False -# else : -# self.wordgraph = param.get('simi', 'wordgraph') -# if 'listet' in dir(self.tableau) : -# self.paramsimi['stars'] = self.tableau.listet -# self.paramsimi['bystar'] = False -# self.paramsimi['cexfromchi'] = True -# self.paramsimi['tvprop'] = False -# self.paramsimi['sfromchi'] = False -# self.paramsimi['coeff_te'] = True -# self.paramsimi['coeff_tv'] = True -# self.paramsimi['coeff_tv_nb'] = 0 -# self.paramsimi['label_e'] = False -# self.paramsimi['width'] = 1000 -# self.paramsimi['height'] = 1000 - def make_param(self) : if self.paramsimi['first'] : @@ -218,7 +191,6 @@ class DoSimi(AnalyseMatrix): else : keep_coord = self.dial.check_coord.GetValue() #self.select = self.dial.check_colch.GetValue() - paramsimi = {'coeff' : self.dial.choice1.GetSelection(), 'layout' : self.dial.choice2.GetSelection(), 'type_graph' : self.dial.choice3.GetSelection(), @@ -257,32 +229,14 @@ class DoSimi(AnalyseMatrix): if 'sfromchi' in self.paramsimi : paramsimi['sfromchi'] = self.dial.checki.GetValue() if 'vlabcolor' in self.paramsimi : - paramsimi['vlabcolor'] = self.paramsimi['vlabcolor'] + paramsimi['vlabcolor'] = self.paramsimi['vlabcolor'] if 'check_bystar' in dir(self.dial) : paramsimi['bystar'] = self.dial.check_bystar.GetValue() paramsimi['stars'] = self.paramsimi['stars'] + if 'tmpchi' in self.paramsimi : + paramsimi['tmpchi'] = self.paramsimi['tmpchi'] return paramsimi - -# def make_ira(self): -# self.tableau.save_tableau(self.DictPathOut['db']) -# conf = RawConfigParser() -# conf.read(self.DictPathOut['ira']) -# if not 'simi' in conf.sections() : -# conf.add_section('simi') -# date = datetime.datetime.now().ctime() -# if self.fromprof : -# conf.set('simi', 'corpus', self.Source.corpus.parametres['uuid']) -# conf.set('simi', 'uuid', str(uuid4())) -# conf.set('simi', 'date', str(date)) -# conf.set('simi', 'indice', self.paramsimi['coeff']) -# conf.set('simi','layout', self.paramsimi['layout']) -# conf.set('simi', 'seuil_ok', self.paramsimi['seuil_ok']) -# conf.set('simi', 'seuil', str(self.paramsimi['seuil'])) -# conf.set('simi', 'wordgraph', self.wordgraph) -# fileout = open(self.DictPathOut['ira'], 'w') -# conf.write(fileout) -# fileout.close() -# + def addgraph(self) : if self.parametres['type_graph'] == 1: if self.parametres['svg'] : @@ -296,22 +250,20 @@ class DoSimi(AnalyseMatrix): else : graph_simi = [[os.path.basename(fileout), self.script.txtgraph]] print_liste(self.DictPathOut['liste_graph'], graph_simi) - + def DoR(self, dlg): - if self.paramsimi['type'] == 1 : + if self.paramsimi['type_graph'] == 1 : graph = False wait = False else : graph = True wait = True - pid = exec_rcode(self.RPath, self.tmpfile, wait = wait, graph = graph) - if self.paramsimi['type'] == 1 : + pid = exec_rcode(self.ira.RPath, self.tmpfile, wait = wait, graph = graph) + if self.paramsimi['type_graph'] == 1 : while pid.poll() == None : if not self.cmd : - dlg.Pulse(u'R ...') + dlg.Pulse('R ...') sleep(0.2) else : sleep(0.2) check_Rresult(self.parent, pid) - -