[wxPython] Using dialog units

As a newbie just getting to know (and love) Python and wxPython, I have
been getting in a muddle using dialog units through sometimes having to
use pixels. I've created the two helper functions below in order to stick
to dialog units as far as possible.

I know they are trivial, but someone might find them useful.

Regards,
David Hughes
Forestfield Software Ltd

···

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

# Helper functions to complement wxDLG_SZE that convert one dimensional
# horizontal or vertical distances from dialog units to pixels

from wxPython.wx import *

def wxDLG_HD(win,dx):
    dy = -1 # dummy height
    pix_s = wxDLG_SZE(win, wxSize(dx,dy)) # creates wxSize object
    return pix_s.GetWidth()

def wxDLG_VD(win,dy):
    dx = -1 # dummy width
    pix_s = wxDLG_SZE(win, wxSize(dx,dy))
    return pix_s.GetHeight()

Sample usage:

    listID = NewId()
    self.list = wxListCtrl(self, listID, wxDefaultPosition,
                wxDefaultSize, wxLC_REPORT|wxSUNKEN_BORDER)
    lcs = wxLayoutConstraints()
    lcs.top.SameAs(self,wxTop,wxDLG_VD(self,56)) # dialog above here
    lcs.left.SameAs(self,wxLeft,wxDLG_HD(self,6))
    lcs.bottom.SameAs(self,wxBottom,wxDLG_VD(self,6))
    lcs.right.SameAs(self,wxRight,wxDLG_HD(self,6))
    self.list.SetConstraints(lcs) # list occupies remainder
        
    ... read the dialog and
    populate the list...

    self.list.SetColumnWidth(0, wxLIST_AUTOSIZE)
    self.list.SetColumnWidth(1, wxDLG_HD(self.list,40))
    self.list.SetColumnWidth(2, wxDLG_HD(self.list,24))