Wx.dialog can check the need to check the control to determine the click [], how

Note

If you are using a window or panel instead of a dialog, you will need to call Window.InitDialog explicitly before showing the window.

How to explain the above code

The text from the

Started by Andrea at February 02, 2016 - 7:24 PM

Personal understanding, it should be according to the "data is transferred from Python variables to the dialog just as the dialog is being shown".
For example is for dialog, so, when do you check / corresponding data to have displayed windows/panel to sync, need to use Windos.InitDialog......

Posted by Walker at February 17, 2016 - 7:30 PM

This section of the code in the frame, does not seem to play a role, may be I have some problems

Posted by Andrea at January 05, 2017 - 6:23 PM

  1. #!/bin/env python
  2. import wx
  3. class Validator(wx.PyValidator):
  4. def __init__(self):
  5. wx.PyValidator.__init__(self)

  6. def Clone(self):
  7. return Validator()

  8. def Validate(self, win):
  9. txt_ctrl = self.GetWindow()

  10. if len(txt_ctrl.GetValue()) == 0:
  11. wx.MessageBox('Please, provide a value.', 'Error')
  12. txt_ctrl.SetBackgroundColour('pink')
  13. txt_ctrl.SetFocus()
  14. txt_ctrl.Refresh()
  15. return False
  16. else:
  17. txt_ctrl.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
  18. txt_ctrl.Refresh()
  19. return True

  20. def TransferToWindow(self):
  21. return True

  22. def TransferFromWindow(self):
  23. return True

  24. class MyFrame(wx.Frame):

  25. def __init__(self):
  26. wx.Frame.__init__(self, None, -1, "My Frame", size=(300, 300))
  27. self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)
  28. panel = wx.Panel(self, -1)

  29. wx.StaticText(panel, -1, "Pos:", pos=(10, 12))
  30. self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(40, 10),validator=Validator())
  31. self.ctrl = wx.TextCtrl(panel, -1, "", pos=(40, 50),validator=Validator())
  32. #self.posCtrl.SetValidator(Validator())

  33. ck = wx.Button(panel,-1,"Check", pos=(40, 80))

  34. self.InitDialog()
  35. self.Bind(wx.EVT_BUTTON, self.OnButton, ck )
  36. def OnButton(self, evt):
  37. rtn = self.Validate()
  38. print rtn


  39. if __name__ == '__main__':
  40. app = wx.PySimpleApp()
  41. frame = MyFrame()
  42. frame.Show(True)
  43. app.MainLoop()

Posted by Andrea at January 13, 2017 - 5:41 PM

#!/bin/env python
import wx
class Validator(wx.PyValidator):
def __init__(self):
wx.PyValidator.__init__(self)

def Clone(self):
return Validator()

def Validate(self, win):
txt_ctrl = self.GetWindow()

if len(txt_ctrl.GetValue()) == 0:
wx.MessageBox('Please, provide a value.', 'Error')
txt_ctrl.SetBackgroundColour('pink')
txt_ctrl.SetFocus()
txt_ctrl.Refresh()
return False
else:
txt_ctrl.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW))
txt_ctrl.Refresh()
return True

def TransferToWindow(self):
return True

def TransferFromWindow(self):
return True

class MyFrame(wx.Frame):

def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size=(300, 300))
self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY) #1
panel = wx.Panel(self, -1)

wx.StaticText(panel, -1, "Pos:", pos=(10, 12))
self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(40, 10),validator=Validator()) #1
self.ctrl = wx.TextCtrl(panel, -1, "", pos=(40, 50),validator=Validator()) #1
#self.posCtrl.SetValidator(Validator())

ck = wx.Button(panel,-1,"Check", pos=(40, 80))

self.InitDialog() #1
self.Bind(wx.EVT_BUTTON, self.OnButton, ck )
def OnButton(self, evt):
rtn = self.Validate()
print rtn


if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show(True)
app.MainLoop()

Posted by Andrea at January 13, 2017 - 6:34 PM