1 # Contributor and minor fixes: Marcelo Barbero, Argentina
   2 # Revision: 02 May 2006
   3 
   4 # LearnSizer*.py is a small application aimed to learn the sizers and
   5 # their usage.
   6 # This application is a collection of panels. Each panel contains
   7 # a few widgets laid out with sizers. The panels are numbered
   8 # MyPanel_0 to MyPanel_n. The panel 0 is the simpliest case. The
   9 # order of the panels follows an increasing complexity in the
  10 # layout. It is warmly recommended to start with MyPanel_0.
  11 #
  12 # Do not forget:
  13 # - the wxPython doc
  14 # - the wiki page http://wiki.wxpython.org/index.cgi/UsingSizers
  15 # - dir(<instance of a sizer>) for a list of methods
  16 # - print sizer.method.__doc__
  17 #
  18 #--------------------------------------------------------------------
  19 
  20 import os
  21 import sys
  22 import wx
  23 
  24 #-------------------------------------------------------------------
  25 
  26 # - a wx.Window with a coloured background
  27 # - pos and size == (-1, -1) since sizers are used
  28 class ColWin(wx.Window):
  29 
  30     def __init__(self, parent, id, BackColour):
  31         wx.Window.__init__(self, parent, id, (-1, -1), (-1, -1), wx.SIMPLE_BORDER)
  32         self.SetBackgroundColour(BackColour)
  33 
  34 #-------------------------------------------------------------------
  35 
  36 
  37 class MyPanel_0(wx.Panel):
  38     """
  39     - the simplest sizer, a ColWin
  40     - use of named arguments
  41     """
  42 
  43     def __init__(self, parent):
  44         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
  45 
  46         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
  47 
  48         b = 20
  49         vsizer1 = wx.BoxSizer(orient=wx.VERTICAL)
  50         # or
  51         # vsizer1 = wx.BoxSizer(orient=wx.HORIZONTAL)
  52         vsizer1.Add(item=wgreen, proportion=1, flag=wx.EXPAND | wx.ALL, border=b)
  53         self.SetSizer(vsizer1)
  54 
  55 #-------------------------------------------------------------------
  56 
  57 class MyPanel_1(wx.Panel):
  58     """
  59     - two ColWins, vertically
  60     """
  61 
  62     def __init__(self, parent):
  63         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
  64 
  65         wred = ColWin(self, wx.NewId(), wx.RED)
  66         wblue = ColWin(self, wx.NewId(), wx.BLUE)
  67 
  68         b = 5
  69         vsizer1 = wx.BoxSizer(wx.VERTICAL)
  70         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
  71         vsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
  72         self.SetSizer(vsizer1)
  73 
  74 #-------------------------------------------------------------------
  75 
  76 class MyPanel_2(wx.Panel):
  77     """
  78     - three ColWins, horizontally
  79     """
  80 
  81     def __init__(self, parent):
  82         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
  83 
  84         wred = ColWin(self, wx.NewId(), wx.RED)
  85         wblue = ColWin(self, wx.NewId(), wx.BLUE)
  86         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
  87 
  88         b = 5
  89         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
  90         hsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
  91         hsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
  92         hsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
  93         self.SetSizer(hsizer1)
  94 
  95 #-------------------------------------------------------------------
  96 
  97 class MyPanel_3(wx.Panel):
  98     """
  99     - three ColWins, horizontally, height ratio 1:2:3
 100     """
 101 
 102     def __init__(self, parent):
 103         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 104 
 105         wred = ColWin(self, wx.NewId(), wx.RED)
 106         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 107         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 108 
 109         b = 5
 110         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 111         hsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 112         hsizer1.Add(wblue, 2, wx.EXPAND | wx.ALL, b)
 113         hsizer1.Add(wgreen, 3, wx.EXPAND | wx.ALL, b)
 114         self.SetSizer(hsizer1)
 115 
 116 #-------------------------------------------------------------------
 117 
 118 class MyPanel_4(wx.Panel):
 119     """
 120     - two ColWins, vertically, a fixed width of 50 pixels between the two items
 121     """
 122 
 123     def __init__(self, parent):
 124         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 125 
 126         wred = ColWin(self, wx.NewId(), wx.RED)
 127         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 128 
 129         b = 5
 130         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 131         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 132         vsizer1.Add((-1, 50), 0,  wx.ALL, b)
 133         vsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 134         self.SetSizer(vsizer1)
 135 
 136 #-------------------------------------------------------------------
 137 
 138 class MyPanel_5(wx.Panel):
 139     """
 140     - two items, a ColWin and a Button, vertically
 141     - the Button is either left/right aligned or centered
 142     - comment / uncomment for testing the Button alignment
 143     - wx.ALIGN_LEFT is the default value
 144     """
 145 
 146     def __init__(self, parent):
 147         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 148 
 149         wred = ColWin(self, wx.NewId(), wx.RED)
 150         b1 = wx.Button(self, wx.NewId(), 'button1', (-1, -1), wx.DefaultSize)
 151 
 152         b = 5
 153         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 154         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 155 
 156         #~ vsizer1.Add(b1, 0, wx.ALIGN_LEFT | wx.ALL, b)
 157         #~ vsizer1.Add(b1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 158         vsizer1.Add(b1, 0, wx.ALIGN_CENTER | wx.ALL, b)
 159         self.SetSizer(vsizer1)
 160 
 161 #-------------------------------------------------------------------
 162 
 163 class MyPanel_6(wx.Panel):
 164     """
 165     - three items, a ColWin and two Buttons
 166     - the Buttons are either left/right aligned or centered
 167     """
 168 
 169     def __init__(self, parent):
 170         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 171 
 172         wred = ColWin(self, wx.NewId(), wx.RED)
 173         b1 = wx.Button(self, wx.NewId(), '&OK', (-1, -1), wx.DefaultSize)
 174         b2 = wx.Button(self, wx.NewId(), '&Cancel', (-1, -1), wx.DefaultSize)
 175 
 176         b = 10
 177         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 178         hsizer1.Add(b1, 0)
 179         hsizer1.Add(b2, 0, wx.LEFT, b)
 180 
 181         b = 5
 182         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 183         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 184         vsizer1.Add(hsizer1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 185         #~ vsizer1.Add(hsizer1, 0, wx.ALIGN_CENTER | wx.ALL, b)
 186         #~ vsizer1.Add(hsizer1, 0, wx.ALIGN_LEFT | wx.ALL, b)
 187         self.SetSizer(vsizer1)
 188 
 189 #-------------------------------------------------------------------
 190 
 191 class MyPanel_7(wx.Panel):
 192     """
 193     - four items, a ColWin, two Buttons, and a StaticLine
 194     - the Buttons are either left/right aligned or centered
 195     - the height of the static line == 2, the wx.GROW flag specifies an
 196       horizontal expansion, since the StaticLine is in a vertical sizer
 197     """
 198     def __init__(self, parent):
 199         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 200         
 201         wred = ColWin(self, wx.NewId(), wx.RED)
 202         b1 = wx.Button(self, wx.NewId(), '&OK', (-1, -1), wx.DefaultSize)
 203         b2 = wx.Button(self, wx.NewId(), '&Cancel', (-1, -1), wx.DefaultSize)
 204         staline = wx.StaticLine(self, wx.NewId(), (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
 205         
 206         b = 5
 207         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 208         hsizer1.Add(b1, 0)
 209         hsizer1.Add(b2, 0, wx.LEFT, b)
 210         
 211         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 212         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 213         vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
 214         vsizer1.Add(hsizer1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 215         self.SetSizer(vsizer1)
 216 
 217 #-------------------------------------------------------------------
 218 
 219 class MyPanel_8(wx.Panel):
 220     """
 221     - 7 items, 2 ColWins and 5 Buttons
 222     - ColWins: one is sizable, the others not
 223     - Buttons at the right of the frame
 224     - something like a toolbar at the right
 225     """
 226 
 227     def __init__(self, parent):
 228         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 229 
 230         wred = ColWin(self, wx.NewId(), wx.RED)
 231         wwhite = ColWin(self, wx.NewId(), wx.WHITE)
 232 
 233         b1 = wx.Button(self, wx.NewId(), '1', (-1, -1), wx.DefaultSize)
 234         b2 = wx.Button(self, wx.NewId(), '2', (-1, -1), wx.DefaultSize)
 235         b3 = wx.Button(self, wx.NewId(), '3', (-1, -1), wx.DefaultSize)
 236         b4 = wx.Button(self, wx.NewId(), '4', (-1, -1), wx.DefaultSize)
 237         b5 = wx.Button(self, wx.NewId(), '5', (-1, -1), wx.DefaultSize)
 238 
 239         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 240         b = 3
 241         vsizer1.Add(wred, 1, wx.EXPAND | wx.BOTTOM, b)
 242         vsizer1.Add(wwhite, 0, wx.EXPAND, b)
 243 
 244         vsizer2 = wx.BoxSizer(wx.VERTICAL)
 245         b = 5
 246         vsizer2.Add(b1, 0, wx.BOTTOM, b)
 247         vsizer2.Add(b2, 0, wx.BOTTOM, b)
 248         vsizer2.Add(b3, 0, wx.BOTTOM, b)
 249         vsizer2.Add(b4, 0, wx.BOTTOM, b)
 250         vsizer2.Add(b5, 0, wx.BOTTOM, b)
 251 
 252         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 253         b = 10
 254         hsizer1.Add(vsizer1, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.BOTTOM, b)
 255         hsizer1.Add(vsizer2, 0, wx.EXPAND| wx.ALL, b)
 256 
 257         self.SetSizer(hsizer1)
 258 
 259 #-------------------------------------------------------------------
 260 
 261 class MyPanel_9(wx.Panel):
 262     """
 263     - 7 items, 2 ColWins and 5 Buttons
 264     - the ColWins are sizable
 265     - the Buttons have a fixed height and a default width
 266     - something like a toolbar at the top
 267     """
 268     def __init__(self, parent):
 269         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 270 
 271         wred = ColWin(self, wx.NewId(), wx.RED)
 272         wwhite = ColWin(self, wx.NewId(), wx.WHITE)
 273 
 274         h = 40
 275         b1 = wx.Button(self, wx.NewId(), '1', (-1, -1), (-1, h))
 276         b2 = wx.Button(self, wx.NewId(), '2', (-1, -1), (-1, h))
 277         b3 = wx.Button(self, wx.NewId(), '3', (-1, -1), (-1, h))
 278         b4 = wx.Button(self, wx.NewId(), '4', (-1, -1), (-1, h))
 279         b5 = wx.Button(self, wx.NewId(), '5', (-1, -1), (-1, h))
 280 
 281         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 282         hsizer1.Add(b1, 0)
 283         hsizer1.Add(b2, 0)
 284         hsizer1.Add(b3, 0)
 285         hsizer1.Add(b4, 0)
 286         hsizer1.Add(b5, 0)
 287 
 288         b = 2
 289         hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
 290         hsizer2.Add(wred, 1, wx.EXPAND | wx.RIGHT, b)
 291         hsizer2.Add(wwhite, 1, wx.EXPAND | wx.LEFT, b)
 292 
 293         b = 5
 294         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 295         vsizer1.Add(hsizer1, 0, wx.EXPAND, b)
 296         vsizer1.Add(hsizer2, 1, wx.ALL | wx.EXPAND, b)
 297 
 298         self.SetSizer(vsizer1)
 299 
 300 #-------------------------------------------------------------------
 301 
 302 class MyPanel_10(wx.Panel):
 303     """
 304     - three ColWins in a StaticBoxSizer, vertically
 305     """
 306 
 307     def __init__(self, parent):
 308         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 309 
 310         wred = ColWin(self, wx.NewId(), wx.RED)
 311         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 312         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 313 
 314         b = 10  #inside the staticbox
 315         vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'StaticboxSizer with a caption'), wx.VERTICAL)
 316         vsbsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 317         vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 318         vsbsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 319         self.SetSizer(vsbsizer1)
 320 
 321 #-------------------------------------------------------------------
 322 
 323 class MyPanel_11(wx.Panel):
 324     """
 325     - three ColWins in a StaticBoxSizer, vertically
 326     - the StaticBoxSizer is in a sizer to enable a border
 327     """
 328 
 329     def __init__(self, parent):
 330         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 331 
 332         wred = ColWin(self, wx.NewId(), wx.RED)
 333         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 334         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 335 
 336         b = 10  #inside the staticbox
 337         vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'StaticboxSizer with a caption'), wx.VERTICAL)
 338         vsbsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 339         vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 340         vsbsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 341 
 342         b = 20
 343         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 344         hsizer1.Add(vsbsizer1, 1, wx.EXPAND | wx.ALL, b)
 345 
 346         self.SetSizer(hsizer1)
 347 
 348 #-------------------------------------------------------------------
 349 
 350 class MyPanel_12(wx.Panel):
 351     """
 352     - 5 ColWins, vertically
 353     - the ColWins 2 and 4 are in StaticBoxSizers
 354     """
 355     def __init__(self, parent):
 356         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 357 
 358         wred = ColWin(self, wx.NewId(), wx.RED)
 359         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 360         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 361         wwhite = ColWin(self, wx.NewId(), wx.WHITE)
 362         wyellow = ColWin(self, wx.NewId(), wx.NamedColour('yellow'))
 363         
 364         b = 10
 365         vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'blue'), wx.VERTICAL)
 366         vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 367         
 368         vsbsizer2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'white'), wx.VERTICAL)
 369         vsbsizer2.Add(wwhite, 1, wx.EXPAND | wx.ALL, b)
 370         
 371         b = 5
 372         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 373         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 374         vsizer1.Add(vsbsizer1, 1, wx.EXPAND | wx.ALL, b)
 375         vsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 376         vsizer1.Add(vsbsizer2, 1, wx.EXPAND | wx.ALL, b)
 377         vsizer1.Add(wyellow, 1, wx.EXPAND | wx.ALL, b)
 378         
 379         self.SetSizer(vsizer1)
 380 
 381 #-------------------------------------------------------------------
 382 
 383 class MyPanel_13(wx.Panel):
 384     """
 385     - 3 StaticBoxSizers with each a ColWin
 386     - the StaticBoxSizers are arranged vertically
 387     """
 388 
 389     def __init__(self, parent):
 390         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 391 
 392         wred = ColWin(self, wx.NewId(), wx.NamedColour('green'))
 393         wgreen = ColWin(self, wx.NewId(), wx.NamedColour('red'))
 394         wblue = ColWin(self, wx.NewId(), wx.NamedColour('blue'))
 395         
 396         b = 10
 397         sizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'Staticbox'), wx.VERTICAL)
 398         sizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 399 
 400         sizer2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'Staticbox'), wx.VERTICAL)
 401         sizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 402 
 403         sizer4 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'Staticbox'), wx.VERTICAL)
 404         sizer4.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 405         
 406         #tricky: the 2nd and 3rd staticbox sizer are shifted one pixel to the
 407         #left, try with b2 = 0
 408         b1, b2 = 0, -1
 409         sizer3 = wx.BoxSizer(wx.HORIZONTAL)
 410         sizer3.Add(sizer1, 1, wx.EXPAND, b1)
 411         sizer3.Add(sizer2, 1, wx.EXPAND | wx.LEFT, b2)
 412         sizer3.Add(sizer4, 1, wx.EXPAND | wx.LEFT, b2)
 413         
 414         self.SetSizer(sizer3)
 415 
 416 #-------------------------------------------------------------------
 417 
 418 class MyPanel_14(wx.Panel):
 419     """
 420     - 3 ColWins, horizontally, 2 spacers with a fixed height
 421     """
 422     def __init__(self, parent):
 423         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 424 
 425         wred = ColWin(self, wx.NewId(), wx.RED)
 426         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 427         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 428 
 429         b = 0
 430         h = 20
 431         hsizer1 = wx.BoxSizer(wx.VERTICAL)
 432         hsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 433         hsizer1.Add((-1, h))
 434         hsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 435         hsizer1.Add((-1, h))
 436         hsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 437         self.SetSizer(hsizer1)
 438 
 439 #-------------------------------------------------------------------
 440 
 441 class MyPanel_15(wx.Panel):
 442     """
 443     - 4 items, a ColWin, 3 Buttons
 444     - Buttons 1 and 3 are left/right aligned, Button 2 is centered
 445     - use of spacers to set a gap between the Buttons.
 446     - better way?
 447     """
 448 
 449     def __init__(self, parent):
 450         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 451 
 452         wgreen = ColWin(self, wx.NewId(), wx.NamedColour('green'))
 453         b1 = wx.Button(self, wx.NewId(), 'button1', (-1, -1), wx.DefaultSize)
 454         b2 = wx.Button(self, wx.NewId(), 'button2', (-1, -1), wx.DefaultSize)
 455         b3 = wx.Button(self, wx.NewId(), 'button3', (-1, -1), wx.DefaultSize)
 456 
 457         b = 0
 458         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 459         hsizer1.Add(b1, 0, wx.ALL, b)
 460         hsizer1.Add((-1, -1), 1)
 461         hsizer1.Add(b2, 0, wx.ALL, b)
 462         hsizer1.Add((-1, -1), 1)
 463         hsizer1.Add(b3, 0, wx.ALL, b)
 464 
 465         #tip: this does not work
 466         #~ b = 0
 467         #~ hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 468         #~ hsizer1.Add(b1, 0, wx.ALIGN_LEFT, b)
 469         #~ hsizer1.Add(b2, 0, wx.ALIGN_CENTER, b)
 470         #~ hsizer1.Add(b3, 0, wx.ALIGN_RIGHT, b)
 471 
 472         b = 5
 473         vsizer2 = wx.BoxSizer(wx.VERTICAL)
 474         vsizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 475         vsizer2.Add(hsizer1, 0, wx.EXPAND | wx.ALL, b)
 476         self.SetSizer(vsizer2)
 477 
 478 #-------------------------------------------------------------------
 479 
 480 class MyPanel_16(wx.Panel):
 481     """
 482     - 4 items, a ColWin, 3 Buttons
 483     - Buttons 1 and 3 are top/bottom aligned, Button 2 is centered
 484     - use of spacers to set a gap between the Buttons
 485     - better way?
 486     """
 487 
 488     def __init__(self, parent):
 489         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 490 
 491         wgreen = ColWin(self, wx.NewId(), wx.NamedColour('green'))
 492         b1 = wx.Button(self, wx.NewId(), 'button1', (-1, -1), wx.DefaultSize)
 493         b2 = wx.Button(self, wx.NewId(), 'button2', (-1, -1), wx.DefaultSize)
 494         b3 = wx.Button(self, wx.NewId(), 'button3', (-1, -1), wx.DefaultSize)
 495 
 496         b = 0
 497         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 498         vsizer1.Add(b1, 0, wx.ALL, b)
 499         vsizer1.Add((-1, -1), 1)
 500         vsizer1.Add(b2, 0, wx.ALL, b)
 501         vsizer1.Add((-1, -1), 1)
 502         vsizer1.Add(b3, 0, wx.ALL, b)
 503 
 504         b = 5
 505         hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
 506         hsizer2.Add(vsizer1, 0, wx.EXPAND | wx.ALL, b)
 507         hsizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 508         self.SetSizer(hsizer2)
 509 
 510 #-------------------------------------------------------------------
 511 
 512 class MyPanel_17(wx.Panel):
 513     """
 514     - an input box
 515     """
 516 
 517     def __init__(self, parent):
 518         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 519         self.parent = parent
 520 
 521         s = 'abc' + os.linesep + 'def' + os.linesep + 'ghi'
 522         statxt = wx.StaticText(self, -1, s, (-1, -1), (-1, -1))
 523         txt = wx.TextCtrl(self, wx.NewId(), 'input', (-1, -1), (-1, -1))
 524         staline = wx.StaticLine(self, -1, (-1, -1), (-1, -1), wx.LI_HORIZONTAL)
 525 
 526         b1 = wx.Button(self, wx.NewId(), "&OK", (-1, -1), wx.DefaultSize)
 527         b2 = wx.Button(self, wx.NewId(), "&Cancel", (-1, -1), wx.DefaultSize)
 528 
 529         b = 10
 530         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 531         hsizer1.Add(b1, 0)
 532         hsizer1.Add(b2, 0, wx.LEFT, b)
 533 
 534         b = 5
 535         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 536         vsizer1.Add(statxt, 0, wx.GROW | wx.ALL, b)
 537         vsizer1.Add(txt, 0, wx.GROW | wx.ALL, b)
 538         vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
 539         vsizer1.Add(hsizer1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 540         vsizer1.SetMinSize((300, -1))
 541         self.SetSizerAndFit(vsizer1)
 542 
 543         #the items are not sizable, once set, pass the fitted size to
 544         #the parent
 545         self.parent.SetClientSize(vsizer1.GetSize())
 546 
 547 #-------------------------------------------------------------------
 548 
 549 class MyPanel_18(wx.Panel):
 550     """
 551     - a message box
 552     """
 553 
 554     def __init__(self, parent):
 555         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 556         self.parent = parent
 557 
 558         s = 'This is a rather long message with.'
 559         s += (os.linesep + 'a lot of lines...')*20
 560 
 561         statxt = wx.StaticText(self, -1, s, (-1, -1), (-1, -1))
 562         staline = wx.StaticLine(self, -1, (-1, -1), (-1, -1), wx.LI_HORIZONTAL)
 563         b1 = wx.Button(self, wx.NewId(), "&OK", (-1, -1), wx.DefaultSize)
 564 
 565         b = 5
 566         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 567         vsizer1.Add(statxt, 1, wx.EXPAND | wx.ALL, b)
 568         vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
 569         vsizer1.Add(b1, 0, wx.ALIGN_CENTER | wx.ALL, b)
 570         vsizer1.SetMinSize((200, -1))
 571         self.SetSizerAndFit(vsizer1)
 572 
 573         self.parent.SetClientSize(vsizer1.GetSize())
 574 
 575 #-------------------------------------------------------------------
 576 
 577 class MyPanel_19(wx.Panel):
 578     """
 579     - a serie of couples, StaticText-TextCtrl
 580     - Buttons ok and cancel
 581     """
 582 
 583     def __init__(self, parent):
 584         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 585         self.parent = parent
 586         
 587         lab1 = wx.StaticText(self, -1, 'hydrogen :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
 588         lab2 = wx.StaticText(self, -1, 'tin :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
 589         lab3 = wx.StaticText(self, -1, 'mendelevium :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
 590         lab4 = wx.StaticText(self, -1, 'carbon :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
 591         txt1 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
 592         txt2 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
 593         txt3 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
 594         txt4 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
 595         b1 = wx.Button(self, wx.NewId(), '&OK', (-1, -1), wx.DefaultSize)
 596         b2 = wx.Button(self, wx.NewId(), '&Cancel', (-1, -1), wx.DefaultSize)
 597         staline = wx.StaticLine(self, wx.NewId(), (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
 598         
 599         b = 5
 600         w = 100
 601         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 602         hsizer1.Add(lab1, 0, wx.RIGHT, b)
 603         hsizer1.Add(txt1, 1, wx.GROW, b)
 604         hsizer1.SetItemMinSize(lab1, (w, -1))
 605 
 606         hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
 607         hsizer2.Add(lab2, 0, wx.RIGHT, b)
 608         hsizer2.Add(txt2, 1, wx.GROW, b)
 609         hsizer2.SetItemMinSize(lab2, (w, -1))
 610 
 611         hsizer3 = wx.BoxSizer(wx.HORIZONTAL)
 612         hsizer3.Add(lab3, 0, wx.RIGHT, b)
 613         hsizer3.Add(txt3, 1, wx.GROW, b)
 614         hsizer3.SetItemMinSize(lab3, (w, -1))
 615 
 616         hsizer4 = wx.BoxSizer(wx.HORIZONTAL)
 617         hsizer4.Add(lab4, 0, wx.RIGHT, b)
 618         hsizer4.Add(txt4, 1, wx.GROW, b)
 619         hsizer4.SetItemMinSize(lab4, (w, -1))
 620 
 621         hsizer5 = wx.BoxSizer(wx.HORIZONTAL)
 622         hsizer5.Add(b1, 0)
 623         hsizer5.Add(b2, 0, wx.LEFT, 10)
 624         
 625         b = 5
 626         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 627         vsizer1.Add(hsizer1, 0, wx.EXPAND | wx.ALL, b)
 628         vsizer1.Add(hsizer2, 0, wx.EXPAND | wx.ALL, b)
 629         vsizer1.Add(hsizer3, 0, wx.EXPAND | wx.ALL, b)
 630         vsizer1.Add(hsizer4, 0, wx.EXPAND | wx.ALL, b)
 631         vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
 632         vsizer1.Add(hsizer5, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 633 
 634         self.SetSizerAndFit(vsizer1)
 635         self.parent.SetClientSize(vsizer1.GetSize())
 636         
 637 #-------------------------------------------------------------------
 638 
 639 class MyPanel_20(wx.Panel):
 640     """
 641     - a FlexGridSizer
 642     - 4 ColWins as cells, all sizeable
 643     """
 644 
 645     def __init__(self, parent):
 646         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 647 
 648         wred = ColWin(self, -1, wx.RED)
 649         wblue = ColWin(self, -1, wx.BLUE)
 650         wwhite = ColWin(self, -1, wx.WHITE)
 651         wcyan = ColWin(self, -1, wx.CYAN)
 652 
 653         hgap, vgap = 0, 0
 654         nrows, ncols = 2, 2
 655         fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
 656         
 657         b = 5
 658         fgs.AddMany([(wred, 1, wx.EXPAND | wx.ALL, b),
 659                      (wblue, 1, wx.EXPAND | wx.ALL, b),
 660                      (wwhite, 1, wx.EXPAND | wx.ALL, b),
 661                      (wcyan, 1, wx.EXPAND | wx.ALL, b),
 662                     ])
 663 
 664         # or
 665         #~ fgs.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 666         #~ fgs.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 667         #~ fgs.Add(wwhite, 1, wx.EXPAND | wx.ALL, b)
 668         #~ fgs.Add(wcyan, 1, wx.EXPAND | wx.ALL, b)
 669 
 670         #set all rows and cols sizable, try to comment / uncomment
 671         fgs.AddGrowableRow(0)
 672         fgs.AddGrowableRow(1)
 673         fgs.AddGrowableCol(0)
 674         fgs.AddGrowableCol(1)
 675 
 676         self.SetSizer(fgs)
 677 
 678 #-------------------------------------------------------------------
 679 
 680 class MyPanel_21(wx.Panel):
 681     """
 682     - a FlexgridSizer with 4 cells
 683     - cell (0, 0) is a column of 3 Buttons
 684     - cell (0, 1) is a ColWin
 685     - cell (1, 0) is empty
 686     - cell (1, 1) is a row of 3 Buttons
 687     """
 688 
 689     def __init__(self, parent):
 690         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 691 
 692         wwhite = ColWin(self, -1, wx.WHITE)
 693         b1 = wx.Button(self, -1, 'button1', (-1, -1), wx.DefaultSize)
 694         b2 = wx.Button(self, -1, 'button2', (-1, -1), wx.DefaultSize)
 695         b3 = wx.Button(self, -1, 'button3', (-1, -1), wx.DefaultSize)
 696         b4 = wx.Button(self, -1, 'button4', (-1, -1), wx.DefaultSize)
 697         b5 = wx.Button(self, -1, 'button5', (-1, -1), wx.DefaultSize)
 698         b6 = wx.Button(self, -1, 'button6', (-1, -1), wx.DefaultSize)
 699 
 700         b = 0
 701         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 702         hsizer1.Add(b1, 0, wx.ALL, b)
 703         hsizer1.Add((-1, -1), 1)
 704         hsizer1.Add(b2, 0, wx.ALL, b)
 705         hsizer1.Add((-1, -1), 1)
 706         hsizer1.Add(b3, 0, wx.ALL, b)
 707 
 708         b = 0
 709         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 710         vsizer1.Add(b4, 0, wx.ALL, b)
 711         vsizer1.Add((-1, -1), 1)
 712         vsizer1.Add(b5, 0, wx.ALL, b)
 713         vsizer1.Add((-1, -1), 1)
 714         vsizer1.Add(b6, 0, wx.ALL, b)
 715 
 716         hgap, vgap = 0, 0
 717         nrows, ncols = 2, 2
 718         fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
 719         
 720         b = 5
 721         fgs.AddMany([(vsizer1, 1, wx.EXPAND | wx.ALL, b),
 722                      (wwhite, 1, wx.EXPAND | wx.ALL, b),
 723                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 724                      (hsizer1, 1, wx.EXPAND | wx.ALL, b),
 725                     ])
 726 
 727         #really tricky ;-)
 728         fgs.AddGrowableRow(0)
 729         fgs.AddGrowableCol(1)
 730         
 731         self.SetSizer(fgs)
 732 
 733 #-------------------------------------------------------------------
 734 
 735 class MyPanel_22(wx.Panel):
 736     """
 737     - a FlexGridSizer of 9 cells (3x3) with 5 ColWins in cells and 4 empty cells
 738     """
 739 
 740     def __init__(self, parent):
 741         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 742 
 743         wwhite = ColWin(self, -1, wx.WHITE)
 744         wblue = ColWin(self, -1, wx.BLUE)
 745         wgreen = ColWin(self, -1, wx.GREEN)
 746         wcyan = ColWin(self, -1, wx.CYAN)
 747         wred = ColWin(self, -1, wx.RED)
 748 
 749         hgap, vgap = 0, 0
 750         nrows, ncols = 3, 3
 751         fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
 752         
 753         b = 5
 754         fgs.AddMany([(wwhite, 1, wx.EXPAND | wx.ALL, b),
 755                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 756                      (wblue, 1, wx.EXPAND | wx.ALL, b),
 757                      
 758                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 759                      (wgreen, 1, wx.EXPAND | wx.ALL, b),
 760                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 761 
 762                      (wred, 1, wx.EXPAND | wx.ALL, b),
 763                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 764                      (wcyan, 1, wx.EXPAND | wx.ALL, b),
 765                     ])
 766 
 767         fgs.AddGrowableRow(0)
 768         fgs.AddGrowableRow(1)
 769         fgs.AddGrowableRow(2)
 770 
 771         fgs.AddGrowableCol(0)
 772         fgs.AddGrowableCol(1)
 773         fgs.AddGrowableCol(2)
 774 
 775         self.SetSizer(fgs)
 776 
 777 #-------------------------------------------------------------------
 778 
 779 class MyPanel_23(wx.Panel):
 780     """
 781     - a FlexGridSizer of 9 cells (3x3) with 4 ColWins in cells and 5 empty cells
 782     - rows 1 and 3 have a fixed size
 783     """
 784 
 785     def __init__(self, parent):
 786         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 787 
 788         h = 40
 789         wwhite = wx.Window(self, -1, (-1, -1), (-1, h), wx.SIMPLE_BORDER)
 790         wwhite.SetBackgroundColour(wx.WHITE)
 791         wblue = ColWin(self, -1, wx.BLUE)
 792         wgreen = ColWin(self, -1, wx.GREEN)
 793         wred = wx.Window(self, -1, (-1, -1), (-1, h), wx.SIMPLE_BORDER)
 794         wred.SetBackgroundColour(wx.RED)
 795 
 796         hgap, vgap = 0, 0
 797         nrows, ncols = 3, 3
 798         fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
 799         
 800         b = 5
 801         fgs.AddMany([((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 802                      (wwhite, 1, wx.EXPAND | wx.ALL, b),
 803                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 804                      
 805                      (wblue, 1, wx.EXPAND | wx.ALL, b),
 806                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 807                      (wgreen, 1, wx.EXPAND | wx.ALL, b),
 808                      
 809                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 810                      (wred, 1, wx.EXPAND | wx.ALL, b),
 811                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 812                     ])
 813 
 814         fgs.AddGrowableRow(1)
 815         
 816         fgs.AddGrowableCol(0)
 817         fgs.AddGrowableCol(1)
 818         fgs.AddGrowableCol(2)
 819         
 820         self.SetSizer(fgs)
 821 
 822 #-------------------------------------------------------------------
 823 
 824 class MyPanel_24(wx.Panel):
 825     """
 826     - this exemple is coming from one of my applications
 827     - in the real app, the white window is a drawing area and
 828       the five lower windows are StaticTexts with a defined
 829       font size. This is why I force a fixed height.
 830     """
 831 
 832     def __init__(self, parent):
 833         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 834         self.parent = parent
 835 
 836         #a menu for the beauty of the demo
 837         menu1 = wx.Menu()
 838         menu1.Append(101, '&aaa')
 839         menuBar = wx.MenuBar()
 840         menuBar.Append(menu1, '&File')
 841         self.parent.SetMenuBar(menuBar)
 842 
 843         wwhite = ColWin(self, -1, wx.WHITE)
 844         wblue = ColWin(self, -1, wx.BLUE)
 845         wgreen = ColWin(self, -1, wx.GREEN)
 846         wcyan = ColWin(self, -1, wx.CYAN)
 847         wred = ColWin(self, -1, wx.RED)
 848         wcoral = ColWin(self, -1, wx.NamedColour('coral'))
 849         staline = wx.StaticLine(self, -1, (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
 850         
 851         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 852         b = 5
 853         vsizer1.Add(wblue, 1, wx.EXPAND | wx.BOTTOM, b)
 854         vsizer1.Add(wgreen, 1, wx.EXPAND)
 855 
 856         hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
 857         b = 5
 858         minhe = 100
 859         hsizer2.Add(wcoral, 2, wx.EXPAND | wx.RIGHT, b)
 860         hsizer2.Add(wcyan, 3, wx.EXPAND | wx.RIGHT, b)
 861         hsizer2.Add(wred, 3, wx.EXPAND | wx.RIGHT, b)
 862         hsizer2.Add(vsizer1, 2, wx.EXPAND, border=b)
 863         hsizer2.SetItemMinSize(wcoral, (-1, minhe))
 864         hsizer2.SetItemMinSize(wcyan, (-1, minhe))
 865         hsizer2.SetItemMinSize(wred, (-1, minhe))
 866         hsizer2.SetItemMinSize(vsizer1, (-1, minhe))
 867         
 868         vsizer3 = wx.BoxSizer(wx.VERTICAL)
 869         b = 5
 870         vsizer3.Add(staline, 0, wx.GROW | wx.ALL, 0)
 871         vsizer3.Add(wwhite, 1, wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, b)
 872         vsizer3.Add(hsizer2, 0, wx.EXPAND | wx.ALL, b)
 873         
 874         self.SetSizerAndFit(vsizer3)
 875 
 876 #-------------------------------------------------------------------
 877 
 878 class MyPanel_25(wx.Panel):
 879     """
 880     - this shows the relaton between the font size and the size of the
 881       widgets when sizers are used
 882     """
 883 
 884     def __init__(self, parent):
 885         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 886         self.parent = parent
 887 
 888         fs = 20
 889         self.SetFont(wx.Font(fs, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
 890 
 891         statxt1 = wx.StaticText(self, -1, 'one, two, three', (-1, -1), (-1, -1))
 892         statxt1.SetBackgroundColour(wx.WHITE)
 893         statxt2 = wx.StaticText(self, -1, 'eins, zwei, drei', (-1, -1), (-1, -1))
 894         statxt3 = wx.StaticText(self, -1, 'un, deux, trois', (-1, -1), (-1, -1))
 895         b1 = wx.Button(self, wx.NewId(), 'button1', (-1, -1), (-1, -1))
 896         b2 = wx.Button(self, wx.NewId(), 'button2', (-1, -1), (-1, -1))
 897 
 898         b = 5
 899         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 900         hsizer1.Add(b1, 1, wx.EXPAND | wx.ALL, b)
 901         hsizer1.Add(b2, 1, wx.EXPAND | wx.ALL, b)
 902         
 903         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 904         vsizer1.Add(statxt1, 0, wx.ALL, b)
 905         vsizer1.Add(statxt2, 0, wx.ALL, b)
 906         vsizer1.Add(statxt3, 0, wx.ALL, b)
 907         vsizer1.Add(hsizer1, 0, wx.ALL, b)
 908         
 909         self.SetSizerAndFit(vsizer1)
 910         self.parent.SetClientSize(vsizer1.GetSize())
 911 
 912 #-------------------------------------------------------------------
 913 
 914 class MyPanel_26(wx.Panel):
 915     """
 916     - a GridBagSizer of 4 cells (2x2)
 917     - Note: cell spanning is always specified
 918     - gbs.Add.__doc__ : Add(self, item, GBPosition pos,
 919                             GBSpan span=DefaultSpan, int flag=0,
 920                             int border=0, userData=None) -> wx.GBSizerItem
 921     """
 922 
 923     def __init__(self, parent):
 924         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 925 
 926         wwhite = ColWin(self, -1, wx.WHITE)
 927         wblue = ColWin(self, -1, wx.BLUE)
 928         wgreen = ColWin(self, -1, wx.GREEN)
 929         wred = ColWin(self, -1, wx.RED)
 930 
 931         vgap, hgap = 10, 20
 932         gbs = wx.GridBagSizer(vgap, hgap)
 933 
 934         b = 0
 935         gbs.Add(wwhite, (0, 0), (1, 1), wx.EXPAND | wx.ALL, b)
 936         gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND | wx.ALL, b)
 937         gbs.Add(wgreen, (1, 0), (1, 1), wx.EXPAND | wx.ALL, b)
 938         gbs.Add(wred, (1, 1), (1, 1), wx.EXPAND | wx.ALL, b)
 939 
 940         gbs.AddGrowableRow(0)
 941         gbs.AddGrowableRow(1)
 942         gbs.AddGrowableCol(0)
 943         gbs.AddGrowableCol(1)
 944         
 945         self.SetSizer(gbs)
 946 
 947 #-------------------------------------------------------------------
 948 
 949 class MyPanel_27(wx.Panel):
 950     """
 951     - a GridBagSizer of 9 cells (3x3)
 952     - Note: cell spanning is always specified
 953     - vgap and hgap define the space between the cells and not
 954       between the cells and the border of the panel/frame.
 955       This example creates a constant spacing for all cells.
 956 
 957     """
 958 
 959     def __init__(self, parent):
 960         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 961 
 962         wwhite = ColWin(self, -1, wx.WHITE)
 963         wblue = ColWin(self, -1, wx.BLUE)
 964         wgreen = ColWin(self, -1, wx.GREEN)
 965         wred = ColWin(self, -1, wx.RED)
 966         wblack = ColWin(self, -1, wx.BLACK)
 967         wpink = ColWin(self, -1, wx.NamedColour('pink'))
 968         wyellow = ColWin(self, -1, wx.NamedColour('yellow'))
 969         wcyan = ColWin(self, -1, wx.NamedColour('cyan'))
 970         worange = ColWin(self, -1, wx.NamedColour('orange'))
 971 
 972         vgap = hgap = 10
 973         gbs = wx.GridBagSizer(vgap, hgap)
 974 
 975         b = vgap
 976         gbs.Add(wwhite, (0, 0), (1, 1), wx.EXPAND | wx.LEFT | wx.TOP, b)
 977         gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND | wx.TOP, b)
 978         gbs.Add(wgreen, (0, 2), (1, 1), wx.EXPAND | wx.RIGHT | wx.TOP, b)
 979 
 980         gbs.Add(wred, (1, 0), (1, 1), wx.EXPAND | wx.LEFT, b)
 981         gbs.Add(wblack, (1, 1), (1, 1), wx.EXPAND)
 982         gbs.Add(wpink, (1, 2), (1, 1), wx.EXPAND | wx.RIGHT, b)
 983 
 984         gbs.Add(wyellow, (2, 0), (1, 1), wx.EXPAND | wx.LEFT | wx.BOTTOM, b)
 985         gbs.Add(wcyan, (2, 1), (1, 1), wx.EXPAND | wx.BOTTOM, b)
 986         gbs.Add(worange, (2, 2), (1, 1), wx.EXPAND | wx.RIGHT | wx.BOTTOM, b)
 987 
 988         gbs.AddGrowableRow(0)
 989         gbs.AddGrowableRow(1)
 990         gbs.AddGrowableRow(2)
 991         gbs.AddGrowableCol(0)
 992         gbs.AddGrowableCol(1)
 993         gbs.AddGrowableCol(2)
 994 
 995         self.SetSizer(gbs)
 996 
 997 #-------------------------------------------------------------------
 998 
 999 class MyPanel_28(wx.Panel):
1000     """
1001     - a GridBagSizer of 9 cells (3x3)
1002     - Layout like MyPanel_27, uses a secondary sizer to get a border
1003     """
1004 
1005     def __init__(self, parent):
1006         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
1007 
1008         wwhite = ColWin(self, -1, wx.WHITE)
1009         wblue = ColWin(self, -1, wx.BLUE)
1010         wgreen = ColWin(self, -1, wx.GREEN)
1011         wred = ColWin(self, -1, wx.RED)
1012         wblack = ColWin(self, -1, wx.BLACK)
1013         wpink = ColWin(self, -1, wx.NamedColour('pink'))
1014         wyellow = ColWin(self, -1, wx.NamedColour('yellow'))
1015         wcyan = ColWin(self, -1, wx.NamedColour('cyan'))
1016         worange = ColWin(self, -1, wx.NamedColour('orange'))
1017 
1018         vgap = hgap = 10
1019         gbs = wx.GridBagSizer(vgap, hgap)
1020 
1021         b = 0
1022         gbs.Add(wwhite, (0, 0), (1, 1), wx.EXPAND, b)
1023         gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND, b)
1024         gbs.Add(wgreen, (0, 2), (1, 1), wx.EXPAND, b)
1025 
1026         gbs.Add(wred, (1, 0), (1, 1), wx.EXPAND, b)
1027         gbs.Add(wblack, (1, 1), (1, 1), wx.EXPAND)
1028         gbs.Add(wpink, (1, 2), (1, 1), wx.EXPAND, b)
1029 
1030         gbs.Add(wyellow, (2, 0), (1, 1), wx.EXPAND, b)
1031         gbs.Add(wcyan, (2, 1), (1, 1), wx.EXPAND, b)
1032         gbs.Add(worange, (2, 2), (1, 1), wx.EXPAND, b)
1033 
1034         gbs.AddGrowableRow(0)
1035         gbs.AddGrowableRow(1)
1036         gbs.AddGrowableRow(2)
1037         gbs.AddGrowableCol(0)
1038         gbs.AddGrowableCol(1)
1039         gbs.AddGrowableCol(2)
1040 
1041         b = vgap
1042         vsizer1 = wx.BoxSizer(wx.VERTICAL)
1043         vsizer1.Add(gbs, 1, wx.EXPAND | wx.ALL, b)
1044         self.SetSizer(vsizer1)
1045 
1046 #-------------------------------------------------------------------
1047 
1048 class MyPanel_29(wx.Panel):
1049     """
1050     - a GridBagSizer of 25 cells (5x5)
1051     - spanning
1052     - cell (1, 1) is empty
1053     - when spanning, cells ovelapping raises an error. This explains
1054       the commented lines for unused coloured windows.
1055     """
1056 
1057     def __init__(self, parent):
1058         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
1059 
1060         wwhite = ColWin(self, -1, wx.WHITE)
1061         #~ wblue = ColWin(self, -1, wx.BLUE)
1062         #~ wgreen = ColWin(self, -1, wx.GREEN)
1063         wred = ColWin(self, -1, wx.RED)
1064         wblack = ColWin(self, -1, wx.BLACK)
1065         
1066         wpink = ColWin(self, -1, wx.NamedColour('pink'))
1067         #~ wyellow = ColWin(self, -1, wx.NamedColour('yellow'))
1068         wcyan = ColWin(self, -1, wx.NamedColour('cyan'))
1069         worange = ColWin(self, -1, wx.NamedColour('orange'))
1070         wgold = ColWin(self, -1, wx.NamedColour('gold'))
1071 
1072         wtan = ColWin(self, -1, wx.NamedColour('tan'))
1073         wcoral = ColWin(self, -1, wx.NamedColour('coral'))
1074         #~ wplum = ColWin(self, -1, wx.NamedColour('plum'))
1075         wspringgreen = ColWin(self, -1, wx.NamedColour('spring green'))
1076         #~ wbrown = ColWin(self, -1, wx.NamedColour('brown'))
1077 
1078         wwheat = ColWin(self, -1, wx.NamedColour('wheat'))
1079         #~ wvioletred = ColWin(self, -1, wx.NamedColour('violet red'))
1080         #~ wgoldenrod = ColWin(self, -1, wx.NamedColour('goldenrod'))
1081         wpalegreen = ColWin(self, -1, wx.NamedColour('pale green'))
1082         #~ wyellowgreen = ColWin(self, -1, wx.NamedColour('yellow green'))
1083 
1084         wnavy = ColWin(self, -1, wx.NamedColour('navy'))
1085         wskyblue = ColWin(self, -1, wx.NamedColour('sky blue'))
1086         wmagenta = ColWin(self, -1, wx.NamedColour('magenta'))
1087         wkhaki = ColWin(self, -1, wx.NamedColour('khaki'))
1088         #~ wslateblue = ColWin(self, -1, wx.NamedColour('slate blue'))
1089 
1090         vgap = hgap = 10
1091         gbs = wx.GridBagSizer(vgap, hgap)
1092 
1093         b = 0
1094         gbs.Add(wwhite, (0, 0), (1, 3), wx.EXPAND | wx.ALL, b)
1095         #~ gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1096         #~ gbs.Add(wgreen, (0, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1097         gbs.Add(wred, (0, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1098         gbs.Add(wblack, (0, 4), (1, 1), wx.EXPAND | wx.ALL, b)
1099 
1100         gbs.Add(wpink, (1, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1101         #~ gbs.Add(wyellow, (1, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1102         gbs.Add(wcyan, (1, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1103         gbs.Add(worange, (1, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1104         gbs.Add(wgold, (1, 4), (4, 1), wx.EXPAND | wx.ALL, b)
1105 
1106         gbs.Add(wtan, (2, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1107         gbs.Add(wcoral, (2, 1), (2, 2), wx.EXPAND | wx.ALL, b)
1108         #~ gbs.Add(wplum, (2, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1109         gbs.Add(wspringgreen, (2, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1110         #~ gbs.Add(wbrown, (2, 4), (1, 1), wx.EXPAND | wx.ALL, b)
1111 
1112         gbs.Add(wwheat, (3, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1113         #~ gbs.Add(wvioletred, (3, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1114         #~ gbs.Add(wgoldenrod, (3, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1115         gbs.Add(wpalegreen, (3, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1116         #~ gbs.Add(wyellowgreen, (3, 4), (1, 1), wx.EXPAND | wx.ALL, b)
1117 
1118         gbs.Add(wnavy, (4, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1119         gbs.Add(wskyblue, (4, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1120         gbs.Add(wmagenta, (4, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1121         gbs.Add(wkhaki, (4, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1122         #~ gbs.Add(wslateblue, (4, 4), (1, 1), wx.EXPAND | wx.ALL, b)
1123 
1124         gbs.AddGrowableRow(0)
1125         gbs.AddGrowableRow(1)
1126         gbs.AddGrowableRow(2)
1127         gbs.AddGrowableRow(3)
1128         gbs.AddGrowableRow(4)
1129         gbs.AddGrowableCol(0)
1130         gbs.AddGrowableCol(1)
1131         gbs.AddGrowableCol(2)
1132         gbs.AddGrowableCol(3)
1133         gbs.AddGrowableCol(4)
1134 
1135         self.SetSizer(gbs)
1136 
1137 #-------------------------------------------------------------------
1138 
1139 class MyPanel_30(wx.Panel):
1140     """
1141     - a GridBagSizer of 16 cells (4x4)
1142     """
1143 
1144     def __init__(self, parent):
1145         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
1146 
1147         wwhite = ColWin(self, -1, wx.WHITE)
1148         wblue = ColWin(self, -1, wx.BLUE)
1149         wgreen = ColWin(self, -1, wx.GREEN)
1150         wred = ColWin(self, -1, wx.RED)
1151         
1152         wpink = ColWin(self, -1, wx.NamedColour('pink'))
1153         wyellow = ColWin(self, -1, wx.NamedColour('yellow'))
1154         wcyan = ColWin(self, -1, wx.NamedColour('cyan'))
1155         worange = ColWin(self, -1, wx.NamedColour('orange'))
1156 
1157         wtan = ColWin(self, -1, wx.NamedColour('tan'))
1158         wcoral = ColWin(self, -1, wx.NamedColour('coral'))
1159         wplum = ColWin(self, -1, wx.NamedColour('plum'))
1160         wspringgreen = ColWin(self, -1, wx.NamedColour('spring green'))
1161 
1162         wwheat = ColWin(self, -1, wx.NamedColour('wheat'))
1163         wvioletred = ColWin(self, -1, wx.NamedColour('violet red'))
1164         wgoldenrod = ColWin(self, -1, wx.NamedColour('goldenrod'))
1165         wpalegreen = ColWin(self, -1, wx.NamedColour('pale green'))
1166 
1167         vgap = hgap = 10
1168         gbs = wx.GridBagSizer(vgap, hgap)
1169 
1170         b = 0
1171         gbs.Add(wwhite, (0, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1172         gbs.Add(wblue, (0, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1173         gbs.Add(wgreen, (0, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1174         gbs.Add(wred, (0, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1175 
1176         gbs.Add(wpink, (1, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1177         gbs.Add(wyellow, (1, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1178         gbs.Add(wcyan, (1, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1179         gbs.Add(worange, (1, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1180 
1181         gbs.Add(wtan, (2, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1182         gbs.Add(wcoral, (2, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1183         gbs.Add(wplum, (2, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1184         gbs.Add(wspringgreen, (2, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1185 
1186         gbs.Add(wwheat, (3, 0), (1, 1), wx.EXPAND | wx.ALL, b)
1187         gbs.Add(wvioletred, (3, 1), (1, 1), wx.EXPAND | wx.ALL, b)
1188         gbs.Add(wgoldenrod, (3, 2), (1, 1), wx.EXPAND | wx.ALL, b)
1189         gbs.Add(wpalegreen, (3, 3), (1, 1), wx.EXPAND | wx.ALL, b)
1190 
1191         gbs.AddGrowableRow(0)
1192         gbs.AddGrowableRow(1)
1193         #~ gbs.AddGrowableRow(2)
1194         gbs.AddGrowableRow(3)
1195         gbs.AddGrowableCol(0)
1196         gbs.AddGrowableCol(1)
1197         #~ gbs.AddGrowableCol(2)
1198         gbs.AddGrowableCol(3)
1199 
1200         self.SetSizer(gbs)
1201 
1202         #~ for e in dir(gbs):
1203             #~ print e
1204         print gbs.SetDimension.__doc__
1205 
1206 #-------------------------------------------------------------------
1207 
1208 class MyPanel_31(wx.Panel):
1209     """
1210     - based on MyPanel_15 where the central button has been replaced by
1211       an horizontal sizer conaining two buttons.
1212     """
1213 
1214     def __init__(self, parent):
1215         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
1216 
1217         wgreen = ColWin(self, wx.NewId(), wx.NamedColour('green'))
1218         b1 = wx.Button(self, wx.NewId(), 'button1', (-1, -1), wx.DefaultSize)
1219         b2 = wx.Button(self, wx.NewId(), 'button2', (-1, -1), wx.DefaultSize)
1220         b3 = wx.Button(self, wx.NewId(), 'button3', (-1, -1), wx.DefaultSize)
1221         b4 = wx.Button(self, wx.NewId(), 'button4', (-1, -1), wx.DefaultSize)
1222 
1223         b = 0
1224         hsizer1a = wx.BoxSizer(wx.HORIZONTAL)
1225         hsizer1a.Add(b2, 0, wx.ALL, b)
1226         hsizer1a.Add(b3, 0, wx.ALL, b)
1227 
1228         b = 0
1229         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
1230         hsizer1.Add(b1, 0, wx.ALL, b)
1231         hsizer1.Add((-1, -1), 1)
1232         hsizer1.Add(hsizer1a, 0, wx.ALL, b)
1233         hsizer1.Add((-1, -1), 1)
1234         hsizer1.Add(b4, 0, wx.ALL, b)
1235 
1236         b = 0
1237         hsizer1b = wx.BoxSizer(wx.HORIZONTAL)
1238         hsizer1b.Add((-1, -1), 1)
1239         hsizer1b.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
1240         hsizer1b.Add((-1, -1), 1)
1241 
1242         b = 5
1243         vsizer2 = wx.BoxSizer(wx.VERTICAL)
1244         vsizer2.Add(hsizer1, 0, wx.EXPAND | wx.ALL, b)
1245         #~ vsizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
1246         vsizer2.Add(hsizer1b, 1, wx.EXPAND | wx.ALL, b)
1247         self.SetSizer(vsizer2)
1248 
1249 #-------------------------------------------------------------------
1250 
1251 class TestComboBox(wx.Panel):
1252     def __init__(self, parent, id):
1253         wx.Panel.__init__(self, parent, id)
1254 
1255         sampleList = []
1256         for i in range(0, 32):
1257             sampleList.append('MyPanel_' + str(i))
1258 
1259         self.st = wx.StaticText(self, -1, "Select the example you want to see."
1260                          "Then click the View button.", (-1, -1))
1261 
1262         self.doctxt = wx.StaticText(self, -1, "")
1263         self.doctxt.SetLabel(MyPanel_0.__doc__)
1264 
1265         # This combobox is created with a preset list of values.
1266         self.cb = wx.ComboBox(self, -1, "MyPanel_0", (-1, -1),
1267             (-1, -1), sampleList, wx.CB_DROPDOWN | wx.CB_READONLY
1268             )
1269 
1270         self.stline = wx.StaticLine(self, -1, (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
1271 
1272         btnView = wx.Button(self, -1, "&View")
1273         self.Bind(wx.EVT_BUTTON, self.OnClickView, btnView)
1274 
1275         btnExit = wx.Button(self, -1, "E&xit")
1276         self.Bind(wx.EVT_BUTTON, self.OnClickExit, btnExit)
1277 
1278         b = 5
1279         vsizer1 = wx.BoxSizer(wx.VERTICAL)
1280         vsizer1.Add(self.st, 0, wx.EXPAND | wx.ALL, b)
1281         vsizer1.Add(self.cb, 0, wx.EXPAND | wx.ALL, 0)
1282         vsizer1.Add(self.doctxt, 0, wx.EXPAND | wx.ALL, b)
1283 
1284         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
1285         hsizer1.Add(btnView, 0)
1286         hsizer1.Add(btnExit, 0, wx.LEFT, b)
1287 
1288         vsizer2 = wx.BoxSizer(wx.VERTICAL)
1289         vsizer2.Add(vsizer1, 5, wx.EXPAND | wx.ALL, 0)
1290         vsizer2.Add(self.stline, 0, wx.GROW | wx.ALL, b)
1291         vsizer2.Add(hsizer1, 1, wx.ALIGN_RIGHT | wx.ALL, b)
1292         self.SetSizer(vsizer2)
1293 
1294         self.Bind(wx.EVT_COMBOBOX, self.OnEvtComboBox, self.cb)
1295 
1296     #~ Based on Tim Roberts' proposal
1297     #~ Tim Roberts, timr@probo.com
1298     # When the user selects something, we go here.
1299     def OnEvtComboBox(self, evt):
1300         self.doctxt.SetLabel(eval('%s.__doc__' % evt.GetString()))
1301 
1302     def OnClickView(self, evt):
1303         win = wx.Frame(self, -1, self.cb.GetValue(), size=(500, 300),
1304                   style = wx.DEFAULT_FRAME_STYLE)
1305         eval('%s(win)' % self.cb.GetValue())
1306 
1307         win.CenterOnScreen()
1308         win.Show(True)
1309 
1310     def OnClickExit(self, evt):
1311         sys.exit()
1312 
1313 #-------------------------------------------------------------------
1314 
1315 class MyApp(wx.App):
1316 
1317     def OnInit(self):
1318         frame = wx.Frame(None, -1, __file__, (0, 0), (450, 300))
1319         frame.panel = TestComboBox(frame, -1)
1320         frame.Show(True)
1321         self.SetTopWindow(frame)
1322         return True
1323 
1324 #-------------------------------------------------------------------
1325 
1326 def main():
1327     app = MyApp(False)
1328     app.MainLoop()
1329 
1330 #-------------------------------------------------------------------
1331 
1332 if __name__ == "__main__" :
1333     main()
1334 
1335 #eof-------------------------------------------------------------------

LearnSizers3.py (last edited 2008-03-11 10:50:29 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.