1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
17 #------------------------------------
18 # import des modules wx
19 #------------------------------------
21 import wx.lib.agw.customtreectrl as CT
23 #------------------------------------
24 # import des fichiers du projet
25 #------------------------------------
26 from openanalyse import OpenAnalyse
27 from corpus import Corpus, copycorpus
28 from tableau import Tableau, copymatrix
29 from functions import DoConf, GetTxtProfile, TGen, BugReport, open_folder, translateprofile, ReadProfileAsDico, write_translation_profile, progressbar, doconcorde
30 from profile_segment import ProfileSegment, ProfilType
31 from search_tools import SearchFrame
32 from dialog import PrefSimpleFile, PrefExport, SearchCorpus, translate_dialog, PrefUCECarac
33 from layout import open_antiprofil, TgenLayout
34 from guifunct import TGenFrame
35 from textaslexico import TgenSpec
36 from textreinert import TgenProf
37 from mergeclustergraph import MergeClusterGraph
40 log = logging.getLogger('iramuteq.tree')
43 def buildmenu(menu, parent_menu):
44 for i in range(parent_menu.GetMenuItemCount()) :
45 item = parent_menu.FindItemByPosition(i)
47 itemtext = item.GetItemLabelText()
48 itemicon = item.GetBitmap()
49 nitem = wx.MenuItem(menu, itemid, itemtext)
50 nitem.SetBitmap(itemicon)
53 for val in item.GetSubMenu().GetMenuItems() :
55 itemtext = val.GetItemLabelText()
56 itemicon = val.GetBitmap()
57 nitem = wx.MenuItem(menu, itemid, itemtext)
58 nitem.SetBitmap(itemicon)
60 menu.Append(-1, item.GetItemLabelText(), nmenu)
65 class InfoDialog ( wx.Dialog ):
67 def __init__( self, parent, txt, parametres ):
68 wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = "Informations", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
69 if len(parametres) > 30 :
73 self.SetSizeHints( wx.Size( 500,200 ), wx.DefaultSize )
74 bSizer1 = wx.BoxSizer( wx.VERTICAL )
75 self.m_panel2 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
76 bSizer2 = wx.BoxSizer( wx.VERTICAL )
77 self.m_staticText4 = wx.StaticText( self.m_panel2, wx.ID_ANY, txt, wx.DefaultPosition, wx.DefaultSize, 0 )
78 self.m_staticText4.Wrap( -1 )
79 bSizer2.Add( self.m_staticText4, 0, wx.ALL, 5 )
80 self.m_panel2.SetSizer( bSizer2 )
81 self.m_panel2.Layout()
82 bSizer2.Fit( self.m_panel2 )
83 bSizer1.Add( self.m_panel2, 0, wx.EXPAND |wx.ALL, 5 )
84 self.m_panel1 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL|wx.VSCROLL )
85 fgSizer1 = wx.FlexGridSizer( 0, nb, 0, 0 )
86 fgSizer1.AddGrowableCol( 1 )
88 fgSizer1.AddGrowableCol( 3 )
89 fgSizer1.SetFlexibleDirection( wx.BOTH )
90 fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_NONE )
92 for val in parametres :
93 fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[0], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
94 #fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
95 txtctrl.append( wx.TextCtrl( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, (450, 20), wx.TE_READONLY ) )
96 txtctrl[-1].SetBackgroundColour('#DDE8EB')
97 #wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
98 fgSizer1.Add( txtctrl[-1], 0, wx.ALL|wx.EXPAND, 0)
99 #fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND |wx.ALL, 0)
100 #fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND|wx.ALL, 0)
101 self.m_panel1.SetSizer( fgSizer1 )
102 self.m_panel1.Layout()
103 fgSizer1.Fit( self.m_panel1 )
104 bSizer1.Add( self.m_panel1, 1, wx.EXPAND|wx.ALL, 3 )
105 m_sdbSizer1 = wx.StdDialogButtonSizer()
106 self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK )
107 m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
108 m_sdbSizer1.Realize();
109 bSizer1.Add( m_sdbSizer1, 0, wx.EXPAND, 5 )
110 self.SetSizer( bSizer1 )
113 self.Centre( wx.BOTH )
119 class LeftTree(CT.CustomTreeCtrl):
121 def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
123 style=wx.SUNKEN_BORDER|wx.WANTS_CHARS,
124 agwStyle=CT.TR_HIDE_ROOT|CT.TR_HAS_BUTTONS|CT.TR_HAS_VARIABLE_ROW_HEIGHT):
125 CT.CustomTreeCtrl.__init__(self, parent, id, pos, size, style, agwStyle)
133 if data.startswith("TR_"):
134 treestyles.append(data)
135 elif data.startswith("EVT_"):
139 font = wx.Font(pointSize=self.ira.fontsize + 2, family=wx.FONTFAMILY_DEFAULT, style=wx.FONTSTYLE_NORMAL, weight=wx.FONTWEIGHT_NORMAL)
142 self.styles = treestyles
144 self.il = wx.ImageList(16, 16)
146 for img in self.ira.images_analyses :
147 self.ild[img] = self.il.Add(self.ira.images_analyses[img])
148 self.SetImageList(self.il)
151 self.history = parent.history
152 self.h = self.history.history
153 idopenfolder = wx.NewId()
154 #accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('E'), idopenfolder)])
155 self.Bind(wx.EVT_MENU, self.OnOpenFolder, id=idopenfolder)
156 idsearchcorpus = wx.NewId()
157 accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('E'), idopenfolder), (wx.ACCEL_CTRL, ord('F'), idsearchcorpus)])
158 self.Bind(wx.EVT_MENU, self.OnSearchCorpus, id=idsearchcorpus)
159 self.SetAcceleratorTable(accel_tbl)
160 self.root = self.AddRoot("Iramuteq")
161 if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
162 self.SetPyData(self.root, None)
163 self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal)
164 self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded)
165 self.textroot = self.AppendItem(self.root, _('Textual corpus'))
166 self.SetPyData(self.textroot, {'uuid': 'textroot'})
167 self.SetItemImage(self.textroot, self.ild['textroot'], CT.TreeItemIcon_Normal)
168 self.SetItemImage(self.textroot, self.ild['textroot'], CT.TreeItemIcon_Expanded)
169 for corpus in reversed(self.h) :
170 child = self.AppendItem(self.textroot, corpus['corpus_name'])
171 self.SetPyData(child, corpus)
172 self.SetItemImage(child, self.ild['corpus'], CT.TreeItemIcon_Normal)
173 self.SetItemImage(child, self.ild['corpus'], CT.TreeItemIcon_Expanded)
174 if 'analyses' in corpus :
175 for y in corpus['analyses'] :
176 last = self.AppendItem(child, y['name'], ct_type=0)
177 self.SetPyData(last, y)
178 if y['type'] in self.ild :
179 img = self.ild[y['type']]
182 self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
183 self.SetItemImage(last, img, CT.TreeItemIcon_Expanded)
184 self.matroot = self.AppendItem(self.root, _('Matrix'))
185 self.SetPyData(self.matroot, {'uuid': 'matroot'})
186 self.SetItemImage(self.matroot, self.ild['matroot'], CT.TreeItemIcon_Normal)
187 self.SetItemImage(self.matroot, self.ild['matroot'], CT.TreeItemIcon_Expanded)
189 for matrix in reversed(self.history.matrix) :
190 if 'matrix_name' in matrix :
191 child = self.AppendItem(self.matroot, matrix['matrix_name'])
192 self.SetPyData(child, matrix)
193 self.SetItemImage(child, self.ild['matrix'], CT.TreeItemIcon_Normal)
194 self.SetItemImage(child, self.ild['matrix'], CT.TreeItemIcon_Expanded)
195 if 'analyses' in matrix :
196 for y in matrix['analyses'] :
197 last = self.AppendItem(child, y['name'], ct_type=0)
198 self.SetPyData(last, y)
199 if y['type'] in self.ild :
200 img = self.ild[y['type']]
203 self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
204 self.SetItemImage(last, img, CT.TreeItemIcon_Expanded)
206 orphmat.append(matrix)
207 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
208 #self.Bind(wx.EVT_IDLE, self.OnIdle)
209 self.eventdict = {'EVT_TREE_BEGIN_DRAG': self.OnBeginDrag, 'EVT_TREE_BEGIN_LABEL_EDIT': self.OnBeginEdit,
210 'EVT_TREE_BEGIN_RDRAG': self.OnBeginRDrag, 'EVT_TREE_DELETE_ITEM': self.OnDeleteItem,
211 'EVT_TREE_END_DRAG': self.OnEndDrag, 'EVT_TREE_END_LABEL_EDIT': self.OnEndEdit,
212 'EVT_TREE_ITEM_ACTIVATED': self.OnActivate, 'EVT_TREE_ITEM_CHECKED': self.OnItemCheck,
213 'EVT_TREE_ITEM_CHECKING': self.OnItemChecking, 'EVT_TREE_ITEM_COLLAPSED': self.OnItemCollapsed,
214 'EVT_TREE_ITEM_COLLAPSING': self.OnItemCollapsing, 'EVT_TREE_ITEM_EXPANDED': self.OnItemExpanded,
215 'EVT_TREE_ITEM_EXPANDING': self.OnItemExpanding, 'EVT_TREE_ITEM_GETTOOLTIP': self.OnToolTip,
216 'EVT_TREE_ITEM_MENU': self.OnItemMenu, 'EVT_TREE_ITEM_RIGHT_CLICK': self.OnRightDown,
217 'EVT_TREE_KEY_DOWN': self.OnKey, 'EVT_TREE_SEL_CHANGED': self.OnSelChanged,
218 'EVT_TREE_SEL_CHANGING': self.OnSelChanging, "EVT_TREE_ITEM_HYPERLINK": self.OnHyperLink}
219 mainframe = wx.GetTopLevelParent(self)
220 if not hasattr(mainframe, "leftpanel"):
221 #self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded)
222 #self.Bind(CT.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed)
223 self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
224 self.Bind(CT.EVT_TREE_SEL_CHANGING, self.OnSelChanging)
225 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
226 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
228 for combos in mainframe.treeevents:
229 self.BindEvents(combos)
230 if hasattr(mainframe, "leftpanel"):
231 self.ChangeStyle(mainframe.treestyles)
232 if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
233 self.SelectItem(self.root)
234 self.Expand(self.root)
236 def BindEvents(self, choice, recreate=False):
237 value = choice.GetValue()
238 text = choice.GetLabel()
240 binder = self.eventdict[text]
242 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
243 self.Bind(wx.EVT_RIGHT_DOWN, None)
244 self.Bind(wx.EVT_RIGHT_UP, None)
245 self.Bind(eval(evt), binder)
247 self.Bind(eval(evt), None)
248 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
249 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
250 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
252 def ChangeStyle(self, combos):
255 if combo.GetValue() == 1:
256 style = style | eval("CT." + combo.GetLabel())
257 if self.GetAGWWindowStyleFlag() != style:
258 self.SetAGWWindowStyleFlag(style)
260 def OnCompareItems(self, item1, item2):
261 t1 = self.GetItemText(item1)
262 t2 = self.GetItemText(item2)
269 def OnIdle(self, event):
272 # if self.gauge.IsEnabled() and self.gauge.IsShown():
273 # self.count = self.count + 1
274 # if self.count >= 50:
276 # self.gauge.SetValue(self.count)
281 def CloseItem(self, itemParent = None, uuid = None) :
282 if itemParent is None :
283 itemParent = self.root
284 child, cookie = self.GetFirstChild(itemParent)
286 pydata = self.GetPyData(child)
287 if pydata['uuid'] == uuid :
288 self.SetItemBold(child, False)
290 self.CloseItem(child, uuid)
291 child, cookie = self.GetNextChild(itemParent, cookie)
293 def GiveFocus(self, itemParent = None, uuid = None, bold = False) :
294 if itemParent is None :
295 itemParent = self.root
296 child, cookie = self.GetFirstChild(itemParent)
298 pydata = self.GetPyData(child)
299 if pydata['uuid'] == uuid :
300 self.SelectItem(child)
302 self.SetItemBold(child, True)
304 self.GiveFocus(child, uuid, bold)
305 child, cookie = self.GetNextChild(itemParent, cookie)
307 def IsInTree(self, itemParent = None, uuid = None) :
308 if itemParent is None :
309 itemParent = self.root
310 child, cookie = self.GetFirstChild(itemParent)
312 pydata = self.GetPyData(child)
313 if pydata['uuid'] == uuid :
315 self.GiveFocus(child, uuid)
316 child, cookie = self.GetNextChild(itemParent, cookie)
319 def OnRightDown(self, event):
320 pt = event.GetPosition()
321 item, flags = self.HitTest(pt)
324 #self.log.info("OnRightClick: %s, %s, %s" % (self.GetItemText(item), type(item), item.__class__) + "\n")
325 self.SelectItem(item)
327 def OnRightUp(self, event):
332 if not self.IsItemEnabled(item):
335 # Item Text Appearance
336 ishtml = self.IsItemHyperText(item)
337 back = self.GetItemBackgroundColour(item)
338 fore = self.GetItemTextColour(item)
339 isbold = self.IsBold(item)
340 font = self.GetItemFont(item)
342 normal = self.GetItemImage(item, CT.TreeItemIcon_Normal)
343 selected = self.GetItemImage(item, CT.TreeItemIcon_Selected)
344 expanded = self.GetItemImage(item, CT.TreeItemIcon_Expanded)
345 selexp = self.GetItemImage(item, CT.TreeItemIcon_SelectedExpanded)
346 # Enabling/Disabling Windows Associated To An Item
347 haswin = self.GetItemWindow(item)
348 # Enabling/Disabling Items
349 enabled = self.IsItemEnabled(item)
350 # Generic Item's Info
351 children = self.GetChildrenCount(item)
352 itemtype = self.GetItemType(item)
353 text = self.GetItemText(item)
354 pydata = self.GetPyData(item)
357 self.itemdict = {"ishtml": ishtml, "back": back, "fore": fore, "isbold": isbold,
358 "font": font, "normal": normal, "selected": selected, "expanded": expanded,
359 "selexp": selexp, "haswin": haswin, "children": children,
360 "itemtype": itemtype, "text": text, "pydata": pydata, "enabled": enabled}
361 if not item in [self.textroot, self.matroot] :
363 info = wx.MenuItem(menu, wx.ID_ANY, _("Informations"))
364 info.SetBitmap(wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, size = (16,16)))
366 rename = wx.MenuItem(menu, wx.ID_ANY, _("Rename"))
367 rename.SetBitmap(wx.ArtProvider.GetBitmap(wx.ART_TIP, size = (16,16)))
369 openfolder = wx.MenuItem(menu, wx.ID_ANY, _("Open directory"))
370 openfolder.SetBitmap(wx.ArtProvider.GetBitmap(wx.ART_FOLDER_OPEN, size = (16,16)))
371 menu.Append(openfolder)
372 menu.AppendSeparator()
373 if 'corpus_name' in pydata :
374 buildmenu(menu, self.parent.text_menu)
375 menu.AppendSeparator()
376 elif 'matrix_name' in pydata :
377 buildmenu(menu, self.parent.matrix_menu)
378 menu.AppendSeparator()
379 elif pydata.get('type', False) == 'alceste' and pydata['uuid'] in self.parent.history.opened :
381 antipro = openmenu.Append(wx.ID_ANY, _("Antiprofiles"))
382 menu.Append(wx.ID_ANY, _("Open ..."), openmenu)
383 translate = menu.Append(wx.ID_ANY, _("Translate Profile"))
384 profsr = menu.Append(wx.ID_ANY, _("Repeated segments profiles"))
385 profgram = menu.Append(wx.ID_ANY, _("POS profiles"))
386 stcaract = menu.Append(wx.ID_ANY, _("Typical text segments"))
387 tgen = menu.Append(wx.ID_ANY, _("Tgen Editor"))
388 computetgen = menu.Append(wx.ID_ANY, _("Compute Tgen"))
389 mergeclustergraph = menu.Append(wx.ID_ANY, _("Merge Cluster Graph"))
390 export_corpus = menu.Append(wx.ID_ANY, _("Export corpus"))
391 colored = menu.Append(wx.ID_ANY, _("Colored corpus"))
392 navig = menu.Append(wx.ID_ANY, _("Navigator"))
393 statclasse = menu.Append(wx.ID_ANY, _("Clusters statistics"))
394 rapport = menu.Append(wx.ID_ANY, _("Report"))
395 export_classes = menu.Append(wx.ID_ANY, _("Export clusters"))
396 subcorpusfromcl = menu.Append(wx.ID_ANY, _("Sub corpus from clusters"))
397 menu.AppendSeparator()
398 self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
399 self.Bind(wx.EVT_MENU, self.OnTranslate, translate)
400 self.Bind(wx.EVT_MENU, self.OnProfSR, profsr)
401 self.Bind(wx.EVT_MENU, self.OnProfGram, profgram)
402 self.Bind(wx.EVT_MENU, self.OnStCaract, stcaract)
403 self.Bind(wx.EVT_MENU, self.OnTgenEditor, tgen)
404 self.Bind(wx.EVT_MENU, self.OnTgenCompute, computetgen)
405 self.Bind(wx.EVT_MENU, self.OnMergeClusterGraph, mergeclustergraph)
406 self.Bind(wx.EVT_MENU, self.OnExportCorpus, export_corpus)
407 self.Bind(wx.EVT_MENU, self.OnColored, colored)
408 self.Bind(wx.EVT_MENU, self.OnNavig, navig)
409 self.Bind(wx.EVT_MENU, self.StatClasse, statclasse)
410 self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
411 self.Bind(wx.EVT_MENU, self.OnExportClasses, export_classes)
412 self.Bind(wx.EVT_MENU, self.OnSubCorpusFromClusters, subcorpusfromcl)
413 elif pydata.get('type', False) == 'stat' and pydata['uuid'] in self.parent.history.opened :
414 export_dictionary = menu.Append(wx.ID_ANY, _("Export dictionary"))
415 export_lems = menu.Append(wx.ID_ANY, _("Export lemma dictionary"))
416 export_cut_corpus = menu.Append(wx.ID_ANY, _("Export segmented corpus"))
417 self.Bind(wx.EVT_MENU, self.OnExportDictionary, export_dictionary)
418 self.Bind(wx.EVT_MENU, self.OnExportLems, export_lems)
419 self.Bind(wx.EVT_MENU, self.OnExportCutCorpus, export_cut_corpus)
420 menu.AppendSeparator()
421 elif pydata.get('type', False) == 'spec' and pydata['uuid'] in self.parent.history.opened :
422 tgen = menu.Append(wx.ID_ANY, _("Tgen Editor"))
423 computetgen = menu.Append(wx.ID_ANY, _("Compute Tgen"))
424 self.Bind(wx.EVT_MENU, self.OnTgenEditor, tgen)
425 self.Bind(wx.EVT_MENU, self.OnTgenCompute, computetgen)
426 menu.AppendSeparator()
427 elif pydata.get('type', False) == 'reinertmatrix' and pydata['uuid'] in self.parent.history.opened :
429 antipro = openmenu.Append(wx.ID_ANY, _("antiprofiles"))
430 rapport = menu.Append(wx.ID_ANY, _("Report"))
431 menu.Append(wx.ID_ANY, _("Open ..."), openmenu)
432 self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
433 self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
434 itemdelete = wx.MenuItem(menu, wx.ID_ANY, _("Delete from history"))
435 itemdelete.SetBitmap(wx.ArtProvider.GetBitmap(wx.ART_DELETE, size = (16,16)))
436 menu.Append(itemdelete)
437 #item11 = menu.Append(wx.ID_ANY, "Prepend An Item")
438 #item12 = menu.Append(wx.ID_ANY, "Append An Item")
439 #self.Bind(wx.EVT_MENU, self.OnItemBackground, item1)
440 #self.Bind(wx.EVT_MENU, self.OnItemForeground, item2)
441 #self.Bind(wx.EVT_MENU, self.OnItemBold, item3)
442 #self.Bind(wx.EVT_MENU, self.OnItemFont, item4)
443 #self.Bind(wx.EVT_MENU, self.OnItemHyperText, item5)
444 #self.Bind(wx.EVT_MENU, self.OnEnableWindow, item6)
445 #self.Bind(wx.EVT_MENU, self.OnDisableItem, item7)
446 #self.Bind(wx.EVT_MENU, self.OnItemIcons, item8)
447 self.Bind(wx.EVT_MENU, self.OnItemInfo, info)
448 self.Bind(wx.EVT_MENU, self.OnRename, rename)
449 self.Bind(wx.EVT_MENU, self.OnItemDelete, itemdelete)
450 self.Bind(wx.EVT_MENU, self.OnOpenFolder, openfolder)
451 #self.Bind(wx.EVT_MENU, self.OnItemPrepend, item11)
452 #self.Bind(wx.EVT_MENU, self.OnItemAppend, item12)
457 busy = wx.BusyInfo(_("Please wait...Reading corpus"), self.parent)
459 if self.pydata['uuid'] in self.parent.history.openedcorpus :
460 corpus = copycorpus(self.parent.history.openedcorpus[self.pydata['uuid']])
461 elif 'corpus_name' in self.pydata :
462 corpus = Corpus(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('corpus'), read = True)
464 cuuid = self.pydata['corpus']
465 if cuuid in self.parent.history.openedcorpus :
466 corpus = copycorpus(self.parent.history.openedcorpus[cuuid])
468 irapath = self.parent.history.corpus[cuuid]['ira']
469 corpus = Corpus(self.parent, parametres = DoConf(irapath).getoptions('corpus'), read = True)
474 if 'matrix_name' in self.pydata :
475 matrix = Tableau(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('matrix'))
477 return copymatrix(matrix)
479 cuuid = self.pydata['matrix']
480 matrix = Tableau(self.parent, parametres = DoConf(self.history.matrixanalyse[cuuid]['ira']).getoptions('matrix'))
482 return copymatrix(matrix)
484 def OnSpec(self, evt) :
485 self.parent.OnTextSpec(evt, self.getcorpus())
487 def OnStat(self, evt) :
488 self.parent.OnTextStat(evt, self.getcorpus())
490 def OnReinert(self, evt) :
491 self.parent.OnTextReinert(evt, self.getcorpus())
493 def OnPam(self, evt) :
494 self.parent.OnPamSimple(evt, self.getcorpus())
496 def OnSimiTxt(self, evt) :
497 self.parent.OnSimiTxt(evt, self.getcorpus())
499 def OnWordCloud(self, evt) :
500 self.parent.OnWordCloud(evt, self.getcorpus())
502 # def OnFreq(self, evt):
503 # self.parent.OnFreq(evt, self.getmatrix())
505 # def OnChiSquare(self, evt):
506 # self.parent.OnChi2(evt, self.getmatrix())
508 # def OnSimiTab(self, evt):
509 # self.parent.OnSimiTab(evt, self.getmatrix())
511 # def OnProto(self, evt):
512 # self.parent.OnProto(evt, self.getmatrix())
514 # def OnSplitFromVar(self, evt):
515 # self.parent.OnSplitVar(evt, self.getmatrix())
517 # def OnCHDReinert(self, evt):
518 # self.parent.OnCHDReinert(evt, self.getmatrix())
520 #def OnSubTextFromMeta(self, evt):
521 # self.parent.OnSubText(self.getcorpus(), parametres = {'frommeta' : True})
523 #def OnSubTextFromTheme(self, evt):
524 # self.parent.OnSubText(self.getcorpus(), parametres = {'fromtheme' : True})
526 def OnProfSR(self, evt) :
527 ProfileSegment(self.parent, self.page.dictpathout, self.page.parametres, self.page.corpus)
529 def OnProfGram(self, evt) :
530 ProfilType(self.parent, self.page.corpus, self.page.parametres)
532 def OnMergeClusterGraph(self, evt) :
533 MergeClusterGraph(self.parent, self.page.corpus, self.page.parametres)
534 print('merge done !')
536 def OnStCaract(self, evt) :
537 dial = PrefUCECarac(self, self.parent)
538 dial.CenterOnParent()
539 if self.page.parametres['classif_mode'] != 2 :
543 if dial.ShowModal() == wx.ID_OK :
544 limite = dial.spin_eff.GetValue()
545 atype = dial.radio_type.GetSelection()
547 corpus = self.page.corpus
548 dlg = progressbar(self.ira, maxi = len(corpus.lc))
549 dlg.Update(1, 'wait...')
550 for i in range(0, len(corpus.lc)) :
551 page = self.page.ProfNB.GetPage(i)
553 dlg.Update(i, 'Cluster %i' % (i+1))
554 uces = corpus.lc[rcl]
555 tab = corpus.make_table_with_classe(uces, page.la, uci = uci)
558 ntab = [round(sum([page.lchi[j] for j, word in enumerate(line) if word == 1]),2) for line in tab]
560 ntab = [round(sum([page.lchi[j] for j, word in enumerate(line) if word == 1])/float(sum(line)),2) if sum(line)!=0 else 0 for line in tab]
561 ntab2 = [[ntab[j], uces[j]] for j, val in enumerate(ntab)]
563 ntab2.sort(reverse = True)
564 ntab2 = ntab2[:limite]
565 nuces = [val[1] for val in ntab2]
566 ucis_txt, ucestxt = doconcorde(corpus, nuces, page.la, uci = uci)
567 items = ['<br>'.join([ucis_txt[j], '<table bgcolor = #1BF0F7 border=0><tr><td><b>score : %.2f</b></td></tr></table><br>' % ntab2[j][0], ucestxt[j]]) for j, uce in enumerate(nuces)]
568 filename = self.page.pathout['st_caract_cl_%i.html' % (rcl+1)]
569 with open(filename, 'w', encoding='utf8') as f :
570 f.write('\n'.join(items))
573 def OnExportCorpus(self, evt) :
574 dial = PrefExport(self, self.parent)
575 dial.fbb.SetValue(os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'export_corpus.txt'))
576 dial.CenterOnParent()
577 res = dial.ShowModal()
579 if dial.radio_type.GetSelection() == 0 : alc = True
581 if dial.radio_lem.GetSelection() == 0 : lem = True
583 if self.page.parametres['classif_mode'] != 2 :
587 self.page.corpus.export_corpus_classes(dial.fbb.GetValue(), alc = alc, lem = lem, uci = uci)
590 dlg = wx.MessageDialog(self.parent, msg, "Export", wx.OK | wx.ICON_INFORMATION)
595 def OnExportCutCorpus(self, evt) :
597 fileout = os.path.join(os.path.dirname(self.page.pathout['ira']), 'segmented_corpus.txt')
598 txt = self.page.corpus.make_cut_corpus(uci = uci)
599 with open(fileout, 'w', encoding='utf8') as f :
601 msg = '\n'.join([_("Done !"), fileout])
602 dlg = wx.MessageDialog(self.parent, msg, _("Segmented corpus"), wx.OK | wx.ICON_INFORMATION)
607 def OnColored(self, evt) :
608 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.html', 'title': _("Colored corpus")})
609 dial.fbb.SetValue(os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'corpus_couleur.html'))
610 dial.CenterOnParent()
611 res = dial.ShowModal()
613 fileout = dial.fbb.GetValue()
615 if self.page.parametres['classif_mode'] != 2 :
619 txt = self.page.corpus.make_colored_corpus(uci = uci)
620 with open(fileout, 'w', encoding='utf8') as f :
622 msg = ' !\n'.join([_("Done"), _("Open in a web browser ?")])
623 dlg = wx.MessageDialog(self.parent, msg, "Corpus en couleur", wx.NO | wx.YES | wx.ICON_QUESTION)
625 if dlg.ShowModal() == wx.ID_YES :
626 webbrowser.open(fileout)
629 def OnNavig(self, evt):
630 if 'FrameSearch' not in dir(self.page) :
631 self.page.FrameSearch = SearchFrame(self.parent, -1, _("Search ..."), self.page.corpus)
632 self.page.FrameSearch.Show()
634 def StatClasse(self, evt):
635 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.csv', 'title': _("Clusters statistics")})
636 dial.fbb.SetValue( os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'stat_par_classe.csv'))
637 dial.CenterOnParent()
638 res = dial.ShowModal()
640 fileout = dial.fbb.GetValue()
642 self.page.corpus.get_stat_by_cluster(fileout)
644 dlg = wx.MessageDialog(self.parent, msg, _("Clusters statistics"), wx.OK | wx.ICON_INFORMATION)
646 if dlg.ShowModal() == wx.ID_OK :
649 def OpenAntipro(self, evt) :
651 for i in range(0, self.page.TabChdSim.GetPageCount()) :
652 page = self.page.TabChdSim.GetPage(i)
653 if self.page.TabChdSim.GetPageText(i) == _("Antiprofiles") :
654 self.page.TabChdSim.SetSelection(i)
658 open_antiprofil(self.page, self.page.dictpathout['ANTIPRO_OUT'], 'utf8')
659 self.page.TabChdSim.SetSelection(self.page.TabChdSim.GetPageCount() - 1)
661 def OnTranslate(self, evt) :
662 dial = translate_dialog(self.parent)
663 dial.CenterOnParent()
664 res = dial.ShowModal()
666 to_l = dial.getto_l()
667 from_l = dial.getfrom_l()
669 busy = wx.BusyInfo(_("Please wait..."), self.parent)
671 prof, lems = translateprofile(self.page.corpus, ReadProfileAsDico(self.page.dictpathout['PROFILE_OUT'], True, self.parent.syscoding), lf=from_l, lt=to_l)
672 write_translation_profile(prof, lems, to_l, self.page.dictpathout)
673 open_antiprofil(self.page, prof, 'utf8', title = _('Translation') + ' %s' % to_l, translation = True, lems=lems)
675 self.page.lems = lems
676 self.page.TabChdSim.SetSelection(self.page.TabChdSim.GetPageCount() - 1)
680 def OnRapport(self, evt) :
681 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.txt', 'title': _("Report")})
682 dial.fbb.SetValue(self.page.dictpathout['rapport'])
683 dial.CenterOnParent()
684 res = dial.ShowModal()
686 fileout = dial.fbb.GetValue()
688 with open(fileout, 'w', encoding='utf8') as f :
689 f.write(self.page.debtext + '\n' + GetTxtProfile(self.page.DictProfile, self.page.cluster_size))
691 dlg = wx.MessageDialog(self.parent, msg, _("Report"), wx.OK | wx.ICON_INFORMATION)
698 def OnExportDictionary(self, evt) :
699 corpus = self.page.corpus
700 corpus.export_dictionary(self.page.pathout['dictionary.csv'], self.parent.syscoding)
701 log.info('export dictionary %s' % self.page.pathout['dictionary.csv'])
702 dial = wx.MessageDialog(self.parent, self.page.pathout['dictionary.csv'], 'Export', wx.OK)
706 def OnExportLems(self, evt) :
707 corpus = self.page.corpus
708 corpus.export_lems(self.page.pathout['lemmes.csv'], self.parent.syscoding)
709 log.info('export lemmes %s' % self.page.pathout['lemmes.csv'])
710 dial = wx.MessageDialog(self.parent, self.page.pathout['lemmes.csv'], 'Export', wx.OK)
714 def OnTgenEditor(self, evt):
715 corpus = self.page.corpus
716 tgenpath = os.path.join(self.page.parametres['pathout'], 'tgen.csv')
717 tgen = TGen(path = tgenpath, encoding = self.parent.syscoding)
718 if os.path.exists(tgenpath) :
720 if isinstance(evt, list) :
722 while 'tgen%i' %i in tgen.tgen :
724 tgenname = 'tgen%i' %i
725 tgen.tgen[tgenname] = evt
726 tgenframe = TGenFrame(self.parent, corpus, tgen)
728 if isinstance(evt, list) :
729 tgenframe.OnNewTgen(None, tgen = tgenname)
731 def OnTgenCompute(self, evt):
732 corpus = self.page.corpus
733 tgenpath = os.path.join(self.page.parametres['pathout'], 'tgen.csv')
734 if not os.path.exists(tgenpath) :
735 message = wx.MessageDialog(self.parent, _("No TGen yet !"), style = wx.ICON_EXCLAMATION | wx.OK)
739 self.page.parametres['tgenpath'] = tgenpath
740 tgen = TGen(path = tgenpath, encoding = self.parent.syscoding)
741 if self.page.parametres['type'] == 'spec' :
742 self.page.parametres['etoiles'] = self.page.etoiles
743 TgenSpec(self.parent, corpus, self.page.parametres)
744 elif self.page.parametres['type'] == 'alceste' :
745 TgenProf(self.parent, corpus, self.page.parametres, self.page.cluster_size)
746 TgenLayout(self.page)
748 def OnExportClasses(self, event):
749 corpus = self.page.corpus
750 if self.page.parametres['classif_mode'] != 2 :
754 busy = wx.BusyInfo(_("Please wait..."), self.parent)
756 for i in range(1, self.page.parametres['clnb'] + 1) :
757 corpus.export_classe(self.page.pathout['classe_%i_export.txt' % i], i, uci = uci)
759 dial = wx.MessageDialog(self, self.page.pathout['classe_x_export.txt'], "Export", wx.OK|wx.ICON_INFORMATION)
763 def OnSubCorpusFromClusters(self, evt):
764 self.parent.OnSubText(evt, corpus = self.getcorpus(), parametres = {'fromclusters' : True, 'clnb': self.page.parametres['clnb'], 'lc' : self.page.corpus.lc})
766 def OnRename(self, event):
767 pydata = self.itemdict['pydata']
768 if 'matrix_name' in pydata :
770 elif 'corpus_name' in pydata :
774 oldname = pydata[name]
775 dlg = wx.TextEntryDialog(self, _("New Name"), _('Rename'), oldname)
776 if dlg.ShowModal() == wx.ID_OK:
777 newname = dlg.GetValue()
779 pydata[name] = newname
780 Totconf = DoConf(configfile=pydata['ira'])
781 conf = Totconf.getoptions()
783 Totconf.makeoptions(Totconf.getsections(), [conf])
784 self.history.update(pydata)
785 self.SetItemText(self.current, newname)
786 self.EnsureVisible(self.current)
788 def OnOpenFolder(self, evt):
790 open_folder(os.path.dirname(self.pydata['ira']))
792 print('cannot open folder %s' % self.pydata.get('ira', 'noirapath'))
794 def GetCorpusByName(self, corpus_name) :
795 return [corpus for corpus in self.h if corpus_name in corpus['corpus_name']]
797 def OnSearchCorpus(self, evt):
798 searchframe = SearchCorpus(self.ira, self, None, None)
800 #res = self.GetCorpusByName('Ministres')
803 def SetContentBackground(self, itemParent = None, uuid = None, color = True) :
804 if itemParent is None :
805 itemParent = self.root
806 child, cookie = self.GetFirstChild(itemParent)
808 pydata = self.GetPyData(child)
809 if pydata['uuid'] == uuid :
810 self.SelectItem(child)
812 self.SetItemBackgroundColour(child, wx.Colour(15,234,56))
814 self.SetContentBackground(child, uuid, color)
815 child, cookie = self.GetNextChild(itemParent, cookie)
817 def OnItemBackground(self, event):
818 colourdata = wx.ColourData()
819 colourdata.SetColour(self.itemdict["back"])
820 dlg = wx.ColourDialog(self, colourdata)
821 dlg.GetColourData().SetChooseFull(True)
822 if dlg.ShowModal() == wx.ID_OK:
823 data = dlg.GetColourData()
824 col1 = data.GetColour().Get()
825 self.SetItemBackgroundColour(self.current, col1)
828 def OnItemForeground(self, event):
829 colourdata = wx.ColourData()
830 colourdata.SetColour(self.itemdict["fore"])
831 dlg = wx.ColourDialog(self, colourdata)
832 dlg.GetColourData().SetChooseFull(True)
833 if dlg.ShowModal() == wx.ID_OK:
834 data = dlg.GetColourData()
835 col1 = data.GetColour().Get()
836 self.SetItemTextColour(self.current, col1)
839 def OnItemBold(self, event):
840 self.SetItemBold(self.current, not self.itemdict["isbold"])
842 def OnItemFont(self, event):
844 font = self.itemdict["font"]
846 font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
847 data.SetInitialFont(font)
848 dlg = wx.FontDialog(self, data)
849 if dlg.ShowModal() == wx.ID_OK:
850 data = dlg.GetFontData()
851 font = data.GetChosenFont()
852 self.SetItemFont(self.current, font)
855 def OnItemHyperText(self, event):
856 self.SetItemHyperText(self.current, not self.itemdict["ishtml"])
858 def OnEnableWindow(self, event):
859 enable = self.GetItemWindowEnabled(self.current)
860 self.SetItemWindowEnabled(self.current, not enable)
862 def OnDisableItem(self, event):
863 self.EnableItem(self.current, False)
865 def OnItemIcons(self, event):
866 bitmaps = [self.itemdict["normal"], self.itemdict["selected"],
867 self.itemdict["expanded"], self.itemdict["selexp"]]
869 dlg = TreeIcons(self, -1, bitmaps=bitmaps)
873 def SetNewIcons(self, bitmaps):
874 self.SetItemImage(self.current, bitmaps[0], CT.TreeItemIcon_Normal)
875 self.SetItemImage(self.current, bitmaps[1], CT.TreeItemIcon_Selected)
876 self.SetItemImage(self.current, bitmaps[2], CT.TreeItemIcon_Expanded)
877 self.SetItemImage(self.current, bitmaps[3], CT.TreeItemIcon_SelectedExpanded)
879 def OnItemInfo(self, event):
880 itemtext = self.itemdict["text"]
881 numchildren = str(self.itemdict["children"])
882 itemtype = self.itemdict["itemtype"]
883 pydata = self.itemdict['pydata']
884 #if 'analyses' in pydata :
885 # toshow = dict([[val, pydata[val]] for val in pydata if val not in['analyses', 'isload']])
887 toshow = pydata['ira']
888 toshow = DoConf(toshow).getoptions()
889 txt = DoConf().totext(toshow)
890 parametres = [val.split('\t\t:') for val in txt.splitlines()]
895 itemtype = "CheckBox"
897 itemtype = "RadioButton"
898 dlg = InfoDialog(self, itemtext, parametres)
903 def OnItemDelete(self, event):
904 strs = "Are You Sure You Want To Delete Item " + self.GetItemText(self.current) + "?"
905 dlg = wx.MessageDialog(None, strs, 'Deleting Item', wx.OK | wx.CANCEL | wx.ICON_QUESTION)
906 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
910 pydata = self.itemdict['pydata']
911 if 'corpus_name' in pydata :
912 self.history.delete(pydata, True)
914 self.history.delete(pydata)
915 self.DeleteChildren(self.current)
916 self.Delete(self.current)
919 def OnItemPrepend(self, event):
920 dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
921 if dlg.ShowModal() == wx.ID_OK:
922 newname = dlg.GetValue()
923 newitem = self.PrependItem(self.current, newname)
924 self.EnsureVisible(newitem)
927 def AddAnalyse(self, parametres, itemParent = None, bold = True) :
928 uuid = parametres.get('corpus', None)
929 if uuid is not None :
930 if itemParent is None :
931 itemParent = self.textroot
932 child, cookie = self.GetFirstChild(itemParent)
935 pydata = self.GetPyData(child)
936 if pydata['uuid'] == uuid :
939 self.GiveFocus(child, uuid)
940 child, cookie = self.GetNextChild(itemParent, cookie)
941 #item = self.AppendItem(child, parametres['name'])
942 if corpus is not None :
943 item = self.AppendItem(corpus, parametres['name'])
945 item = self.AppendItem(self.textroot, parametres['name'])
947 item = self.AppendItem(self.matroot, parametres['name'])
948 self.SetPyData(item, parametres)
949 if parametres['type'] in self.ild :
950 img = self.ild[parametres['type']]
953 self.SetItemImage(item, img, CT.TreeItemIcon_Normal)
954 self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
955 self.SetItemBold(item, bold)
956 self.SelectItem(item)
958 def AddMatAnalyse(self, parametres, itemParent = None, bold = True) :
959 uuid = parametres.get('matrix', None)
960 if uuid is not None :
961 if itemParent is None :
962 itemParent = self.matroot
963 child, cookie = self.GetFirstChild(itemParent)
966 pydata = self.GetPyData(child)
967 if pydata['uuid'] == uuid :
970 self.GiveFocus(child, uuid)
971 child, cookie = self.GetNextChild(itemParent, cookie)
972 #item = self.AppendItem(child, parametres['name'])
973 if matrix is not None :
974 item = self.AppendItem(matrix, parametres['name'])
976 item = self.AppendItem(self.matroot, parametres['name'])
977 self.SetPyData(item, parametres)
978 if parametres['type'] in self.ild :
979 img = self.ild[parametres['type']]
982 self.SetItemImage(item, img, CT.TreeItemIcon_Normal)
983 self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
984 self.SetItemBold(item, bold)
985 self.SelectItem(item)
987 def OnItemAppend(self, item, select = True):
988 if 'corpus_name' in item :
989 child = self.InsertItem(self.textroot, 0, item['corpus_name'])
991 child = self.InsertItem(self.matroot, 0, item['matrix_name'])
992 self.SetPyData(child, item)
993 if item['type'] in self.ild :
994 img = self.ild[item['type']]
997 self.SetItemImage(child, img, CT.TreeItemIcon_Normal)
998 self.SetItemImage(child, img, CT.TreeItemIcon_Expanded)
1000 self.history.addtab(item)
1001 self.SetItemBold(child, True)
1002 self.SelectItem(child)
1003 #dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
1004 #if dlg.ShowModal() == wx.ID_OK:
1005 # newname = dlg.GetValue()
1006 # newitem = self.AppendItem(self.current, newname)
1007 # self.EnsureVisible(newitem)
1010 def OnBeginEdit(self, event):
1011 #self.log.info("OnBeginEdit" + "\n")
1012 # show how to prevent edit...
1013 item = event.GetItem()
1014 if item and self.GetItemText(item) == "The Root Item":
1016 #self.log.info("You can't edit this one..." + "\n")
1017 # Lets just see what's visible of its children
1019 root = event.GetItem()
1020 (child, cookie) = self.GetFirstChild(root)
1022 #self.log.info("Child [%s] visible = %d" % (self.GetItemText(child), self.IsVisible(child)) + "\n")
1023 (child, cookie) = self.GetNextChild(root, cookie)
1026 def OnEndEdit(self, event):
1027 #self.log.info("OnEndEdit: %s %s" %(event.IsEditCancelled(), event.GetLabel()))
1028 # show how to reject edit, we'll not allow any digits
1029 for x in event.GetLabel():
1030 if x in string.digits:
1031 #self.log.info(", You can't enter digits..." + "\n")
1036 def OnLeftDClick(self, event):
1037 pt = event.GetPosition()
1038 item, flags = self.HitTest(pt)
1039 if item is not None :
1040 pydata = self.GetPyData(item)
1041 if pydata['uuid'] in self.parent.history.opened :
1042 for i in range(self.parent.nb.GetPageCount()) :
1043 page = self.parent.nb.GetPage(i)
1044 if 'parametres' in dir(page) :
1045 if page.parametres['uuid'] == pydata['uuid'] :
1046 self.parent.nb.SetSelection(i)
1048 elif pydata['uuid'] in ['textroot', 'matroot'] :
1051 if os.path.exists(pydata['ira']) :
1052 busy = wx.BusyInfo(_("Please wait..."), self.parent)
1055 OpenAnalyse(self.parent, pydata)
1057 self.SetItemBold(item, True)
1058 self.OnSelChanged(pydata = pydata)
1063 wx.MessageBox(_("This file does not exist : %s" % pydata['ira']), 'Information', wx.ICON_EXCLAMATION | wx.STAY_ON_TOP )
1064 #if item and (flags & CT.TREE_HITTEST_ONITEMLABEL):
1065 # if self.GetAGWWindowStyleFlag() & CT.TR_EDIT_LABELS:
1066 # self.log.info("OnLeftDClick: %s (manually starting label edit)"% self.GetItemText(item) + "\n")
1067 #self.EditLabel(item)
1069 # pydata = self.GetPyData(item)
1071 # self.log.info("OnLeftDClick: Cannot Start Manual Editing, Missing Style TR_EDIT_LABELS\n")
1074 def OnItemExpanded(self, event):
1075 item = event.GetItem()
1077 self.log.info("OnItemExpanded: %s" % self.GetItemText(item) + "\n")
1079 def OnItemExpanding(self, event):
1080 item = event.GetItem()
1082 self.log.info("OnItemExpanding: %s" % self.GetItemText(item) + "\n")
1085 def OnItemCollapsed(self, event):
1086 item = event.GetItem()
1088 self.log.info("OnItemCollapsed: %s" % self.GetItemText(item) + "\n")
1090 def OnItemCollapsing(self, event):
1091 item = event.GetItem()
1093 self.log.info("OnItemCollapsing: %s" % self.GetItemText(item) + "\n")
1096 def OnSelChanged(self, event = None, pydata = None):
1097 if event is not None :
1098 item = event.GetItem()
1099 pydata = self.GetPyData(item)
1100 if pydata is not None :
1101 if 'corpus_name' in pydata or 'corpus' in pydata :
1102 #self.ira.ShowMenu('matrix', False)
1103 self.ira.ShowMenu('text', True)
1104 if 'matrix_name' in pydata or 'matrix' in pydata:
1105 #self.ira.ShowMenu('text', False)
1106 self.ira.ShowMenu('matrix', True)
1107 if 'uuid' in pydata :
1108 if pydata['uuid'] in ['textroot', 'matroot'] :
1109 self.ira.ShowMenu('text', False)
1110 self.ira.ShowMenu('matrix', False)
1111 self.pydata = pydata
1112 if pydata['uuid'] in self.parent.history.opened :
1113 for i in range(self.parent.nb.GetPageCount()) :
1114 self.page = self.parent.nb.GetPage(i)
1115 if 'parametres' in dir(self.page) :
1116 if self.page.parametres['uuid'] == pydata['uuid'] :
1117 self.parent.nb.SetSelection(i)
1118 wx.CallAfter(self.parent.nb.SendSizeEvent)
1119 #self.parent.Refresh()
1121 #self.parent._mgr.Update()
1122 #if event is not None :
1125 def OnSelChanging(self, event):
1126 item = event.GetItem()
1127 olditem = event.GetOldItem()
1130 olditemtext = "None"
1132 olditemtext = self.GetItemText(olditem)
1133 #self.log.info("OnSelChanging: From %s" % olditemtext + " To %s" % self.GetItemText(item) + "\n")
1136 def OnBeginDrag(self, event):
1137 self.item = event.GetItem()
1139 self.log.info("Beginning Drag..." + "\n")
1142 def OnBeginRDrag(self, event):
1143 self.item = event.GetItem()
1145 self.log.info("Beginning Right Drag..." + "\n")
1148 def OnEndDrag(self, event):
1149 self.item = event.GetItem()
1151 self.log.info("Ending Drag!" + "\n")
1154 def OnDeleteItem(self, event):
1155 item = event.GetItem()
1158 self.log.info("Deleting Item: %s" % self.GetItemText(item) + "\n")
1161 def OnItemCheck(self, event):
1162 item = event.GetItem()
1163 self.log.info("Item " + self.GetItemText(item) + " Has Been Checked!\n")
1166 def OnItemChecking(self, event):
1167 item = event.GetItem()
1168 self.log.info("Item " + self.GetItemText(item) + " Is Being Checked...\n")
1171 def OnToolTip(self, event):
1172 item = event.GetItem()
1174 event.SetToolTip(wx.ToolTip(self.GetItemText(item)))
1176 def OnItemMenu(self, event):
1177 item = event.GetItem()
1179 self.log.info("OnItemMenu: %s" % self.GetItemText(item) + "\n")
1182 def OnKey(self, event):
1183 keycode = event.GetKeyCode()
1184 keyname = keyMap.get(keycode, None)
1185 if keycode == wx.WXK_BACK:
1186 self.log.info("OnKeyDown: HAHAHAHA! I Vetoed Your Backspace! HAHAHAHA\n")
1189 if "unicode" in wx.PlatformInfo:
1190 keycode = event.GetUnicodeKey()
1192 keycode = event.GetKeyCode()
1193 keyname = "\"" + chr(event.GetUnicodeKey()) + "\""
1195 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1200 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1202 keyname = "\"%s\"" % chr(keycode)
1204 keyname = "unknown (%s)" % keycode
1205 self.log.info("OnKeyDown: You Pressed '" + keyname + "'\n")
1208 def OnActivate(self, event):
1210 self.log.info("OnActivate: %s" % self.GetItemText(self.item) + "\n")
1213 def OnHyperLink(self, event):
1214 item = event.GetItem()
1216 self.log.info("OnHyperLink: %s" % self.GetItemText(self.item) + "\n")
1218 def OnTextCtrl(self, event):
1219 char = chr(event.GetKeyCode())
1220 self.log.info("EDITING THE TEXTCTRL: You Wrote '" + char + \
1221 "' (KeyCode = " + str(event.GetKeyCode()) + ")\n")
1224 def OnComboBox(self, event):
1225 selection = event.GetEventObject().GetValue()
1226 self.log.info("CHOICE FROM COMBOBOX: You Chose '" + selection + "'\n")