import wx

#import sys
#sys.setdefaultencoding('UTF-8')

if wx.Platform == '__WXMSW__':
    import  wx.lib.iewin    as  iewin


class App(wx.App):
    def OnInit(self):
            title = 'test'
            dlg = wx.Dialog(parent=None,id=-1,title=title,
			    size=(800, 700), pos=(-1,-1),
			    style=wx.SUNKEN_BORDER|wx.DEFAULT_DIALOG_STYLE)
            sizer = wx.BoxSizer(wx.VERTICAL)
            self.ie = iewin.IEHtmlWindow(dlg, -1, 
			    style = wx.NO_FULL_REPAINT_ON_RESIZE )            
            sizer.Add(self.ie, 1, wx.EXPAND)
            self.location = wx.ComboBox(
                            dlg, -1, "", style=wx.CB_DROPDOWN|wx.PROCESS_ENTER
                            )
            self.Bind(wx.EVT_COMBOBOX, self.OnLocationSelect, self.location)
            self.location.Bind(wx.EVT_KEY_UP, self.OnLocationKey)
            self.location.Bind(wx.EVT_CHAR, self.IgnoreReturn)
            self.current = "http://www.google.com"
            self.ie.LoadUrl(self.current)
            self.location.Append(self.current)
            dlg.SetSizer(sizer)
            # Since this is a wxWindow we have to call Layout ourselves
            self.Bind(wx.EVT_SIZE, self.OnSize)

	    dlg.Bind(wx.EVT_CLOSE, self.OnClose)
            dlg.ShowModal()           
            return True

    def OnClose(self, evt):
	    wx.MessageBox("You can not close the window right now. Sorry.",
			    "That's all folks!")
	    evt.Veto()
    
    def OnSize(self, evt):
        self.Layout()

    def OnLocationSelect(self, evt):
        url = self.location.GetStringSelection()
        self.log.write('OnLocationSelect: %s\n' % url)
        self.ie.Navigate(url)

    def OnLocationKey(self, evt):
        if evt.KeyCode() == wx.WXK_RETURN:
            URL = self.location.GetValue()
            self.location.Append(URL)
            self.ie.Navigate(URL)
        else:
            evt.Skip()

    def IgnoreReturn(self, evt):
        if evt.GetKeyCode() != wx.WXK_RETURN:
            evt.Skip()

if __name__ == '__main__':
    app = App()
    app.MainLoop()
