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)
464 #panel.TabChdSim = LB.LabelBook(panel, -1, agwStyle = INB_TOP|INB_SHOW_ONLY_TEXT|INB_FIT_LABELTEXT)
465 panel.TabChdSim.SetAGWWindowStyleFlag(notebook_flags)
466 panel.TabChdSim.SetArtProvider(aui.ChromeTabArt())
467 font = wx.Font(self.parent.fontsize, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
468 panel.TabChdSim.SetFont(font)
469 sizer1.Add(panel.TabChdSim,10, wx.EXPAND, 5)
470 panel.SetSizer(sizer1)
472 if isinstance(self.corpus, Corpus) :
473 panel.TabChdSim.corpus = corpus
474 panel.TabChdSim.corpus.dictpathout = self.DictPathOut
476 panel.TabChdSim.tableau = corpus
477 panel.TabChdSim.tableau.dictpathout = self.DictPathOut
478 panel.parametres = self.parametres
480 self.notenb = self.parent.nb.GetPageCount()
481 if os.path.exists(self.DictPathOut['liste_graph_chd']) :
482 list_graph = read_list_file(self.DictPathOut['liste_graph_chd'])
483 CHD = GraphPanelDendro(panel.TabChdSim, DictPathOut, list_graph, txt = self.debtext)
484 panel.TabChdSim.AddPage(CHD,'CHD')
485 # panel.ProfNB.SetArtProvider(aui.ChromeTabArt())
486 # panel.ProfNB = LB.LabelBook(panel, -1, agwStyle = INB_LEFT|INB_SHOW_ONLY_TEXT|INB_FIT_LABELTEXT)
487 # panel.ProfNB = wx.Listbook(self.parent, -1, style = wx.BK_DEFAULT)
488 # panel.ProfNB = wx.Treebook(self.parent, -1, style = wx.BK_DEFAULT)
489 # self.ProfNB.SetTabCtrlHeight(100)
490 # panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
491 if os.path.exists(DictPathOut['prof_seg']) :
492 prof_seg = ReadProfileAsDico(DictPathOut['prof_seg'], False)
493 self.prof_seg_nb = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
494 panel.ProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
495 notebook_flags |= aui.AUI_NB_WINDOWLIST_BUTTON
496 panel.ProfNB.SetAGWWindowStyleFlag(notebook_flags)
497 for i in range(0, clnb):
498 self.cluster_size.append(DictProfile[str(i + 1)][0][0:3])
499 if isinstance(self.corpus, Corpus) :
500 DictProfile[str(i + 1)][1:] = [val[0:5] + [getlemgram(self.corpus, val)] + val[6:] for val in DictProfile[str(i + 1)][1:]]
501 dlg.Update(3+i, 'Classe %i' %(i+1))
502 ind = '/'.join(DictProfile[str(i + 1)][0][0:2]).strip()
503 indpour = '\n'.join([ind, DictProfile[str(i + 1)][0][2]])
504 self.tabprofile = ProfListctrlPanel(self.parent, self.panel, DictProfile[str(i + 1)], Alceste, i + 1)
505 #self.tabantiprofile = ProfListctrlPanel(self.parent, self, DictAnti[str(i + 1)], Alceste, i + 1)
506 panel.ProfNB.AddPage(self.tabprofile, clusternames[i] + '\n%s%%' % indpour, True)
507 panel.ProfNB.SetPageTextColour(i, '#890909')
508 panel.ProfNB.SetRenamable(i, True)
509 # panel.AntiProfNB.AddPage(self.tabantiprofile, 'classe %s' % str(i + 1))
510 if os.path.exists(DictPathOut['prof_seg']) :
511 self.tab_prof_seg = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1)
512 self.prof_seg_nb.AddPage(self.tab_prof_seg, _("Cluster") + ' %i' % (i + 1))
513 panel.ProfNB.SetSelection(0)
514 panel.ProfNB.SetFont(font)
516 self.TabAFC = aui.AuiNotebook(panel.TabChdSim, -1, wx.DefaultPosition)
518 list_graph=read_list_file(DictPathOut['liste_graph_afc'])
519 self.tabAFCGraph = GraphPanelAfc(self.TabAFC, DictPathOut, list_graph, self.clnb)
520 self.TabAFC.AddPage(self.tabAFCGraph, _("CA"))
521 if os.path.exists(self.DictPathOut['afc_facteur']) :
522 dictrow, first = ReadList(self.DictPathOut['afc_facteur'])
523 self.TabAFC_facteur = ListForSpec(self.parent, parametres, dictrow, first[1:])
524 # dictrow, first = ReadList(self.DictPathOut['afc_row'], self.encoding)
525 # self.TabAFC_ligne = ListForSpec(self.parent, self.parametres, dictrow, first)
526 # dictrow, first = ReadList(self.DictPathOut['afc_col'], self.encoding)
527 # self.TabAFC_colonne = ListForSpec(parent, self.parametres, dictrow, first)
528 self.TabAFC.AddPage(self.TabAFC_facteur, _("Factor"))
529 # self.TabAFC.AddPage(self.TabAFC_colonne, 'Colonnes')
530 # self.TabAFC.AddPage(self.TabAFC_ligne, 'Lignes')
531 sizer_3 = wx.BoxSizer(wx.VERTICAL)
532 self.parent.nb_panel_2 = wx.Panel(panel.TabChdSim, -1)
533 self.parent.button_simi = wx.Button(self.parent.nb_panel_2, -1, "Voyager")
534 self.parent.simi3dpanel = simi3d(self.parent.nb_panel_2, -1)
535 sizer_3.Add(self.parent.simi3dpanel, 1, wx.EXPAND, 0)
536 sizer_3.Add(self.parent.button_simi, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
537 self.parent.nb_panel_2.SetSizer(sizer_3)
538 self.TabAFC.AddPage(self.parent.nb_panel_2, _("3D graph"))
539 self.parent.Bind(wx.EVT_BUTTON, self.onsimi, self.parent.button_simi)
540 panel.TabChdSim.AddPage(panel.ProfNB, _("Profiles"))
541 # panel.TabChdSim.AddPage(panel.AntiProfNB, 'Antiprofils')
542 dlg.Update(4 + self.clnb, 'Affichage...')
544 panel.TabChdSim.AddPage(self.TabAFC, _("CA"))
545 if os.path.exists(DictPathOut['prof_seg']) :
546 panel.TabChdSim.AddPage(self.prof_seg_nb, _("Repeated segments profiles"))
547 # panel.Bind(wx.EVT_BUTTON, self.ongetrapport, id = self.ID_rapport)
548 if os.path.exists(os.path.join(self.parametres['pathout'], 'tgenchi2.csv')) :
549 self.parametres['tgenspec'] = os.path.join(self.parametres['pathout'], 'tgenchi2.csv')
551 if os.path.exists(self.dictpathout['translations.txt']) :
552 with open(self.dictpathout['translations.txt'], 'r', encoding='utf8') as f:
554 translist = [line.split('\t') for line in translist.splitlines()]
555 for line in translist :
557 panel.TabChdSim.SetSelection(0)
558 self.parent.nb.AddPage(panel, _("Clustering") + ' - %s' % corpname)
559 self.parent.ShowTab(True)
560 self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
561 # for pane in self.parent._mgr.GetAllPanes() :
562 # if isinstance(pane.window, aui.AuiNotebook):
564 # nb.SetAGWWindowStyleFlag(notebook_flags)
565 # nb.SetArtProvider(aui.ChromeTabArt())
567 self.parent._mgr.Update()
569 def opentrans(self, trans) :
570 prof = ReadProfileAsDico(self.dictpathout[trans[0]], False)
571 with open(self.dictpathout[trans[1]], 'r', encoding='utf8') as f :
573 lems = [line.split('\t') for line in lems.splitlines()]
575 open_antiprofil(self.panel, prof, 'utf8', title = trans[0], translation=True, lems=lems)
576 self.panel.lems = lems
577 self.panel.TabChdSim.SetSelection(self.panel.TabChdSim.GetPageCount() - 1)
579 def onsimi(self,event):
580 outfile = print_simi3d(self)
581 error = exec_rcode(self.parent.RPath, outfile, wait = True)
583 def onclusterstat(self, evt) :
584 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.csv', 'title': 'Stat par classe'})
585 dial.fbb.SetValue( os.path.join(os.path.dirname(self.corpus.dictpathout['ira']), 'stat_par_classe.csv'))
586 dial.CenterOnParent()
587 res = dial.ShowModal()
589 fileout = dial.fbb.GetValue()
591 self.corpus.get_stat_by_cluster(fileout)
593 dlg = wx.MessageDialog(self.parent, msg, _("Stat by cluster"), wx.OK | wx.ICON_INFORMATION)
595 if dlg.ShowModal() == wx.ID_OK :
598 #def onsearchf(self, evt) :
599 # if 'FrameSearch' not in dir(self.panel) :
600 # self.panel.FrameSearch = SearchFrame(self.parent, -1, "Rechercher...", self.corpus)
601 # self.panel.FrameSearch.Show()
603 def PrintRapport(self, corpus, parametres, istxt = True):
607 |i|R|a|M|u|T|e|Q| - %s
611 """ % datetime.datetime.now().ctime()
613 totocc = corpus.gettotocc()
614 txt += ': '.join([_('Number of texts'), '%i%s' % (corpus.getucinb(), sep)])
615 txt += ': '.join([_('Number of text segments'), '%i%s' % (corpus.getucenb(), sep)])
616 txt += ': '.join([_('Number of forms'), '%i%s' % (len(corpus.formes), sep)])
617 txt += ': '.join([_('Number of occurrences'), '%i%s' % (totocc, sep)])
618 #txt += 'moyenne d\'occurrences par forme: %f%s' % (float(totocc) / float(len(self.corpus.formes)), sep)
619 txt += ': '.join([_('Number of lemmas'), '%i%s' % (len(corpus.lems), sep)])
620 txt += ': '.join([_('Number of active forms'), '%i%s' % (corpus.getactivesnb(1), sep)])
621 txt += ': '.join([_('Number of supplementary forms'), '%i%s' % (corpus.getactivesnb(2), sep)])
622 txt += ' >= '.join([_('Number of active forms with a frequency'), '%i: %i%s' % (parametres['eff_min_forme'], parametres['nbactives'], sep)])
623 txt += ': '.join([_('Mean of forms by segment'), '%f%s' % (float(totocc) / float(corpus.getucenb()), sep)])
624 if 'tailleuc1' in parametres :
625 if parametres['classif_mode'] == 0 :
626 txt += ': '.join([_('Size of rst1 / rst2'), '%i / %i - %i / %i%s' % (parametres['tailleuc1'], parametres['tailleuc2'], parametres['lenuc1'], parametres['lenuc2'], sep)])
628 self.Ucenb = self.nbind
629 txt += ': '.join([_('Number of lines'), '%i%s' % (self.nbind, sep)])
630 txt += ': '.join([_('Number of clusters'), '%i%s' % (self.clnb, sep)])
632 txt += ': '.join([_('Number of clusters'), '%i%s' % (parametres['clnb'], sep)])
633 if parametres['classif_mode'] == 0 or parametres['classif_mode'] == 1 :
634 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)])
635 elif self.parametres['classif_mode'] == 2 :
636 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)])
638 txt += ' '.join(['%i' % self.ucecla, _('line classified on'), '%i (%.2f%%)%s' % (self.Ucenb, (float(self.ucecla) / float(self.Ucenb)) * 100, sep)])
640 txt += ''.join([sep, '###########################', sep, _('time'), ' : %s' % parametres.get('time', ''), sep, '###########################', sep])
641 # ecriture du resultat dans le fichier
642 with open(self.pathout['pre_rapport'], 'w', encoding='utf8') as f :
646 class SashList(wx.Panel) :
648 def __init__(self, parent) :
649 wx.Panel.__init__(self, parent, -1)
652 #self.gparent=gparent
656 # A window to the left of the client window
657 #self.listlex = listlex
658 self.leftwin1 = wx.SashLayoutWindow(
659 self, -1, wx.DefaultPosition, (200, 300),
660 wx.NO_BORDER|wx.SW_3D
662 self.leftwin1.SetDefaultSize((120, 1000))
663 self.leftwin1.SetOrientation(wx.LAYOUT_VERTICAL)
664 self.leftwin1.SetAlignment(wx.LAYOUT_LEFT)
665 self.leftwin1.SetBackgroundColour(wx.Colour(0, 255, 0))
666 self.leftwin1.SetSashVisible(wx.SASH_RIGHT, True)
667 self.leftwin1.SetExtraBorderSize(10)
668 #textWindow = wx.TextCtrl(
669 # leftwin1, -1, "", wx.DefaultPosition, wx.DefaultSize,
670 # wx.TE_MULTILINE|wx.SUNKEN_BORDER
672 #textWindow.SetValue("A sub window")
673 self.leftWindow1 = self.leftwin1
674 winids.append(self.leftwin1.GetId())
675 rightwin1 = wx.SashLayoutWindow(
676 self, -1, wx.DefaultPosition, (200, 300),
677 wx.NO_BORDER|wx.SW_3D
679 rightwin1.SetDefaultSize((120, 1000))
680 rightwin1.SetOrientation(wx.LAYOUT_VERTICAL)
681 rightwin1.SetAlignment(wx.LAYOUT_LEFT)
682 rightwin1.SetBackgroundColour(wx.Colour(0, 255, 0))
683 rightwin1.SetSashVisible(wx.SASH_RIGHT, True)
684 rightwin1.SetExtraBorderSize(10)
685 #textWindow = wx.TextCtrl(
686 # leftwin1, -1, "", wx.DefaultPosition, wx.DefaultSize,
687 # wx.TE_MULTILINE|wx.SUNKEN_BORDER
689 #textWindow.SetValue("A sub window")
690 self.rightwin1 = rightwin1
691 winids.append(rightwin1.GetId())
696 def __init__(self, page):
698 parametres = self.page.parametres
699 ira = wx.GetApp().GetTopWindow()
700 tgenpath = os.path.join(parametres['pathout'], 'tgen.csv')
701 self.page.tgens, etoiles = ReadList(parametres['tgenspec'], ira.syscoding, sep="\t")
702 tgen = TGen(path = tgenpath, encoding = 'UTF-8')
704 tgenlempath = os.path.join(parametres['pathout'], 'tgenlemchi2.csv')
705 if os.path.exists(tgenlempath) :
706 self.page.parametres['tgenlemspec'] = tgenlempath
707 self.page.tgenlem, etoiles = ReadList(self.page.parametres['tgenlemspec'], ira.syscoding, sep="\t")
710 if 'TabChdSim' in dir(page) :
711 page = page.TabChdSim
712 for i in range(page.GetPageCount()) :
713 tab = page.GetPage(i)
714 if 'gparent' in dir(tab) :
715 if tab.gparent is not None :
716 gparent = tab.gparent
717 if 'tgen' in dir(tab) :
722 self.page.tgentab.RefreshData(self.page.tgens)
723 self.page.tgentab.tgens = tgen.tgen
724 self.page.tgentab.tgenlem = self.page.tgenlem
727 self.page.tgentab = ListForSpec(ira, gparent, self.page.tgens, etoiles[1:])
728 self.page.tgentab.tgen = True
729 self.page.tgentab.tgens = tgen.tgen
730 if os.path.exists(tgenlempath) :
731 self.page.tgentab.tgenlem = self.page.tgenlem
732 page.AddPage(self.page.tgentab, _('Tgens Specificities'))
733 page.SetSelection(page.GetPageCount() - 1)
738 def __init__(self, ira, corpus, parametres):
739 self.pathout = PathOut(dirout = parametres['pathout'])
741 self.dictpathout = StatTxtPathOut(parametres['pathout'])
742 #self.corpus.read_corpus_from_shelves(self.corpus.dictpathout['db'])
744 self.corpus.parametres['syscoding'] = 'UTF8'
745 self.encoding = self.corpus.parametres['syscoding']
746 self.parametres = parametres
747 self.DictSpec, first = ReadList(self.dictpathout['tablespecf'], self.corpus.parametres['syscoding'])
748 if os.path.exists(self.pathout['banalites.csv']) :
749 self.dictban, firstban = ReadList(self.pathout['banalites.csv'], self.corpus.parametres['syscoding'])
750 self.DictType, firstt = ReadList(self.dictpathout['tablespect'], self.corpus.parametres['syscoding'])
751 self.DictEff, firsteff = ReadList(self.dictpathout['tableafcm'], self.corpus.parametres['syscoding'])
752 self.DictEffType, firstefft = ReadList(self.dictpathout['tabletypem'], self.corpus.parametres['syscoding'])
753 self.DictEffRelForme, firsteffrelf = ReadList(self.dictpathout['eff_relatif_forme'], self.corpus.parametres['syscoding'])
754 self.DictEffRelType, firsteffrelt = ReadList(self.dictpathout['eff_relatif_type'], self.corpus.parametres['syscoding'])
755 self.etoiles = firsteff[1:]
756 #sash = SashList(ira.nb)
757 self.TabStat = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition)
758 self.TabStat.parametres = parametres
759 #self.ListPan = LexPanel(self, ira, self.DictSpec, self.etoiles)
760 self.ListPan = ListForSpec(ira, self, self.DictSpec, self.etoiles)
761 self.ListPan.pathout = self.pathout
762 if os.path.exists(self.pathout['banalites.csv']) :
763 self.listban = ListForSpec(ira, self, self.dictban, ['eff'] + self.etoiles, usefirst = True)
764 #self.ListPan2 = ListForSpec(sash.rightwin1, self, self.DictSpec, first)
765 self.ListPant = ListForSpec(ira, self, self.DictType, self.etoiles)
766 self.ListPant.pathout = self.pathout
767 self.ListPanEff = ListForSpec(ira, self, self.DictEff, self.etoiles)
768 self.ListPanEff.pathout = self.pathout
769 self.ListPanEffType = ListForSpec(ira, self, self.DictEffType, self.etoiles)
770 self.ListPanEffType.pathout = self.pathout
771 self.ListPanEffRelForme = ListForSpec(ira, self, self.DictEffRelForme, self.etoiles)
772 self.ListPanEffRelForme.pathout = self.pathout
773 self.ListPanEffRelType = ListForSpec(ira, self, self.DictEffRelType, self.etoiles)
774 self.ListPanEffRelType.pathout = self.pathout
775 self.TabStat.AddPage(self.ListPan, _('Forms'))
776 if os.path.exists(self.pathout['banalites.csv']) :
777 self.TabStat.AddPage(self.listban, _('Banal forms'))
778 self.TabStat.AddPage(self.ListPant, _('POS'))
779 self.TabStat.AddPage(self.ListPanEff, _('Forms frequencies'))
780 self.TabStat.AddPage(self.ListPanEffType, _('POS frequencies'))
781 self.TabStat.AddPage(self.ListPanEffRelForme, _('Forms relative frequencies'))
782 self.TabStat.AddPage(self.ListPanEffRelType, _('POS relative frequencies'))
783 if self.parametres['clnb'] > 2 :
784 self.TabAFC = aui.AuiNotebook(self.TabStat, -1, wx.DefaultPosition)
785 list_graph=read_list_file(self.dictpathout['liste_graph_afcf'], encoding = self.encoding)
786 self.tabAFCGraph = GraphPanelAfc(self.TabAFC, self.dictpathout, list_graph, self.parametres['clnb'], itempath ='liste_graph_afcf', coding = self.encoding)
787 self.TabAFC.AddPage(self.tabAFCGraph, _('CA forms'))
788 list_graph=read_list_file(self.dictpathout['liste_graph_afct'], encoding = self.encoding)
789 self.tabAFCTGraph = GraphPanelAfc(self.TabAFC, self.dictpathout, list_graph, self.parametres['clnb'], itempath ='liste_graph_afct', coding=self.encoding)
790 self.TabAFC.AddPage(self.tabAFCTGraph, _('CA POS'))
791 self.TabStat.AddPage(self.TabAFC, _('CA'))
792 ira.nb.AddPage(self.TabStat, ' - '.join([_('Specificities'), self.parametres['name']]))
794 self.TabStat.corpus = self.corpus
795 self.TabStat.etoiles = self.etoiles
796 self.TabStat.pathout = self.pathout
797 if os.path.exists(os.path.join(self.parametres['pathout'], 'tgenspec.csv')) :
798 self.parametres['tgenspec'] = os.path.join(self.parametres['pathout'], 'tgenspec.csv')
799 TgenLayout(self.TabStat)
800 self.TabStat.SetSelection(0)
801 ira.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
802 ira.ShowAPane("Tab_content")
807 def __init__(self, ira, corpus, parametres):
808 self.pathout = PathOut(dirout = parametres['pathout'])
811 self.read_result() # qui va définir la propriété self.result
812 self.parametres = parametres
813 self.TabStat = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition)
814 self.TabStat.parametres = parametres
815 self.TabStat.corpus = corpus
816 self.TabStat.pathout = self.pathout
817 # CHD = GraphPanel(panel.TabChdSim, DictPathOut, list_graph, txt = self.debtext)
818 # panel.TabChdSim.AddPage(CHD,'CHD')
819 #self.TabStatTot = wx.TextCtrl(self.TabStat, -1, style=wx.NO_BORDER | wx.TE_MULTILINE | wx.TE_RICH2)
820 list_graph = [['zipf.png', 'zipf']]
821 self.TabStatTot = GraphPanel(ira.nb, self.pathout, list_graph, self.result['glob'])
822 self.TabStat.AddPage(self.TabStatTot, _('Abstract'))
823 dictlabel = {'total' : _('Total'),
824 'formes_actives' : _('Actives forms'),
825 'formes_supplémentaires': _('Supplementary forms'),
826 'hapax' : _('Hapax'),
828 for item in self.result:
830 datam = [['forme', 'nb']] #???
831 self.ListPan = ListPanel(ira, self, self.result[item])
832 self.TabStat.AddPage(self.ListPan, dictlabel[item])
833 ira.nb.AddPage(self.TabStat, '%s' % parametres['name'])
834 ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
835 ira.ShowAPane("Tab_content")
837 def read_result(self) :
838 lcle = {'total' :'total.csv', 'formes_actives':'formes_actives.csv', 'formes_supplémentaires':'formes_supplémentaires.csv', 'hapax': 'hapax.csv'}
841 with open(self.pathout[lcle[key]], 'r', encoding='utf-8') as f :
842 self.result[key] = [line.split(';') for line in f.read().splitlines()]
843 self.result[key] = dict([[i,[line[0],int(line[1]), line[2]]] for i, line in enumerate(self.result[key])])
844 with open(self.pathout['glob.txt'], 'r', encoding='utf-8') as f :
845 self.result['glob'] = f.read()
848 class GraphPanelDendro(wx.Panel):
850 def __init__(self,parent, dico, list_graph, txt=False):
851 wx.Panel.__init__(self,parent)
853 self.dictpathout = dico
854 self.dirout = os.path.dirname(self.dictpathout['ira'])
855 self.list_graph = list_graph
856 self.parent = self.GetParent()#parent
857 self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "Arial")) #modifié
860 self.tabchd = self.parent.GetParent()
861 self.ira = self.tabchd.GetParent()
862 self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
863 self.panel_1.SetBackgroundColour('white')
864 self.deb = wx.StaticText(self.panel_1, -1, txt)
865 dendro_img = wx.Image(os.path.join(self.ira.images_path,'but_dendro.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
866 dendro_liste_img = wx.Image(os.path.join(self.ira.images_path,'but_dendro_liste.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
867 dendro_cloud_img= wx.Image(os.path.join(self.ira.images_path,'but_dendro_cloud.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
868 self.butdendro = wx.BitmapButton(self, -1, dendro_img)
869 self.butdendrotexte = wx.BitmapButton(self, -1, dendro_liste_img)
870 self.butdendrocloud = wx.BitmapButton(self, -1, dendro_cloud_img)
871 for i in range(0,len(list_graph)):
872 if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
873 filename, ext = os.path.splitext(list_graph[i][0])
875 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])))
877 self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
878 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
879 self.__set_properties()
882 def __set_properties(self):
883 self.panel_1.EnableScrolling(True,True)
884 #self.panel_1.SetSize((1000,1000))
885 self.panel_1.SetScrollRate(20, 20)
886 self.panel_1.SetFocus()
887 self.Bind(wx.EVT_BUTTON, self.ondendro, self.butdendro)
888 self.Bind(wx.EVT_BUTTON, self.ondendrotexte, self.butdendrotexte)
889 self.Bind(wx.EVT_BUTTON, self.ondendrocloud, self.butdendrocloud)
890 self.param = {'width' : 700,
894 'taille_classe' : True,
898 self.type_dendro = [ "phylogram", "cladogram", "fan", "unrooted", "radial" ]
900 def __do_layout(self):
901 self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
902 self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
903 self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
904 self.sizer_3.Add(self.deb)
905 self.sizer_1.Add(self.butdendro, 0, 0, 0)
906 self.sizer_1.Add(self.butdendrotexte, 0, 0, 0)
907 self.sizer_1.Add(self.butdendrocloud, 0, 0, 0)
908 for i in range(0, len(self.listimg)):
909 self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
910 self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
911 self.panel_1.SetSizer(self.sizer_3)
912 self.sizer_2.Add(self.sizer_1, 0, wx.EXPAND, 0)
913 self.sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0)
914 self.SetSizer(self.sizer_2)
916 def make_param(self, dial):
917 self.param['width'] = dial.m_spinCtrl2.GetValue()
918 self.param['height'] = dial.m_spinCtrl1.GetValue()
919 self.param['type_dendro'] = dial.m_choice1.GetSelection()
920 self.param['svg'] = dial.choice_format.GetSelection()
921 if self.param['typedendro'] == 'classique' :
922 self.param['color_nb'] = dial.m_radioBox1.GetSelection()
923 self.param['taille_classe'] = dial.m_checkBox1.GetValue()
924 self.param['type_tclasse'] = dial.m_radioBox2.GetSelection()
925 if self.param.get('translation', False) :
926 if dial.trans.GetSelection() == 0 :
927 del self.param['translation']
929 self.param['translation'] = self.param['translation'][dial.trans.GetSelection()-1][1]
931 def make_dendro(self, dendro = 'simple') :
932 if self.param['svg'] :
936 while os.path.exists(os.path.join(self.dirout, 'dendrogramme_' + str(self.graphnb)+typefile)) :
938 fileout = ffr(os.path.join(self.dirout,'dendrogramme_' + str(self.graphnb)+typefile))
939 width = self.param['width']
940 height = self.param['height']
941 type_dendro = self.type_dendro[self.param['type_dendro']]
942 if self.param['taille_classe'] :
946 if self.param['color_nb'] == 0 :
950 if self.param['type_tclasse'] == 0 :
954 if self.param['svg'] :
958 dendro_path = self.dictpathout['Rdendro']
959 classe_path = self.dictpathout['uce']
964 classes <- read.csv2("%s", row.names=1)
965 classes <- classes[,1]
966 """ % (ffr(dendro_path), ffr(self.ira.RscriptsPath['Rgraph']), ffr(classe_path))
967 if dendro == 'simple' :
969 open_file_graph("%s", width=%i, height=%i, svg=%s)
970 plot.dendropr(tree.cut1$tree.cl, classes, type.dendro="%s", histo=%s, bw=%s, lab=NULL, tclasse=%s)
971 """ % (ffr(fileout), width, height, svg, type_dendro, histo, bw, tclasse)
972 elif dendro == 'texte' :
976 if (is.null(debsup)) {
979 chistable <- chistabletot[1:(debsup-1),]
980 """ % (ffr(self.dictpathout['RData.RData']), ffr(self.ira.RscriptsPath['Rgraph']))
981 if self.param.get('translation', False) :
983 rn <- read.csv2("%s", header=FALSE, sep='\t')
984 rnchis <- row.names(chistable)
985 commun <- intersect(rnchis, unique(rn[,2]))
986 idrnchis <- sapply(commun, function(x) {which(rnchis==x)})
987 idrn <- sapply(commun, function(x) {which(as.vector(rn[,2])==x)[1]})
988 rownames(chistable)[idrnchis] <- as.vector(rn[idrn,1])
989 """ % ffr(self.param['translation'])
991 open_file_graph("%s", width=%i, height=%i, svg = %s)
992 plot.dendro.prof(tree.cut1$tree.cl, classes, chistable, nbbycl = 60, type.dendro="%s", bw=%s, lab=NULL)
993 """ % (ffr(fileout), width, height, svg, type_dendro, bw)
994 elif dendro == 'cloud' :
998 if (is.null(debsup)) {
1001 chistable <- chistabletot[1:(debsup-1),]
1002 open_file_graph("%s", width=%i, height=%i, svg=%s)
1003 plot.dendro.cloud(tree.cut1$tree.cl, classes, chistable, nbbycl = 300, type.dendro="%s", bw=%s, lab=NULL)
1004 """ % (ffr(self.dictpathout['RData.RData']), ffr(self.ira.RscriptsPath['Rgraph']), ffr(fileout), width, height, svg, type_dendro, bw)
1005 tmpfile = tempfile.mktemp()
1006 # ecriture du fichier de script à éxécuter
1007 with open(tmpfile, 'w', encoding='utf8') as f :
1009 # dialogue d'attente
1010 busy = wx.BusyInfo(_("Please wait..."), self.parent)
1012 error = exec_rcode(self.ira.RPath, tmpfile, wait=True)
1015 check_Rresult(self.ira, error)
1016 self.list_graph.append([fileout, 'Dendrogramme CHD1 - %s' % type_dendro])
1017 print_liste(self.dictpathout['liste_graph_chd'], self.list_graph)
1018 if self.param['svg'] :
1019 self.sizer_3.Add(hl.HyperLinkCtrl(self.panel_1, -1, fileout, URL=fileout), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1021 self.sizer_3.Add(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(fileout, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1022 self.sizer_3.Add(wx.StaticText(self.panel_1,-1, 'Dendrogramme CHD1 - %s' % type_dendro), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1023 self.sizer_3.Fit(self.panel_1)
1025 self.panel_1.Scroll(0,self.panel_1.GetScrollRange(wx.VERTICAL))
1028 def ondendro(self, evt):
1029 self.param['typedendro'] = 'classique'
1030 dial = PrefDendro(self.ira, self.param)
1031 val = dial.ShowModal()
1032 if val == wx.ID_OK :
1033 self.make_param(dial)
1036 def ondendrotexte(self, evt):
1037 self.param['typedendro'] = 'texte'
1038 if os.path.exists(self.dictpathout['translations.txt']) :
1039 with codecs.open(self.dictpathout['translations.txt'], 'r', 'utf8') as f :
1042 trans = [line.split('\t')[1] for line in content.splitlines()]
1043 trans = [[val, self.dictpathout[val]] for val in trans]
1044 self.param['translation'] = trans
1045 dial = PrefDendro(self.ira, self.param)
1046 val = dial.ShowModal()
1047 if val == wx.ID_OK :
1048 self.make_param(dial)
1049 self.make_dendro(dendro = 'texte')
1051 def ondendrocloud(self, evt):
1052 self.param['typedendro'] = 'cloud'
1053 dial = PrefDendro(self.ira, self.param)
1054 val = dial.ShowModal()
1055 if val == wx.ID_OK :
1056 self.make_param(dial)
1057 self.make_dendro(dendro = 'cloud')
1062 def __init__(self, ira, parametres) :
1063 #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)
1064 self.panel = CopusPanel(ira, parametres)
1065 ira.nb.AddPage(self.panel, 'Description %s' % parametres['corpus_name'])
1066 #self.text.write(DoConf().totext(parametres))
1067 ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
1068 ira.ShowAPane("Tab_content")
1072 def __init__(self, ira, matrix):
1073 #self.parent.content = self.csvtable
1074 self.sheet = MySheet(ira.nb)
1075 ira.nb.AddPage(self.sheet, matrix.parametres['matrix_name'])
1076 self.sheet.Populate(matrix.csvtable)
1077 self.sheet.parametres = matrix.parametres
1078 ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
1079 ira.ShowAPane("Tab_content")
1082 class CopusPanel(wx.Panel) :
1084 def __init__(self, parent, parametres) :
1085 wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.TAB_TRAVERSAL )
1086 self.parametres = parametres
1087 fgSizer5 = wx.FlexGridSizer( 0, 2, 0, 0 )
1088 fgSizer5.SetFlexibleDirection( wx.BOTH )
1089 fgSizer5.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
1090 self.fgSizer5 = fgSizer5
1091 self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, _("Description of corpus"), wx.DefaultPosition, wx.DefaultSize, 0 )
1092 self.m_staticText18.Wrap( -1 )
1093 fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
1094 self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize, 0 )
1095 self.m_staticText19.Wrap( -1 )
1096 fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
1097 self.m_staticText20 = wx.StaticText( self, wx.ID_ANY, "Nom", wx.DefaultPosition, wx.DefaultSize, 0 )
1098 self.m_staticText20.Wrap( -1 )
1099 fgSizer5.Add( self.m_staticText20, 0, wx.ALL, 5 )
1100 self.m_staticText21 = wx.StaticText( self, wx.ID_ANY, parametres['corpus_name'], wx.DefaultPosition, wx.DefaultSize, 0 )
1101 self.m_staticText21.Wrap( -1 )
1102 fgSizer5.Add( self.m_staticText21, 0, wx.ALL, 5 )
1103 description = {'lang' : _('Language'),
1104 'encoding' : _('Characters set'),
1105 'ucinb' : _('Number of texts'),
1106 'ucenb' : _('Number of text segments'),
1107 'formesnb' : _('Number of forms'),
1108 'hapax' : _('Number of hapax'),
1110 keys = ['lang', 'encoding', 'originalpath', 'pathout', 'date', 'time']
1111 self.addkeys(keys, description)
1112 self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, "Paramètres", wx.DefaultPosition, wx.DefaultSize, 0 )
1113 self.m_staticText18.Wrap( -1 )
1114 fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
1115 self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize, 0 )
1116 self.m_staticText19.Wrap( -1 )
1117 fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
1118 keys = ['ucemethod', 'ucesize', 'keep_caract', 'expressions']
1119 self.addkeys(keys, description)
1120 self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, "Statistiques", wx.DefaultPosition, wx.DefaultSize, 0 )
1121 self.m_staticText18.Wrap( -1 )
1122 fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
1123 self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize, 0 )
1124 self.m_staticText19.Wrap( -1 )
1125 fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
1126 keys = ['ucinb', 'ucenb', 'occurrences', 'formesnb', 'hapax']
1127 self.addkeys(keys, description)
1128 self.SetSizer( fgSizer5 )
1131 def addkeys(self, keys, description) :
1133 option = self.parametres.get(key,'non défini')
1134 if isinstance(option, int) :
1135 option = repr(option)
1136 text = wx.StaticText( self, wx.ID_ANY, description.get(key, key), wx.DefaultPosition, wx.DefaultSize, 0 )
1138 self.fgSizer5.Add( text, 0, wx.ALL, 5 )
1139 text = wx.StaticText( self, wx.ID_ANY, option, wx.DefaultPosition, wx.DefaultSize, 0 )
1141 self.fgSizer5.Add( text, 0, wx.ALL, 5 )
1144 class DefaultTextLayout :
1146 def __init__(self, ira, corpus, parametres, cmd = False) :
1147 self.pathout = PathOut(dirout = parametres['pathout'])
1150 self.parametres = parametres
1151 self.corpus = corpus
1155 def dolayout(self, cmd) :
1156 log.info('no layout yet')
1159 class WordCloudLayout(DefaultTextLayout):
1162 self.pathout.basefiles(simipath)
1163 self.Tab = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
1164 if self.parametres['svg'] :
1165 list_graph = [['nuage_1.svg', 'Nuage']]
1167 list_graph = [['nuage_1.png', 'Nuage']]
1168 self.TabStatTot = GraphPanel(self.ira.nb, self.pathout, list_graph)
1169 self.Tab.AddPage(self.TabStatTot, 'Nuage')
1170 self.Tab.corpus = self.corpus
1171 self.Tab.parametres = self.parametres
1172 self.ira.nb.AddPage(self.Tab, '%s' % self.parametres['name'])
1173 self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1174 self.ira.ShowAPane("Tab_content")
1177 class LabbeLayout(DefaultTextLayout):
1180 self.Tab = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
1181 #if self.parametres['svg'] :
1182 # list_graph = [['nuage_1.svg', 'Nuage']]
1184 # list_graph = [['nuage_1.png', 'Nuage']]
1185 list_graph = [['labbe-tree.png', _('Ward clustering (method ward2)')],
1186 ['labbe-heatmap.png', _('Heatmap')],
1187 ['labbe-matrix.png', _('Matrix')]]
1188 for val in list_graph :
1189 #self.TabStatTot = GraphPanel(self.ira.nb, self.pathout, [val])
1190 self.Tab.AddPage(GraphPanel(self.Tab, self.pathout, [val]), val[1])
1191 self.Tab.corpus = self.corpus
1192 self.Tab.parametres = self.parametres
1193 self.ira.nb.AddPage(self.Tab, '%s' % self.parametres['name'])
1194 self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1195 self.ira.ShowAPane("Tab_content")
1199 nodesfile = self.pathout['nodes.csv']
1200 edgesfile = self.pathout['edges.csv']
1201 jsonout = self.pathout.makenew('graphe_json', 'json')
1206 """ % (ffr(self.pathout['RData.RData']), ffr(self.parent.RscriptsPath['Rgraph']))
1210 """ % (ffr(nodesfile), ffr(edgesfile))
1212 if ("communities" %in% names(graph.simi)) {
1217 graph.to.file(graph.simi, nodesfile = nodesf, edgesfile = edgesf, community = community)
1219 # ecriture du fichier de script à éxécuter
1220 filetmp = tempfile.mktemp()
1221 with open(filetmp, 'w', encoding='utf8') as f :
1223 exec_rcode(self.ira.RPath, filetmp)
1224 GraphToJson(nodesfile, edgesfile, jsonout)
1225 # une fonction à ré-activer ???
1226 # pour le moment, j'ai mis le module network_to_blender de coté
1227 # launchcommand(['/home/pierre/prog/blender-2.73-linux-glibc211-x86_64/blender', '-P', os.path.join(self.ira.AppliPath, 'network_to_blender.py'), jsonout])
1230 class SimiLayout(DefaultTextLayout) :
1232 def dolayout(self) :
1233 self.pathout.basefiles(simipath)
1235 self.indices = indices_simi
1236 if os.path.exists(self.pathout['liste_graph']) :
1237 list_graph = read_list_file(self.pathout['liste_graph'])
1239 list_graph = [['','']]
1241 notebook_flags = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT
1242 self.tabsimi = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
1243 self.tabsimi.SetAGWWindowStyleFlag(notebook_flags)
1244 self.tabsimi.SetArtProvider(aui.ChromeTabArt())
1245 self.tabsimi.corpus = self.corpus
1246 self.tabsimi.parametres = self.parametres
1247 self.graphpan = GraphPanelSimi(self.tabsimi, self.pathout, list_graph)
1248 self.graphpan.Bind(wx.EVT_BUTTON, self.redosimi, self.graphpan.butafc)
1249 self.graphpan.Bind(wx.EVT_BUTTON, self.export, self.graphpan.butexport)
1250 self.graphpan.Bind(wx.EVT_BUTTON, self.blender, self.graphpan.butblender)
1251 self.tabsimi.AddPage(self.graphpan, _('Graph'))
1252 self.ira.nb.AddPage(self.tabsimi, _('Graph analysis'))
1253 self.ira.ShowTab(True)
1254 self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1256 def redosimi(self, evt) :
1258 # with open(self.pathout['selected.csv'],'r') as f :
1259 # selected = f.read()
1260 # selected = [int(val) for val in selected.splitlines()]
1261 # if self.actives is None :
1262 # with codecs.open(self.pathout['actives.csv'], 'r', self.parametres['encoding']) as f :
1263 # self.actives = f.read()
1264 # self.actives = self.actives.splitlines()#[act for act in self.actives.splitlines()]
1265 # if os.path.exists(self.pathout['actives_nb.csv']) :
1266 # with open(self.pathout['actives_nb.csv'], 'r') as f :
1268 # act_nb = act_nb.splitlines()
1269 # dictcol = dict([[i, [self.actives[i], int(act_nb[i])]] for i, val in enumerate(self.actives)])
1271 # dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
1272 # #res = SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], selected = selected, dlg = True)
1274 # prep = PrepSimi(self.ira, self, self.parametres,self.pathout['selected.csv'], self.actives, indices_simi, wordlist = dictcol, selected = selected)
1275 # if prep.val == wx.ID_OK :
1276 # self.parametres = prep.parametres
1277 # script = PrintSimiScript(self)
1278 # script.make_script()
1279 # pid = exec_rcode(self.ira.RPath, script.scriptout, wait = True)
1280 # check_Rresult(self.ira, pid)
1281 # if self.parametres['type_graph'] in [1,3] :
1282 # if self.parametres['svg'] :
1283 # filename, ext = os.path.splitext(script.filename)
1284 # fileout = filename + '.svg'
1285 # elif self.parametres['type_graph'] == 3 :
1286 # fileout = script.filename
1287 # parametres = {'gexffile' : fileout,
1288 # 'dirout' : os.path.dirname(fileout),
1289 # 'titre': 'Le titre',
1290 # #'nodemin': self.param['txt_min'],
1291 # #'nodemax': self.param['txt_max'],
1292 # #'bargraphw' : 60*int(self.param['clnb']),
1294 # web = WebExport(self.ira, parametres)
1295 # fileout = web.exportsimi()
1297 # fileout = script.filename
1298 # if os.path.exists(self.pathout['liste_graph']):
1299 # graph_simi = read_list_file(self.pathout['liste_graph'])
1300 # graph_simi.append([os.path.basename(fileout), script.txtgraph])
1302 # graph_simi = [[os.path.basename(fileout), script.txtgraph]]
1303 # print_liste(self.pathout['liste_graph'], graph_simi)
1304 # DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira'])
1305 # if self.parametres['type_graph'] in [1,3] :
1306 # if self.parametres['svg'] or self.parametres['type_graph'] == 3 :
1307 # self.graphpan.sizer_3.Add(hl.HyperLinkCtrl(self.graphpan.panel_1, -1, fileout, URL = fileout), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1309 # 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)
1310 # self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1, script.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1311 # self.graphpan.sizer_3.Fit(self.graphpan.panel_1)
1312 # self.graphpan.Layout()
1313 # self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL))
1315 def export(self, evt) :
1317 while os.path.exists(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml')):
1319 fileout = ffr(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml'))
1325 graph <- graph.simi$graph
1326 V(graph)$x <- graph.simi$layout[,1]
1327 V(graph)$y <- graph.simi$layout[,2]
1328 if (length(graph.simi$label.cex == 1)) {
1329 V(graph)$weight <- graph.simi$eff
1331 V(graph)$weight <- graph.simi$label.cex
1333 V(graph)$rcolor <- vertex.label.color
1334 V(graph)$frequences <- graph.simi$mat.eff
1335 V(graph)$label <- as.character(graph.simi$v.label)
1336 E(graph)$weight <- graph.simi$we.width
1337 write.graph(graph, fileout, format = 'graphml')
1338 #saveAsGEXF(graph, filepath = fileout)
1339 """ % (ffr(self.pathout['RData.RData']), ffr(self.parent.RscriptsPath['simi']), fileout)
1340 filetmp = tempfile.mktemp()
1341 with open(filetmp, 'w', encoding='utf8') as f :
1343 exec_rcode(self.ira.RPath, filetmp)
1344 mss = wx.MessageDialog(self.ira, fileout, _('File exported'), wx.OK)
1345 mss.CenterOnParent()
1349 def blender(self, evt):
1353 class DefaultMatLayout :
1355 def __init__(self, parent, tableau, parametres) :
1356 self.pathout = PathOut(dirout = parametres['pathout'])
1358 self.parent = parent
1359 self.tableau = tableau
1360 self.parametres = parametres
1361 if os.path.exists(self.pathout['analyse.db']) :
1362 self.tableau.read_tableau(self.pathout['analyse.db'])
1364 self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1365 self.ira.ShowAPane("Tab_content")
1367 def dolayout(self) :
1371 class FreqLayout(DefaultMatLayout) :
1373 def dolayout(self) :
1374 self.tab = wx.html.HtmlWindow(self.ira.nb, -1)
1375 #self.tab = wx.html2.WebView.New(self)
1376 res = normpath_win32(self.pathout['resultats.html']).replace('\\','/')
1377 #self.tab.LoadPage(res)
1378 self.tab.LoadFile(res)
1379 #self.tab.LoadURL(res)
1380 self.tab.parametres = self.parametres
1381 self.ira.nb.AddPage(self.tab, ' - '.join([_("Frequency"), self.parametres['name']]))
1384 class Chi2Layout(DefaultMatLayout) :
1387 self.tab = wx.html.HtmlWindow(self.ira.nb, -1)
1388 if "gtk2" in wx.PlatformInfo:
1389 self.tab.SetStandardFonts()
1390 res = normpath_win32(self.pathout['resultats-chi2.html']).replace('\\','/')
1391 self.tab.LoadFile(res)
1392 self.tab.parametres = self.parametres
1393 self.ira.nb.AddPage(self.tab, ' - '.join(["Chi2", self.parametres['name']]))
1394 #self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1395 #self.ira.ShowAPane("Tab_content")
1398 class ProtoLayout(DefaultMatLayout) :
1400 def dolayout(self) :
1401 list_graph = [['proto.png', _('Prototypical analysis')]]
1402 #self.Tab = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
1403 #if self.parametres['svg'] :
1404 # list_graph = [['nuage_1.svg', 'Nuage']]
1406 # list_graph = [['nuage_1.png', 'Nuage']]
1407 self.TabProto = GraphPanel(self.ira.nb, self.pathout, list_graph)
1408 #self.Tab.AddPage(self.TabProto, 'Analyse Prototypique')
1409 #self.Tab.corpus = self.corpus
1410 self.TabProto.parametres = self.parametres
1411 self.ira.nb.AddPage(self.TabProto, ' - '.join([_('Prototypical analysis'), self.parametres['name']]))
1412 #self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1413 #self.ira.ShowAPane("Tab_content")
1415 class CateLayout(DefaultMatLayout) :
1417 def dolayout(self) :
1418 self.tableau.read_tableau(self.pathout['analyse.db'])
1419 TabCate = ElCategorizator(self.ira.nb, self.pathout, self.tableau)
1420 TabCate.parametres = self.parametres
1421 self.ira.nb.AddPage(TabCate, ' - '.join([_('ElCaTeGoRiZaToR'), self.parametres['name']]))
1423 class SimiMatLayout(DefaultMatLayout) :
1426 self.pathout.basefiles(simipath)
1427 self.indices = indices_simi
1428 if os.path.exists(self.pathout['liste_graph']) :
1429 list_graph = read_list_file(self.pathout['liste_graph'])
1431 list_graph = [['','']]
1432 notebook_flags = aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT
1433 self.tabsimi = aui.AuiNotebook(self.parent.nb, -1, wx.DefaultPosition)
1434 self.tabsimi.SetAGWWindowStyleFlag(notebook_flags)
1435 self.tabsimi.SetArtProvider(aui.ChromeTabArt())
1436 self.graphpan = GraphPanelSimi(self.tabsimi, self.pathout, list_graph)
1437 self.graphpan.Bind(wx.EVT_BUTTON, self.redosimi, self.graphpan.butafc)
1438 self.graphpan.Bind(wx.EVT_BUTTON, self.export, self.graphpan.butexport)
1439 self.graphpan.Bind(wx.EVT_BUTTON, self.blender, self.graphpan.butblender)
1440 self.tabsimi.AddPage(self.graphpan, _('Graph'))
1441 self.tabsimi.parametres = self.parametres
1442 self.parent.nb.AddPage(self.tabsimi, ' - '.join([_('Graph analysis'), self.parametres['name']]))
1443 #self.parent.ShowTab(True)
1444 #self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
1446 def redosimi(self,evt) :
1447 with open(self.pathout['selected.csv'],'r', encoding='utf8') as f :
1449 selected = [int(val) for val in selected.splitlines()]
1450 #if self.actives is None :
1451 # with codecs.open(self.pathout['actives.csv'], 'r', self.parametres['encoding']) as f :
1452 # self.actives = f.read()
1453 # self.actives = self.actives.splitlines()#[act for act in self.actives.splitlines()]
1455 actives = [[val, self.tableau.actives[val][0]] for val in self.tableau.actives]
1457 actives = [[val, self.tableau.actives[val]] for val in self.tableau.actives]
1458 #self.tableau.make_listactives()
1459 actives = dict([[i, val] for i, val in enumerate(actives)])
1461 #dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
1462 self.dial = PrefSimi(self.parent, -1, self.parametres, self.indices, wordlist = actives, selected = selected, actives = self.tableau.listactives)
1463 self.dial.CenterOnParent()
1464 self.val = self.dial.ShowModal()
1465 if self.val == wx.ID_OK :
1466 last = self.dial.listcol.GetFirstSelected()
1467 lastl = [self.dial.listcol.GetFirstSelected()]
1468 indexes = [self.dial.listcol.getColumnText(self.dial.listcol.GetFirstSelected(),0)]
1469 while self.dial.listcol.GetNextSelected(last) != -1:
1470 last = self.dial.listcol.GetNextSelected(last)
1472 indexes.append(self.dial.listcol.getColumnText(last,0))
1473 self.column = [self.tableau.listactives.index(val) for val in indexes]
1475 with open(self.pathout['selected.csv'], 'w', encoding='utf8') as f :
1476 f.write('\n'.join([repr(val) for val in self.column]))
1479 self.script = PrintSimiScript(self)
1480 self.script.make_script()
1481 self.tmpfile = self.script.scriptout
1482 dlg = progressbar(self, maxi = 2)
1485 if self.parametres['type_graph'] == 1:
1486 if self.parametres['svg'] :
1487 filename, ext = os.path.splitext(self.script.filename)
1488 fileout = filename + '.svg'
1490 fileout = self.script.filename
1491 fileout = normpath_win32(fileout)
1492 if os.path.exists(self.pathout['liste_graph']):
1493 graph_simi = read_list_file(self.pathout['liste_graph'])
1494 graph_simi.append([os.path.basename(fileout), self.script.txtgraph])
1496 graph_simi = [[os.path.basename(fileout), self.script.txtgraph]]
1497 print_liste(self.pathout['liste_graph'], graph_simi)
1498 DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira'])
1499 if self.parametres['type_graph'] == 1:
1500 if self.parametres['svg'] :
1501 self.graphpan.sizer_3.Add(hl.HyperLinkCtrl(self.graphpan.panel_1, -1, fileout, URL = fileout), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1503 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)
1504 self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1, self.script.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1505 self.graphpan.sizer_3.Fit(self.graphpan.panel_1)
1506 self.graphpan.Layout()
1507 self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL))
1511 def make_param(self) :
1512 if self.parametres['first'] :
1515 keep_coord = self.dial.check_coord.GetValue()
1516 #self.select = self.dial.check_colch.GetValue()
1517 paramsimi = {'coeff' : self.dial.choice1.GetSelection(),
1518 'layout' : self.dial.choice2.GetSelection(),
1519 'type_graph' : self.dial.choice3.GetSelection(),
1520 'arbremax' : self.dial.check1.GetValue(),
1521 'coeff_tv' : self.dial.check_s_size.GetValue(),
1522 'coeff_tv_nb' : self.dial.spin_tv.GetValue(),
1523 'tvprop' : self.dial.check2.GetValue(),
1524 'tvmin' : self.dial.spin_tvmin.GetValue(),
1525 'tvmax' : self.dial.spin_tvmax.GetValue(),
1526 'coeff_te' : self.dial.check3.GetValue(),
1527 'coeff_temin' : self.dial.spin_temin.GetValue(),
1528 'coeff_temax' : self.dial.spin_temax.GetValue(),
1529 'label_e' : self.dial.check_elab.GetValue(),
1530 'label_v' : self.dial.check_vlab.GetValue(),
1531 'vcex' : self.dial.check_vcex.GetValue(),
1532 'vcexmin' : self.dial.spin_vcexmin.GetValue(),
1533 'vcexmax' : self.dial.spin_vcexmax.GetValue(),
1534 'cex' : self.dial.spin_cex.GetValue(),
1535 'seuil_ok' : self.dial.check_seuil.GetValue(),
1536 'seuil' : self.dial.spin_seuil.GetValue(),
1537 'cols' : self.dial.cols.GetColour(),
1538 'cola' : self.dial.cola.GetColour(),
1539 'width' : self.dial.spin_width.GetValue(),
1540 'height' : self.dial.spin_height.GetValue(),
1542 'keep_coord' : keep_coord,
1543 'alpha' : self.dial.slider_sphere.GetValue(),
1544 'film' : self.dial.film.GetValue(),
1545 'svg' : self.dial.choix_format.GetSelection(),
1546 'halo' : self.dial.halo.GetValue(),
1547 'com' : self.dial.comcheck.GetValue(),
1548 'communities' : self.dial.choix_com.GetSelection(),
1549 'edgecurved' : self.dial.check_curved.GetValue(),
1551 if 'cexfromchi' in self.parametres :
1552 paramsimi['cexfromchi'] = self.dial.checkit.GetValue()
1553 if 'sfromchi' in self.parametres :
1554 paramsimi['sfromchi'] = self.dial.checki.GetValue()
1555 if 'vlabcolor' in self.parametres :
1556 paramsimi['vlabcolor'] = self.parametres['vlabcolor']
1557 if 'check_bystar' in dir(self.dial) :
1558 paramsimi['bystar'] = self.dial.check_bystar.GetValue()
1559 paramsimi['stars'] = self.parametres['stars']
1560 self.parametres.update(paramsimi)
1563 if self.parametres['type_graph'] == 1 :
1569 pid = exec_rcode(self.parent.RPath, self.tmpfile, wait = wait, graph = graph)
1570 if self.parametres['type_graph'] == 1 :
1571 while pid.poll() == None :
1574 check_Rresult(self.parent, pid)
1576 def export(self, evt) :
1578 while os.path.exists(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml')):
1580 fileout = ffr(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml'))
1586 graph <- graph.simi$graph
1587 V(graph)$x <- graph.simi$layout[,1]
1588 V(graph)$y <- graph.simi$layout[,2]
1589 if (length(graph.simi$label.cex == 1)) {
1590 V(graph)$weight <- graph.simi$mat.eff
1592 V(graph)$weight <- graph.simi$label.cex
1594 V(graph)$color <- vertex.label.color
1595 V(graph)$frequences <- graph.simi$mat.eff
1596 V(graph)$fprop <- graph.simi$mat.eff/nrow(dm)
1597 V(graph)$label <- as.character(graph.simi$v.label)
1598 E(graph)$weight <- graph.simi$we.width
1599 write.graph(graph, fileout, format = 'graphml')
1600 #saveAsGEXF(graph, filepath = fileout)
1601 """ % (ffr(self.pathout['RData.RData']), ffr(self.parent.RscriptsPath['simi']), fileout)
1602 filetmp = tempfile.mktemp()
1603 with open(filetmp, 'w', encoding='utf8') as f :
1605 exec_rcode(self.ira.RPath, filetmp)
1606 mss = wx.MessageDialog(self.ira, fileout, _('File exported'), wx.OK)
1607 mss.CenterOnParent()
1611 def blender(self, evt):
1615 class GraphPanelSimi(wx.Panel):
1617 def __init__(self,parent, dico, list_graph):
1618 wx.Panel.__init__(self,parent)
1621 self.dirout = os.path.dirname(self.Dict['ira'])
1622 self.parent = self.GetParent()
1623 self.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, "courier")) #modifié
1626 self.tabsimi = self.parent.GetParent()
1627 self.ira = self.tabsimi.GetParent()
1628 self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
1629 afc_img = wx.Image(os.path.join(self.ira.images_path,'button_simi.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1630 self.butafc = wx.BitmapButton(self, -1, afc_img)
1631 export_img = wx.Image(os.path.join(self.ira.images_path,'button_export.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1632 self.butexport = wx.BitmapButton(self, -1, export_img)
1633 blender_img = wx.Image(os.path.join(self.ira.images_path,'button_blender.png'), wx.BITMAP_TYPE_ANY)
1634 blender_img.Rescale(32,32)
1635 blender_img = blender_img.ConvertToBitmap()
1636 self.butblender = wx.BitmapButton(self, -1, blender_img)
1637 for i in range(0,len(list_graph)):
1638 if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
1639 filename, ext = os.path.splitext(list_graph[i][0])
1640 if ext in ['.svg', '.html'] :
1641 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])))
1643 self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
1644 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
1645 self.panel_1.Bind(wx.EVT_MOTION, self.onMouseMove)
1646 self.__set_properties()
1649 def __set_properties(self):
1650 self.panel_1.EnableScrolling(True,True)
1651 #self.panel_1.SetSize((1000,1000))
1652 self.panel_1.SetScrollRate(20, 20)
1653 self.panel_1.SetFocus()
1655 def __do_layout(self):
1656 self.sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
1657 self.sizer_2 = wx.BoxSizer(wx.VERTICAL)
1658 self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
1659 self.sizer_2.Add(self.butafc, 0, 0, 0)
1660 self.sizer_2.Add(self.butexport, 0, 0, 0)
1661 self.sizer_2.Add(self.butblender, 0, 0, 0)
1662 for i in range(0, len(self.listimg)):
1663 self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1664 self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1665 self.panel_1.SetSizer(self.sizer_3)
1666 self.sizer_1.Add(self.sizer_2, 0, wx.EXPAND, 0)
1667 self.sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
1668 self.SetSizer(self.sizer_1)
1670 def onMouseMove(self, event):
1671 self.panel_1.SetFocus()