python - wxPython -- Adding statictext resizes the panel -


i have simple setup of flexgridsizer creating 3 x 3 grid: (quick note easy reading: pvs = sizers, pvp = panels)

    pvs["flex"] = wx.flexgridsizer(rows = 3, cols = 3, vgap = 0, hgap = 0)     index, vert in enumerate(pv.vertnames):         horiz in pv.horiznames:             pvp["{0}_{1}".format(vert, horiz)] = wx.panel(self)             pvp["{0}_{1}".format(vert, horiz)].setbackgroundcolour(c.colors["black"])      panel in pvp.values():         pvs["flex"].add(panel, flag = wx.expand)      proportions = (1, 6, 1)      index, prop in enumerate(proportions):         pvs["flex"].addgrowablecol(index, prop)         pvs["flex"].addgrowablerow(index, prop)      self.setsizer(pvs["flex"]) 

i don't explicitly set size of panels, sized growable rows , column proportions.

later down way, add, say, 2 statictexts top middle panel:

    pvs[me] = {"vert": wx.boxsizer(wx.vertical)}     pvt[me] = {}      panel.setforegroundcolour(c.colors["blue"])     pvt[me]["title"] = wx.statictext(panel, label = c.title)     pvt[me]["title"].setownfont(titlefont)     pvt[me]["subtitle"] = wx.statictext(panel, label = c.subtitle)     pvt[me]["subtitle"].setownfont(subfont)      pvs[me]["vert"].add(pvt[me]["title"], flag = wx.align_center)     pvs[me]["vert"].add(pvt[me]["subtitle"], flag = wx.align_center)      panel.setsizer(pvs[me]["vert"]) 

finally issue: adding these statictexts resizes top middle panel wider , taller. there way lock flexgridsizer proportions? or perhaps i'm doing wrong can change avoid behavior?

in troubleshooting, discovered there plenty of room text fit in @ original panel size given large font size. can drop font size 5 , tiny still resizes panel tiny bit larger, it's it's pushing way panel instead of fitting inside.

i discovered issue having leaving panels without size growable based on put in them. decided add explicit sizes still keep them flexible different frame sizes having sizes created on-the-fly based on percentages:

    width = self.package.frame.size[0]     height = self.package.frame.size[1]     corner = ((width * .125), (height * .125))     ns = ((width * .75), (height * .125))     ew = ((width * .125), (height * .75))     mid = ((width * .75), (height * .75))     sizeiter = iter((corner, ns, corner, ew, mid, ew, corner, ns, corner)) 

and in loop created panels:

pvp["{0}_{1}".format(vert, horiz)] = wx.panel(self) 

changed to:

pvp["{0}_{1}".format(vert, horiz)] = wx.panel(self, size = next(sizeiter)) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -