During a refactoring session, I put a lot of my gui code into little functions which directly inserts data into a wx.Sizer object.
For instance, this little function:
def buildStatusDisplay(self, status_disp, flag):
grid = wx.FlexGridSizer(cols=1, hgap=5, vgap=0)
font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.LIGHT, False, 'Segoe UI')
for option in status_disp:
left = wx.StaticText(self, -1, option)
left.SetFont(font)
grid.Add(left, 0, flag=flag)
return grid
So it creates all of the StaticText objects using the throwaway left, and then returns the FlexGrid. However, I need some of the labels in the StaticText objects to update based on user input, but, I’m not sure how to access them.
I’ve looped through the sizer that gets returned from the function, but I don’t see anything relating to a way that would let me get reference to the objects which make up the sizer.
for i in dir(sizer):
print i
>>Add
>>AddF
>>AddGrowableCol
>>AddGrowableRow
>>AddItem
>>AddMany
>>AddSizer
>>AddSpacer
>>AddStretchSpacer
>>AddWindow
>>CalcMin
>>CalcRowsCols
>>Children
>>ClassName
>>Clear
>>ColWidths
>>Cols
>>ComputeFittingCli
>>ComputeFittingWin
>>ContainingWindow
>>DeleteWindows
>>Destroy
>>Detach
>>Fit
>>FitInside
>>FlexibleDirection
>>GetChildren
>>GetClassName
>>GetColWidths
>>GetCols
>>GetContainingWind
>>GetFlexibleDirect
>>GetHGap
>>GetItem
>>GetItemIndex
>>GetMinSize
>>GetMinSizeTuple
>>GetNonFlexibleGro
>>GetPosition
>>GetPositionTuple
>>GetRowHeights
>>GetRows
>>GetSize
>>GetSizeTuple
>>GetVGap
>>HGap
>>Hide
>>Insert
>>InsertF
>>InsertItem
>>InsertSizer
>>InsertSpacer
>>InsertStretchSpac
>>InsertWindow
>>IsSameAs
>>IsShown
>>Layout
>>MinSize
>>NonFlexibleGrowMo
>>Position
>>Prepend
>>PrependF
>>PrependItem
>>PrependSizer
>>PrependSpacer
>>PrependStretchSpa
>>PrependWindow
>>RecalcSizes
>>Remove
>>RemoveGrowableCol
>>RemoveGrowableRow
>>RemovePos
>>RemoveSizer
>>RemoveWindow
>>Replace
>>RowHeights
>>Rows
>>SetCols
>>SetContainingWind
>>SetDimension
>>SetFlexibleDirect
>>SetHGap
>>SetItemMinSize
>>SetMinSize
>>SetNonFlexibleGro
>>SetRows
>>SetSizeHints
>>SetVGap
>>SetVirtualSizeHin
>>Show
>>ShowItems
>>Size
>>VGap
>>_ReplaceItem
>>_ReplaceSizer
>>_ReplaceWin
>>_SetItemMinSize
>>__class__
>>__del__
>>__delattr__
>>__dict__
>>__doc__
>>__format__
>>__getattribute__
>>__hash__
>>__init__
>>__module__
>>__new__
>>__reduce__
>>__reduce_ex__
>>__repr__
>>__setattr__
>>__sizeof__
>>__str__
>>__subclasshook__
>>__swig_destroy__
>>__weakref__
>>_setOORInfo
GetChildren() returns only SizerItems which don’t seem to hold any reference to the underlying objects either.
Anyone know how to access something inside of a sizer? I suppose I could just explode the function a bit and either return a list of the objects as well as the sizer, or simple dump the function and keep identifiers to the objects I need to modify in main.. but… my gui code is already spaghetti enough. If I can avoid it, I would like to.
On the
wx.SizerItem, there is aGetWindowwhich gives you exactly that. UseIsWindowto check if there is a ‘window’ available. All underlying objects inherit fromwx.Window, so that is what you want.Here is an example,
objis awx.Frameobject: