1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2012, Pierre Ratinaud
9 import wx.lib.agw.customtreectrl as CT
11 from openanalyse import OpenAnalyse
12 from corpus import Corpus, copycorpus
13 from tableau import Tableau, copymatrix
14 from functions import DoConf, GetTxtProfile, TGen, BugReport
15 from profile_segment import ProfileSegment, ProfilType
16 from search_tools import SearchFrame
17 from dialog import PrefSimpleFile, PrefExport
18 from layout import open_antiprofil, TgenLayout
19 from guifunct import TGenFrame
20 from textaslexico import TgenSpec
21 from textreinert import TgenProf
23 log = logging.getLogger('iramuteq.tree')
25 def buildmenu(menu, parent_menu):
26 for i in range(parent_menu.GetMenuItemCount()) :
27 item = parent_menu.FindItemByPosition(i)
29 itemtext = item.GetText()
30 itemicon = item.GetBitmap()
31 nitem = wx.MenuItem(menu, itemid, itemtext)
32 nitem.SetBitmap(itemicon)
35 for val in item.GetSubMenu().GetMenuItems() :
37 itemtext = val.GetText()
38 itemicon = val.GetBitmap()
39 nitem = wx.MenuItem(menu, itemid, itemtext)
40 nitem.SetBitmap(itemicon)
41 nmenu.AppendItem(nitem)
42 menu.AppendMenu(-1, item.GetText(), nmenu)
44 menu.AppendItem(nitem)
46 class InfoDialog ( wx.Dialog ):
48 def __init__( self, parent, txt, parametres ):
49 wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Informations", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
50 if len(parametres) > 30 :
54 self.SetSizeHintsSz( wx.Size( 500,200 ), wx.DefaultSize )
56 bSizer1 = wx.BoxSizer( wx.VERTICAL )
58 self.m_panel2 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
59 bSizer2 = wx.BoxSizer( wx.VERTICAL )
61 self.m_staticText4 = wx.StaticText( self.m_panel2, wx.ID_ANY, txt, wx.DefaultPosition, wx.DefaultSize, 0 )
62 self.m_staticText4.Wrap( -1 )
63 bSizer2.Add( self.m_staticText4, 0, wx.ALL, 5 )
66 self.m_panel2.SetSizer( bSizer2 )
67 self.m_panel2.Layout()
68 bSizer2.Fit( self.m_panel2 )
69 bSizer1.Add( self.m_panel2, 0, wx.EXPAND |wx.ALL, 5 )
71 self.m_panel1 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
73 fgSizer1 = wx.FlexGridSizer( 0, nb, 0, 0 )
74 fgSizer1.SetFlexibleDirection( wx.BOTH )
75 fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
78 for val in parametres :
79 fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[0], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
80 #fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
81 txtctrl.append( wx.TextCtrl( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, (450, 20), wx.TE_READONLY ) )
82 txtctrl[-1].SetBackgroundColour('#DDE8EB')
83 #wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
84 fgSizer1.Add( txtctrl[-1], 0, wx.ALL|wx.EXPAND, 0)
85 #fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND |wx.ALL, 0)
86 #fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND|wx.ALL, 0)
88 self.m_panel1.SetSizer( fgSizer1 )
89 self.m_panel1.Layout()
90 fgSizer1.Fit( self.m_panel1 )
91 bSizer1.Add( self.m_panel1, 0, wx.EXPAND|wx.ALL, 3 )
93 m_sdbSizer1 = wx.StdDialogButtonSizer()
94 self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK )
95 m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
96 m_sdbSizer1.Realize();
98 bSizer1.Add( m_sdbSizer1, 0, wx.EXPAND, 5 )
101 self.SetSizer( bSizer1 )
105 self.Centre( wx.BOTH )
111 class LeftTree(CT.CustomTreeCtrl):
113 def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
115 style=wx.SUNKEN_BORDER|wx.WANTS_CHARS,
116 agwStyle=CT.TR_HIDE_ROOT|CT.TR_HAS_BUTTONS|CT.TR_HAS_VARIABLE_ROW_HEIGHT):
118 CT.CustomTreeCtrl.__init__(self, parent, id, pos, size, style, agwStyle)
124 if data.startswith("TR_"):
125 treestyles.append(data)
126 elif data.startswith("EVT_"):
131 self.styles = treestyles
135 self.il = wx.ImageList(16, 16)
137 for img in self.ira.images_analyses :
138 self.ild[img] = self.il.Add(self.ira.images_analyses[img])
139 self.SetImageList(self.il)
144 self.history = parent.history
145 self.h = self.history.history
146 self.root = self.AddRoot("Iramuteq")
148 if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
149 self.SetPyData(self.root, None)
150 self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal)
151 self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded)
153 self.textroot = self.AppendItem(self.root, _(u'Textual corpus'))
154 self.SetPyData(self.textroot, {'uuid': 'textroot'})
155 self.SetItemImage(self.textroot, self.ild['textroot'], CT.TreeItemIcon_Normal)
156 self.SetItemImage(self.textroot, self.ild['textroot'], CT.TreeItemIcon_Expanded)
158 for corpus in reversed(self.h) :
159 child = self.AppendItem(self.textroot, corpus['corpus_name'])
160 self.SetPyData(child, corpus)
161 self.SetItemImage(child, self.ild['corpus'], CT.TreeItemIcon_Normal)
162 self.SetItemImage(child, self.ild['corpus'], CT.TreeItemIcon_Expanded)
164 if 'analyses' in corpus :
165 for y in corpus['analyses'] :
166 last = self.AppendItem(child, y['name'], ct_type=0)
167 self.SetPyData(last, y)
168 if y['type'] in self.ild :
169 img = self.ild[y['type']]
172 self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
173 self.SetItemImage(last, img, CT.TreeItemIcon_Expanded)
175 self.matroot = self.AppendItem(self.root, _(u'Matrix'))
176 self.SetPyData(self.matroot, {'uuid': 'matroot'})
177 self.SetItemImage(self.matroot, self.ild['matroot'], CT.TreeItemIcon_Normal)
178 self.SetItemImage(self.matroot, self.ild['matroot'], CT.TreeItemIcon_Expanded)
181 for matrix in reversed(self.history.matrix) :
182 if 'matrix_name' in matrix :
183 child = self.AppendItem(self.matroot, matrix['matrix_name'])
184 self.SetPyData(child, matrix)
185 self.SetItemImage(child, self.ild['matrix'], CT.TreeItemIcon_Normal)
186 self.SetItemImage(child, self.ild['matrix'], CT.TreeItemIcon_Expanded)
187 if 'analyses' in matrix :
188 for y in matrix['analyses'] :
189 last = self.AppendItem(child, y['name'], ct_type=0)
190 self.SetPyData(last, y)
191 if y['type'] in self.ild :
192 img = self.ild[y['type']]
195 self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
196 self.SetItemImage(last, img, CT.TreeItemIcon_Expanded)
198 orphmat.append(matrix)
200 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
201 #self.Bind(wx.EVT_IDLE, self.OnIdle)
203 self.eventdict = {'EVT_TREE_BEGIN_DRAG': self.OnBeginDrag, 'EVT_TREE_BEGIN_LABEL_EDIT': self.OnBeginEdit,
204 'EVT_TREE_BEGIN_RDRAG': self.OnBeginRDrag, 'EVT_TREE_DELETE_ITEM': self.OnDeleteItem,
205 'EVT_TREE_END_DRAG': self.OnEndDrag, 'EVT_TREE_END_LABEL_EDIT': self.OnEndEdit,
206 'EVT_TREE_ITEM_ACTIVATED': self.OnActivate, 'EVT_TREE_ITEM_CHECKED': self.OnItemCheck,
207 'EVT_TREE_ITEM_CHECKING': self.OnItemChecking, 'EVT_TREE_ITEM_COLLAPSED': self.OnItemCollapsed,
208 'EVT_TREE_ITEM_COLLAPSING': self.OnItemCollapsing, 'EVT_TREE_ITEM_EXPANDED': self.OnItemExpanded,
209 'EVT_TREE_ITEM_EXPANDING': self.OnItemExpanding, 'EVT_TREE_ITEM_GETTOOLTIP': self.OnToolTip,
210 'EVT_TREE_ITEM_MENU': self.OnItemMenu, 'EVT_TREE_ITEM_RIGHT_CLICK': self.OnRightDown,
211 'EVT_TREE_KEY_DOWN': self.OnKey, 'EVT_TREE_SEL_CHANGED': self.OnSelChanged,
212 'EVT_TREE_SEL_CHANGING': self.OnSelChanging, "EVT_TREE_ITEM_HYPERLINK": self.OnHyperLink}
214 mainframe = wx.GetTopLevelParent(self)
216 if not hasattr(mainframe, "leftpanel"):
217 #self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded)
218 #self.Bind(CT.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed)
219 self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
220 self.Bind(CT.EVT_TREE_SEL_CHANGING, self.OnSelChanging)
221 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
222 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
224 for combos in mainframe.treeevents:
225 self.BindEvents(combos)
227 if hasattr(mainframe, "leftpanel"):
228 self.ChangeStyle(mainframe.treestyles)
230 if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
231 self.SelectItem(self.root)
232 self.Expand(self.root)
235 def BindEvents(self, choice, recreate=False):
237 value = choice.GetValue()
238 text = choice.GetLabel()
241 binder = self.eventdict[text]
244 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
245 self.Bind(wx.EVT_RIGHT_DOWN, None)
246 self.Bind(wx.EVT_RIGHT_UP, None)
247 self.Bind(eval(evt), binder)
249 self.Bind(eval(evt), None)
250 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
251 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
252 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
255 def ChangeStyle(self, combos):
259 if combo.GetValue() == 1:
260 style = style | eval("CT." + combo.GetLabel())
262 if self.GetAGWWindowStyleFlag() != style:
263 self.SetAGWWindowStyleFlag(style)
266 def OnCompareItems(self, item1, item2):
268 t1 = self.GetItemText(item1)
269 t2 = self.GetItemText(item2)
280 def OnIdle(self, event):
284 # if self.gauge.IsEnabled() and self.gauge.IsShown():
285 # self.count = self.count + 1
287 # if self.count >= 50:
290 # self.gauge.SetValue(self.count)
298 def CloseItem(self, itemParent = None, uuid = None) :
299 if itemParent is None :
300 itemParent = self.root
301 child, cookie = self.GetFirstChild(itemParent)
303 pydata = self.GetPyData(child)
304 if pydata['uuid'] == uuid :
305 self.SetItemBold(child, False)
307 self.CloseItem(child, uuid)
308 child, cookie = self.GetNextChild(itemParent, cookie)
310 def GiveFocus(self, itemParent = None, uuid = None, bold = False) :
311 if itemParent is None :
312 itemParent = self.root
313 child, cookie = self.GetFirstChild(itemParent)
315 pydata = self.GetPyData(child)
316 if pydata['uuid'] == uuid :
317 self.SelectItem(child)
319 self.SetItemBold(child, True)
321 self.GiveFocus(child, uuid, bold)
322 child, cookie = self.GetNextChild(itemParent, cookie)
324 def IsInTree(self, itemParent = None, uuid = None) :
325 if itemParent is None :
326 itemParent = self.root
327 child, cookie = self.GetFirstChild(itemParent)
330 pydata = self.GetPyData(child)
331 if pydata['uuid'] == uuid :
333 self.GiveFocus(child, uuid)
334 child, cookie = self.GetNextChild(itemParent, cookie)
338 def OnRightDown(self, event):
340 pt = event.GetPosition()
341 item, flags = self.HitTest(pt)
345 #self.log.info("OnRightClick: %s, %s, %s" % (self.GetItemText(item), type(item), item.__class__) + "\n")
346 self.SelectItem(item)
349 def OnRightUp(self, event):
357 if not self.IsItemEnabled(item):
361 # Item Text Appearance
362 ishtml = self.IsItemHyperText(item)
363 back = self.GetItemBackgroundColour(item)
364 fore = self.GetItemTextColour(item)
365 isbold = self.IsBold(item)
366 font = self.GetItemFont(item)
369 normal = self.GetItemImage(item, CT.TreeItemIcon_Normal)
370 selected = self.GetItemImage(item, CT.TreeItemIcon_Selected)
371 expanded = self.GetItemImage(item, CT.TreeItemIcon_Expanded)
372 selexp = self.GetItemImage(item, CT.TreeItemIcon_SelectedExpanded)
374 # Enabling/Disabling Windows Associated To An Item
375 haswin = self.GetItemWindow(item)
377 # Enabling/Disabling Items
378 enabled = self.IsItemEnabled(item)
380 # Generic Item's Info
381 children = self.GetChildrenCount(item)
382 itemtype = self.GetItemType(item)
383 text = self.GetItemText(item)
384 pydata = self.GetPyData(item)
388 self.itemdict = {"ishtml": ishtml, "back": back, "fore": fore, "isbold": isbold,
389 "font": font, "normal": normal, "selected": selected, "expanded": expanded,
390 "selexp": selexp, "haswin": haswin, "children": children,
391 "itemtype": itemtype, "text": text, "pydata": pydata, "enabled": enabled}
393 if not item in [self.textroot, self.matroot] :
395 info = wx.MenuItem(menu, wx.ID_ANY, _(u"Informations").decode('utf8'))
396 info.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_INFORMATION, size = (16,16)))
397 menu.AppendItem(info)
399 rename = wx.MenuItem(menu, wx.ID_ANY, _(u"Rename").decode('utf8'))
400 rename.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_TIP, size = (16,16)))
401 menu.AppendItem(rename)
402 menu.AppendSeparator()
404 if 'corpus_name' in pydata :
405 buildmenu(menu, self.parent.text_menu)
406 menu.AppendSeparator()
407 elif 'matrix_name' in pydata :
408 buildmenu(menu, self.parent.matrix_menu)
409 menu.AppendSeparator()
410 elif pydata.get('type', False) == 'alceste' and pydata['uuid'] in self.parent.history.opened :
412 antipro = openmenu.Append(wx.ID_ANY, _(u"Antiprofiles").decode('utf8'))
413 menu.AppendMenu(wx.ID_ANY, _(u"Open ...").decode('utf8'), openmenu)
415 profsr = menu.Append(wx.ID_ANY, _(u"Repeated segments profiles").decode('utf8'))
416 profgram = menu.Append(wx.ID_ANY, _(u"POS profiles").decode('utf8'))
417 tgen = menu.Append(wx.ID_ANY, _(u"Tgen Editor").decode('utf8'))
418 computetgen = menu.Append(wx.ID_ANY, _(u"Compute Tgen").decode('utf8'))
419 export_corpus = menu.Append(wx.ID_ANY, _(u"Export corpus").decode('utf8'))
420 colored = menu.Append(wx.ID_ANY, _(u"Colored corpus").decode('utf8'))
421 navig = menu.Append(wx.ID_ANY, _(u"Navigator").decode('utf8'))
422 statclasse = menu.Append(wx.ID_ANY, _(u"Clusters statistics").decode('utf8'))
423 rapport = menu.Append(wx.ID_ANY, _(u"Report").decode('utf8'))
424 export_classes = menu.Append(wx.ID_ANY, _(u"Export clusters").decode('utf8'))
425 subcorpusfromcl = menu.Append(wx.ID_ANY, _(u"Sub corpus from clusters").decode('utf8'))
426 menu.AppendSeparator()
427 self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
428 self.Bind(wx.EVT_MENU, self.OnProfSR, profsr)
429 self.Bind(wx.EVT_MENU, self.OnProfGram, profgram)
430 self.Bind(wx.EVT_MENU, self.OnTgenEditor, tgen)
431 self.Bind(wx.EVT_MENU, self.OnTgenCompute, computetgen)
432 self.Bind(wx.EVT_MENU, self.OnExportCorpus, export_corpus)
433 self.Bind(wx.EVT_MENU, self.OnColored, colored)
434 self.Bind(wx.EVT_MENU, self.OnNavig, navig)
435 self.Bind(wx.EVT_MENU, self.StatClasse, statclasse)
436 self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
437 self.Bind(wx.EVT_MENU, self.OnExportClasses, export_classes)
438 self.Bind(wx.EVT_MENU, self.OnSubCorpusFromClusters, subcorpusfromcl)
439 elif pydata.get('type', False) == 'stat' and pydata['uuid'] in self.parent.history.opened :
440 export_dictionary = menu.Append(wx.ID_ANY, _(u"Export dictionary").decode('utf8'))
441 export_lems = menu.Append(wx.ID_ANY, _(u"Export lemma dictionary").decode('utf8'))
442 self.Bind(wx.EVT_MENU, self.OnExportDictionary, export_dictionary)
443 self.Bind(wx.EVT_MENU, self.OnExportLems, export_lems)
444 menu.AppendSeparator()
445 elif pydata.get('type', False) == 'spec' and pydata['uuid'] in self.parent.history.opened :
446 tgen = menu.Append(wx.ID_ANY, _(u"Tgen Editor").decode('utf8'))
447 computetgen = menu.Append(wx.ID_ANY, _(u"Compute Tgen").decode('utf8'))
448 self.Bind(wx.EVT_MENU, self.OnTgenEditor, tgen)
449 self.Bind(wx.EVT_MENU, self.OnTgenCompute, computetgen)
450 menu.AppendSeparator()
451 elif pydata.get('type', False) == 'reinertmatrix' and pydata['uuid'] in self.parent.history.opened :
453 antipro = openmenu.Append(wx.ID_ANY, _(u"antiprofiles").decode('utf8'))
454 rapport = menu.Append(wx.ID_ANY, _(u"Report").decode('utf8'))
455 menu.AppendMenu(wx.ID_ANY, _(u"Open ...").decode('utf8'), openmenu)
456 self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
457 self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
459 itemdelete = wx.MenuItem(menu, wx.ID_ANY, _(u"Delete from history").decode('utf8'))
460 itemdelete.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_DELETE, size = (16,16)))
461 menu.AppendItem(itemdelete)
462 #item11 = menu.Append(wx.ID_ANY, "Prepend An Item")
463 #item12 = menu.Append(wx.ID_ANY, "Append An Item")
465 #self.Bind(wx.EVT_MENU, self.OnItemBackground, item1)
466 #self.Bind(wx.EVT_MENU, self.OnItemForeground, item2)
467 #self.Bind(wx.EVT_MENU, self.OnItemBold, item3)
468 #self.Bind(wx.EVT_MENU, self.OnItemFont, item4)
469 #self.Bind(wx.EVT_MENU, self.OnItemHyperText, item5)
470 #self.Bind(wx.EVT_MENU, self.OnEnableWindow, item6)
471 #self.Bind(wx.EVT_MENU, self.OnDisableItem, item7)
472 #self.Bind(wx.EVT_MENU, self.OnItemIcons, item8)
473 self.Bind(wx.EVT_MENU, self.OnItemInfo, info)
474 self.Bind(wx.EVT_MENU, self.OnRename, rename)
475 self.Bind(wx.EVT_MENU, self.OnItemDelete, itemdelete)
476 #self.Bind(wx.EVT_MENU, self.OnItemPrepend, item11)
477 #self.Bind(wx.EVT_MENU, self.OnItemAppend, item12)
483 busy = wx.BusyInfo(_("Please wait...Reading corpus").decode('utf8'), self.parent)
485 if self.pydata['uuid'] in self.parent.history.openedcorpus :
486 corpus = copycorpus(self.parent.history.openedcorpus[self.pydata['uuid']])
487 elif 'corpus_name' in self.pydata :
488 corpus = Corpus(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('corpus'), read = True)
490 cuuid = self.pydata['corpus']
491 if cuuid in self.parent.history.openedcorpus :
492 corpus = copycorpus(self.parent.history.openedcorpus[cuuid])
494 irapath = self.parent.history.corpus[cuuid]['ira']
495 corpus = Corpus(self.parent, parametres = DoConf(irapath).getoptions('corpus'), read = True)
500 if 'matrix_name' in self.pydata :
501 matrix = Tableau(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('matrix'))
503 return copymatrix(matrix)
505 cuuid = self.pydata['matrix']
506 matrix = Tableau(self.parent, parametres = DoConf(self.history.matrixanalyse[cuuid]['ira']).getoptions('matrix'))
508 return copymatrix(matrix)
510 def OnSpec(self, evt) :
511 self.parent.OnTextSpec(evt, self.getcorpus())
513 def OnStat(self, evt) :
514 self.parent.OnTextStat(evt, self.getcorpus())
516 def OnReinert(self, evt) :
517 self.parent.OnTextReinert(evt, self.getcorpus())
519 def OnPam(self, evt) :
520 self.parent.OnPamSimple(evt, self.getcorpus())
522 def OnSimiTxt(self, evt) :
523 self.parent.OnSimiTxt(evt, self.getcorpus())
525 def OnWordCloud(self, evt) :
526 self.parent.OnWordCloud(evt, self.getcorpus())
528 # def OnFreq(self, evt):
529 # self.parent.OnFreq(evt, self.getmatrix())
531 # def OnChiSquare(self, evt):
532 # self.parent.OnChi2(evt, self.getmatrix())
534 # def OnSimiTab(self, evt):
535 # self.parent.OnSimiTab(evt, self.getmatrix())
537 # def OnProto(self, evt):
538 # self.parent.OnProto(evt, self.getmatrix())
540 # def OnSplitFromVar(self, evt):
541 # self.parent.OnSplitVar(evt, self.getmatrix())
543 # def OnCHDReinert(self, evt):
544 # self.parent.OnCHDReinert(evt, self.getmatrix())
546 #def OnSubTextFromMeta(self, evt):
547 # self.parent.OnSubText(self.getcorpus(), parametres = {'frommeta' : True})
549 #def OnSubTextFromTheme(self, evt):
550 # self.parent.OnSubText(self.getcorpus(), parametres = {'fromtheme' : True})
552 def OnProfSR(self, evt) :
553 ProfileSegment(self.parent, self.page.dictpathout, self.page.parametres, self.page.corpus)
555 def OnProfGram(self, evt) :
556 ProfilType(self.parent, self.page.corpus, self.page.parametres)
558 def OnExportCorpus(self, evt) :
559 dial = PrefExport(self, self.parent)
560 dial.fbb.SetValue(os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'export_corpus.txt'))
561 dial.CenterOnParent()
562 res = dial.ShowModal()
564 if dial.radio_type.GetSelection() == 0 : alc = True
566 if dial.radio_lem.GetSelection() == 0 : lem = True
568 if self.page.parametres['classif_mode'] != 2 :
572 self.page.corpus.export_corpus_classes(dial.fbb.GetValue(), alc = alc, lem = lem, uci = uci)
575 dlg = wx.MessageDialog(self.parent, msg, u"Export", wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
580 def OnColored(self, evt) :
581 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.html', 'title': _(u"Colored corpus").decode('utf8')})
582 dial.fbb.SetValue(os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'corpus_couleur.html'))
583 dial.CenterOnParent()
584 res = dial.ShowModal()
586 fileout = dial.fbb.GetValue()
588 if self.page.parametres['classif_mode'] != 2 :
592 txt = self.page.corpus.make_colored_corpus(uci = uci)
593 with open(fileout, 'w') as f :
595 msg = ' !\n'.join([_(u"Done").decode('utf8'), _(u"Open in a web browser ?").decode('utf8')])
596 dlg = wx.MessageDialog(self.parent, msg, u"Corpus en couleur", wx.NO | wx.YES | wx.NO_DEFAULT | wx.ICON_QUESTION)
598 if dlg.ShowModal() == wx.ID_YES :
599 webbrowser.open(fileout)
602 def OnNavig(self, evt):
603 if 'FrameSearch' not in dir(self.page) :
604 self.page.FrameSearch = SearchFrame(self.parent, -1, _(u"Search ...").decode('utf8'), self.page.corpus)
605 self.page.FrameSearch.Show()
607 def StatClasse(self, evt):
608 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.csv', 'title': _(u"Clusters statistics").decode('utf8')})
609 dial.fbb.SetValue( os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'stat_par_classe.csv'))
610 dial.CenterOnParent()
611 res = dial.ShowModal()
613 fileout = dial.fbb.GetValue()
615 self.page.corpus.get_stat_by_cluster(fileout)
617 dlg = wx.MessageDialog(self.parent, msg, _(u"Clusters statistics").decode('utf8'), wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
619 if dlg.ShowModal() == wx.ID_OK :
622 def OpenAntipro(self, evt) :
624 for i in range(0, self.page.TabChdSim.GetPageCount()) :
625 page = self.page.TabChdSim.GetPage(i)
626 if self.page.TabChdSim.GetPageText(i) == _(u"Antiprofiles").decode('utf8') :
627 self.page.TabChdSim.SetSelection(i)
631 open_antiprofil(self.page, self.page.dictpathout['ANTIPRO_OUT'], self.parent.syscoding)
632 self.page.TabChdSim.SetSelection(self.page.TabChdSim.GetPageCount() - 1)
634 def OnRapport(self, evt) :
635 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.txt', 'title': _(u"Report").decode('utf8')})
636 dial.fbb.SetValue(self.page.dictpathout['rapport'])
637 dial.CenterOnParent()
638 res = dial.ShowModal()
640 fileout = dial.fbb.GetValue()
642 with open(fileout, 'w') as f :
643 f.write(self.page.debtext + '\n' + GetTxtProfile(self.page.DictProfile, self.page.cluster_size))
645 dlg = wx.MessageDialog(self.parent, msg, _(u"Report").decode('utf8'), wx.OK | wx.NO_DEFAULT | wx.ICON_INFORMATION)
652 def OnExportDictionary(self, evt) :
653 corpus = self.page.corpus
654 corpus.export_dictionary(self.page.pathout['dictionary.csv'], self.parent.syscoding)
655 log.info('export dictionary %s' % self.page.pathout['dictionary.csv'])
656 dial = wx.MessageDialog(self.parent, self.page.pathout['dictionary.csv'], 'Export', wx.OK)
660 def OnExportLems(self, evt) :
661 corpus = self.page.corpus
662 corpus.export_lems(self.page.pathout['lemmes.csv'], self.parent.syscoding)
663 log.info('export lemmes %s' % self.page.pathout['lemmes.csv'])
664 dial = wx.MessageDialog(self.parent, self.page.pathout['lemmes.csv'], 'Export', wx.OK)
668 def OnTgenEditor(self, evt):
669 corpus = self.page.corpus
670 tgenpath = os.path.join(self.page.parametres['pathout'], 'tgen.csv')
671 tgen = TGen(path = tgenpath, encoding = self.parent.syscoding)
672 if os.path.exists(tgenpath) :
674 if isinstance(evt, list) :
676 while 'tgen%i' %i in tgen.tgen :
678 tgenname = 'tgen%i' %i
679 tgen.tgen[tgenname] = evt
680 tgenframe = TGenFrame(self.parent, corpus, tgen)
682 if isinstance(evt, list) :
683 tgenframe.OnNewTgen(None, tgen = tgenname)
685 def OnTgenCompute(self, evt):
686 corpus = self.page.corpus
687 tgenpath = os.path.join(self.page.parametres['pathout'], 'tgen.csv')
688 if not os.path.exists(tgenpath) :
689 message = wx.MessageDialog(self.parent, _(u"No TGen yet !"), style = wx.ICON_EXCLAMATION | wx.OK)
693 self.page.parametres['tgenpath'] = tgenpath
694 tgen = TGen(path = tgenpath, encoding = self.parent.syscoding)
695 if self.page.parametres['type'] == 'spec' :
696 self.page.parametres['etoiles'] = self.page.etoiles
697 TgenSpec(self.parent, corpus, self.page.parametres)
698 elif self.page.parametres['type'] == 'alceste' :
699 TgenProf(self.parent, corpus, self.page.parametres, self.page.cluster_size)
700 TgenLayout(self.page)
702 def OnExportClasses(self, event):
703 corpus = self.page.corpus
704 if self.page.parametres['classif_mode'] != 2 :
708 busy = wx.BusyInfo(_("Please wait...").decode('utf8'), self.parent)
710 for i in range(1, self.page.parametres['clnb'] + 1) :
711 corpus.export_classe(self.page.pathout['classe_%i_export.txt' % i], i, uci = uci)
713 dial = wx.MessageDialog(self, self.page.pathout['classe_x_export.txt'], u"Export", wx.OK|wx.ICON_INFORMATION)
717 def OnSubCorpusFromClusters(self, evt):
718 self.parent.OnSubText(evt, corpus = self.getcorpus(), parametres = {'fromclusters' : True, 'clnb': self.page.parametres['clnb'], 'lc' : self.page.corpus.lc})
720 def OnRename(self, event):
721 pydata = self.itemdict['pydata']
722 if 'matrix_name' in pydata :
724 elif 'corpus_name' in pydata :
728 oldname = pydata[name]
729 dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', oldname)
730 if dlg.ShowModal() == wx.ID_OK:
731 newname = dlg.GetValue()
733 pydata[name] = newname
734 Totconf = DoConf(configfile=pydata['ira'])
735 conf = Totconf.getoptions()
737 Totconf.makeoptions(Totconf.getsections(), [conf])
738 self.history.update(pydata)
739 self.SetItemText(self.current, newname)
740 self.EnsureVisible(self.current)
742 def OnItemBackground(self, event):
744 colourdata = wx.ColourData()
745 colourdata.SetColour(self.itemdict["back"])
746 dlg = wx.ColourDialog(self, colourdata)
748 dlg.GetColourData().SetChooseFull(True)
750 if dlg.ShowModal() == wx.ID_OK:
751 data = dlg.GetColourData()
752 col1 = data.GetColour().Get()
753 self.SetItemBackgroundColour(self.current, col1)
757 def OnItemForeground(self, event):
759 colourdata = wx.ColourData()
760 colourdata.SetColour(self.itemdict["fore"])
761 dlg = wx.ColourDialog(self, colourdata)
763 dlg.GetColourData().SetChooseFull(True)
765 if dlg.ShowModal() == wx.ID_OK:
766 data = dlg.GetColourData()
767 col1 = data.GetColour().Get()
768 self.SetItemTextColour(self.current, col1)
772 def OnItemBold(self, event):
774 self.SetItemBold(self.current, not self.itemdict["isbold"])
777 def OnItemFont(self, event):
780 font = self.itemdict["font"]
783 font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
785 data.SetInitialFont(font)
787 dlg = wx.FontDialog(self, data)
789 if dlg.ShowModal() == wx.ID_OK:
790 data = dlg.GetFontData()
791 font = data.GetChosenFont()
792 self.SetItemFont(self.current, font)
797 def OnItemHyperText(self, event):
799 self.SetItemHyperText(self.current, not self.itemdict["ishtml"])
802 def OnEnableWindow(self, event):
804 enable = self.GetItemWindowEnabled(self.current)
805 self.SetItemWindowEnabled(self.current, not enable)
808 def OnDisableItem(self, event):
810 self.EnableItem(self.current, False)
813 def OnItemIcons(self, event):
815 bitmaps = [self.itemdict["normal"], self.itemdict["selected"],
816 self.itemdict["expanded"], self.itemdict["selexp"]]
819 dlg = TreeIcons(self, -1, bitmaps=bitmaps)
824 def SetNewIcons(self, bitmaps):
826 self.SetItemImage(self.current, bitmaps[0], CT.TreeItemIcon_Normal)
827 self.SetItemImage(self.current, bitmaps[1], CT.TreeItemIcon_Selected)
828 self.SetItemImage(self.current, bitmaps[2], CT.TreeItemIcon_Expanded)
829 self.SetItemImage(self.current, bitmaps[3], CT.TreeItemIcon_SelectedExpanded)
832 def OnItemInfo(self, event):
834 itemtext = self.itemdict["text"]
835 numchildren = str(self.itemdict["children"])
836 itemtype = self.itemdict["itemtype"]
837 pydata = self.itemdict['pydata']
838 #if 'analyses' in pydata :
839 # toshow = dict([[val, pydata[val]] for val in pydata if val not in['analyses', 'isload']])
841 toshow = pydata['ira']
842 toshow = DoConf(toshow).getoptions()
843 txt = DoConf().totext(toshow)
844 parametres = [val.split('\t\t:') for val in txt.splitlines()]
850 itemtype = "CheckBox"
852 itemtype = "RadioButton"
854 dlg = InfoDialog(self, itemtext, parametres)
861 def OnItemDelete(self, event):
863 strs = "Are You Sure You Want To Delete Item " + self.GetItemText(self.current) + "?"
864 dlg = wx.MessageDialog(None, strs, 'Deleting Item', wx.OK | wx.CANCEL | wx.ICON_QUESTION)
866 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
872 pydata = self.itemdict['pydata']
873 if 'corpus_name' in pydata :
874 self.history.delete(pydata, True)
876 self.history.delete(pydata)
877 self.DeleteChildren(self.current)
878 self.Delete(self.current)
883 def OnItemPrepend(self, event):
885 dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
887 if dlg.ShowModal() == wx.ID_OK:
888 newname = dlg.GetValue()
889 newitem = self.PrependItem(self.current, newname)
890 self.EnsureVisible(newitem)
894 def AddAnalyse(self, parametres, itemParent = None, bold = True) :
895 uuid = parametres.get('corpus', None)
896 if uuid is not None :
897 if itemParent is None :
898 itemParent = self.textroot
899 child, cookie = self.GetFirstChild(itemParent)
902 pydata = self.GetPyData(child)
903 if pydata['uuid'] == uuid :
906 self.GiveFocus(child, uuid)
907 child, cookie = self.GetNextChild(itemParent, cookie)
908 #item = self.AppendItem(child, parametres['name'])
909 if corpus is not None :
910 item = self.AppendItem(corpus, parametres['name'])
912 item = self.AppendItem(self.textroot, parametres['name'])
914 item = self.AppendItem(self.matroot, parametres['name'])
915 self.SetPyData(item, parametres)
916 if parametres['type'] in self.ild :
917 img = self.ild[parametres['type']]
920 self.SetItemImage(item, img, CT.TreeItemIcon_Normal)
921 self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
922 self.SetItemBold(item, bold)
923 self.SelectItem(item)
925 def AddMatAnalyse(self, parametres, itemParent = None, bold = True) :
926 uuid = parametres.get('matrix', None)
927 if uuid is not None :
928 if itemParent is None :
929 itemParent = self.matroot
930 child, cookie = self.GetFirstChild(itemParent)
933 pydata = self.GetPyData(child)
934 if pydata['uuid'] == uuid :
937 self.GiveFocus(child, uuid)
938 child, cookie = self.GetNextChild(itemParent, cookie)
939 #item = self.AppendItem(child, parametres['name'])
940 if matrix is not None :
941 item = self.AppendItem(matrix, parametres['name'])
943 item = self.AppendItem(self.matroot, parametres['name'])
944 self.SetPyData(item, parametres)
945 if parametres['type'] in self.ild :
946 img = self.ild[parametres['type']]
949 self.SetItemImage(item, img, CT.TreeItemIcon_Normal)
950 self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
951 self.SetItemBold(item, bold)
952 self.SelectItem(item)
954 def OnItemAppend(self, item, select = True):
955 if 'corpus_name' in item :
956 child = self.InsertItem(self.textroot, 0, item['corpus_name'])
958 child = self.InsertItem(self.matroot, 0, item['matrix_name'])
959 self.SetPyData(child, item)
960 if item['type'] in self.ild :
961 img = self.ild[item['type']]
964 self.SetItemImage(child, img, CT.TreeItemIcon_Normal)
965 self.SetItemImage(child, img, CT.TreeItemIcon_Expanded)
967 self.history.addtab(item)
968 self.SetItemBold(child, True)
969 self.SelectItem(child)
971 #dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
973 #if dlg.ShowModal() == wx.ID_OK:
974 # newname = dlg.GetValue()
975 # newitem = self.AppendItem(self.current, newname)
976 # self.EnsureVisible(newitem)
982 def OnBeginEdit(self, event):
984 #self.log.info("OnBeginEdit" + "\n")
985 # show how to prevent edit...
986 item = event.GetItem()
987 if item and self.GetItemText(item) == "The Root Item":
989 #self.log.info("You can't edit this one..." + "\n")
991 # Lets just see what's visible of its children
993 root = event.GetItem()
994 (child, cookie) = self.GetFirstChild(root)
997 #self.log.info("Child [%s] visible = %d" % (self.GetItemText(child), self.IsVisible(child)) + "\n")
998 (child, cookie) = self.GetNextChild(root, cookie)
1003 def OnEndEdit(self, event):
1005 #self.log.info("OnEndEdit: %s %s" %(event.IsEditCancelled(), event.GetLabel()))
1006 # show how to reject edit, we'll not allow any digits
1007 for x in event.GetLabel():
1008 if x in string.digits:
1009 #self.log.info(", You can't enter digits..." + "\n")
1016 def OnLeftDClick(self, event):
1017 pt = event.GetPosition()
1018 item, flags = self.HitTest(pt)
1019 if item is not None :
1020 pydata = self.GetPyData(item)
1021 if pydata['uuid'] in self.parent.history.opened :
1022 for i in range(self.parent.nb.GetPageCount()) :
1023 page = self.parent.nb.GetPage(i)
1024 if 'parametres' in dir(page) :
1025 if page.parametres['uuid'] == pydata['uuid'] :
1026 self.parent.nb.SetSelection(i)
1028 elif pydata['uuid'] in ['textroot', 'matroot'] :
1031 if os.path.exists(pydata['ira']) :
1032 busy = wx.BusyInfo(_("Please wait..."), self.parent)
1035 OpenAnalyse(self.parent, pydata)
1037 self.SetItemBold(item, True)
1038 self.OnSelChanged(pydata = pydata)
1043 wx.MessageBox(_(u"This file does not exist : %s" % pydata['ira']).decode('utf8'), 'Information', wx.ICON_EXCLAMATION | wx.STAY_ON_TOP )
1044 #if item and (flags & CT.TREE_HITTEST_ONITEMLABEL):
1045 # if self.GetAGWWindowStyleFlag() & CT.TR_EDIT_LABELS:
1046 # self.log.info("OnLeftDClick: %s (manually starting label edit)"% self.GetItemText(item) + "\n")
1048 #self.EditLabel(item)
1050 # pydata = self.GetPyData(item)
1052 # self.log.info("OnLeftDClick: Cannot Start Manual Editing, Missing Style TR_EDIT_LABELS\n")
1057 def OnItemExpanded(self, event):
1059 item = event.GetItem()
1061 self.log.info("OnItemExpanded: %s" % self.GetItemText(item) + "\n")
1064 def OnItemExpanding(self, event):
1066 item = event.GetItem()
1068 self.log.info("OnItemExpanding: %s" % self.GetItemText(item) + "\n")
1073 def OnItemCollapsed(self, event):
1075 item = event.GetItem()
1077 self.log.info("OnItemCollapsed: %s" % self.GetItemText(item) + "\n")
1080 def OnItemCollapsing(self, event):
1082 item = event.GetItem()
1084 self.log.info("OnItemCollapsing: %s" % self.GetItemText(item) + "\n")
1089 def OnSelChanged(self, event = None, pydata = None):
1090 if event is not None :
1091 item = event.GetItem()
1092 pydata = self.GetPyData(item)
1094 if pydata is not None :
1095 if 'corpus_name' in pydata or 'corpus' in pydata :
1096 self.ira.ShowMenu('matrix', False)
1097 self.ira.ShowMenu('text', True)
1098 if 'matrix_name' in pydata or 'matrix' in pydata:
1099 self.ira.ShowMenu('text', False)
1100 self.ira.ShowMenu('matrix', True)
1101 if 'uuid' in pydata :
1102 if pydata['uuid'] in ['textroot', 'matroot'] :
1103 self.ira.ShowMenu('text', False)
1104 self.ira.ShowMenu('matrix', False)
1105 self.pydata = pydata
1106 if pydata['uuid'] in self.parent.history.opened :
1107 for i in range(self.parent.nb.GetPageCount()) :
1108 self.page = self.parent.nb.GetPage(i)
1109 if 'parametres' in dir(self.page) :
1110 if self.page.parametres['uuid'] == pydata['uuid'] :
1111 self.parent.nb.SetSelection(i)
1113 if event is not None :
1117 def OnSelChanging(self, event):
1119 item = event.GetItem()
1120 olditem = event.GetOldItem()
1124 olditemtext = "None"
1126 olditemtext = self.GetItemText(olditem)
1127 #self.log.info("OnSelChanging: From %s" % olditemtext + " To %s" % self.GetItemText(item) + "\n")
1132 def OnBeginDrag(self, event):
1134 self.item = event.GetItem()
1136 self.log.info("Beginning Drag..." + "\n")
1141 def OnBeginRDrag(self, event):
1143 self.item = event.GetItem()
1145 self.log.info("Beginning Right Drag..." + "\n")
1150 def OnEndDrag(self, event):
1152 self.item = event.GetItem()
1154 self.log.info("Ending Drag!" + "\n")
1159 def OnDeleteItem(self, event):
1161 item = event.GetItem()
1166 self.log.info("Deleting Item: %s" % self.GetItemText(item) + "\n")
1170 def OnItemCheck(self, event):
1172 item = event.GetItem()
1173 self.log.info("Item " + self.GetItemText(item) + " Has Been Checked!\n")
1177 def OnItemChecking(self, event):
1179 item = event.GetItem()
1180 self.log.info("Item " + self.GetItemText(item) + " Is Being Checked...\n")
1184 def OnToolTip(self, event):
1186 item = event.GetItem()
1188 event.SetToolTip(wx.ToolTip(self.GetItemText(item)))
1191 def OnItemMenu(self, event):
1193 item = event.GetItem()
1195 self.log.info("OnItemMenu: %s" % self.GetItemText(item) + "\n")
1200 def OnKey(self, event):
1202 keycode = event.GetKeyCode()
1203 keyname = keyMap.get(keycode, None)
1205 if keycode == wx.WXK_BACK:
1206 self.log.info("OnKeyDown: HAHAHAHA! I Vetoed Your Backspace! HAHAHAHA\n")
1210 if "unicode" in wx.PlatformInfo:
1211 keycode = event.GetUnicodeKey()
1213 keycode = event.GetKeyCode()
1214 keyname = "\"" + unichr(event.GetUnicodeKey()) + "\""
1216 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1222 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1224 keyname = "\"%s\"" % chr(keycode)
1226 keyname = "unknown (%s)" % keycode
1228 self.log.info("OnKeyDown: You Pressed '" + keyname + "'\n")
1233 def OnActivate(self, event):
1236 self.log.info("OnActivate: %s" % self.GetItemText(self.item) + "\n")
1241 def OnHyperLink(self, event):
1243 item = event.GetItem()
1245 self.log.info("OnHyperLink: %s" % self.GetItemText(self.item) + "\n")
1248 def OnTextCtrl(self, event):
1250 char = chr(event.GetKeyCode())
1251 self.log.info("EDITING THE TEXTCTRL: You Wrote '" + char + \
1252 "' (KeyCode = " + str(event.GetKeyCode()) + ")\n")
1256 def OnComboBox(self, event):
1258 selection = event.GetEventObject().GetValue()
1259 self.log.info("CHOICE FROM COMBOBOX: You Chose '" + selection + "'\n")