+ def OnTestHide(self, evt):
+ tree.CloseTestWindow()
+
+ # Find object by relative position
+ def FindObject(self, item, obj):
+ # We simply perform depth-first traversal, sinse it's too much
+ # hassle to deal with all sizer/window combinations
+ w = tree.FindNodeObject(item)
+ if w == obj:
+ return item
+ if tree.ItemHasChildren(item):
+ child = tree.GetFirstChild(item)[0]
+ while child:
+ found = self.FindObject(child, obj)
+ if found: return found
+ child = tree.GetNextSibling(child)
+ return None
+
+ def OnTestWinLeftDown(self, evt):
+ pos = evt.GetPosition()
+ self.SetHandler(g.testWin)
+ g.testWin.Disconnect(wxID_ANY, wxID_ANY, wxEVT_LEFT_DOWN)
+ item = self.FindObject(g.testWin.item, evt.GetEventObject())
+ if item:
+ tree.SelectItem(item)
+ self.tb.ToggleTool(self.ID_TOOL_LOCATE, False)
+ if item:
+ self.SetStatusText('Selected %s' % tree.GetItemText(item))
+ else:
+ self.SetStatusText('Locate failed!')
+
+ def SetHandler(self, w, h=None):
+ if h:
+ w.SetEventHandler(h)
+ w.SetCursor(wxCROSS_CURSOR)
+ else:
+ w.SetEventHandler(w)
+ w.SetCursor(wxNullCursor)
+ for ch in w.GetChildren():
+ self.SetHandler(ch, h)
+
+ def OnLocate(self, evt):
+ if g.testWin:
+ if evt.GetId() == self.ID_LOCATE or \
+ evt.GetId() == self.ID_TOOL_LOCATE and evt.IsChecked():
+ self.SetHandler(g.testWin, g.testWin)
+ g.testWin.Connect(wxID_ANY, wxID_ANY, wxEVT_LEFT_DOWN, self.OnTestWinLeftDown)
+ if evt.GetId() == self.ID_LOCATE:
+ self.tb.ToggleTool(self.ID_TOOL_LOCATE, True)
+ elif evt.GetId() == self.ID_TOOL_LOCATE and not evt.IsChecked():
+ self.SetHandler(g.testWin, None)
+ g.testWin.Disconnect(wxID_ANY, wxID_ANY, wxEVT_LEFT_DOWN)
+ self.SetStatusText('Click somewhere in your test window now')
+