
import sys
import wx

#------------------------------------------------------------------------------

class SizeDialog( wx.Dialog ) :
    """ A simple custom dialog that returns the values of 2 wx.TextCtrl_s. """

    def __init__( self, parent, id, title, initialValues=(0, 0) ) :
        
        wid_initValue = initialValues[0]
        hgt_initValue = initialValues[1]
        
        dlgStyle = wx.CAPTION
        wx.Dialog.__init__( self, parent, id, title, size=(300, 120), 
                            style=dlgStyle )

        dlg_vertSizer = wx.BoxSizer( wx.VERTICAL )
        self.SetSizer( dlg_vertSizer )

        allCtrls_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
        allCtrls_horzSizer.AddSpacer( 15 )
        
        width_stTxt = wx.StaticText( self, -1, 'X' )
        allCtrls_horzSizer.Add( width_stTxt, proportion=0, 
                                flag=wx.ALIGN_CENTER | wx.ALL, border=5 )
        
        self.txtWidth_txtCtrl  = wx.TextCtrl( self, -1, str( wid_initValue ) )
        allCtrls_horzSizer.Add( self.txtWidth_txtCtrl, proportion=1, 
                                flag=wx.ALIGN_CENTER )
        
        allCtrls_horzSizer.AddSpacer( 15 )
        
        height_stTxt = wx.StaticText( self, -1, 'Y' )
        allCtrls_horzSizer.Add( height_stTxt, proportion=0, 
                                flag=wx.ALIGN_CENTER | wx.ALL, border=5 )
        
        self.txtHeight_txtCtrl = wx.TextCtrl( self, -1, str( hgt_initValue ) )
        
        allCtrls_horzSizer.Add( self.txtHeight_txtCtrl, proportion=1, 
                                flag=wx.ALIGN_CENTER )
        
        allCtrls_horzSizer.AddSpacer( 15 )
        
        allCtrlsHorzSizer_borderFlags = wx.ALL
        allCtrlsHorzSizer_posnFlags = wx.EXPAND | wx.ALIGN_CENTER
        allCtrlsHorzSizer_flags = allCtrlsHorzSizer_borderFlags | allCtrlsHorzSizer_posnFlags
        
        dlg_vertSizer.Add( allCtrls_horzSizer, proportion=0, 
                           flag=allCtrlsHorzSizer_flags, border=10 )
        
        btns_horzSizer = wx.BoxSizer( wx.HORIZONTAL )
        
        buttons = self.CreateSeparatedButtonSizer( flags=wx.OK | wx.CANCEL )
        
        dlg_vertSizer.Add( buttons, proportion=0, flag=wx.ALIGN_CENTER )
        
        self.SetSizer( dlg_vertSizer )
        
        #--------------------
        
        self.timeout_timer = wx.Timer( self, -1 )
        self.Bind( wx.EVT_TIMER, self.OnTimeout )
        timeout_secs = 5;  timeout_millisecs = 1000 * timeout_secs
        self.timeout_timer.Start( timeout_millisecs, oneShot=True )
        
    #end __init
    
    #------------------------
    
    def OnTimeout( self, event ) :
        print '!!!!  TIME-OUT  !!!!'
        self.Destroy()
        
    #--------------
    
    def GetWidth( self ) :
        return self.txtWidth_txtCtrl.GetValue()
    
    def GetHeight( self ) :
        return self.txtHeight_txtCtrl.GetValue()
    
#end SizeDialog class

#------------------------------------------------------------------------------

class DummyFrame( wx.Frame ) :
    """ The app frame that will never be seen.
        It's created simply to allow app.MainLoop() to run.
    """
    def __init__( self, parent=None, id=-1 ):
    
        wx.Frame.__init__( self, parent=parent, id=id, size=(400, 300), pos=(200, 0) )
        
        #self.Show()
        
        dlg = SizeDialog( None, -1, 'Custom Dialog with No Frame Resizing or Controls', 
                          initialValues=(16, 24) )
        dlgReturn_ID = dlg.ShowModal()
        try :
            self.Destroy()
        except PyDeadObjectError :
            pass
        #end try
        
        if dlgReturn_ID == wx.ID_OK :
            print
            print '----  You clicked "OK"'
            print '      Size:  (%s, %s)' % (dlg.GetWidth(), dlg.GetHeight())
            
        elif dlgReturn_ID == wx.ID_CANCEL :
            print
            print '----  "Cancel" or "X" clicked.'
        #end if
        
    #end __init
    
#end class

#==============================================================================
        
if __name__ == '__main__' :

    app = wx.PySimpleApp()
    appFrame = DummyFrame()
    app.MainLoop()
    
    sys.exit(1)  # Keep the MSW shell window open so I can read the print outputs.
    
#end if
