alignment - wxPython - Align buttons in an expanding sizer -
i'm trying make dialog looks similar wx.messagedialog. there's section @ bottom coloured different in code, buttons not cooperate.
the buttons should aligned right, , bottom section should expand colour grey. there's simple solution, able see error?
this sizer set expand:
this sizer set not expand:
here's working simplified version of code demonstrates issue. troublesome code @ bottom, surrounded "===":
import wx class testdialog(wx.dialog): def __init__(self, parent, msg, title): wx.dialog.__init__(self, parent, id=-1, title=title) # outer sizer, allow spot @ bottom buttons outersizer = wx.boxsizer(wx.vertical) # main sizer message dialog mainsizer = wx.boxsizer(wx.horizontal) staticicon = wx.staticbitmap(self, bitmap=wx.artprovider.getbitmap(wx.art_information), size=(32,32)) mainsizer.add(staticicon, flag=wx.all, border=10) # sizer hold message , buttons controlssizer = wx.boxsizer(wx.vertical) # static text field show (error/warning) message on message dialog errortext = wx.statictext(self, -1, msg, wx.defaultposition, wx.defaultsize, 0) errortext.wrap(600) # sizer can nest inside controls sizer. allows use multiple border flags errortextsizer = wx.boxsizer(wx.horizontal) errortextsizer.add(errortext, flag=wx.top, border=15) # add error text controls sizer controlssizer.add(errortextsizer, flag=wx.right, border=10) # outer button panel, slighty greyed outerbuttonpanel = wx.panel(self) outerbuttonpanelsizer = wx.boxsizer(wx.horizontal) outerbuttonpanel.setsizer(outerbuttonpanelsizer) # button "yes" option btnyes = wx.button(outerbuttonpanel, label='yes') btnyes.bind(wx.evt_button, self.__yes) outerbuttonpanelsizer.add(btnyes, flag=wx.align_right | wx.all, border=15) # button "no" option btnno = wx.button(outerbuttonpanel, label='no') btnno.bind(wx.evt_button, self.__no) outerbuttonpanelsizer.add(btnno, flag=wx.align_right | wx.right | wx.top | wx.bottom, border=15) outerbuttonpanel.setbackgroundcolour(wx.colour(100, 100, 100)) # find decent colour # add sizers each other, finish mainsizer.add(controlssizer) outersizer.add(mainsizer) # ==================================================================== outersizer.add(outerbuttonpanel, flag=wx.align_right | wx.expand) # ==================================================================== #outersizer.add(outerbuttonpanel, flag=wx.align_right) # ==================================================================== # done layout self.setsizerandfit(outersizer) self.centeronscreen() def __yes(self, evt): self.endmodal(wx.id_yes) def __no(self, evt): self.endmodal(wx.id_no) if __name__ == '__main__': app = wx.app() dlg = testdialog(none, "test test test test test test test test test test test test test test test test", "test title") val = dlg.showmodal() print "dialog result: " + str(val == wx.id_yes) app.exit()
at last, solution. wx apparently doesn't approve of multiple horizontal box sizers nested panel @ core. more specifically, doesn't when attempt align set expand. can tell, have nest multiple panels , vertical box sizers (with horizontal box sizer buttons).
here's example above, working properly. literally, change
outerbuttonpanelsizer = wx.boxsizer(wx.vertical)
to
outerbuttonpanelsizer = wx.boxsizer(wx.horizontal)
and whole thing breaks.
import wx class testdialog(wx.dialog): def __init__(self, parent, msg, title): wx.dialog.__init__(self, parent, id=-1, title=title) # outer sizer, allow spot @ bottom buttons outersizer = wx.boxsizer(wx.vertical) # main sizer message dialog mainsizer = wx.boxsizer(wx.horizontal) staticicon = wx.staticbitmap(self, bitmap=wx.artprovider.getbitmap(wx.art_information), size=(32,32)) mainsizer.add(staticicon, flag=wx.all, border=10) # sizer hold message , buttons controlssizer = wx.boxsizer(wx.vertical) # static text field show (error/warning) message on message dialog errortext = wx.statictext(self, -1, msg, wx.defaultposition, wx.defaultsize, 0) errortext.wrap(600) # sizer can nest inside controls sizer. allows use multiple border flags errortextsizer = wx.boxsizer(wx.horizontal) errortextsizer.add(errortext, flag=wx.top, border=15) # add error text controls sizer controlssizer.add(errortextsizer, flag=wx.right, border=10) # outer button panel, slighty greyed outerbuttonpanel = wx.panel(self) outerbuttonpanelsizer = wx.boxsizer(wx.vertical) outerbuttonpanel.setsizer(outerbuttonpanelsizer) # inner panel buttons (this allows right align buttons innerbuttonpanel = wx.panel(outerbuttonpanel) innerbuttonpanelsizer = wx.boxsizer(wx.horizontal) # button "yes" option btnyes = wx.button(innerbuttonpanel, label='yes') btnyes.bind(wx.evt_button, self.__yes) innerbuttonpanelsizer.add(btnyes, flag=wx.all, border=15) # button "no" option btnno = wx.button(innerbuttonpanel, label='no') btnno.bind(wx.evt_button, self.__no) innerbuttonpanelsizer.add(btnno, flag=wx.right | wx.top | wx.bottom, border=15) # add inner button panel outer button panel , align right innerbuttonpanel.setsizer(innerbuttonpanelsizer) outerbuttonpanelsizer.add(innerbuttonpanel, flag=wx.align_right) outerbuttonpanel.setbackgroundcolour(wx.colour(100, 100, 100)) # find decent colour # add sizers each other, finish mainsizer.add(controlssizer) outersizer.add(mainsizer) # ==================================================================== outersizer.add(outerbuttonpanel, flag=wx.expand) # done layout self.setsizerandfit(outersizer) self.centeronscreen() def __yes(self, evt): self.endmodal(wx.id_yes) def __no(self, evt): self.endmodal(wx.id_no) if __name__ == '__main__': app = wx.app() dlg = testdialog(none, "test test test test test test test test test test test test test test test test", "test title") val = dlg.showmodal() print "dialog result: " + str(val == wx.id_yes) app.exit()
Comments
Post a Comment