Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wx
- import wx.lib.agw.hypertreelist as HTL
- class MyScrolledWindow(wx.ScrolledWindow):
- def __init__(self, parent):
- wx.ScrolledWindow.__init__(self, parent, style=wx.BORDER_SIMPLE)
- self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
- self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
- self.Bind(wx.EVT_LEFT_DOWN, self.OnMouse)
- self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
- self.label = wx.StaticText(self, label="Init")
- self.combo = None
- text = wx.StaticText(self, pos=(0,60))
- text.SetLabel("<Click to SetFocusIgnoringChildren>")
- def OnSetFocus(self, event):
- self.label.SetLabel("MyScrolledWindow GOT Focus, prior=%s" %
- event.GetWindow().__class__)
- event.Skip()
- def OnKillFocus(self, event):
- self.label.SetLabel("MyScrolledWindow LOST Focus to %s" %
- event.GetWindow().__class__)
- event.Skip()
- def OnMouse(self, event):
- if event.LeftDown():
- self.SetFocusIgnoringChildren()
- def OnKeyDown(self, event):
- self.label.SetLabel("KeyDown, keycode=%s" % event.GetKeyCode())
- event.Skip()
- def CreateCombo(self):
- if not self.combo:
- self.combo = wx.ComboBox(self, pos=(0,30), choices=['one','two'])
- class MyPanel(wx.Panel):
- def __init__(self, parent):
- wx.Panel.__init__(self, parent)
- sizer = wx.BoxSizer(orient=wx.VERTICAL)
- self.window = MyScrolledWindow(self)
- button = wx.Button(self, label="Create Child")
- sizer.Add(self.window, proportion=1, flag=wx.EXPAND)
- sizer.Add(button, flag=wx.ALIGN_CENTER | wx.EXPAND | wx.ALL, border=10)
- sizer.Add(wx.StaticText(self, label="Ctrl-F to print current focus"))
- self.SetSizer(sizer)
- self.Bind(wx.EVT_BUTTON, self.OnButton)
- def OnButton(self, event):
- self.window.CreateCombo()
- class MyFrame(wx.Frame):
- def __init__(self, parent):
- wx.Frame.__init__(self, parent, -1, "HyperTreeList Demo")
- panel = MyPanel(self)
- ctrl_f = wx.NewId()
- self.Bind(wx.EVT_MENU, self.OnCtrlD, id=ctrl_f)
- accel = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), ctrl_f)])
- self.SetAcceleratorTable(accel)
- def OnCtrlD(self, event):
- print('*'*72)
- print("Focus=%s" % self.FindFocus().__class__)
- # Entrypoint
- app = wx.App(0)
- locale = wx.Locale(wx.LANGUAGE_DEFAULT)
- frame = MyFrame(None)
- app.SetTopWindow(frame)
- frame.Show()
- app.MainLoop()
Add Comment
Please, Sign In to add comment