1 # -*- coding: utf-8 -*-
3 #----------------------------------------------------------------------------
5 # Author: Pierre Ratinaud
8 #comes from ListCtrl.py from the demo tool of wxPython:
9 # Author: Robin Dunn & Gary Dumer
12 # Copyright: (c) 1998 by Total Control Software
13 # Licence: wxWindows license
14 #----------------------------------------------------------------------------
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
24 from tableau import Tableau
25 from search_tools import SearchFrame
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
35 #---------------------------------------------------------------------------
37 class ProfListctrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
38 def __init__(self, parent, ID, pos=wx.DefaultPosition,
39 size=wx.DefaultSize, style=0):
40 wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
41 listmix.ListCtrlAutoWidthMixin.__init__(self)
44 class ProfListctrlPanel(wx.Panel, listmix.ColumnSorterMixin):
45 def __init__(self, parent, gparent, ProfClasse, Alceste=False, cl=0):
50 if 'tableau' in dir(self.Source):
51 self.tableau = self.Source.tableau
52 self.Alceste = Alceste
56 wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS)
58 search_id = wx.NewId()
59 searchall_id = wx.NewId()
60 self.parent.Bind(wx.EVT_MENU, self.onsearch, id = search_id)
61 self.parent.Bind(wx.EVT_MENU, self.onsearchall, id = searchall_id)
62 self.accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), search_id),
63 (wx.ACCEL_CTRL|wx.ACCEL_SHIFT, ord('F'), searchall_id)])
64 self.SetAcceleratorTable(self.accel_tbl)
66 self.il = wx.ImageList(16, 16)
67 # self.idx1 = self.il.Add(images.getSmilesBitmap())
68 self.sm_up = self.il.Add(getSmallUpArrowBitmap())
69 self.sm_dn = self.il.Add(getSmallDnArrowBitmap())
72 self.list = ProfListctrl(self, tID,
76 | wx.LC_SORT_ASCENDING
83 limit = [i for i,b in enumerate(classe[1:]) if b[0] == '*']
86 limitsup = [i for i,b in enumerate(classe[1:]) if b[0] == '*****']
90 limitsup = limitsup[0]
91 classen = [line for line in classe[1:] if line[0] != '*' and line[0] != '*****']
93 limit = len(classen) - 1
94 dictdata = dict(zip([i for i in range(0,len(classen))], classen))
95 #if not self.Alceste :
97 self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
99 self.PopulateList(dictdata, limit, limitsup, Alceste)
101 self.Bind(wx.EVT_SIZE, self.OnSize)
102 self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick)
103 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
106 self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick)
109 self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
110 self.itemDataMap = dictdata
111 listmix.ColumnSorterMixin.__init__(self, 8)
113 #-----------------------------------------------------------------------------------------
115 def PopulateList(self, dictdata, limit, limitsup, Alceste):
118 # for normal, simple columns, you can add them like this:
119 self.list.InsertColumn(0, "num", wx.LIST_FORMAT_RIGHT)
120 self.list.InsertColumn(1, "eff. uce", wx.LIST_FORMAT_RIGHT)
121 self.list.InsertColumn(2, "eff. total", wx.LIST_FORMAT_RIGHT)
122 self.list.InsertColumn(3, "pourcentage", wx.LIST_FORMAT_RIGHT)
123 self.list.InsertColumn(4, "chi2", wx.LIST_FORMAT_RIGHT)
124 self.list.InsertColumn(5, "Type", wx.LIST_FORMAT_RIGHT)
125 self.list.InsertColumn(6, "forme", wx.LIST_FORMAT_RIGHT)
126 self.list.InsertColumn(7, "p", wx.LIST_FORMAT_RIGHT)
128 for key in dictdata : #.iteritems():
129 index = self.list.InsertStringItem(sys.maxint, '%4i' % key)
131 for val in dictdata[key][1:]:
132 self.list.SetStringItem(index, i, str(dictdata[key][i]))
134 self.list.SetItemData(index, key)
136 self.list.SetColumnWidth(0, 60)
137 self.list.SetColumnWidth(1, 70)
138 self.list.SetColumnWidth(2, 80)
139 self.list.SetColumnWidth(3, 100)
140 self.list.SetColumnWidth(4, 70)
141 self.list.SetColumnWidth(5, wx.LIST_AUTOSIZE)
142 self.list.SetColumnWidth(6, wx.LIST_AUTOSIZE)
143 self.list.SetColumnWidth(7, wx.LIST_AUTOSIZE)
145 # show how to change the colour of a couple items
147 for i in range(limitsup, limit):
148 item = self.list.GetItem(i)
149 item.SetTextColour(wx.RED)
150 self.list.SetItem(item)
154 for i in range(limit, len(dictdata)):
155 item = self.list.GetItem(i)
156 item.SetTextColour(wx.BLUE)
157 self.list.SetItem(item)
160 self.la = [self.getColumnText(i,6) for i in range(0, limitsup-1)]
161 self.lchi = [float(self.getColumnText(i,4)) for i in range(0, limitsup-1)]
162 self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, limitsup-1)]
164 self.la = [self.getColumnText(i,6) for i in range(0, limit)]
165 self.lfreq = [int(self.getColumnText(i,1)) for i in range(0, limit)]
166 self.lchi = [float(self.getColumnText(i,4)) for i in range(0, limit)]
168 def do_greyline(self):
169 for row in xrange(self.list.GetItemCount()):
171 self.list.SetItemBackgroundColour(row, (230, 230, 230))
173 self.list.SetItemBackgroundColour(row, wx.WHITE)
176 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
177 def GetListCtrl(self):
180 # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
181 def GetSortImages(self):
182 return (self.sm_dn, self.sm_up)
185 def OnRightDown(self, event):
188 item, flags = self.list.HitTest((x, y))
190 if flags & wx.LIST_HITTEST_ONITEM:
191 self.list.Select(item)
196 def getColumnText(self, index, col):
197 item = self.list.GetItem(index, col)
198 return item.GetText()
201 def OnItemSelected(self, event):
202 self.currentItem = event.m_itemIndex
205 def onsearch(self, evt) :
206 self.dial = SearchDial(self, self, 6, True)
207 self.dial.CenterOnParent()
208 self.dial.ShowModal()
211 def onsearchall(self, evt) :
212 if 'FrameSearch' not in dir(self.Source) :
213 self.Source.FrameSearch = SearchFrame(self.parent, -1, u"Rechercher...", self.Source.corpus)
214 self.dial = SearchDial(self, self.Source.FrameSearch.liste, 1, False)
215 self.dial.CenterOnParent()
216 self.dial.ShowModal()
219 def OnRightClick(self, event):
221 # only do this part the first time so the events are only bound once
223 if not hasattr(self, "popupID1"):
224 self.popupID1 = wx.NewId()
225 self.popupID2 = wx.NewId()
226 self.popupID3 = wx.NewId()
227 self.popupID4 = wx.NewId()
228 self.popupID5 = wx.NewId()
229 self.popupID6 = wx.NewId()
230 self.popupID7 = wx.NewId()
231 self.popupID8 = wx.NewId()
232 self.popupID9 = wx.NewId()
233 #self.popupID10 = wx.NewId()
234 self.popupIDgraph = wx.NewId()
235 self.idseg = wx.NewId()
236 self.iducecarac = wx.NewId()
237 self.idtablex = wx.NewId()
238 self.idchimod = wx.NewId()
239 self.idwordgraph = wx.NewId()
240 self.popup_proxe = wx.NewId()
241 self.idlexdendro = wx.NewId()
242 self.idexport = wx.NewId()
243 # self.export_classes = wx.NewId()
245 self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1)
246 self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2)
247 self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
248 self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4)
249 self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5)
250 self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6)
251 self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7)
252 self.Bind(wx.EVT_MENU, self.OnPopupHeight, id=self.popupID8)
253 self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9)
254 #self.Bind(wx.EVT_MENU, self.OnPopupSpec, id=self.popupID10)
255 self.Bind(wx.EVT_MENU, self.on_graph, id=self.popupIDgraph)
256 self.Bind(wx.EVT_MENU, self.on_segments, id=self.idseg)
257 self.Bind(wx.EVT_MENU, self.on_uce_carac, id = self.iducecarac)
258 self.Bind(wx.EVT_MENU, self.on_tablex, id = self.idtablex)
259 self.Bind(wx.EVT_MENU, self.quest_var_mod, id = self.idchimod)
260 self.Bind(wx.EVT_MENU, self.onwordgraph, id = self.idwordgraph)
261 self.Bind(wx.EVT_MENU, self.onproxe, id = self.popup_proxe)
262 self.Bind(wx.EVT_MENU, self.onlexdendro, id = self.idlexdendro)
263 self.Bind(wx.EVT_MENU, self.onexport, id = self.idexport)
264 # self.Bind(wx.EVT_MENU, self.on_export_classes, id = self.export_classes)
265 # self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3)
269 menu.Append(self.popupID1, u"Formes associées")
270 menu.Append(self.idtablex, u"Chi2 par classe")
271 menu.Append(self.idlexdendro, u"Chi2 par classe + dendro")
272 menu.Append(self.idchimod, u"Chi2 modalités de la variable")
273 menu.Append(self.idwordgraph, u"Graphe du mot")
274 #menu.Append(self.export_classes, u"Exporter le corpus...")
276 #menu.Append(self.popupID10, u"Spécificités")
278 menu_conc = wx.Menu()
279 menu_conc.Append(self.popupID2, u"dans les uce de la classe")
280 menu_conc.Append(self.popupID3, u"dans les uce classées")
281 menu_conc.Append(self.popupID4, u"dans toutes les uce")
282 menu.AppendMenu(-1, u"Concordancier", menu_conc)
283 menu_cnrtl = wx.Menu()
284 menu_cnrtl.Append(self.popupID5, u"Définition")
285 menu_cnrtl.Append(self.popupID6, u"Etymologie")
286 menu_cnrtl.Append(self.popupID7, u"Synonymie")
287 menu_cnrtl.Append(self.popupID8, u"Antonymie")
288 menu_cnrtl.Append(self.popupID9, u"Morphologie")
289 menu_cnrtl.Append(self.popup_proxe, u"Proxémie")
290 menu.AppendMenu(-1, u"Outils du CNRTL", menu_cnrtl)
291 menu.AppendSeparator()
292 menu.Append(self.popupIDgraph, u"Graphe de la classe")
293 menu.Append(self.idseg, u"Segments répétés")
294 menu.Append(self.iducecarac, u"UCE caractéristiques")
295 menu.Append(self.idexport, 'Partitionner...')
296 #menu.Append(self.popupID2, u"Concordancier")
297 # menu.Append(self.popupID3, "recharger")
301 elif 'tableau' in dir(self.Source) :
302 if not hasattr(self, "pop1"):
303 self.pop1 = wx.NewId()
304 self.pop2 = wx.NewId()
305 self.pop3 = wx.NewId()
306 self.Bind(wx.EVT_MENU, self.quest_simi, id=self.pop1)
307 self.Bind(wx.EVT_MENU, self.on_tablex, id=self.pop2)
308 self.Bind(wx.EVT_MENU, self.quest_var_mod, id=self.pop3)
311 menu.Append(self.pop2, u"Chi2 par classe")
312 menu.Append(self.pop3, u"Chi2 modalités de la variable")
313 menu.AppendSeparator()
314 menu.Append(self.pop1, u"Graph de la classe")
318 def onexport(self, evt) :
319 if 'corpus' in dir(self.Source):
320 corpus = self.Source.corpus
321 ClasseCHD(self.parent, corpus, self.cl)
323 def quest_var_mod(self, evt) :
324 if 'corpus' in dir(self.Source):
325 corpus = self.Source.corpus
326 if self.var_mod == {} :
327 self.var_mod = treat_var_mod([val for val in corpus.make_etoiles()])
329 corpus = self.Source.tableau
330 if self.var_mod == {} :
331 self.var_mod = treat_var_mod([val for val in corpus.actives] + [val for val in corpus.sups])
332 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
333 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
337 vchistable = [line[1:] for line in chistable]
338 fchistable = [line[0] for line in chistable]
339 word = self.getColumnText(self.list.GetFirstSelected(), 6)
340 if len(word.split('_')) > 1 :
341 var = word.split('_')[0]
342 words = [word for word in self.var_mod[var]]
347 if word in fchistable :
348 tableout.append(vchistable[fchistable.index(word)])
350 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
351 txt = barplot(tableout, kwords, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
352 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
353 file = open(tmpscript,'w')
356 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
357 win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
358 win.addsaveimage(tmpgraph)
359 txt = "<img src='%s'>" % tmpgraph
360 win.HtmlPage.SetPage(txt)
363 dial = wx.MessageDialog(self, u"Ce n'est pas une forme du type variable_modalité", u"Problème", wx.OK | wx.ICON_WARNING)
364 dial.CenterOnParent()
368 def quest_simi(self, evt) :
369 tableau = self.Source.tableau
370 tab = tableau.make_table_from_classe(self.cl, self.la)
371 pathout = ConstructPathOut(self.Source.pathout+'/', 'simi_classe_%i' %self.cl)
372 self.filename = os.path.join(pathout,'mat01.csv')
373 tableau.printtable(self.filename, tab)
375 paramsimi = {'coeff' : 0,
398 'cola' : (200,200,200),
406 # self.tableau.actives = {}
407 # self.tableau.lchi = self.lchi
408 # self.tableau.chi = {}
409 # for i, val in enumerate(self.la) :
410 # self.tableau.actives[val] = [self.lfreq[i]]
411 # self.tableau.chi[val] = [self.lchi[i]]
414 self.tableau.chi = {}
415 self.tableau.lchi = self.lchi
416 self.tableau.parametre['fromprof'] = True
417 for i, val in enumerate(self.la) :
418 act[val] = [self.lfreq[i]]
419 self.tableau.chi[val] = [self.lchi[i]]
420 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, listactives = self.la, actives = act)
422 def onwordgraph(self, evt):
423 word = self.getColumnText(self.list.GetFirstSelected(), 6)
424 dlg = progressbar(self, 2)
425 corpus = self.Source.corpus
426 uces = corpus.lc[self.cl-1]
427 dlg.Update(1, u'Tableau...')
428 #tab = corpus.make_table_with_classe(uces, self.la)
429 pathout = ConstructPathOut(self.Source.pathout.dirout + '/' , 'simi_%s' % word)
430 self.filename = os.path.join(pathout,'mat01.csv')
431 dlg.Update(2, u'Ecriture...')
432 #corpus.write_tab(tab, self.filename)
434 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
436 paramsimi = {'coeff' : 0,
457 'cola' : (200,200,200),
465 self.tableau = Tableau(self.parent, '')
466 self.tableau.listactives = self.la
467 self.tableau.actives = {}
468 for i, val in enumerate(self.la) :
469 self.tableau.actives[val] = [self.lfreq[i]]
470 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout, wordgraph = word)
473 def OnPopupOne(self, event):
474 corpus = self.Source.corpus
475 #print 'ATTENTION PRINT ET TABLE'
476 #corpus.make_et_table()
477 word = self.getColumnText(self.list.GetFirstSelected(), 6)
478 lems = corpus.getlems()
479 uces = corpus.lc[self.cl-1]
481 #FIXME : donner aussi eff reel a la place de nb uce
482 for forme in lems[word].formes :
483 ucef = list(set(corpus.getworduces(forme)).intersection(uces))
484 #ucef = [uce for uce in corpus.formes[forme][1] if uce in uces]
487 rep.append([corpus.getforme(forme).forme, nb])
488 win = message(self, -1, u"Formes associées", size=(300, 200), style=wx.DEFAULT_FRAME_STYLE)
489 win.html = '<html>\n' + '<br>'.join([' : '.join([str(val) for val in forme]) for forme in rep]) + '\n</html>'
490 win.HtmlPage.SetPage(win.html)
493 def on_graph(self, evt):
494 dlg = progressbar(self, 2)
495 corpus = self.Source.corpus
496 uces = corpus.lc[self.cl-1]
497 dlg.Update(1, u'Tableau...')
498 #tab = corpus.make_table_with_classe(uces, self.la)
499 pathout = ConstructPathOut(self.Source.pathout.dirout+'/', 'simi_classe_%i' %self.cl)
500 self.filename = os.path.join(pathout,'mat01.csv')
501 dlg.Update(2, u'Ecriture...')
502 #corpus.write_tab(tab, self.filename)
504 corpus.make_and_write_sparse_matrix_from_classe(self.la, uces, self.filename)
506 paramsimi = {'coeff' : 0,
529 'cola' : (200,200,200),
537 self.tableau = Tableau(self.parent, '')
538 self.tableau.listactives = self.la
539 self.tableau.actives = {}
540 self.tableau.lchi = self.lchi
541 self.tableau.chi = {}
542 self.tableau.parametre['fromprof'] = True
543 for i, val in enumerate(self.la) :
544 self.tableau.actives[val] = [self.lfreq[i]]
545 self.tableau.chi[val] = [self.lchi[i]]
546 DoSimi(self, param = paramsimi, fromprof = ffr(self.filename), pathout = pathout)
548 def on_segments(self,evt) :
549 dlg = progressbar(self, 2)
550 corpus = self.Source.corpus
551 uces = corpus.lc[self.cl-1]
553 dlg.Update(1, u'Segments...')
554 for i in range(2,10) :
555 li = corpus.find_segments_in_classe(uces, i, 1000)
560 l.sort(reverse = True)
562 dlg.Update(2, 'Tri...')
563 for i, line in enumerate(l) :
564 d[i] = [line[1],line[0], line[2]]
566 para={'dico': d,'fline':first}
568 win = wliste(self, -1, u"Segments répétés - Classe %i" % self.cl, d, first, size=(600, 500))
571 def on_uce_carac(self,evt) :
572 dial = PrefUCECarac(self, self.parent)
573 dial.CenterOnParent()
574 if dial.ShowModal() == wx.ID_OK :
575 limite = dial.spin_eff.GetValue()
576 atype = dial.radio_type.GetSelection()
577 dlg = progressbar(self,maxi = 4)
578 corpus = self.Source.corpus
579 uces = corpus.lc[self.cl-1]
580 tab = corpus.make_table_with_classe(uces, self.la)
582 dlg.Update(2, u'score...')
584 ntab = [round(sum([self.lchi[i] for i, word in enumerate(line) if word == 1]),2) for line in tab]
586 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]
587 ntab2 = [[ntab[i], uces[i]] for i, val in enumerate(ntab)]
589 ntab2.sort(reverse = True)
590 ntab2 = ntab2[:limite]
591 nuces = [val[1] for val in ntab2]
592 dlg.Update(3, u'concordancier...')
593 #ucestxt = [corpus.ucis_paras_uces[val[1][0]][val[1][1]][val[1][2]] for val in ntab2]
594 ucestxt1 = [row for row in corpus.getconcorde(nuces)]
597 for uce in ucestxt1 :
598 ucetxt = ' '+uce[1]+' '
599 ucis_txt.append(' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>')
601 listmot = corpus.getlems()[lem].formes
603 forme = corpus.getforme(id).forme
604 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
605 ucestxt.append(ucetxt)
606 #ucestxt = [corpus.make_concord(self.la, ' '.join(uce), 'red') for uce in ucestxt]
607 dlg.Update(4, u'texte...')
608 #ucis_txt = [' '.join(corpus.ucis[val[1][0]][0]) for val in ntab2]
609 win = message(self, -1, u"UCE caractéristiques - Classe %i" % self.cl, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
610 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>'
611 win.HtmlPage.SetPage(win.html)
615 def on_tablex(self, evt):
616 if 'corpus' in dir(self.Source):
617 corpus = self.Source.corpus
619 corpus = self.Source.tableau
620 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
621 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
625 vchistable = [line[1:] for line in chistable]
626 fchistable = [line[0] for line in chistable]
627 words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
628 tableout = [vchistable[fchistable.index(words[0])]]
629 last = self.list.GetFirstSelected()
630 while self.list.GetNextSelected(last) != -1:
631 last = self.list.GetNextSelected(last)
632 word = self.getColumnText(last, 6)
634 tableout.append(vchistable[fchistable.index(word)])
635 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
637 txt = barplot(tableout, words, title, self.Source.parent.RscriptsPath['Rgraph'], tmpgraph)
638 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
639 file = open(tmpscript,'w')
643 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
644 win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
645 win.addsaveimage(tmpgraph)
646 txt = "<img src='%s'>" % tmpgraph
647 win.HtmlPage.SetPage(txt)
650 def onlexdendro(self, evt):
651 if 'corpus' in dir(self.Source):
652 corpus = self.Source.corpus
654 corpus = self.Source.tableau
655 with codecs.open(self.Source.pathout['chisqtable'], 'r', corpus.parametres['syscoding']) as f :
656 chistable = [line.replace('\n','').replace('\r','').replace('"','').replace(',','.').split(';') for line in f]
660 vchistable = [line[1:] for line in chistable]
661 fchistable = [line[0] for line in chistable]
662 words = [self.getColumnText(self.list.GetFirstSelected(), 6)]
663 tableout = [vchistable[fchistable.index(words[0])]]
664 last = self.list.GetFirstSelected()
665 while self.list.GetNextSelected(last) != -1:
666 last = self.list.GetNextSelected(last)
667 word = self.getColumnText(last, 6)
669 tableout.append(vchistable[fchistable.index(word)])
670 tmpgraph = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
671 txttable = 'c(' + ','.join([','.join(line) for line in tableout]) + ')'
672 rownames = 'c("' + '","'.join(words) + '")'
673 colnames = 'c("' + '","'.join(title) + '")'
678 di <- matrix(data=%s, nrow=%i, byrow = TRUE)
683 height <- (30*ncol(di)) + (15*nrow(di))
684 height <- ifelse(height <= 400, 400, height)
686 open_file_graph("%s", width=width, height=height)
687 plot.dendro.lex(tree.cut1$tree.cl, di)
688 """ % (self.Source.pathout['Rdendro'], txttable, rownb, rownames, colnames, self.Source.parent.RscriptsPath['Rgraph'], ffr(tmpgraph))
689 tmpscript = tempfile.mktemp(dir=self.Source.parent.TEMPDIR)
690 file = open(tmpscript,'w')
693 exec_rcode(self.Source.parent.RPath, tmpscript, wait = True)
694 win = MessageImage(self, -1, u"Graphique", size=(700, 500),style = wx.DEFAULT_FRAME_STYLE)
695 win.addsaveimage(tmpgraph)
696 txt = "<img src='%s'>" % tmpgraph
697 win.HtmlPage.SetPage(txt)
701 def make_concord(self, uces, title, color = 'red') :
702 corpus = self.Source.corpus
703 ListWord = [self.getColumnText(self.list.GetFirstSelected(), 6)]
704 last = self.list.GetFirstSelected()
705 while self.list.GetNextSelected(last) != -1:
706 last = self.list.GetNextSelected(last)
707 ListWord.append(self.getColumnText(last, 6))
708 listmot = [forme for item in ListWord for forme in corpus.getlems()[item].formes]
709 win = message(self, -1, title, size=(600, 500), style=wx.DEFAULT_FRAME_STYLE)
710 toshow = ['<html>\n<H1>Concordancier</H1>\n']
711 toshow.append('<h3><font color=%s>' % color + ' '.join(ListWord) + '</font></h3><br>')
714 for word in ListWord :
715 ucef += list(set(corpus.getlemuces(word)).intersection(uces))
716 ucef = list(set(ucef))
718 res = corpus.getconcorde(ucef)
719 txt = '<br>'.join(toshow) +'<br><br>'
721 ucetxt = ' '+uce[1]+' '
722 txt += ' '.join(corpus.ucis[corpus.getucefromid(uce[0]).uci].etoiles) + '<br>'
723 for forme in listmot:
724 forme = corpus.getforme(forme).forme
725 ucetxt = ucetxt.replace(' '+forme+' ', '<font color=red> ' + forme + ' </font>')
726 txt += ucetxt + '<br><br>'
727 win.HtmlPage.SetPage(txt)
730 def OnPopupTwo(self, event):
731 corpus = self.Source.corpus
732 uces = corpus.lc[self.cl-1]
733 win = self.make_concord(uces, "Concordancier - Classe %i" % self.cl)
736 def OnPopupThree(self, event):
737 corpus = self.Source.corpus
738 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))]
739 win = self.make_concord(uces, "Concordancier - UCE classées")
742 def OnPopupFour(self, event):
743 corpus = self.Source.corpus
744 uces = [classe[i] for classe in corpus.lc for i in range(0,len(classe))] + corpus.lc0
745 win = self.make_concord(uces, "Concordancier - Toutes les UCE")
748 def OnPopupFive(self, event):
749 word = self.getColumnText(self.list.GetFirstSelected(), 6)
750 lk = "http://www.cnrtl.fr/definition/" + word
753 def OnPopupSix(self, event):
754 word = self.getColumnText(self.list.GetFirstSelected(), 6)
755 lk = "http://www.cnrtl.fr/etymologie/" + word
758 def OnPopupSeven(self, event):
759 word = self.getColumnText(self.list.GetFirstSelected(), 6)
760 lk = "http://www.cnrtl.fr/synonymie/" + word
763 def OnPopupHeight(self, event):
764 word = self.getColumnText(self.list.GetFirstSelected(), 6)
765 lk = "http://www.cnrtl.fr/antonymie/" + word
768 def OnPopupNine(self, event):
769 word = self.getColumnText(self.list.GetFirstSelected(), 6)
770 lk = "http://www.cnrtl.fr/morphologie/" + word
773 def onproxe(self, evt) :
774 word = self.getColumnText(self.list.GetFirstSelected(), 6)
775 lk = "http://www.cnrtl.fr/proxemie/" + word
778 def OnSize(self, event):
779 w, h = self.GetClientSizeTuple()
780 self.list.SetDimensions(0, 0, w, h)
782 def OnColClick(self, event):
786 class wliste(wx.Frame):
787 def __init__(self, parent, id, title, d, fline, size=(600, 500)):
788 wx.Frame.__init__(self, parent, id)
789 self.liste = ListForSpec(self, parent, d, fline)
790 self.button_1 = wx.Button(self, -1, "Fermer")
791 self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
792 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
795 def __do_layout(self):
796 sizer_1 = wx.BoxSizer(wx.VERTICAL)
797 sizer_2 = wx.BoxSizer(wx.VERTICAL)
798 sizer_2.Add(self.liste, 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0)
799 sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, 0)
800 sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
801 self.SetAutoLayout(True)
802 self.SetSizer(sizer_1)
805 def OnCloseMe(self, event):
808 def OnCloseWindow(self, event):
811 class message(wx.Frame):
812 def __init__(self, *args, **kwds):
813 kwds["style"] = wx.DEFAULT_FRAME_STYLE
814 wx.Frame.__init__(self, *args, **kwds)
816 self.HtmlPage=wx.html.HtmlWindow(self, -1)
817 if "gtk2" in wx.PlatformInfo:
818 self.HtmlPage.SetStandardFonts()
819 self.HtmlPage.SetFonts('Courier','Courier')
820 self.button_1 = wx.Button(self, -1, "Fermer")
821 self.button_2 = wx.Button(self, -1, u"Enregistrer...")
823 self.Bind(wx.EVT_BUTTON, self.OnSavePage, self.button_2)
824 self.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.button_1)
825 self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
828 def __do_layout(self):
829 sizer_1 = wx.BoxSizer(wx.VERTICAL)
830 sizer_2 = wx.BoxSizer(wx.VERTICAL)
831 sizer_2.Add(self.HtmlPage, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
832 sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ADJUST_MINSIZE, 0)
833 sizer_2.Add(self.button_2, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ADJUST_MINSIZE, 0)
834 sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
835 self.SetAutoLayout(True)
836 self.SetSizer(sizer_1)
839 def OnSavePage(self, evt) :
841 self, message="Enregistrer sous...", defaultDir=os.getcwd(),
842 defaultFile="concordancier.html", wildcard="html|*.html", style=wx.SAVE | wx.OVERWRITE_PROMPT
844 dlg.SetFilterIndex(2)
846 if dlg.ShowModal() == wx.ID_OK:
848 with open(path, 'w') as f :
851 def OnCloseMe(self, event):
854 def OnCloseWindow(self, event):
857 def getSmallUpArrowData():
859 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
860 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
861 \x00\x00<IDAT8\x8dcddbf\xa0\x040Q\xa4{h\x18\xf0\xff\xdf\xdf\xffd\x1b\x00\xd3\
862 \x8c\xcf\x10\x9c\x06\xa0k\xc2e\x08m\xc2\x00\x97m\xd8\xc41\x0c \x14h\xe8\xf2\
863 \x8c\xa3)q\x10\x18\x00\x00R\xd8#\xec\xb2\xcd\xc1Y\x00\x00\x00\x00IEND\xaeB`\
866 def getSmallUpArrowBitmap():
867 return wx.BitmapFromImage(getSmallUpArrowImage())
869 def getSmallUpArrowImage():
870 stream = cStringIO.StringIO(getSmallUpArrowData())
871 return wx.ImageFromStream(stream)
873 #----------------------------------------------------------------------
874 def getSmallDnArrowData():
876 "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
877 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
878 \x00\x00HIDAT8\x8dcddbf\xa0\x040Q\xa4{\xd4\x00\x06\x06\x06\x06\x06\x16t\x81\
879 \xff\xff\xfe\xfe'\xa4\x89\x91\x89\x99\x11\xa7\x0b\x90%\ti\xc6j\x00>C\xb0\x89\
880 \xd3.\x10\xd1m\xc3\xe5*\xbc.\x80i\xc2\x17.\x8c\xa3y\x81\x01\x00\xa1\x0e\x04e\
881 ?\x84B\xef\x00\x00\x00\x00IEND\xaeB`\x82"
883 def getSmallDnArrowBitmap():
884 return wx.BitmapFromImage(getSmallDnArrowImage())
886 def getSmallDnArrowImage():
887 stream = cStringIO.StringIO(getSmallDnArrowData())
888 return wx.ImageFromStream(stream)