Merge branch '3.0' of http://www.iramuteq.org/git/iramuteq into 3.0
authorpierre <pierre.ratinaud@univ-tlse2.fr>
Mon, 12 Feb 2024 15:29:16 +0000 (16:29 +0100)
committerpierre <pierre.ratinaud@univ-tlse2.fr>
Mon, 12 Feb 2024 15:29:16 +0000 (16:29 +0100)
Rscripts/CHD.R
Rscripts/chdquest.R
dialog.py
iramuteq.py
layout.py
tabchi2.py
tabfrequence.py
tableau.py
tree.py

index 4e64b01..e686637 100644 (file)
@@ -229,6 +229,7 @@ CHD<-function(data.in, x=9, mode.patate = FALSE, svd.method, libsvdc.path=NULL){
                        print('###################################')
                        print('longueur < 0')
                        malcl<-length(vdelta)
+
                        if ((it>1)&&(!is.logical(listsub[[it]]))&&(!is.logical(listsub[[it-1]]))){
                                if (all(listsub[[it]]==listsub[[(it-1)]])){
                                        malcl<-0
@@ -248,14 +249,14 @@ CHD<-function(data.in, x=9, mode.patate = FALSE, svd.method, libsvdc.path=NULL){
                        #t2<-dtable[dtable[,'cl']==clnb+1,][,-ncol(dtable)]
                    t1<-dtable[which(cl[,1]==clnb),]#[,-ncol(dtable)]
                        t2<-dtable[which(cl[,1]==clnb+1),]#[,-ncol(dtable)]
-            if (class(t1)=='numeric') {
+            if (inherits(t1, "numeric")) {
                 sc1 <- as.vector(t1)
                 nrowt1 <- 1
             } else {
                 sc1 <- colSums(t1)
                 nrowt1 <- nrow(t1)
             }
-            if (class(t2)=='numeric') {
+            if  (inherits(t2, "numeric")) {
                 sc2 <- as.vector(t2)
                 nrowt2 <- 1
             } else {
index b4c4a49..f40a368 100644 (file)
@@ -157,7 +157,7 @@ Rchdquest<-function(tableuc1,listeuce1,uceout ,nbt = 9, mincl = 2, mode.patate =
                        chitable[2,1]<-poids2[j]-chitable[1,1]
                        chitable[2,2]<-nrow(classeuce1)-poids2[j]-chitable[1,2]
                        chitest<-chisq.test(chitable,correct=FALSE)
-                       if ((chitable[1,1]-chitest$expected)<0) {
+                       if ((chitable[1,1]-chitest$expected[1,1])<0) {
                            chicroise[i,j]<--round(chitest$statistic,digits=7)
                        } else {
                            chicroise[i,j]<-round(chitest$statistic,digits=7)
index 4143526..54751ad 100755 (executable)
--- a/dialog.py
+++ b/dialog.py
@@ -190,9 +190,9 @@ class FileOptionDialog(wx.Dialog):
             grid_sizer.Add(label, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
             self.spin1 = wx.SpinCtrl(self, -1, '',size = wx.DefaultSize, min=1, max=500)
             grid_sizer.Add(self.spin1, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL, 5)
-        sizer.Add(grid_sizer, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)
+        sizer.Add(grid_sizer, 0, wx.GROW | wx.ALL, 5)
         line = wx.StaticLine(self, -1, size=(20, -1), style=wx.LI_HORIZONTAL)
-        sizer.Add(line, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5)
+        sizer.Add(line, 0, wx.GROW | wx.RIGHT | wx.TOP, 5)
         btnsizer = wx.StdDialogButtonSizer()
         if wx.Platform != "__WXMSW__":
             btn = wx.ContextHelpButton(self)
@@ -203,7 +203,7 @@ class FileOptionDialog(wx.Dialog):
         btn = wx.Button(self, wx.ID_CANCEL)
         btnsizer.AddButton(btn)
         btnsizer.Realize()
-        sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL, 5)
+        sizer.Add(btnsizer, 0,  wx.ALIGN_CENTER_HORIZONTAL, 5)
         self.SetSizer(sizer)
         sizer.Fit(self)
 
index a8afd32..3f5183b 100755 (executable)
@@ -752,16 +752,23 @@ class IraFrame(wx.Frame):
     # vu comme elle est écrite, impossible de gérer
     # l'affichage/masquage des toolbars en fonction du contexte
     def ShowMenu(self, menu, Show=True):
+        print("showmenu")
         if menu == 'text' :
             menu_pos = 4
             if Show :
                 self._mgr.GetPane('tb_text').Show()
+                self._mgr.GetPane('tb_mat').Hide()
+                self.mb.EnableTop(menu_pos, Show)
+                self.mb.EnableTop(3, False)
             else :
                 self._mgr.GetPane('tb_text').Hide()
         elif menu == 'matrix' :
             menu_pos = 3
             if Show :
                 self._mgr.GetPane('tb_mat').Show()
+                self._mgr.GetPane('tb_text').Hide()
+                self.mb.EnableTop(menu_pos, Show)
+                self.mb.EnableTop(4, False)
             else :
                 self._mgr.GetPane('tb_mat').Hide()
         elif menu == 'view' :
@@ -769,9 +776,9 @@ class IraFrame(wx.Frame):
         else :
             menu_pos = None
         if not menu_pos is None :
-            self.mb.EnableTop(menu_pos, Show)
+            #self.mb.EnableTop(menu_pos, Show)
             self.mb.Refresh()
-        #self._mgr.Update()
+        self._mgr.Update()
 
     #--------------------------------------------------------------------
     # fin de __init__ du wx.Frame
@@ -919,6 +926,7 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
 
     # action ou évènement ?
     def OnPageChanged(self, event) :
+        print("OnPageChange")
         new = event.GetSelection()
         nobject = event.GetEventObject()
         parent = nobject.GetParent()
@@ -927,14 +935,13 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
             if 'parametres' in dir(npage) :
                 #self.tree.GiveFocus(uuid=npage.parametres['uuid'])
                 if npage.parametres.get('matrix', False) :
-                    self.ShowMenu('text', False)
+                    #self.ShowMenu('text', False)
                     self.ShowMenu('matrix', True)
                 elif npage.parametres.get('corpus', False) :
                     self.ShowMenu('text')
-                    self.ShowMenu('matrix', False)
-        #self._mgr.Update()
-        #wx.CallAfter(self.nb.SendSizeEvent)
-        #self.Refresh()
+                    #self.ShowMenu('matrix', False)
+        wx.CallAfter(self.nb.SendSizeEvent)
+        self.Refresh()
 
     # action ou évènement ?
     def OnCloseTab(self, evt):
@@ -976,7 +983,6 @@ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, États-Unis."""
                 pane.Hide()
         self._mgr.GetPane(panel).Show()
         self._mgr.Update()
-        print('show a pane refresh')
         wx.CallAfter(self.nb.SendSizeEvent)
         self.Refresh()
 
index 7c7edd9..fec0197 100644 (file)
--- a/layout.py
+++ b/layout.py
@@ -251,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)
@@ -991,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)
@@ -1206,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)
@@ -1429,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 :
@@ -1442,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()
@@ -1456,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()
@@ -1584,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)
index 8d6f208..aa5ea7c 100755 (executable)
@@ -308,7 +308,7 @@ class ChiSquare(AnalyseMatrix):
         """ % (ffr(self.parametres['pathout']),ffr(self.OutFrame))
         tmpfile=tempfile.mktemp(dir=self.TEMPDIR)
         print(tmpfile)
-        tmpscript=open(tmpfile,'w')
+        tmpscript=open(tmpfile,'w', encoding='utf8')
         tmpscript.write(txt)
         tmpscript.close()
         pid = exec_rcode(self.RPath, tmpfile, wait = False)
@@ -334,7 +334,7 @@ class ChiSquare(AnalyseMatrix):
 
     def dolayout(self, option):
         ListFile=[False]
-        file=open(self.OutFrame,'r')
+        file=open(self.OutFrame,'r', encoding='utf8')
         content=file.readlines()
         file.close()
         lcont = [line.replace('"','').replace('\n','').split(';') for line in content]
@@ -381,7 +381,7 @@ class ChiSquare(AnalyseMatrix):
             allhtml.append(html_graphs)
         header="""
         <html>\n
-        <meta http-equiv="content-Type" content="text/html; charset=%s" />\n
+        <meta http-equiv="content-Type" content="text/html; charset=utf8" />\n
         <body>\n
         <h1>Test du Chi2</h1>\n
         <br>
@@ -391,12 +391,12 @@ class ChiSquare(AnalyseMatrix):
         <font color=blue>p &lt;= 0.05 mais il y a des valeurs théoriques &lt; 5</font><br>
         <font color=red>p &gt; 0.05</font>
         </td></tr></table><br><br>
-        """%self.parent.SysEncoding
+        """
         pretxt = '<br>\n'.join(links)+'<br><hr><br>\n'
         txt = '<br><hr><br>\n'.join(['<br><br>'.join([tab[i] for tab in allhtml]) for i,val in enumerate(res)])
         txt = header + pretxt + txt + '\n</body></html>'
         fileout=os.path.join(self.parametres['pathout'],'resultats-chi2.html')
-        with open(fileout, 'w') as f :
+        with open(fileout, 'w',encoding='utf8') as f :
             f.write(txt)
         ListFile.append(fileout)         
         return ListFile
index 9d58769..9e444f4 100644 (file)
@@ -124,7 +124,7 @@ class Frequences(AnalyseMatrix) :
     def dolayout(self):
         listtab = []
         tab = []
-        with open(self.outframe) as f :
+        with open(self.outframe, 'r', encoding='utf8') as f :
             content = f.read().splitlines()
         content.pop(0)
         content.pop(0)
@@ -144,10 +144,10 @@ class Frequences(AnalyseMatrix) :
         #    else :
         #        tab.append(ligne)
         pretexte = '''<html>
-        <meta http-equiv="content-Type" content="text/html; charset=%s" />
+        <meta http-equiv="content-Type" content="text/html; charset=utf8" />
         <body>\n<h1>Fréquences</h1>
         <a name="deb"></a><br>
-        ''' % self.parent.SysEncoding
+        ''' 
         for i in range(0, len(listtab)):
             pretexte += '<p><a href="#%s">%s</a></p>' % (str(i), self.listtitre[i])
             texte += '<hr size="5" align="center" width="50%" color="green">\n'
@@ -167,7 +167,7 @@ class Frequences(AnalyseMatrix) :
             """ % os.path.basename(self.fileforR[i])
             texte += '</body>\n</html>'
         fileout = os.path.join(self.pathout.dirout, 'resultats.html')
-        with open(fileout, 'w') as f :
+        with open(fileout, 'w', encoding='utf8') as f :
             f.write(pretexte + texte)
         #return fileout
 
@@ -183,7 +183,7 @@ class FreqMultiple(Frequences):
         freq = [[line[0], repr(line[1]), line[2], line[3], line[4]] for line in freq]
         freq.insert(0, ['mod', 'freq', 'percent of total', 'row number', 'percent of rows'])
         self.freq = freq
-        with open(self.pathout['frequences.csv'], 'w') as f :
+        with open(self.pathout['frequences.csv'], 'w', encoding='utf8') as f :
             f.write('\n'.join(['\t'.join(line) for line in freq]))
         self.rscript = FreqMultiScript(self)
         self.rscript.make_script()
@@ -192,10 +192,10 @@ class FreqMultiple(Frequences):
 
     def dolayout(self):
         pretexte = '''<html>
-        <meta http-equiv="content-Type" content="text/html; charset=%s" />
+        <meta http-equiv="content-Type" content="text/html; charset=utf8" />
         <body>\n<h1>Fréquences</h1>
         <a name="deb"></a><br>
-        ''' % self.parent.SysEncoding       
+        '''       
         txt = """
         <table>\n<tr><td>\n
         <table border=1><tr><td>
@@ -203,5 +203,5 @@ class FreqMultiple(Frequences):
         txt += '</td></tr><tr><td>'.join(['</td><td>'.join(line) for line in self.freq]) + '</td></tr></table></td></tr>'
         txt += '<tr><td><img src="%s" alt="graph"/></td><td><img src="%s" alt="graph"/></td></tr></table>' % (os.path.basename(self.pathout['barplotfreq.png']), os.path.basename(self.pathout['barplotrow.png']))
         txt += "</body>\n</html>"
-        with open(self.pathout['resultats.html'], 'w') as f :
+        with open(self.pathout['resultats.html'], 'w', encoding='utf8') as f :
             f.write(pretexte + txt)
index 7325279..1be437b 100644 (file)
@@ -211,7 +211,7 @@ class Tableau() :
         self.linecontent = [[val.replace('"','').replace(';',' ').replace('\t', ' ').strip() for val in line] for line in self.linecontent]
 
     def write_csvfile(self) :
-        with open(self.parametres['csvfile'], 'w') as f :
+        with open(self.parametres['csvfile'], 'w', encoding='utf8') as f :
             f.write('\n'.join(['\t'.join(line) for line in self.csvtable]))
 
     def make_tmpfile(self) :
@@ -237,7 +237,7 @@ class Tableau() :
         self.write_csvfile()
 
     def read_csvfile(self):
-        with codecs.open(self.parametres['csvfile'], 'r', self.parametres['syscoding']) as f:
+        with open(self.parametres['csvfile'], 'r', encoding='utf8') as f:
             self.csvtable = [line.split('\t') for line in f.read().splitlines()]
         self.linecontent = [line[1:] for line in self.csvtable]
         self.linecontent.pop(0)
@@ -301,7 +301,7 @@ class Tableau() :
         #out = [[self.rownames[i]] + out[i] for i in range(len(linecontent))]
         #out.insert(0,[self.idname] + self.listactives)
         out.insert(0, self.listactives)
-        with open(fileout, 'w') as f :
+        with open(fileout, 'w', encoding='utf8') as f :
             f.write('\n'.join([';'.join(line) for line in out]))
 
     def make_01_from_selection(self, listact, listsup = None, dowrite = True) :
@@ -329,15 +329,15 @@ class Tableau() :
         #table = [[self.rownames[i]] + table[i] for i in range(len(self.rownames))]
         #table.insert(0, [self.idname] + self.listactives)
         table.insert(0, self.listactives)
-        with open(fileout, 'w') as f:
+        with open(fileout, 'w', encoding='utf8') as f:
             f.write('\n'.join([';'.join(line) for line in table]))
 
     def printtable(self, filename, Table, sep = ';'):
-        with open(filename, 'w') as f :
+        with open(filename, 'w', encoding='utf8') as f :
             f.write('\n'.join([sep.join(line) for line in Table]))
 
     def buildprofil(self) :
-        with open(self.pathout['uce'], 'r') as filein :
+        with open(self.pathout['uce'], 'r', encoding='utf8') as filein :
             content = filein.readlines()
         content.pop(0)
         lsucecl = []
diff --git a/tree.py b/tree.py
index 4b61d84..d8f73a7 100755 (executable)
--- a/tree.py
+++ b/tree.py
@@ -1096,16 +1096,16 @@ class LeftTree(CT.CustomTreeCtrl):
         event.Skip()
 
     def OnSelChanged(self, event = None, pydata = None):
+        print("OnSelChange")
         if event is not None :
             item = event.GetItem()
             pydata = self.GetPyData(item)
-        print('selchange',pydata)
         if pydata is not None :
             if 'corpus_name' in pydata or 'corpus' in pydata :
-                self.ira.ShowMenu('matrix', False)
+                #self.ira.ShowMenu('matrix', False)
                 self.ira.ShowMenu('text', True)
             if 'matrix_name' in pydata or 'matrix' in pydata:
-                self.ira.ShowMenu('text', False)
+                #self.ira.ShowMenu('text', False)
                 self.ira.ShowMenu('matrix', True)
             if 'uuid' in pydata :
                 if pydata['uuid'] in ['textroot', 'matroot'] :
@@ -1120,7 +1120,7 @@ class LeftTree(CT.CustomTreeCtrl):
                             self.parent.nb.SetSelection(i)
                             break
         #self.parent._mgr.Update()
-        #wx.CallAfter(self.parent.nb.SendSizeEvent)
+        wx.CallAfter(self.parent.nb.SendSizeEvent)
         self.parent.Refresh()
         #if event is not None :
         #    event.Skip()
@@ -1134,7 +1134,7 @@ class LeftTree(CT.CustomTreeCtrl):
             else:
                 olditemtext = self.GetItemText(olditem)
             #self.log.info("OnSelChanging: From %s" % olditemtext + " To %s" % self.GetItemText(item) + "\n")
-        event.Skip()
+        #event.Skip()
 
     def OnBeginDrag(self, event):
         self.item = event.GetItem()