multisplit
[iramuteq] / analyse_merge.py
1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
5 #License: GNU/GPL
6
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
10 import os
11 from time import sleep
12
13 #------------------------------------
14 # import des modules wx
15 #------------------------------------
16 import wx
17
18 #------------------------------------
19 # import des fichiers du projet
20 #------------------------------------
21 from chemins import PathOut
22 from functions import exec_rcode, check_Rresult
23 from dialog import MergeDialog
24 from PrintRScript import MergeGraphes
25
26 def merge_graphes(lgraphes):
27     script = MergeGraphes({'lgraphes':lgraphes, 'grapheout' : '/tmp/graphe.graphml'}) 
28     script.make_script()
29     script.write()
30     return script
31
32 class AnalyseMerge :
33     def __init__(self, ira, parametres, dlg = None):
34         self.ira = ira
35         self.dlg = dlg
36         self.parametres = parametres
37         if 'pathout' not in self.parametres :
38             self.parametres['pathout'] = PathOut(self.parametres['fileout'], analyse_type = self.parametres['type'], dirout = os.path.dirname(self.parametres['fileout'])).mkdirout()
39             self.pathout = PathOut(analyse_type = self.parametres['type'], dirout = self.parametres['pathout'])
40         else :
41             self.pathout = PathOut(dirout = self.parametres['pathout'], analyse_type = self.parametres['type'])
42         if self.doparametres(dlg=dlg) is not None :
43             script = merge_graphes(self.parametres['graphs'])
44             self.doR(script.scriptout, dlg=False)
45             print('fini')
46
47     def doparametres(self, dlg=None):
48         if dlg is not None :
49             dial = MergeDialog(self.ira)
50             res = dial.ShowModal()
51             if res == wx.ID_OK :
52                 self.parametres['graphs'] = [graph.GetPath() for graph in dial.graphs if graph.GetPath() != '']
53                 return True
54             # pas besoin d'un dial.Destroy() ???
55         return True
56             
57     def doR(self, Rscript, wait = False, dlg = None, message = '') :
58         #log.info('R code...')
59         pid = exec_rcode(self.ira.RPath, Rscript, wait = wait)
60         while pid.poll() is None :
61             if dlg :
62                 self.dlg.Pulse(message)
63                 sleep(0.2)
64             else :
65                 sleep(0.2)
66         return check_Rresult(self.ira, pid)