Hallo,
now i have two examples extracted from my code, one where the problem occurs (TestDialog_Ko) and a second, where everything work OK (TestDialog_OK):
REMARK: you need to replace the two toolbar icons (Bus_AfpX.png) with local icons on your machine
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wx
class TestDialog_Ko(wx.Dialog):
def __init__(self, *args, **kw):
print ("TestDialog_Ko Input:", args, kw)
self.textmap = {}
self.vtextmap = {}
self.choicemap = {}
self.no_readonly = True
self.close_dialog = True
super(TestDialog_Ko, self).__init__(*args, **kw)
self.left_weight = 1
self.right_weight = 7
#self.right_weight = 2
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.statictext = wx.StaticText(self, -1, label="Test with asynchron focus", name="Text")
self.line2_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.label_T_Vorname_Adresse = wx.StaticText(self, -1, label="&Vorname:", name="T_Vorname_Adresse")
self.text_Vorname_Adresse = wx.TextCtrl(self, -1, value="", style=wx.TE_MULTILINE|wx.TE_BESTWRAP, name="Vorname_Adresse")
self.text_Vorname_Adresse.Bind(wx.EVT_KILL_FOCUS, self.On_KillFocus)
self.textmap["Vorname_Adresse"] = "Vorname.ADRESSE"
self.line2_sizer.AddSpacer(10)
self.line2_sizer.Add(self.label_T_Vorname_Adresse,self.left_weight,wx.EXPAND)
self.line2_sizer.AddSpacer(10)
self.line2_sizer.Add(self.text_Vorname_Adresse,self.right_weight,wx.EXPAND)
self.line2_sizer.AddSpacer(10)
self.line3_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.label_T_Name_Adresse = wx.StaticText(self, -1, label="&Name:", name="T_Name_Adresse")
self.text_Name_Adresse = wx.TextCtrl(self, -1, value="", style=wx.TE_MULTILINE|wx.TE_BESTWRAP, name="Name_Adresse")
self.text_Name_Adresse.Bind(wx.EVT_KILL_FOCUS, self.On_KillFocus)
self.textmap["Name_Adresse"] = "Name.ADRESSE"
self.line3_sizer.AddSpacer(10)
self.line3_sizer.Add(self.label_T_Name_Adresse,self.left_weight,wx.EXPAND)
self.line3_sizer.AddSpacer(10)
self.line3_sizer.Add(self.text_Name_Adresse,self.right_weight,wx.EXPAND)
self.line3_sizer.AddSpacer(10)
self.line4_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.label_T_Strasse_Adresse = wx.StaticText(self, -1, label="Stra&sse:", name="T_Strasse_Adresse")
self.text_Strasse_Adresse = wx.TextCtrl(self, -1, value="", style=0, name="Strasse_Adresse")
self.text_Strasse_Adresse.Bind(wx.EVT_KILL_FOCUS, self.On_KillFocus)
self.textmap["Strasse_Adresse"] = "Strasse.ADRESSE"
self.line4_sizer.AddSpacer(10)
self.line4_sizer.Add(self.label_T_Strasse_Adresse,self.left_weight,wx.EXPAND)
self.line4_sizer.AddSpacer(10)
self.line4_sizer.Add(self.text_Strasse_Adresse,self.right_weight,wx.EXPAND)
self.line4_sizer.AddSpacer(10)
self.sizer.AddSpacer(10)
self.sizer.Add(self.statictext, 1, wx.EXPAND)
self.sizer.AddSpacer(10)
self.sizer.Add(self.line2_sizer,1,wx.EXPAND)
self.sizer.AddSpacer(10)
self.sizer.Add(self.line3_sizer,2,wx.EXPAND)
self.sizer.AddSpacer(10)
self.sizer.Add(self.line4_sizer,1,wx.EXPAND)
self.sizer.AddSpacer(10)
self.SetSize((560,315))
self.SetTitle("Test Dialog Ko")
self.SetSizer(self.sizer)
self.SetSizerAndFit(self.sizer)
self.SetAutoLayout(1)
#self.sizer.Fit(self)
def On_KillFocus(self, event):
print ("TestDialog.On_KillFocus")
class TestDialog_Ok(wx.Dialog):
## constructor
def __init__(self, *args, **kw):
super(TestDialog_Ok, self).__init__(*args, **kw)
width = 250
height = 70
self.Ok = False
self.typ = None
self.result = []
self.label = []
self.texts = []
self.check = []
self.buttons = []
self.button_pushed = None
self.sizers = []
self.statictext = wx.StaticText(self, -1, label="Test with synchron focus", name="Text")
self.SetTitle("Test OK")
self.lines = 3
self.texts = [None]*self.lines
self.sizers = [None]*self.lines
for i in range(self.lines):
self.label.append(wx.StaticText(self, -1, label="Label " + str(i), name="L" + str(i)))
self.texts[i] = wx.TextCtrl(self, -1, value="", name="T" + str(i))
self.sizers[i] = wx.BoxSizer(wx.HORIZONTAL)
self.sizers[i].AddStretchSpacer(1)
self.sizers[i].Add(self.label[-1],5,wx.EXPAND)
self.sizers[i].Add(self.texts[i],9,wx.EXPAND)
self.sizers[i].AddStretchSpacer(1)
height += 35 #30+5
self.sizer=wx.BoxSizer(wx.VERTICAL)
self.sizer.AddSpacer(10)
self.sizer.Add(self.statictext, 1, wx.EXPAND)
self.sizer.AddSpacer(5)
for i in range(self.lines):
self.sizer.AddSpacer(5)
self.sizer.Add(self.sizers[i], 1, wx.EXPAND)
self.sizer.AddSpacer(10)
self.SetSizerAndFit(self.sizer)
self.SetAutoLayout(1)
self.sizer.Fit(self)
self.SetSize((width, height))
class Example(wx.Frame):
def __init__(self, *args, **kw):
super(Example, self).__init__(*args, **kw)
self.InitUI()
def InitUI(self):
ID_LEFT = wx.NewIdRef()
tb = self.CreateToolBar()
tb.AddTool(toolId=ID_LEFT, label='Ko',
bitmap=wx.Bitmap('Bus_AfpX.png'), kind=wx.ITEM_NORMAL)
ID_RIGHT = wx.NewIdRef()
tb.AddTool(toolId=ID_RIGHT, label='OK',
bitmap=wx.Bitmap('Bus_AfpX.png'), kind=wx.ITEM_NORMAL)
tb.Realize()
self.Bind(wx.EVT_TOOL, self.button_push_left, id=ID_LEFT)
self.Bind(wx.EVT_TOOL, self.button_push_right, id=ID_RIGHT)
self.SetSize((50, 100))
self.SetTitle('Frame for test dialog')
self.Centre()
self.Show(True)
def button_push_left(self, event):
dlg = TestDialog_Ko(parent=None)
dlg.ShowModal()
dlg.Destroy()
def button_push_right(self, event):
dlg = TestDialog_Ok(parent=None)
dlg.ShowModal()
dlg.Destroy()
# Main
if __name__ == "__main__":
ex = wx.App()
Example(None)
ex.MainLoop()