2010-01-16 1 views
1

Suite à this tutorial sur WxPython, j'ai remarqué que dans l'exemple de dialogue Rechercher/Remplacer il y a des panneaux supplémentaires où il ne semble pas qu'ils font quoi que ce soit. En fait, ils semblent gâcher encore plus la mise en page (bien que ce soit probablement une erreur que je fait quelque part) Par exemple, le tutoriel a ce code:Pourquoi devrais-je créer plusieurs wx.Panel?

panel = wx.Panel(self, -1) 

panel1 = wx.Panel(panel, -1) 
grid1 = wx.GridSizer(2, 2) 
grid1.Add(wx.StaticText(panel1, -1, 'Find: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL) 
grid1.Add(wx.ComboBox(panel1, -1, size=(120, -1))) 
grid1.Add(wx.StaticText(panel1, -1, 'Replace with: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL) 
grid1.Add(wx.ComboBox(panel1, -1, size=(120, -1))) 

panel1.SetSizer(grid1) 
vbox.Add(panel1, 0, wx.BOTTOM | wx.TOP, 9) 

Pourquoi est-ce différent de:

panel = wx.Panel(self, -1) 

grid1 = wx.GridSizer(2, 2) 
grid1.Add(wx.StaticText(panel, -1, 'Find: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL) 
grid1.Add(wx.ComboBox(panel, -1, size=(120, -1))) 
grid1.Add(wx.StaticText(panel, -1, 'Replace with: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL) 
grid1.Add(wx.ComboBox(panel, -1, size=(120, -1))) 

vbox.Add(grid1, 0, wx.BOTTOM | wx.TOP, 9) 

Notez que je ne crée pas un panneau, en ajoutant simplement grid1 directement à vbox.

Répondre

1

Je ne suis pas sûr. J'ai réécrit l'exemple en moins de code, même si c'est un peu difficile à suivre. Je peux lui envoyer ces suggestions par courriel.

import wx 

class FindReplace(wx.Dialog): 
    def __init__(self, parent, id, title): 
     wx.Dialog.__init__(self, parent, id, title, size=(255, 365)) 

     vbox_top = wx.BoxSizer(wx.VERTICAL) 
     vbox = wx.BoxSizer(wx.VERTICAL) 

     grid1 = wx.GridSizer(2, 2) 
     grid1.Add(wx.StaticText(self, -1, 'Find: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL) 
     grid1.Add(wx.ComboBox(self, -1, size=(120, -1))) 
     grid1.Add(wx.StaticText(self, -1, 'Replace with: ', (5, 5)), 0, wx.ALIGN_CENTER_VERTICAL) 
     grid1.Add(wx.ComboBox(self, -1, size=(120, -1))) 


     hbox2 = wx.BoxSizer(wx.HORIZONTAL) 
     sizer21 = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Direction'), orient=wx.VERTICAL) 
     sizer21.Add(wx.RadioButton(self, -1, 'Forward', style=wx.RB_GROUP)) 
     sizer21.Add(wx.RadioButton(self, -1, 'Backward')) 
     hbox2.Add(sizer21, 1, wx.RIGHT, 5) 

     sizer22 = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Scope'), orient=wx.VERTICAL) 
     # we must define wx.RB_GROUP style, otherwise all 4 RadioButtons would be mutually exclusive 
     sizer22.Add(wx.RadioButton(self, -1, 'All', style=wx.RB_GROUP)) 
     sizer22.Add(wx.RadioButton(self, -1, 'Selected Lines')) 
     hbox2.Add(sizer22, 1) 


     sizer3 = wx.StaticBoxSizer(wx.StaticBox(self, -1, 'Options'), orient=wx.VERTICAL) 
     vbox3 = wx.BoxSizer(wx.VERTICAL) 
     grid = wx.GridSizer(3, 2, 0, 5) 
     grid.Add(wx.CheckBox(self, -1, 'Case Sensitive')) 
     grid.Add(wx.CheckBox(self, -1, 'Wrap Search')) 
     grid.Add(wx.CheckBox(self, -1, 'Whole Word')) 
     grid.Add(wx.CheckBox(self, -1, 'Incremental')) 
     vbox3.Add(grid) 
     vbox3.Add(wx.CheckBox(self, -1, 'Regular expressions')) 
     sizer3.Add(vbox3, 0, wx.TOP, 4) 


     sizer4 = wx.GridSizer(2, 2, 2, 2) 
     sizer4.Add(wx.Button(self, -1, 'Find', size=(120, -1))) 
     sizer4.Add(wx.Button(self, -1, 'Replace/Find', size=(120, -1))) 
     sizer4.Add(wx.Button(self, -1, 'Replace', size=(120, -1))) 
     sizer4.Add(wx.Button(self, -1, 'Replace All', size=(120, -1))) 

     sizer5 = wx.BoxSizer(wx.HORIZONTAL) 
     sizer5.Add((191, -1), 1, wx.EXPAND | wx.ALIGN_RIGHT) 
     sizer5.Add(wx.Button(self, -1, 'Close', size=(50, -1))) 


     vbox.Add(grid1, 0, wx.BOTTOM | wx.TOP, 9)   
     vbox.Add(hbox2, 0, wx.BOTTOM, 9)   
     vbox.Add(sizer3, 0, wx.BOTTOM, 15)   
     vbox.Add(sizer4, 0, wx.BOTTOM, 9)   
     vbox.Add(sizer5, 1, wx.BOTTOM, 9) 
     vbox_top.Add(vbox, 1, wx.LEFT, 5) 

     self.SetSizer(vbox_top) 
     self.Centre() 


app = wx.App(False) 
d = FindReplace(None, -1, 'Find/Replace') 
d.ShowModal() 
d.Destroy() 
app.MainLoop() 
+0

Eh bien, merci. BTW, je viens de le remarquer: le vbox_top est-il nécessaire? Cela semble un peu redondant. – Javier

+0

Pas vraiment, semble qu'il est seulement utilisé pour espacer la grille entière des widgets 5px de la gauche de la fenêtre. Je ne suis pas un fan de tous les -1 "id" étant utilisés, mais cba pour changer cela :) C'est un inconvénient de wx, si vous voulez spécifier une certaine frontière pour un groupe de widgets, en les plaçant dans un calibreur est le chemin à parcourir. –

Questions connexes