Merge branch '3.0' of http://www.iramuteq.org/git/iramuteq into 3.0
[iramuteq] / layout.py
index d437c4b..fec0197 100644 (file)
--- a/layout.py
+++ b/layout.py
@@ -38,6 +38,7 @@ from PrintRScript import write_afc_graph, print_simi3d, PrintSimiScript
 from profile_segment import ProfileSegment
 from listlex import *
 from Liste import *
+from elcategorizator import ElCategorizator
 from search_tools import SearchFrame
 from dialog import PrefGraph, PrefExport, PrefSimpleFile, PrefDendro, SimpleDialog, ImageViewer
 from guifunct import SelectColumn, PrepSimi, PrefSimi, redosimi
@@ -250,7 +251,7 @@ class GraphPanelAfc(wx.Panel):
                 """
             txt += write_afc_graph(self)
             filetmp = tempfile.mktemp()
-            with open(filetmp, 'w') as f :
+            with open(filetmp, 'w', encoding='utf8') as f :
                 f.write(txt)
             pid = exec_rcode(self.ira.RPath, filetmp)
             check_Rresult(self.ira, pid)
@@ -419,7 +420,7 @@ class OpenCHDS():
         for i in range(0, clnb) :
             clusternames[i] = ' '.join(['%i' % (i + 1), _('Cluster'),  '%i' % (i + 1)])
         if os.path.exists(self.pathout['classes_names.txt']) :
-            with codecs.open(self.pathout['classes_names.txt'], 'r', self.parent.syscoding) as f :
+            with open(self.pathout['classes_names.txt'], 'r', encoding='utf8') as f :
                 clusternames_ = f.read()
             clusternames_ =  dict([[i, ' '.join([repr(i + 1), line])] for i, line in enumerate(clusternames_.splitlines())])
             clusternames.update(clusternames_)
@@ -430,7 +431,7 @@ class OpenCHDS():
         panel = wx.Panel(parent, -1)
         sizer1 = wx.BoxSizer(wx.VERTICAL)
         if os.path.exists(DictPathOut['pre_rapport']):
-            with codecs.open(DictPathOut['pre_rapport'], 'r') as f :
+            with open(DictPathOut['pre_rapport'], 'r', encoding='utf8') as f :
                 txt = f.read()
             self.debtext = txt
         else :
@@ -543,7 +544,7 @@ class OpenCHDS():
             self.parametres['tgenspec'] = os.path.join(self.parametres['pathout'], 'tgenchi2.csv')
             TgenLayout(panel)
         if os.path.exists(self.dictpathout['translations.txt']) :
-            with codecs.open(self.dictpathout['translations.txt'], 'r', 'utf8') as f:
+            with open(self.dictpathout['translations.txt'], 'r', encoding='utf8') as f:
                 translist = f.read()
             translist = [line.split('\t') for line in translist.splitlines()]
             for line in translist :
@@ -562,7 +563,7 @@ class OpenCHDS():
 
     def opentrans(self, trans) :
         prof = ReadProfileAsDico(self.dictpathout[trans[0]], False)
-        with codecs.open(self.dictpathout[trans[1]], 'r') as f :
+        with open(self.dictpathout[trans[1]], 'r', encoding='utf8') as f :
             lems = f.read()
         lems = [line.split('\t') for line in lems.splitlines()]
         lems = dict(lems)
@@ -633,7 +634,7 @@ def PrintRapport(self, corpus, parametres, istxt = True):
 
     txt += ''.join([sep, '###########################', sep, _('time'), ' : %s' % parametres.get('time', ''), sep, '###########################', sep])
     # ecriture du resultat dans le fichier
-    with open(self.pathout['pre_rapport'], 'w') as f :
+    with open(self.pathout['pre_rapport'], 'w', encoding='utf8') as f :
         f.write(txt)
 
 
@@ -735,6 +736,7 @@ class dolexlayout :
         self.dictpathout = StatTxtPathOut(parametres['pathout'])
         #self.corpus.read_corpus_from_shelves(self.corpus.dictpathout['db'])
         self.parent = ira
+        self.corpus.parametres['syscoding'] = 'UTF8'
         self.encoding = self.corpus.parametres['syscoding']
         self.parametres = parametres
         self.DictSpec, first = ReadList(self.dictpathout['tablespecf'], self.corpus.parametres['syscoding'])
@@ -989,7 +991,7 @@ class GraphPanelDendro(wx.Panel):
             """ % (ffr(self.dictpathout['RData.RData']), ffr(self.ira.RscriptsPath['Rgraph']), ffr(fileout), width, height, svg, type_dendro, bw)
         tmpfile = tempfile.mktemp()
         # ecriture du fichier de script à éxécuter
-        with open(tmpfile, 'w') as f :
+        with open(tmpfile, 'w', encoding='utf8') as f :
             f.write(txt)
         # dialogue d'attente
         busy = wx.BusyInfo(_("Please wait..."), self.parent)
@@ -1204,7 +1206,7 @@ def blender(self):
     """
     # ecriture du fichier de script à éxécuter
     filetmp = tempfile.mktemp()
-    with open(filetmp, 'w') as f :
+    with open(filetmp, 'w', encoding='utf8') as f :
         f.write(txt)
     exec_rcode(self.ira.RPath, filetmp)
     GraphToJson(nodesfile, edgesfile, jsonout)
@@ -1324,7 +1326,7 @@ class SimiLayout(DefaultTextLayout) :
         #saveAsGEXF(graph, filepath = fileout)
         """ % (ffr(self.pathout['RData.RData']), ffr(self.parent.RscriptsPath['simi']), fileout)
         filetmp = tempfile.mktemp()
-        with open(filetmp, 'w') as f :
+        with open(filetmp, 'w', encoding='utf8') as f :
             f.write(txt)
         exec_rcode(self.ira.RPath, filetmp)
         mss = wx.MessageDialog(self.ira, fileout, _('File exported'), wx.OK)
@@ -1397,6 +1399,11 @@ class ProtoLayout(DefaultMatLayout) :
         #self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
         #self.ira.ShowAPane("Tab_content")
 
+class CateLayout(DefaultMatLayout) :
+
+    def dolayout(self) :
+        TabCate = ElCategorizator(self.ira.nb, self.pathout, self.tableau)
+        self.ira.nb.AddPage(TabCate, ' - '.join([_('ElCaTeGoRiZaToR'), self.parametres['name']]))
 
 class SimiMatLayout(DefaultMatLayout) :
 
@@ -1422,7 +1429,7 @@ class SimiMatLayout(DefaultMatLayout) :
         #self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
 
     def redosimi(self,evt) :
-        with open(self.pathout['selected.csv'],'r') as f :
+        with open(self.pathout['selected.csv'],'r', encoding='utf8') as f :
             selected = f.read()
         selected = [int(val) for val in selected.splitlines()]
         #if self.actives is None :
@@ -1435,6 +1442,7 @@ class SimiMatLayout(DefaultMatLayout) :
             actives = [[val, self.tableau.actives[val]] for val in self.tableau.actives]
         #self.tableau.make_listactives()
         actives = dict([[i, val] for i, val in enumerate(actives)])
+        print(actives)
         #dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
         self.dial = PrefSimi(self.parent, -1, self.parametres, self.indices, wordlist = actives, selected = selected, actives = self.tableau.listactives)
         self.dial.CenterOnParent()
@@ -1449,7 +1457,7 @@ class SimiMatLayout(DefaultMatLayout) :
                 indexes.append(self.dial.listcol.getColumnText(last,0))
             self.column = [self.tableau.listactives.index(val) for val in indexes]
             self.column.sort()
-            with open(self.pathout['selected.csv'], 'w') as f :
+            with open(self.pathout['selected.csv'], 'w', encoding='utf8') as f :
                 f.write('\n'.join([repr(val) for val in self.column]))
             self.make_param()
             self.dial.Destroy()
@@ -1577,7 +1585,7 @@ class SimiMatLayout(DefaultMatLayout) :
         #saveAsGEXF(graph, filepath = fileout)
         """ % (ffr(self.pathout['RData.RData']), ffr(self.parent.RscriptsPath['simi']), fileout)
         filetmp = tempfile.mktemp()
-        with open(filetmp, 'w') as f :
+        with open(filetmp, 'w', encoding='utf8') as f :
             f.write(txt)
         exec_rcode(self.ira.RPath, filetmp)
         mss = wx.MessageDialog(self.ira, fileout, _('File exported'), wx.OK)