Hi,
I'm working on a Preferences/Options dialog for my application and I'm having trouble with a StaticText control of all things. My goal is to have a caption on each config page very similar to how FireFox does it. The caption should have:
* sunken window frame
* the background color and text color/size/weight should match system appearance/theme for active window captions
* padding around the text
* text centered vertically, aligned left
However, I'm having problems with the padding. I did come up with something (code below) that sort of works using window.GetFullTextExtent() and sizer.SetItemMinSize(), but it has a bad smell and is chopping off the descenders in the text. I realize I could use wx.HTML but that seems like overkill.
Also, is there anyway to find out the system's default text size and weight for active window captions?
Thanks in advance for any help!
-geoff
···
###
import wx
class DlgTest(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(
self,
parent,
-1,
"DlgTest",
style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
caption = wx.Panel(self, style=wx.SUNKEN_BORDER)
caption.SetBackgroundColour(
wx.SystemSettings.GetColour(wx.SYS_COLOUR_ACTIVECAPTION))
caption.SetForegroundColour(
wx.SystemSettings.GetColour(wx.SYS_COLOUR_CAPTIONTEXT))
text = wx.StaticText(
caption,
-1,
"Active Caption (descenders: gee jay pee queue why)")
extent = caption.GetFullTextExtent(text.GetLabel(), text.GetFont())
captionSizer = wx.BoxSizer(wx.VERTICAL)
captionSizer.Add(text, 1, wx.ALL, text.GetFont().GetPointSize())
captionSizer.SetItemMinSize(text, (extent[0], extent[1] + extent[2] + extent[3]))
caption.SetSizer(captionSizer)
mainSizer = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(caption, 0, wx.ALL|wx.EXPAND, 5)
mainSizer.Add(wx.TextCtrl(self, -1), 1, wx.ALL|wx.EXPAND, 5)
mainSizer.Add(wx.Button(self, wx.ID_OK), 0, wx.ALL|wx.ALIGN_RIGHT, 5)
self.SetSizer(mainSizer)
app = wx.PySimpleApp()
dlg = DlgTest(wx.Frame(None, -1))
dlg.ShowModal()
dlg.Destroy()