HtmlWindow (wxHTML) Widget
HtmlWindow is the wxWidgets HTML display widget. It can be found in the wx.html module. It is not a full featured browser, and does not support modern html features like CSS, and certainly not JavaScript. However, it can be very useful for laying out and rendering a wide variety of documents, using a well understood markup language. It also has the wonderful special feature of being able to embed wx Widgets in an html page.
HtmlWindow and Form tags
HtmlWindow has no form support, but it can be extended with custom tag handlers. Download this attachment for a sample package implementing support for HTML forms.
Embedding Images in HtmlWindow
HtmlWindow can display inline images in the usual way, by providing a url to the image. However, if you want to be able to use HtmlWindow to display a page with some images, but don't want to have to have the image files on the file system, there are a couple ways to embed images that you have in memory, and can be loaded from python code (or gotten into memory any other way).
The following example demonstrates two ways:
* Using HtmlWindow's ability to show a wx widget on the page, and embedding a wxStaticBitmap. HtmlWindow is expecting to instantiate the class, and there is no way to pass a wx.Bitmap into the constructor, so you need a custom class. If you want to do something more fancy, you can creating new tag handler.
* Using wx.MemoryFSHandler(). HtmlWindow uses wx.FileSystem as an abstraction of the file system to load resources. You can add a MemoryFSHandler to it, and put whatever you want in there. I think this is the cleanest way to do it, and the html is then pretty standard.
Note: in the below code, the html refers to the name of the module that the "Bitmap1" class is defined, which is this file, so you need to name it ImageInHtml.py in order for it to work.
import wx import wx.lib.wxpTag # The html page as a python string literal page = r""" <HTML> <BODY> <H1>Embedding an Image in wxHTML</H1> <H3> As a wx.StaticBitmap: </H3> <center> <wxp module="ImageInHtml" class="Bitmap1"> </wxp> </center> <H3> Using a MemoryFSHandler: </H3> <center> <img src="memory:smalltest.png"> </center> </BODY> </HTML> """ class Bitmap1(wx.StaticBitmap): """ A custom StaticBitmap class that holds your image. """ def __init__(self, *args, **kwargs): """ The __init__ is called by the HtmlWindow, it takes all the usual wx.Window parameters, then the custom bitmap is added to the key word arguments. """ bmp = smalltest.GetBitmap() kwargs['bitmap'] = bmp wx.StaticBitmap.__init__(self, *args, **kwargs) class DemoFrame(wx.Frame): """ This window displays a HtmlWindow """ def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) htmlwin = wx.html.HtmlWindow(self) htmlwin.SetPage(page) class MyApp(wx.App): """ A little test wx.App """ def OnInit(self): # add the image to the MemoryFileSystem: mfs = wx.MemoryFSHandler() wx.FileSystem_AddHandler(mfs) mfs.AddFile("smalltest.png", smalltest.GetImage(), wx.BITMAP_TYPE_PNG) # Initializing the Frame frame = DemoFrame(None, title="HTML Tester Window", size = (500,500)) self.SetTopWindow(frame) frame.Show(True) return True ## This is the image data itself, created with the img2py utility that ## ships with wxPython from wx.lib.embeddedimage import PyEmbeddedImage smalltest = PyEmbeddedImage( "iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABHNCSVQICAgIfAhkiAAAAAlw" "SFlzAAAMIgAADCIByQlnqQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoA" "ABYNSURBVHic7Z13mFTl2Yfv58zM9pndnS0gTTEiCiodBURUVAzGjiWaKKAQNVZUDGI00aiI" "idFE/YJiIjGKijGABRGNBpSmCIgggtIUlrJ1tk97vj8OwsK2mdnZPbOze1/XuWDPvOU55/2d" "txdRVdppuxhWG9COtbQLoI3TLoA2TrsA2jjtAmjjtAugjWO32gCrEZEhuTDJBt0UXEGwC3xV" "CIt9sBpYq6pFVtvZXEhb7QcQkTQ3LOsOXe6FjJ5AOmaW+BWwGvzLwLMaxAPBBFiyF/6gqqus" "tTzKqGqbvLJg1qNQpaCNXdWgb0KwDxRmmfoYYrX90braZA4gIkN6w7trIcMWpt/lwLVQUgDz" "CuAWVfU0h40tRZusBObCuKkRJD7AKcAGSJ8MV2TAJhEZGW37WpI2mQN0ENmyGrp3amI4G4Ex" "UJwH/ymEX6tqZTTsa0naXA4gImkOyGxq4gMcB6yFjAlwZRbMFxGJQrAtSpsTANDrJAhGKzAb" "MA2SfwonZ8Gj0Qq3pWiLAujdD1KjHegL4OwIE0VkQLTDbk7anACyYFBvSAzXXxBYCDwC3ung" "O7wzIAG4BpwGDIyGnS1Fm+sJ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" "5Ltq/DYiVAEAKkmi9uNtmnRFYoU4Zb7VCV3P89owK3yH218AdLbKLiubgddifumCucvTOzV2" "Ah1M6Av00CrF/02AqterHVqqE6JvatMQEQfwDgeLhZqUqurOFjbpAFYKIJ2DB/EkYOYIr4hI" "NnARh5aTjRNEUeao6p6oWhkdXgGGU3v7s0LC34cmqsTSnMA04ELMJbqRDPZsBK6JqkVRQEQm" "AxcDXszuoor9/88HrlJVS88dtlIAFZjlf81cKHH/FS4lmDXp6B0fGgX27xu8ChiDWaSlAbsw" "Wz6brbTtRyxrBopIV8xj15u6y0M1MFhVW+0R7lZiWR1AzalRk2naIIgHGNue+JFjeU+giJyB" "ORCSjtlLFmqxVAY8r6qTmsu2toDlAoAD/f79gdOA0fv/H8AsHuoShA9zUeZp2krX5ccKMSGA" "wxGRjpgJ3Im6m4M7gRNUtbhFDYtDYnU+QE/M4qAu+4qBUe2JHx1iUgCq+j+gH2bbvubewR7g" "Co3C8G47JjFZBPzI/nb0ZcAfMcV6pbbi3ThikZgWwI/sryQ61KIx83imVQigneYjJusA7bQc" "7QJo47QLoI3TLoA2TrsA2jjtAmjjtAugjdMugDbO/wOgoxtWADHq7wAAAABJRU5ErkJggg==") if __name__ == "__main__" : app = MyApp(0) app.MainLoop()