multisplit
[iramuteq] / profile_segment.py
index b7e1f24..e432d96 100644 (file)
@@ -1,19 +1,33 @@
-#!/bin/env python
 # -*- coding: utf-8 -*-
-# Author: Pierre Ratinaud
-# Copyright (c) 2010, Pierre Ratinaud
-# License: GNU/GPL
+#Author: Pierre Ratinaud
+#Copyright (c) 2008-2020 Pierre Ratinaud
+#modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
+#License: GNU/GPL
 
+#------------------------------------
+# import des modules python
+#------------------------------------
 import tempfile
-from ProfList import *
+from time import sleep
+
+#------------------------------------
+# import des modules wx
+#------------------------------------
 import wx
 import wx.lib.agw.aui as aui
+
+#------------------------------------
+# import des fichiers du projet
+#------------------------------------
+from ProfList import *
 from functions import exec_rcode, check_Rresult, ReadProfileAsDico, ReadList
 from listlex import *
 from dialog import PrefSegProf, PrefProfTypes
-from time import sleep
+from chemins import ffr
+
 
 class ProfileSegment() :
+
     def __init__(self, parent, pathout, parametres, corpus) :
         self.parent = parent
         self.corpus = corpus
@@ -31,10 +45,10 @@ class ProfileSegment() :
             self.eff = dial.spin_eff.GetValue()
             dial.Destroy()
             self.dlg = progressbar(self, maxi=4)
-            self.dlg.Update(1, u'Recherche des segments')
+            self.dlg.Update(1, 'Recherche des segments')
             self.make_table()
             self.make_prof()
-            self.dlg.Update(3, u'ouverture des profils')
+            self.dlg.Update(3, 'ouverture des profils')
             self.do_layout()
             self.dlg.Update(4, 'fini')
             self.dlg.Destroy()
@@ -46,34 +60,36 @@ class ProfileSegment() :
         txt = """
         load("%s")
         source("%s")
-        """ % (self.dictpathout['RData'], self.parent.RscriptsPath['chdfunct'])
+        """ % (ffr(self.dictpathout['RData']), ffr(self.parent.RscriptsPath['chdfunct']))
 
         txt += """
         dt <- read.csv2("%s", row.names = 1)
         to <- build.pond.prof(dt)
         PrintProfile(n1,to[4],NULL,to[5],NULL,clnb,"%s","%s")
-        """ % (self.corpus.dictpathout['segments_classes'], self.dictpathout['prof_seg'], self.dictpathout['antiprof_seg'])
+        """ % (ffr(self.corpus.dictpathout['segments_classes']), ffr(self.dictpathout['prof_seg']), ffr(self.dictpathout['antiprof_seg']))
         fo = tempfile.mktemp(dir=self.parent.TEMPDIR)
-        with open(fo, 'w') as f :
+        with open(fo, 'w', encoding='utf8') as f :
             f.write(txt)
         pid = exec_rcode(self.parent.RPath, fo, wait=False)
         while pid.poll() == None :
-            self.dlg.Pulse(u'Construction des profils...')
+            self.dlg.Pulse('Construction des profils...')
             sleep(0.2)
         check_Rresult(self.parent, pid)
 
     def do_layout(self) :
         SelectTab = self.parent.nb.GetSelection()
         page = self.parent.nb.GetPage(SelectTab).TabChdSim
-        prof_seg = ReadProfileAsDico(self.dictpathout['prof_seg'], True, self.parent.syscoding)
+        prof_seg = ReadProfileAsDico(self.dictpathout['prof_seg'], True, 'utf8')
         prof_seg_nb = aui.AuiNotebook(self.parent, -1, wx.DefaultPosition)
         for i in range(0, len(self.corpus.lc)) :
             ntab = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1)
             prof_seg_nb.AddPage(ntab, 'classe %i' % (i + 1))
-        page.AddPage(prof_seg_nb, u'Profils des segements répétés')
+        page.AddPage(prof_seg_nb, 'Profils des segements répétés')
         page.SetSelection(page.GetPageCount() - 1)
 
+
 class ProfilType() :
+
     def __init__(self, parent, corpus, parametres) :
         self.parent = parent
         self.corpus = corpus
@@ -93,11 +109,11 @@ class ProfilType() :
             # else :
             #    self.corpus.parametre['outprof'] = {self.outprof: alceste}
             self.dlg = progressbar(self, maxi=4)
-            self.dlg.Update(1, u'Recherche des types')
+            self.dlg.Update(1, 'Recherche des types')
             self.make_table()
-            self.dlg.Update(1, u'Construction des profils')
+            self.dlg.Update(1, 'Construction des profils')
             self.make_prof(alceste=alceste)
-            self.dlg.Update(3, u'Ouverture des profils')
+            self.dlg.Update(3, 'Ouverture des profils')
             self.do_layout(alceste=alceste)
             self.dlg.Update(4, 'fini')
             self.dlg.Destroy()
@@ -109,29 +125,28 @@ class ProfilType() :
         txt = """
         load("%s")
         source("%s")
-        """ % (self.corpus.dictpathout['RData'], self.parent.RscriptsPath['chdfunct'])
-
+        """ % (ffr(self.corpus.dictpathout['RData']), ffr(self.parent.RscriptsPath['chdfunct']))
         txt += """
         dt <- read.csv2("%s", row.names = 1)
-        """ % self.corpus.dictpathout['type_cl']
+        """ % ffr(self.corpus.dictpathout['type_cl'])
         if alceste :
             txt += """
             to <- build.pond.prof(dt)
             PrintProfile(n1,to[4],NULL,to[5],NULL,clnb,"%s","%s")
-            """ % (self.outprof, self.corpus.dictpathout['antiprof_type'])
+            """ % (ffr(self.outprof), ffr(self.corpus.dictpathout['antiprof_type']))
         else :
             txt += """
             to <- AsLexico2(dt)
             write.csv2(to[[1]], file = "%s")
-            """ % (self.outprof)
+            """ % (ffr(self.outprof))
             # write.csv2(to[[3]], file = "%s")
             # % (self.outprof)
         fo = tempfile.mktemp(dir=self.parent.TEMPDIR)
-        with open(fo, 'w') as f :
+        with open(fo, 'w', encoding='utf8') as f :
             f.write(txt)
         pid = exec_rcode(self.parent.RPath, fo, wait=False)
         while pid.poll() == None :
-            self.dlg.Pulse(u'Construction des profils...')
+            self.dlg.Pulse('Construction des profils...')
             sleep(0.2)
         check_Rresult(self.parent, pid)
 
@@ -146,9 +161,9 @@ class ProfilType() :
                 prof_seg_nb.AddPage(ntab, 'classe %i' % (i + 1))
         else :
             self.DictSpec, first = ReadList(self.outprof)
-            self.ListPan = ListForSpec(self.parent, self, self.DictSpec, first)
-            prof_seg_nb.AddPage(self.ListPan, u'Spécificités')
+            self.ListPan = ListForSpec(self.parent, self, self.DictSpec, first[1:])
+            prof_seg_nb.AddPage(self.ListPan, 'Spécificités')
 
-        page.AddPage(prof_seg_nb, u'Profils des types')
+        page.AddPage(prof_seg_nb, 'Profils des types')
         page.SetSelection(page.GetPageCount() - 1)