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, open_folder, translateprofile, ReadProfileAsDico, write_translation_profile, progressbar, doconcorde
15 from profile_segment import ProfileSegment, ProfilType
16 from search_tools import SearchFrame
17 from dialog import PrefSimpleFile, PrefExport, SearchCorpus, translate_dialog, PrefUCECarac
18 from layout import open_antiprofil, TgenLayout
19 from guifunct import TGenFrame
20 from textaslexico import TgenSpec
21 from textreinert import TgenProf
22 from mergeclustergraph import MergeClusterGraph
24 log = logging.getLogger('iramuteq.tree')
26 def buildmenu(menu, parent_menu):
27 for i in range(parent_menu.GetMenuItemCount()) :
28 item = parent_menu.FindItemByPosition(i)
30 itemtext = item.GetText()
31 itemicon = item.GetBitmap()
32 nitem = wx.MenuItem(menu, itemid, itemtext)
33 nitem.SetBitmap(itemicon)
36 for val in item.GetSubMenu().GetMenuItems() :
38 itemtext = val.GetText()
39 itemicon = val.GetBitmap()
40 nitem = wx.MenuItem(menu, itemid, itemtext)
41 nitem.SetBitmap(itemicon)
42 nmenu.AppendItem(nitem)
43 menu.AppendMenu(-1, item.GetText(), nmenu)
45 menu.AppendItem(nitem)
47 class InfoDialog ( wx.Dialog ):
49 def __init__( self, parent, txt, parametres ):
50 wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Informations", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
51 if len(parametres) > 30 :
55 self.SetSizeHintsSz( wx.Size( 500,200 ), wx.DefaultSize )
57 bSizer1 = wx.BoxSizer( wx.VERTICAL )
59 self.m_panel2 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
60 bSizer2 = wx.BoxSizer( wx.VERTICAL )
62 self.m_staticText4 = wx.StaticText( self.m_panel2, wx.ID_ANY, txt, wx.DefaultPosition, wx.DefaultSize, 0 )
63 self.m_staticText4.Wrap( -1 )
64 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|wx.VSCROLL )
73 fgSizer1 = wx.FlexGridSizer( 0, nb, 0, 0 )
74 fgSizer1.AddGrowableCol( 1 )
76 fgSizer1.AddGrowableCol( 3 )
77 fgSizer1.SetFlexibleDirection( wx.BOTH )
78 fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_NONE )
81 for val in parametres :
82 fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[0], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
83 #fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
84 txtctrl.append( wx.TextCtrl( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, (450, 20), wx.TE_READONLY ) )
85 txtctrl[-1].SetBackgroundColour('#DDE8EB')
86 #wx.SystemSettings.GetColour(wx.SYS_COLOUR_GRAYTEXT))
87 fgSizer1.Add( txtctrl[-1], 0, wx.ALL|wx.EXPAND, 0)
88 #fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND |wx.ALL, 0)
89 #fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND|wx.ALL, 0)
91 self.m_panel1.SetSizer( fgSizer1 )
92 self.m_panel1.Layout()
93 fgSizer1.Fit( self.m_panel1 )
94 bSizer1.Add( self.m_panel1, 1, wx.EXPAND|wx.ALL, 3 )
96 m_sdbSizer1 = wx.StdDialogButtonSizer()
97 self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK )
98 m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
99 m_sdbSizer1.Realize();
101 bSizer1.Add( m_sdbSizer1, 0, wx.EXPAND, 5 )
103 self.SetSizer( bSizer1 )
106 self.Centre( wx.BOTH )
112 class LeftTree(CT.CustomTreeCtrl):
114 def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
116 style=wx.SUNKEN_BORDER|wx.WANTS_CHARS,
117 agwStyle=CT.TR_HIDE_ROOT|CT.TR_HAS_BUTTONS|CT.TR_HAS_VARIABLE_ROW_HEIGHT):
119 CT.CustomTreeCtrl.__init__(self, parent, id, pos, size, style, agwStyle)
120 #FIXME : test for bigger font on HIDPI screen
121 font = wx.Font(pointSize=12, family=wx.DEFAULT, style=wx.NORMAL, weight=wx.FONTWEIGHT_NORMAL,
122 underline=False, face="", encoding=wx.FONTENCODING_DEFAULT)
130 if data.startswith("TR_"):
131 treestyles.append(data)
132 elif data.startswith("EVT_"):
137 self.styles = treestyles
141 self.il = wx.ImageList(16, 16)
143 for img in self.ira.images_analyses :
144 self.ild[img] = self.il.Add(self.ira.images_analyses[img])
145 self.SetImageList(self.il)
150 self.history = parent.history
151 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)
157 idsearchcorpus = wx.NewId()
158 accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('E'), idopenfolder), (wx.ACCEL_CTRL, ord('F'), idsearchcorpus)])
159 self.Bind(wx.EVT_MENU, self.OnSearchCorpus, id=idsearchcorpus)
160 self.SetAcceleratorTable(accel_tbl)
162 self.root = self.AddRoot("Iramuteq")
164 if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
165 self.SetPyData(self.root, None)
166 self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal)
167 self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded)
169 self.textroot = self.AppendItem(self.root, _(u'Textual corpus'))
170 self.SetPyData(self.textroot, {'uuid': 'textroot'})
171 self.SetItemImage(self.textroot, self.ild['textroot'], CT.TreeItemIcon_Normal)
172 self.SetItemImage(self.textroot, self.ild['textroot'], CT.TreeItemIcon_Expanded)
174 for corpus in reversed(self.h) :
175 child = self.AppendItem(self.textroot, corpus['corpus_name'])
176 self.SetPyData(child, corpus)
177 self.SetItemImage(child, self.ild['corpus'], CT.TreeItemIcon_Normal)
178 self.SetItemImage(child, self.ild['corpus'], CT.TreeItemIcon_Expanded)
180 if 'analyses' in corpus :
181 for y in corpus['analyses'] :
182 last = self.AppendItem(child, y['name'], ct_type=0)
183 self.SetPyData(last, y)
184 if y['type'] in self.ild :
185 img = self.ild[y['type']]
188 self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
189 self.SetItemImage(last, img, CT.TreeItemIcon_Expanded)
191 self.matroot = self.AppendItem(self.root, _(u'Matrix'))
192 self.SetPyData(self.matroot, {'uuid': 'matroot'})
193 self.SetItemImage(self.matroot, self.ild['matroot'], CT.TreeItemIcon_Normal)
194 self.SetItemImage(self.matroot, self.ild['matroot'], CT.TreeItemIcon_Expanded)
197 for matrix in reversed(self.history.matrix) :
198 if 'matrix_name' in matrix :
199 child = self.AppendItem(self.matroot, matrix['matrix_name'])
200 self.SetPyData(child, matrix)
201 self.SetItemImage(child, self.ild['matrix'], CT.TreeItemIcon_Normal)
202 self.SetItemImage(child, self.ild['matrix'], CT.TreeItemIcon_Expanded)
203 if 'analyses' in matrix :
204 for y in matrix['analyses'] :
205 last = self.AppendItem(child, y['name'], ct_type=0)
206 self.SetPyData(last, y)
207 if y['type'] in self.ild :
208 img = self.ild[y['type']]
211 self.SetItemImage(last, img, CT.TreeItemIcon_Normal)
212 self.SetItemImage(last, img, CT.TreeItemIcon_Expanded)
214 orphmat.append(matrix)
216 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
217 #self.Bind(wx.EVT_IDLE, self.OnIdle)
219 self.eventdict = {'EVT_TREE_BEGIN_DRAG': self.OnBeginDrag, 'EVT_TREE_BEGIN_LABEL_EDIT': self.OnBeginEdit,
220 'EVT_TREE_BEGIN_RDRAG': self.OnBeginRDrag, 'EVT_TREE_DELETE_ITEM': self.OnDeleteItem,
221 'EVT_TREE_END_DRAG': self.OnEndDrag, 'EVT_TREE_END_LABEL_EDIT': self.OnEndEdit,
222 'EVT_TREE_ITEM_ACTIVATED': self.OnActivate, 'EVT_TREE_ITEM_CHECKED': self.OnItemCheck,
223 'EVT_TREE_ITEM_CHECKING': self.OnItemChecking, 'EVT_TREE_ITEM_COLLAPSED': self.OnItemCollapsed,
224 'EVT_TREE_ITEM_COLLAPSING': self.OnItemCollapsing, 'EVT_TREE_ITEM_EXPANDED': self.OnItemExpanded,
225 'EVT_TREE_ITEM_EXPANDING': self.OnItemExpanding, 'EVT_TREE_ITEM_GETTOOLTIP': self.OnToolTip,
226 'EVT_TREE_ITEM_MENU': self.OnItemMenu, 'EVT_TREE_ITEM_RIGHT_CLICK': self.OnRightDown,
227 'EVT_TREE_KEY_DOWN': self.OnKey, 'EVT_TREE_SEL_CHANGED': self.OnSelChanged,
228 'EVT_TREE_SEL_CHANGING': self.OnSelChanging, "EVT_TREE_ITEM_HYPERLINK": self.OnHyperLink}
230 mainframe = wx.GetTopLevelParent(self)
232 if not hasattr(mainframe, "leftpanel"):
233 #self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded)
234 #self.Bind(CT.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed)
235 self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
236 self.Bind(CT.EVT_TREE_SEL_CHANGING, self.OnSelChanging)
237 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
238 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
240 for combos in mainframe.treeevents:
241 self.BindEvents(combos)
243 if hasattr(mainframe, "leftpanel"):
244 self.ChangeStyle(mainframe.treestyles)
246 if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
247 self.SelectItem(self.root)
248 self.Expand(self.root)
251 def BindEvents(self, choice, recreate=False):
253 value = choice.GetValue()
254 text = choice.GetLabel()
257 binder = self.eventdict[text]
260 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
261 self.Bind(wx.EVT_RIGHT_DOWN, None)
262 self.Bind(wx.EVT_RIGHT_UP, None)
263 self.Bind(eval(evt), binder)
265 self.Bind(eval(evt), None)
266 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
267 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
268 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
271 def ChangeStyle(self, combos):
275 if combo.GetValue() == 1:
276 style = style | eval("CT." + combo.GetLabel())
278 if self.GetAGWWindowStyleFlag() != style:
279 self.SetAGWWindowStyleFlag(style)
282 def OnCompareItems(self, item1, item2):
284 t1 = self.GetItemText(item1)
285 t2 = self.GetItemText(item2)
294 def OnIdle(self, event):
298 # if self.gauge.IsEnabled() and self.gauge.IsShown():
299 # self.count = self.count + 1
301 # if self.count >= 50:
304 # self.gauge.SetValue(self.count)
312 def CloseItem(self, itemParent = None, uuid = None) :
313 if itemParent is None :
314 itemParent = self.root
315 child, cookie = self.GetFirstChild(itemParent)
317 pydata = self.GetPyData(child)
318 if pydata['uuid'] == uuid :
319 self.SetItemBold(child, False)
321 self.CloseItem(child, uuid)
322 child, cookie = self.GetNextChild(itemParent, cookie)
324 def GiveFocus(self, itemParent = None, uuid = None, bold = False) :
325 if itemParent is None :
326 itemParent = self.root
327 child, cookie = self.GetFirstChild(itemParent)
329 pydata = self.GetPyData(child)
330 if pydata['uuid'] == uuid :
331 self.SelectItem(child)
333 self.SetItemBold(child, True)
335 self.GiveFocus(child, uuid, bold)
336 child, cookie = self.GetNextChild(itemParent, cookie)
338 def IsInTree(self, itemParent = None, uuid = None) :
339 if itemParent is None :
340 itemParent = self.root
341 child, cookie = self.GetFirstChild(itemParent)
344 pydata = self.GetPyData(child)
345 if pydata['uuid'] == uuid :
347 self.GiveFocus(child, uuid)
348 child, cookie = self.GetNextChild(itemParent, cookie)
352 def OnRightDown(self, event):
353 pt = event.GetPosition()
354 item, flags = self.HitTest(pt)
358 #self.log.info("OnRightClick: %s, %s, %s" % (self.GetItemText(item), type(item), item.__class__) + "\n")
359 self.SelectItem(item)
362 def OnRightUp(self, event):
370 if not self.IsItemEnabled(item):
374 # Item Text Appearance
375 ishtml = self.IsItemHyperText(item)
376 back = self.GetItemBackgroundColour(item)
377 fore = self.GetItemTextColour(item)
378 isbold = self.IsBold(item)
379 font = self.GetItemFont(item)
382 normal = self.GetItemImage(item, CT.TreeItemIcon_Normal)
383 selected = self.GetItemImage(item, CT.TreeItemIcon_Selected)
384 expanded = self.GetItemImage(item, CT.TreeItemIcon_Expanded)
385 selexp = self.GetItemImage(item, CT.TreeItemIcon_SelectedExpanded)
387 # Enabling/Disabling Windows Associated To An Item
388 haswin = self.GetItemWindow(item)
390 # Enabling/Disabling Items
391 enabled = self.IsItemEnabled(item)
393 # Generic Item's Info
394 children = self.GetChildrenCount(item)
395 itemtype = self.GetItemType(item)
396 text = self.GetItemText(item)
397 pydata = self.GetPyData(item)
401 self.itemdict = {"ishtml": ishtml, "back": back, "fore": fore, "isbold": isbold,
402 "font": font, "normal": normal, "selected": selected, "expanded": expanded,
403 "selexp": selexp, "haswin": haswin, "children": children,
404 "itemtype": itemtype, "text": text, "pydata": pydata, "enabled": enabled}
406 if not item in [self.textroot, self.matroot] :
408 info = wx.MenuItem(menu, wx.ID_ANY, _(u"Informations").decode('utf8'))
409 info.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_INFORMATION, size = (16,16)))
410 menu.AppendItem(info)
412 rename = wx.MenuItem(menu, wx.ID_ANY, _(u"Rename").decode('utf8'))
413 rename.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_TIP, size = (16,16)))
414 menu.AppendItem(rename)
416 openfolder = wx.MenuItem(menu, wx.ID_ANY, _(u"Open directory").decode('utf8'))
417 openfolder.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_FOLDER_OPEN, size = (16,16)))
418 menu.AppendItem(openfolder)
420 menu.AppendSeparator()
422 if 'corpus_name' in pydata :
423 buildmenu(menu, self.parent.text_menu)
424 menu.AppendSeparator()
425 elif 'matrix_name' in pydata :
426 buildmenu(menu, self.parent.matrix_menu)
427 menu.AppendSeparator()
428 elif pydata.get('type', False) == 'alceste' and pydata['uuid'] in self.parent.history.opened :
430 antipro = openmenu.Append(wx.ID_ANY, _(u"Antiprofiles").decode('utf8'))
431 menu.AppendMenu(wx.ID_ANY, _(u"Open ...").decode('utf8'), openmenu)
433 translate = menu.Append(wx.ID_ANY, _(u"Translate Profile").decode('utf8'))
434 profsr = menu.Append(wx.ID_ANY, _(u"Repeated segments profiles").decode('utf8'))
435 profgram = menu.Append(wx.ID_ANY, _(u"POS profiles").decode('utf8'))
436 stcaract = menu.Append(wx.ID_ANY, _(u"Typical text segments").decode('utf8'))
437 tgen = menu.Append(wx.ID_ANY, _(u"Tgen Editor").decode('utf8'))
438 computetgen = menu.Append(wx.ID_ANY, _(u"Compute Tgen").decode('utf8'))
439 mergeclustergraph = menu.Append(wx.ID_ANY, _(u"Merge Cluster Graph").decode('utf8'))
440 export_corpus = menu.Append(wx.ID_ANY, _(u"Export corpus").decode('utf8'))
441 colored = menu.Append(wx.ID_ANY, _(u"Colored corpus").decode('utf8'))
442 navig = menu.Append(wx.ID_ANY, _(u"Navigator").decode('utf8'))
443 statclasse = menu.Append(wx.ID_ANY, _(u"Clusters statistics").decode('utf8'))
444 rapport = menu.Append(wx.ID_ANY, _(u"Report").decode('utf8'))
445 export_classes = menu.Append(wx.ID_ANY, _(u"Export clusters").decode('utf8'))
446 subcorpusfromcl = menu.Append(wx.ID_ANY, _(u"Sub corpus from clusters").decode('utf8'))
447 menu.AppendSeparator()
448 self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
449 self.Bind(wx.EVT_MENU, self.OnTranslate, translate)
450 self.Bind(wx.EVT_MENU, self.OnProfSR, profsr)
451 self.Bind(wx.EVT_MENU, self.OnProfGram, profgram)
452 self.Bind(wx.EVT_MENU, self.OnStCaract, stcaract)
453 self.Bind(wx.EVT_MENU, self.OnTgenEditor, tgen)
454 self.Bind(wx.EVT_MENU, self.OnTgenCompute, computetgen)
455 self.Bind(wx.EVT_MENU, self.OnMergeClusterGraph, mergeclustergraph)
456 self.Bind(wx.EVT_MENU, self.OnExportCorpus, export_corpus)
457 self.Bind(wx.EVT_MENU, self.OnColored, colored)
458 self.Bind(wx.EVT_MENU, self.OnNavig, navig)
459 self.Bind(wx.EVT_MENU, self.StatClasse, statclasse)
460 self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
461 self.Bind(wx.EVT_MENU, self.OnExportClasses, export_classes)
462 self.Bind(wx.EVT_MENU, self.OnSubCorpusFromClusters, subcorpusfromcl)
463 elif pydata.get('type', False) == 'stat' and pydata['uuid'] in self.parent.history.opened :
464 export_dictionary = menu.Append(wx.ID_ANY, _(u"Export dictionary").decode('utf8'))
465 export_lems = menu.Append(wx.ID_ANY, _(u"Export lemma dictionary").decode('utf8'))
466 export_cut_corpus = menu.Append(wx.ID_ANY, _(u"Export segmented corpus").decode('utf8'))
467 self.Bind(wx.EVT_MENU, self.OnExportDictionary, export_dictionary)
468 self.Bind(wx.EVT_MENU, self.OnExportLems, export_lems)
469 self.Bind(wx.EVT_MENU, self.OnExportCutCorpus, export_cut_corpus)
470 menu.AppendSeparator()
471 elif pydata.get('type', False) == 'spec' and pydata['uuid'] in self.parent.history.opened :
472 tgen = menu.Append(wx.ID_ANY, _(u"Tgen Editor").decode('utf8'))
473 computetgen = menu.Append(wx.ID_ANY, _(u"Compute Tgen").decode('utf8'))
474 self.Bind(wx.EVT_MENU, self.OnTgenEditor, tgen)
475 self.Bind(wx.EVT_MENU, self.OnTgenCompute, computetgen)
476 menu.AppendSeparator()
477 elif pydata.get('type', False) == 'reinertmatrix' and pydata['uuid'] in self.parent.history.opened :
479 antipro = openmenu.Append(wx.ID_ANY, _(u"antiprofiles").decode('utf8'))
480 rapport = menu.Append(wx.ID_ANY, _(u"Report").decode('utf8'))
481 menu.AppendMenu(wx.ID_ANY, _(u"Open ...").decode('utf8'), openmenu)
482 self.Bind(wx.EVT_MENU, self.OpenAntipro, antipro)
483 self.Bind(wx.EVT_MENU, self.OnRapport, rapport)
485 itemdelete = wx.MenuItem(menu, wx.ID_ANY, _(u"Delete from history").decode('utf8'))
486 itemdelete.SetBitmap(wx.ArtProvider_GetBitmap(wx.ART_DELETE, size = (16,16)))
487 menu.AppendItem(itemdelete)
488 #item11 = menu.Append(wx.ID_ANY, "Prepend An Item")
489 #item12 = menu.Append(wx.ID_ANY, "Append An Item")
491 #self.Bind(wx.EVT_MENU, self.OnItemBackground, item1)
492 #self.Bind(wx.EVT_MENU, self.OnItemForeground, item2)
493 #self.Bind(wx.EVT_MENU, self.OnItemBold, item3)
494 #self.Bind(wx.EVT_MENU, self.OnItemFont, item4)
495 #self.Bind(wx.EVT_MENU, self.OnItemHyperText, item5)
496 #self.Bind(wx.EVT_MENU, self.OnEnableWindow, item6)
497 #self.Bind(wx.EVT_MENU, self.OnDisableItem, item7)
498 #self.Bind(wx.EVT_MENU, self.OnItemIcons, item8)
499 self.Bind(wx.EVT_MENU, self.OnItemInfo, info)
500 self.Bind(wx.EVT_MENU, self.OnRename, rename)
501 self.Bind(wx.EVT_MENU, self.OnItemDelete, itemdelete)
502 self.Bind(wx.EVT_MENU, self.OnOpenFolder, openfolder)
503 #self.Bind(wx.EVT_MENU, self.OnItemPrepend, item11)
504 #self.Bind(wx.EVT_MENU, self.OnItemAppend, item12)
510 busy = wx.BusyInfo(_("Please wait...Reading corpus").decode('utf8'), self.parent)
512 if self.pydata['uuid'] in self.parent.history.openedcorpus :
513 corpus = copycorpus(self.parent.history.openedcorpus[self.pydata['uuid']])
514 elif 'corpus_name' in self.pydata :
515 corpus = Corpus(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('corpus'), read = True)
517 cuuid = self.pydata['corpus']
518 if cuuid in self.parent.history.openedcorpus :
519 corpus = copycorpus(self.parent.history.openedcorpus[cuuid])
521 irapath = self.parent.history.corpus[cuuid]['ira']
522 corpus = Corpus(self.parent, parametres = DoConf(irapath).getoptions('corpus'), read = True)
527 if 'matrix_name' in self.pydata :
528 matrix = Tableau(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('matrix'))
530 return copymatrix(matrix)
532 cuuid = self.pydata['matrix']
533 matrix = Tableau(self.parent, parametres = DoConf(self.history.matrixanalyse[cuuid]['ira']).getoptions('matrix'))
535 return copymatrix(matrix)
537 def OnSpec(self, evt) :
538 self.parent.OnTextSpec(evt, self.getcorpus())
540 def OnStat(self, evt) :
541 self.parent.OnTextStat(evt, self.getcorpus())
543 def OnReinert(self, evt) :
544 self.parent.OnTextReinert(evt, self.getcorpus())
546 def OnPam(self, evt) :
547 self.parent.OnPamSimple(evt, self.getcorpus())
549 def OnSimiTxt(self, evt) :
550 self.parent.OnSimiTxt(evt, self.getcorpus())
552 def OnWordCloud(self, evt) :
553 self.parent.OnWordCloud(evt, self.getcorpus())
555 # def OnFreq(self, evt):
556 # self.parent.OnFreq(evt, self.getmatrix())
558 # def OnChiSquare(self, evt):
559 # self.parent.OnChi2(evt, self.getmatrix())
561 # def OnSimiTab(self, evt):
562 # self.parent.OnSimiTab(evt, self.getmatrix())
564 # def OnProto(self, evt):
565 # self.parent.OnProto(evt, self.getmatrix())
567 # def OnSplitFromVar(self, evt):
568 # self.parent.OnSplitVar(evt, self.getmatrix())
570 # def OnCHDReinert(self, evt):
571 # self.parent.OnCHDReinert(evt, self.getmatrix())
573 #def OnSubTextFromMeta(self, evt):
574 # self.parent.OnSubText(self.getcorpus(), parametres = {'frommeta' : True})
576 #def OnSubTextFromTheme(self, evt):
577 # self.parent.OnSubText(self.getcorpus(), parametres = {'fromtheme' : True})
579 def OnProfSR(self, evt) :
580 ProfileSegment(self.parent, self.page.dictpathout, self.page.parametres, self.page.corpus)
582 def OnProfGram(self, evt) :
583 ProfilType(self.parent, self.page.corpus, self.page.parametres)
585 def OnMergeClusterGraph(self, evt) :
586 MergeClusterGraph(self.parent, self.page.corpus, self.page.parametres)
589 def OnStCaract(self, evt) :
590 dial = PrefUCECarac(self, self.parent)
591 dial.CenterOnParent()
592 if self.page.parametres['classif_mode'] != 2 :
597 if dial.ShowModal() == wx.ID_OK :
598 limite = dial.spin_eff.GetValue()
599 atype = dial.radio_type.GetSelection()
601 corpus = self.page.corpus
602 dlg = progressbar(self.ira, maxi = len(corpus.lc))
603 dlg.Update(1, 'wait...')
604 for i in range(0, len(corpus.lc)) :
605 page = self.page.ProfNB.GetPage(i)
607 dlg.Update(i, u'Cluster %i' % (i+1))
608 uces = corpus.lc[rcl]
609 tab = corpus.make_table_with_classe(uces, page.la, uci = uci)
612 ntab = [round(sum([page.lchi[j] for j, word in enumerate(line) if word == 1]),2) for line in tab]
614 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]
615 ntab2 = [[ntab[j], uces[j]] for j, val in enumerate(ntab)]
617 ntab2.sort(reverse = True)
618 ntab2 = ntab2[:limite]
619 nuces = [val[1] for val in ntab2]
620 ucis_txt, ucestxt = doconcorde(corpus, nuces, page.la, uci = uci)
621 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)]
622 filename = self.page.pathout['st_caract_cl_%i.html' % (rcl+1)]
623 with open(filename, 'w') as f :
624 f.write('\n'.join(items))
628 def OnExportCorpus(self, evt) :
629 dial = PrefExport(self, self.parent)
630 dial.fbb.SetValue(os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'export_corpus.txt'))
631 dial.CenterOnParent()
632 res = dial.ShowModal()
634 if dial.radio_type.GetSelection() == 0 : alc = True
636 if dial.radio_lem.GetSelection() == 0 : lem = True
638 if self.page.parametres['classif_mode'] != 2 :
642 self.page.corpus.export_corpus_classes(dial.fbb.GetValue(), alc = alc, lem = lem, uci = uci)
645 dlg = wx.MessageDialog(self.parent, msg, u"Export", wx.OK | wx.ICON_INFORMATION)
650 def OnExportCutCorpus(self, evt) :
652 fileout = os.path.join(os.path.dirname(self.page.pathout['ira']), 'segmented_corpus.txt')
653 txt = self.page.corpus.make_cut_corpus(uci = uci)
654 with open(fileout, 'w') as f :
656 msg = '\n'.join([_(u"Done !").decode('utf8'), fileout])
657 dlg = wx.MessageDialog(self.parent, msg, _(u"Segmented corpus"), wx.OK | wx.ICON_INFORMATION)
663 def OnColored(self, evt) :
664 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.html', 'title': _(u"Colored corpus").decode('utf8')})
665 dial.fbb.SetValue(os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'corpus_couleur.html'))
666 dial.CenterOnParent()
667 res = dial.ShowModal()
669 fileout = dial.fbb.GetValue()
671 if self.page.parametres['classif_mode'] != 2 :
675 txt = self.page.corpus.make_colored_corpus(uci = uci)
676 with open(fileout, 'w') as f :
678 msg = ' !\n'.join([_(u"Done").decode('utf8'), _(u"Open in a web browser ?").decode('utf8')])
679 dlg = wx.MessageDialog(self.parent, msg, u"Corpus en couleur", wx.NO | wx.YES | wx.ICON_QUESTION)
681 if dlg.ShowModal() == wx.ID_YES :
682 webbrowser.open(fileout)
685 def OnNavig(self, evt):
686 if 'FrameSearch' not in dir(self.page) :
687 self.page.FrameSearch = SearchFrame(self.parent, -1, _(u"Search ...").decode('utf8'), self.page.corpus)
688 self.page.FrameSearch.Show()
690 def StatClasse(self, evt):
691 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.csv', 'title': _(u"Clusters statistics").decode('utf8')})
692 dial.fbb.SetValue( os.path.join(os.path.dirname(self.page.dictpathout['ira']), 'stat_par_classe.csv'))
693 dial.CenterOnParent()
694 res = dial.ShowModal()
696 fileout = dial.fbb.GetValue()
698 self.page.corpus.get_stat_by_cluster(fileout)
700 dlg = wx.MessageDialog(self.parent, msg, _(u"Clusters statistics").decode('utf8'), wx.OK | wx.ICON_INFORMATION)
702 if dlg.ShowModal() == wx.ID_OK :
705 def OpenAntipro(self, evt) :
707 for i in range(0, self.page.TabChdSim.GetPageCount()) :
708 page = self.page.TabChdSim.GetPage(i)
709 if self.page.TabChdSim.GetPageText(i) == _(u"Antiprofiles").decode('utf8') :
710 self.page.TabChdSim.SetSelection(i)
714 open_antiprofil(self.page, self.page.dictpathout['ANTIPRO_OUT'], self.parent.syscoding)
715 self.page.TabChdSim.SetSelection(self.page.TabChdSim.GetPageCount() - 1)
717 def OnTranslate(self, evt) :
718 dial = translate_dialog(self.parent)
719 dial.CenterOnParent()
720 res = dial.ShowModal()
722 to_l = dial.getto_l()
723 from_l = dial.getfrom_l()
725 busy = wx.BusyInfo(_("Please wait...").decode('utf8'), self.parent)
727 prof, lems = translateprofile(self.page.corpus, ReadProfileAsDico(self.page.dictpathout['PROFILE_OUT'], True, self.parent.syscoding), lf=from_l, lt=to_l)
728 write_translation_profile(prof, lems, to_l, self.page.dictpathout)
729 open_antiprofil(self.page, prof, 'utf8', title = _(u'Translation').decode('utf8') + ' %s' % to_l, translation = True, lems=lems)
731 self.page.lems = lems
732 self.page.TabChdSim.SetSelection(self.page.TabChdSim.GetPageCount() - 1)
736 def OnRapport(self, evt) :
737 dial = PrefSimpleFile(self, self.parent, **{'mask' : '*.txt', 'title': _(u"Report").decode('utf8')})
738 dial.fbb.SetValue(self.page.dictpathout['rapport'])
739 dial.CenterOnParent()
740 res = dial.ShowModal()
742 fileout = dial.fbb.GetValue()
744 with open(fileout, 'w') as f :
745 f.write(self.page.debtext + '\n' + GetTxtProfile(self.page.DictProfile, self.page.cluster_size))
747 dlg = wx.MessageDialog(self.parent, msg, _(u"Report").decode('utf8'), wx.OK | wx.ICON_INFORMATION)
754 def OnExportDictionary(self, evt) :
755 corpus = self.page.corpus
756 corpus.export_dictionary(self.page.pathout['dictionary.csv'], self.parent.syscoding)
757 log.info('export dictionary %s' % self.page.pathout['dictionary.csv'])
758 dial = wx.MessageDialog(self.parent, self.page.pathout['dictionary.csv'], 'Export', wx.OK)
762 def OnExportLems(self, evt) :
763 corpus = self.page.corpus
764 corpus.export_lems(self.page.pathout['lemmes.csv'], self.parent.syscoding)
765 log.info('export lemmes %s' % self.page.pathout['lemmes.csv'])
766 dial = wx.MessageDialog(self.parent, self.page.pathout['lemmes.csv'], 'Export', wx.OK)
770 def OnTgenEditor(self, evt):
771 corpus = self.page.corpus
772 tgenpath = os.path.join(self.page.parametres['pathout'], 'tgen.csv')
773 tgen = TGen(path = tgenpath, encoding = self.parent.syscoding)
774 if os.path.exists(tgenpath) :
776 if isinstance(evt, list) :
778 while 'tgen%i' %i in tgen.tgen :
780 tgenname = 'tgen%i' %i
781 tgen.tgen[tgenname] = evt
782 tgenframe = TGenFrame(self.parent, corpus, tgen)
784 if isinstance(evt, list) :
785 tgenframe.OnNewTgen(None, tgen = tgenname)
787 def OnTgenCompute(self, evt):
788 corpus = self.page.corpus
789 tgenpath = os.path.join(self.page.parametres['pathout'], 'tgen.csv')
790 if not os.path.exists(tgenpath) :
791 message = wx.MessageDialog(self.parent, _(u"No TGen yet !").decode('utf8'), style = wx.ICON_EXCLAMATION | wx.OK)
795 self.page.parametres['tgenpath'] = tgenpath
796 tgen = TGen(path = tgenpath, encoding = self.parent.syscoding)
797 if self.page.parametres['type'] == 'spec' :
798 self.page.parametres['etoiles'] = self.page.etoiles
799 TgenSpec(self.parent, corpus, self.page.parametres)
800 elif self.page.parametres['type'] == 'alceste' :
801 TgenProf(self.parent, corpus, self.page.parametres, self.page.cluster_size)
802 TgenLayout(self.page)
804 def OnExportClasses(self, event):
805 corpus = self.page.corpus
806 if self.page.parametres['classif_mode'] != 2 :
810 busy = wx.BusyInfo(_("Please wait...").decode('utf8'), self.parent)
812 for i in range(1, self.page.parametres['clnb'] + 1) :
813 corpus.export_classe(self.page.pathout['classe_%i_export.txt' % i], i, uci = uci)
815 dial = wx.MessageDialog(self, self.page.pathout['classe_x_export.txt'], u"Export", wx.OK|wx.ICON_INFORMATION)
819 def OnSubCorpusFromClusters(self, evt):
820 self.parent.OnSubText(evt, corpus = self.getcorpus(), parametres = {'fromclusters' : True, 'clnb': self.page.parametres['clnb'], 'lc' : self.page.corpus.lc})
822 def OnRename(self, event):
823 pydata = self.itemdict['pydata']
824 if 'matrix_name' in pydata :
826 elif 'corpus_name' in pydata :
830 oldname = pydata[name]
831 dlg = wx.TextEntryDialog(self, _("New Name").decode('utf8'), _(u'Rename').decode('utf8'), oldname)
832 if dlg.ShowModal() == wx.ID_OK:
833 newname = dlg.GetValue()
835 pydata[name] = newname
836 Totconf = DoConf(configfile=pydata['ira'])
837 conf = Totconf.getoptions()
839 Totconf.makeoptions(Totconf.getsections(), [conf])
840 self.history.update(pydata)
841 self.SetItemText(self.current, newname)
842 self.EnsureVisible(self.current)
844 def OnOpenFolder(self, evt):
846 open_folder(os.path.dirname(self.pydata['ira']))
848 print 'cannot open folder %s' % self.pydata.get('ira', 'noirapath')
850 def GetCorpusByName(self, corpus_name) :
851 return [corpus for corpus in self.h if corpus_name in corpus['corpus_name']]
853 def OnSearchCorpus(self, evt):
854 searchframe = SearchCorpus(self.ira, self, None, None)
856 #res = self.GetCorpusByName('Ministres')
859 def SetContentBackground(self, itemParent = None, uuid = None, color = True) :
860 if itemParent is None :
861 itemParent = self.root
862 child, cookie = self.GetFirstChild(itemParent)
864 pydata = self.GetPyData(child)
865 if pydata['uuid'] == uuid :
866 self.SelectItem(child)
868 self.SetItemBackgroundColour(child, wx.Colour(15,234,56))
870 self.SetContentBackground(child, uuid, color)
871 child, cookie = self.GetNextChild(itemParent, cookie)
874 def OnItemBackground(self, event):
876 colourdata = wx.ColourData()
877 colourdata.SetColour(self.itemdict["back"])
878 dlg = wx.ColourDialog(self, colourdata)
880 dlg.GetColourData().SetChooseFull(True)
882 if dlg.ShowModal() == wx.ID_OK:
883 data = dlg.GetColourData()
884 col1 = data.GetColour().Get()
885 self.SetItemBackgroundColour(self.current, col1)
889 def OnItemForeground(self, event):
891 colourdata = wx.ColourData()
892 colourdata.SetColour(self.itemdict["fore"])
893 dlg = wx.ColourDialog(self, colourdata)
895 dlg.GetColourData().SetChooseFull(True)
897 if dlg.ShowModal() == wx.ID_OK:
898 data = dlg.GetColourData()
899 col1 = data.GetColour().Get()
900 self.SetItemTextColour(self.current, col1)
904 def OnItemBold(self, event):
906 self.SetItemBold(self.current, not self.itemdict["isbold"])
909 def OnItemFont(self, event):
912 font = self.itemdict["font"]
915 font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
917 data.SetInitialFont(font)
919 dlg = wx.FontDialog(self, data)
921 if dlg.ShowModal() == wx.ID_OK:
922 data = dlg.GetFontData()
923 font = data.GetChosenFont()
924 self.SetItemFont(self.current, font)
929 def OnItemHyperText(self, event):
931 self.SetItemHyperText(self.current, not self.itemdict["ishtml"])
934 def OnEnableWindow(self, event):
936 enable = self.GetItemWindowEnabled(self.current)
937 self.SetItemWindowEnabled(self.current, not enable)
940 def OnDisableItem(self, event):
942 self.EnableItem(self.current, False)
945 def OnItemIcons(self, event):
947 bitmaps = [self.itemdict["normal"], self.itemdict["selected"],
948 self.itemdict["expanded"], self.itemdict["selexp"]]
951 dlg = TreeIcons(self, -1, bitmaps=bitmaps)
956 def SetNewIcons(self, bitmaps):
958 self.SetItemImage(self.current, bitmaps[0], CT.TreeItemIcon_Normal)
959 self.SetItemImage(self.current, bitmaps[1], CT.TreeItemIcon_Selected)
960 self.SetItemImage(self.current, bitmaps[2], CT.TreeItemIcon_Expanded)
961 self.SetItemImage(self.current, bitmaps[3], CT.TreeItemIcon_SelectedExpanded)
964 def OnItemInfo(self, event):
966 itemtext = self.itemdict["text"]
967 numchildren = str(self.itemdict["children"])
968 itemtype = self.itemdict["itemtype"]
969 pydata = self.itemdict['pydata']
970 #if 'analyses' in pydata :
971 # toshow = dict([[val, pydata[val]] for val in pydata if val not in['analyses', 'isload']])
973 toshow = pydata['ira']
974 toshow = DoConf(toshow).getoptions()
975 txt = DoConf().totext(toshow)
976 parametres = [val.split('\t\t:') for val in txt.splitlines()]
982 itemtype = "CheckBox"
984 itemtype = "RadioButton"
986 dlg = InfoDialog(self, itemtext, parametres)
993 def OnItemDelete(self, event):
995 strs = "Are You Sure You Want To Delete Item " + self.GetItemText(self.current) + "?"
996 dlg = wx.MessageDialog(None, strs, 'Deleting Item', wx.OK | wx.CANCEL | wx.ICON_QUESTION)
998 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
1004 pydata = self.itemdict['pydata']
1005 if 'corpus_name' in pydata :
1006 self.history.delete(pydata, True)
1008 self.history.delete(pydata)
1009 self.DeleteChildren(self.current)
1010 self.Delete(self.current)
1015 def OnItemPrepend(self, event):
1017 dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
1019 if dlg.ShowModal() == wx.ID_OK:
1020 newname = dlg.GetValue()
1021 newitem = self.PrependItem(self.current, newname)
1022 self.EnsureVisible(newitem)
1026 def AddAnalyse(self, parametres, itemParent = None, bold = True) :
1027 uuid = parametres.get('corpus', None)
1028 if uuid is not None :
1029 if itemParent is None :
1030 itemParent = self.textroot
1031 child, cookie = self.GetFirstChild(itemParent)
1034 pydata = self.GetPyData(child)
1035 if pydata['uuid'] == uuid :
1038 self.GiveFocus(child, uuid)
1039 child, cookie = self.GetNextChild(itemParent, cookie)
1040 #item = self.AppendItem(child, parametres['name'])
1041 if corpus is not None :
1042 item = self.AppendItem(corpus, parametres['name'])
1044 item = self.AppendItem(self.textroot, parametres['name'])
1046 item = self.AppendItem(self.matroot, parametres['name'])
1047 self.SetPyData(item, parametres)
1048 if parametres['type'] in self.ild :
1049 img = self.ild[parametres['type']]
1052 self.SetItemImage(item, img, CT.TreeItemIcon_Normal)
1053 self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
1054 self.SetItemBold(item, bold)
1055 self.SelectItem(item)
1057 def AddMatAnalyse(self, parametres, itemParent = None, bold = True) :
1058 uuid = parametres.get('matrix', None)
1059 if uuid is not None :
1060 if itemParent is None :
1061 itemParent = self.matroot
1062 child, cookie = self.GetFirstChild(itemParent)
1065 pydata = self.GetPyData(child)
1066 if pydata['uuid'] == uuid :
1069 self.GiveFocus(child, uuid)
1070 child, cookie = self.GetNextChild(itemParent, cookie)
1071 #item = self.AppendItem(child, parametres['name'])
1072 if matrix is not None :
1073 item = self.AppendItem(matrix, parametres['name'])
1075 item = self.AppendItem(self.matroot, parametres['name'])
1076 self.SetPyData(item, parametres)
1077 if parametres['type'] in self.ild :
1078 img = self.ild[parametres['type']]
1081 self.SetItemImage(item, img, CT.TreeItemIcon_Normal)
1082 self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
1083 self.SetItemBold(item, bold)
1084 self.SelectItem(item)
1086 def OnItemAppend(self, item, select = True):
1087 if 'corpus_name' in item :
1088 child = self.InsertItem(self.textroot, 0, item['corpus_name'])
1090 child = self.InsertItem(self.matroot, 0, item['matrix_name'])
1091 self.SetPyData(child, item)
1092 if item['type'] in self.ild :
1093 img = self.ild[item['type']]
1096 self.SetItemImage(child, img, CT.TreeItemIcon_Normal)
1097 self.SetItemImage(child, img, CT.TreeItemIcon_Expanded)
1099 self.history.addtab(item)
1100 self.SetItemBold(child, True)
1101 self.SelectItem(child)
1103 #dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
1105 #if dlg.ShowModal() == wx.ID_OK:
1106 # newname = dlg.GetValue()
1107 # newitem = self.AppendItem(self.current, newname)
1108 # self.EnsureVisible(newitem)
1114 def OnBeginEdit(self, event):
1116 #self.log.info("OnBeginEdit" + "\n")
1117 # show how to prevent edit...
1118 item = event.GetItem()
1119 if item and self.GetItemText(item) == "The Root Item":
1121 #self.log.info("You can't edit this one..." + "\n")
1123 # Lets just see what's visible of its children
1125 root = event.GetItem()
1126 (child, cookie) = self.GetFirstChild(root)
1129 #self.log.info("Child [%s] visible = %d" % (self.GetItemText(child), self.IsVisible(child)) + "\n")
1130 (child, cookie) = self.GetNextChild(root, cookie)
1135 def OnEndEdit(self, event):
1137 #self.log.info("OnEndEdit: %s %s" %(event.IsEditCancelled(), event.GetLabel()))
1138 # show how to reject edit, we'll not allow any digits
1139 for x in event.GetLabel():
1140 if x in string.digits:
1141 #self.log.info(", You can't enter digits..." + "\n")
1148 def OnLeftDClick(self, event):
1149 pt = event.GetPosition()
1150 item, flags = self.HitTest(pt)
1151 if item is not None :
1152 pydata = self.GetPyData(item)
1153 if pydata['uuid'] in self.parent.history.opened :
1154 for i in range(self.parent.nb.GetPageCount()) :
1155 page = self.parent.nb.GetPage(i)
1156 if 'parametres' in dir(page) :
1157 if page.parametres['uuid'] == pydata['uuid'] :
1158 self.parent.nb.SetSelection(i)
1160 elif pydata['uuid'] in ['textroot', 'matroot'] :
1163 if os.path.exists(pydata['ira']) :
1164 busy = wx.BusyInfo(_("Please wait..."), self.parent)
1167 OpenAnalyse(self.parent, pydata)
1169 self.SetItemBold(item, True)
1170 self.OnSelChanged(pydata = pydata)
1175 wx.MessageBox(_(u"This file does not exist : %s" % pydata['ira']).decode('utf8'), 'Information', wx.ICON_EXCLAMATION | wx.STAY_ON_TOP )
1176 #if item and (flags & CT.TREE_HITTEST_ONITEMLABEL):
1177 # if self.GetAGWWindowStyleFlag() & CT.TR_EDIT_LABELS:
1178 # self.log.info("OnLeftDClick: %s (manually starting label edit)"% self.GetItemText(item) + "\n")
1180 #self.EditLabel(item)
1182 # pydata = self.GetPyData(item)
1184 # self.log.info("OnLeftDClick: Cannot Start Manual Editing, Missing Style TR_EDIT_LABELS\n")
1189 def OnItemExpanded(self, event):
1191 item = event.GetItem()
1193 self.log.info("OnItemExpanded: %s" % self.GetItemText(item) + "\n")
1196 def OnItemExpanding(self, event):
1198 item = event.GetItem()
1200 self.log.info("OnItemExpanding: %s" % self.GetItemText(item) + "\n")
1205 def OnItemCollapsed(self, event):
1207 item = event.GetItem()
1209 self.log.info("OnItemCollapsed: %s" % self.GetItemText(item) + "\n")
1212 def OnItemCollapsing(self, event):
1214 item = event.GetItem()
1216 self.log.info("OnItemCollapsing: %s" % self.GetItemText(item) + "\n")
1221 def OnSelChanged(self, event = None, pydata = None):
1222 if event is not None :
1223 item = event.GetItem()
1224 pydata = self.GetPyData(item)
1226 if pydata is not None :
1227 if 'corpus_name' in pydata or 'corpus' in pydata :
1228 self.ira.ShowMenu('matrix', False)
1229 self.ira.ShowMenu('text', True)
1230 if 'matrix_name' in pydata or 'matrix' in pydata:
1231 self.ira.ShowMenu('text', False)
1232 self.ira.ShowMenu('matrix', True)
1233 if 'uuid' in pydata :
1234 if pydata['uuid'] in ['textroot', 'matroot'] :
1235 self.ira.ShowMenu('text', False)
1236 self.ira.ShowMenu('matrix', False)
1237 self.pydata = pydata
1238 if pydata['uuid'] in self.parent.history.opened :
1239 for i in range(self.parent.nb.GetPageCount()) :
1240 self.page = self.parent.nb.GetPage(i)
1241 if 'parametres' in dir(self.page) :
1242 if self.page.parametres['uuid'] == pydata['uuid'] :
1243 self.parent.nb.SetSelection(i)
1245 if event is not None :
1249 def OnSelChanging(self, event):
1251 item = event.GetItem()
1252 olditem = event.GetOldItem()
1256 olditemtext = "None"
1258 olditemtext = self.GetItemText(olditem)
1259 #self.log.info("OnSelChanging: From %s" % olditemtext + " To %s" % self.GetItemText(item) + "\n")
1264 def OnBeginDrag(self, event):
1266 self.item = event.GetItem()
1268 self.log.info("Beginning Drag..." + "\n")
1273 def OnBeginRDrag(self, event):
1275 self.item = event.GetItem()
1277 self.log.info("Beginning Right Drag..." + "\n")
1282 def OnEndDrag(self, event):
1284 self.item = event.GetItem()
1286 self.log.info("Ending Drag!" + "\n")
1291 def OnDeleteItem(self, event):
1293 item = event.GetItem()
1298 self.log.info("Deleting Item: %s" % self.GetItemText(item) + "\n")
1302 def OnItemCheck(self, event):
1304 item = event.GetItem()
1305 self.log.info("Item " + self.GetItemText(item) + " Has Been Checked!\n")
1309 def OnItemChecking(self, event):
1311 item = event.GetItem()
1312 self.log.info("Item " + self.GetItemText(item) + " Is Being Checked...\n")
1316 def OnToolTip(self, event):
1318 item = event.GetItem()
1320 event.SetToolTip(wx.ToolTip(self.GetItemText(item)))
1323 def OnItemMenu(self, event):
1325 item = event.GetItem()
1327 self.log.info("OnItemMenu: %s" % self.GetItemText(item) + "\n")
1332 def OnKey(self, event):
1334 keycode = event.GetKeyCode()
1335 keyname = keyMap.get(keycode, None)
1337 if keycode == wx.WXK_BACK:
1338 self.log.info("OnKeyDown: HAHAHAHA! I Vetoed Your Backspace! HAHAHAHA\n")
1342 if "unicode" in wx.PlatformInfo:
1343 keycode = event.GetUnicodeKey()
1345 keycode = event.GetKeyCode()
1346 keyname = "\"" + unichr(event.GetUnicodeKey()) + "\""
1348 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1354 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
1356 keyname = "\"%s\"" % chr(keycode)
1358 keyname = "unknown (%s)" % keycode
1360 self.log.info("OnKeyDown: You Pressed '" + keyname + "'\n")
1365 def OnActivate(self, event):
1368 self.log.info("OnActivate: %s" % self.GetItemText(self.item) + "\n")
1373 def OnHyperLink(self, event):
1375 item = event.GetItem()
1377 self.log.info("OnHyperLink: %s" % self.GetItemText(self.item) + "\n")
1380 def OnTextCtrl(self, event):
1382 char = chr(event.GetKeyCode())
1383 self.log.info("EDITING THE TEXTCTRL: You Wrote '" + char + \
1384 "' (KeyCode = " + str(event.GetKeyCode()) + ")\n")
1388 def OnComboBox(self, event):
1390 selection = event.GetEventObject().GetValue()
1391 self.log.info("CHOICE FROM COMBOBOX: You Chose '" + selection + "'\n")