[TreeCtrl Q1]What's the default font for TreeCtrl item?

Hi,

  I found out that the font for the TreeCtrl item is not the system default font. I get the system default font and set the tree item font to it, then I find that the tree item text looks slightly different from the original one. So I write a small script to narrow down the problem, and find that wxpy crash!

    This is my script:

···

##=================================================
import wx

class myFrame(wx.Frame): ## {{{
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
        ##------ panel
        self.panel_=wx.Panel(self,-1)
        self.sizer_ = wx.BoxSizer( wx.VERTICAL )
        self.tree_ = wx.TreeCtrl(self.panel_,-1)
        root = self.tree_.AddRoot('xxx')
        ##------ put stuff into sizer
        self.sizer_.Add(self.tree_,proportion = 1,flag=wx.EXPAND)

        ## apply sizer
        self.panel_.SetSizer(self.sizer_)
        self.panel_.SetAutoLayout(True)
        ## this cause an error!!!!
        default_font = self.tree_.GetItemFont(root)
        print default_font
        default_fontname = default_font.GetFaceName()
        default_fontsize = default_font.GetPointSize()
        print default_fontname
        print default_fontsize
## }}}

def main(): ## {{{
    app = wx.PySimpleApp(0)
    frame = myFrame(None,-1,title='')
    frame.Show(True)
    app.SetTopWindow(frame)
    app.MainLoop()
## }}}

if __name__ == "__main__":main()

##=================================================
    
    Could Any kind soul help me out? Any help would be appreciated!

Best regards,

    Bruce Who
      2005\-05\-30

Bruce Who wrote:

Hi,

  I found out that the font for the TreeCtrl item is not the system default font. I get the system default font and set the tree item font to it, then I find that the tree item text looks slightly different from the original one. So I write a small script to narrow down the problem, and find that wxpy crash!

        ## this cause an error!!!!
        default_font = self.tree_.GetItemFont(root)

You'll want to check default_font.Ok() before using it. An "invalid"
font (wx.NullFont actually) normally means to use the platform or theme
default, whatever it is. For windows the window.GetFont() method will
actually look up the system font and will give that to you, so you could
add this:

  if not default_font.Ok():
    default_font = self.tree_.GetFont()

···

        print default_font
        default_fontname = default_font.GetFaceName()
        default_fontsize = default_font.GetPointSize()
        print default_fontname
        print default_fontsize

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!