...
[iramuteq] / layout.py
1 #!/bin/env python
2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008-2009 Pierre Ratinaud
5 #Lisense: GNU/GPL
6
7 import os
8 import wx
9 import wx.lib.hyperlink as hl
10 if wx.__version__ >= '2.11' :
11     import wx.lib.agw.aui as aui
12 else :
13     import aui
14 from chemins import ConstructPathOut, ChdTxtPathOut, FFF, ffr, PathOut, StatTxtPathOut, simipath
15 from ConfigParser import ConfigParser
16 from functions import ReadProfileAsDico, GetTxtProfile, read_list_file, ReadList, exec_rcode, print_liste, BugReport, DoConf, indices_simi, check_Rresult, progressbar
17 from ProfList import ProfListctrlPanel
18 from guiparam3d import param3d, simi3d
19 from PrintRScript import write_afc_graph, print_simi3d, PrintSimiScript
20 from profile_segment import ProfileSegment
21 from functions import ReadList
22 from listlex import *
23 from Liste import *
24 from search_tools import SearchFrame
25 from dialog import PrefGraph, PrefExport, PrefSimpleFile, PrefDendro
26 from guifunct import SelectColumn, PrepSimi, PrefSimi
27 from corpus import Corpus
28 import datetime
29 import sys
30 import tempfile
31 from time import sleep
32 import shutil
33 import codecs
34 import logging
35
36 log = logging.getLogger('iramuteq.layout')
37
38
39 class GraphPanelAfc(wx.Panel):
40     def __init__(self, parent, dico, list_graph, clnb, itempath = 'liste_graph_afc', coding = sys.getdefaultencoding()):
41         wx.Panel.__init__(self,parent)
42         self.afcnb = 1
43         self.clnb = clnb
44         self.Dict = dico
45         self.coding = coding
46         self.itempath = itempath
47         self.parent = self.GetParent()#parent
48         self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Arial"))
49         self.labels = []
50         self.listimg = []
51         self.buts = []
52         self.list_graph = list_graph
53         self.TabCHD = self.parent.GetParent()
54         self.nb = self.TabCHD.GetParent()
55         self.ira = self.nb.GetParent()
56         self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
57         afc_img = wx.Image(os.path.join(self.ira.images_path,'button_afc.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
58         self.butafc = wx.BitmapButton(self, -1, afc_img)
59         self.Bind(wx.EVT_BUTTON, self.afc_graph, self.butafc)
60         self.dirout = os.path.dirname(self.Dict['ira'])
61         b = 0
62         todel = []
63         for i in range(0,len(list_graph)):
64             if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
65                 filename, ext = os.path.splitext(list_graph[i][0])
66                 if ext == '.svg' :
67                     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])))
68                 else :
69                     self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
70                 if os.path.exists(os.path.join(self.dirout,list_graph[i][0] + '_notplotted.csv')) :
71                    txt = u' - liste des points non représentés : %s' % os.path.join(self.dirout,list_graph[i][0] + '_notplotted.csv')
72                 else :
73                     txt = ''
74                 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1] + txt))
75                 self.buts.append(wx.Button(self.panel_1, wx.ID_DELETE, name = `i - b`))
76             else :
77                 todel.append(i)
78                 b += 1
79         self.list_graph = [graph for i, graph in enumerate(self.list_graph) if i not in todel]
80                 
81         self.param = { 'typegraph' : 0, 
82               'width' : 800,
83               'height' : 800,
84               'what' : 0,
85               'qui' : 0,
86               'do_select_nb' : 0,
87               'do_select_chi' : 0,
88               'do_select_chi_classe' : 0,
89               'select_nb' : 50,
90               'select_chi' : 4,
91               'nbchic' : 30,
92               'over' : 0, 
93               'cex_txt' : 0,
94               'txt_min' : 5,
95               'txt_max' : 40,
96               'tchi' : 0,
97               'tchi_min' : 5,
98               'tchi_max' : 40,
99               'taillecar' : 9,
100               'facteur' : [1,2,3],
101               'alpha' : 10,
102               'clnb' : clnb,
103               'svg' : 0,
104             }
105
106         self.__set_properties()
107         self.__do_layout()
108
109     def __set_properties(self):
110         self.panel_1.EnableScrolling(True,True)
111         #self.panel_1.SetSize((1000,1000))
112         self.panel_1.SetScrollRate(20, 20)
113         self.panel_1.SetFocus()
114
115     def __do_layout(self):    
116         self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
117         self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
118         self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
119         self.sizer_2.Add(self.butafc, 0, 0, 0)
120         for i in range(0, len(self.listimg)):
121             self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
122             self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
123             self.sizer_3.Add(self.buts[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
124             self.Bind(wx.EVT_BUTTON, self.on_delete_image, self.buts[i])
125         self.panel_1.SetSizer(self.sizer_3)
126         self.sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0)
127         self.SetSizer(self.sizer_2) 
128
129     def on_delete_image(self, event) :
130         image_id = int(event.GetEventObject().GetName())
131         image_path = self.list_graph[image_id][0]
132         message = 'This file will be delete : %s.\nAre you sure ?' % os.path.join(self.dirout, image_path)
133         dial = wx.MessageDialog(self, message, style = wx.YES_NO)
134         res = dial.ShowModal()
135         if res == wx.ID_YES :
136             dial.Destroy()
137             log.info('delete image %i' % image_id)
138             oldimg = self.listimg.pop(image_id)
139             oldimg.Destroy()
140             oldlab = self.labels.pop(image_id)
141             oldlab.Destroy()
142             oldbut = self.buts.pop(image_id)
143             oldbut.Show(False)
144             for i, but in enumerate(self.buts) :
145                 but.SetName(`i`)
146             todel = self.list_graph.pop(image_id)
147             os.remove(os.path.join(self.dirout, todel[0]))
148             print_liste(self.Dict[self.itempath], self.list_graph)
149             self.sizer_3.Fit(self.panel_1)
150             self.Layout()
151         else :
152             dial.Destroy()
153         
154
155     def afc_graph(self,event):
156         #dirout = os.path.dirname(self.Dict['ira'])
157         while os.path.exists(os.path.join(self.dirout,'graph_afc_'+str(self.afcnb)+'.png')):
158             self.afcnb +=1
159         self.fileout = ffr(os.path.join(self.dirout,'graph_afc_'+str(self.afcnb)+'.png'))
160         dial = PrefGraph(self.parent,-1,self.param,'')
161         dial.CenterOnParent()
162         val = dial.ShowModal()
163         if val == wx.ID_OK :
164             if dial.choix_format.GetSelection() == 0 :
165                 svg = 0
166             else :
167                 svg = 1
168             self.param = {'typegraph' : dial.choicetype.GetSelection(),
169                           'width' : dial.spin1.GetValue(),
170                           'height' : dial.spin2.GetValue(),
171                           'what' : dial.choice1.GetSelection(),
172                           'qui' : dial.choice2.GetSelection(),
173                           'do_select_nb' : dial.check1.GetValue(),
174                           'do_select_chi' : dial.check2.GetValue(),
175                           'do_select_chi_classe' : dial.check_chic.GetValue(),
176                           'select_nb' : dial.spin_nb.GetValue(),
177                           'select_chi' : dial.spin_chi.GetValue(),
178                           'nbchic' : dial.spin_nbchic.GetValue(),
179                           'over' : dial.check3.GetValue(), 
180                           'cex_txt' : dial.check4.GetValue(),
181                           'txt_min' : dial.spin_min.GetValue(),
182                           'txt_max' : dial.spin_max.GetValue(),
183                           'tchi' : dial.check_tchi.GetValue(),
184                           'tchi_min' : dial.spin_min_tchi.GetValue(),
185                           'tchi_max' : dial.spin_max_tchi.GetValue(),
186                           'taillecar' : dial.spin3.GetValue(),
187                           'facteur' : [dial.spin_f1.GetValue(),dial.spin_f2.GetValue(), dial.spin_f3.GetValue()],
188                           'clnb' : self.clnb,
189                           'film' : str(dial.film.GetValue()).upper(),
190                           'alpha' : dial.slider_sphere.GetValue(),
191                           'svg' : svg
192                         }
193             self.nb.parent = self.ira
194             self.DictPathOut = self.Dict
195             self.RscriptsPath = self.ira.RscriptsPath
196             txt = """
197             load("%s")
198             """ % self.DictPathOut['RData']
199             if self.itempath == 'liste_graph_afcf' :
200                 txt += """
201                 afc <- afcf
202                 afc_table <- afcf_table
203                 chistabletot <- specfp
204                 """ 
205             elif self.itempath == 'liste_graph_afct' :
206                 txt +="""
207                 afc <- afct
208                 afc_table <- afct_table
209                 chistabletot <- spectp
210                 """
211             txt += write_afc_graph(self)
212             filetmp = tempfile.mktemp()
213             with open(filetmp, 'w') as f :
214                 f.write(txt)
215             pid = exec_rcode(self.ira.RPath, filetmp)
216             check_Rresult(self.ira, pid)
217             if self.param['typegraph'] == 0 :
218                 txt = 'Variables '
219                 if self.param['qui'] == 0 : value = u'actives'
220                 if self.param['qui'] == 1 : value = u'supplémentaires'
221                 if self.param['qui'] == 2 : value = u'étoilées'
222                 if self.param['qui'] == 3 : value = u'classes'
223                 txt += value + ' - '
224                 if self.param['what'] == 0 : value = u'Coordonnées'
225                 if self.param['what'] == 1 : value = u'Corrélations'
226                 txt += value + u' - facteur %i / %i' % (self.param['facteur'][0], self.param['facteur'][1])
227                 if self.param['do_select_nb'] : txt += u' - sélection de %i variables' % self.param['select_nb']
228                 if self.param['do_select_chi'] : txt += u' - sélection des variables avec chi2 > %i ' % self.param['select_chi']
229                 if self.param['over'] : txt += u' - Eviter les recouvrements'
230                 if self.param['cex_txt'] : txt += u' - taille du texte proportionnel à la masse'
231                 if self.param['tchi'] : txt += u' - taille du texte proportionnel au chi2 d\'association'
232                 #list_graph = read_list_file(self.DictPathOut[self.itempath], self.coding)
233                 if self.param['svg'] :
234                     filename, ext = os.path.splitext(self.fileout)
235                     self.fileout = filename + '.svg'
236                 self.list_graph.append([os.path.basename(self.fileout), txt])
237                 print_liste(self.DictPathOut[self.itempath], self.list_graph)
238                 if not self.param['svg'] :
239                     self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(self.fileout, wx.BITMAP_TYPE_ANY)))
240                 else :
241                     self.listimg.append(hl.HyperLinkCtrl(self.panel_1, -1, self.fileout, URL=self.fileout))
242                 self.sizer_3.Add( self.listimg[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
243                 self.labels.append(wx.StaticText(self.panel_1,-1, txt))
244                 self.sizer_3.Add(self.labels[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
245                 self.buts.append(wx.Button(self.panel_1, wx.ID_DELETE, name = `len(self.list_graph) - 1`))
246                 self.sizer_3.Add(self.buts[-1], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
247                 self.sizer_3.Fit(self.panel_1)
248                 self.Layout()
249     
250                 self.panel_1.Scroll(0,self.panel_1.GetScrollRange(wx.VERTICAL))
251             
252
253 class GraphPanel(wx.ScrolledWindow):
254     def __init__(self, parent, dico, list_graph, txt = '', style = wx.TAB_TRAVERSAL):
255         wx.ScrolledWindow.__init__(self, parent, style = style)
256         self.Dict = dico
257         self.txt = txt
258         self.parent = parent
259         self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Arial"))
260         self.labels = []
261         self.listimg = []
262         self.dirout = os.path.dirname(self.Dict['ira'])
263         self.deb = wx.StaticText(self, -1, txt)
264         for i in range(0,len(list_graph)):
265             if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
266                 filename, ext = os.path.splitext(list_graph[i][0])
267                 if ext == '.svg' :
268                     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])))
269                 else :
270                     self.listimg.append(wx.StaticBitmap(self, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
271                 self.labels.append(wx.StaticText(self, -1, list_graph[i][1]))
272         self.Bind(wx.EVT_MOTION, self.onMouseMove) 
273         self.__set_properties()
274         self.__do_layout()
275
276     def __set_properties(self):
277         self.EnableScrolling(True,True)
278         self.SetScrollRate(20, 20)   
279         self.SetFocus()
280
281
282     def __do_layout(self):
283         self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
284         self.sizer_2 = wx.BoxSizer(wx.VERTICAL)
285         self.sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
286         self.sizer_1.Add(self.deb)   
287         for i in range(0, len(self.listimg)):
288             self.sizer_1.Add(self.listimg[i], 1, wx.ALIGN_CENTER_HORIZONTAL, 0)
289             self.sizer_1.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
290         self.sizer_2.Add(self.sizer_1, 1, wx.EXPAND, 0)
291         self.SetSizer(self.sizer_1)
292         self.sizer_1.Fit(self)
293
294     def onMouseMove(self, event):
295         self.SetFocus()
296        
297
298 def open_antiprofil(panel, AntiProfile, encoding) :
299     DictAnti = ReadProfileAsDico(AntiProfile, True, encoding)
300     panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
301     for i in range(0, panel.parametres['clnb']):
302         tabantiprofile = ProfListctrlPanel(panel, panel, DictAnti[str(i + 1)], True, i + 1)
303         panel.AntiProfNB.AddPage(tabantiprofile, 'classe %s' % str(i + 1))
304     panel.TabChdSim.AddPage(panel.AntiProfNB, 'Antiprofils')
305
306
307
308 def getlemgram(corpus, lem) :
309     if not lem[6] in corpus.lems :
310         return lem[5]
311     else :
312         return corpus.lems[lem[6]].gram
313
314 class OpenCHDS():
315     def __init__(self, parent, corpus, parametres, Alceste=False):
316        #sep = u'\n ' 
317        sep=' '
318        self.parent = parent
319        self.corpus = corpus
320        self.parametres = parametres
321        self.pathout = PathOut(parametres['ira'])
322        self.pathout.basefiles(ChdTxtPathOut)
323        DictPathOut = self.pathout 
324        self.DictPathOut = DictPathOut
325        self.dictpathout = DictPathOut
326        self.parent = parent
327
328        Profile = DictPathOut['PROFILE_OUT']
329        AntiProfile = DictPathOut['ANTIPRO_OUT']
330        self.encoding = self.parametres['encoding']
331        if isinstance(self.corpus, Corpus) :
332             self.corpus.make_ucecl_from_R(self.pathout['uce'])
333             corpname = self.corpus.parametres['corpus_name']
334        else :
335            corpname = self.corpus.parametres['name']
336
337        clnb = parametres['clnb']
338        dlg = progressbar(self, maxi = 4 + clnb) 
339        self.clnb = clnb 
340        print 'lecture des profils'
341        dlg.Update(2, u'lecture des profils')
342  
343        DictProfile = ReadProfileAsDico(Profile, Alceste, self.encoding)
344        self.DictProfile = DictProfile
345        self.cluster_size = []
346        #print 'lecture des antiprofils'
347        #DictAnti = ReadProfileAsDico(self, AntiProfile, Alceste, self.encoding)
348
349        panel = wx.Panel(parent, -1)
350        sizer1 = wx.BoxSizer(wx.VERTICAL)
351
352        if os.path.exists(DictPathOut['pre_rapport']):
353            with codecs.open(DictPathOut['pre_rapport'], 'r', self.encoding) as f :
354                 txt = f.read()
355            self.debtext = txt
356        else :
357            self.debtext = ''
358 #       panel.chd_toolbar = wx.ToolBar(panel, -1, wx.DefaultPosition, wx.DefaultSize, wx.TB_FLAT | wx.TB_NODIVIDER)
359 #       panel.chd_toolbar.SetToolBitmapSize(wx.Size(16, 16))
360
361        if isinstance(self.corpus, Corpus) :
362            panel.corpus = self.corpus
363        else :
364            panel.tableau = self.corpus
365            #self.parent.tableau = panel.tableau
366        panel.dictpathout = self.DictPathOut
367        panel.pathout = self.DictPathOut
368        panel.parent = self.parent
369        panel.DictProfile = self.DictProfile
370        panel.cluster_size = self.cluster_size
371        panel.debtext = self.debtext
372
373 #       self.ID_rapport = wx.NewId()
374 #       #rap_img = wx.Image(os.path.join(self.parent.images_path,'icone_rap_16.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
375 #       #panel.chd_toolbar.AddLabelTool(self.ID_rapport, "rapport", rap_img, shortHelp=u"Produire le rapport", longHelp=u"Exporter un rapport en texte simple")
376 #       butrap = wx.Button(panel.chd_toolbar, self.ID_rapport, u"Rapport ")
377 #       panel.chd_toolbar.AddControl(butrap)
378 #       
379 #       panel.chd_toolbar.Realize()
380 #       sizer1.Add(panel.chd_toolbar,0, wx.EXPAND, 5)
381
382        #self.TabChdSim = wx.aui.AuiNotebook(self.parent.nb, -1, wx.DefaultPosition)
383        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
384        panel.TabChdSim = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
385        panel.TabChdSim.SetAGWWindowStyleFlag(notebook_flags)
386        panel.TabChdSim.SetArtProvider(aui.ChromeTabArt())
387        sizer1.Add(panel.TabChdSim,10, wx.EXPAND, 5)
388        panel.SetSizer(sizer1)
389        sizer1.Fit(panel)
390        
391
392        if isinstance(self.corpus, Corpus) :
393            panel.TabChdSim.corpus = corpus
394            panel.TabChdSim.corpus.dictpathout = self.DictPathOut
395        else :
396            panel.TabChdSim.tableau = corpus
397            panel.TabChdSim.tableau.dictpathout = self.DictPathOut
398        panel.parametres = self.parametres
399        self.panel = panel
400
401        self.notenb = self.parent.nb.GetPageCount()
402
403            
404        if os.path.exists(self.DictPathOut['liste_graph_chd']) :
405            list_graph = read_list_file(self.DictPathOut['liste_graph_chd'], self.encoding)
406            CHD = GraphPanelDendro(panel.TabChdSim, DictPathOut, list_graph, txt = self.debtext)
407            panel.TabChdSim.AddPage(CHD,'CHD')
408                
409        panel.ProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
410        panel.ProfNB.SetArtProvider(aui.ChromeTabArt())
411        #self.ProfNB.SetTabCtrlHeight(100)
412        #panel.AntiProfNB = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
413        if os.path.exists(DictPathOut['prof_seg']) :
414             prof_seg = ReadProfileAsDico(DictPathOut['prof_seg'], False, self.encoding)
415             self.prof_seg_nb = aui.AuiNotebook(panel, -1, wx.DefaultPosition)
416        for i in range(0, clnb):
417             self.cluster_size.append(DictProfile[str(i + 1)][0][0:3])
418             if isinstance(self.corpus, Corpus) :
419                 DictProfile[str(i + 1)][1:] = [val[0:5] + [getlemgram(self.corpus, val)] + val[6:] for val in DictProfile[str(i + 1)][1:]]
420             dlg.Update(3+i, 'Classe %i' %(i+1))
421             ind = '/'.join(DictProfile[str(i + 1)][0][0:2])
422             indpour = ' - '.join([ind, DictProfile[str(i + 1)][0][2]])
423             self.tabprofile = ProfListctrlPanel(self.parent, self.panel, DictProfile[str(i + 1)], Alceste, i + 1)
424             #self.tabantiprofile = ProfListctrlPanel(self.parent, self, DictAnti[str(i + 1)], Alceste, i + 1)
425             panel.ProfNB.AddPage(self.tabprofile, 'classe %s %s(%s%%)' % (str(i + 1), sep, indpour))
426             #panel.AntiProfNB.AddPage(self.tabantiprofile, 'classe %s' % str(i + 1))
427             if os.path.exists(DictPathOut['prof_seg']) :
428                 self.tab_prof_seg = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1)
429                 self.prof_seg_nb.AddPage(self.tab_prof_seg, 'classe %i' % (i + 1))
430
431        if clnb > 2 :
432            self.TabAFC = aui.AuiNotebook(panel.TabChdSim, -1, wx.DefaultPosition)
433            log.info('read AFC') 
434            list_graph=read_list_file(DictPathOut['liste_graph_afc'], self.encoding)
435            self.tabAFCGraph = GraphPanelAfc(self.TabAFC, DictPathOut, list_graph, self.clnb, coding=self.encoding)
436            self.TabAFC.AddPage(self.tabAFCGraph, 'AFC')
437            
438            if os.path.exists(self.DictPathOut['afc_facteur']) :
439                dictrow, first = ReadList(self.DictPathOut['afc_facteur'], self.encoding)
440                self.TabAFC_facteur = ListForSpec(self.parent, parametres, dictrow, first)
441                #dictrow, first = ReadList(self.DictPathOut['afc_row'], self.encoding)
442                #self.TabAFC_ligne = ListForSpec(self.parent, self.parametres, dictrow, first)
443                #dictrow, first = ReadList(self.DictPathOut['afc_col'], self.encoding)
444                #self.TabAFC_colonne = ListForSpec(parent, self.parametres, dictrow, first)
445                self.TabAFC.AddPage(self.TabAFC_facteur, 'Facteurs')
446                #self.TabAFC.AddPage(self.TabAFC_colonne, u'Colonnes')
447                #self.TabAFC.AddPage(self.TabAFC_ligne, u'Lignes')
448            
449            sizer_3 = wx.BoxSizer(wx.VERTICAL)
450            self.parent.nb_panel_2 = wx.Panel(panel.TabChdSim, -1)
451            self.parent.button_simi = wx.Button(self.parent.nb_panel_2, -1, "Voyager")
452            self.parent.simi3dpanel = simi3d(self.parent.nb_panel_2, -1)
453            sizer_3.Add(self.parent.simi3dpanel, 1, wx.EXPAND, 0)
454            sizer_3.Add(self.parent.button_simi, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
455            self.parent.nb_panel_2.SetSizer(sizer_3)
456            self.TabAFC.AddPage(self.parent.nb_panel_2, "graph 3D")
457            self.parent.Bind(wx.EVT_BUTTON, self.onsimi, self.parent.button_simi)
458        
459        panel.TabChdSim.AddPage(panel.ProfNB, 'Profils')
460        #panel.TabChdSim.AddPage(panel.AntiProfNB, 'Antiprofils')
461        dlg.Update(4 + self.clnb, 'Affichage...')
462        if clnb > 2 :
463            panel.TabChdSim.AddPage(self.TabAFC, 'AFC')
464        if os.path.exists(DictPathOut['prof_seg']) :
465            panel.TabChdSim.AddPage(self.prof_seg_nb, u'Profils des segments répétés')
466       
467 #       panel.Bind(wx.EVT_BUTTON, self.ongetrapport, id = self.ID_rapport)
468        self.parent.nb.AddPage(panel, 'Classification - %s' % corpname)
469        self.parent.ShowTab(True)
470        self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1)     
471        #for pane in self.parent._mgr.GetAllPanes() :
472        #     if isinstance(pane.window, aui.AuiNotebook):
473        #         nb = pane.window
474        #         nb.SetAGWWindowStyleFlag(notebook_flags)
475        #         nb.SetArtProvider(aui.ChromeTabArt())
476        dlg.Destroy() 
477        self.parent._mgr.Update()
478         
479     def onsimi(self,event):
480         outfile = print_simi3d(self)
481         error = exec_rcode(self.parent.RPath, outfile, wait = True)
482
483     def onclusterstat(self, evt) :
484         dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.csv', 'title': 'Stat par classe'})
485         dial.fbb.SetValue( os.path.join(os.path.dirname(self.corpus.dictpathout['ira']), 'stat_par_classe.csv'))
486         dial.CenterOnParent()
487         res = dial.ShowModal()
488         if res == wx.ID_OK :
489             fileout = dial.fbb.GetValue()
490             dial.Destroy()
491             self.corpus.get_stat_by_cluster(fileout)
492             msg = u"Fini !"
493             dlg = wx.MessageDialog(self.parent, msg, u"Stat par classe", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
494             dlg.CenterOnParent()
495             if dlg.ShowModal() == wx.ID_OK :
496                 dlg.Destroy()
497
498     #def onsearchf(self, evt) :
499     #    if 'FrameSearch' not in dir(self.panel) :
500     #        self.panel.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.corpus)
501     #    self.panel.FrameSearch.Show()
502     
503         
504
505 def PrintRapport(self, corpus, parametres, istxt = True):
506     #if sys.platform == 'win32':
507     #    sep = '\r\n'
508     #else:
509     sep = '\n'
510     txt = """
511 +-+-+-+-+-+-+-+-+
512 |i|R|a|M|u|T|e|Q| - %s
513 +-+-+-+-+-+-+-+-+
514
515
516 """ % datetime.datetime.now().ctime()
517     if istxt :
518         totocc = corpus.gettotocc()
519         txt += u'nombre de textes: %i%s' % (corpus.getucinb(), sep)
520         txt += u'nombre de segments de textes: %i%s' % (corpus.getucenb(), sep)
521         txt += u'nombre de formes: %i%s' % (len(corpus.formes), sep)
522         txt += u'nombre d\'occurrences: %i%s' % (totocc, sep)
523         txt += u'moyenne d\'occurrences par forme: %f%s' % (float(totocc) / float(len(self.corpus.formes)), sep)
524         txt += u'nombre de lemmes: %i%s' % (len(corpus.lems), sep)
525         txt += u'nombre de formes actives: %i%s' % (corpus.getactivesnb(1), sep)
526         txt += u'nombre de formes supplémentaires: %i%s' % (corpus.getactivesnb(2), sep)
527         txt += u'nombre de formes actives de fréquence >= %i: %i%s' % (parametres['eff_min_forme'], parametres['nbactives'], sep)
528         txt += u'moyenne d\'occurrences par segments :%f%s' % (float(totocc) / float(corpus.getucenb()), sep)
529         if 'tailleuc1' in parametres :
530             if parametres['classif_mode'] == 0 :
531                 txt += u'taille rst1 / rst2: %i / %i - %i / %i%s' % (parametres['tailleuc1'], parametres['tailleuc2'], parametres['lenuc1'], parametres['lenuc2'], sep)
532     else :
533         self.Ucenb = self.nbind
534         txt += u'nombre d\'individus : %i%s' % (self.nbind, sep)
535         txt += u'nombre de classes : %i%s' % (self.clnb, sep)
536     if istxt :
537         txt += u'nombre de classes : %i%s' % (parametres['clnb'], sep)
538         if parametres['classif_mode'] == 0 or parametres['classif_mode'] == 1 :
539             txt += u'%i segments classés sur %i (%.2f%%)%s' % (sum([len(cl) for cl in corpus.lc]), corpus.getucenb(), (float(sum([len(cl) for cl in corpus.lc])) / float(corpus.getucenb())) * 100, sep)
540         elif self.parametres['classif_mode'] == 2 :
541             txt += u'%i textes classés sur %i (%.2f%%)%s' % (sum([len(cl) for cl in corpus.lc]), corpus.getucinb(), (float(sum([len(cl) for cl in corpus.lc]))) / float(corpus.getucinb()) * 100, sep)
542     else :
543         txt += u'%i segments classées sur %i (%.2f%%)%s' % (self.ucecla, self.Ucenb, (float(self.ucecla) / float(self.Ucenb)) * 100, sep)
544  
545     txt += """
546 ###########################
547 temps d'analyse : %s
548 ###########################
549 """ % parametres.get('time', '')
550     with open(self.pathout['pre_rapport'], 'w') as f :
551         f.write(txt)
552
553
554 class SashList(wx.Panel) :
555     def __init__(self, parent) :
556         wx.Panel.__init__(self, parent, -1)
557         self.parent=parent
558         winids = []
559         #self.gparent=gparent
560         #self.dlist=dlist
561         #self.first = first
562         #self.menu = menu        
563         # A window to the left of the client window
564         #self.listlex = listlex
565         self.leftwin1 =  wx.SashLayoutWindow(
566                 self, -1, wx.DefaultPosition, (200, 300), 
567                 wx.NO_BORDER|wx.SW_3D
568                 )
569
570         self.leftwin1.SetDefaultSize((120, 1000))
571         self.leftwin1.SetOrientation(wx.LAYOUT_VERTICAL)
572         self.leftwin1.SetAlignment(wx.LAYOUT_LEFT)
573         self.leftwin1.SetBackgroundColour(wx.Colour(0, 255, 0))
574         self.leftwin1.SetSashVisible(wx.SASH_RIGHT, True)
575         self.leftwin1.SetExtraBorderSize(10)
576         
577         #textWindow = wx.TextCtrl(
578         #                leftwin1, -1, "", wx.DefaultPosition, wx.DefaultSize, 
579         #                wx.TE_MULTILINE|wx.SUNKEN_BORDER
580         #                )
581
582         #textWindow.SetValue("A sub window")
583
584         self.leftWindow1 = self.leftwin1
585         winids.append(self.leftwin1.GetId())
586         
587         rightwin1 =  wx.SashLayoutWindow(
588                 self, -1, wx.DefaultPosition, (200, 300), 
589                 wx.NO_BORDER|wx.SW_3D
590                 )
591
592         rightwin1.SetDefaultSize((120, 1000))
593         rightwin1.SetOrientation(wx.LAYOUT_VERTICAL)
594         rightwin1.SetAlignment(wx.LAYOUT_LEFT)
595         rightwin1.SetBackgroundColour(wx.Colour(0, 255, 0))
596         rightwin1.SetSashVisible(wx.SASH_RIGHT, True)
597         rightwin1.SetExtraBorderSize(10)
598         #textWindow = wx.TextCtrl(
599         #                leftwin1, -1, "", wx.DefaultPosition, wx.DefaultSize, 
600         #                wx.TE_MULTILINE|wx.SUNKEN_BORDER
601         #                )
602
603         #textWindow.SetValue("A sub window")
604
605         self.rightwin1 = rightwin1
606         winids.append(rightwin1.GetId())
607
608
609
610 class dolexlayout :
611     def __init__(self, ira, corpus, parametres):
612         self.pathout = PathOut(dirout = parametres['pathout'])
613         self.corpus = corpus
614         self.dictpathout = StatTxtPathOut(parametres['pathout'])
615         #self.corpus.read_corpus_from_shelves(self.corpus.dictpathout['db'])
616         self.parent = ira
617         self.encoding = self.corpus.parametres['syscoding']
618         self.parametres = parametres
619
620         self.DictSpec, first = ReadList(self.dictpathout['tablespecf'], self.corpus.parametres['syscoding'])
621         self.DictType, firstt = ReadList(self.dictpathout['tablespect'], self.corpus.parametres['syscoding'])
622         self.DictEff, firsteff = ReadList(self.dictpathout['tableafcm'], self.corpus.parametres['syscoding'])
623         self.DictEffType, firstefft = ReadList(self.dictpathout['tabletypem'], self.corpus.parametres['syscoding'])
624         self.DictEffRelForme, firsteffrelf = ReadList(self.dictpathout['eff_relatif_forme'], self.corpus.parametres['syscoding']) 
625         self.DictEffRelType, firsteffrelt = ReadList(self.dictpathout['eff_relatif_type'], self.corpus.parametres['syscoding'])    
626         
627         #sash = SashList(ira.nb)
628         
629         
630         self.TabStat = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition)
631         self.TabStat.parametres = parametres
632         self.ListPan = ListForSpec(ira, self, self.DictSpec, first)
633         #self.ListPan2 = ListForSpec(sash.rightwin1, self, self.DictSpec, first)
634         self.ListPant = ListForSpec(ira, self, self.DictType, firstt)
635         self.ListPanEff = ListForSpec(ira, self, self.DictEff, firsteff)
636         self.ListPanEffType = ListForSpec(ira, self, self.DictEffType, firstefft)
637         self.ListPanEffRelForme = ListForSpec(ira, self, self.DictEffRelForme, firsteffrelf)
638         self.ListPanEffRelType = ListForSpec(ira, self.parent, self.DictEffRelType, firsteffrelt)
639         
640         self.TabStat.AddPage(self.ListPan, u'formes') 
641         self.TabStat.AddPage(self.ListPant, u'Types')
642         self.TabStat.AddPage(self.ListPanEff, u'Effectifs formes')
643         self.TabStat.AddPage(self.ListPanEffType, u'Effectifs Type')
644         self.TabStat.AddPage(self.ListPanEffRelForme, u'Effectifs relatifs formes')
645         self.TabStat.AddPage(self.ListPanEffRelType, u'Effectifs relatifs Type')
646         if self.parametres['clnb'] > 2 :
647            self.TabAFC = aui.AuiNotebook(self.TabStat, -1, wx.DefaultPosition)
648            list_graph=read_list_file(self.dictpathout['liste_graph_afcf'], encoding = self.encoding)
649            self.tabAFCGraph = GraphPanelAfc(self.TabAFC, self.dictpathout, list_graph, self.parametres['clnb'], itempath ='liste_graph_afcf', coding = self.encoding)
650            self.TabAFC.AddPage(self.tabAFCGraph, 'AFC formes')
651            list_graph=read_list_file(self.dictpathout['liste_graph_afct'], encoding = self.encoding)
652            self.tabAFCTGraph = GraphPanelAfc(self.TabAFC, self.dictpathout, list_graph, self.parametres['clnb'], itempath ='liste_graph_afct', coding=self.encoding)
653            self.TabAFC.AddPage(self.tabAFCTGraph, 'AFC type')
654            self.TabStat.AddPage(self.TabAFC, 'AFC')
655            
656         
657         ira.nb.AddPage(self.TabStat, u'Spécificités')
658         
659         self.TabStat.corpus = self.corpus
660         ira.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
661         ira.ShowAPane("Tab_content")
662
663 class StatLayout:
664     def __init__(self, ira, corpus, parametres):
665         self.pathout = PathOut(dirout = parametres['pathout'])
666         self.corpus = corpus
667         self.ira = ira
668         self.read_result()
669         self.TabStat = aui.AuiNotebook(ira.nb, -1, wx.DefaultPosition)
670         self.TabStat.parametres = parametres
671         self.TabStat.corpus = corpus
672         self.TabStat.pathout = self.pathout
673 #        CHD = GraphPanel(panel.TabChdSim, DictPathOut, list_graph, txt = self.debtext)
674          #      panel.TabChdSim.AddPage(CHD,'CHD')
675
676         #self.TabStatTot = wx.TextCtrl(self.TabStat, -1, style=wx.NO_BORDER | wx.TE_MULTILINE | wx.TE_RICH2)
677         list_graph = [['zipf.png', 'zipf']]
678         self.TabStatTot = GraphPanel(ira.nb, self.pathout, list_graph, self.result['glob'])
679         self.TabStat.AddPage(self.TabStatTot, 'global')
680         for item in self.result:
681             if item != 'glob':
682                 datam = [['forme', 'nb']]
683                 self.ListPan = ListPanel(ira, self, self.result[item])
684                 self.TabStat.AddPage(self.ListPan, ' '.join(item.split('_'))) 
685         ira.nb.AddPage(self.TabStat, '%s' % parametres['name'])
686         ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
687         ira.ShowAPane("Tab_content")
688
689     def read_result(self) :
690         lcle = {'total' :u'total.csv', u'formes_actives':u'formes_actives.csv', u'formes_supplémentaires':u'formes_supplémentaires.csv', u'hapax': u'hapax.csv'}
691         self.result = {}
692         for key in lcle :
693             with open(self.pathout[lcle[key]], 'r') as f :
694                 self.result[key] = [line.split(';') for line in f.read().splitlines()]
695                 self.result[key] = dict([[i,[line[0],int(line[1]), line[2]]] for i, line in enumerate(self.result[key])])
696         with open(self.pathout['glob.txt'], 'r') as f :
697             self.result['glob'] = f.read()
698
699 class GraphPanelDendro(wx.Panel):
700     def __init__(self,parent, dico, list_graph, txt=False):
701         wx.Panel.__init__(self,parent)
702         self.graphnb = 1
703         self.dictpathout = dico
704         self.dirout = os.path.dirname(self.dictpathout['ira'])
705         self.list_graph = list_graph
706         self.parent = self.GetParent()#parent
707         self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Arial"))
708         self.labels = []
709         self.listimg = []
710         self.tabchd = self.parent.GetParent()
711         self.ira = self.tabchd.GetParent()
712         self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
713         self.panel_1.SetBackgroundColour('white')
714         self.deb = wx.StaticText(self.panel_1, -1, txt)
715         dendro_img = wx.Image(os.path.join(self.ira.images_path,'but_dendro.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
716         self.butdendro = wx.BitmapButton(self, -1, dendro_img)
717         self.butdendrotexte = wx.BitmapButton(self, -1, dendro_img)
718         self.butdendrocloud = wx.BitmapButton(self, -1, dendro_img)
719         
720         for i in range(0,len(list_graph)):
721             if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
722                 self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
723                 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
724                 
725         self.__set_properties()
726         self.__do_layout()
727
728     def __set_properties(self):
729         self.panel_1.EnableScrolling(True,True)
730         #self.panel_1.SetSize((1000,1000))
731         self.panel_1.SetScrollRate(20, 20)
732         self.panel_1.SetFocus()
733         self.Bind(wx.EVT_BUTTON, self.ondendro, self.butdendro)
734         self.Bind(wx.EVT_BUTTON, self.ondendrotexte, self.butdendrotexte)
735         self.Bind(wx.EVT_BUTTON, self.ondendrocloud, self.butdendrocloud)
736         self.param = {'width' : 700,
737                        'height': 500,
738                        'type_dendro': 0,
739                        'color_nb': 0,
740                        'taille_classe' : True,
741                        'type_tclasse' : 0
742                      }
743         self.type_dendro = [ u"phylogram", u"cladogram", u"fan", u"unrooted", u"radial" ]
744
745     def __do_layout(self):    
746         self.sizer_1 = wx.BoxSizer(wx.VERTICAL)
747         self.sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
748         self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
749         self.sizer_3.Add(self.deb)
750         self.sizer_1.Add(self.butdendro, 0, 0, 0)
751         self.sizer_1.Add(self.butdendrotexte, 0, 0, 0)
752         self.sizer_1.Add(self.butdendrocloud, 0, 0, 0)
753
754         for i in range(0, len(self.listimg)):
755             self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
756             self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
757         self.panel_1.SetSizer(self.sizer_3)
758         self.sizer_2.Add(self.sizer_1, 0, wx.EXPAND, 0)
759         self.sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0)
760         self.SetSizer(self.sizer_2) 
761
762     def make_param(self, dial):
763         self.param['width'] = dial.m_spinCtrl2.GetValue()
764         self.param['height'] = dial.m_spinCtrl1.GetValue()
765         self.param['type_dendro'] = dial.m_choice1.GetSelection()
766         self.param['color_nb'] = dial.m_radioBox1.GetSelection()
767         self.param['taille_classe'] = dial.m_checkBox1.GetValue()
768         self.param['type_tclasse'] = dial.m_radioBox2.GetSelection()
769
770     def make_dendro(self, dendro = 'simple') :
771         while os.path.exists(os.path.join(self.dirout, 'dendrogamme_' + str(self.graphnb)+'.png')) :
772             self.graphnb += 1
773         fileout = ffr(os.path.join(self.dirout,'dendrogamme_' + str(self.graphnb)+'.png'))
774         width = self.param['width']
775         height = self.param['height']
776         type_dendro = self.type_dendro[self.param['type_dendro']]
777         if self.param['taille_classe'] :
778             tclasse = 'TRUE'
779         else :
780             tclasse = 'FALSE'
781         if self.param['color_nb'] == 0 :
782             bw = 'FALSE'
783         else :
784             bw = 'TRUE'
785         if self.param['type_tclasse'] == 0 :
786             histo='FALSE'
787         else :
788             histo = 'TRUE'
789         dendro_path = self.dictpathout['Rdendro']
790         classe_path = self.dictpathout['uce']
791         txt = """
792         library(ape)
793         load("%s")
794         source("%s")
795         classes <- read.csv2("%s", row.names=1)
796         classes <- classes[,1]
797         """ % (ffr(dendro_path), ffr(self.ira.RscriptsPath['Rgraph']),  ffr(classe_path))
798         if dendro == 'simple' :
799             txt += """
800             open_file_graph("%s", width=%i, height=%i)
801             plot.dendropr(tree.cut1$tree.cl, classes, type.dendro="%s", histo=%s, bw=%s, lab=NULL, tclasse=%s)
802             """ % (ffr(fileout), width, height, type_dendro, histo, bw, tclasse)
803         elif dendro == 'texte' :
804             txt += """
805             load("%s")
806             source("%s")
807             chistable <- chistabletot[1:(debsup-1),]
808             open_file_graph("%s", width=%i, height=%i)
809             plot.dendro.prof(tree.cut1$tree.cl, classes, chistable, nbbycl = 60, type.dendro="%s", bw=%s, lab=NULL)
810             """ % (ffr(self.dictpathout['RData.RData']), ffr(self.ira.RscriptsPath['Rgraph']), ffr(fileout), width, height, type_dendro, bw)
811         elif dendro == 'cloud' :
812             txt += """
813             load("%s")
814             source("%s")
815             chistable <- chistabletot[1:(debsup-1),]
816             open_file_graph("%s", width=%i, height=%i)
817             plot.dendro.cloud(tree.cut1$tree.cl, classes, chistable, nbbycl = 300, type.dendro="%s", bw=%s, lab=NULL)
818             """ % (ffr(self.dictpathout['RData.RData']), ffr(self.ira.RscriptsPath['Rgraph']), ffr(fileout), width, height, type_dendro, bw)
819
820
821         tmpfile = tempfile.mktemp()
822         with open(tmpfile, 'w') as f :
823             f.write(txt)
824         error = exec_rcode(self.ira.RPath, tmpfile, wait=True) 
825         check_Rresult(self.ira, error)
826         self.list_graph.append([fileout, 'Dendrogramme CHD1 - %s' %  type_dendro])
827         print_liste(self.dictpathout['liste_graph_chd'], self.list_graph)
828         self.sizer_3.Add(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(fileout, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
829         self.sizer_3.Add(wx.StaticText(self.panel_1,-1, 'Dendrogramme CHD1 - %s' %  type_dendro), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
830         self.sizer_3.Fit(self.panel_1)
831         self.Layout()
832         self.panel_1.Scroll(0,self.panel_1.GetScrollRange(wx.VERTICAL))
833
834
835     def ondendro(self, evt):
836         dial = PrefDendro(self.ira, self.param)
837         val = dial.ShowModal()
838         if val == wx.ID_OK :
839             self.make_param(dial)
840             self.make_dendro()
841     
842     def ondendrotexte(self, evt):
843         dial = PrefDendro(self.ira, self.param)
844         val = dial.ShowModal()
845         if val == wx.ID_OK :
846             self.make_param(dial)
847             self.make_dendro(dendro = 'texte')
848
849     def ondendrocloud(self, evt):
850         dial = PrefDendro(self.ira, self.param)
851         val = dial.ShowModal()
852         if val == wx.ID_OK :
853             self.make_param(dial)
854             self.make_dendro(dendro = 'cloud')
855
856 class OpenCorpus :
857     def __init__(self, ira, parametres) :
858         #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)
859         self.panel = CopusPanel(ira, parametres)
860         ira.nb.AddPage(self.panel, 'Description %s' % parametres['corpus_name'])
861         #self.text.write(DoConf().totext(parametres))
862         ira.nb.SetSelection(ira.nb.GetPageCount() - 1)
863         ira.ShowAPane("Tab_content")
864
865 class CopusPanel(wx.Panel) :
866     def __init__(self, parent, parametres) :
867         wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.TAB_TRAVERSAL )
868         self.parametres = parametres
869         fgSizer5 = wx.FlexGridSizer( 0, 2, 0, 0 )
870         fgSizer5.SetFlexibleDirection( wx.BOTH )
871         fgSizer5.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )        
872         self.fgSizer5 = fgSizer5
873         
874         self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, u"Description du corpus", wx.DefaultPosition, wx.DefaultSize, 0 )
875
876         self.m_staticText18.Wrap( -1 )
877         fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
878         
879         self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, u"", wx.DefaultPosition, wx.DefaultSize, 0 )
880         self.m_staticText19.Wrap( -1 )
881         fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
882
883         self.m_staticText20 = wx.StaticText( self, wx.ID_ANY, u"Nom", wx.DefaultPosition, wx.DefaultSize, 0 )
884         self.m_staticText20.Wrap( -1 )
885         fgSizer5.Add( self.m_staticText20, 0, wx.ALL, 5 )
886         
887         self.m_staticText21 = wx.StaticText( self, wx.ID_ANY, parametres['corpus_name'], wx.DefaultPosition, wx.DefaultSize, 0 )
888         self.m_staticText21.Wrap( -1 )
889         fgSizer5.Add( self.m_staticText21, 0, wx.ALL, 5 )
890
891         description = {'lang' : u'langue',
892                        'encoding' : u'encodage',
893                        'ucinb' : u'Nombre de textes',
894                        'ucenb' : u'Nombre de segments de texte',
895                        'formesnb' : u'Nombre de formes',
896                        'hapax' : u'Nombre d\'hapax'
897                       }
898
899         keys = ['lang', 'encoding', 'originalpath', 'pathout', 'date', 'time']
900
901         self.addkeys(keys, description)
902
903         self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, u"Paramètres", wx.DefaultPosition, wx.DefaultSize, 0 )
904         self.m_staticText18.Wrap( -1 )
905         fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
906         
907         self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, u"", wx.DefaultPosition, wx.DefaultSize, 0 )
908         self.m_staticText19.Wrap( -1 )
909         fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
910
911         keys = ['ucemethod', 'ucesize', 'keep_caract', 'expressions']
912         self.addkeys(keys, description)
913
914         self.m_staticText18 = wx.StaticText( self, wx.ID_ANY, u"Statistiques", wx.DefaultPosition, wx.DefaultSize, 0 )
915         self.m_staticText18.Wrap( -1 )
916         fgSizer5.Add( self.m_staticText18, 0, wx.ALL, 5 )
917         
918         self.m_staticText19 = wx.StaticText( self, wx.ID_ANY, u"", wx.DefaultPosition, wx.DefaultSize, 0 )
919         self.m_staticText19.Wrap( -1 )
920         fgSizer5.Add( self.m_staticText19, 0, wx.ALL, 5 )
921
922         keys = ['ucinb', 'ucenb', 'occurrences', 'formesnb', 'hapax']
923         self.addkeys(keys, description)
924
925         self.SetSizer( fgSizer5 )
926         self.Layout()
927
928     def addkeys(self, keys, description) :
929         for key in keys :
930             option = self.parametres.get(key,u'non défini')
931             if isinstance(option, int) :
932                 option = `option`
933             text = wx.StaticText( self, wx.ID_ANY, description.get(key, key), wx.DefaultPosition, wx.DefaultSize, 0 )
934             text.Wrap( -1 )
935             self.fgSizer5.Add( text, 0, wx.ALL, 5 )
936
937             text = wx.StaticText( self, wx.ID_ANY, option, wx.DefaultPosition, wx.DefaultSize, 0 )
938             text.Wrap( -1 )
939             self.fgSizer5.Add( text, 0, wx.ALL, 5 )
940
941 class DefaultTextLayout :
942     def __init__(self, ira, corpus, parametres) :
943         self.pathout = PathOut(dirout = parametres['pathout'])
944         self.ira = ira
945         self.parent = ira
946         self.parametres = parametres
947         self.corpus = corpus
948         self.dolayout()
949     
950     def dolayout(self) :
951         log.info('no layout yet')
952
953 class WordCloudLayout(DefaultTextLayout):
954     def dolayout(self):
955         self.pathout.basefiles(simipath)
956         self.Tab = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
957         if self.parametres['svg'] :
958             list_graph = [['nuage_1.svg', 'Nuage']]
959         else :
960             list_graph = [['nuage_1.png', 'Nuage']]
961         self.TabStatTot = GraphPanel(self.ira.nb, self.pathout, list_graph)
962         self.Tab.AddPage(self.TabStatTot, 'Nuage')
963         self.Tab.corpus = self.corpus
964         self.Tab.parametres = self.parametres
965         self.ira.nb.AddPage(self.Tab, '%s' % self.parametres['name'])
966         self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
967         self.ira.ShowAPane("Tab_content")
968
969 class SimiLayout(DefaultTextLayout) :
970     def dolayout(self) :
971         self.pathout.basefiles(simipath)
972         self.actives = None
973         self.indices = indices_simi
974         if os.path.exists(self.pathout['liste_graph']) :
975             list_graph = read_list_file(self.pathout['liste_graph'])
976         else : 
977             list_graph = [['','']]
978         notebook_flags =  aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT
979         self.tabsimi = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
980         self.tabsimi.SetAGWWindowStyleFlag(notebook_flags)
981         self.tabsimi.SetArtProvider(aui.ChromeTabArt())
982         self.tabsimi.corpus = self.corpus
983         self.tabsimi.parametres = self.parametres
984         self.graphpan = GraphPanelSimi(self.tabsimi, self.pathout, list_graph)
985         self.graphpan.Bind(wx.EVT_BUTTON, self.redosimi, self.graphpan.butafc)
986         self.graphpan.Bind(wx.EVT_BUTTON, self.export, self.graphpan.butexport)
987         self.tabsimi.AddPage(self.graphpan, 'Graph')
988         self.ira.nb.AddPage(self.tabsimi, 'Analyse de graph')
989         self.ira.ShowTab(True)
990         self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
991         
992     def redosimi(self, evt) :
993         with open(self.pathout['selected.csv'],'r') as f :
994             selected = f.read()
995         selected = [int(val) for val in selected.splitlines()]
996         if self.actives is None :
997             with codecs.open(self.pathout['actives.csv'], 'r', self.parametres['encoding']) as f :
998                 self.actives = f.read()
999             self.actives = self.actives.splitlines()#[act for act in self.actives.splitlines()]
1000         if os.path.exists(self.pathout['actives_nb.csv']) :
1001             with open(self.pathout['actives_nb.csv'], 'r') as f :
1002                 act_nb = f.read()
1003                 act_nb = act_nb.splitlines()
1004             dictcol = dict([[i, [self.actives[i], int(act_nb[i])]] for i, val in enumerate(self.actives)])
1005         else :
1006             dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
1007         #res = SelectColumn(self.ira, dictcol, self.actives, self.pathout['selected.csv'], selected = selected, dlg = True) 
1008         #if res.ok :
1009         prep = PrepSimi(self.ira, self, self.parametres,self.pathout['selected.csv'], self.actives, indices_simi, wordlist = dictcol, selected = selected)
1010         if prep.val == wx.ID_OK :
1011             self.parametres = prep.parametres
1012
1013             script = PrintSimiScript(self)
1014             script.make_script()
1015             pid = exec_rcode(self.ira.RPath, script.scriptout, wait = True)
1016             check_Rresult(self.ira, pid)
1017             if self.parametres['type_graph'] == 1:
1018                 if self.parametres['svg'] :
1019                     filename, ext = os.path.splitext(script.filename)
1020                     fileout = filename + '.svg'
1021                 else :
1022                     fileout = script.filename
1023                 if os.path.exists(self.pathout['liste_graph']):
1024                     graph_simi = read_list_file(self.pathout['liste_graph'])
1025                     graph_simi.append([os.path.basename(fileout), script.txtgraph])
1026                 else :
1027                     graph_simi = [[os.path.basename(fileout), script.txtgraph]]
1028                 print_liste(self.pathout['liste_graph'], graph_simi)
1029             DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira'])
1030             if self.parametres['type_graph'] == 1:
1031                 if self.parametres['svg'] :
1032                     self.graphpan.sizer_3.Add(hl.HyperLinkCtrl(self.graphpan.panel_1, -1, fileout, URL = fileout), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1033                 else :
1034                     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)
1035                 self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1, script.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1036                 self.graphpan.sizer_3.Fit(self.graphpan.panel_1)
1037                 self.graphpan.Layout()
1038                 self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL))
1039
1040     def export(self, evt) :
1041         nb = 1
1042         while os.path.exists(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml')):
1043             nb +=1
1044         fileout = ffr(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml'))
1045         txt = """
1046         library(igraph)
1047         load("%s")
1048         fileout <- "%s"
1049         graph <- graph.simi$graph
1050         V(graph)$x <- graph.simi$layout[,1]
1051         V(graph)$y <- graph.simi$layout[,2]
1052         if (graph.simi$label.cex == 1) {
1053             V(graph)$weight <- graph.simi$eff
1054         } else {
1055             V(graph)$weight <- graph.simi$label.cex
1056         }
1057         V(graph)$colors <- vertex.label.color
1058         E(graph)$weight <- graph.simi$we.width
1059         write.graph(graph, fileout, format = 'graphml')
1060         """ % (self.pathout['RData.RData'], fileout)
1061         filetmp = tempfile.mktemp()
1062         with open(filetmp, 'w') as f :
1063             f.write(txt)
1064         exec_rcode(self.ira.RPath, filetmp)
1065         mss = wx.MessageDialog(self.ira, fileout, u'Fichier exporté', wx.OK)
1066         mss.CenterOnParent()
1067         mss.ShowModal()
1068         mss.Destroy()
1069
1070 class DefaultMatLayout :
1071     def __init__(self, parent, tableau, parametres) :
1072         self.pathout = PathOut(dirout = parametres['pathout'])
1073         self.ira = parent
1074         self.parent = parent
1075         self.tableau = tableau
1076         self.parametres = parametres
1077         self.dolayout()
1078
1079     def dolayout(self) :
1080         pass
1081
1082 class ProtoLayout(DefaultMatLayout) :
1083     def dolayout(self) :
1084         list_graph = [['proto.png', 'Analyse prototypique']]
1085         #self.Tab = aui.AuiNotebook(self.ira.nb, -1, wx.DefaultPosition)
1086         #if self.parametres['svg'] :
1087         #    list_graph = [['nuage_1.svg', 'Nuage']]
1088         #else :
1089         #    list_graph = [['nuage_1.png', 'Nuage']]
1090         self.TabProto = GraphPanel(self.ira.nb, self.pathout, list_graph)
1091         #self.Tab.AddPage(self.TabProto, 'Analyse Prototypique')
1092         #self.Tab.corpus = self.corpus
1093         self.TabProto.parametres = self.parametres
1094         self.ira.nb.AddPage(self.TabProto, 'Analyse Prototypique - %s' % self.parametres['name'])
1095         self.ira.nb.SetSelection(self.ira.nb.GetPageCount() - 1)
1096         self.ira.ShowAPane("Tab_content")
1097
1098
1099 class SimiMatLayout(DefaultMatLayout) :
1100     def dolayout(self):
1101         self.pathout.basefiles(simipath)
1102         self.indices = indices_simi
1103         if os.path.exists(self.pathout['liste_graph']) :
1104             list_graph = read_list_file(self.pathout['liste_graph'])
1105         else : 
1106             list_graph = [['','']]
1107         notebook_flags =  aui.AUI_NB_DEFAULT_STYLE | aui.AUI_NB_TAB_EXTERNAL_MOVE | aui.AUI_NB_TAB_MOVE | aui.AUI_NB_TAB_FLOAT
1108         self.tabsimi = aui.AuiNotebook(self.parent.nb, -1, wx.DefaultPosition)
1109         self.tabsimi.SetAGWWindowStyleFlag(notebook_flags)
1110         self.tabsimi.SetArtProvider(aui.ChromeTabArt())
1111         self.graphpan = GraphPanelSimi(self.tabsimi, self.pathout, list_graph)
1112         self.graphpan.Bind(wx.EVT_BUTTON, self.redosimi, self.graphpan.butafc)
1113         self.graphpan.Bind(wx.EVT_BUTTON, self.export, self.graphpan.butexport)
1114         self.tabsimi.AddPage(self.graphpan, 'Graph')
1115         self.tabsimi.parametres = self.parametres
1116         self.parent.nb.AddPage(self.tabsimi, 'Analyse de graph')
1117         self.parent.ShowTab(True)
1118         self.parent.nb.SetSelection(self.parent.nb.GetPageCount() - 1)
1119
1120     def redosimi(self,evt) :
1121         with open(self.pathout['selected.csv'],'r') as f :
1122             selected = f.read()
1123         selected = [int(val) for val in selected.splitlines()]
1124         #if self.actives is None :
1125         #    with codecs.open(self.pathout['actives.csv'], 'r', self.parametres['encoding']) as f :
1126         #        self.actives = f.read()
1127         #    self.actives = self.actives.splitlines()#[act for act in self.actives.splitlines()]
1128         try :
1129             actives = [[val, self.tableau.actives[val][0]] for val in self.tableau.actives]
1130         except :
1131             actives = [[val, self.tableau.actives[val]] for val in self.tableau.actives]
1132
1133         #self.tableau.make_listactives()
1134         actives = dict([[i, val] for i, val in enumerate(actives)])
1135         #dictcol = dict([[i, [act, self.corpus.getlemeff(act)]] for i, act in enumerate(self.actives)])
1136         self.dial = PrefSimi(self.parent, -1, self.parametres, self.indices, wordlist = actives, selected = selected, actives = self.tableau.listactives)
1137         self.dial.CenterOnParent()
1138         self.val = self.dial.ShowModal()
1139         if self.val == wx.ID_OK :
1140             last = self.dial.listcol.GetFirstSelected()
1141             lastl = [self.dial.listcol.GetFirstSelected()]
1142             indexes = [self.dial.listcol.getColumnText(self.dial.listcol.GetFirstSelected(),0)]
1143             while self.dial.listcol.GetNextSelected(last) != -1:
1144                 last = self.dial.listcol.GetNextSelected(last)
1145                 lastl.append(last)
1146                 indexes.append(self.dial.listcol.getColumnText(last,0))
1147             self.column = [self.tableau.listactives.index(val) for val in indexes]
1148             self.column.sort()
1149             with open(self.pathout['selected.csv'], 'w') as f :
1150                 f.write('\n'.join([`val` for val in self.column]))
1151             self.make_param()
1152             self.dial.Destroy()
1153             self.script = PrintSimiScript(self)
1154             self.script.make_script()
1155             self.tmpfile = self.script.scriptout
1156             dlg = progressbar(self, maxi = 2)
1157             self.DoR(dlg)
1158             dlg.Destroy()
1159             if self.parametres['type_graph'] == 1:
1160                 if self.parametres['svg'] :
1161                     filename, ext = os.path.splitext(self.script.filename)
1162                     fileout = filename + '.svg'
1163                 else :
1164                     fileout = self.script.filename
1165                 if os.path.exists(self.pathout['liste_graph']):
1166                     graph_simi = read_list_file(self.pathout['liste_graph'])
1167                     graph_simi.append([os.path.basename(fileout), self.script.txtgraph])
1168                 else :
1169                     graph_simi = [[os.path.basename(fileout), self.script.txtgraph]]
1170                 print_liste(self.pathout['liste_graph'], graph_simi)            
1171             DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira'])
1172             if self.parametres['type_graph'] == 1:
1173                 if self.parametres['svg'] :
1174                     self.graphpan.sizer_3.Add(hl.HyperLinkCtrl(self.graphpan.panel_1, -1, fileout, URL = fileout), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1175                 else :
1176                     self.graphpan.sizer_3.Add(wx.StaticBitmap(self.graphpan.panel_1, -1, wx.Bitmap(self.script.filename, wx.BITMAP_TYPE_ANY)), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1177                 self.graphpan.sizer_3.Add(wx.StaticText(self.graphpan.panel_1,-1, self.script.txtgraph), 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1178                 self.graphpan.sizer_3.Fit(self.graphpan.panel_1)
1179                 self.graphpan.Layout()
1180                 self.graphpan.panel_1.Scroll(0,self.graphpan.panel_1.GetScrollRange(wx.VERTICAL))
1181         else :
1182             self.dial.Destroy()
1183                
1184
1185     def make_param(self) :
1186         if self.parametres['first'] :
1187             keep_coord = False
1188         else :
1189             keep_coord = self.dial.check_coord.GetValue()
1190         #self.select = self.dial.check_colch.GetValue()
1191
1192         paramsimi = {'coeff' : self.dial.choice1.GetSelection(),
1193                           'layout' : self.dial.choice2.GetSelection(),
1194                           'type_graph' : self.dial.choice3.GetSelection(),
1195                           'arbremax' : self.dial.check1.GetValue(),
1196                           'coeff_tv' : self.dial.check_s_size.GetValue(),
1197                           'coeff_tv_nb' : self.dial.spin_tv.GetValue(),
1198                           'tvprop' : self.dial.check2.GetValue(),
1199                           'tvmin' : self.dial.spin_tvmin.GetValue(),
1200                           'tvmax' : self.dial.spin_tvmax.GetValue(),
1201                           'coeff_te' : self.dial.check3.GetValue(),
1202                           'coeff_temin' : self.dial.spin_temin.GetValue(),
1203                           'coeff_temax' : self.dial.spin_temax.GetValue(),
1204                           'label_e' : self.dial.check_elab.GetValue(),
1205                           'label_v' : self.dial.check_vlab.GetValue(),
1206                           'vcex' : self.dial.check_vcex.GetValue(),
1207                           'vcexmin' : self.dial.spin_vcexmin.GetValue(),
1208                           'vcexmax' : self.dial.spin_vcexmax.GetValue(),
1209                           'cex' : self.dial.spin_cex.GetValue(),
1210                           'seuil_ok' : self.dial.check_seuil.GetValue(),
1211                           'seuil' : self.dial.spin_seuil.GetValue(),
1212                           'cols' : self.dial.cols.GetColour(),
1213                           'cola' : self.dial.cola.GetColour(),
1214                           'width' : self.dial.spin_width.GetValue(),
1215                           'height' : self.dial.spin_height.GetValue(),
1216                           'first' : False,
1217                           'keep_coord' : keep_coord,
1218                           'alpha' : self.dial.slider_sphere.GetValue(),
1219                           'film' : self.dial.film.GetValue(),
1220                           'svg' : self.dial.choix_format.GetSelection(),
1221                           'halo' : self.dial.halo.GetValue(),
1222                           'com' : self.dial.comcheck.GetValue(),
1223                           'communities' : self.dial.choix_com.GetSelection(),
1224                           }        
1225         if 'cexfromchi' in self.parametres :
1226             paramsimi['cexfromchi'] = self.dial.checkit.GetValue()
1227         if 'sfromchi' in self.parametres :
1228             paramsimi['sfromchi'] = self.dial.checki.GetValue()
1229         if 'vlabcolor' in self.parametres :
1230            paramsimi['vlabcolor'] = self.parametres['vlabcolor']
1231         if 'check_bystar' in dir(self.dial) :
1232             paramsimi['bystar'] = self.dial.check_bystar.GetValue()
1233             paramsimi['stars'] = self.parametres['stars']
1234         self.parametres.update(paramsimi)
1235
1236     def DoR(self, dlg):
1237         if self.parametres['type_graph'] == 1 :
1238             graph = False
1239             wait = False
1240         else : 
1241             graph = True
1242             wait = True
1243         pid = exec_rcode(self.parent.RPath, self.tmpfile, wait = wait, graph = graph)
1244         if self.parametres['type_graph'] == 1 :
1245             while pid.poll() == None :
1246                 dlg.Pulse(u'R ...')
1247                 sleep(0.2)
1248             check_Rresult(self.parent, pid)
1249     
1250     def export(self, evt) : 
1251         nb = 1
1252         while os.path.exists(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml')):
1253             nb +=1
1254         fileout = ffr(os.path.join(self.pathout.dirout,'graph_'+str(nb)+'.graphml'))
1255         txt = """
1256         library(igraph)
1257         load("%s")
1258         fileout <- "%s"
1259         graph <- graph.simi$graph
1260         V(graph)$x <- graph.simi$layout[,1]
1261         V(graph)$y <- graph.simi$layout[,2]
1262         if (graph.simi$label.cex == 1) {
1263             V(graph)$weight <- graph.simi$eff
1264         } else {
1265             V(graph)$weight <- graph.simi$label.cex
1266         }
1267         V(graph)$colors <- vertex.label.color
1268         E(graph)$weigth <- graph.simi$we.width
1269         write.graph(graph, fileout, format = 'graphml')
1270         """ % (self.pathout['RData.RData'], fileout)
1271         filetmp = tempfile.mktemp()
1272         with open(filetmp, 'w') as f :
1273             f.write(txt)
1274         exec_rcode(self.ira.RPath, filetmp)
1275         mss = wx.MessageDialog(self.ira, fileout, u'Fichier exporté', wx.OK)
1276         mss.CenterOnParent()
1277         mss.ShowModal()
1278         mss.Destroy()
1279
1280         
1281 class GraphPanelSimi(wx.Panel):
1282     def __init__(self,parent, dico, list_graph):
1283         wx.Panel.__init__(self,parent)
1284         self.afcnb = 1
1285         self.Dict = dico
1286         self.dirout = os.path.dirname(self.Dict['ira'])
1287         self.parent = self.GetParent()#parent
1288         self.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "courier"))
1289         self.labels = []
1290         self.listimg = []
1291         self.tabsimi = self.parent.GetParent()
1292         self.ira = self.tabsimi.GetParent()
1293         self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL)
1294         afc_img = wx.Image(os.path.join(self.ira.images_path,'button_simi.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1295         self.butafc = wx.BitmapButton(self, -1, afc_img)
1296         export_img = wx.Image(os.path.join(self.ira.images_path,'button_export.jpg'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
1297         self.butexport = wx.BitmapButton(self, -1, export_img)
1298         for i in range(0,len(list_graph)):
1299             if os.path.exists(os.path.join(self.dirout,list_graph[i][0])) :
1300                 filename, ext = os.path.splitext(list_graph[i][0])
1301                 if ext == '.svg' :
1302                     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])))
1303                 else :
1304                     self.listimg.append(wx.StaticBitmap(self.panel_1, -1, wx.Bitmap(os.path.join(self.dirout,list_graph[i][0]), wx.BITMAP_TYPE_ANY)))
1305                 self.labels.append(wx.StaticText(self.panel_1, -1, list_graph[i][1]))
1306         self.panel_1.Bind(wx.EVT_MOTION, self.onMouseMove) 
1307         self.__set_properties()
1308         self.__do_layout()
1309
1310     def __set_properties(self):
1311         self.panel_1.EnableScrolling(True,True)
1312         #self.panel_1.SetSize((1000,1000))
1313         self.panel_1.SetScrollRate(20, 20)
1314         self.panel_1.SetFocus()
1315
1316     def __do_layout(self):    
1317         self.sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
1318         self.sizer_2 = wx.BoxSizer(wx.VERTICAL)
1319         self.sizer_3 = wx.BoxSizer(wx.VERTICAL)
1320         self.sizer_2.Add(self.butafc, 0, 0, 0)
1321         self.sizer_2.Add(self.butexport, 0, 0, 0)
1322         for i in range(0, len(self.listimg)):
1323             self.sizer_3.Add(self.listimg[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1324             self.sizer_3.Add(self.labels[i], 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
1325         self.panel_1.SetSizer(self.sizer_3)
1326         self.sizer_1.Add(self.sizer_2, 0, wx.EXPAND, 0)
1327         self.sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
1328         self.SetSizer(self.sizer_1) 
1329
1330     def onMouseMove(self, event):
1331         self.panel_1.SetFocus()