Embedding Images in the HtmlWindow

HI folks,

A few months back, someone asked about how to embed images in a wx.html.HtmlWindow, without having to have the image in a file on the disk somewhere.

Discussion ensued, I posted a kind-of-ugly way to do it by embedding a wx.StaticBitmap that I couldn't figure out how to improve on.

Robin posted that you should be able to do it with wx.MemoryFSHandler().

Fast forward a couple months...

I figure out how to use wx.MemoryFSHandler(), and it's pretty slick. I've written up small sample, and posted it in the wiki here:

http://wiki.wxpython.org/wxHTML

Please check it out, improve it, add better description to the Wiki page, whatever.

In particular, while I like the wx.MemoryFSHandler() approach, I would like to better understand how the namespaces work when embedding a wx control in an HtmlWindow

For instance, I couldn't figure out how to embed an instance of a wx.StaticBitmap, rather than having to make a custom class -- anyone?

Enjoy,

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Since you need to pass a wx.Bitmap to the wx.StaticBitmap constructor and since the wxp tag handler doesn't have the smarts to be able to take a path name and convert it to a bitmap for you, then using a custom class is probably the only way to do it as it stands now.

In a nutshell, the wxp tag simply looks up the given class name in the given module, makes a dictionary out of the <param> tags specified and then calls the class passing those as keyword args. The HtmlWindow widget then manages things like the size and placement of the widget created by the wxpTag code.

Of course creating new tag handlers is always an option if you want to do more than that.

···

On 9/18/09 1:52 PM, Christopher Barker wrote:

In particular, while I like the wx.MemoryFSHandler() approach, I would
like to better understand how the namespaces work when embedding a wx
control in an HtmlWindow

For instance, I couldn't figure out how to embed an instance of a
wx.StaticBitmap, rather than having to make a custom class -- anyone?

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

In particular, while I like the wx.MemoryFSHandler() approach, I would
like to better understand how the namespaces work when embedding a wx
control in an HtmlWindow

For instance, I couldn't figure out how to embed an instance of a
wx.StaticBitmap, rather than having to make a custom class -- anyone?

Since you need to pass a wx.Bitmap to the wx.StaticBitmap constructor and since the wxp tag handler doesn't have the smarts to be able to take a path name and convert it to a bitmap for you,

well, I was thinking along the lines of having a wx.StaticBitmap instance that already had its bitmap, and passing that in. But I guess that wxHTML is expecting to instantiate the class?

But it's nice to know that my kludge is as good as it gets.

In a nutshell, the wxp tag simply looks up the given class name in the given module, makes a dictionary out of the <param> tags specified and then calls the class passing those as keyword args.

here is the key -- what namespace does that dictionary get build using? If I could access that namespace, I could put a pre-build wx.Bitmap in it.

Of course creating new tag handlers is always an option if you want to do more than that.

I'll keep that in mind -- for this purpose, I think the wx.MemoryFSHandler() approach is the elegant solution.

I'll add a bit more note to the Wiki,

-Chris

···

On 9/18/09 1:52 PM, Christopher Barker wrote:

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Robin Dunn wrote:

In particular, while I like the wx.MemoryFSHandler() approach, I would
like to better understand how the namespaces work when embedding a wx
control in an HtmlWindow

For instance, I couldn't figure out how to embed an instance of a
wx.StaticBitmap, rather than having to make a custom class -- anyone?

Since you need to pass a wx.Bitmap to the wx.StaticBitmap constructor
and since the wxp tag handler doesn't have the smarts to be able to take
a path name and convert it to a bitmap for you,

well, I was thinking along the lines of having a wx.StaticBitmap
instance that already had its bitmap, and passing that in. But I guess
that wxHTML is expecting to instantiate the class?

Yes. Well, it's done in the tag handler and it is designed to do the instantiation itself. I suppose that a different tag handler could be written that just makes a placeholder widget that can be replaced later, or something like that.

But it's nice to know that my kludge is as good as it gets.

In a nutshell, the wxp tag simply looks up the given class name in the
given module, makes a dictionary out of the<param> tags specified and
then calls the class passing those as keyword args.

here is the key -- what namespace does that dictionary get build using?
If I could access that namespace, I could put a pre-build wx.Bitmap in it.

See wx.lib.wxpTag. When it sees the opening <wxp> tag it creates an instance of _Context for storing the details found along the way. It uses the instance's __dict__ for the globals in the eval.

···

On 9/21/09 1:43 PM, Christopher Barker wrote:

On 9/18/09 1:52 PM, Christopher Barker wrote:

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

In a nutshell, the wxp tag simply looks up the given class name in the
given module, makes a dictionary out of the<param> tags specified and
then calls the class passing those as keyword args.

here is the key -- what namespace does that dictionary get build using?
If I could access that namespace, I could put a pre-build wx.Bitmap in it.

See wx.lib.wxpTag. When it sees the opening <wxp> tag it creates an instance of _Context for storing the details found along the way. It uses the instance's __dict__ for the globals in the eval.

So I should be able to patch something in there if I wanted it to be found. But for now, I don't need it, but I'll remember to look there if I ever do!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov