Changing font style/size for overall wx.python GUI look

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ateale
    New Member
    • Jun 2007
    • 46

    #1

    Changing font style/size for overall wx.python GUI look

    Hey guys

    I have had a bit of a hunt around on google to try find out how to change the overall default font style/size for a wx.python app - but not had any luck.

    Does anyone have any idea if it is possible?

    All I really want to do is make the wx.StaticText, wx.CheckBox, wx.TextCtrl & wx.Button fonts smaller in my GUI app

    Thanks if anyone can give me some pointers!

    Cheers

    Adam
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by ateale
    Hey guys

    I have had a bit of a hunt around on google to try find out how to change the overall default font style/size for a wx.python app - but not had any luck.

    Does anyone have any idea if it is possible?

    All I really want to do is make the wx.StaticText, wx.CheckBox, wx.TextCtrl & wx.Button fonts smaller in my GUI app

    Thanks if anyone can give me some pointers!

    Cheers

    Adam
    One word: inheritance! Set the font size for a panel and all the widgets on that panel get that font size by default. Same thing with any parent of any widget. Since the app is not a window, nobody inherits attributes from it.

    I'm pretty sure, but I'll double check that.

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by bartonc
      One word: inheritance! Set the font size for a panel and all the widgets on that panel get that font size by default. Same thing with any parent of any widget. Since the app is not a window, nobody inherits attributes from it.

      I'm pretty sure, but I'll double check that.
      wxWindow is the lowes object that I could find that has a font attribute. The most interesting thing that I stumbled across was this:
      Originally posted by wxWidgets 2.8.0: A portable C++ and Python GUI toolkit
      wxWindow::Inher itAttributes
      void InheritAttribut es()

      This function is (or should be, in case of custom controls) called during window creation to intelligently set up the window visual attributes, that is the font and the foreground and background colours.

      By "intelligently' ' the following is meant: by default, all windows use their own default attributes. However if some of the parents attributes are explicitly (that is, using SetFont and not SetOwnFont) changed and if the corresponding attribute hadn't been explicitly set for this window itself, then this window takes the same value as used by the parent. In addition, if the window overrides ShouldInheritCo lours to return false, the colours will not be changed no matter what and only the font might.

      This rather complicated logic is necessary in order to accommodate the different usage scenarios. The most common one is when all default attributes are used and in this case, nothing should be inherited as in modern GUIs different controls use different fonts (and colours) than their siblings so they can't inherit the same value from the parent. However it was also deemed desirable to allow to simply change the attributes of all children at once by just changing the font or colour of their common parent, hence in this case we do inherit the parents attributes.

      Comment

      • ateale
        New Member
        • Jun 2007
        • 46

        #4
        Thanks BartonC !
        I had a look and tried to use:
        font = wx.Font(10, wx.FONTFAMILY_M ODERN, wx.NORMAL, wx.BOLD)
        wx.Window.SetFo nt(self, font)

        but it doesn't change anything

        I don't think i really understand the wx.window and inheritance thing. I read about inheritance in the doc, but I don't understand how to apply it to my script

        i just realised I am using wx.Frame not wx.Window - guess this is the reason?

        Any ideas?

        Thanks!

        Adam

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by ateale
          Thanks BartonC !
          I had a look and tried to use:
          panel.SetFont(w x.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))

          but it doesn't change anything

          I don't think i really understand the wx.window and inheritance thing. I read about inheritance in the doc, but I don't understand how to apply it to my script

          Any ideas?

          Thanks!

          Adam
          Yep. When you're sticking down your widgets in a frame, you need to watch who the parent is. I'll use a subclass of dialog as an example:[CODE=python]
          class SegmentDialog(w x.Dialog): # The parent of widgets that get self as their parent
          def _init_ctrls(sel f, prnt):
          # generated method, don't edit
          wx.Dialog.__ini t__(self, id=wxID_SEGMENT DIALOG, name='SegmentDi alog', parent=prnt,
          pos=wx.Point(8, 8), size=wx.Size(10 08, 724), style=wx.DEFAUL T_DIALOG_STYLE,
          title='Station Capture - HETAP Pro 2.0')
          self.SetFont(wx .Font(18, wx.SWISS, wx.NORMAL, wx.NORMAL, False,'MS Shell Dlg 2'))
          # the panel would get that font, but gets its own, instead.

          self.panel1 = wx.Panel(id=wxI D_SEGMENTDIALOG PANEL1, name='panel1', parent=self, # Here is the panel's parent #
          pos=wx.Point(0, 0), size=wx.Size(10 08, 696), style=wx.TAB_TR AVERSAL)
          self.panel1.Set BackgroundColou r(wx.Colour(232 , 232, 232))
          self.panel1.Set ToolTipString(' ')
          self.panel1.Set Font(wx.Font(16 , wx.SWISS, wx.NORMAL, wx.BOLD, False,'MS Shell Dlg 2'))
          # widgets get the panel as the parent

          self.staticLine 1 = wx.StaticLine(i d=wxID_SEGMENTD IALOGSTATICLINE 1, name='staticLin e1',
          parent=self.pan el1, pos=wx.Point(16 , 185), size=wx.Size(79 5, 3), style=0)
          # and, so, get that font

          def __init__(self, parent, dbDialog, publisher):
          self._init_ctrl s(parent)[/CODE]

          Hope that's clear.

          Comment

          Working...