It's all about scoping and knowing where your data is coming from.
You've got this bad habit of passing events to things that don't need an
event. Rule of thumb: don't pass events unless there is a possibility
of them being Skip()ed
- Josiah
#!/usr/bin/env python
# customdialog1.py
import wx
class MyDialog(wx.Dialog):
def __init__(self, parent, ID):
wx.Dialog.__init__(self, parent, ID)
mainSizer = wx.BoxSizer(wx.VERTICAL)
gridSizer = wx.FlexGridSizer(2, 2, 5, 5)
gridSizer.AddGrowableCol(1, 1)
gridSizer.Add(wx.StaticText(self, wx.ID_ANY, 'Number: '))
numT = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(25, 25), style=wx.RAISED_BORDER)
self.numT = numT = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(25, 5), style=wx.RAISED_BORDER)
self.Bind(wx.EVT_TEXT_ENTER, self.OnNewNumber, numT)
gridSizer.Add(numT)
gridSizer.Add(wx.StaticText(self, wx.ID_ANY, 'Component: '))
compT = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(150, 25), style=wx.RAISED_BORDER)
self.compT = compT = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(150, 25), style=wx.RAISED_BORDER)
self.Bind(wx.EVT_TEXT_ENTER, self.OnNewComponent, compT)
gridSizer.Add(compT)
buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
applyBut = wx.Button(self, wx.ID_APPLY, 'Apply')
buttonSizer.Add(applyBut, 0, wx.ALL, 5)
mainSizer.Add(gridSizer, 0, wx.ALL, 10)
mainSizer.Add(buttonSizer, 0 , wx.ALIGN_RIGHT)
applyBut.Bind(wx.EVT_BUTTON, self.OnAcceptData)
self.SetSizerAndFit(mainSizer)
def OnNewNumber(self, event):
num = None
num = self.numT.GetValue()
foo = wx.MessageDialog(self, 'You entered: %\n' % numT.GetValue(),
foo = wx.MessageDialog(self, 'You entered: %\n' % num,
'Text Entered', style=wx.OK|wx.ICON_INFORMATION)
foo.ShowModal()
foo.Destroy()
return num
def OnNewComponent(self, event):
comp = None
comp = self.compT.GetValue()
bar = wx.MessageDialog(self, 'You entered: %\n' % compT.GetValue(),
bar = wx.MessageDialog(self, 'You entered: %\n' % comp,
'Text Entered', style=wx.OK|wx.ICON_INFORMATION)
bar.ShowModal()
bar.Destroy()
return num
return comp
def OnAcceptData(self, event):
self.OnNewNumber(event)
self.onNewComponent(event)
self.OnNewComponent(event)
#You should do something with the data returned by
#the above two methods.
#Perhaps by passing them to self.GetParent()
···
Rich Shepard <rshepard@appl-ecosys.com> wrote:
self.Close()
class MyFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title, size=(550,500))
panel = wx.Panel(self, -1)
wx.Button(panel, 1, 'Show Custom Dialog', (100,100))
wx.EVT_BUTTON(self, 1, self.OnShowCustomDialog)
def OnShowCustomDialog(self, event):
dia = MyDialog(self, -1)
dia.ShowModal()
dia.Destroy()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'customdialog1.py')
frame.Show(True)
frame.Centre()
return True
app = MyApp(0)
app.MainLoop()