You can also use a wx.ClientDC for this and save a few steps dealing with the bitmap. ClientDCs are kind of frowned upon for drawing these days because of how the newer environments work, but we've tried to ensure that ClientDCs are still a good lightweight-as-possible solution for measuring text. In fact, that is what wx.Window.GetTextExtent uses internally, but if you're going to be measuring a bunch of text snippets it would be better to create just one wx.ClientDC and use it to do the measuring.
···
On 2/27/12 10:56 PM, Andrea Gavana wrote:
Hi Michael,
On 28 February 2012 02:21, Michael Hipp wrote:
I'm trying to do some column auto-sizing on a DataViewCtrl. This seems to be
the call to find out the on-screen size of a string:
wxDC:GetFullTextExtent(string, font=NULL)
I can get the wxFont() being used and I have a string to test, but how do I
get the DC for the wx.DataViewCtrl?
I never used DataViewCtrl myself, but for measuring text I normally do
something like this:
dc = wx.MemoryDC()
# Whatever number
dc.SelectObject(wx.EmptyBitmap(100, 100))
width, height, d, e = dc.GetFullTextExtent(my_text, my_font)