self.GetContainingSizer().SetItemMinSize(self,(0,(dc.GetTextExtent(lines[0])[1]+verticalspacing)*lines.__len__()))
in DisplayText is supposed to make is so the sizer will be big enough for
the text, but it seems like it's always 1 refresh behind.
If you run the code and restore and maximize it, the DisplayText is the size
it should have been when you restored it.
import wx
info={'Country 1':{'comparison 1':[True,'text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text'],'comparison
2':[True,'text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text']},'Country 2':{'comparison 1':[True,'text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text'],'comparison 2':[True,'text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text']},'Country
3':{'comparison 1':[True,'text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text'],'comparison 2':[True,'text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text
text text text']}}
class frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,'Comparing Countries')
self.SetBackgroundColour('white')
self.countries=info.keys()
self.countries.sort()
self.framesizer=wx.BoxSizer(wx.HORIZONTAL)
#countries lists
self.listsplitter=wx.SplitterWindow(self)
self.listsplitter.SetSashGravity(.5)
self.list1=wx.ListBox(self.listsplitter,choices=self.countries)
self.list1.SetSelection(0)
self.list2=wx.ListBox(self.listsplitter,choices=self.countries)
self.list2.SetSelection(1)
self.listsplitter.SplitHorizontally(self.list1,self.list2)
self.framesizer.Add(self.listsplitter,0,wx.EXPAND|wx.TOP|wx.LEFT|wx.BOTTOM,5)
self.Bind(wx.EVT_LISTBOX,self.newcountry)
#countries lists
self.countryscroll=wx.ScrolledWindow(self)
self.countrysizer=wx.BoxSizer(wx.VERTICAL)
self.countryscroll.SetSizer(self.countrysizer)
self.countryscroll.SetScrollbars(20,20,50,50)
self.countryscroll.SetFocus()
self.framesizer.Add(self.countryscroll,1,wx.EXPAND)
self.SetMinSize((800,500))
self.newcountry(None)
self.SetSizer(self.framesizer)
self.Maximize()
self.Show()
def newcountry(self,event):
self.countrysizer.Clear(True)
#country info
titlessizer=wx.BoxSizer(wx.HORIZONTAL)
self.title1=wx.StaticText(self.countryscroll,label=self.list1.GetStringSelection(),style=wx.ALIGN_CENTER)
self.title2=wx.StaticText(self.countryscroll,label=self.list2.GetStringSelection(),style=wx.ALIGN_CENTER)
self.title1.SetFont(wx.Font(40,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.title2.SetFont(wx.Font(40,wx.SWISS,wx.NORMAL,wx.NORMAL))
titlessizer.Add(self.title1,1,wx.LEFT|wx.RIGHT,20)
titlessizer.Add(self.title2,1,wx.LEFT|wx.RIGHT,20)
self.countrysizer.Add(titlessizer,0,wx.EXPAND|wx.ALL,5)
#country info
keys=info[self.list1.GetStringSelection()].keys()
keys.sort()
for i in range(0,keys.__len__()):
if
info[self.list1.GetStringSelection()][keys[i]][0]==info[self.list2.GetStringSelection()][keys[i]][0]:
temp=wx.StaticText(self.countryscroll,label=keys[i],style=wx.ALIGN_CENTER)
temp.SetFont(wx.Font(30,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.countrysizer.Add(temp,0,wx.EXPAND|wx.ALL,5)
tempsizer=wx.BoxSizer(wx.HORIZONTAL)
temp=DisplayText(self.countryscroll,text=info[self.list1.GetStringSelection()][keys[i]][1],fontsize=18)
tempsizer.Add(temp,1,wx.EXPAND|wx.LEFT|wx.RIGHT,40)
temp=DisplayText(self.countryscroll,text=info[self.list2.GetStringSelection()][keys[i]][1],fontsize=18)
tempsizer.Add(temp,1,wx.EXPAND|wx.LEFT|wx.RIGHT,40)
self.countrysizer.Add(tempsizer,0,wx.EXPAND|wx.ALL,5)
self.countryscroll.Refresh()
self.countrysizer.Layout()
class DisplayText(wx.Panel):
def __init__(self,parent,text='',fontsize=10,size=(-1,-1)):
wx.Panel.__init__(self,parent,-1,size=size)
self.SetBackgroundColour('grey')
self.Bind(wx.EVT_PAINT,self.OnPaint)
self.Bind(wx.EVT_SIZE,self.OnSize)
self.font=wx.Font(fontsize,wx.SWISS,wx.NORMAL,wx.NORMAL)
self.text=text
def SetText(self,text):
self.text=text
self.Refresh()
def OnPaint(self,event):
dc=wx.PaintDC(self)
dc.SetFont(self.font)
if self.text!='':
w,h=self.GetSize()
verticalspacing=0
words=self.text.split()
lines=[' '+words[0]]
currentline=0
for i in range(1,words.__len__()):
if dc.GetTextExtent(lines[currentline]+' '+words[i])[0]<w:
if lines[currentline]!='':
lines[currentline]+=' '
lines[currentline]+=words[i]
else:
lines+=[words[i]]
currentline+=1
self.GetContainingSizer().SetItemMinSize(self,(0,(dc.GetTextExtent(lines[0])[1]+verticalspacing)*lines.__len__()))
for i in range(0,lines.__len__()):
tw,th=dc.GetTextExtent(lines[i])
dc.DrawText(lines[i],0,(th+verticalspacing)*i)
def OnSize(self,event):
self.Refresh()
app=wx.App()
f=frame()
app.MainLoop()
···
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/Sizers-again-tp4437363p4437363.html
Sent from the wxPython-users mailing list archive at Nabble.com.