Guest User

Untitled

a guest
Dec 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import wx
  2. import wx.lib.agw.hypertreelist as HTL
  3.  
  4. class MyScrolledWindow(wx.ScrolledWindow):
  5. def __init__(self, parent):
  6. wx.ScrolledWindow.__init__(self, parent, style=wx.BORDER_SIMPLE)
  7. self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
  8. self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
  9. self.Bind(wx.EVT_LEFT_DOWN, self.OnMouse)
  10. self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
  11. self.label = wx.StaticText(self, label="Init")
  12. self.combo = None
  13. text = wx.StaticText(self, pos=(0,60))
  14. text.SetLabel("<Click to SetFocusIgnoringChildren>")
  15.  
  16. def OnSetFocus(self, event):
  17. self.label.SetLabel("MyScrolledWindow GOT Focus, prior=%s" %
  18. event.GetWindow().__class__)
  19. event.Skip()
  20.  
  21. def OnKillFocus(self, event):
  22. self.label.SetLabel("MyScrolledWindow LOST Focus to %s" %
  23. event.GetWindow().__class__)
  24. event.Skip()
  25.  
  26. def OnMouse(self, event):
  27. if event.LeftDown():
  28. self.SetFocusIgnoringChildren()
  29.  
  30. def OnKeyDown(self, event):
  31. self.label.SetLabel("KeyDown, keycode=%s" % event.GetKeyCode())
  32. event.Skip()
  33.  
  34. def CreateCombo(self):
  35. if not self.combo:
  36. self.combo = wx.ComboBox(self, pos=(0,30), choices=['one','two'])
  37.  
  38.  
  39. class MyPanel(wx.Panel):
  40. def __init__(self, parent):
  41. wx.Panel.__init__(self, parent)
  42. sizer = wx.BoxSizer(orient=wx.VERTICAL)
  43. self.window = MyScrolledWindow(self)
  44. button = wx.Button(self, label="Create Child")
  45. sizer.Add(self.window, proportion=1, flag=wx.EXPAND)
  46. sizer.Add(button, flag=wx.ALIGN_CENTER | wx.EXPAND | wx.ALL, border=10)
  47. sizer.Add(wx.StaticText(self, label="Ctrl-F to print current focus"))
  48. self.SetSizer(sizer)
  49. self.Bind(wx.EVT_BUTTON, self.OnButton)
  50.  
  51. def OnButton(self, event):
  52. self.window.CreateCombo()
  53.  
  54.  
  55. class MyFrame(wx.Frame):
  56. def __init__(self, parent):
  57. wx.Frame.__init__(self, parent, -1, "HyperTreeList Demo")
  58. panel = MyPanel(self)
  59.  
  60. ctrl_f = wx.NewId()
  61. self.Bind(wx.EVT_MENU, self.OnCtrlD, id=ctrl_f)
  62. accel = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('F'), ctrl_f)])
  63. self.SetAcceleratorTable(accel)
  64.  
  65. def OnCtrlD(self, event):
  66. print('*'*72)
  67. print("Focus=%s" % self.FindFocus().__class__)
  68.  
  69.  
  70. # Entrypoint
  71. app = wx.App(0)
  72. locale = wx.Locale(wx.LANGUAGE_DEFAULT)
  73. frame = MyFrame(None)
  74. app.SetTopWindow(frame)
  75. frame.Show()
  76. app.MainLoop()
Add Comment
Please, Sign In to add comment