#!/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.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.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
        foo = wx.MessageDialog(self, 'You entered: %\n' % numT.GetValue(),
                               'Text Entered', style=wx.OK|wx.ICON_INFORMATION)
        foo.ShowModal()
        foo.Destroy()
        return num

    def OnNewComponent(self, event):
        comp = None
        bar = wx.MessageDialog(self, 'You entered: %\n' % compT.GetValue(),
                               'Text Entered', style=wx.OK|wx.ICON_INFORMATION)
        bar.ShowModal()
        bar.Destroy()
        return num

    def OnAcceptData(self, event):
        self.OnNewNumber(event)
        self.onNewComponent(event)
        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()
