I've seen this once, but can't find it at the moment. It goes something like the:
-
f = window.GetFont()
-
dc = wx.WindowDC(window)
-
dc.SetFont(f)
-
width, height = dc.GetTextExtent("Text to measure")
By "window", I mean the widget that will get the text.
Once again BartonC saves the day! Thanks a bunch, that code worked flawlessly with only one minor thing.
Since this is in a status bar and the text is at the end of the status bar, it gets cut off by the window resize 'grabber area' (if that makes any sense). See I have a date/time display in the last field of my status bar... so as I update the text I adjust the size of that last field with the following code:
-
# This is the timer's update function
-
def Notify(self):
-
t = time.localtime(time.time())
-
st = time.strftime(" %b %d, %Y %I:%M:%S", t)
-
self.SetStatusText(st, 3)
-
f = self.sb.GetFont()
-
dc = wx.WindowDC(self.sb)
-
dc.SetFont(f)
-
width, height = dc.GetTextExtent(st)
-
self.sb.SetStatusWidths([-4, -2, 17, width + 30])
-
I know it's not a very good idea to just use an assumed size of 30 for that little box in the corner, but it works on the systems that used to get cut off and looks the same on the systems that never had the problem in the first place so; success!!
Thanks again to BartonC, the Forum Rock Star.