...
[iramuteq] / functions.py
index 480f277..730d135 100644 (file)
@@ -64,7 +64,7 @@ class History :
             tosave['corpus'] = analyse['corpus']
             tosave['name'] = analyse['name']
             acorpus_uuid =  analyse['corpus']
-            if acorpus_uuid in self.ordercorpus :
+            if acorpus_uuid in self.corpus :
                 if 'analyses' in self.history[self.ordercorpus[acorpus_uuid]] :
                     self.history[self.ordercorpus[acorpus_uuid]]['analyses'].append(tosave)
                 else :
@@ -264,7 +264,7 @@ def treat_line_alceste(i, line) :
         line[5] = str(float(line[5].replace(',', '.')))[0:7]
     return [i, int(line[0]), int(line[1]), float(line[2]), float(line[3]), line[6], line[4], line[5]]
 
-def ReadProfileAsDico(parent, File, Alceste=False, encoding = sys.getdefaultencoding()):
+def ReadProfileAsDico(File, Alceste=False, encoding = sys.getdefaultencoding()):
     #print 'lecture des profils : ReadProfileAsDico'
     #if Alceste :
     #    print 'lecture du dictionnaire de type'
@@ -274,7 +274,6 @@ def ReadProfileAsDico(parent, File, Alceste=False, encoding = sys.getdefaultenco
     dictlem = {}
     print 'lecture des profiles'
     #encoding = sys.getdefaultencoding()
-    print encoding
     FileReader = codecs.open(File, 'r', encoding)
     Filecontent = FileReader.readlines()
     FileReader.close()
@@ -298,11 +297,11 @@ def ReadProfileAsDico(parent, File, Alceste=False, encoding = sys.getdefaultenco
         DictProfile[cluster] = [valclusters[i]] + prof[i]
     return DictProfile
 
-def GetTxtProfile(dictprofile) :
+def GetTxtProfile(dictprofile, cluster_size) :
     proflist = []
     for classe in range(0, len(dictprofile)) :
         prof = dictprofile[str(classe + 1)]
-        clinfo = prof[0]
+        clinfo = cluster_size[classe]
         proflist.append('\n'.join([' '.join(['classe %i' % (classe + 1), '-', '%s uce sur %s - %s%%' % (clinfo[0], clinfo[1], clinfo[2])]), '\n'.join(['%5s|%5s|%6s|%6s|%8s|%8s|%20s\t%10s' % tuple([str(val) for val in line]) for line in prof if len(line)==8])]))
     return '\n\n'.join(proflist)
 
@@ -389,23 +388,14 @@ def BugReport(parent, error = None):
     txt += exc
 
     dial = BugDialog(parent)
-    #for line in formatExceptionInfo():
-    #    if type(line) == type([]):
-    #        for don in line:
-    #            txt += don.replace('    ', ' ')
-    #    else:
-    #        txt += line + '\n'
     if 'Rerror' in dir(parent) :
         txt += parent.Rerror
         parent.Rerror = ''
-    #if error is not None :
-    #    txt += '\n%s\n' %error
-    print formatExceptionInfo()
-    log.error(txt)
+    log.info(txt)
     dial.text_ctrl_1.write(txt)
     dial.CenterOnParent()
     dial.ShowModal()
-    #raise Exception('Bug')
+    dial.Destroy()
     
 def PlaySound(parent):
     if parent.pref.getboolean('iramuteq', 'sound') :
@@ -463,6 +453,12 @@ def ReadList(filein, encoding = sys.getdefaultencoding()):
         i += 1
     return dict, first
 
+def exec_RCMD(rpath, command) :
+    log.info('R CMD INSTALL %s' % command)
+    rpath = rpath.replace('\\','\\\\')
+    error = call(["%s" % rpath, 'CMD', 'INSTALL', "%s" % command])
+    return error
+
 def exec_rcode(rpath, rcode, wait = True, graph = False):
     log.info("R Script : %s" % rcode)
     needX11 = False
@@ -515,20 +511,27 @@ def check_Rresult(parent, pid) :
     if isinstance(pid, Popen) :
         if pid.returncode != 0 :
             error = pid.communicate()
+            print error
             error = [str(error[0]), error[1]]
             if error[1] is None :
                 error[1] = 'None'
             parent.Rerror = '\n'.join([str(pid.returncode), '\n'.join(error)])
-            try :
-                raise Exception('\n'.join(u'Erreur R', '\n'.join(error[1:])))
-            except :
-                BugReport(parent)
+            #try :
+            raise Exception('\n'.join([u'Erreur R', '\n'.join(error[1:])]))
+            return False
+            #except :
+            #    BugReport(parent)
+        else :
+            return True
     else :
         if pid != 0 :
-            try :
-                raise Exception(u'Erreur R')
-            except :
-                BugReport(parent)
+            #try :
+            raise Exception(u'Erreur R')
+            return False
+            #except :
+            #    BugReport(parent)
+        else :
+            return True
 
 def print_liste(filename,liste):
     with open(filename,'w') as f :
@@ -541,9 +544,9 @@ def read_list_file(filename, encoding = sys.getdefaultencoding()):
         ncontent=[line.replace('\n','').split(';') for line in content if line.strip() != '']
     return ncontent
         
-class MessageImage(wx.Dialog):
+class MessageImage(wx.Frame):
     def __init__(self, parent,title, size):
-        wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_DIALOG_STYLE )
+        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_FRAME_STYLE )
         self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
         self.imageFile = False
         self.imagename = u"chi_classe.png"