wx.DC GetTextExtent woes - 2.8.11.0 vs 2.9.2.4

Hi All,

I am building a nice app which contains a (wx.lib.agw) CustomTreeCtrl on the left side. I have run the app on 2.8.11.0 up to now and everything was fine. However, I gave it a go and run it on 2.9.2.4 and now the CustomTreeCtrl items look like fat pigs, each of them occupying way too much vertical space (i.e., there is too much blank space between two adjacent siblings).

As the CustomTreeCtrl demo (apparently) does not exhibit this issue (or it does not exhibit it too much), I thought the reason my app is showing the problem is because I have mixed bold/normal fonts and also varying font sizes (between 8 and 11 points). Lo and behold, it appears that in 2.9.2.4 something has been changed in the way text extensions are measured using wx.DC.GetTextExtent (the wx.DC.GetMultiLineTextExtent suffers of the same problem) or I have missed some important migration note between 2.8 and 2.9.

On Windows 7, Python 2.5.4, If you run the attached sample using wxPython 2.8.11.0, you might see this output:

E:\MyProjects>dc_issue.py

What’s going on with dc.GetTextExtent()?

Python 2.5.4-final, wxPython 2.8.11.0 (msw-unicode)

Measuring string: Hello wxPython & wxWidgets

Font size : 9

Bold font : False

width, height : 188, 18

Font size : 9

Bold font : True

width, height : 220, 18

Font size : 11

Bold font : True

width, height : 266, 22

On Windows 7, Python 2.7.2, If you run the attached sample using wxPython 2.9.2.4, you might see this output::

E:\MyProjects>python dc_issue.py

What’s going on with dc.GetTextExtent()?

Python 2.7.2-final, wxPython 2.9.2.4 msw (classic)

Measuring string: Hello wxPython & wxWidgets

Font size : 10

Bold font : False

width, height : 224, 23

Font size : 10

Bold font : True

width, height : 240, 23

Font size : 12

Bold font : True

width, height : 284, 28

As you can see, in 2.9.2.4 both width and height are way off their (correct, as reported by wxPython 2.8.11.0) values, by a factor between 10% and 20%.

What am I missing?

Thank you in advance for your suggestions.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

dc_issue.py (1.7 KB)

···

import wx

The only thing I know about is that the way that the default font is fetched has changed, (a different (more modern) API, or something like that) so your two examples will actually be using different fonts.

dc_issue.py (1.69 KB)

···

On 10/7/11 2:07 PM, Andrea Gavana wrote:

Hi All,

     I am building a nice app which contains a (wx.lib.agw)
CustomTreeCtrl on the left side. I have run the app on 2.8.11.0 up to
now and everything was fine. However, I gave it a go and run it on
2.9.2.4 and now the CustomTreeCtrl items look like fat pigs, each of
them occupying way too much vertical space (i.e., there is too much
blank space between two adjacent siblings).

As the CustomTreeCtrl demo (apparently) does not exhibit this issue (or
it does not exhibit it too much), I thought the reason my app is showing
the problem is because I have mixed bold/normal fonts and also varying
font sizes (between 8 and 11 points). Lo and behold, it appears that in
2.9.2.4 something has been changed in the way text extensions are
measured using wx.DC.GetTextExtent (the wx.DC.GetMultiLineTextExtent
suffers of the same problem) or I have missed some important migration
note between 2.8 and 2.9.

On Windows 7, Python 2.5.4, If you run the attached sample using
wxPython 2.8.11.0, you might see this output:

As you can see, in 2.9.2.4 both width and height are way off their
(correct, as reported by wxPython 2.8.11.0) values, by a factor between
10% and 20%.

What am I missing?

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

What's going on with dc.GetTextExtent()?

Python 2.6.6-final, wxPython 2.8.12.1 (msw-unicode)

Measuring string: Hello wxPython & wxWidgets

Font size : 9
Bold font : False
Face name : MS Shell Dlg 2
width, height : 162, 14

Font size : 9
Bold font : True
Face name : MS Shell Dlg 2
width, height : 182, 14

Font size : 11
Bold font : True
Face name : MS Shell Dlg 2
width, height : 220, 18

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

What's going on with dc.GetTextExtent()?

Python 2.7.1-final, wxPython 2.9.2.4 msw (classic)

Measuring string: Hello wxPython & wxWidgets

Font size : 10
Bold font : False
Face name : Segoe UI
width, height : 169, 17

Font size : 10
Bold font : True
Face name : Segoe UI
width, height : 185, 17

Font size : 12
Bold font : True
Face name : Segoe UI
width, height : 229, 21

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

--
Robin Dunn
Software Craftsman

GetTextExtent is also part the problem with wx.lib.masked.numctrl in 2.9.2 when using "useFixedWidthFont=False", numbers are no longer correctly aligned and control size is not correctly calculated.

My fix which is attached to "masked numctrl diff between 2.8 and 2.9" thread is more of a hack then a fix.

Werner

···

On 10/08/2011 06:08 AM, Robin Dunn wrote:

On 10/7/11 2:07 PM, Andrea Gavana wrote:

Hi All,

     I am building a nice app which contains a (wx.lib.agw)
CustomTreeCtrl on the left side. I have run the app on 2.8.11.0 up to
now and everything was fine. However, I gave it a go and run it on
2.9.2.4 and now the CustomTreeCtrl items look like fat pigs, each of
them occupying way too much vertical space (i.e., there is too much
blank space between two adjacent siblings).

As the CustomTreeCtrl demo (apparently) does not exhibit this issue (or
it does not exhibit it too much), I thought the reason my app is showing
the problem is because I have mixed bold/normal fonts and also varying
font sizes (between 8 and 11 points). Lo and behold, it appears that in
2.9.2.4 something has been changed in the way text extensions are
measured using wx.DC.GetTextExtent (the wx.DC.GetMultiLineTextExtent
suffers of the same problem) or I have missed some important migration
note between 2.8 and 2.9.

On Windows 7, Python 2.5.4, If you run the attached sample using
wxPython 2.8.11.0, you might see this output:

As you can see, in 2.9.2.4 both width and height are way off their
(correct, as reported by wxPython 2.8.11.0) values, by a factor between
10% and 20%.

What am I missing?

The only thing I know about is that the way that the default font is fetched has changed, (a different (more modern) API, or something like that) so your two examples will actually be using different fonts.