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
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
14 from time import sleep
19 #------------------------------------
20 # import des modules wx
21 #------------------------------------
23 import wx.lib.agw.hyperlink as hl
24 import wx.lib.agw.aui as aui
25 import wx.lib.agw.labelbook as LB
26 from wx.lib.agw.fmresources import *
28 #------------------------------------
29 # import des fichiers du projet
30 #------------------------------------
31 from chemins import ConstructPathOut, ChdTxtPathOut, FFF, ffr, PathOut, StatTxtPathOut, simipath
32 from configparser import ConfigParser
33 from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf,\
34 indices_simi, check_Rresult, progressbar, normpath_win32, TGen, ReadList, launchcommand
35 from ProfList import ProfListctrlPanel
36 from guiparam3d import param3d, simi3d
37 from PrintRScript import write_afc_graph, print_simi3d, PrintSimiScript
38 from profile_segment import ProfileSegment
41 from elcategorizator import ElCategorizator
42 from search_tools import SearchFrame
43 from dialog import PrefGraph, PrefExport, PrefSimpleFile, PrefDendro, SimpleDialog, ImageViewer
44 from guifunct import SelectColumn, PrepSimi, PrefSimi, redosimi
45 from webexport import WebExport
46 from corpus import Corpus
47 from sheet import MySheet
48 from graph_to_json import GraphToJson
49 from listlex2 import LexPanel
57 log = logging.getLogger('iramuteq.layout')
61 class GraphPanelAfc(wx.Panel):
63 def __init__(self, parent, dico, list_graph, clnb, itempath = 'liste_graph_afc', coding = sys.getdefaultencoding()):
64 wx.Panel.__init__(self,parent)
69 self.itempath = itempath
70 self.parent = self.GetParent()
71 self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "Arial"))
75 self.list_graph = list_graph
76 self.TabCHD = self.parent.GetParent()
77 self.nb = self.TabCHD.GetParent()
78 self.ira = self.nb.GetParent()
79 self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
80 afc_img = wx.Image(os.path.join(self.ira.images_path,'button_afc.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
81 self.butafc = wx.BitmapButton(self, -1, afc_img)
82 self.Bind(wx.EVT_BUTTON, self.afc_graph, self.butafc)
83 self.dirout = os.path.dirname(self.Dict['ira'])
86 for i in range(0,len(list_graph)):
87 if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
88 filename, ext = os.path.splitext(list_graph[i][0])
89 if ext == '.svg' or ext == '.html':
90 self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, os.path.join(self.dirout,list_graph[i][0]), URL=os.path.join(self.dirout,list_graph[i][0])))
92 self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY), name=repr(i-b)))
93 self.listimg[-1].Bind(wx.EVT_RIGHT_DOWN, self.onrightclick)
94 if os.path.exists(os.path.join(self.dirout,list_graph[i][0] + '_notplotted.csv')) :
95 txt = _("List of not plotted points : ") + '%s' % os.path.join(self.dirout,list_graph[i][0] + '_notplotted.csv')
98 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1] + txt))
99 self.buts.append(wx.Button(self.panel_1, wx.ID_DELETE, name = repr(i - b)))
103 self.list_graph = [graph for i, graph in enumerate(self.list_graph) if i not in todel]
104 self.param = { 'typegraph' : 0,
111 'do_select_chi_classe' : 0,
128 self.__set_properties()
131 def __set_properties(self):
132 self.panel_1.EnableScrolling(True,True)
133 #self.panel_1.SetSize((1000,1000))
134 self.panel_1.SetScrollRate(20, 20)
135 self.panel_1.SetFocus()
137 def __do_layout(self):
138 self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
139 self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
140 self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
141 self.sizer_2.Add(self.butafc, 0, 0, 0)
142 for i in range(0, len(self.listimg)):
143 self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
144 self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
145 self.sizer_3.Add(self.buts[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
146 self.Bind(wx.EVT_BUTTON, self.on_delete_image, self.buts[i])
147 self.panel_1.SetSizer(self.sizer_3)
148 self.sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0)
149 self.SetSizer(self.sizer_2)
151 def on_delete_image(self, event) :
152 image_id = int(event.GetEventObject().GetName())
153 image_path = self.list_graph[image_id][0]
154 message = _('This file will be delete : ') + '%s.\n' % os.path.join(self.dirout, image_path) + _('Are you sure ?')
155 dial = wx.MessageDialog(self, message, style = wx.YES_NO)
156 res = dial.ShowModal()
157 if res == wx.ID_YES :
159 log.info('delete image %i' % image_id)
160 oldimg = self.listimg.pop(image_id)
162 oldlab = self.labels.pop(image_id)
164 oldbut = self.buts.pop(image_id)
166 for i, but in enumerate(self.buts) :
168 self.listimg[i].SetName(repr(i))
169 todel = self.list_graph.pop(image_id)
170 os.remove(os.path.join(self.dirout, todel[0]))
171 print_liste(self.Dict[self.itempath], self.list_graph)
172 self.sizer_3.Fit(self.panel_1)
177 def onrightclick(self, event):
178 image_id = int(event.GetEventObject().GetName())
179 image_path = self.list_graph[image_id][0]
180 viewer = ImageViewer(self, {'tmpgraph' : os.path.join(self.dirout,image_path), 'svg': 'FALSE', 'wildcard': '*.*'}, self.labels[image_id].GetLabelText(), self.listimg[image_id].GetSize())
183 #print self.labels[image_id].GetLabelText()
185 def afc_graph(self,event):
186 #dirout = os.path.dirname(self.Dict['ira'])
187 dial = PrefGraph(self.parent,-1,self.param,'')
188 dial.CenterOnParent()
189 val = dial.ShowModal()
191 if dial.choix_format.GetSelection() == 0 :
195 typegraph = dial.choicetype.GetSelection()
200 if self.clnb <= 3 and typegraph == 1 :
206 while os.path.exists(os.path.join(self.dirout,'graph_afc_'+str(self.afcnb)+typefile)):
208 self.fileout = ffr(os.path.join(self.dirout,'graph_afc_'+str(self.afcnb)+typefile))
210 self.param = {'typegraph' : typegraph,
211 'width' : dial.spin1.GetValue(),
212 'height' : dial.spin2.GetValue(),
213 'what' : dial.choice1.GetSelection(),
214 'qui' : dial.choice2.GetSelection(),
215 'do_select_nb' : dial.check1.GetValue(),
216 'do_select_chi' : dial.check2.GetValue(),
217 'do_select_chi_classe' : dial.check_chic.GetValue(),
218 'select_nb' : dial.spin_nb.GetValue(),
219 'select_chi' : dial.spin_chi.GetValue(),
220 'nbchic' : dial.spin_nbchic.GetValue(),
221 'over' : dial.check3.GetValue(),
222 'cex_txt' : dial.check4.GetValue(),
223 'txt_min' : dial.spin_min.GetValue(),
224 'txt_max' : dial.spin_max.GetValue(),
225 'tchi' : dial.check_tchi.GetValue(),
226 'tchi_min' : dial.spin_min_tchi.GetValue(),
227 'tchi_max' : dial.spin_max_tchi.GetValue(),
228 'taillecar' : dial.spin3.GetValue(),
229 'facteur' : [dial.spin_f1.GetValue(),dial.spin_f2.GetValue(), dial.spin_f3.GetValue()],
231 'film' : str(dial.film.GetValue()).upper(),
232 'alpha' : dial.slider_sphere.GetValue(),
235 self.nb.parent = self.ira
236 self.DictPathOut = self.Dict
237 self.RscriptsPath = self.ira.RscriptsPath
240 """ % ffr(self.DictPathOut['RData'])
241 if self.itempath == 'liste_graph_afcf' :
244 afc_table <- afcf_table
245 chistabletot <- specfp
247 elif self.itempath == 'liste_graph_afct' :
250 afc_table <- afct_table
251 chistabletot <- spectp
253 txt += write_afc_graph(self)
254 filetmp = tempfile.mktemp()
255 with open(filetmp, 'w', encoding='utf8') as f :
257 pid = exec_rcode(self.ira.RPath, filetmp)
258 check_Rresult(self.ira, pid)
259 if self.param['typegraph'] != 1 :
261 if self.param['qui'] == 0 : value = 'actives'
262 if self.param['qui'] == 1 : value = 'supplémentaires'
263 if self.param['qui'] == 2 : value = 'étoilées'
264 if self.param['qui'] == 3 : value = 'classes'
266 if self.param['what'] == 0 : value = 'Coordonnées'
267 if self.param['what'] == 1 : value = 'Corrélations'
268 txt += value + ' - facteur %i / %i' % (self.param['facteur'][0], self.param['facteur'][1])
269 if self.param['do_select_nb'] : txt += ' - sélection de %i variables' % self.param['select_nb']
270 if self.param['do_select_chi'] : txt += ' - sélection des variables avec chi2 > %i ' % self.param['select_chi']
271 if self.param['over'] : txt += ' - Eviter les recouvrements'
272 if self.param['cex_txt'] : txt += ' - taille du texte proportionnel à la masse'
273 if self.param['tchi'] : txt += ' - taille du texte proportionnel au chi2 d\'association'
274 #list_graph = read_list_file(self.DictPathOut[self.itempath], self.coding)
275 if self.param['svg'] :
276 filename, ext = os.path.splitext(self.fileout)
277 self.fileout = filename + '.svg'
278 if self.param['typegraph'] == 2 :
279 parametres = {'gexffile' : self.fileout,
281 'nodemin': self.param['txt_min'],
282 'nodemax': self.param['txt_max'],
283 'bargraphw' : 60*int(self.param['clnb']),
285 web = WebExport(self.ira, parametres)
286 self.fileout = web.exportafc()
287 if self.param['typegraph'] == 3 :
288 fileout = os.path.join(os.path.basename(self.fileout), 'index.html')
290 fileout = os.path.basename(self.fileout)
291 self.list_graph.append([fileout, txt])
292 print_liste(self.DictPathOut[self.itempath], self.list_graph)
293 if self.param['svg'] or self.param['typegraph'] == 2:
294 self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, self.fileout, URL=self.fileout))
295 elif self.param['typegraph'] == 3 :
296 fileout = os.path.join(self.fileout,'index.html')
297 self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, fileout, URL=fileout))
299 self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(self.fileout, wx.BITMAP_TYPE_ANY), name=repr(len(self.list_graph) - 1)))
300 self.listimg[-1].Bind(wx.EVT_RIGHT_DOWN, self.onrightclick)
301 self.sizer_3.Add( self.listimg[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
302 self.labels.append(wx.StaticText(self.panel_1,-1, txt))
303 self.sizer_3.Add(self.labels[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
304 self.buts.append(wx.Button(self.panel_1, wx.ID_DELETE, name = repr(len(self.list_graph) - 1)))
305 self.sizer_3.Add(self.buts[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
306 self.sizer_3.Fit(self.panel_1)
309 self.panel_1.Scroll(0,self.panel_1.GetScrollRange(wx.VERTICAL))
310 # elif self.param['typegraph'] == 2 :
311 # parametres = {'gexffile' : self.fileout,
312 # 'titre': 'Le titre',
313 # 'nodemin': self.param['txt_min'],
314 # 'nodemax': self.param['txt_max'],
315 # 'bargraphw' : 60*int(self.param['clnb']),
317 # web = WebExport(self.ira, parametres)
318 # afcout = web.exportafc()
319 # dial = SimpleDialog(self.ira)
320 # dial.link.SetLabel(afcout)
321 # dial.link.SetURL(afcout)
326 class GraphPanel(wx.ScrolledWindow):
328 def __init__(self, parent, dico, list_graph, txt = '', style = wx.TAB_TRAVERSAL):
329 wx.ScrolledWindow.__init__(self, parent, style = style)
333 self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "Arial"))
336 self.dirout = os.path.dirname(self.Dict['ira'])
337 self.deb = wx.StaticText(self, -1, txt)
338 for i in range(0,len(list_graph)):
339 if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
340 filename, ext = os.path.splitext(list_graph[i][0])
342 self.listimg.append(hl.HyperLinkCtrl(self, -1, os.path.join(self.dirout,list_graph[i][0]), URL=os.path.join(self.dirout,list_graph[i][0])))
344 self.listimg.append(wx.StaticBitmap(self, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
345 self.labels.append(wx.StaticText(self, -1, list_graph[i][1]))
346 self.Bind(wx.EVT_MOTION, self.onMouseMove)
347 self.__set_properties()
350 def __set_properties(self):
351 self.EnableScrolling(True,True)
352 self.SetScrollRate(20, 20)
355 def __do_layout(self):
356 self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
357 self.sizer_2 = wx.BoxSizer(wx.VERTICAL)
358 self.sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
359 self.sizer_1.Add(self.deb)
360 for i in range(0, len(self.listimg)):
361 self.sizer_1.Add(self.listimg[i], 1, wx.ALIGN_CENTER_HORIZONTAL, 0)
362 self.sizer_1.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
363 self.sizer_2.Add(self.sizer_1, 1, wx.EXPAND, 0)
364 self.SetSizer(self.sizer_1)
365 self.sizer_1.Fit(self)
367 def onMouseMove(self, event):
370 def open_antiprofil(panel, AntiProfile, encoding, title = _("Antiprofiles"), translation = False, lems=None) :
372 DictAnti = ReadProfileAsDico(AntiProfile, True, encoding)
374 DictAnti = AntiProfile
375 panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
376 for i in range(0, panel.parametres['clnb']):
377 tabantiprofile = ProfListctrlPanel(panel.parent, panel, DictAnti[str(i + 1)], True, i + 1, translation = translation)
378 tabantiprofile.lems = lems
379 panel.AntiProfNB.AddPage(tabantiprofile, 'classe %s' % str(i + 1))
380 panel.TabChdSim.AddPage(panel.AntiProfNB, title)
382 def getlemgram(corpus, lem) :
383 if not lem[6] in corpus.lems :
386 return corpus.lems[lem[6]].gram
391 def __init__(self, parent, corpus, parametres, Alceste=False):
395 self.parametres = parametres
396 self.pathout = PathOut(parametres['ira'])
397 self.pathout.basefiles(ChdTxtPathOut)
398 DictPathOut = self.pathout
399 self.DictPathOut = DictPathOut
400 self.dictpathout = DictPathOut
401 self.Alceste = Alceste
402 Profile = DictPathOut['PROFILE_OUT']
403 AntiProfile = DictPathOut['ANTIPRO_OUT']
404 # self.encoding = self.parametres['encoding']
405 if isinstance(self.corpus, Corpus) :
406 self.corpus.make_ucecl_from_R(self.pathout['uce'])
407 corpname = self.corpus.parametres['corpus_name']
409 corpname = self.corpus.parametres['matrix_name']
410 if os.path.exists(self.pathout['analyse.db']) :
411 self.corpus.read_tableau(self.pathout['analyse.db'])
412 clnb = parametres['clnb']
413 dlg = progressbar(self, maxi = 4 + clnb)
415 print('lecture des profils')
416 dlg.Update(2, _("Reading profiles"))
417 DictProfile = ReadProfileAsDico(Profile, Alceste)
418 self.DictProfile = DictProfile
419 self.cluster_size = []
421 for i in range(0, clnb) :
422 clusternames[i] = ' '.join(['%i' % (i + 1), _('Cluster'), '%i' % (i + 1)])
423 if os.path.exists(self.pathout['classes_names.txt']) :
424 with open(self.pathout['classes_names.txt'], 'r', encoding='utf8') as f :
425 clusternames_ = f.read()
426 clusternames_ = dict([[i, ' '.join([repr(i + 1), line])] for i, line in enumerate(clusternames_.splitlines())])
427 clusternames.update(clusternames_)
428 #DictAnti = ReadProfileAsDico(self, AntiProfile, Alceste, self.encoding)
430 # preparation de l'affichage
432 panel = wx.Panel(parent, -1)
433 sizer1 = wx.BoxSizer(wx.VERTICAL)
434 if os.path.exists(DictPathOut['pre_rapport']):
435 with open(DictPathOut['pre_rapport'], 'r', encoding='utf8') as f :
440 # panel.chd_toolbar = wx.ToolBar(panel, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT | wx.TB_NODIVIDER)
441 # panel.chd_toolbar.SetToolBitmapSize(wx.Size(16, 16))
442 if isinstance(self.corpus, Corpus) :
443 panel.corpus = self.corpus
445 panel.tableau = self.corpus
446 #self.parent.tableau = panel.tableau
447 panel.dictpathout = self.DictPathOut
448 panel.pathout = self.DictPathOut
449 panel.parent = self.parent
450 panel.DictProfile = self.DictProfile
451 panel.cluster_size = self.cluster_size
452 panel.debtext = self.debtext
453 # self.ID_rapport = wx.NewId()
454 # #rap_img = wx.Image(os.path.join(self.parent.images_path,'icone_rap_16.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
455 # #panel.chd_toolbar.AddLabelTool(self.ID_rapport, "rapport", rap_img, shortHelp=u"Produire le rapport", longHelp=u"Exporter un rapport en texte simple")
456 # butrap = wx.Button(panel.chd_toolbar, self.ID_rapport, u"Rapport ")
457 # panel.chd_toolbar.AddControl(butrap)
458 # panel.chd_toolbar.Realize()
459 # sizer1.Add(panel.chd_toolbar,0, wx.EXPAND, 5)
460 # self.TabChdSim = wx.aui.AuiNotebook(self.parent.nb, -1, wx.DefaultPosition)
461 notebook_flags = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT| wx.NO_BORDER
462 panel.TabChdSim = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
463 #panel.TabChdSim = LB.LabelBook(panel, -1, agwStyle = INB_TOP|INB_SHOW_ONLY_TEXT|INB_FIT_LABELTEXT)
464 panel.TabChdSim.SetAGWWindowStyleFlag(notebook_flags)
465 panel.TabChdSim.SetArtProvider(aui.ChromeTabArt())
466 sizer1.Add(panel.TabChdSim,10, wx.EXPAND, 5)
467 panel.SetSizer(sizer1)
469 if isinstance(self.corpus, Corpus) :
470 panel.TabChdSim.corpus = corpus
471 panel.TabChdSim.corpus.dictpathout = self.DictPathOut
473 panel.TabChdSim.tableau = corpus
474 panel.TabChdSim.tableau.dictpathout = self.DictPathOut
475 panel.parametres = self.parametres
477 self.notenb = self.parent.nb.GetPageCount()
478 if os.path.exists(self.DictPathOut['liste_graph_chd']) :
479 list_graph = read_list_file(self.DictPathOut['liste_graph_chd'])
480 CHD = GraphPanelDendro(panel.TabChdSim, DictPathOut, list_graph, txt = self.debtext)
481 panel.TabChdSim.AddPage(CHD,'CHD')
482 # panel.ProfNB.SetArtProvider(aui.ChromeTabArt())
483 # panel.ProfNB = LB.LabelBook(panel, -1, agwStyle = INB_LEFT|INB_SHOW_ONLY_TEXT|INB_FIT_LABELTEXT)
484 # panel.ProfNB = wx.Listbook(self.parent, -1, style = wx.BK_DEFAULT)
485 # panel.ProfNB = wx.Treebook(self.parent, -1, style = wx.BK_DEFAULT)
486 # self.ProfNB.SetTabCtrlHeight(100)
487 # panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
488 if os.path.exists(DictPathOut['prof_seg']) :
489 prof_seg = ReadProfileAsDico(DictPathOut['prof_seg'], False)
490 self.prof_seg_nb = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
491 panel.ProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
492 notebook_flags |= aui.AUI_NB_WINDOWLIST_BUTTON
493 panel.ProfNB.SetAGWWindowStyleFlag(notebook_flags)
494 for i in range(0, clnb):
495 self.cluster_size.append(DictProfile[str(i + 1)][0][0:3])
496 if isinstance(self.corpus, Corpus) :
497 DictProfile[str(i + 1)][1:] = [val[0:5] + [getlemgram(self.corpus, val)] + val[6:] for val in DictProfile[str(i + 1)][1:]]
498 dlg.Update(3+i, 'Classe %i' %(i+1))
499 ind = '/'.join(DictProfile[str(i + 1)][0][0:2]).strip()
500 indpour = '\n'.join([ind, DictProfile[str(i + 1)][0][2]])
501 self.tabprofile = ProfListctrlPanel(self.parent, self.panel, DictProfile[str(i + 1)], Alceste, i + 1)
502 #self.tabantiprofile = ProfListctrlPanel(self.parent, self, DictAnti[str(i + 1)], Alceste, i + 1)
503 panel.ProfNB.AddPage(self.tabprofile, clusternames[i] + '\n%s%%' % indpour, True)
504 panel.ProfNB.SetPageTextColour(i, '#890909')
505 panel.ProfNB.SetRenamable(i, True)
506 # panel.AntiProfNB.AddPage(self.tabantiprofile, 'classe %s' % str(i + 1))
507 if os.path.exists(DictPathOut['prof_seg']) :
508 self.tab_prof_seg = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1)
509 self.prof_seg_nb.AddPage(self.tab_prof_seg, _("Cluster") + ' %i' % (i + 1))
510 panel.ProfNB.SetSelection(0)
512 self.TabAFC = aui.AuiNotebook(panel.TabChdSim, -1, wx.DefaultPosition)
514 list_graph=read_list_file(DictPathOut['liste_graph_afc'])
515 self.tabAFCGraph = GraphPanelAfc(self.TabAFC, DictPathOut, list_graph, self.clnb)
516 self.TabAFC.AddPage(self.tabAFCGraph, _("CA"))
517 if os.path.exists(self.DictPathOut['afc_facteur']) :
518 dictrow, first = ReadList(self.DictPathOut['afc_facteur'])
519 self.TabAFC_facteur = ListForSpec(self.parent, parametres, dictrow, first[1:])
520 # dictrow, first = ReadList(self.DictPathOut['afc_row'], self.encoding)
521 # self.TabAFC_ligne = ListForSpec(self.parent, self.parametres, dictrow, first)
522 # dictrow, first = ReadList(self.DictPathOut['afc_col'], self.encoding)
523 # self.TabAFC_colonne = ListForSpec(parent, self.parametres, dictrow, first)
524 self.TabAFC.AddPage(self.TabAFC_facteur, _("Factor"))
525 # self.TabAFC.AddPage(self.TabAFC_colonne, 'Colonnes')
526 # self.TabAFC.AddPage(self.TabAFC_ligne, 'Lignes')
527 sizer_3 = wx.BoxSizer(wx.VERTICAL)
528 self.parent.nb_panel_2 = wx.Panel(panel.TabChdSim, -1)
529 self.parent.button_simi = wx.Button(self.parent.nb_panel_2, -1, "Voyager")
530 self.parent.simi3dpanel = simi3d(self.parent.nb_panel_2, -1)
531 sizer_3.Add(self.parent.simi3dpanel, 1, wx.EXPAND, 0)
532 sizer_3.Add(self.parent.button_simi, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
533 self.parent.nb_panel_2.SetSizer(sizer_3)
534 self.TabAFC.AddPage(self.parent.nb_panel_2, _("3D graph"))
535 self.parent.Bind(wx.EVT_BUTTON, self.onsimi, self.parent.button_simi)
536 panel.TabChdSim.AddPage(panel.ProfNB, _("Profiles"))
537 # panel.TabChdSim.AddPage(panel.AntiProfNB, 'Antiprofils')
538 dlg.Update(4 + self.clnb, 'Affichage...')
540 panel.TabChdSim.AddPage(self.TabAFC, _("CA"))
541 if os.path.exists(DictPathOut['prof_seg']) :
542 panel.TabChdSim.AddPage(self.prof_seg_nb, _("Repeated segments profiles"))
543 # panel.Bind(wx.EVT_BUTTON, self.ongetrapport, id = self.ID_rapport)
544 if os.path.exists(os.path.join(self.parametres['pathout'], 'tgenchi2.csv')) :
545 self.parametres['tgenspec'] = os.path.join(self.parametres['pathout'], 'tgenchi2.csv')
547 if os.path.exists(self.dictpathout['translations.txt']) :
548 with open(self.dictpathout['translations.txt'], 'r', encoding='utf8') as f:
550 translist = [line.split('\t') for line in translist.splitlines()]
551 for line in translist :
553 panel.TabChdSim.SetSelection(0)
554 self.parent.nb.AddPage(panel, _("Clustering") + ' - %s' % corpname)
555 self.parent.ShowTab(True)
556 self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
557 # for pane in self.parent._mgr.GetAllPanes() :
558 # if isinstance(pane.window, aui.AuiNotebook):
560 # nb.SetAGWWindowStyleFlag(notebook_flags)
561 # nb.SetArtProvider(aui.ChromeTabArt())
563 self.parent._mgr.Update()
565 def opentrans(self, trans) :
566 prof = ReadProfileAsDico(self.dictpathout[trans[0]], False)
567 with open(self.dictpathout[trans[1]], 'r', encoding='utf8') as f :
569 lems = [line.split('\t') for line in lems.splitlines()]
571 open_antiprofil(self.panel, prof, 'utf8', title = trans[0], translation=True, lems=lems)
572 self.panel.lems = lems
573 self.panel.TabChdSim.SetSelection(self.panel.TabChdSim.GetPageCount() - 1)
575 def onsimi(self,event):
576 outfile = print_simi3d(self)
577 error = exec_rcode(self.parent.RPath, outfile, wait = True)
579 def onclusterstat(self, evt) :
580 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.csv', 'title': 'Stat par classe'})
581 dial.fbb.SetValue( os.path.join(os.path.dirname(self.corpus.dictpathout['ira']), 'stat_par_classe.csv'))
582 dial.CenterOnParent()
583 res = dial.ShowModal()
585 fileout = dial.fbb.GetValue()
587 self.corpus.get_stat_by_cluster(fileout)
589 dlg = wx.MessageDialog(self.parent, msg, _("Stat by cluster"), wx.OK | wx.ICON_INFORMATION)
591 if dlg.ShowModal() == wx.ID_OK :
594 #def onsearchf(self, evt) :
595 # if 'FrameSearch' not in dir(self.panel) :
596 # self.panel.FrameSearch = SearchFrame(self.parent, -1, "Rechercher...", self.corpus)
597 # self.panel.FrameSearch.Show()
599 def PrintRapport(self, corpus, parametres, istxt = True):
603 |i|R|a|M|u|T|e|Q| - %s
607 """ % datetime.datetime.now().ctime()
609 totocc = corpus.gettotocc()
610 txt += ': '.join([_('Number of texts'), '%i%s' % (corpus.getucinb(), sep)])
611 txt += ': '.join([_('Number of text segments'), '%i%s' % (corpus.getucenb(), sep)])
612 txt += ': '.join([_('Number of forms'), '%i%s' % (len(corpus.formes), sep)])
613 txt += ': '.join([_('Number of occurrences'), '%i%s' % (totocc, sep)])
614 #txt += 'moyenne d\'occurrences par forme: %f%s' % (float(totocc) / float(len(self.corpus.formes)), sep)
615 txt += ': '.join([_('Number of lemmas'), '%i%s' % (len(corpus.lems), sep)])
616 txt += ': '.join([_('Number of active forms'), '%i%s' % (corpus.getactivesnb(1), sep)])
617 txt += ': '.join([_('Number of supplementary forms'), '%i%s' % (corpus.getactivesnb(2), sep)])
618 txt += ' >= '.join([_('Number of active forms with a frequency'), '%i: %i%s' % (parametres['eff_min_forme'], parametres['nbactives'], sep)])
619 txt += ': '.join([_('Mean of forms by segment'), '%f%s' % (float(totocc) / float(corpus.getucenb()), sep)])
620 if 'tailleuc1' in parametres :
621 if parametres['classif_mode'] == 0 :
622 txt += ': '.join([_('Size of rst1 / rst2'), '%i / %i - %i / %i%s' % (parametres['tailleuc1'], parametres['tailleuc2'], parametres['lenuc1'], parametres['lenuc2'], sep)])
624 self.Ucenb = self.nbind
625 txt += ': '.join([_('Number of lines'), '%i%s' % (self.nbind, sep)])
626 txt += ': '.join([_('Number of clusters'), '%i%s' % (self.clnb, sep)])
628 txt += ': '.join([_('Number of clusters'), '%i%s' % (parametres['clnb'], sep)])
629 if parametres['classif_mode'] == 0 or parametres['classif_mode'] == 1 :
630 txt += ' '.join(['%i' % sum([len(cl) for cl in corpus.lc]), _('segments classified on'), '%i (%.2f%%)%s' % (corpus.getucenb(), (float(sum([len(cl) for cl in corpus.lc])) / float(corpus.getucenb())) * 100, sep)])
631 elif self.parametres['classif_mode'] == 2 :
632 txt += ' '.join(['%i' % sum([len(cl) for cl in corpus.lc]), _('texts classified on'), '%i (%.2f%%)%s' % (corpus.getucinb(), (float(sum([len(cl) for cl in corpus.lc]))) / float(corpus.getucinb()) * 100, sep)])
634 txt += ' '.join(['%i' % self.ucecla, _('line classified on'), '%i (%.2f%%)%s' % (self.Ucenb, (float(self.ucecla) / float(self.Ucenb)) * 100, sep)])
636 txt += ''.join([sep, '###########################', sep, _('time'), ' : %s' % parametres.get('time', ''), sep, '###########################', sep])
637 # ecriture du resultat dans le fichier
638 with open(self.pathout['pre_rapport'], 'w', encoding='utf8') as f :
642 class SashList(wx.Panel) :
644 def __init__(self, parent) :
645 wx.Panel.__init__(self, parent, -1)
648 #self.gparent=gparent
652 # A window to the left of the client window
653 #self.listlex = listlex
654 self.leftwin1 = wx.SashLayoutWindow(
655 self, -1, wx.DefaultPosition, (200, 300),
656 wx.NO_BORDER|wx.SW_3D
658 self.leftwin1.SetDefaultSize((120, 1000))
659 self.leftwin1.SetOrientation(wx.LAYOUT_VERTICAL)
660 self.leftwin1.SetAlignment(wx.LAYOUT_LEFT)
661 self.leftwin1.SetBackgroundColour(wx.Colour(0, 255, 0))
662 self.leftwin1.SetSashVisible(wx.SASH_RIGHT, True)
663 self.leftwin1.SetExtraBorderSize(10)
664 #textWindow = wx.TextCtrl(
665 # leftwin1, -1, "", wx.DefaultPosition, wx.DefaultSize,
666 # wx.TE_MULTILINE|wx.SUNKEN_BORDER
668 #textWindow.SetValue("A sub window")
669 self.leftWindow1 = self.leftwin1
670 winids.append(self.leftwin1.GetId())
671 rightwin1 = wx.SashLayoutWindow(
672 self, -1, wx.DefaultPosition, (200, 300),
673 wx.NO_BORDER|wx.SW_3D
675 rightwin1.SetDefaultSize((120, 1000))
676 rightwin1.SetOrientation(wx.LAYOUT_VERTICAL)
677 rightwin1.SetAlignment(wx.LAYOUT_LEFT)
678 rightwin1.SetBackgroundColour(wx.Colour(0, 255, 0))
679 rightwin1.SetSashVisible(wx.SASH_RIGHT, True)
680 rightwin1.SetExtraBorderSize(10)
681 #textWindow = wx.TextCtrl(
682 # leftwin1, -1, "", wx.DefaultPosition, wx.DefaultSize,
683 # wx.TE_MULTILINE|wx.SUNKEN_BORDER
685 #textWindow.SetValue("A sub window")
686 self.rightwin1 = rightwin1
687 winids.append(rightwin1.GetId())
692 def __init__(self, page):
694 parametres = self.page.parametres
695 ira = wx.GetApp().GetTopWindow()
696 tgenpath = os.path.join(parametres['pathout'], 'tgen.csv')
697 self.page.tgens, etoiles = ReadList(parametres['tgenspec'], ira.syscoding, sep="\t")
698 tgen = TGen(path = tgenpath, encoding = 'UTF-8')
700 tgenlempath = os.path.join(parametres['pathout'], 'tgenlemchi2.csv')
701 if os.path.exists(tgenlempath) :
702 self.page.parametres['tgenlemspec'] = tgenlempath
703 self.page.tgenlem, etoiles = ReadList(self.page.parametres['tgenlemspec'], ira.syscoding, sep="\t")
706 if 'TabChdSim' in dir(page) :
707 page = page.TabChdSim
708 for i in range(page.GetPageCount()) :
709 tab = page.GetPage(i)
710 if 'gparent' in dir(tab) :
711 if tab.gparent is not None :
712 gparent = tab.gparent
713 if 'tgen' in dir(tab) :
718 self.page.tgentab.RefreshData(self.page.tgens)
719 self.page.tgentab.tgens = tgen.tgen
720 self.page.tgentab.tgenlem = self.page.tgenlem
723 self.page.tgentab = ListForSpec(ira, gparent, self.page.tgens, etoiles[1:])
724 self.page.tgentab.tgen = True
725 self.page.tgentab.tgens = tgen.tgen
726 if os.path.exists(tgenlempath) :
727 self.page.tgentab.tgenlem = self.page.tgenlem
728 page.AddPage(self.page.tgentab, _('Tgens Specificities'))
729 page.SetSelection(page.GetPageCount() - 1)
734 def __init__(self, ira, corpus, parametres):
735 self.pathout = PathOut(dirout = parametres['pathout'])
737 self.dictpathout = StatTxtPathOut(parametres['pathout'])
738 #self.corpus.read_corpus_from_shelves(self.corpus.dictpathout['db'])
740 self.corpus.parametres['syscoding'] = 'UTF8'
741 self.encoding = self.corpus.parametres['syscoding']
742 self.parametres = parametres
743 self.DictSpec, first = ReadList(self.dictpathout['tablespecf'], self.corpus.parametres['syscoding'])
744 if os.path.exists(self.pathout['banalites.csv']) :
745 self.dictban, firstban = ReadList(self.pathout['banalites.csv'], self.corpus.parametres['syscoding'])
746 self.DictType, firstt = ReadList(self.dictpathout['tablespect'], self.corpus.parametres['syscoding'])
747 self.DictEff, firsteff = ReadList(self.dictpathout['tableafcm'], self.corpus.parametres['syscoding'])
748 self.DictEffType, firstefft = ReadList(self.dictpathout['tabletypem'], self.corpus.parametres['syscoding'])
749 self.DictEffRelForme, firsteffrelf = ReadList(self.dictpathout['eff_relatif_forme'], self.corpus.parametres['syscoding'])
750 self.DictEffRelType, firsteffrelt = ReadList(self.dictpathout['eff_relatif_type'], self.corpus.parametres['syscoding'])
751 self.etoiles = firsteff[1:]
752 #sash = SashList(ira.nb)
753 self.TabStat = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition)
754 self.TabStat.parametres = parametres
755 #self.ListPan = LexPanel(self, ira, self.DictSpec, self.etoiles)
756 self.ListPan = ListForSpec(ira, self, self.DictSpec, self.etoiles)
757 self.ListPan.pathout = self.pathout
758 if os.path.exists(self.pathout['banalites.csv']) :
759 self.listban = ListForSpec(ira, self, self.dictban, ['eff'] + self.etoiles, usefirst = True)
760 #self.ListPan2 = ListForSpec(sash.rightwin1, self, self.DictSpec, first)
761 self.ListPant = ListForSpec(ira, self, self.DictType, self.etoiles)
762 self.ListPant.pathout = self.pathout
763 self.ListPanEff = ListForSpec(ira, self, self.DictEff, self.etoiles)
764 self.ListPanEff.pathout = self.pathout
765 self.ListPanEffType = ListForSpec(ira, self, self.DictEffType, self.etoiles)
766 self.ListPanEffType.pathout = self.pathout
767 self.ListPanEffRelForme = ListForSpec(ira, self, self.DictEffRelForme, self.etoiles)
768 self.ListPanEffRelForme.pathout = self.pathout
769 self.ListPanEffRelType = ListForSpec(ira, self, self.DictEffRelType, self.etoiles)
770 self.ListPanEffRelType.pathout = self.pathout
771 self.TabStat.AddPage(self.ListPan, _('Forms'))
772 if os.path.exists(self.pathout['banalites.csv']) :
773 self.TabStat.AddPage(self.listban, _('Banal forms'))
774 self.TabStat.AddPage(self.ListPant, _('POS'))
775 self.TabStat.AddPage(self.ListPanEff, _('Forms frequencies'))
776 self.TabStat.AddPage(self.ListPanEffType, _('POS frequencies'))
777 self.TabStat.AddPage(self.ListPanEffRelForme, _('Forms relative frequencies'))
778 self.TabStat.AddPage(self.ListPanEffRelType, _('POS relative frequencies'))
779 if self.parametres['clnb'] > 2 :
780 self.TabAFC = aui.AuiNotebook(self.TabStat, -1, wx.DefaultPosition)
781 list_graph=read_list_file(self.dictpathout['liste_graph_afcf'], encoding = self.encoding)
782 self.tabAFCGraph = GraphPanelAfc(self.TabAFC, self.dictpathout, list_graph, self.parametres['clnb'], itempath ='liste_graph_afcf', coding = self.encoding)
783 self.TabAFC.AddPage(self.tabAFCGraph, _('CA forms'))
784 list_graph=read_list_file(self.dictpathout['liste_graph_afct'], encoding = self.encoding)
785 self.tabAFCTGraph = GraphPanelAfc(self.TabAFC, self.dictpathout, list_graph, self.parametres['clnb'], itempath ='liste_graph_afct', coding=self.encoding)
786 self.TabAFC.AddPage(self.tabAFCTGraph, _('CA POS'))
787 self.TabStat.AddPage(self.TabAFC, _('CA'))
788 ira.nb.AddPage(self.TabStat, ' - '.join([_('Specificities'), self.parametres['name']]))
790 self.TabStat.corpus = self.corpus
791 self.TabStat.etoiles = self.etoiles
792 self.TabStat.pathout = self.pathout
793 if os.path.exists(os.path.join(self.parametres['pathout'], 'tgenspec.csv')) :
794 self.parametres['tgenspec'] = os.path.join(self.parametres['pathout'], 'tgenspec.csv')
795 TgenLayout(self.TabStat)
796 self.TabStat.SetSelection(0)
797 ira.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
798 ira.ShowAPane("Tab_content")
803 def __init__(self, ira, corpus, parametres):
804 self.pathout = PathOut(dirout = parametres['pathout'])
807 self.read_result() # qui va définir la propriété self.result
808 self.parametres = parametres
809 self.TabStat = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition)
810 self.TabStat.parametres = parametres
811 self.TabStat.corpus = corpus
812 self.TabStat.pathout = self.pathout
813 # CHD = GraphPanel(panel.TabChdSim, DictPathOut, list_graph, txt = self.debtext)
814 # panel.TabChdSim.AddPage(CHD,'CHD')
815 #self.TabStatTot = wx.TextCtrl(self.TabStat, -1, style=wx.NO_BORDER | wx.TE_MULTILINE | wx.TE_RICH2)
816 list_graph = [['zipf.png', 'zipf']]
817 self.TabStatTot = GraphPanel(ira.nb, self.pathout, list_graph, self.result['glob'])
818 self.TabStat.AddPage(self.TabStatTot, _('Abstract'))
819 dictlabel = {'total' : _('Total'),
820 'formes_actives' : _('Actives forms'),
821 'formes_supplémentaires': _('Supplementary forms'),
822 'hapax' : _('Hapax'),
824 for item in self.result:
826 datam = [['forme', 'nb']] #???
827 self.ListPan = ListPanel(ira, self, self.result[item])
828 self.TabStat.AddPage(self.ListPan, dictlabel[item])
829 ira.nb.AddPage(self.TabStat, '%s' % parametres['name'])
830 ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
831 ira.ShowAPane("Tab_content")
833 def read_result(self) :
834 lcle = {'total' :'total.csv', 'formes_actives':'formes_actives.csv', 'formes_supplémentaires':'formes_supplémentaires.csv', 'hapax': 'hapax.csv'}
837 with open(self.pathout[lcle[key]], 'r', encoding='utf-8') as f :
838 self.result[key] = [line.split(';') for line in f.read().splitlines()]
839 self.result[key] = dict([[i,[line[0],int(line[1]), line[2]]] for i, line in enumerate(self.result[key])])
840 with open(self.pathout['glob.txt'], 'r', encoding='utf-8') as f :
841 self.result['glob'] = f.read()
844 class GraphPanelDendro(wx.Panel):
846 def __init__(self,parent, dico, list_graph, txt=False):
847 wx.Panel.__init__(self,parent)
849 self.dictpathout = dico
850 self.dirout = os.path.dirname(self.dictpathout['ira'])
851 self.list_graph = list_graph
852 self.parent = self.GetParent()#parent
853 self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "Arial")) #modifié
856 self.tabchd = self.parent.GetParent()
857 self.ira = self.tabchd.GetParent()
858 self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
859 self.panel_1.SetBackgroundColour('white')
860 self.deb = wx.StaticText(self.panel_1, -1, txt)
861 dendro_img = wx.Image(os.path.join(self.ira.images_path,'but_dendro.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
862 dendro_liste_img = wx.Image(os.path.join(self.ira.images_path,'but_dendro_liste.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
863 dendro_cloud_img= wx.Image(os.path.join(self.ira.images_path,'but_dendro_cloud.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
864 self.butdendro = wx.BitmapButton(self, -1, dendro_img)
865 self.butdendrotexte = wx.BitmapButton(self, -1, dendro_liste_img)
866 self.butdendrocloud = wx.BitmapButton(self, -1, dendro_cloud_img)
867 for i in range(0,len(list_graph)):
868 if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
869 filename, ext = os.path.splitext(list_graph[i][0])
871 self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, os.path.join(self.dirout,list_graph[i][0]), URL=os.path.join(self.dirout,list_graph[i][0])))
873 self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
874 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
875 self.__set_properties()
878 def __set_properties(self):
879 self.panel_1.EnableScrolling(True,True)
880 #self.panel_1.SetSize((1000,1000))
881 self.panel_1.SetScrollRate(20, 20)
882 self.panel_1.SetFocus()
883 self.Bind(wx.EVT_BUTTON, self.ondendro, self.butdendro)
884 self.Bind(wx.EVT_BUTTON, self.ondendrotexte, self.butdendrotexte)
885 self.Bind(wx.EVT_BUTTON, self.ondendrocloud, self.butdendrocloud)
886 self.param = {'width' : 700,
890 'taille_classe' : True,
894 self.type_dendro = [ "phylogram", "cladogram", "fan", "unrooted", "radial" ]
896 def __do_layout(self):
897 self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
898 self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
899 self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
900 self.sizer_3.Add(self.deb)
901 self.sizer_1.Add(self.butdendro, 0, 0, 0)
902 self.sizer_1.Add(self.butdendrotexte, 0, 0, 0)
903 self.sizer_1.Add(self.butdendrocloud, 0, 0, 0)
904 for i in range(0, len(self.listimg)):
905 self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
906 self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
907 self.panel_1.SetSizer(self.sizer_3)
908 self.sizer_2.Add(self.sizer_1, 0, wx.EXPAND, 0)
909 self.sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0)
910 self.SetSizer(self.sizer_2)
912 def make_param(self, dial):
913 self.param['width'] = dial.m_spinCtrl2.GetValue()
914 self.param['height'] = dial.m_spinCtrl1.GetValue()
915 self.param['type_dendro'] = dial.m_choice1.GetSelection()
916 self.param['svg'] = dial.choice_format.GetSelection()
917 if self.param['typedendro'] == 'classique' :
918 self.param['color_nb'] = dial.m_radioBox1.GetSelection()
919 self.param['taille_classe'] = dial.m_checkBox1.GetValue()
920 self.param['type_tclasse'] = dial.m_radioBox2.GetSelection()
921 if self.param.get('translation', False) :
922 if dial.trans.GetSelection() == 0 :
923 del self.param['translation']
925 self.param['translation'] = self.param['translation'][dial.trans.GetSelection()-1][1]
927 def make_dendro(self, dendro = 'simple') :
928 if self.param['svg'] :
932 while os.path.exists(os.path.join(self.dirout, 'dendrogramme_' + str(self.graphnb)+typefile)) :
934 fileout = ffr(os.path.join(self.dirout,'dendrogramme_' + str(self.graphnb)+typefile))
935 width = self.param['width']
936 height = self.param['height']
937 type_dendro = self.type_dendro[self.param['type_dendro']]
938 if self.param['taille_classe'] :
942 if self.param['color_nb'] == 0 :
946 if self.param['type_tclasse'] == 0 :
950 if self.param['svg'] :
954 dendro_path = self.dictpathout['Rdendro']
955 classe_path = self.dictpathout['uce']
960 classes <- read.csv2("%s", row.names=1)
961 classes <- classes[,1]
962 """ % (ffr(dendro_path), ffr(self.ira.RscriptsPath['Rgraph']), ffr(classe_path))
963 if dendro == 'simple' :
965 open_file_graph("%s", width=%i, height=%i, svg=%s)
966 plot.dendropr(tree.cut1$tree.cl, classes, type.dendro="%s", histo=%s, bw=%s, lab=NULL, tclasse=%s)
967 """ % (ffr(fileout), width, height, svg, type_dendro, histo, bw, tclasse)
968 elif dendro == 'texte' :
972 if (is.null(debsup)) {
975 chistable <- chistabletot[1:(debsup-1),]
976 """ % (ffr(self.dictpathout['RData.RData']), ffr(self.ira.RscriptsPath['Rgraph']))
977 if self.param.get('translation', False) :
979 rn <- read.csv2("%s", header=FALSE, sep='\t')
980 rnchis <- row.names(chistable)
981 commun <- intersect(rnchis, unique(rn[,2]))
982 idrnchis <- sapply(commun, function(x) {which(rnchis==x)})
983 idrn <- sapply(commun, function(x) {which(as.vector(rn[,2])==x)[1]})
984 rownames(chistable)[idrnchis] <- as.vector(rn[idrn,1])
985 """ % ffr(self.param['translation'])
987 open_file_graph("%s", width=%i, height=%i, svg = %s)
988 plot.dendro.prof(tree.cut1$tree.cl, classes, chistable, nbbycl = 60, type.dendro="%s", bw=%s, lab=NULL)
989 """ % (ffr(fileout), width, height, svg, type_dendro, bw)
990 elif dendro == 'cloud' :
994 if (is.null(debsup)) {
997 chistable <- chistabletot[1:(debsup-1),]
998 open_file_graph("%s", width=%i, height=%i, svg=%s)
999 plot.dendro.cloud(tree.cut1$tree.cl, classes, chistable, nbbycl = 300, type.dendro="%s", bw=%s, lab=NULL)
1000 """ % (ffr(self.dictpathout['RData.RData']), ffr(self.ira.RscriptsPath['Rgraph']), ffr(fileout), width, height, svg, type_dendro, bw)
1001 tmpfile = tempfile.mktemp()
1002 # ecriture du fichier de script à éxécuter
1003 with open(tmpfile, 'w', encoding='utf8') as f :
1005 # dialogue d'attente
1006 busy = wx.BusyInfo(_("Please wait..."), self.parent)
1008 error = exec_rcode(self.ira.RPath, tmpfile, wait=True)
1011 check_Rresult(self.ira, error)
1012 self.list_graph.append([fileout, 'Dendrogramme CHD1 - %s' % type_dendro])
1013 print_liste(self.dictpathout['liste_graph_chd'], self.list_graph)
1014 if self.param['svg'] :
1015 self.sizer_3.Add(hl.HyperLinkCtrl(self.panel_1, -1, fileout, URL=fileout), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1017 self.sizer_3.Add(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(fileout, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1018 self.sizer_3.Add(wx.StaticText(self.panel_1,-1, 'Dendrogramme CHD1 - %s' % type_dendro), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1019 self.sizer_3.Fit(self.panel_1)
1021 self.panel_1.Scroll(0,self.panel_1.GetScrollRange(wx.VERTICAL))
1024 def ondendro(self, evt):
1025 self.param['typedendro'] = 'classique'
1026 dial = PrefDendro(self.ira, self.param)
1027 val = dial.ShowModal()
1028 if val == wx.ID_OK :
1029 self.make_param(dial)
1032 def ondendrotexte(self, evt):
1033 self.param['typedendro'] = 'texte'
1034 if os.path.exists(self.dictpathout['translations.txt']) :
1035 with codecs.open(self.dictpathout['translations.txt'], 'r', 'utf8') as f :
1038 trans = [line.split('\t')[1] for line in content.splitlines()]
1039 trans = [[val, self.dictpathout[val]] for val in trans]
1040 self.param['translation'] = trans
1041 dial = PrefDendro(self.ira, self.param)
1042 val = dial.ShowModal()
1043 if val == wx.ID_OK :
1044 self.make_param(dial)
1045 self.make_dendro(dendro = 'texte')
1047 def ondendrocloud(self, evt):
1048 self.param['typedendro'] = 'cloud'
1049 dial = PrefDendro(self.ira, self.param)
1050 val = dial.ShowModal()
1051 if val == wx.ID_OK :
1052 self.make_param(dial)
1053 self.make_dendro(dendro = 'cloud')
1058 def __init__(self, ira, parametres) :
1059 #self.text = wx.TextCtrl(ira, -1, "", wx.Point(0, 0), wx.Size(200, 200), wx.NO_BORDER | wx.TE_MULTILINE | wx.TE_RICH2 | wx.TE_READONLY)
1060 self.panel = CopusPanel(ira, parametres)
1061 ira.nb.AddPage(self.panel, 'Description %s' % parametres['corpus_name'])
1062 #self.text.write(DoConf().totext(parametres))
1063 ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
1064 ira.ShowAPane("Tab_content")
1068 def __init__(self, ira, matrix):
1069 #self.parent.content = self.csvtable
1070 self.sheet = MySheet(ira.nb)
1071 ira.nb.AddPage(self.sheet, matrix.parametres['matrix_name'])
1072 self.sheet.Populate(matrix.csvtable)
1073 self.sheet.parametres = matrix.parametres
1074 ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
1075 ira.ShowAPane("Tab_content")
1078 class CopusPanel(wx.Panel) :
1080 def __init__(self, parent, parametres) :
1081 wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.TAB_TRAVERSAL )
1082 self.parametres = parametres
1083 fgSizer5 = wx.FlexGridSizer( 0, 2, 0, 0 )
1084 fgSizer5.SetFlexibleDirection( wx.BOTH )
1085 fgSizer5.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
1086 self.fgSizer5 = fgSizer5
1087 self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, _("Description of corpus"), wx.DefaultPosition, wx.DefaultSize, 0 )
1088 self.m_staticText18.Wrap( -1 )
1089 fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
1090 self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize, 0 )
1091 self.m_staticText19.Wrap( -1 )
1092 fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
1093 self.m_staticText20 = wx.StaticText( self, wx.ID_ANY, "Nom", wx.DefaultPosition, wx.DefaultSize, 0 )
1094 self.m_staticText20.Wrap( -1 )
1095 fgSizer5.Add( self.m_staticText20, 0, wx.ALL, 5 )
1096 self.m_staticText21 = wx.StaticText( self, wx.ID_ANY, parametres['corpus_name'], wx.DefaultPosition, wx.DefaultSize, 0 )
1097 self.m_staticText21.Wrap( -1 )
1098 fgSizer5.Add( self.m_staticText21, 0, wx.ALL, 5 )
1099 description = {'lang' : _('Language'),
1100 'encoding' : _('Characters set'),
1101 'ucinb' : _('Number of texts'),
1102 'ucenb' : _('Number of text segments'),
1103 'formesnb' : _('Number of forms'),
1104 'hapax' : _('Number of hapax'),
1106 keys = ['lang', 'encoding', 'originalpath', 'pathout', 'date', 'time']
1107 self.addkeys(keys, description)
1108 self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, "Paramètres", wx.DefaultPosition, wx.DefaultSize, 0 )
1109 self.m_staticText18.Wrap( -1 )
1110 fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
1111 self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize, 0 )
1112 self.m_staticText19.Wrap( -1 )
1113 fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
1114 keys = ['ucemethod', 'ucesize', 'keep_caract', 'expressions']
1115 self.addkeys(keys, description)
1116 self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, "Statistiques", wx.DefaultPosition, wx.DefaultSize, 0 )
1117 self.m_staticText18.Wrap( -1 )
1118 fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
1119 self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize, 0 )
1120 self.m_staticText19.Wrap( -1 )
1121 fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
1122 keys = ['ucinb', 'ucenb', 'occurrences', 'formesnb', 'hapax']
1123 self.addkeys(keys, description)
1124 self.SetSizer( fgSizer5 )
1127 def addkeys(self, keys, description) :
1129 option = self.parametres.get(key,'non défini')
1130 if isinstance(option, int) :
1131 option = repr(option)
1132 text = wx.StaticText( self, wx.ID_ANY, description.get(key, key), wx.DefaultPosition, wx.DefaultSize, 0 )
1134 self.fgSizer5.Add( text, 0, wx.ALL, 5 )
1135 text = wx.StaticText( self, wx.ID_ANY, option, wx.DefaultPosition, wx.DefaultSize, 0 )
1137 self.fgSizer5.Add( text, 0, wx.ALL, 5 )
1140 class DefaultTextLayout :
1142 def __init__(self, ira, corpus, parametres, cmd = False) :
1143 self.pathout = PathOut(dirout = parametres['pathout'])
1146 self.parametres = parametres
1147 self.corpus = corpus
1151 def dolayout(self, cmd) :
1152 log.info('no layout yet')
1155 class WordCloudLayout(DefaultTextLayout):
1158 self.pathout.basefiles(simipath)
1159 self.Tab = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
1160 if self.parametres['svg'] :
1161 list_graph = [['nuage_1.svg', 'Nuage']]
1163 list_graph = [['nuage_1.png', 'Nuage']]
1164 self.TabStatTot = GraphPanel(self.ira.nb, self.pathout, list_graph)
1165 self.Tab.AddPage(self.TabStatTot, 'Nuage')
1166 self.Tab.corpus = self.corpus
1167 self.Tab.parametres = self.parametres
1168 self.ira.nb.AddPage(self.Tab, '%s' % self.parametres['name'])
1169 self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1170 self.ira.ShowAPane("Tab_content")
1173 class LabbeLayout(DefaultTextLayout):
1176 self.Tab = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
1177 #if self.parametres['svg'] :
1178 # list_graph = [['nuage_1.svg', 'Nuage']]
1180 # list_graph = [['nuage_1.png', 'Nuage']]
1181 list_graph = [['labbe-tree.png', _('Ward clustering (method ward2)')],
1182 ['labbe-heatmap.png', _('Heatmap')],
1183 ['labbe-matrix.png', _('Matrix')]]
1184 for val in list_graph :
1185 #self.TabStatTot = GraphPanel(self.ira.nb, self.pathout, [val])
1186 self.Tab.AddPage(GraphPanel(self.Tab, self.pathout, [val]), val[1])
1187 self.Tab.corpus = self.corpus
1188 self.Tab.parametres = self.parametres
1189 self.ira.nb.AddPage(self.Tab, '%s' % self.parametres['name'])
1190 self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1191 self.ira.ShowAPane("Tab_content")
1195 nodesfile = self.pathout['nodes.csv']
1196 edgesfile = self.pathout['edges.csv']
1197 jsonout = self.pathout.makenew('graphe_json', 'json')
1202 """ % (ffr(self.pathout['RData.RData']), ffr(self.parent.RscriptsPath['Rgraph']))
1206 """ % (ffr(nodesfile), ffr(edgesfile))
1208 if ("communities" %in% names(graph.simi)) {
1213 graph.to.file(graph.simi, nodesfile = nodesf, edgesfile = edgesf, community = community)
1215 # ecriture du fichier de script à éxécuter
1216 filetmp = tempfile.mktemp()
1217 with open(filetmp, 'w', encoding='utf8') as f :
1219 exec_rcode(self.ira.RPath, filetmp)
1220 GraphToJson(nodesfile, edgesfile, jsonout)
1221 # une fonction à ré-activer ???
1222 # pour le moment, j'ai mis le module network_to_blender de coté
1223 # launchcommand(['/home/pierre/prog/blender-2.73-linux-glibc211-x86_64/blender', '-P', os.path.join(self.ira.AppliPath, 'network_to_blender.py'), jsonout])
1226 class SimiLayout(DefaultTextLayout) :
1228 def dolayout(self) :
1229 self.pathout.basefiles(simipath)
1231 self.indices = indices_simi
1232 if os.path.exists(self.pathout['liste_graph']) :
1233 list_graph = read_list_file(self.pathout['liste_graph'])
1235 list_graph = [['','']]
1237 notebook_flags = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT
1238 self.tabsimi = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
1239 self.tabsimi.SetAGWWindowStyleFlag(notebook_flags)
1240 self.tabsimi.SetArtProvider(aui.ChromeTabArt())
1241 self.tabsimi.corpus = self.corpus
1242 self.tabsimi.parametres = self.parametres
1243 self.graphpan = GraphPanelSimi(self.tabsimi, self.pathout, list_graph)
1244 self.graphpan.Bind(wx.EVT_BUTTON, self.redosimi, self.graphpan.butafc)
1245 self.graphpan.Bind(wx.EVT_BUTTON, self.export, self.graphpan.butexport)
1246 self.graphpan.Bind(wx.EVT_BUTTON, self.blender, self.graphpan.butblender)
1247 self.tabsimi.AddPage(self.graphpan, _('Graph'))
1248 self.ira.nb.AddPage(self.tabsimi, _('Graph analysis'))
1249 self.ira.ShowTab(True)
1250 self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1252 def redosimi(self, evt) :
1254 # with open(self.pathout['selected.csv'],'r') as f :
1255 # selected = f.read()
1256 # selected = [int(val) for val in selected.splitlines()]
1257 # if self.actives is None :
1258 # with codecs.open(self.pathout['actives.csv'], 'r', self.parametres['encoding']) as f :
1259 # self.actives = f.read()
1260 # self.actives = self.actives.splitlines()#[act for act in self.actives.splitlines()]
1261 # if os.path.exists(self.pathout['actives_nb.csv']) :
1262 # with open(self.pathout['actives_nb.csv'], 'r') as f :
1264 # act_nb = act_nb.splitlines()
1265 # dictcol = dict([[i, [self.actives[i], int(act_nb[i])]] for i, val in enumerate(self.actives)])
1267 # dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
1268 # #res = SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], selected = selected, dlg = True)
1270 # prep = PrepSimi(self.ira, self, self.parametres,self.pathout['selected.csv'], self.actives, indices_simi, wordlist = dictcol, selected = selected)
1271 # if prep.val == wx.ID_OK :
1272 # self.parametres = prep.parametres
1273 # script = PrintSimiScript(self)
1274 # script.make_script()
1275 # pid = exec_rcode(self.ira.RPath, script.scriptout, wait = True)
1276 # check_Rresult(self.ira, pid)
1277 # if self.parametres['type_graph'] in [1,3] :
1278 # if self.parametres['svg'] :
1279 # filename, ext = os.path.splitext(script.filename)
1280 # fileout = filename + '.svg'
1281 # elif self.parametres['type_graph'] == 3 :
1282 # fileout = script.filename
1283 # parametres = {'gexffile' : fileout,
1284 # 'dirout' : os.path.dirname(fileout),
1285 # 'titre': 'Le titre',
1286 # #'nodemin': self.param['txt_min'],
1287 # #'nodemax': self.param['txt_max'],
1288 # #'bargraphw' : 60*int(self.param['clnb']),
1290 # web = WebExport(self.ira, parametres)
1291 # fileout = web.exportsimi()
1293 # fileout = script.filename
1294 # if os.path.exists(self.pathout['liste_graph']):
1295 # graph_simi = read_list_file(self.pathout['liste_graph'])
1296 # graph_simi.append([os.path.basename(fileout), script.txtgraph])
1298 # graph_simi = [[os.path.basename(fileout), script.txtgraph]]
1299 # print_liste(self.pathout['liste_graph'], graph_simi)
1300 # DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira'])
1301 # if self.parametres['type_graph'] in [1,3] :
1302 # if self.parametres['svg'] or self.parametres['type_graph'] == 3 :
1303 # self.graphpan.sizer_3.Add(hl.HyperLinkCtrl(self.graphpan.panel_1, -1, fileout, URL = fileout), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1305 # self.graphpan.sizer_3.Add(wx.StaticBitmap(self.graphpan.panel_1, -1, wx.Bitmap(fileout, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1306 # self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1, script.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1307 # self.graphpan.sizer_3.Fit(self.graphpan.panel_1)
1308 # self.graphpan.Layout()
1309 # self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL))
1311 def export(self, evt) :
1313 while os.path.exists(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml')):
1315 fileout = ffr(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml'))
1321 graph <- graph.simi$graph
1322 V(graph)$x <- graph.simi$layout[,1]
1323 V(graph)$y <- graph.simi$layout[,2]
1324 if (length(graph.simi$label.cex == 1)) {
1325 V(graph)$weight <- graph.simi$eff
1327 V(graph)$weight <- graph.simi$label.cex
1329 V(graph)$rcolor <- vertex.label.color
1330 V(graph)$frequences <- graph.simi$mat.eff
1331 V(graph)$label <- as.character(graph.simi$v.label)
1332 E(graph)$weight <- graph.simi$we.width
1333 write.graph(graph, fileout, format = 'graphml')
1334 #saveAsGEXF(graph, filepath = fileout)
1335 """ % (ffr(self.pathout['RData.RData']), ffr(self.parent.RscriptsPath['simi']), fileout)
1336 filetmp = tempfile.mktemp()
1337 with open(filetmp, 'w', encoding='utf8') as f :
1339 exec_rcode(self.ira.RPath, filetmp)
1340 mss = wx.MessageDialog(self.ira, fileout, _('File exported'), wx.OK)
1341 mss.CenterOnParent()
1345 def blender(self, evt):
1349 class DefaultMatLayout :
1351 def __init__(self, parent, tableau, parametres) :
1352 self.pathout = PathOut(dirout = parametres['pathout'])
1354 self.parent = parent
1355 self.tableau = tableau
1356 self.parametres = parametres
1357 if os.path.exists(self.pathout['analyse.db']) :
1358 self.tableau.read_tableau(self.pathout['analyse.db'])
1360 self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1361 self.ira.ShowAPane("Tab_content")
1363 def dolayout(self) :
1367 class FreqLayout(DefaultMatLayout) :
1369 def dolayout(self) :
1370 self.tab = wx.html.HtmlWindow(self.ira.nb, -1)
1371 #self.tab = wx.html2.WebView.New(self)
1372 res = normpath_win32(self.pathout['resultats.html']).replace('\\','/')
1373 #self.tab.LoadPage(res)
1374 self.tab.LoadFile(res)
1375 #self.tab.LoadURL(res)
1376 self.tab.parametres = self.parametres
1377 self.ira.nb.AddPage(self.tab, ' - '.join([_("Frequency"), self.parametres['name']]))
1380 class Chi2Layout(DefaultMatLayout) :
1383 self.tab = wx.html.HtmlWindow(self.ira.nb, -1)
1384 if "gtk2" in wx.PlatformInfo:
1385 self.tab.SetStandardFonts()
1386 res = normpath_win32(self.pathout['resultats-chi2.html']).replace('\\','/')
1387 self.tab.LoadFile(res)
1388 self.tab.parametres = self.parametres
1389 self.ira.nb.AddPage(self.tab, ' - '.join(["Chi2", self.parametres['name']]))
1390 #self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1391 #self.ira.ShowAPane("Tab_content")
1394 class ProtoLayout(DefaultMatLayout) :
1396 def dolayout(self) :
1397 list_graph = [['proto.png', _('Prototypical analysis')]]
1398 #self.Tab = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
1399 #if self.parametres['svg'] :
1400 # list_graph = [['nuage_1.svg', 'Nuage']]
1402 # list_graph = [['nuage_1.png', 'Nuage']]
1403 self.TabProto = GraphPanel(self.ira.nb, self.pathout, list_graph)
1404 #self.Tab.AddPage(self.TabProto, 'Analyse Prototypique')
1405 #self.Tab.corpus = self.corpus
1406 self.TabProto.parametres = self.parametres
1407 self.ira.nb.AddPage(self.TabProto, ' - '.join([_('Prototypical analysis'), self.parametres['name']]))
1408 #self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1409 #self.ira.ShowAPane("Tab_content")
1411 class CateLayout(DefaultMatLayout) :
1413 def dolayout(self) :
1414 self.tableau.read_tableau(self.pathout['analyse.db'])
1415 TabCate = ElCategorizator(self.ira.nb, self.pathout, self.tableau)
1416 self.ira.nb.AddPage(TabCate, ' - '.join([_('ElCaTeGoRiZaToR'), self.parametres['name']]))
1418 class SimiMatLayout(DefaultMatLayout) :
1421 self.pathout.basefiles(simipath)
1422 self.indices = indices_simi
1423 if os.path.exists(self.pathout['liste_graph']) :
1424 list_graph = read_list_file(self.pathout['liste_graph'])
1426 list_graph = [['','']]
1427 notebook_flags = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT
1428 self.tabsimi = aui.AuiNotebook(self.parent.nb, -1, wx.DefaultPosition)
1429 self.tabsimi.SetAGWWindowStyleFlag(notebook_flags)
1430 self.tabsimi.SetArtProvider(aui.ChromeTabArt())
1431 self.graphpan = GraphPanelSimi(self.tabsimi, self.pathout, list_graph)
1432 self.graphpan.Bind(wx.EVT_BUTTON, self.redosimi, self.graphpan.butafc)
1433 self.graphpan.Bind(wx.EVT_BUTTON, self.export, self.graphpan.butexport)
1434 self.graphpan.Bind(wx.EVT_BUTTON, self.blender, self.graphpan.butblender)
1435 self.tabsimi.AddPage(self.graphpan, _('Graph'))
1436 self.tabsimi.parametres = self.parametres
1437 self.parent.nb.AddPage(self.tabsimi, ' - '.join([_('Graph analysis'), self.parametres['name']]))
1438 #self.parent.ShowTab(True)
1439 #self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
1441 def redosimi(self,evt) :
1442 with open(self.pathout['selected.csv'],'r', encoding='utf8') as f :
1444 selected = [int(val) for val in selected.splitlines()]
1445 #if self.actives is None :
1446 # with codecs.open(self.pathout['actives.csv'], 'r', self.parametres['encoding']) as f :
1447 # self.actives = f.read()
1448 # self.actives = self.actives.splitlines()#[act for act in self.actives.splitlines()]
1450 actives = [[val, self.tableau.actives[val][0]] for val in self.tableau.actives]
1452 actives = [[val, self.tableau.actives[val]] for val in self.tableau.actives]
1453 #self.tableau.make_listactives()
1454 actives = dict([[i, val] for i, val in enumerate(actives)])
1456 #dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
1457 self.dial = PrefSimi(self.parent, -1, self.parametres, self.indices, wordlist = actives, selected = selected, actives = self.tableau.listactives)
1458 self.dial.CenterOnParent()
1459 self.val = self.dial.ShowModal()
1460 if self.val == wx.ID_OK :
1461 last = self.dial.listcol.GetFirstSelected()
1462 lastl = [self.dial.listcol.GetFirstSelected()]
1463 indexes = [self.dial.listcol.getColumnText(self.dial.listcol.GetFirstSelected(),0)]
1464 while self.dial.listcol.GetNextSelected(last) != -1:
1465 last = self.dial.listcol.GetNextSelected(last)
1467 indexes.append(self.dial.listcol.getColumnText(last,0))
1468 self.column = [self.tableau.listactives.index(val) for val in indexes]
1470 with open(self.pathout['selected.csv'], 'w', encoding='utf8') as f :
1471 f.write('\n'.join([repr(val) for val in self.column]))
1474 self.script = PrintSimiScript(self)
1475 self.script.make_script()
1476 self.tmpfile = self.script.scriptout
1477 dlg = progressbar(self, maxi = 2)
1480 if self.parametres['type_graph'] == 1:
1481 if self.parametres['svg'] :
1482 filename, ext = os.path.splitext(self.script.filename)
1483 fileout = filename + '.svg'
1485 fileout = self.script.filename
1486 fileout = normpath_win32(fileout)
1487 if os.path.exists(self.pathout['liste_graph']):
1488 graph_simi = read_list_file(self.pathout['liste_graph'])
1489 graph_simi.append([os.path.basename(fileout), self.script.txtgraph])
1491 graph_simi = [[os.path.basename(fileout), self.script.txtgraph]]
1492 print_liste(self.pathout['liste_graph'], graph_simi)
1493 DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira'])
1494 if self.parametres['type_graph'] == 1:
1495 if self.parametres['svg'] :
1496 self.graphpan.sizer_3.Add(hl.HyperLinkCtrl(self.graphpan.panel_1, -1, fileout, URL = fileout), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1498 self.graphpan.sizer_3.Add(wx.StaticBitmap(self.graphpan.panel_1, -1, wx.Bitmap(fileout, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1499 self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1, self.script.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1500 self.graphpan.sizer_3.Fit(self.graphpan.panel_1)
1501 self.graphpan.Layout()
1502 self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL))
1506 def make_param(self) :
1507 if self.parametres['first'] :
1510 keep_coord = self.dial.check_coord.GetValue()
1511 #self.select = self.dial.check_colch.GetValue()
1512 paramsimi = {'coeff' : self.dial.choice1.GetSelection(),
1513 'layout' : self.dial.choice2.GetSelection(),
1514 'type_graph' : self.dial.choice3.GetSelection(),
1515 'arbremax' : self.dial.check1.GetValue(),
1516 'coeff_tv' : self.dial.check_s_size.GetValue(),
1517 'coeff_tv_nb' : self.dial.spin_tv.GetValue(),
1518 'tvprop' : self.dial.check2.GetValue(),
1519 'tvmin' : self.dial.spin_tvmin.GetValue(),
1520 'tvmax' : self.dial.spin_tvmax.GetValue(),
1521 'coeff_te' : self.dial.check3.GetValue(),
1522 'coeff_temin' : self.dial.spin_temin.GetValue(),
1523 'coeff_temax' : self.dial.spin_temax.GetValue(),
1524 'label_e' : self.dial.check_elab.GetValue(),
1525 'label_v' : self.dial.check_vlab.GetValue(),
1526 'vcex' : self.dial.check_vcex.GetValue(),
1527 'vcexmin' : self.dial.spin_vcexmin.GetValue(),
1528 'vcexmax' : self.dial.spin_vcexmax.GetValue(),
1529 'cex' : self.dial.spin_cex.GetValue(),
1530 'seuil_ok' : self.dial.check_seuil.GetValue(),
1531 'seuil' : self.dial.spin_seuil.GetValue(),
1532 'cols' : self.dial.cols.GetColour(),
1533 'cola' : self.dial.cola.GetColour(),
1534 'width' : self.dial.spin_width.GetValue(),
1535 'height' : self.dial.spin_height.GetValue(),
1537 'keep_coord' : keep_coord,
1538 'alpha' : self.dial.slider_sphere.GetValue(),
1539 'film' : self.dial.film.GetValue(),
1540 'svg' : self.dial.choix_format.GetSelection(),
1541 'halo' : self.dial.halo.GetValue(),
1542 'com' : self.dial.comcheck.GetValue(),
1543 'communities' : self.dial.choix_com.GetSelection(),
1544 'edgecurved' : self.dial.check_curved.GetValue(),
1546 if 'cexfromchi' in self.parametres :
1547 paramsimi['cexfromchi'] = self.dial.checkit.GetValue()
1548 if 'sfromchi' in self.parametres :
1549 paramsimi['sfromchi'] = self.dial.checki.GetValue()
1550 if 'vlabcolor' in self.parametres :
1551 paramsimi['vlabcolor'] = self.parametres['vlabcolor']
1552 if 'check_bystar' in dir(self.dial) :
1553 paramsimi['bystar'] = self.dial.check_bystar.GetValue()
1554 paramsimi['stars'] = self.parametres['stars']
1555 self.parametres.update(paramsimi)
1558 if self.parametres['type_graph'] == 1 :
1564 pid = exec_rcode(self.parent.RPath, self.tmpfile, wait = wait, graph = graph)
1565 if self.parametres['type_graph'] == 1 :
1566 while pid.poll() == None :
1569 check_Rresult(self.parent, pid)
1571 def export(self, evt) :
1573 while os.path.exists(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml')):
1575 fileout = ffr(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml'))
1581 graph <- graph.simi$graph
1582 V(graph)$x <- graph.simi$layout[,1]
1583 V(graph)$y <- graph.simi$layout[,2]
1584 if (length(graph.simi$label.cex == 1)) {
1585 V(graph)$weight <- graph.simi$mat.eff
1587 V(graph)$weight <- graph.simi$label.cex
1589 V(graph)$color <- vertex.label.color
1590 V(graph)$frequences <- graph.simi$mat.eff
1591 V(graph)$fprop <- graph.simi$mat.eff/nrow(dm)
1592 V(graph)$label <- as.character(graph.simi$v.label)
1593 E(graph)$weight <- graph.simi$we.width
1594 write.graph(graph, fileout, format = 'graphml')
1595 #saveAsGEXF(graph, filepath = fileout)
1596 """ % (ffr(self.pathout['RData.RData']), ffr(self.parent.RscriptsPath['simi']), fileout)
1597 filetmp = tempfile.mktemp()
1598 with open(filetmp, 'w', encoding='utf8') as f :
1600 exec_rcode(self.ira.RPath, filetmp)
1601 mss = wx.MessageDialog(self.ira, fileout, _('File exported'), wx.OK)
1602 mss.CenterOnParent()
1606 def blender(self, evt):
1610 class GraphPanelSimi(wx.Panel):
1612 def __init__(self,parent, dico, list_graph):
1613 wx.Panel.__init__(self,parent)
1616 self.dirout = os.path.dirname(self.Dict['ira'])
1617 self.parent = self.GetParent()
1618 self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "courier")) #modifié
1621 self.tabsimi = self.parent.GetParent()
1622 self.ira = self.tabsimi.GetParent()
1623 self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
1624 afc_img = wx.Image(os.path.join(self.ira.images_path,'button_simi.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1625 self.butafc = wx.BitmapButton(self, -1, afc_img)
1626 export_img = wx.Image(os.path.join(self.ira.images_path,'button_export.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1627 self.butexport = wx.BitmapButton(self, -1, export_img)
1628 blender_img = wx.Image(os.path.join(self.ira.images_path,'button_blender.png'), wx.BITMAP_TYPE_ANY)
1629 blender_img.Rescale(32,32)
1630 blender_img = blender_img.ConvertToBitmap()
1631 self.butblender = wx.BitmapButton(self, -1, blender_img)
1632 for i in range(0,len(list_graph)):
1633 if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
1634 filename, ext = os.path.splitext(list_graph[i][0])
1635 if ext in ['.svg', '.html'] :
1636 self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, os.path.join(self.dirout,list_graph[i][0]), URL=os.path.join(self.dirout,list_graph[i][0])))
1638 self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
1639 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
1640 self.panel_1.Bind(wx.EVT_MOTION, self.onMouseMove)
1641 self.__set_properties()
1644 def __set_properties(self):
1645 self.panel_1.EnableScrolling(True,True)
1646 #self.panel_1.SetSize((1000,1000))
1647 self.panel_1.SetScrollRate(20, 20)
1648 self.panel_1.SetFocus()
1650 def __do_layout(self):
1651 self.sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
1652 self.sizer_2 = wx.BoxSizer(wx.VERTICAL)
1653 self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
1654 self.sizer_2.Add(self.butafc, 0, 0, 0)
1655 self.sizer_2.Add(self.butexport, 0, 0, 0)
1656 self.sizer_2.Add(self.butblender, 0, 0, 0)
1657 for i in range(0, len(self.listimg)):
1658 self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1659 self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1660 self.panel_1.SetSizer(self.sizer_3)
1661 self.sizer_1.Add(self.sizer_2, 0, wx.EXPAND, 0)
1662 self.sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
1663 self.SetSizer(self.sizer_1)
1665 def onMouseMove(self, event):
1666 self.panel_1.SetFocus()