Attachment 'LearnSizers1.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 #--------------------------------------------------------------------
   3 # Name:      LearnSizers1.py
   4 # Purpose:   A demo app to learn sizers
   5 # Author:    Jean-Michel Fauth, Switzerland
   6 # Copyright: (c) 2005 Jean-Michel Fauth
   7 # Licence:   GPL
   8 #--------------------------------------------------------------------
   9 # os dev:    windows 98
  10 # py dev:    Python 2.4.1
  11 # wx dev:    wxPython 2.6.1
  12 # Revision:  27 June 2005
  13 #--------------------------------------------------------------------
  14 # Contributor and minor fixes: Marcelo Barbero, Argentina
  15 # Revision: 03 August 2005
  16 
  17 # LearnSizer*.py is a small application aimed to learn the sizers and
  18 # their usage.
  19 # This application is a collection of panels. Each panel contains
  20 # a few widgets laid out with sizers. The panels are numbered
  21 # MyPanel_0 to MyPanel_n. The panel 0 is the simpliest case. The
  22 # order of the panels follows an increasing complexity in the
  23 # layout. It is warmly recommended to start with MyPanel_0.
  24 #
  25 # Do not forget:
  26 # - the wxPython doc
  27 # - the wiki page http://wiki.wxpython.org/index.cgi/UsingSizers
  28 # - dir(<instance of a sizer>) for a list of methods
  29 # - print sizer.method.__doc__
  30 #
  31 #--------------------------------------------------------------------
  32 
  33 import os
  34 import sys
  35 import wx
  36 
  37 #-------------------------------------------------------------------
  38 
  39 class ColWin(wx.Window):
  40     """- A wx.Window with a coloured background
  41     - pos and size == (-1, -1) since sizers are used"""
  42 
  43     def __init__(self, parent, id, BackColour):
  44         wx.Window.__init__(self, parent, id, (-1, -1), (-1, -1), wx.SIMPLE_BORDER)
  45         self.SetBackgroundColour(BackColour)
  46 
  47 #-------------------------------------------------------------------
  48 
  49 class MyPanel_0(wx.Panel):
  50     """- The simpliest sizer, a ColWin
  51     - use of named arguments"""
  52 
  53     def __init__(self, parent):
  54         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
  55 
  56         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
  57 
  58         b = 20
  59         vsizer1 = wx.BoxSizer(orient=wx.VERTICAL)
  60         # or
  61         # vsizer1 = wx.BoxSizer(orient=wx.HORIZONTAL)
  62         vsizer1.Add(item=wgreen, proportion=1, flag=wx.EXPAND | wx.ALL, border=b)
  63         self.SetSizer(vsizer1)
  64 
  65 #-------------------------------------------------------------------
  66 
  67 class MyPanel_1(wx.Panel):
  68     """- Two ColWins, vertically"""
  69 
  70     def __init__(self, parent):
  71         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
  72 
  73         wred = ColWin(self, wx.NewId(), wx.RED)
  74         wblue = ColWin(self, wx.NewId(), wx.BLUE)
  75 
  76         b = 5
  77         vsizer1 = wx.BoxSizer(wx.VERTICAL)
  78         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
  79         vsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
  80         self.SetSizer(vsizer1)
  81 
  82 #-------------------------------------------------------------------
  83 
  84 class MyPanel_2(wx.Panel):
  85     """- Three ColWins, horizontally """
  86 
  87     def __init__(self, parent):
  88         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
  89 
  90         wred = ColWin(self, wx.NewId(), wx.RED)
  91         wblue = ColWin(self, wx.NewId(), wx.BLUE)
  92         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
  93 
  94         b = 5
  95         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
  96         hsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
  97         hsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
  98         hsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
  99         self.SetSizer(hsizer1)
 100 
 101 #-------------------------------------------------------------------
 102 
 103 class MyPanel_3(wx.Panel):
 104     """- Three ColWins, horizontally, height ratio 1:2:3"""
 105 
 106     def __init__(self, parent):
 107         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 108 
 109         wred = ColWin(self, wx.NewId(), wx.RED)
 110         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 111         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 112 
 113         b = 5
 114         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 115         hsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 116         hsizer1.Add(wblue, 2, wx.EXPAND | wx.ALL, b)
 117         hsizer1.Add(wgreen, 3, wx.EXPAND | wx.ALL, b)
 118         self.SetSizer(hsizer1)
 119 
 120 #-------------------------------------------------------------------
 121 
 122 class MyPanel_4(wx.Panel):
 123     """- Two ColWins, vertically, a fixed width of 50 pixels between
 124     the two items"""
 125 
 126     def __init__(self, parent):
 127         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 128 
 129         wred = ColWin(self, wx.NewId(), wx.RED)
 130         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 131 
 132         b = 5
 133         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 134         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 135         vsizer1.Add((-1, 50), 0,  wx.ALL, b)
 136         vsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 137         self.SetSizer(vsizer1)
 138 
 139 #-------------------------------------------------------------------
 140 
 141 class MyPanel_5(wx.Panel):
 142     """- Two items: a ColWin and a Button, vertically
 143     - the Button is either left/right aligned or centered
 144     - comment / uncomment for testing the Button alignment
 145     - wx.ALIGN_LEFT is the default value"""
 146 
 147     def __init__(self, parent):
 148         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 149 
 150         wred = ColWin(self, wx.NewId(), wx.RED)
 151         b1 = wx.Button(self, wx.NewId(), 'button1', (-1, -1), wx.DefaultSize)
 152 
 153         b = 5
 154         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 155         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 156 
 157         #~ vsizer1.Add(b1, 0, wx.ALIGN_LEFT | wx.ALL, b)
 158         #~ vsizer1.Add(b1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 159         vsizer1.Add(b1, 0, wx.ALIGN_CENTER | wx.ALL, b)
 160         self.SetSizer(vsizer1)
 161 
 162 #-------------------------------------------------------------------
 163 
 164 class MyPanel_6(wx.Panel):
 165     """- Three items: a ColWin and two Buttons
 166     - the Buttons are either left/right aligned or centered"""
 167 
 168     def __init__(self, parent):
 169         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 170 
 171         wred = ColWin(self, wx.NewId(), wx.RED)
 172         b1 = wx.Button(self, wx.NewId(), '&OK', (-1, -1), wx.DefaultSize)
 173         b2 = wx.Button(self, wx.NewId(), '&Cancel', (-1, -1), wx.DefaultSize)
 174 
 175         b = 10
 176         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 177         hsizer1.Add(b1, 0)
 178         hsizer1.Add(b2, 0, wx.LEFT, b)
 179 
 180         b = 5
 181         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 182         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 183         vsizer1.Add(hsizer1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 184         #~ vsizer1.Add(hsizer1, 0, wx.ALIGN_CENTER | wx.ALL, b)
 185         #~ vsizer1.Add(hsizer1, 0, wx.ALIGN_LEFT | wx.ALL, b)
 186         self.SetSizer(vsizer1)
 187 
 188 #-------------------------------------------------------------------
 189 
 190 class MyPanel_7(wx.Panel):
 191     """- Four items: a ColWin, two Buttons, and a StaticLine
 192     - the Buttons are either left/right aligned or centered
 193     - the height of the static line == 2, the wx.GROW flag specifies an
 194       horizontal expansion, since the StaticLine is in a vertical sizer"""
 195 
 196     def __init__(self, parent):
 197         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 198 
 199         wred = ColWin(self, wx.NewId(), wx.RED)
 200         b1 = wx.Button(self, wx.NewId(), '&OK', (-1, -1), wx.DefaultSize)
 201         b2 = wx.Button(self, wx.NewId(), '&Cancel', (-1, -1), wx.DefaultSize)
 202         staline = wx.StaticLine(self, wx.NewId(), (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
 203 
 204         b = 5
 205         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 206         hsizer1.Add(b1, 0)
 207         hsizer1.Add(b2, 0, wx.LEFT, b)
 208 
 209         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 210         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 211         vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
 212         vsizer1.Add(hsizer1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 213         self.SetSizer(vsizer1)
 214 
 215 #-------------------------------------------------------------------
 216 
 217 class MyPanel_8(wx.Panel):
 218     """- 7 items: 2 ColWins and 5 Buttons
 219     - ColWins: one is sizable, the other not
 220     - Buttons at the right of the frame
 221     - something like a toolbar at the right"""
 222 
 223     def __init__(self, parent):
 224         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 225 
 226         wred = ColWin(self, wx.NewId(), wx.RED)
 227         wwhite = ColWin(self, wx.NewId(), wx.WHITE)
 228 
 229         b1 = wx.Button(self, wx.NewId(), '1', (-1, -1), wx.DefaultSize)
 230         b2 = wx.Button(self, wx.NewId(), '2', (-1, -1), wx.DefaultSize)
 231         b3 = wx.Button(self, wx.NewId(), '3', (-1, -1), wx.DefaultSize)
 232         b4 = wx.Button(self, wx.NewId(), '4', (-1, -1), wx.DefaultSize)
 233         b5 = wx.Button(self, wx.NewId(), '5', (-1, -1), wx.DefaultSize)
 234 
 235         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 236         b = 3
 237         vsizer1.Add(wred, 1, wx.EXPAND | wx.BOTTOM, b)
 238         vsizer1.Add(wwhite, 0, wx.EXPAND, b)
 239 
 240         vsizer2 = wx.BoxSizer(wx.VERTICAL)
 241         b = 5
 242         vsizer2.Add(b1, 0, wx.BOTTOM, b)
 243         vsizer2.Add(b2, 0, wx.BOTTOM, b)
 244         vsizer2.Add(b3, 0, wx.BOTTOM, b)
 245         vsizer2.Add(b4, 0, wx.BOTTOM, b)
 246         vsizer2.Add(b5, 0, wx.BOTTOM, b)
 247 
 248         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 249         b = 10
 250         hsizer1.Add(vsizer1, 1, wx.EXPAND | wx.LEFT | wx.TOP | wx.BOTTOM, b)
 251         hsizer1.Add(vsizer2, 0, wx.EXPAND| wx.ALL, b)
 252 
 253         self.SetSizer(hsizer1)
 254 
 255 #-------------------------------------------------------------------
 256 
 257 class MyPanel_9(wx.Panel):
 258     """- 7 items: 2 ColWins and 5 Buttons
 259     - the ColWins are sizable
 260     - the Buttons have a fixed height and a default width
 261     - something like a toolbar at the top"""
 262 
 263     def __init__(self, parent):
 264         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 265 
 266         wred = ColWin(self, wx.NewId(), wx.RED)
 267         wwhite = ColWin(self, wx.NewId(), wx.WHITE)
 268 
 269         h = 40
 270         b1 = wx.Button(self, wx.NewId(), '1', (-1, -1), (-1, h))
 271         b2 = wx.Button(self, wx.NewId(), '2', (-1, -1), (-1, h))
 272         b3 = wx.Button(self, wx.NewId(), '3', (-1, -1), (-1, h))
 273         b4 = wx.Button(self, wx.NewId(), '4', (-1, -1), (-1, h))
 274         b5 = wx.Button(self, wx.NewId(), '5', (-1, -1), (-1, h))
 275 
 276         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 277         hsizer1.Add(b1, 0)
 278         hsizer1.Add(b2, 0)
 279         hsizer1.Add(b3, 0)
 280         hsizer1.Add(b4, 0)
 281         hsizer1.Add(b5, 0)
 282 
 283         b = 2
 284         hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
 285         hsizer2.Add(wred, 1, wx.EXPAND | wx.RIGHT, b)
 286         hsizer2.Add(wwhite, 1, wx.EXPAND | wx.LEFT, b)
 287 
 288         b = 5
 289         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 290         vsizer1.Add(hsizer1, 0, wx.EXPAND, b)
 291         vsizer1.Add(hsizer2, 1, wx.ALL | wx.EXPAND, b)
 292 
 293         self.SetSizer(vsizer1)
 294 
 295 #-------------------------------------------------------------------
 296 
 297 class MyPanel_10(wx.Panel):
 298     """- Three ColWins in a StaticBoxSizer, vertically"""
 299 
 300     def __init__(self, parent):
 301         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 302 
 303         wred = ColWin(self, wx.NewId(), wx.RED)
 304         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 305         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 306 
 307         b = 10  #inside the staticbox
 308         vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'StaticboxSizer with a caption'), wx.VERTICAL)
 309         vsbsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 310         vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 311         vsbsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 312         self.SetSizer(vsbsizer1)
 313 
 314 #-------------------------------------------------------------------
 315 
 316 class MyPanel_11(wx.Panel):
 317     """- Three ColWins in a StaticBoxSizer, vertically
 318     - the StaticBoxSizer is in a sizer to enable a border"""
 319 
 320     def __init__(self, parent):
 321         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 322 
 323         wred = ColWin(self, wx.NewId(), wx.RED)
 324         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 325         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 326 
 327         b = 10  #inside the staticbox
 328         vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'StaticboxSizer with a caption'), wx.VERTICAL)
 329         vsbsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 330         vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 331         vsbsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 332 
 333         b = 20
 334         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 335         hsizer1.Add(vsbsizer1, 1, wx.EXPAND | wx.ALL, b)
 336 
 337         self.SetSizer(hsizer1)
 338 
 339 #-------------------------------------------------------------------
 340 
 341 class MyPanel_12(wx.Panel):
 342     """- 5 ColWins, vertically
 343     - ColWins 2 and 4 are in StaticBoxSizer"""
 344 
 345     def __init__(self, parent):
 346         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 347 
 348         wred = ColWin(self, wx.NewId(), wx.RED)
 349         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 350         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 351         wwhite = ColWin(self, wx.NewId(), wx.WHITE)
 352         wyellow = ColWin(self, wx.NewId(), wx.NamedColour('yellow'))
 353 
 354         b = 10
 355         vsbsizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'blue'), wx.VERTICAL)
 356         vsbsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 357 
 358         vsbsizer2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'white'), wx.VERTICAL)
 359         vsbsizer2.Add(wwhite, 1, wx.EXPAND | wx.ALL, b)
 360 
 361         b = 5
 362         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 363         vsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 364         vsizer1.Add(vsbsizer1, 1, wx.EXPAND | wx.ALL, b)
 365         vsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 366         vsizer1.Add(vsbsizer2, 1, wx.EXPAND | wx.ALL, b)
 367         vsizer1.Add(wyellow, 1, wx.EXPAND | wx.ALL, b)
 368 
 369         self.SetSizer(vsizer1)
 370 
 371 #-------------------------------------------------------------------
 372 
 373 class MyPanel_13(wx.Panel):
 374     """- 3 StaticBoxSizers with a ColWin in each
 375     - the StaticBoxSizers are arranged vertically"""
 376 
 377     def __init__(self, parent):
 378         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 379 
 380         wred = ColWin(self, wx.NewId(), wx.NamedColour('red'))
 381         wgreen = ColWin(self, wx.NewId(), wx.NamedColour('green'))
 382         wblue = ColWin(self, wx.NewId(), wx.NamedColour('blue'))
 383 
 384         b = 10
 385         sizer1 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'Staticbox'), wx.VERTICAL)
 386         sizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 387 
 388         sizer2 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'Staticbox'), wx.VERTICAL)
 389         sizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 390 
 391         sizer4 = wx.StaticBoxSizer(wx.StaticBox(self, wx.NewId(), 'Staticbox'), wx.VERTICAL)
 392         sizer4.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 393 
 394         #tricky: the 2nd and 3rd staticbox sizer are shifted one pixel to the
 395         #left, try with b2 = 0
 396         b1, b2 = 0, -1
 397         sizer3 = wx.BoxSizer(wx.HORIZONTAL)
 398         sizer3.Add(sizer1, 1, wx.EXPAND, b1)
 399         sizer3.Add(sizer2, 1, wx.EXPAND | wx.LEFT, b2)
 400         sizer3.Add(sizer4, 1, wx.EXPAND | wx.LEFT, b2)
 401 
 402         self.SetSizer(sizer3)
 403 
 404 #-------------------------------------------------------------------
 405 
 406 class MyPanel_14(wx.Panel):
 407     """- 3 ColWins, horizontally, 2 spacers with a fixed height"""
 408 
 409     def __init__(self, parent):
 410         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 411 
 412         wred = ColWin(self, wx.NewId(), wx.RED)
 413         wblue = ColWin(self, wx.NewId(), wx.BLUE)
 414         wgreen = ColWin(self, wx.NewId(), wx.GREEN)
 415 
 416         b = 0
 417         h = 20
 418         hsizer1 = wx.BoxSizer(wx.VERTICAL)
 419         hsizer1.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 420         hsizer1.Add((-1, h))
 421         hsizer1.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 422         hsizer1.Add((-1, h))
 423         hsizer1.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 424         self.SetSizer(hsizer1)
 425 
 426 #-------------------------------------------------------------------
 427 
 428 class MyPanel_15(wx.Panel):
 429     """- 4 items: a ColWin and 3 Buttons
 430     - Buttons 1 and 3 are left/right aligned, Button 2 is centered
 431     - use of spacers to set a gap between the Buttons.
 432     - better way?"""
 433 
 434     def __init__(self, parent):
 435         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 436 
 437         wgreen = ColWin(self, wx.NewId(), wx.NamedColour('green'))
 438         b1 = wx.Button(self, wx.NewId(), 'button1', (-1, -1), wx.DefaultSize)
 439         b2 = wx.Button(self, wx.NewId(), 'button2', (-1, -1), wx.DefaultSize)
 440         b3 = wx.Button(self, wx.NewId(), 'button3', (-1, -1), wx.DefaultSize)
 441 
 442         b = 0
 443         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 444         hsizer1.Add(b1, 0, wx.ALL, b)
 445         hsizer1.Add((-1, -1), 1)
 446         hsizer1.Add(b2, 0, wx.ALL, b)
 447         hsizer1.Add((-1, -1), 1)
 448         hsizer1.Add(b3, 0, wx.ALL, b)
 449 
 450         #tip: this does not work
 451         #~ b = 0
 452         #~ hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 453         #~ hsizer1.Add(b1, 0, wx.ALIGN_LEFT, b)
 454         #~ hsizer1.Add(b2, 0, wx.ALIGN_CENTER, b)
 455         #~ hsizer1.Add(b3, 0, wx.ALIGN_RIGHT, b)
 456 
 457         b = 5
 458         vsizer2 = wx.BoxSizer(wx.VERTICAL)
 459         vsizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 460         vsizer2.Add(hsizer1, 0, wx.EXPAND | wx.ALL, b)
 461         self.SetSizer(vsizer2)
 462 
 463 #-------------------------------------------------------------------
 464 
 465 class MyPanel_16(wx.Panel):
 466     """- 4 items: a ColWin, 3 Buttons
 467     - Buttons 1 and 3 are top/bottom aligned, Button 2 is centered
 468     - use of spacers to set a gap between the Buttons
 469     - better way?"""
 470 
 471     def __init__(self, parent):
 472         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 473 
 474         wgreen = ColWin(self, wx.NewId(), wx.NamedColour('green'))
 475         b1 = wx.Button(self, wx.NewId(), 'button1', (-1, -1), wx.DefaultSize)
 476         b2 = wx.Button(self, wx.NewId(), 'button2', (-1, -1), wx.DefaultSize)
 477         b3 = wx.Button(self, wx.NewId(), 'button3', (-1, -1), wx.DefaultSize)
 478 
 479         b = 0
 480         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 481         vsizer1.Add(b1, 0, wx.ALL, b)
 482         vsizer1.Add((-1, -1), 1)
 483         vsizer1.Add(b2, 0, wx.ALL, b)
 484         vsizer1.Add((-1, -1), 1)
 485         vsizer1.Add(b3, 0, wx.ALL, b)
 486 
 487         b = 5
 488         hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
 489         hsizer2.Add(vsizer1, 0, wx.EXPAND | wx.ALL, b)
 490         hsizer2.Add(wgreen, 1, wx.EXPAND | wx.ALL, b)
 491         self.SetSizer(hsizer2)
 492 
 493 #-------------------------------------------------------------------
 494 
 495 class MyPanel_17(wx.Panel):
 496     """- An input box"""
 497     def __init__(self, parent):
 498         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 499         self.parent = parent
 500 
 501         s = 'abc' + os.linesep + 'def' + os.linesep + 'ghi'
 502         statxt = wx.StaticText(self, -1, s, (-1, -1), (-1, -1))
 503         txt = wx.TextCtrl(self, wx.NewId(), 'input', (-1, -1), (-1, -1))
 504         staline = wx.StaticLine(self, -1, (-1, -1), (-1, -1), wx.LI_HORIZONTAL)
 505 
 506         b1 = wx.Button(self, wx.NewId(), "&OK", (-1, -1), wx.DefaultSize)
 507         b2 = wx.Button(self, wx.NewId(), "&Cancel", (-1, -1), wx.DefaultSize)
 508 
 509         b = 10
 510         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 511         hsizer1.Add(b1, 0)
 512         hsizer1.Add(b2, 0, wx.LEFT, b)
 513 
 514         b = 5
 515         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 516         vsizer1.Add(statxt, 0, wx.GROW | wx.ALL, b)
 517         vsizer1.Add(txt, 0, wx.GROW | wx.ALL, b)
 518         vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
 519         vsizer1.Add(hsizer1, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 520         vsizer1.SetMinSize((300, -1))
 521         self.SetSizerAndFit(vsizer1)
 522 
 523         #the items are not sizable, once set, pass the fitted size to
 524         #the parent
 525         self.parent.SetClientSize(vsizer1.GetSize())
 526 
 527 #-------------------------------------------------------------------
 528 
 529 class MyPanel_18(wx.Panel):
 530     """- A message box"""
 531 
 532     def __init__(self, parent):
 533         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 534         self.parent = parent
 535 
 536         s = 'This is a rather long message with.'
 537         s += (os.linesep + 'a lot of lines...')*20
 538 
 539         statxt = wx.StaticText(self, -1, s, (-1, -1), (-1, -1))
 540         staline = wx.StaticLine(self, -1, (-1, -1), (-1, -1), wx.LI_HORIZONTAL)
 541         b1 = wx.Button(self, wx.NewId(), "&OK", (-1, -1), wx.DefaultSize)
 542 
 543         b = 5
 544         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 545         vsizer1.Add(statxt, 1, wx.EXPAND | wx.ALL, b)
 546         vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
 547         vsizer1.Add(b1, 0, wx.ALIGN_CENTER | wx.ALL, b)
 548         vsizer1.SetMinSize((200, -1))
 549         self.SetSizerAndFit(vsizer1)
 550 
 551         self.parent.SetClientSize(vsizer1.GetSize())
 552 
 553 #-------------------------------------------------------------------
 554 
 555 class MyPanel_19(wx.Panel):
 556     """- A serie of couples, StaticText-TextCtrl
 557     - Buttons ok and cancel"""
 558 
 559     def __init__(self, parent):
 560         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 561         self.parent = parent
 562 
 563         lab1 = wx.StaticText(self, -1, 'hydrogen :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
 564         lab2 = wx.StaticText(self, -1, 'tin :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
 565         lab3 = wx.StaticText(self, -1, 'mendelevium :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
 566         lab4 = wx.StaticText(self, -1, 'carbon :', (-1, -1), (-1, -1), wx.ALIGN_RIGHT)
 567         txt1 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
 568         txt2 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
 569         txt3 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
 570         txt4 = wx.TextCtrl(self, -1, '', (-1, -1), (-1, -1))
 571         b1 = wx.Button(self, wx.NewId(), '&OK', (-1, -1), wx.DefaultSize)
 572         b2 = wx.Button(self, wx.NewId(), '&Cancel', (-1, -1), wx.DefaultSize)
 573         staline = wx.StaticLine(self, wx.NewId(), (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
 574 
 575         b = 5
 576         w = 100
 577         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 578         hsizer1.Add(lab1, 0, wx.RIGHT, b)
 579         hsizer1.Add(txt1, 1, wx.GROW, b)
 580         hsizer1.SetItemMinSize(lab1, (w, -1))
 581 
 582         hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
 583         hsizer2.Add(lab2, 0, wx.RIGHT, b)
 584         hsizer2.Add(txt2, 1, wx.GROW, b)
 585         hsizer2.SetItemMinSize(lab2, (w, -1))
 586 
 587         hsizer3 = wx.BoxSizer(wx.HORIZONTAL)
 588         hsizer3.Add(lab3, 0, wx.RIGHT, b)
 589         hsizer3.Add(txt3, 1, wx.GROW, b)
 590         hsizer3.SetItemMinSize(lab3, (w, -1))
 591 
 592         hsizer4 = wx.BoxSizer(wx.HORIZONTAL)
 593         hsizer4.Add(lab4, 0, wx.RIGHT, b)
 594         hsizer4.Add(txt4, 1, wx.GROW, b)
 595         hsizer4.SetItemMinSize(lab4, (w, -1))
 596 
 597         hsizer5 = wx.BoxSizer(wx.HORIZONTAL)
 598         hsizer5.Add(b1, 0)
 599         hsizer5.Add(b2, 0, wx.LEFT, 10)
 600 
 601         b = 5
 602         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 603         vsizer1.Add(hsizer1, 0, wx.EXPAND | wx.ALL, b)
 604         vsizer1.Add(hsizer2, 0, wx.EXPAND | wx.ALL, b)
 605         vsizer1.Add(hsizer3, 0, wx.EXPAND | wx.ALL, b)
 606         vsizer1.Add(hsizer4, 0, wx.EXPAND | wx.ALL, b)
 607         vsizer1.Add(staline, 0, wx.GROW | wx.ALL, b)
 608         vsizer1.Add(hsizer5, 0, wx.ALIGN_RIGHT | wx.ALL, b)
 609 
 610         self.SetSizerAndFit(vsizer1)
 611         self.parent.SetClientSize(vsizer1.GetSize())
 612 
 613 #-------------------------------------------------------------------
 614 
 615 class MyPanel_20(wx.Panel):
 616     """- A FlexGridSizer
 617     - 4 ColWins as cells, all sizeable"""
 618 
 619     def __init__(self, parent):
 620         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 621 
 622         wred = ColWin(self, -1, wx.RED)
 623         wblue = ColWin(self, -1, wx.BLUE)
 624         wwhite = ColWin(self, -1, wx.WHITE)
 625         wcyan = ColWin(self, -1, wx.CYAN)
 626 
 627         hgap, vgap = 0, 0
 628         nrows, ncols = 2, 2
 629         fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
 630 
 631         b = 5
 632         fgs.AddMany([(wred, 1, wx.EXPAND | wx.ALL, b),
 633                      (wblue, 1, wx.EXPAND | wx.ALL, b),
 634                      (wwhite, 1, wx.EXPAND | wx.ALL, b),
 635                      (wcyan, 1, wx.EXPAND | wx.ALL, b),
 636                     ])
 637 
 638         # or
 639         #~ fgs.Add(wred, 1, wx.EXPAND | wx.ALL, b)
 640         #~ fgs.Add(wblue, 1, wx.EXPAND | wx.ALL, b)
 641         #~ fgs.Add(wwhite, 1, wx.EXPAND | wx.ALL, b)
 642         #~ fgs.Add(wcyan, 1, wx.EXPAND | wx.ALL, b)
 643 
 644         #set all rows and cols sizable, try to comment / uncomment
 645         fgs.AddGrowableRow(0)
 646         fgs.AddGrowableRow(1)
 647         fgs.AddGrowableCol(0)
 648         fgs.AddGrowableCol(1)
 649 
 650         self.SetSizer(fgs)
 651 
 652 #-------------------------------------------------------------------
 653 
 654 class MyPanel_21(wx.Panel):
 655     """- A FlexgridSizer with 4 cells
 656     - cell (0, 0) is a column of 3 Buttons
 657     - cell (1, 1) is a row of 3 Buttons
 658     - cell (1, 0) is empty
 659     - cell (0, 1) is a ColWin"""
 660 
 661     def __init__(self, parent):
 662         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 663 
 664         wwhite = ColWin(self, -1, wx.WHITE)
 665         b1 = wx.Button(self, -1, 'button1', (-1, -1), wx.DefaultSize)
 666         b2 = wx.Button(self, -1, 'button2', (-1, -1), wx.DefaultSize)
 667         b3 = wx.Button(self, -1, 'button3', (-1, -1), wx.DefaultSize)
 668         b4 = wx.Button(self, -1, 'button4', (-1, -1), wx.DefaultSize)
 669         b5 = wx.Button(self, -1, 'button5', (-1, -1), wx.DefaultSize)
 670         b6 = wx.Button(self, -1, 'button6', (-1, -1), wx.DefaultSize)
 671 
 672         b = 0
 673         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 674         hsizer1.Add(b1, 0, wx.ALL, b)
 675         hsizer1.Add((-1, -1), 1)
 676         hsizer1.Add(b2, 0, wx.ALL, b)
 677         hsizer1.Add((-1, -1), 1)
 678         hsizer1.Add(b3, 0, wx.ALL, b)
 679 
 680         b = 0
 681         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 682         vsizer1.Add(b4, 0, wx.ALL, b)
 683         vsizer1.Add((-1, -1), 1)
 684         vsizer1.Add(b5, 0, wx.ALL, b)
 685         vsizer1.Add((-1, -1), 1)
 686         vsizer1.Add(b6, 0, wx.ALL, b)
 687 
 688         hgap, vgap = 0, 0
 689         nrows, ncols = 2, 2
 690         fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
 691 
 692         b = 5
 693         fgs.AddMany([(vsizer1, 1, wx.EXPAND | wx.ALL, b),
 694                      (wwhite, 1, wx.EXPAND | wx.ALL, b),
 695                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 696                      (hsizer1, 1, wx.EXPAND | wx.ALL, b),
 697                     ])
 698 
 699         #really tricky ;-)
 700         fgs.AddGrowableRow(0)
 701         fgs.AddGrowableCol(1)
 702 
 703         self.SetSizer(fgs)
 704 
 705 #-------------------------------------------------------------------
 706 
 707 class MyPanel_22(wx.Panel):
 708     """- A FlexGridSizer of 9 cells (3x3) with 5 ColWins in cells
 709     and 4 empty cells"""
 710 
 711     def __init__(self, parent):
 712         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 713 
 714         wwhite = ColWin(self, -1, wx.WHITE)
 715         wblue = ColWin(self, -1, wx.BLUE)
 716         wgreen = ColWin(self, -1, wx.GREEN)
 717         wcyan = ColWin(self, -1, wx.CYAN)
 718         wred = ColWin(self, -1, wx.RED)
 719 
 720         hgap, vgap = 0, 0
 721         nrows, ncols = 3, 3
 722         fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
 723 
 724         b = 5
 725         fgs.AddMany([(wwhite, 1, wx.EXPAND | wx.ALL, b),
 726                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 727                      (wblue, 1, wx.EXPAND | wx.ALL, b),
 728 
 729                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 730                      (wgreen, 1, wx.EXPAND | wx.ALL, b),
 731                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 732 
 733                      (wred, 1, wx.EXPAND | wx.ALL, b),
 734                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 735                      (wcyan, 1, wx.EXPAND | wx.ALL, b),
 736                     ])
 737 
 738         fgs.AddGrowableRow(0)
 739         fgs.AddGrowableRow(1)
 740         fgs.AddGrowableRow(2)
 741 
 742         fgs.AddGrowableCol(0)
 743         fgs.AddGrowableCol(1)
 744         fgs.AddGrowableCol(2)
 745 
 746         self.SetSizer(fgs)
 747 
 748 #-------------------------------------------------------------------
 749 
 750 class MyPanel_23(wx.Panel):
 751     """- A FlexGridSizer of 9 cells (3x3) with 4 ColWins in cells and 5 empty cells
 752     - rows 1 and 3 have a fixed size"""
 753 
 754     def __init__(self, parent):
 755         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 756 
 757         h = 40
 758         wwhite = wx.Window(self, -1, (-1, -1), (-1, h), wx.SIMPLE_BORDER)
 759         wwhite.SetBackgroundColour(wx.WHITE)
 760         wblue = ColWin(self, -1, wx.BLUE)
 761         wgreen = ColWin(self, -1, wx.GREEN)
 762         wred = wx.Window(self, -1, (-1, -1), (-1, h), wx.SIMPLE_BORDER)
 763         wred.SetBackgroundColour(wx.RED)
 764 
 765         hgap, vgap = 0, 0
 766         nrows, ncols = 3, 3
 767         fgs = wx.FlexGridSizer(nrows, ncols, hgap, vgap)
 768 
 769         b = 5
 770         fgs.AddMany([((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 771                      (wwhite, 1, wx.EXPAND | wx.ALL, b),
 772                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 773 
 774                      (wblue, 1, wx.EXPAND | wx.ALL, b),
 775                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 776                      (wgreen, 1, wx.EXPAND | wx.ALL, b),
 777 
 778                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 779                      (wred, 1, wx.EXPAND | wx.ALL, b),
 780                      ((-1, -1), 1, wx.EXPAND | wx.ALL, b),
 781                     ])
 782 
 783         fgs.AddGrowableRow(1)
 784 
 785         fgs.AddGrowableCol(0)
 786         fgs.AddGrowableCol(1)
 787         fgs.AddGrowableCol(2)
 788 
 789         self.SetSizer(fgs)
 790 
 791 #-------------------------------------------------------------------
 792 
 793 class MyPanel_24(wx.Panel):
 794     """- This example is coming from one of my applications
 795     - in the real app, the white window is a drawing area and
 796       the five lower windows are StaticTexts with a defined
 797       font size (this is why I force a fixed height)"""
 798 
 799     def __init__(self, parent):
 800         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 801         self.parent = parent
 802 
 803         #a menu for the beauty of the demo
 804         menu1 = wx.Menu()
 805         menu1.Append(101, '&aaa')
 806         menuBar = wx.MenuBar()
 807         menuBar.Append(menu1, '&File')
 808         self.parent.SetMenuBar(menuBar)
 809 
 810         wwhite = ColWin(self, -1, wx.WHITE)
 811         wblue = ColWin(self, -1, wx.BLUE)
 812         wgreen = ColWin(self, -1, wx.GREEN)
 813         wcyan = ColWin(self, -1, wx.CYAN)
 814         wred = ColWin(self, -1, wx.RED)
 815         wcoral = ColWin(self, -1, wx.NamedColour('coral'))
 816         staline = wx.StaticLine(self, -1, (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
 817 
 818         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 819         b = 5
 820         vsizer1.Add(wblue, 1, wx.EXPAND | wx.BOTTOM, b)
 821         vsizer1.Add(wgreen, 1, wx.EXPAND)
 822 
 823         hsizer2 = wx.BoxSizer(wx.HORIZONTAL)
 824         b = 5
 825         minhe = 100
 826         hsizer2.Add(wcoral, 2, wx.EXPAND | wx.RIGHT, b)
 827         hsizer2.Add(wcyan, 3, wx.EXPAND | wx.RIGHT, b)
 828         hsizer2.Add(wred, 3, wx.EXPAND | wx.RIGHT, b)
 829         hsizer2.Add(vsizer1, 2, wx.EXPAND, border=b)
 830         hsizer2.SetItemMinSize(wcoral, (-1, minhe))
 831         hsizer2.SetItemMinSize(wcyan, (-1, minhe))
 832         hsizer2.SetItemMinSize(wred, (-1, minhe))
 833         hsizer2.SetItemMinSize(vsizer1, (-1, minhe))
 834 
 835         vsizer3 = wx.BoxSizer(wx.VERTICAL)
 836         b = 5
 837         vsizer3.Add(staline, 0, wx.GROW | wx.ALL, 0)
 838         vsizer3.Add(wwhite, 1, wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT, b)
 839         vsizer3.Add(hsizer2, 0, wx.EXPAND | wx.ALL, b)
 840 
 841         self.SetSizerAndFit(vsizer3)
 842 
 843 #-------------------------------------------------------------------
 844 
 845 class MyPanel_25(wx.Panel):
 846     """- This shows the relaton between the font size and the size of the
 847       widgets when sizers are used"""
 848 
 849     def __init__(self, parent):
 850         wx.Panel.__init__(self, parent, -1, wx.DefaultPosition, wx.DefaultSize)
 851         self.parent = parent
 852 
 853         fs = 20
 854         self.SetFont(wx.Font(fs, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
 855 
 856 
 857         statxt1 = wx.StaticText(self, -1, 'one, two, three', (-1, -1), (-1, -1))
 858         statxt1.SetBackgroundColour(wx.WHITE)
 859         statxt2 = wx.StaticText(self, -1, 'eins, zwei, drei', (-1, -1), (-1, -1))
 860         statxt3 = wx.StaticText(self, -1, 'un, deux, trois', (-1, -1), (-1, -1))
 861         b1 = wx.Button(self, wx.NewId(), 'button1', (-1, -1), (-1, -1))
 862         b2 = wx.Button(self, wx.NewId(), 'button2', (-1, -1), (-1, -1))
 863 
 864         b = 5
 865         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 866         hsizer1.Add(b1, 1, wx.EXPAND | wx.ALL, b)
 867         hsizer1.Add(b2, 1, wx.EXPAND | wx.ALL, b)
 868 
 869         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 870         vsizer1.Add(statxt1, 0, wx.ALL, b)
 871         vsizer1.Add(statxt2, 0, wx.ALL, b)
 872         vsizer1.Add(statxt3, 0, wx.ALL, b)
 873         vsizer1.Add(hsizer1, 0, wx.ALL, b)
 874 
 875         self.SetSizerAndFit(vsizer1)
 876         self.parent.SetClientSize(vsizer1.GetSize())
 877 
 878 #-------------------------------------------------------------------
 879 
 880 class TestComboBox(wx.Panel):
 881     def __init__(self, parent, id):
 882         wx.Panel.__init__(self, parent, id)
 883 
 884         sampleList = []
 885         for i in range(0, 26):
 886             sampleList.append('MyPanel_' + `i`)
 887 
 888         st = wx.StaticText(self, -1, "Select the example you want to see."
 889                          "Then click the View button.", (-1, -1))
 890 
 891         doctxt = wx.StaticText(self, -1, "")
 892         doctxt.SetLabel(MyPanel_0.__doc__)
 893         self.doctxt = doctxt
 894 
 895         # This combobox is created with a preset list of values.
 896         cb = wx.ComboBox(
 897             self, -1, "MyPanel_0", (-1, -1),
 898             (-1, -1), sampleList, wx.CB_DROPDOWN
 899             )
 900         self.cb = cb
 901 
 902         stline = wx.StaticLine(self, -1, (-1, -1), (-1, 2), wx.LI_HORIZONTAL)
 903 
 904         btnView = wx.Button(self, -1, "&View")
 905         self.Bind(wx.EVT_BUTTON, self.OnClickView, btnView)
 906 
 907         btnExit = wx.Button(self, -1, "E&xit")
 908         self.Bind(wx.EVT_BUTTON, self.OnClickExit, btnExit)
 909 
 910         b = 5
 911         vsizer1 = wx.BoxSizer(wx.VERTICAL)
 912         vsizer1.Add(st, 0, wx.EXPAND | wx.ALL, b)
 913         vsizer1.Add(cb, 0, wx.EXPAND | wx.ALL, 0)
 914         vsizer1.Add(doctxt, 0, wx.EXPAND | wx.ALL, b)
 915 
 916         hsizer1 = wx.BoxSizer(wx.HORIZONTAL)
 917         hsizer1.Add(btnView, 0)
 918         hsizer1.Add(btnExit, 0, wx.LEFT, b)
 919 
 920         vsizer2 = wx.BoxSizer(wx.VERTICAL)
 921         vsizer2.Add(vsizer1, 5, wx.EXPAND | wx.ALL, 0)
 922         vsizer2.Add(stline, 0, wx.GROW | wx.ALL, b)
 923         vsizer2.Add(hsizer1, 1, wx.ALIGN_RIGHT | wx.ALL, b)
 924         self.SetSizer(vsizer2)
 925 
 926         self.Bind(wx.EVT_COMBOBOX, self.EvtComboBox, cb)
 927 
 928     # When the user selects something, we go here.
 929     def EvtComboBox(self, evt):
 930         self.doctxt.SetLabel(eval('%s.__doc__' % self.cb.GetValue()))
 931 
 932     def OnClickView(self, evt):
 933         win = wx.Frame(self, -1, self.cb.GetValue(), size=(350, 200),
 934                   style = wx.DEFAULT_FRAME_STYLE)
 935         eval('%s(win)' % self.cb.GetValue())
 936 
 937         win.CenterOnScreen()
 938         win.Show(True)
 939 
 940     def OnClickExit(self, evt):
 941         sys.exit()
 942 
 943 
 944 #-------------------------------------------------------------------
 945 
 946 
 947 class MyFrame(wx.Frame):
 948 
 949     def __init__(self, parent, id):
 950         s = __file__
 951         wx.Frame.__init__(self, parent, id, s, (0, 0), (500, 400))
 952 
 953         self.panel = eval('MyPanel_%d(self)' % panel)
 954         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
 955 
 956     def OnCloseWindow(self, event):
 957         self.Destroy()
 958 
 959 #-------------------------------------------------------------------
 960 
 961 class MyApp(wx.App):
 962 
 963     def OnInit(self):
 964         frame = wx.Frame(None, -1, __file__, (0, 0), (400, 300))
 965         frame.panel = TestComboBox(frame, -1)
 966         frame.Show(True)
 967         self.SetTopWindow(frame)
 968         return True
 969 
 970 #-------------------------------------------------------------------
 971 
 972 def main():
 973     app = MyApp(False)
 974     app.MainLoop()
 975 
 976 #-------------------------------------------------------------------
 977 
 978 if __name__ == "__main__" :
 979     main()
 980 
 981 #eof-------------------------------------------------------------------

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-10-04 09:16:03, 35.5 KB) [[attachment:LearnSizers1.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

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