2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2012, Pierre Ratinaud
8 import wx.lib.agw.customtreectrl as CT
10 from openanalyse import OpenAnalyse
11 from corpusNG import Corpus, copycorpus
12 from functions import DoConf
15 log = logging.getLogger('iramuteq.tree')
16 #from agw import customtreectrl as CT
18 class InfoDialog ( wx.Dialog ):
20 def __init__( self, parent, txt, parametres ):
21 wx.Dialog.__init__ ( self, parent, id = wx.ID_ANY, title = u"Informations", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_DIALOG_STYLE )
23 self.SetSizeHintsSz( wx.Size( 400,200 ), wx.DefaultSize )
25 bSizer1 = wx.BoxSizer( wx.VERTICAL )
27 self.m_panel2 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
28 bSizer2 = wx.BoxSizer( wx.VERTICAL )
30 self.m_staticText4 = wx.StaticText( self.m_panel2, wx.ID_ANY, txt, wx.DefaultPosition, wx.DefaultSize, 0 )
31 self.m_staticText4.Wrap( -1 )
32 bSizer2.Add( self.m_staticText4, 0, wx.ALL, 5 )
35 self.m_panel2.SetSizer( bSizer2 )
36 self.m_panel2.Layout()
37 bSizer2.Fit( self.m_panel2 )
38 bSizer1.Add( self.m_panel2, 0, wx.EXPAND |wx.ALL, 5 )
40 self.m_panel1 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
41 fgSizer1 = wx.FlexGridSizer( 0, 2, 0, 0 )
42 fgSizer1.SetFlexibleDirection( wx.BOTH )
43 fgSizer1.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_SPECIFIED )
45 for val in parametres :
46 fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[0], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
47 fgSizer1.Add( wx.StaticText( self.m_panel1, wx.ID_ANY, val[1], wx.DefaultPosition, wx.DefaultSize, 0 ), 0, wx.ALL, 0)
48 fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND |wx.ALL, 0)
49 fgSizer1.Add( wx.StaticLine( self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ), 0, wx.EXPAND|wx.ALL, 0)
51 self.m_panel1.SetSizer( fgSizer1 )
52 self.m_panel1.Layout()
53 fgSizer1.Fit( self.m_panel1 )
54 bSizer1.Add( self.m_panel1, 0, wx.EXPAND |wx.ALL, 3 )
56 m_sdbSizer1 = wx.StdDialogButtonSizer()
57 self.m_sdbSizer1OK = wx.Button( self, wx.ID_OK )
58 m_sdbSizer1.AddButton( self.m_sdbSizer1OK )
59 m_sdbSizer1.Realize();
61 bSizer1.Add( m_sdbSizer1, 0, wx.EXPAND, 5 )
64 self.SetSizer( bSizer1 )
68 self.Centre( wx.BOTH )
74 class LeftTree(CT.CustomTreeCtrl):
76 def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
78 style=wx.SUNKEN_BORDER|wx.WANTS_CHARS,
79 agwStyle=CT.TR_HAS_BUTTONS|CT.TR_HAS_VARIABLE_ROW_HEIGHT):
81 CT.CustomTreeCtrl.__init__(self, parent, id, pos, size, style, agwStyle)
87 if data.startswith("TR_"):
88 treestyles.append(data)
89 elif data.startswith("EVT_"):
93 self.styles = treestyles
96 il = wx.ImageList(16, 16)
98 # for items in ArtIDs[1:-1]:
99 # bmp = wx.ArtProvider_GetBitmap(eval(items), wx.ART_TOOLBAR, (16, 16))
102 # smileidx = il.Add(images.Smiles.GetBitmap())
103 # numicons = il.GetImageCount()
105 #self.AssignImageList(il)
109 self.history = parent.history
110 self.h = self.history.history
111 self.root = self.AddRoot("Iramuteq")
113 if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
114 self.SetPyData(self.root, None)
115 self.SetItemImage(self.root, 24, CT.TreeItemIcon_Normal)
116 self.SetItemImage(self.root, 13, CT.TreeItemIcon_Expanded)
118 #textctrl = wx.TextCtrl(self, -1, "I Am A Simple\nMultiline wx.TexCtrl", style=wx.TE_MULTILINE)
119 #self.gauge = wx.Gauge(self, -1, 50, style=wx.GA_HORIZONTAL|wx.GA_SMOOTH)
120 #self.gauge.SetValue(0)
121 #combobox = wx.ComboBox(self, -1, choices=["That", "Was", "A", "Nice", "Holyday!"], style=wx.CB_READONLY|wx.CB_DROPDOWN)
123 #textctrl.Bind(wx.EVT_CHAR, self.OnTextCtrl)
124 #combobox.Bind(wx.EVT_COMBOBOX, self.OnComboBox)
125 #lenArtIds = len(ArtIDs) - 2
126 for x in range(len(self.history.corpora)) :
127 if 'corpus_name' in self.h[self.history.order[x]] :
131 child = self.AppendItem(self.root, self.h[self.history.order[x]][key])
133 # child = self.AppendItem(self.root, "Item %d" % x + "\nHello World\nHappy wxPython-ing!")
134 # self.SetItemBold(child, True)
136 # child = self.AppendItem(self.root, "Item %d" % x)
137 self.SetPyData(child, self.h[self.history.order[x]])
138 self.SetItemImage(child, 24, CT.TreeItemIcon_Normal)
139 self.SetItemImage(child, 13, CT.TreeItemIcon_Expanded)
141 #if random.randint(0, 3) == 0:
142 # self.SetItemLeftImage(child, random.randint(0, lenArtIds))
145 # if y == 0 and x == 1:
146 # last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), ct_type=2, wnd=self.gauge)
147 # elif y == 1 and x == 2:
148 # last = self.AppendItem(child, "Item %d-%s" % (x, chr(ord("a")+y)), ct_type=1, wnd=textctrl)
149 # if random.randint(0, 3) == 1:
150 # self.SetItem3State(last, True)
153 # last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
154 # elif y == 4 and x == 1:
155 # last = self.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)), wnd=combobox)
157 if 'corpus_name' in self.h[self.history.order[x]] :
158 if 'analyses' in self.h[self.history.order[x]] :
159 for y in self.h[self.history.order[x]]['analyses'] :
160 last = self.AppendItem(child, y['name'], ct_type=0)
162 self.SetPyData(last, y)
163 self.SetItemImage(last, 24, CT.TreeItemIcon_Normal)
164 self.SetItemImage(last, 13, CT.TreeItemIcon_Expanded)
166 # if random.randint(0, 3) == 0:
167 # self.SetItemLeftImage(last, random.randint(0, lenArtIds))
169 #for z in range(len(self.history[x]) - 1):
172 # item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=0)
173 # #if random.randint(0, 3) == 1:
174 # # self.SetItem3State(item, True)
176 # item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z), ct_type=0)
178 # item = self.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z))
179 # #self.SetItemHyperText(item, True)
180 # self.SetPyData(item, None)
181 # self.SetItemImage(item, 28, CT.TreeItemIcon_Normal)
182 # self.SetItemImage(item, 28, CT.TreeItemIcon_Selected)
184 # if random.randint(0, 3) == 0:
185 # self.SetItemLeftImage(item, random.randint(0, lenArtIds))
187 self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
188 #self.Bind(wx.EVT_IDLE, self.OnIdle)
190 self.eventdict = {'EVT_TREE_BEGIN_DRAG': self.OnBeginDrag, 'EVT_TREE_BEGIN_LABEL_EDIT': self.OnBeginEdit,
191 'EVT_TREE_BEGIN_RDRAG': self.OnBeginRDrag, 'EVT_TREE_DELETE_ITEM': self.OnDeleteItem,
192 'EVT_TREE_END_DRAG': self.OnEndDrag, 'EVT_TREE_END_LABEL_EDIT': self.OnEndEdit,
193 'EVT_TREE_ITEM_ACTIVATED': self.OnActivate, 'EVT_TREE_ITEM_CHECKED': self.OnItemCheck,
194 'EVT_TREE_ITEM_CHECKING': self.OnItemChecking, 'EVT_TREE_ITEM_COLLAPSED': self.OnItemCollapsed,
195 'EVT_TREE_ITEM_COLLAPSING': self.OnItemCollapsing, 'EVT_TREE_ITEM_EXPANDED': self.OnItemExpanded,
196 'EVT_TREE_ITEM_EXPANDING': self.OnItemExpanding, 'EVT_TREE_ITEM_GETTOOLTIP': self.OnToolTip,
197 'EVT_TREE_ITEM_MENU': self.OnItemMenu, 'EVT_TREE_ITEM_RIGHT_CLICK': self.OnRightDown,
198 'EVT_TREE_KEY_DOWN': self.OnKey, 'EVT_TREE_SEL_CHANGED': self.OnSelChanged,
199 'EVT_TREE_SEL_CHANGING': self.OnSelChanging, "EVT_TREE_ITEM_HYPERLINK": self.OnHyperLink}
201 mainframe = wx.GetTopLevelParent(self)
203 if not hasattr(mainframe, "leftpanel"):
204 self.Bind(CT.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded)
205 self.Bind(CT.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed)
206 self.Bind(CT.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
207 self.Bind(CT.EVT_TREE_SEL_CHANGING, self.OnSelChanging)
208 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
209 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
211 for combos in mainframe.treeevents:
212 self.BindEvents(combos)
214 if hasattr(mainframe, "leftpanel"):
215 self.ChangeStyle(mainframe.treestyles)
217 if not(self.GetAGWWindowStyleFlag() & CT.TR_HIDE_ROOT):
218 self.SelectItem(self.root)
219 self.Expand(self.root)
222 def BindEvents(self, choice, recreate=False):
224 value = choice.GetValue()
225 text = choice.GetLabel()
228 binder = self.eventdict[text]
231 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
232 self.Bind(wx.EVT_RIGHT_DOWN, None)
233 self.Bind(wx.EVT_RIGHT_UP, None)
234 self.Bind(eval(evt), binder)
236 self.Bind(eval(evt), None)
237 if evt == "CT.EVT_TREE_BEGIN_RDRAG":
238 self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
239 self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
242 def ChangeStyle(self, combos):
246 if combo.GetValue() == 1:
247 style = style | eval("CT." + combo.GetLabel())
249 if self.GetAGWWindowStyleFlag() != style:
250 self.SetAGWWindowStyleFlag(style)
253 def OnCompareItems(self, item1, item2):
255 t1 = self.GetItemText(item1)
256 t2 = self.GetItemText(item2)
267 def OnIdle(self, event):
271 # if self.gauge.IsEnabled() and self.gauge.IsShown():
272 # self.count = self.count + 1
274 # if self.count >= 50:
277 # self.gauge.SetValue(self.count)
285 def CloseItem(self, itemParent = None, uuid = None) :
286 if itemParent is None :
287 itemParent = self.root
288 child, cookie = self.GetFirstChild(itemParent)
290 pydata = self.GetPyData(child)
291 if pydata['uuid'] == uuid :
292 self.SetItemBold(child, False)
294 self.CloseItem(child, uuid)
295 child, cookie = self.GetNextChild(itemParent, cookie)
297 def GiveFocus(self, itemParent = None, uuid = None) :
298 if itemParent is None :
299 itemParent = self.root
300 child, cookie = self.GetFirstChild(itemParent)
302 pydata = self.GetPyData(child)
303 if pydata['uuid'] == uuid :
304 self.SelectItem(child)
306 self.GiveFocus(child, uuid)
307 child, cookie = self.GetNextChild(itemParent, cookie)
309 def OnRightDown(self, event):
311 pt = event.GetPosition()
312 item, flags = self.HitTest(pt)
316 #self.log.info("OnRightClick: %s, %s, %s" % (self.GetItemText(item), type(item), item.__class__) + "\n")
317 self.SelectItem(item)
320 def OnRightUp(self, event):
328 if not self.IsItemEnabled(item):
332 # Item Text Appearance
333 ishtml = self.IsItemHyperText(item)
334 back = self.GetItemBackgroundColour(item)
335 fore = self.GetItemTextColour(item)
336 isbold = self.IsBold(item)
337 font = self.GetItemFont(item)
340 normal = self.GetItemImage(item, CT.TreeItemIcon_Normal)
341 selected = self.GetItemImage(item, CT.TreeItemIcon_Selected)
342 expanded = self.GetItemImage(item, CT.TreeItemIcon_Expanded)
343 selexp = self.GetItemImage(item, CT.TreeItemIcon_SelectedExpanded)
345 # Enabling/Disabling Windows Associated To An Item
346 haswin = self.GetItemWindow(item)
348 # Enabling/Disabling Items
349 enabled = self.IsItemEnabled(item)
351 # Generic Item's Info
352 children = self.GetChildrenCount(item)
353 itemtype = self.GetItemType(item)
354 text = self.GetItemText(item)
355 pydata = self.GetPyData(item)
358 self.itemdict = {"ishtml": ishtml, "back": back, "fore": fore, "isbold": isbold,
359 "font": font, "normal": normal, "selected": selected, "expanded": expanded,
360 "selexp": selexp, "haswin": haswin, "children": children,
361 "itemtype": itemtype, "text": text, "pydata": pydata, "enabled": enabled}
364 info = menu.Append(wx.ID_ANY, "Informations")
365 menu.AppendSeparator()
367 if 'corpus_name' in pydata :
368 stat = menu.Append(wx.ID_ANY, u"Statistiques")
369 spec = menu.Append(wx.ID_ANY, u"Spécificté et AFC")
370 classification = wx.Menu()
371 alceste = classification.Append(wx.ID_ANY, u"Méthode ALCESTE")
372 pam = classification.Append(wx.ID_ANY, u"Par matrice des distances")
373 menu.AppendMenu(-1, u"Classification", classification)
374 simi = menu.Append(wx.ID_ANY, u"Analyse de similitude")
375 wdc = menu.Append(wx.ID_ANY, u"Nuage de mots")
376 menu.AppendSeparator()
377 self.Bind(wx.EVT_MENU, self.OnAlceste, alceste)
378 self.Bind(wx.EVT_MENU, self.OnPam, pam)
379 self.Bind(wx.EVT_MENU, self.OnStat, stat)
380 self.Bind(wx.EVT_MENU, self.OnSpec, spec)
381 self.Bind(wx.EVT_MENU, self.OnSimiTxt, simi)
382 self.Bind(wx.EVT_MENU, self.OnWordCloud, wdc)
384 itemdelete = menu.Append(wx.ID_ANY, "Supprimer de l'historique")
385 if item == self.GetRootItem():
386 itemdelete.Enable(False)
387 #item11 = menu.Append(wx.ID_ANY, "Prepend An Item")
388 #item12 = menu.Append(wx.ID_ANY, "Append An Item")
390 #self.Bind(wx.EVT_MENU, self.OnItemBackground, item1)
391 #self.Bind(wx.EVT_MENU, self.OnItemForeground, item2)
392 #self.Bind(wx.EVT_MENU, self.OnItemBold, item3)
393 #self.Bind(wx.EVT_MENU, self.OnItemFont, item4)
394 #self.Bind(wx.EVT_MENU, self.OnItemHyperText, item5)
395 #self.Bind(wx.EVT_MENU, self.OnEnableWindow, item6)
396 #self.Bind(wx.EVT_MENU, self.OnDisableItem, item7)
397 #self.Bind(wx.EVT_MENU, self.OnItemIcons, item8)
398 self.Bind(wx.EVT_MENU, self.OnItemInfo, info)
399 self.Bind(wx.EVT_MENU, self.OnItemDelete, itemdelete)
400 #self.Bind(wx.EVT_MENU, self.OnItemPrepend, item11)
401 #self.Bind(wx.EVT_MENU, self.OnItemAppend, item12)
406 def getcorpus(self, itemdict):
407 if itemdict['pydata']['uuid'] in self.parent.history.openedcorpus :
408 return copycorpus(self.parent.history.openedcorpus[itemdict['pydata']['uuid']])
410 return Corpus(self.parent, parametres = DoConf(itemdict['pydata']['ira']).getoptions('corpus'), read = True)
412 def OnSpec(self, evt) :
413 self.parent.OnTextSpec(evt, self.getcorpus(self.itemdict))
415 def OnStat(self, evt) :
416 self.parent.OnTextStat(evt, self.getcorpus(self.itemdict))
418 def OnAlceste(self, evt) :
419 self.parent.OnTextAlceste(evt, self.getcorpus(self.itemdict))
421 def OnPam(self, evt) :
424 def OnSimiTxt(self, evt) :
425 self.parent.OnSimiTxt(evt, self.getcorpus(self.itemdict))
427 def OnWordCloud(self, evt) :
428 self.parent.OnWordCloud(evt, self.getcorpus(self.itemdict))
430 def OnItemBackground(self, event):
432 colourdata = wx.ColourData()
433 colourdata.SetColour(self.itemdict["back"])
434 dlg = wx.ColourDialog(self, colourdata)
436 dlg.GetColourData().SetChooseFull(True)
438 if dlg.ShowModal() == wx.ID_OK:
439 data = dlg.GetColourData()
440 col1 = data.GetColour().Get()
441 self.SetItemBackgroundColour(self.current, col1)
445 def OnItemForeground(self, event):
447 colourdata = wx.ColourData()
448 colourdata.SetColour(self.itemdict["fore"])
449 dlg = wx.ColourDialog(self, colourdata)
451 dlg.GetColourData().SetChooseFull(True)
453 if dlg.ShowModal() == wx.ID_OK:
454 data = dlg.GetColourData()
455 col1 = data.GetColour().Get()
456 self.SetItemTextColour(self.current, col1)
460 def OnItemBold(self, event):
462 self.SetItemBold(self.current, not self.itemdict["isbold"])
465 def OnItemFont(self, event):
468 font = self.itemdict["font"]
471 font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
473 data.SetInitialFont(font)
475 dlg = wx.FontDialog(self, data)
477 if dlg.ShowModal() == wx.ID_OK:
478 data = dlg.GetFontData()
479 font = data.GetChosenFont()
480 self.SetItemFont(self.current, font)
485 def OnItemHyperText(self, event):
487 self.SetItemHyperText(self.current, not self.itemdict["ishtml"])
490 def OnEnableWindow(self, event):
492 enable = self.GetItemWindowEnabled(self.current)
493 self.SetItemWindowEnabled(self.current, not enable)
496 def OnDisableItem(self, event):
498 self.EnableItem(self.current, False)
501 def OnItemIcons(self, event):
503 bitmaps = [self.itemdict["normal"], self.itemdict["selected"],
504 self.itemdict["expanded"], self.itemdict["selexp"]]
507 dlg = TreeIcons(self, -1, bitmaps=bitmaps)
512 def SetNewIcons(self, bitmaps):
514 self.SetItemImage(self.current, bitmaps[0], CT.TreeItemIcon_Normal)
515 self.SetItemImage(self.current, bitmaps[1], CT.TreeItemIcon_Selected)
516 self.SetItemImage(self.current, bitmaps[2], CT.TreeItemIcon_Expanded)
517 self.SetItemImage(self.current, bitmaps[3], CT.TreeItemIcon_SelectedExpanded)
520 def OnItemInfo(self, event):
522 itemtext = self.itemdict["text"]
523 numchildren = str(self.itemdict["children"])
524 itemtype = self.itemdict["itemtype"]
525 pydata = self.itemdict['pydata']
526 #if 'analyses' in pydata :
527 # toshow = dict([[val, pydata[val]] for val in pydata if val not in['analyses', 'isload']])
529 toshow = pydata['ira']
530 toshow = DoConf(toshow).getoptions()
531 txt = DoConf().totext(toshow)
532 parametres = [val.split('\t\t:') for val in txt.splitlines()]
538 itemtype = "CheckBox"
540 itemtype = "RadioButton"
542 dlg = InfoDialog(self, itemtext, parametres)
548 def OnItemDelete(self, event):
550 strs = "Are You Sure You Want To Delete Item " + self.GetItemText(self.current) + "?"
551 dlg = wx.MessageDialog(None, strs, 'Deleting Item', wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_QUESTION)
553 if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]:
559 pydata = self.itemdict['pydata']
560 if 'corpus_name' in pydata :
561 self.history.delete(pydata['uuid'], True)
563 self.history.delete(pydata['uuid'])
564 self.DeleteChildren(self.current)
565 self.Delete(self.current)
570 def OnItemPrepend(self, event):
572 dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
574 if dlg.ShowModal() == wx.ID_OK:
575 newname = dlg.GetValue()
576 newitem = self.PrependItem(self.current, newname)
577 self.EnsureVisible(newitem)
581 def AddAnalyse(self, parametres, itemParent = None, bold = True) :
582 uuid = parametres['corpus']
583 if itemParent is None :
584 itemParent = self.root
585 child, cookie = self.GetFirstChild(itemParent)
588 pydata = self.GetPyData(child)
589 if pydata['uuid'] == uuid :
592 self.GiveFocus(child, uuid)
593 child, cookie = self.GetNextChild(itemParent, cookie)
594 #item = self.AppendItem(child, parametres['name'])
595 if corpus is not None :
596 item = self.AppendItem(corpus, parametres['name'])
598 item = self.AppendItem(self.root, parametres['name'])
599 self.SetPyData(item, parametres)
600 self.SetItemImage(item, 24, CT.TreeItemIcon_Normal)
601 self.SetItemImage(item, 13, CT.TreeItemIcon_Expanded)
602 self.SetItemBold(item, bold)
604 def OnItemAppend(self, item):
605 child = self.AppendItem(self.root, item['corpus_name'])
606 self.SetPyData(child, item)
607 self.history.addtab(item)
608 self.SetItemImage(child, 24, CT.TreeItemIcon_Normal)
609 self.SetItemImage(child, 13, CT.TreeItemIcon_Expanded)
610 self.SetItemBold(child, True)
612 #dlg = wx.TextEntryDialog(self, "Please Enter The New Item Name", 'Item Naming', 'Python')
614 #if dlg.ShowModal() == wx.ID_OK:
615 # newname = dlg.GetValue()
616 # newitem = self.AppendItem(self.current, newname)
617 # self.EnsureVisible(newitem)
623 def OnBeginEdit(self, event):
625 #self.log.info("OnBeginEdit" + "\n")
626 # show how to prevent edit...
627 item = event.GetItem()
628 if item and self.GetItemText(item) == "The Root Item":
630 #self.log.info("You can't edit this one..." + "\n")
632 # Lets just see what's visible of its children
634 root = event.GetItem()
635 (child, cookie) = self.GetFirstChild(root)
638 #self.log.info("Child [%s] visible = %d" % (self.GetItemText(child), self.IsVisible(child)) + "\n")
639 (child, cookie) = self.GetNextChild(root, cookie)
644 def OnEndEdit(self, event):
646 #self.log.info("OnEndEdit: %s %s" %(event.IsEditCancelled(), event.GetLabel()))
647 # show how to reject edit, we'll not allow any digits
648 for x in event.GetLabel():
649 if x in string.digits:
650 #self.log.info(", You can't enter digits..." + "\n")
657 def OnLeftDClick(self, event):
659 pt = event.GetPosition()
660 item, flags = self.HitTest(pt)
661 pydata = self.GetPyData(item)
662 if pydata['uuid'] in self.parent.history.opened :
663 for i in range(self.parent.nb.GetPageCount()) :
664 page = self.parent.nb.GetPage(i)
665 if 'parametres' in dir(page) :
666 if page.parametres['uuid'] == pydata['uuid'] :
667 self.parent.nb.SetSelection(i)
670 OpenAnalyse(self.parent, pydata)
671 self.SetItemBold(item, True)
672 #if item and (flags & CT.TREE_HITTEST_ONITEMLABEL):
673 # if self.GetAGWWindowStyleFlag() & CT.TR_EDIT_LABELS:
674 # self.log.info("OnLeftDClick: %s (manually starting label edit)"% self.GetItemText(item) + "\n")
676 #self.EditLabel(item)
678 # pydata = self.GetPyData(item)
680 # self.log.info("OnLeftDClick: Cannot Start Manual Editing, Missing Style TR_EDIT_LABELS\n")
685 def OnItemExpanded(self, event):
687 item = event.GetItem()
689 self.log.info("OnItemExpanded: %s" % self.GetItemText(item) + "\n")
692 def OnItemExpanding(self, event):
694 item = event.GetItem()
696 self.log.info("OnItemExpanding: %s" % self.GetItemText(item) + "\n")
701 def OnItemCollapsed(self, event):
703 item = event.GetItem()
705 self.log.info("OnItemCollapsed: %s" % self.GetItemText(item) + "\n")
708 def OnItemCollapsing(self, event):
710 item = event.GetItem()
712 self.log.info("OnItemCollapsing: %s" % self.GetItemText(item) + "\n")
717 def OnSelChanged(self, event):
718 item = event.GetItem()
719 pydata = self.GetPyData(item)
720 if pydata is not None :
721 if pydata['uuid'] in self.parent.history.opened :
722 for i in range(self.parent.nb.GetPageCount()) :
723 page = self.parent.nb.GetPage(i)
724 if 'parametres' in dir(page) :
725 if page.parametres['uuid'] == pydata['uuid'] :
726 self.parent.nb.SetSelection(i)
729 #self.item = event.GetItem()
732 #self.log.info("OnSelChanged: %s" % self.GetItemText(self.item))
733 # if wx.Platform == '__WXMSW__':
734 # self.log.info(", BoundingRect: %s" % self.GetBoundingRect(self.item, True) + "\n")
739 def OnSelChanging(self, event):
741 item = event.GetItem()
742 olditem = event.GetOldItem()
748 olditemtext = self.GetItemText(olditem)
749 self.log.info("OnSelChanging: From %s" % olditemtext + " To %s" % self.GetItemText(item) + "\n")
754 def OnBeginDrag(self, event):
756 self.item = event.GetItem()
758 self.log.info("Beginning Drag..." + "\n")
763 def OnBeginRDrag(self, event):
765 self.item = event.GetItem()
767 self.log.info("Beginning Right Drag..." + "\n")
772 def OnEndDrag(self, event):
774 self.item = event.GetItem()
776 self.log.info("Ending Drag!" + "\n")
781 def OnDeleteItem(self, event):
783 item = event.GetItem()
788 self.log.info("Deleting Item: %s" % self.GetItemText(item) + "\n")
792 def OnItemCheck(self, event):
794 item = event.GetItem()
795 self.log.info("Item " + self.GetItemText(item) + " Has Been Checked!\n")
799 def OnItemChecking(self, event):
801 item = event.GetItem()
802 self.log.info("Item " + self.GetItemText(item) + " Is Being Checked...\n")
806 def OnToolTip(self, event):
808 item = event.GetItem()
810 event.SetToolTip(wx.ToolTip(self.GetItemText(item)))
813 def OnItemMenu(self, event):
815 item = event.GetItem()
817 self.log.info("OnItemMenu: %s" % self.GetItemText(item) + "\n")
822 def OnKey(self, event):
824 keycode = event.GetKeyCode()
825 keyname = keyMap.get(keycode, None)
827 if keycode == wx.WXK_BACK:
828 self.log.info("OnKeyDown: HAHAHAHA! I Vetoed Your Backspace! HAHAHAHA\n")
832 if "unicode" in wx.PlatformInfo:
833 keycode = event.GetUnicodeKey()
835 keycode = event.GetKeyCode()
836 keyname = "\"" + unichr(event.GetUnicodeKey()) + "\""
838 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
844 keyname = "Ctrl-%s" % chr(ord('A') + keycode-1)
846 keyname = "\"%s\"" % chr(keycode)
848 keyname = "unknown (%s)" % keycode
850 self.log.info("OnKeyDown: You Pressed '" + keyname + "'\n")
855 def OnActivate(self, event):
858 self.log.info("OnActivate: %s" % self.GetItemText(self.item) + "\n")
863 def OnHyperLink(self, event):
865 item = event.GetItem()
867 self.log.info("OnHyperLink: %s" % self.GetItemText(self.item) + "\n")
870 def OnTextCtrl(self, event):
872 char = chr(event.GetKeyCode())
873 self.log.info("EDITING THE TEXTCTRL: You Wrote '" + char + \
874 "' (KeyCode = " + str(event.GetKeyCode()) + ")\n")
878 def OnComboBox(self, event):
880 selection = event.GetEventObject().GetValue()
881 self.log.info("CHOICE FROM COMBOBOX: You Chose '" + selection + "'\n")