french dictionary
[iramuteq] / tabsimi.py
index d2facad..b34a107 100644 (file)
@@ -4,7 +4,7 @@
 #Copyright (c) 2009-2010 Pierre Ratinaud
 #Lisense: GNU/GPL
 
-from chemins import ConstructPathOut, simipath, ffr
+from chemins import ConstructPathOut, simipath, ffr, PathOut
 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
@@ -25,7 +25,7 @@ from uuid import uuid4
 
 
 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):
+    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
@@ -33,6 +33,7 @@ class DoSimi(AnalyseMatrix):
         self.actives = actives
         self.openfromprof = openfromprof
         self.cmd = cmd
+        self.dirout = pathout
         if param is not None and fromprof:
             self.paramsimi = param
         else :
@@ -70,26 +71,41 @@ 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
-           
+        #if fromprof :
+        #    self.parent = parent.parent
+        #    self.Source = parent
+        #else :
+        self.parent = parent   
+        self.Source = None
+        if pathout :
+            self.pathout = PathOut(dirout = pathout)
+
         self.RPath = self.parent.PathPath.get('PATHS', 'rpath')
         if not isopen :
-            if not fromprof :
-                self.tableau = self.parent.tableau
-            else :
+            #if not fromprof :
+            #    self.tableau = self.parent.tableau
+            #else :
+            #    self.tableau = parent.tableau
+            if tableau is not None :
+                self.tableau = tableau
+            else : 
                 self.tableau = parent.tableau
             self.tableau.parametre['mineff'] = 0
-            dialcol = FreqDialog(self.parent, -1, self.tableau.get_colnames(), u"Sélectionnez les colonnes", size=(600, 250))
-            dialcol.CenterOnParent()            
-            res = dialcol.ShowModal()
+            if not fromprof :
+                dialcol = FreqDialog(self.parent, -1, self.tableau.get_colnames(), u"Sélectionnez les colonnes", size=(600, 250))
+                dialcol.CenterOnParent()            
+                res = dialcol.ShowModal()
+            else :
+                res = wx.ID_OK
             if res == wx.ID_OK :
-                self.tableau.selected_col = dialcol.list_box_1.GetSelections()
-                actives = self.tableau.getactlistfromselection(self.tableau.selected_col)
+                if not self.actives :
+                    self.tableau.selected_col = dialcol.list_box_1.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)
@@ -108,7 +124,10 @@ class DoSimi(AnalyseMatrix):
                     self.paramsimi = self.make_param()
                     self.parametres = self.paramsimi
                     self.parametres['type'] = 'simimatrix'
-                    self.parametres['pathout'] = ConstructPathOut(self.tableau.parametre['filename'], 'SimiMatrix')
+                    if not pathout : 
+                        self.parametres['pathout'] = ConstructPathOut(self.tableau.parametre['filename'], 'SimiMatrix')
+                    else :
+                        self.parametres['pathout'] = self.dirout
                     self.parametres['filename'] = self.tableau.parametres['filename']
                     self.dial.Destroy()
                     dlg = wx.ProgressDialog("Traitements",
@@ -125,7 +144,6 @@ class DoSimi(AnalyseMatrix):
                 dialcol.Destroy()
 
     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]))
@@ -141,9 +159,10 @@ class DoSimi(AnalyseMatrix):
         #if not self.fromprof :
             #self.pathout = ConstructPathOut(self.tableau.parametre['filename'], 'Simi')
             #self.DictPathOut = construct_simipath(self.pathout)
-        self.parent.tableau.dictpathout = self.pathout
+        self.tableau.dictpathout = self.pathout
         self.dlg.Update(count, u"passage en O/1")
-        self.parent.tableau.make_01_from_selection(self.tableau.selected_col)
+        if not self.fromprof :
+            self.tableau.make_01_from_selection(self.tableau.selected_col)
             #self.Linecontent = parent.table
             #self.ListTo01Form()
         #else :