Merge branch 'master' of http://www.netdig.org/git/iramuteq
[iramuteq] / ProfList.py
1 # -*- coding: utf-8 -*-
2
3 #----------------------------------------------------------------------------
4 # Name:         ListCtrl.py
5 # Author:       Pierre Ratinaud
6
7
8 #comes from ListCtrl.py from the demo tool of wxPython:
9 # Author:       Robin Dunn & Gary Dumer
10 #
11 # Created:
12 # Copyright:    (c) 1998 by Total Control Software
13 # Licence:      wxWindows license
14 #----------------------------------------------------------------------------
15
16 import os
17 import sys
18 import  wx
19 import  wx.lib.mixins.listctrl  as  listmix
20 #from tabsimi import DoSimi
21 from listlex import ListForSpec
22 from chemins import ConstructPathOut, ffr
23 from dialog import PrefExport, PrefUCECarac, SearchDial, message
24 from tableau import Tableau
25 from search_tools import SearchFrame
26 import webbrowser
27 import cStringIO
28 import tempfile
29 import codecs
30 from functions import exec_rcode, MessageImage, progressbar, treat_var_mod
31 from PrintRScript import barplot
32 from textclassechd import ClasseCHD
33 from shutil import copyfile
34
35 #---------------------------------------------------------------------------
36 class ProfListctrlPanel(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.ColumnSorterMixin):
37     def __init__(self, parent, gparent, profclasse, Alceste=False, cl=0):
38         wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES)
39
40         self.parent = parent
41         self.Alceste = Alceste
42         self.Source = gparent
43         self.cl = cl
44         self.var_mod = {}
45
46         line1 = profclasse.pop(0)
47         classen = [line for line in profclasse if line[0] != '*' and line[0] != '*****']
48         try :
49             self.lenact = profclasse.index([u'*****', u'*', u'*', u'*', u'*', u'*', '', ''])
50             profclasse.pop(self.lenact)
51         except ValueError:
52             try :
53                 self.lenact = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
54                 profclasse.pop(self.lenact)
55             except ValueError:
56                 self.lenact = len(profclasse)
57         try :
58             self.lensup = profclasse.index([u'*', u'*', u'*', u'*', u'*', u'*', '', ''])
59             self.lensup = self.lensup - self.lenact
60             profclasse.pop(self.lensup)
61         except ValueError: 
62             self.lensup = len(profclasse) - self.lenact
63         self.lenet = len(profclasse) - (self.lenact + self.lensup)
64 #        print self.lenact, self.lensup, self.lenet
65         for i,  line in enumerate(classen) :
66             line[0] = i
67         dictdata = dict(zip([i for i in range(0,len(classen))], classen))
68
69         if self.lenact != 0 :
70             self.la = [dictdata[i][6] for i in range(0, self.lenact)]
71             self.lchi = [dictdata[i][4] for i in range(0, self.lenact)]
72             self.lfreq = [dictdata[i][1] for i in range(0, self.lenact)]
73         else :
74             self.la = []
75             self.lchi = []
76             self.lfreq = []
77         self.tmpchi = None
78             
79         #adding some art
80         self.il = wx.ImageList(16, 16)
81         a={"sm_up":"GO_UP","sm_dn":"GO_DOWN","w_idx":"WARNING","e_idx":"ERROR","i_idx":"QUESTION"}
82         for k,v in a.items():
83             s="self.%s= self.il.Add(wx.ArtProvider_GetBitmap(wx.ART_%s,wx.ART_TOOLBAR,(16,16)))" % (k,v)
84             exec(s)
85         self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
86
87         #adding some attributes (colourful background for each item rows)
88         self.attr1 = wx.ListItemAttr()
89         self.attr1.SetBackgroundColour((220, 220, 220))
90         self.attrsg = wx.ListItemAttr()
91         self.attrsg.SetBackgroundColour((230, 230, 230))
92         self.attr2 = wx.ListItemAttr()
93         self.attr2.SetBackgroundColour((190, 249, 236))
94         self.attr2s = wx.ListItemAttr()
95         self.attr2s.SetBackgroundColour((211, 252, 244))        
96         self.attr3 = wx.ListItemAttr()
97         self.attr3.SetBackgroundColour((245, 180, 180))
98         self.attr3s = wx.ListItemAttr()
99         self.attr3s.SetBackgroundColour((245, 190, 190))
100
101
102         self.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
103         self.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
104         self.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
105         self.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
106         self.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
107         self.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
108         self.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
109         self.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
110         
111
112         self.SetColumnWidth(0, 60)
113         self.SetColumnWidth(1, 70)
114         self.SetColumnWidth(2, 80)
115         self.SetColumnWidth(3, 100)
116         self.SetColumnWidth(4, 70)
117         self.SetColumnWidth(5, 60)
118         self.SetColumnWidth(6, 140)
119         self.SetColumnWidth(7, wx.LIST_AUTOSIZE)
120
121         #These two should probably be passed to init more cleanly
122         #setting the numbers of items = number of elements in the dictionary
123         self.itemDataMap = dictdata
124         self.itemIndexMap = dictdata.keys()
125         self.SetItemCount(len(dictdata))
126         
127         #mixins
128         listmix.ListCtrlAutoWidthMixin.__init__(self)
129         listmix.ColumnSorterMixin.__init__(self, len(classen[0]))
130
131         #sort by genre (column 2), A->Z ascending order (1)
132         self.SortListItems(0, 1)
133
134         #events
135         #self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected)
136         #self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated)
137         #self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
138         self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
139
140         # for wxMSW
141         self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
142
143         # for wxGTK
144         self.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
145
146         #for searching
147         search_id = wx.NewId()
148         searchall_id = wx.NewId()
149         self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
150         self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
151         self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
152                                               (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
153         self.SetAcceleratorTable(self.accel_tbl)
154
155
156
157     def OnColClick(self,event):
158         event.Skip()
159
160     def OnItemSelected(self, event):
161         self.currentItem = event.m_itemIndex
162
163     def OnItemActivated(self, event):
164         self.currentItem = event.m_itemIndex
165
166     def getColumnText(self, index, col):
167         item = self.GetItem(index, col)
168         return item.GetText()
169
170     def OnItemDeselected(self, evt):
171         pass
172     #---------------------------------------------------
173     # These methods are callbacks for implementing the
174     # "virtualness" of the list...
175
176     def OnGetItemText(self, item, col):
177         index=self.itemIndexMap[item]
178         s = self.itemDataMap[index][col]
179         return s
180
181     def OnGetItemImage(self, item):
182         index=self.itemIndexMap[item]
183         genre=self.itemDataMap[index][2]
184
185         if genre=="Rock":
186             return self.w_idx
187         elif genre=="Jazz":
188             return self.e_idx
189         elif genre=="New Age":
190             return self.i_idx
191         else:
192             return -1
193
194     def OnGetItemAttr(self, item):
195         index=self.itemIndexMap[item]
196         if index < self.lenact :
197             if item % 2 :
198                 return self.attr1
199             else :
200                 return self.attrsg
201         elif index >= self.lenact and index < (self.lenact + self.lensup) :
202             if item % 2 :
203                 return self.attr2
204             else :
205                 return self.attr2s
206         elif index >= (self.lenact + self.lensup) :
207             if item % 2 :
208                 return self.attr3
209             else :
210                 return self.attr3s
211         else :
212             return None
213
214     #---------------------------------------------------
215     # Matt C, 2006/02/22
216     # Here's a better SortItems() method --
217     # the ColumnSorterMixin.__ColumnSorter() method already handles the ascending/descending,
218     # and it knows to sort on another column if the chosen columns have the same value.
219
220     def SortItems(self,sorter=cmp):
221         items = list(self.itemDataMap.keys())
222         items.sort(sorter)
223         self.itemIndexMap = items
224         
225         # redraw the list
226         self.Refresh()
227
228     # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
229     def GetListCtrl(self):
230         return self
231
232     # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
233     def GetSortImages(self):
234         return (self.sm_dn, self.sm_up)
235
236     def onsearch(self, evt) :
237         self.dial = SearchDial(self, self, 6, True)
238         self.dial.CenterOnParent()
239         self.dial.ShowModal()
240         self.dial.Destroy()
241
242     def onsearchall(self, evt) :
243         if 'FrameSearch' not in dir(self.Source) :
244             self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
245         self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
246         self.dial.CenterOnParent()
247         self.dial.ShowModal()
248         self.dial.Destroy()
249
250     def OnRightClick(self, event):
251
252         # only do this part the first time so the events are only bound once
253         if self.Alceste:
254             if not hasattr(self, "popupID1"):
255                 self.popupID1 = wx.NewId()
256                 self.popupID2 = wx.NewId()
257                 self.popupID3 = wx.NewId()
258                 self.popupID4 = wx.NewId()
259                 self.popupID5 = wx.NewId()
260                 self.popupID6 = wx.NewId()
261                 self.popupID7 = wx.NewId()
262                 self.popupID8 = wx.NewId()
263                 self.popupID9 = wx.NewId()
264                 #self.popupID10 = wx.NewId()
265                 self.popupIDgraph = wx.NewId()
266                 self.idseg = wx.NewId()
267                 self.iducecarac = wx.NewId()
268                 self.idtablex = wx.NewId()
269                 self.idchimod = wx.NewId()
270                 self.idwordgraph = wx.NewId()
271                 self.popup_proxe = wx.NewId()
272                 self.idlexdendro = wx.NewId()
273                 self.idexport = wx.NewId()
274             #    self.export_classes = wx.NewId()
275    
276                 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
277                 self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
278                 self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
279                 self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
280                 self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
281                 self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
282                 self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
283                 self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
284                 self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
285                 #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
286                 self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
287                 self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
288                 self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
289                 self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
290                 self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
291                 self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
292                 self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
293                 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
294                 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
295              #  self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
296    #            self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
297     
298             # make a menu
299             menu = wx.Menu()
300             menu.Append(self.popupID1, u"Formes associées")
301             menu.Append(self.idtablex, u"Chi2 par classe")
302             menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
303             menu.Append(self.idchimod, u"Chi2 modalités de la variable")
304             menu.Append(self.idwordgraph, u"Graphe du mot")
305             #menu.Append(self.export_classes, u"Exporter le corpus...") 
306             
307             #menu.Append(self.popupID10, u"Spécificités")
308
309             menu_conc = wx.Menu()
310             menu_conc.Append(self.popupID2, u"dans les uce de la classe")
311             menu_conc.Append(self.popupID3, u"dans les uce classées")
312             menu_conc.Append(self.popupID4, u"dans toutes les uce")
313             menu.AppendMenu(-1, u"Concordancier", menu_conc) 
314             menu_cnrtl = wx.Menu()      
315             menu_cnrtl.Append(self.popupID5, u"Définition")
316             menu_cnrtl.Append(self.popupID6, u"Etymologie")
317             menu_cnrtl.Append(self.popupID7, u"Synonymie")
318             menu_cnrtl.Append(self.popupID8, u"Antonymie")
319             menu_cnrtl.Append(self.popupID9, u"Morphologie")
320             menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
321             menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
322             menu.AppendSeparator()
323             menu.Append(self.popupIDgraph, u"Graphe de la classe")
324             menu.Append(self.idseg, u"Segments répétés")
325             menu.Append(self.iducecarac, u"UCE caractéristiques")
326             menu.Append(self.idexport, 'Partitionner...')
327             #menu.Append(self.popupID2, u"Concordancier")
328     #        menu.Append(self.popupID3, "recharger")
329     
330             self.PopupMenu(menu)
331             menu.Destroy()
332         elif 'tableau' in dir(self.Source) :
333             if not hasattr(self, "pop1"):
334                 self.pop1 = wx.NewId()
335                 self.pop2 = wx.NewId()
336                 self.pop3 = wx.NewId()
337                 self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
338                 self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
339                 self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
340
341             menu = wx.Menu()
342             menu.Append(self.pop2, u"Chi2 par classe")
343             menu.Append(self.pop3, u"Chi2 modalités de la variable")
344             menu.AppendSeparator()
345             menu.Append(self.pop1, u"Graph de la classe")
346             self.PopupMenu(menu)
347             menu.Destroy()
348
349     def onexport(self, evt) :
350         if 'corpus' in dir(self.Source):
351             corpus = self.Source.corpus
352         ClasseCHD(self.parent, corpus, self.cl)
353
354     def getselectedwords(self) :
355         words = [self.getColumnText(self.GetFirstSelected(), 6)]
356         last = self.GetFirstSelected()
357         while self.GetNextSelected(last) != -1:
358             last = self.GetNextSelected(last)
359             words.append(self.getColumnText(last, 6))
360         return words
361
362     def quest_var_mod(self, evt) :
363         if 'corpus' in dir(self.Source):
364             corpus = self.Source.corpus
365             if self.var_mod == {} :
366                 self.var_mod = self.Source.corpus.make_etoiles_dict()
367         else :
368             corpus = self.Source.tableau
369             if self.var_mod == {} :
370                 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
371         with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
372             chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
373         title = chistable[0]
374         title.pop(0)
375         chistable.pop(0)
376         vchistable = [line[1:] for line in chistable]
377         fchistable = [line[0] for line in chistable]
378         word = self.getselectedwords()[0]
379         print self.var_mod
380         if len(word.split('_')) > 1 :
381             var = word.split('_')
382             #words = ['_'.join([var[0],word]) for word in self.var_mod[var[0]]]
383             words = [word for word in self.var_mod[var[0]]]
384             words.sort()
385             tableout = []
386             kwords = []
387             for word in words :
388                 print word
389                 if word in fchistable :
390                     tableout.append(vchistable[fchistable.index(word)])
391                     kwords.append(word)
392             tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
393             print tableout
394             txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
395             tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
396             file = open(tmpscript,'w')
397             file.write(txt)
398             file.close()
399             exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
400             win = MessageImage(self,u"Graphique", size=(700, 500))
401             win.addsaveimage(tmpgraph)
402             txt = "<img src='%s'>" % tmpgraph
403             win.HtmlPage.SetPage(txt)
404             win.Show(True)
405         else :
406             dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
407             dial.CenterOnParent()
408             dial.ShowModal()
409             dial.Destroy()
410
411     def quest_simi(self, evt) :
412         tableau = self.Source.tableau
413         tab = tableau.make_table_from_classe(self.cl, self.la)
414         pathout = ConstructPathOut(os.path.join(self.Source.pathout.dirout, 'simi_classe_%i' %self.cl), 'simi_classe_%i' %self.cl)
415         self.filename = os.path.join(pathout,'mat01.csv')
416         tableau.printtable(self.filename, tab)
417         del tab
418         paramsimi = {'coeff' : 0,
419                           'layout' : 2,
420                           'type_graph' : 1,
421                           'arbremax' : 1,
422                           'coeff_tv' : 1,
423                           'coeff_tv_nb' : 0,
424                           'tvprop' : 0,
425                           'tvmin' : 5,
426                           'tvmax' : 30,
427                           'coeff_te' : 1,
428                           'coeff_temin' : 1,
429                           'coeff_temax' : 10,
430                           'label_v': 1,
431                           'label_e': 1,
432                           'vcex' : 0,
433                           'vcexmin' : 10,
434                           'vcexmax' : 25,
435                           'cex' : 10,
436                           'cexfromchi' : True,
437                           'sfromchi': False,
438                           'seuil_ok' : 0,
439                           'seuil' : 1,
440                           'cols' : (255,0,0),
441                           'cola' : (200,200,200),
442                           'width' : 1000,
443                           'height' : 1000,
444                           'first' : True,
445                           'keep_coord' : True,
446                           'alpha' : 20,
447                           'film': False,
448                           'com' : 0,
449                           'communities' : 0,
450                           'halo' : 0
451                           }
452 #        self.tableau.actives = {}
453 #        self.tableau.lchi = self.lchi
454 #        self.tableau.chi = {}
455 #        for i, val in enumerate(self.la) :
456 #            self.tableau.actives[val] = [self.lfreq[i]]
457 #            self.tableau.chi[val] = [self.lchi[i]]
458                           
459         act = {}
460         tableau.chi = {}
461         tableau.lchi = self.lchi
462         tableau.parametre['fromprof'] = True
463         for i, val in enumerate(self.la) :
464             act[val] = [self.lfreq[i]]
465             tableau.chi[val] = [self.lchi[i]]
466         self.parent.SimiCluster(parametres = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act, tableau = tableau)
467
468     def onwordgraph(self, evt):
469         word = self.getColumnText(self.GetFirstSelected(), 6)
470         if self.tmpchi is None :
471             self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
472             with open(self.tmpchi, 'w') as f:
473                 f.write('\n'.join([str(val) for val in self.lchi]))
474         index = self.la.index(word)
475         parametres = {'type' : 'clustersimitxt', 
476                         'pathout' : self.Source.parametres['pathout'],
477                         'word' : index ,
478                         'lem' : self.Source.parametres['lem'],
479                         'tmpchi' : self.tmpchi}
480         #try :
481         self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = parametres, dlg = progressbar(self, 4))
482         #except :
483         #    print 'not acitve'
484
485     def on_graph(self, evt):
486         if self.tmpchi is None :
487             self.tmpchi = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
488             with open(self.tmpchi, 'w') as f:
489                 f.write('\n'.join([str(val) for val in self.lchi]))
490         parametres = {'type' : 'clustersimitxt', 
491                         'pathout' : self.Source.parametres['pathout'],
492                         'lem' : self.Source.parametres['lem'],
493                         'tmpchi' : self.tmpchi}
494
495         self.parent.SimiFromCluster(self.parent, self.Source.corpus, self.la, self.cl - 1, parametres = parametres, dlg = progressbar(self, 4))
496         #dlg = progressbar(self, 2)
497         #corpus = self.Source.corpus
498         #uces = corpus.lc[self.cl-1]
499         #dlg.Update(1, u'Tableau...')
500         ##tab = corpus.make_table_with_classe(uces, self.la)
501         #pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
502         #self.filename = os.path.join(pathout,'mat01.csv')
503         #dlg.Update(2, u'Ecriture...')
504         ##corpus.write_tab(tab, self.filename)
505         ##del tab
506         #corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
507         #dlg.Destroy()
508         #paramsimi = {'coeff' : 0,
509         #                  'layout' : 2,
510         #                  'type' : 1,
511         #                  'arbremax' : 1,
512         #                  'coeff_tv' : 1,
513         #                  'coeff_tv_nb' : 0,
514         #                  'tvprop' : 0,
515         #                  'tvmin' : 5,
516         #                  'tvmax' : 30,
517         #                  'coeff_te' : 1,
518         #                  'coeff_temin' : 1,
519         #                  'coeff_temax' : 10,
520         #                  'label_v': 1,
521         #                  'label_e': 0,
522         #                  'vcex' : 0,
523         #                  'vcexmin' : 10,
524         #                  'vcexmax' : 25,
525         #                  'cex' : 10,
526         #                  'cexfromchi' : True,
527         #                  'sfromchi': False,
528         #                  'seuil_ok' : 0,
529         #                  'seuil' : 1,
530         #                  'cols' : (255,0,0),
531         #                  'cola' : (200,200,200),
532         #                  'width' : 1000,
533         #                  'height' : 1000,
534         #                  'first' : True,
535         #                  'keep_coord' : True,
536         #                  'alpha' : 20,
537         #                  'film': False,
538         #                  }
539         #self.tableau = Tableau(self.parent, '')
540         #self.tableau.listactives = self.la
541         #self.tableau.actives = {}
542         #self.tableau.lchi = self.lchi
543         #self.tableau.chi = {}
544         #self.tableau.parametre['fromprof'] = True
545         #for i, val in enumerate(self.la) :
546         #    self.tableau.actives[val] = [self.lfreq[i]]
547         #    self.tableau.chi[val] = [self.lchi[i]]
548         #DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
549
550     def on_segments(self,evt) :
551         dlg = progressbar(self, 2)
552         corpus = self.Source.corpus
553         uces = corpus.lc[self.cl-1]
554         l = []
555         dlg.Update(1, u'Segments...')
556         for i in range(2,10) :
557             li = corpus.find_segments_in_classe(uces, i, 1000)
558             if li == [] :
559                 break
560             else :
561                 l += li
562         l.sort(reverse = True)
563         d = {}
564         dlg.Update(2, 'Tri...')
565         for i, line in enumerate(l) :
566             d[i] = [line[1],line[0], line[2]]
567         first = ['','','']
568         para={'dico': d,'fline':first}
569         dlg.Destroy()
570         win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
571         win.Show(True)
572
573     def on_uce_carac(self,evt) :
574         dial = PrefUCECarac(self, self.parent)
575         dial.CenterOnParent()
576         if dial.ShowModal() == wx.ID_OK :
577             limite = dial.spin_eff.GetValue()
578             atype = dial.radio_type.GetSelection()
579             dlg = progressbar(self,maxi = 4)
580             corpus = self.Source.corpus
581             uces = corpus.lc[self.cl-1]
582             tab = corpus.make_table_with_classe(uces, self.la)
583             tab.pop(0)
584             dlg.Update(2, u'score...')
585             if atype == 0 :
586                 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
587             else :
588                 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1])/float(sum(line)),2) if sum(line)!=0 else 0 for line in tab]
589             ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
590             del ntab
591             ntab2.sort(reverse = True)
592             ntab2 = ntab2[:limite]
593             nuces = [val[1] for val in ntab2]
594             dlg.Update(3, u'concordancier...')
595             #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
596             ucestxt1 = [row for row in corpus.getconcorde(nuces)]
597             ucestxt = []
598             ucis_txt = []
599             for uce in ucestxt1 :
600                 ucetxt = ' '+uce[1]+' '
601                 ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
602                 for lem in self.la :
603                     listmot = corpus.getlems()[lem].formes
604                     for id in listmot :
605                         forme = corpus.getforme(id).forme
606                         ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
607                 ucestxt.append(ucetxt)        
608             #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
609             dlg.Update(4, u'texte...')
610             #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
611             win = message(self, u"UCE caractéristiques - Classe %i" % self.cl, (750, 600))
612             win.html = '<html>\n' + '<br><br>'.join(['<br>'.join([ucis_txt[i], 'score : ' + str(ntab2[i][0]), ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n</html>'
613             win.HtmlPage.SetPage(win.html)
614             dlg.Destroy()
615             win.Show(True)
616     
617     def on_tablex(self, evt):
618         if 'corpus' in dir(self.Source):
619             corpus = self.Source.corpus
620         else :
621             corpus = self.Source.tableau
622         with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
623             chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
624         title = chistable[0]
625         title.pop(0)
626         chistable.pop(0)
627         vchistable = [line[1:] for line in chistable]
628         fchistable = [line[0] for line in chistable]
629         words = self.getselectedwords()
630         tableout = [vchistable[fchistable.index(word)] for word in words]
631         tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
632         nbcl = len(title)
633         nbwords = len(words)
634         txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
635         tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
636         file = open(tmpscript,'w')
637         file.write(txt)
638         file.close()
639         exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
640         w = 100 + (20 * nbwords) + (100 * nbcl)
641         h = 100 + (nbwords * 15)
642         if w > 1100 : w = 1100
643         if h > 800 : h = 800
644         if h < 450 : h = 450
645         win = MessageImage(self, u"Graphique", size=(w, h))
646         win.addsaveimage(tmpgraph)
647         txt = "<img src='%s'>" % tmpgraph
648         win.HtmlPage.SetPage(txt)
649         win.Show(True)
650
651     def onlexdendro(self, evt):
652         if 'corpus' in dir(self.Source):
653             corpus = self.Source.corpus
654         else :
655             corpus = self.Source.tableau
656         with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
657             chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
658         title = chistable[0]
659         title.pop(0)
660         chistable.pop(0)
661         vchistable = [line[1:] for line in chistable]
662         fchistable = [line[0] for line in chistable]
663         words = self.getselectedwords()
664         tableout = [vchistable[fchistable.index(word)] for word in words]
665         tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
666         txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
667         rownames = 'c("' + '","'.join(words) + '")'
668         colnames = 'c("' + '","'.join(title) + '")'
669         nbcl = len(title)
670         rownb = len(words)
671         txt = """
672         load("%s")
673         di <- matrix(data=%s, nrow=%i, byrow = TRUE)
674         rownames(di)<- %s
675         colnames(di) <- %s
676         library(ape)
677         source("%s")
678         height <- (30*ncol(di)) + (15*nrow(di))
679         height <- ifelse(height <= 400, 400, height)
680         width <- 500
681         open_file_graph("%s", width=width, height=height)
682         plot.dendro.lex(tree.cut1$tree.cl, di)
683         """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
684         tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
685         file = open(tmpscript,'w')
686         file.write(txt)
687         file.close()
688         exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
689         win = MessageImage(self, u"Graphique", size=(700, 500))
690         win.addsaveimage(tmpgraph)
691         txt = "<img src='%s'>" % tmpgraph
692         win.HtmlPage.SetPage(txt)
693         win.Show(True)
694
695
696     def make_concord(self, uces, title, color = 'red') :
697         corpus = self.Source.corpus
698         ListWord = [self.getColumnText(self.GetFirstSelected(), 6)]
699         last = self.GetFirstSelected()
700         while self.GetNextSelected(last) != -1:
701             last = self.GetNextSelected(last)
702             ListWord.append(self.getColumnText(last, 6))
703         listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
704         win = message(self, title, size=(750, 600))
705         toshow = ['<html>\n<H1>Concordancier</H1>\n']
706         toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
707         duce = {}
708         ucef = []
709         for word in ListWord : 
710             ucef += list(set(corpus.getlemuces(word)).intersection(uces))
711         ucef = list(set(ucef))
712         ucef.sort()
713         res = corpus.getconcorde(ucef)
714         txt = '<br>'.join(toshow) +'<br><br>'
715         for uce in res :
716             ucetxt = ' '+uce[1]+' '
717             txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
718             for forme in listmot:
719                 forme = corpus.getforme(forme).forme
720                 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
721             txt += ucetxt + '<br><br>'
722         win.HtmlPage.SetPage(txt)
723         return win
724
725     def OnPopupTwo(self, event):
726         corpus = self.Source.corpus
727         uces = corpus.lc[self.cl-1]
728         win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
729         win.Show(True)
730     
731     def OnPopupThree(self, event):
732         corpus = self.Source.corpus
733         uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
734         win = self.make_concord(uces, "Concordancier - UCE classées")
735         win.Show(True)
736         
737     def OnPopupFour(self, event):
738         corpus = self.Source.corpus
739         uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
740         win = self.make_concord(uces, "Concordancier - Toutes les UCE")
741         win.Show(True)
742
743     def OnPopupFive(self, event):
744         word = self.getColumnText(self.GetFirstSelected(), 6)
745         lk = "http://www.cnrtl.fr/definition/" + word
746         webbrowser.open(lk)
747
748     def OnPopupSix(self, event):  
749         word = self.getColumnText(self.GetFirstSelected(), 6)
750         lk = "http://www.cnrtl.fr/etymologie/" + word
751         webbrowser.open(lk)
752         
753     def OnPopupSeven(self, event):        
754         word = self.getColumnText(self.GetFirstSelected(), 6)
755         lk = "http://www.cnrtl.fr/synonymie/" + word
756         webbrowser.open(lk)
757         
758     def OnPopupHeight(self, event):  
759         word = self.getColumnText(self.GetFirstSelected(), 6)
760         lk = "http://www.cnrtl.fr/antonymie/" + word
761         webbrowser.open(lk)
762         
763     def OnPopupNine(self, event):            
764         word = self.getColumnText(self.GetFirstSelected(), 6)
765         lk = "http://www.cnrtl.fr/morphologie/" + word
766         webbrowser.open(lk)
767
768     def onproxe(self, evt) :
769         word = self.getColumnText(self.GetFirstSelected(), 6)
770         lk = "http://www.cnrtl.fr/proxemie/" + word
771         webbrowser.open(lk)
772 #
773
774 #---------------------------------------------------------------------------
775 #class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
776 #    def __init__(self, parent, ID, pos=wx.DefaultPosition,
777 #                 size=wx.DefaultSize, style=0):
778 #        wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
779 #        listmix.ListCtrlAutoWidthMixin.__init__(self)
780 #
781 #
782 #class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
783 #    def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
784 #        self.parent = parent
785 #        classe = ProfClasse
786 #        self.cl = cl
787 #        self.Source = gparent
788 #        if 'tableau' in dir(self.Source):
789 #            self.tableau = self.Source.tableau
790 #        self.Alceste = Alceste
791 #        self.var_mod = {}
792 #        
793 #
794 #        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
795 #        
796 #        search_id = wx.NewId()
797 #        searchall_id = wx.NewId()
798 #        self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
799 #        self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
800 #        self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
801 #                                              (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
802 #        self.SetAcceleratorTable(self.accel_tbl)
803 #       
804 #        self.il = wx.ImageList(16, 16)
805 ##        self.idx1 = self.il.Add(images.getSmilesBitmap())
806 #        self.sm_up = self.il.Add(getSmallUpArrowBitmap())
807 #        self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
808 #        tID = wx.NewId()
809 #
810 #        self.list = ProfListctrl(self, tID,
811 #                                 style=wx.LC_REPORT 
812 #                                 | wx.BORDER_NONE
813 #                                 | wx.LC_EDIT_LABELS
814 #                                 | wx.LC_SORT_ASCENDING
815 #                                 )
816 #        line1 = classe.pop(0)
817 #        limit = 0
818 #        limitsup = 0
819 #        i = 0
820 #        dictdata = {}
821 #        classen = [line for line in classe if line[0] != '*' and line[0] != '*****']
822 #        if len(classen) == 0 :
823 #            lenact = 0
824 #            lensup = 0
825 #            lenet = 0
826 #        else :
827 #            lenact = [i for i,b in enumerate(classe) if b[0] == '*****']
828 #            if lenact == [] :
829 #                lensup = 0
830 #                lenact = [i for i,b in enumerate(classe) if b[0] == '*']
831 #                if lenact == [] :
832 #                    lenact = len(classen)
833 #                    lenet = 0
834 #                else :
835 #                    lenact = 0
836 #                    lenet = len(classen)
837 #            else :
838 #                lenact = lenact[0]
839 #                lensup = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
840 #                if lensup != [] :
841 #                   lensup = lensup[0] - lenact
842 #                   lenet = len(classen) - lensup
843 #                else :
844 #                   lensup == 0
845 #                   lenet = len(classen)
846 #        debsup = lenact
847 #                
848 #        self.lenact = lenact
849 #
850 #        debet = lenact + lensup
851 #        dictdata = dict(zip([i for i in range(0,len(classen))], classen))
852 #        self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
853 #        
854 #        self.PopulateList(dictdata, debet, debsup, Alceste)
855 #
856 #        self.Bind(wx.EVT_SIZE, self.OnSize)
857 #        self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
858 #        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
859 #
860 #        # for wxMSW
861 #        self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
862 #
863 #        # for wxGTK
864 #        self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
865 #        self.itemDataMap = dictdata
866 #        listmix.ColumnSorterMixin.__init__(self, 8)
867 #        self.do_greyline()
868 ##-----------------------------------------------------------------------------------------    
869 #
870 #    def PopulateList(self, dictdata, limit, limitsup, Alceste):
871 #        
872 #        
873 #            # for normal, simple columns, you can add them like this:
874 #        self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
875 #        self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
876 #        self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
877 #        self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
878 #        self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
879 #        self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
880 #        self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
881 #        self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
882 #        
883 #        for key in dictdata : #.iteritems():
884 #                index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
885 #                i = 1
886 #                for val in dictdata[key][1:]:
887 #                    self.list.SetStringItem(index, i, str(dictdata[key][i]))
888 #                    i += 1
889 #                self.list.SetItemData(index, key)
890 #
891 #        self.list.SetColumnWidth(0, 60)
892 #        self.list.SetColumnWidth(1, 70)
893 #        self.list.SetColumnWidth(2, 80)
894 #        self.list.SetColumnWidth(3, 100)
895 #        self.list.SetColumnWidth(4, 70)
896 #        self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
897 #        self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
898 #        self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
899 #
900 #        # show how to change the colour of a couple items
901 #        for i in range(limitsup, limit):
902 #            item = self.list.GetItem(i)
903 #            item.SetTextColour(wx.RED) 
904 #            self.list.SetItem(item)
905 #        
906 #        for i in range(limit, len(dictdata)):
907 #            item = self.list.GetItem(i)
908 #            item.SetTextColour(wx.BLUE)
909 #            self.list.SetItem(item)          
910 #        
911 #        if self.lenact != 0 :
912 #            self.la = [self.getColumnText(i,6) for i in range(0, self.lenact)]
913 #            self.lchi = [float(self.getColumnText(i,4)) for i in range(0, self.lenact)]
914 #            self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, self.lenact)]
915 #        else :
916 #            self.la = []
917 #            self.lchi = []
918 #            self.lfreq = []
919 #
920 #    def do_greyline(self):
921 #        for row in xrange(self.list.GetItemCount()):
922 #            if row % 2 :
923 #                self.list.SetItemBackgroundColour(row, (230, 230, 230))
924 #            else :
925 #                self.list.SetItemBackgroundColour(row, wx.WHITE)
926 #
927 #
928 #    # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
929 #    def GetListCtrl(self):
930 #        return self.list
931 #
932 #    # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
933 #    def GetSortImages(self):
934 #        return (self.sm_dn, self.sm_up)
935 #
936 #
937 #    def OnRightDown(self, event):
938 #        x = event.GetX()
939 #        y = event.GetY()
940 #        item, flags = self.list.HitTest((x, y))
941 #
942 #        if flags & wx.LIST_HITTEST_ONITEM:
943 #            self.list.Select(item)
944 #
945 #        event.Skip()
946 #
947 #
948 #    def getColumnText(self, index, col):
949 #        item = self.list.GetItem(index, col)
950 #        return item.GetText()
951 #
952 #
953 #    def OnItemSelected(self, event):
954 #        self.currentItem = event.m_itemIndex
955 #        event.Skip()
956 #
957 #    def onsearch(self, evt) :
958 #        self.dial = SearchDial(self, self, 6, True)
959 #        self.dial.CenterOnParent()
960 #        self.dial.ShowModal()
961 #        self.dial.Destroy()
962 #
963 #    def onsearchall(self, evt) :
964 #        if 'FrameSearch' not in dir(self.Source) :
965 #            self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
966 #        self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
967 #        self.dial.CenterOnParent()
968 #        self.dial.ShowModal()
969 #        self.dial.Destroy()
970 #
971 #    def OnRightClick(self, event):
972 #
973 #        # only do this part the first time so the events are only bound once
974 #        if self.Alceste:
975 #            if not hasattr(self, "popupID1"):
976 #                self.popupID1 = wx.NewId()
977 #                self.popupID2 = wx.NewId()
978 #                self.popupID3 = wx.NewId()
979 #                self.popupID4 = wx.NewId()
980 #                self.popupID5 = wx.NewId()
981 #                self.popupID6 = wx.NewId()
982 #                self.popupID7 = wx.NewId()
983 #                self.popupID8 = wx.NewId()
984 #                self.popupID9 = wx.NewId()
985 #                #self.popupID10 = wx.NewId()
986 #                self.popupIDgraph = wx.NewId()
987 #                self.idseg = wx.NewId()
988 #                self.iducecarac = wx.NewId()
989 #                self.idtablex = wx.NewId()
990 #                self.idchimod = wx.NewId()
991 #                self.idwordgraph = wx.NewId()
992 #                self.popup_proxe = wx.NewId()
993 #                self.idlexdendro = wx.NewId()
994 #                self.idexport = wx.NewId()
995 #            #    self.export_classes = wx.NewId()
996 #   
997 #                self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
998 #                self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
999 #                self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1000 #                self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
1001 #                self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
1002 #                self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
1003 #                self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
1004 #                self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
1005 #                self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
1006 #                #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
1007 #                self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
1008 #                self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
1009 #                self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
1010 #                self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
1011 #                self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
1012 #                self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
1013 #                self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
1014 #                self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
1015 #                self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
1016 #              #  self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
1017 #    #            self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
1018 #    
1019 #            # make a menu
1020 #            menu = wx.Menu()
1021 #            menu.Append(self.popupID1, u"Formes associées")
1022 #            menu.Append(self.idtablex, u"Chi2 par classe")
1023 #            menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
1024 #            menu.Append(self.idchimod, u"Chi2 modalités de la variable")
1025 #            menu.Append(self.idwordgraph, u"Graphe du mot")
1026 #            #menu.Append(self.export_classes, u"Exporter le corpus...") 
1027 #            
1028 #            #menu.Append(self.popupID10, u"Spécificités")
1029 #
1030 #            menu_conc = wx.Menu()
1031 #            menu_conc.Append(self.popupID2, u"dans les uce de la classe")
1032 #            menu_conc.Append(self.popupID3, u"dans les uce classées")
1033 #            menu_conc.Append(self.popupID4, u"dans toutes les uce")
1034 #            menu.AppendMenu(-1, u"Concordancier", menu_conc) 
1035 #            menu_cnrtl = wx.Menu()      
1036 #            menu_cnrtl.Append(self.popupID5, u"Définition")
1037 #            menu_cnrtl.Append(self.popupID6, u"Etymologie")
1038 #            menu_cnrtl.Append(self.popupID7, u"Synonymie")
1039 #            menu_cnrtl.Append(self.popupID8, u"Antonymie")
1040 #            menu_cnrtl.Append(self.popupID9, u"Morphologie")
1041 #            menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
1042 #            menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
1043 #            menu.AppendSeparator()
1044 #            menu.Append(self.popupIDgraph, u"Graphe de la classe")
1045 #            menu.Append(self.idseg, u"Segments répétés")
1046 #            menu.Append(self.iducecarac, u"UCE caractéristiques")
1047 #            menu.Append(self.idexport, 'Partitionner...')
1048 #            #menu.Append(self.popupID2, u"Concordancier")
1049 #    #        menu.Append(self.popupID3, "recharger")
1050 #    
1051 #            self.PopupMenu(menu)
1052 #            menu.Destroy()
1053 #        elif 'tableau' in dir(self.Source) :
1054 #            if not hasattr(self, "pop1"):
1055 #                self.pop1 = wx.NewId()
1056 #                self.pop2 = wx.NewId()
1057 #                self.pop3 = wx.NewId()
1058 #                self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
1059 #                self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
1060 #                self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
1061 #
1062 #            menu = wx.Menu()
1063 #            menu.Append(self.pop2, u"Chi2 par classe")
1064 #            menu.Append(self.pop3, u"Chi2 modalités de la variable")
1065 #            menu.AppendSeparator()
1066 #            menu.Append(self.pop1, u"Graph de la classe")
1067 #            self.PopupMenu(menu)
1068 #            menu.Destroy()
1069 #
1070 #    def onexport(self, evt) :
1071 #        if 'corpus' in dir(self.Source):
1072 #            corpus = self.Source.corpus
1073 #        ClasseCHD(self.parent, corpus, self.cl)
1074 #
1075 #    def quest_var_mod(self, evt) :
1076 #        if 'corpus' in dir(self.Source):
1077 #            corpus = self.Source.corpus
1078 #            if self.var_mod == {} :
1079 #                self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
1080 #        else :
1081 #            corpus = self.Source.tableau
1082 #            if self.var_mod == {} :
1083 #                self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
1084 #        with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1085 #            chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1086 #        title = chistable[0]
1087 #        title.pop(0)
1088 #        chistable.pop(0)
1089 #        vchistable = [line[1:] for line in chistable]
1090 #        fchistable = [line[0] for line in chistable]
1091 #        word = self.getColumnText(self.list.GetFirstSelected(), 6)
1092 #        if len(word.split('_')) > 1 :
1093 #            var = word.split('_')[0]
1094 #            words = [word for word in self.var_mod[var]]
1095 #            words.sort()
1096 #            tableout = []
1097 #            kwords = []
1098 #            for word in words :
1099 #                if word in fchistable :
1100 #                    tableout.append(vchistable[fchistable.index(word)])
1101 #                    kwords.append(word)
1102 #            tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1103 #            txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1104 #            tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1105 #            file = open(tmpscript,'w')
1106 #            file.write(txt)
1107 #            file.close()
1108 #            exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1109 #            win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1110 #            win.addsaveimage(tmpgraph)
1111 #            txt = "<img src='%s'>" % tmpgraph
1112 #            win.HtmlPage.SetPage(txt)
1113 #            win.Show(True)
1114 #        else :
1115 #            dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
1116 #            dial.CenterOnParent()
1117 #            dial.ShowModal()
1118 #            dial.Destroy()
1119 #
1120 #    def quest_simi(self, evt) :
1121 #        tableau = self.Source.tableau
1122 #        tab = tableau.make_table_from_classe(self.cl, self.la)
1123 #        pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
1124 #        self.filename = os.path.join(pathout,'mat01.csv')
1125 #        tableau.printtable(self.filename, tab)
1126 #        del tab
1127 #        paramsimi = {'coeff' : 0,
1128 #                          'layout' : 2,
1129 #                          'type' : 1,
1130 #                          'arbremax' : 1,
1131 #                          'coeff_tv' : 1,
1132 #                          'coeff_tv_nb' : 0,
1133 #                          'tvprop' : 0,
1134 #                          'tvmin' : 5,
1135 #                          'tvmax' : 30,
1136 #                          'coeff_te' : 1,
1137 #                          'coeff_temin' : 1,
1138 #                          'coeff_temax' : 10,
1139 #                          'label_v': 1,
1140 #                          'label_e': 1,
1141 #                          'vcex' : 0,
1142 #                          'vcexmin' : 10,
1143 #                          'vcexmax' : 25,
1144 #                          'cex' : 10,
1145 #                          'cexfromchi' : True,
1146 #                          'sfromchi': False,
1147 #                          'seuil_ok' : 0,
1148 #                          'seuil' : 1,
1149 #                          'cols' : (255,0,0),
1150 #                          'cola' : (200,200,200),
1151 #                          'width' : 1000,
1152 #                          'height' : 1000,
1153 #                          'first' : True,
1154 #                          'keep_coord' : True,
1155 #                          'alpha' : 20,
1156 #                          'film': False,
1157 #                          }
1158 ##        self.tableau.actives = {}
1159 ##        self.tableau.lchi = self.lchi
1160 ##        self.tableau.chi = {}
1161 ##        for i, val in enumerate(self.la) :
1162 ##            self.tableau.actives[val] = [self.lfreq[i]]
1163 ##            self.tableau.chi[val] = [self.lchi[i]]
1164 #                          
1165 #        act = {}
1166 #        self.tableau.chi = {}
1167 #        self.tableau.lchi = self.lchi
1168 #        self.tableau.parametre['fromprof'] = True
1169 #        for i, val in enumerate(self.la) :
1170 #            act[val] = [self.lfreq[i]]
1171 #            self.tableau.chi[val] = [self.lchi[i]]
1172 #        DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
1173 #
1174 #    def onwordgraph(self, evt):
1175 #        word = self.getColumnText(self.list.GetFirstSelected(), 6)
1176 #        dlg = progressbar(self, 2)
1177 #        corpus = self.Source.corpus
1178 #        uces = corpus.lc[self.cl-1]
1179 #        dlg.Update(1, u'Tableau...')
1180 #        #tab = corpus.make_table_with_classe(uces, self.la)
1181 #        pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
1182 #        self.filename = os.path.join(pathout,'mat01.csv')
1183 #        dlg.Update(2, u'Ecriture...')
1184 #        #corpus.write_tab(tab, self.filename)
1185 #        #del tab
1186 #        corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1187 #        dlg.Destroy()
1188 #        paramsimi = {'coeff' : 0,
1189 #                          'layout' : 2,
1190 #                          'type' : 1,
1191 #                          'arbremax' : 0,
1192 #                          'coeff_tv' : 1,
1193 #                          'coeff_tv_nb' : 0,
1194 #                          'tvprop' : 0,
1195 #                          'tvmin' : 5,
1196 #                          'tvmax' : 30,
1197 #                          'coeff_te' : 1,
1198 #                          'coeff_temin' : 1,
1199 #                          'coeff_temax' : 10,
1200 #                          'label_v': 1,
1201 #                          'label_e': 0,
1202 #                          'vcex' : 1,
1203 #                          'vcexmin' : 10,
1204 #                          'vcexmax' : 25, 
1205 #                          'cex' : 10,
1206 #                          'seuil_ok' : 1,
1207 #                          'seuil' : 1,
1208 #                          'cols' : (255,0,0),
1209 #                          'cola' : (200,200,200),
1210 #                          'width' : 600,
1211 #                          'height' : 600,
1212 #                          'first' : True,
1213 #                          'keep_coord' : True,
1214 #                          'alpha' : 20,
1215 #                          'film': False,
1216 #                          }
1217 #        self.tableau = Tableau(self.parent, '')
1218 #        self.tableau.listactives = self.la
1219 #        self.tableau.actives = {}
1220 #        for i, val in enumerate(self.la) :
1221 #            self.tableau.actives[val] = [self.lfreq[i]]
1222 #        DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
1223 #
1224 #
1225     def OnPopupOne(self, event):
1226         corpus = self.Source.corpus
1227         #print 'ATTENTION PRINT ET TABLE'
1228         #corpus.make_et_table()
1229         word = self.getColumnText(self.GetFirstSelected(), 6)
1230         lems = corpus.getlems()
1231         uces = corpus.lc[self.cl-1]
1232         rep = []
1233         #FIXME : donner aussi eff reel a la place de nb uce
1234         for forme in lems[word].formes :
1235             ucef = list(set(corpus.getworduces(forme)).intersection(uces))
1236             #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
1237             if ucef != [] :
1238                 nb = len(ucef)
1239                 rep.append([corpus.getforme(forme).forme, nb])
1240         win = message(self, u"Formes associées", wx.Size(300, 200))
1241         win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
1242         win.HtmlPage.SetPage(win.html)
1243         win.Show(True)
1244 #
1245 #    def on_graph(self, evt):
1246 #        dlg = progressbar(self, 2)
1247 #        corpus = self.Source.corpus
1248 #        uces = corpus.lc[self.cl-1]
1249 #        dlg.Update(1, u'Tableau...')
1250 #        #tab = corpus.make_table_with_classe(uces, self.la)
1251 #        pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
1252 #        self.filename = os.path.join(pathout,'mat01.csv')
1253 #        dlg.Update(2, u'Ecriture...')
1254 #        #corpus.write_tab(tab, self.filename)
1255 #        #del tab
1256 #        corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
1257 #        dlg.Destroy()
1258 #        paramsimi = {'coeff' : 0,
1259 #                          'layout' : 2,
1260 #                          'type' : 1,
1261 #                          'arbremax' : 1,
1262 #                          'coeff_tv' : 1,
1263 #                          'coeff_tv_nb' : 0,
1264 #                          'tvprop' : 0,
1265 #                          'tvmin' : 5,
1266 #                          'tvmax' : 30,
1267 #                          'coeff_te' : 1,
1268 #                          'coeff_temin' : 1,
1269 #                          'coeff_temax' : 10,
1270 #                          'label_v': 1,
1271 #                          'label_e': 0,
1272 #                          'vcex' : 0,
1273 #                          'vcexmin' : 10,
1274 #                          'vcexmax' : 25,
1275 #                          'cex' : 10,
1276 #                          'cexfromchi' : True,
1277 #                          'sfromchi': False,
1278 #                          'seuil_ok' : 0,
1279 #                          'seuil' : 1,
1280 #                          'cols' : (255,0,0),
1281 #                          'cola' : (200,200,200),
1282 #                          'width' : 1000,
1283 #                          'height' : 1000,
1284 #                          'first' : True,
1285 #                          'keep_coord' : True,
1286 #                          'alpha' : 20,
1287 #                          'film': False,
1288 #                          }
1289 #        self.tableau = Tableau(self.parent, '')
1290 #        self.tableau.listactives = self.la
1291 #        self.tableau.actives = {}
1292 #        self.tableau.lchi = self.lchi
1293 #        self.tableau.chi = {}
1294 #        self.tableau.parametre['fromprof'] = True
1295 #        for i, val in enumerate(self.la) :
1296 #            self.tableau.actives[val] = [self.lfreq[i]]
1297 #            self.tableau.chi[val] = [self.lchi[i]]
1298 #        DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
1299 #
1300 #    def on_segments(self,evt) :
1301 #        dlg = progressbar(self, 2)
1302 #        corpus = self.Source.corpus
1303 #        uces = corpus.lc[self.cl-1]
1304 #        l = []
1305 #        dlg.Update(1, u'Segments...')
1306 #        for i in range(2,10) :
1307 #            li = corpus.find_segments_in_classe(uces, i, 1000)
1308 #            if li == [] :
1309 #                break
1310 #            else :
1311 #                l += li
1312 #        l.sort(reverse = True)
1313 #        d = {}
1314 #        dlg.Update(2, 'Tri...')
1315 #        for i, line in enumerate(l) :
1316 #            d[i] = [line[1],line[0], line[2]]
1317 #        first = ['','','']
1318 #        para={'dico': d,'fline':first}
1319 #        dlg.Destroy()
1320 #        win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
1321 #        win.Show(True)
1322 #
1323 #    def on_uce_carac(self,evt) :
1324 #        dial = PrefUCECarac(self, self.parent)
1325 #        dial.CenterOnParent()
1326 #        if dial.ShowModal() == wx.ID_OK :
1327 #            limite = dial.spin_eff.GetValue()
1328 #            atype = dial.radio_type.GetSelection()
1329 #            dlg = progressbar(self,maxi = 4)
1330 #            corpus = self.Source.corpus
1331 #            uces = corpus.lc[self.cl-1]
1332 #            tab = corpus.make_table_with_classe(uces, self.la)
1333 #            tab.pop(0)
1334 #            dlg.Update(2, u'score...')
1335 #            if atype == 0 :
1336 #                ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
1337 #            else :
1338 #                ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1])/float(sum(line)),2) if sum(line)!=0 else 0 for line in tab]
1339 #            ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
1340 #            del ntab
1341 #            ntab2.sort(reverse = True)
1342 #            ntab2 = ntab2[:limite]
1343 #            nuces = [val[1] for val in ntab2]
1344 #            dlg.Update(3, u'concordancier...')
1345 #            #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
1346 #            ucestxt1 = [row for row in corpus.getconcorde(nuces)]
1347 #            ucestxt = []
1348 #            ucis_txt = []
1349 #            for uce in ucestxt1 :
1350 #                ucetxt = ' '+uce[1]+' '
1351 #                ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
1352 #                for lem in self.la :
1353 #                    listmot = corpus.getlems()[lem].formes
1354 #                    for id in listmot :
1355 #                        forme = corpus.getforme(id).forme
1356 #                        ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1357 #                ucestxt.append(ucetxt)        
1358 #            #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
1359 #            dlg.Update(4, u'texte...')
1360 #            #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
1361 #            win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1362 #            win.html = '<html>\n' + '<br><br>'.join(['<br>'.join([ucis_txt[i], 'score : ' + str(ntab2[i][0]), ucestxt[i]]) for i in range(0,len(ucestxt))]) + '\n</html>'
1363 #            win.HtmlPage.SetPage(win.html)
1364 #            dlg.Destroy()
1365 #            win.Show(True)
1366 #    
1367 #    def on_tablex(self, evt):
1368 #        if 'corpus' in dir(self.Source):
1369 #            corpus = self.Source.corpus
1370 #        else :
1371 #            corpus = self.Source.tableau
1372 #        with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1373 #            chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1374 #        title = chistable[0]
1375 #        title.pop(0)
1376 #        chistable.pop(0)
1377 #        vchistable = [line[1:] for line in chistable]
1378 #        fchistable = [line[0] for line in chistable]
1379 #        words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1380 #        tableout = [vchistable[fchistable.index(words[0])]]
1381 #        last = self.list.GetFirstSelected()
1382 #        while self.list.GetNextSelected(last) != -1:
1383 #            last = self.list.GetNextSelected(last)
1384 #            word = self.getColumnText(last, 6)
1385 #            words.append(word)
1386 #            tableout.append(vchistable[fchistable.index(word)])
1387 #        tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1388 #        nbcl = len(title)
1389 #        txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
1390 #        tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1391 #        file = open(tmpscript,'w')
1392 #        file.write(txt)
1393 #        file.close()
1394 #        
1395 #        exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1396 #        win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1397 #        win.addsaveimage(tmpgraph)
1398 #        txt = "<img src='%s'>" % tmpgraph
1399 #        win.HtmlPage.SetPage(txt)
1400 #        win.Show(True)
1401 #
1402 #    def onlexdendro(self, evt):
1403 #        if 'corpus' in dir(self.Source):
1404 #            corpus = self.Source.corpus
1405 #        else :
1406 #            corpus = self.Source.tableau
1407 #        with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
1408 #            chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
1409 #        title = chistable[0]
1410 #        title.pop(0)
1411 #        chistable.pop(0)
1412 #        vchistable = [line[1:] for line in chistable]
1413 #        fchistable = [line[0] for line in chistable]
1414 #        words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1415 #        tableout = [vchistable[fchistable.index(words[0])]]
1416 #        last = self.list.GetFirstSelected()
1417 #        while self.list.GetNextSelected(last) != -1:
1418 #            last = self.list.GetNextSelected(last)
1419 #            word = self.getColumnText(last, 6)
1420 #            words.append(word)
1421 #            tableout.append(vchistable[fchistable.index(word)])
1422 #        tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1423 #        txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
1424 #        rownames = 'c("' + '","'.join(words) + '")'
1425 #        colnames = 'c("' + '","'.join(title) + '")'
1426 #        nbcl = len(title)
1427 #        rownb = len(words)
1428 #        txt = """
1429 #        load("%s")
1430 #        di <- matrix(data=%s, nrow=%i, byrow = TRUE)
1431 #        rownames(di)<- %s
1432 #        colnames(di) <- %s
1433 #        library(ape)
1434 #        source("%s")
1435 #        height <- (30*ncol(di)) + (15*nrow(di))
1436 #        height <- ifelse(height <= 400, 400, height)
1437 #        width <- 500
1438 #        open_file_graph("%s", width=width, height=height)
1439 #        plot.dendro.lex(tree.cut1$tree.cl, di)
1440 #        """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
1441 #        tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
1442 #        file = open(tmpscript,'w')
1443 #        file.write(txt)
1444 #        file.close()
1445 #        exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
1446 #        win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
1447 #        win.addsaveimage(tmpgraph)
1448 #        txt = "<img src='%s'>" % tmpgraph
1449 #        win.HtmlPage.SetPage(txt)
1450 #        win.Show(True)
1451 #
1452 #
1453 #    def make_concord(self, uces, title, color = 'red') :
1454 #        corpus = self.Source.corpus
1455 #        ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
1456 #        last = self.list.GetFirstSelected()
1457 #        while self.list.GetNextSelected(last) != -1:
1458 #            last = self.list.GetNextSelected(last)
1459 #            ListWord.append(self.getColumnText(last, 6))
1460 #        listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
1461 #        win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
1462 #        toshow = ['<html>\n<H1>Concordancier</H1>\n']
1463 #        toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
1464 #        duce = {}
1465 #        ucef = []
1466 #        for word in ListWord : 
1467 #            ucef += list(set(corpus.getlemuces(word)).intersection(uces))
1468 #        ucef = list(set(ucef))
1469 #        ucef.sort()
1470 #        res = corpus.getconcorde(ucef)
1471 #        txt = '<br>'.join(toshow) +'<br><br>'
1472 #        for uce in res :
1473 #            ucetxt = ' '+uce[1]+' '
1474 #            txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
1475 #            for forme in listmot:
1476 #                forme = corpus.getforme(forme).forme
1477 #                ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
1478 #            txt += ucetxt + '<br><br>'
1479 #        win.HtmlPage.SetPage(txt)
1480 #        return win
1481 #
1482 #    def OnPopupTwo(self, event):
1483 #        corpus = self.Source.corpus
1484 #        uces = corpus.lc[self.cl-1]
1485 #        win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
1486 #        win.Show(True)
1487 #    
1488 #    def OnPopupThree(self, event):
1489 #        corpus = self.Source.corpus
1490 #        uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
1491 #        win = self.make_concord(uces, "Concordancier - UCE classées")
1492 #        win.Show(True)
1493 #        
1494 #    def OnPopupFour(self, event):
1495 #        corpus = self.Source.corpus
1496 #        uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
1497 #        win = self.make_concord(uces, "Concordancier - Toutes les UCE")
1498 #        win.Show(True)
1499 #
1500 #    def OnPopupFive(self, event):
1501 #        word = self.getColumnText(self.list.GetFirstSelected(), 6)
1502 #        lk = "http://www.cnrtl.fr/definition/" + word
1503 #        webbrowser.open(lk)
1504 #
1505 #    def OnPopupSix(self, event):  
1506 #        word = self.getColumnText(self.list.GetFirstSelected(), 6)
1507 #        lk = "http://www.cnrtl.fr/etymologie/" + word
1508 #        webbrowser.open(lk)
1509 #        
1510 #    def OnPopupSeven(self, event):        
1511 #        word = self.getColumnText(self.list.GetFirstSelected(), 6)
1512 #        lk = "http://www.cnrtl.fr/synonymie/" + word
1513 #        webbrowser.open(lk)
1514 #        
1515 #    def OnPopupHeight(self, event):  
1516 #        word = self.getColumnText(self.list.GetFirstSelected(), 6)
1517 #        lk = "http://www.cnrtl.fr/antonymie/" + word
1518 #        webbrowser.open(lk)
1519 #        
1520 #    def OnPopupNine(self, event):            
1521 #        word = self.getColumnText(self.list.GetFirstSelected(), 6)
1522 #        lk = "http://www.cnrtl.fr/morphologie/" + word
1523 #        webbrowser.open(lk)
1524 #
1525 #    def onproxe(self, evt) :
1526 #        word = self.getColumnText(self.list.GetFirstSelected(), 6)
1527 #        lk = "http://www.cnrtl.fr/proxemie/" + word
1528 #        webbrowser.open(lk)
1529 #
1530 #    def OnSize(self, event):
1531 #        w, h = self.GetClientSizeTuple()
1532 #        self.list.SetDimensions(0, 0, w, h)
1533 #        
1534 #    def OnColClick(self, event):
1535 #        self.do_greyline()
1536 #
1537 #
1538 #class wliste(wx.Frame):
1539 #    def __init__(self, parent, id, title, d, fline, size=(600, 500)):
1540 #        wx.Frame.__init__(self, parent, id)
1541 #        self.liste = ListForSpec(self, parent, d, fline)
1542 #        self.button_1 = wx.Button(self, -1, "Fermer")
1543 #        self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1544 #        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1545 #        self.__do_layout()
1546 #
1547 #    def __do_layout(self):
1548 #        sizer_1 = wx.BoxSizer(wx.VERTICAL)
1549 #        sizer_2 = wx.BoxSizer(wx.VERTICAL)
1550 #        sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
1551 #        sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
1552 #        sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
1553 #        self.SetAutoLayout(True)
1554 #        self.SetSizer(sizer_1)
1555 #        self.Layout()
1556 #        
1557 #    def OnCloseMe(self, event):
1558 #        self.Close(True)
1559 #
1560 #    def OnCloseWindow(self, event):
1561 #        self.Destroy()
1562 #
1563 #class message(wx.Dialog):
1564 #    def __init__(self, parent, title, size, save = True):
1565 #        wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = title, pos = wx.DefaultPosition, size = size, style = wx.DEFAULT_DIALOG_STYLE )
1566 #       self.save = save        
1567 #        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
1568 #
1569 #        self.html = ""
1570 #        self.HtmlPage=wx.html.HtmlWindow(self, -1)
1571 #        self.HtmlPage.SetMinSize( size )
1572 #        if "gtk2" in wx.PlatformInfo:
1573 #            self.HtmlPage.SetStandardFonts()
1574 #        self.HtmlPage.SetFonts('Courier','Courier')
1575 #
1576 #        self.button_1 = wx.Button(self, wx.ID_CANCEL)
1577 #
1578 #        self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
1579 #        if self.save :
1580 #            self.button_2 = wx.Button(self, wx.ID_SAVE)
1581 #            self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
1582 #        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
1583 #        self.__do_layout()
1584 #
1585 #    def __do_layout(self):
1586 #        sizer_2 = wx.BoxSizer(wx.VERTICAL)
1587 #        sizer_2.Add(self.HtmlPage, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
1588 #        m_sdbSizer1 = wx.StdDialogButtonSizer()
1589 #        m_sdbSizer1.AddButton(  self.button_1 )
1590 #        if self.save :
1591 #            m_sdbSizer1.AddButton(  self.button_2 )
1592 #        m_sdbSizer1.Realize()
1593 #        sizer_2.Add(m_sdbSizer1, 1, wx.EXPAND, 5)
1594 #        self.SetSizer(sizer_2)
1595 #        self.Layout()
1596 #        sizer_2.Fit( self )
1597 #
1598 #    def OnSavePage(self, evt) :
1599 #        dlg = wx.FileDialog(
1600 #            self, message="Enregistrer sous...", defaultDir=os.getcwd(),
1601 #            defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
1602 #            )
1603 #        dlg.SetFilterIndex(2)
1604 #        dlg.CenterOnParent()
1605 #        if dlg.ShowModal() == wx.ID_OK:
1606 #            path = dlg.GetPath()
1607 #            with open(path, 'w') as f :
1608 #                f.write(self.html)
1609 #
1610 #    def OnCloseMe(self, event):
1611 #        self.Close(True)
1612 #
1613 #    def OnCloseWindow(self, event):
1614 #        self.Destroy()