2 #---------------------------------------------------------------------------- 
   4 # Purpose:      Testing lots of stuff, controls, window types, etc. 
  10 # Copyright:    (c) 1998 by Total Control Software 
  11 # Licence:      wxWindows license 
  12 #---------------------------------------------------------------------------- 
  15 from wxPython
.wx 
import * 
  19 #--------------------------------------------------------------------------- 
  21 class TestSimpleControlsDlg(wxDialog
): 
  22     def __init__(self
, parent
, log
): 
  24         wxDialog
.__init
__(self
, parent
, -1, "Test Simple Controls", 
  25                           wxDefaultPosition
, wxSize(350, 400)) 
  28         sampleList 
= ["zero", "one", "two", "three", "four", "five", 
  29                       "six", "seven", "eight", "nine", "ten"] 
  34         wxStaticText(self
, -1, "wxTextCtrl", wxPoint(5, y_pos
), wxSize(75, 20)) 
  35         wxTextCtrl(self
, 10, "", wxPoint(80, y_pos
), wxSize(150, 20)) 
  36         EVT_TEXT(self
, 10, self
.EvtText
) 
  39         wxCheckBox(self
, 20, "wxCheckBox", wxPoint(80, y_pos
), wxSize(150, 20), wxNO_BORDER
) 
  40         EVT_CHECKBOX(self
, 20, self
.EvtCheckBox
) 
  43         rb 
= wxRadioBox(self
, 30, "wxRadioBox", wxPoint(80, y_pos
), wxDefaultSize
, 
  44                         sampleList
, 3, wxRA_SPECIFY_COLS | wxNO_BORDER
) 
  45         EVT_RADIOBOX(self
, 30, self
.EvtRadioBox
) 
  46         width
, height 
= rb
.GetSizeTuple() 
  47         y_pos 
= y_pos 
+ height 
+ 5 
  49         wxStaticText(self
, -1, "wxChoice", wxPoint(5, y_pos
), wxSize(75, 20)) 
  50         wxChoice(self
, 40, wxPoint(80, y_pos
), wxSize(95, 20), #wxDefaultSize, 
  52         EVT_CHOICE(self
, 40, self
.EvtChoice
) 
  55         wxStaticText(self
, -1, "wxComboBox", wxPoint(5, y_pos
), wxSize(75, 18)) 
  56         wxComboBox(self
, 50, "default value", wxPoint(80, y_pos
), wxSize(95, -1), 
  57                    sampleList
, wxCB_DROPDOWN
) 
  58         EVT_COMBOBOX(self
, 50, self
.EvtComboBox
) 
  61         wxStaticText(self
, -1, "wxListBox", wxPoint(5, y_pos
), wxSize(75, 18)) 
  62         lb 
= wxListBox(self
, 60, wxPoint(80, y_pos
), wxSize(95, 80), 
  63                        sampleList
, wxLB_SINGLE
) 
  64         EVT_LISTBOX(self
, 60, self
.EvtListBox
) 
  65         EVT_LISTBOX_DCLICK(self
, 60, self
.EvtListBoxDClick
) 
  67         width
, height 
= lb
.GetSizeTuple() 
  68         y_pos 
= y_pos 
+ height 
+ 5 
  73         wxButton(self
, wxID_OK
, ' OK ', wxPoint(80, y_pos
), wxDefaultSize
).SetDefault() 
  74         wxButton(self
, wxID_CANCEL
, ' Cancel ', wxPoint(140, y_pos
)) 
  77     def EvtText(self
, event
): 
  78         self
.log
.WriteText('EvtText: %s\n' % event
.GetString()) 
  80     def EvtCheckBox(self
, event
): 
  81         self
.log
.WriteText('EvtCheckBox: %d\n' % event
.GetInt()) 
  83     def EvtRadioBox(self
, event
): 
  84         self
.log
.WriteText('EvtRadioBox: %d\n' % event
.GetInt()) 
  86     def EvtChoice(self
, event
): 
  87         self
.log
.WriteText('EvtChoice: %s\n' % event
.GetString()) 
  89     def EvtComboBox(self
, event
): 
  90         self
.log
.WriteText('EvtComboBox: %s\n' % event
.GetString()) 
  92     def EvtListBox(self
, event
): 
  93         self
.log
.WriteText('EvtListBox: %s\n' % event
.GetString()) 
  95     def EvtListBoxDClick(self
, event
): 
  96         self
.log
.WriteText('EvtListBoxDClick:\n') 
 100 #--------------------------------------------------------------------------- 
 102 class TestTimer(wxTimer
): 
 103     def __init__(self
, log
): 
 104         wxTimer
.__init
__(self
) 
 109         self
.log
.WriteText('beep!\n') 
 112 #--------------------------------------------------------------------------- 
 114 class TestLayoutConstraints(wxFrame
): 
 115     def __init__(self
, parent
): 
 116         wxFrame
.__init
__(self
, parent
, -1, 'Test Layout Constraints', 
 117                          wxDefaultPosition
, wxSize(500, 300)) 
 119         self
.SetAutoLayout(true
) 
 120         EVT_BUTTON(self
, 100, self
.OnButton
) 
 122         self
.panelA 
= wxWindow(self
, -1, wxDefaultPosition
, wxDefaultSize
, 
 124         self
.panelA
.SetBackgroundColour(wxBLUE
) 
 125         lc 
= wxLayoutConstraints() 
 126         lc
.top
.SameAs(self
, wxTop
, 10) 
 127         lc
.left
.SameAs(self
, wxLeft
, 10) 
 128         lc
.bottom
.SameAs(self
, wxBottom
, 10) 
 129         lc
.right
.PercentOf(self
, wxRight
, 50) 
 130         self
.panelA
.SetConstraints(lc
) 
 132         self
.panelB 
= wxWindow(self
, -1, wxDefaultPosition
, wxDefaultSize
, 
 134         self
.panelB
.SetBackgroundColour(wxRED
) 
 135         lc 
= wxLayoutConstraints() 
 136         lc
.top
.SameAs(self
, wxTop
, 10) 
 137         lc
.right
.SameAs(self
, wxRight
, 10) 
 138         lc
.bottom
.PercentOf(self
, wxBottom
, 30) 
 139         lc
.left
.RightOf(self
.panelA
, 10) 
 140         self
.panelB
.SetConstraints(lc
) 
 142         self
.panelC 
= wxWindow(self
, -1, wxDefaultPosition
, wxDefaultSize
, 
 144         self
.panelC
.SetBackgroundColour(wxWHITE
) 
 145         lc 
= wxLayoutConstraints() 
 146         lc
.top
.Below(self
.panelB
, 10) 
 147         lc
.right
.SameAs(self
, wxRight
, 10) 
 148         lc
.bottom
.SameAs(self
, wxBottom
, 10) 
 149         lc
.left
.RightOf(self
.panelA
, 10) 
 150         self
.panelC
.SetConstraints(lc
) 
 152         b 
= wxButton(self
.panelA
, 100, ' Panel A ') 
 153         lc 
= wxLayoutConstraints() 
 154         lc
.centreX
.SameAs   (self
.panelA
, wxCentreX
) 
 155         lc
.centreY
.SameAs   (self
.panelA
, wxCentreY
) 
 157         lc
.width
.PercentOf  (self
.panelA
, wxWidth
, 50) 
 158         b
.SetConstraints(lc
); 
 160         b 
= wxButton(self
.panelB
, 100, ' Panel B ') 
 161         lc 
= wxLayoutConstraints() 
 162         lc
.top
.SameAs       (self
.panelB
, wxTop
, 2) 
 163         lc
.right
.SameAs     (self
.panelB
, wxRight
, 4) 
 166         b
.SetConstraints(lc
); 
 168         self
.panelD 
= wxWindow(self
.panelC
, -1, wxDefaultPosition
, wxDefaultSize
, 
 170         self
.panelD
.SetBackgroundColour(wxGREEN
) 
 171         wxStaticText(self
.panelD
, -1, "Panel D", wxPoint(4, 4)).SetBackgroundColour(wxGREEN
) 
 173         b 
= wxButton(self
.panelC
, 100, ' Panel C ') 
 174         lc 
= wxLayoutConstraints() 
 175         lc
.top
.Below        (self
.panelD
) 
 176         lc
.left
.RightOf     (self
.panelD
) 
 179         b
.SetConstraints(lc
); 
 181         lc 
= wxLayoutConstraints() 
 182         lc
.bottom
.PercentOf (self
.panelC
, wxHeight
, 50) 
 183         lc
.right
.PercentOf  (self
.panelC
, wxWidth
, 50) 
 184         lc
.height
.SameAs    (b
, wxHeight
) 
 185         lc
.width
.SameAs     (b
, wxWidth
) 
 186         self
.panelD
.SetConstraints(lc
); 
 189     def OnButton(self
, event
): 
 193     def OnCloseWindow(self
, event
): 
 197 #--------------------------------------------------------------------------- 
 199 class TestGrid(wxFrame
): 
 200     def __init__(self
, parent
, log
): 
 201         wxFrame
.__init
__(self
, parent
, -1, 'Test Grid', 
 202                          wxDefaultPosition
, wxSize(500, 300)) 
 205         grid 
= wxGrid(self
, -1) 
 207         grid
.CreateGrid(16, 16) 
 208         grid
.SetColumnWidth(3, 200) 
 209         grid
.SetRowHeight(4, 45) 
 210         grid
.SetCellValue("First cell", 0, 0) 
 211         grid
.SetCellValue("Another cell", 1, 1) 
 212         grid
.SetCellValue("Yet another cell", 2, 2) 
 213         grid
.SetCellTextFont(wxFont(12, wxROMAN
, wxITALIC
, wxNORMAL
), 0, 0) 
 214         grid
.SetCellTextColour(wxRED
, 1, 1) 
 215         grid
.SetCellBackgroundColour(wxCYAN
, 2, 2) 
 216         grid
.UpdateDimensions() 
 217         grid
.AdjustScrollbars() 
 219         EVT_GRID_SELECT_CELL(grid
, self
.OnSelectCell
) 
 220         EVT_GRID_CELL_CHANGE(grid
, self
.OnCellChange
) 
 221         EVT_GRID_CELL_LCLICK(grid
, self
.OnCellClick
) 
 222         EVT_GRID_LABEL_LCLICK(grid
, self
.OnLabelClick
) 
 226     def OnCloseWindow(self
, event
): 
 229     def OnSelectCell(self
, event
): 
 230         self
.log
.WriteText("OnSelectCell: (%d, %d)\n" % (event
.m_row
, event
.m_col
)) 
 232     def OnCellChange(self
, event
): 
 233         self
.log
.WriteText("OnCellChange: (%d, %d)\n" % (event
.m_row
, event
.m_col
)) 
 235     def OnCellClick(self
, event
): 
 236         self
.log
.WriteText("OnCellClick: (%d, %d)\n" % (event
.m_row
, event
.m_col
)) 
 238     def OnLabelClick(self
, event
): 
 239         self
.log
.WriteText("OnLabelClick: (%d, %d)\n" % (event
.m_row
, event
.m_col
)) 
 241 #--------------------------------------------------------------------------- 
 244 class ColoredPanel(wxWindow
): 
 245     def __init__(self
, parent
, color
): 
 246         wxWindow
.__init
__(self
, parent
, -1, 
 247                           wxDefaultPosition
, wxDefaultSize
, wxRAISED_BORDER
) 
 248         self
.SetBackgroundColour(color
) 
 251 class TestNotebookWindow(wxFrame
): 
 252     def __init__(self
, parent
, log
): 
 253         wxFrame
.__init
__(self
, parent
, -1, 'Test wxNotebook') 
 255         nb 
= wxNotebook(self
, -1, wxPoint(0,0), self
.GetClientSize()) 
 257         win 
= ColoredPanel(nb
, wxBLUE
) 
 258         nb
.AddPage(win
, "Blue") 
 259         st 
= wxStaticText(win
, -1, 
 260                           "You can put nearly any type of window here!", 
 262         st
.SetForegroundColour(wxWHITE
) 
 263         st
.SetBackgroundColour(wxBLUE
) 
 264         st 
= wxStaticText(win
, -1, 
 265                           "Check the next tab for an example...", 
 267         st
.SetForegroundColour(wxWHITE
) 
 268         st
.SetBackgroundColour(wxBLUE
) 
 270         win 
= TestTreeCtrlPanel(nb
, log
) 
 271         nb
.AddPage(win
, "TreeCtrl") 
 273         win 
= TestListCtrlPanel(nb
, log
) 
 274         nb
.AddPage(win
, "ListCtrl") 
 276         win 
= ColoredPanel(nb
, wxRED
) 
 277         nb
.AddPage(win
, "Red") 
 279         win 
= ColoredPanel(nb
, wxGREEN
) 
 280         nb
.AddPage(win
, "Green") 
 282         win 
= ColoredPanel(nb
, wxCYAN
) 
 283         nb
.AddPage(win
, "Cyan") 
 285         win 
= ColoredPanel(nb
, wxWHITE
) 
 286         nb
.AddPage(win
, "White") 
 288         win 
= ColoredPanel(nb
, wxBLACK
) 
 289         nb
.AddPage(win
, "Black") 
 291         win 
= ColoredPanel(nb
, wxNamedColour('MIDNIGHT BLUE')) 
 292         nb
.AddPage(win
, "MIDNIGHT BLUE") 
 294         win 
= ColoredPanel(nb
, wxNamedColour('INDIAN RED')) 
 295         nb
.AddPage(win
, "INDIAN RED") 
 298         self
.SetSize(wxSize(350, 300)) 
 301     def OnCloseWindow(self
, event
): 
 304 #--------------------------------------------------------------------------- 
 306 class TestSplitterWindow(wxFrame
): 
 307     def __init__(self
, parent
): 
 308         wxFrame
.__init
__(self
, parent
, -1, 'Test wxSplitterWindow', 
 309                          wxDefaultPosition
, wxSize(500, 300)) 
 311         splitter 
= wxSplitterWindow(self
, -1) 
 313         p1 
= ColoredPanel(splitter
, wxRED
) 
 314         wxStaticText(p1
, -1, "Panel One", wxPoint(5,5)).SetBackgroundColour(wxRED
) 
 316         p2 
= ColoredPanel(splitter
, wxBLUE
) 
 317         wxStaticText(p2
, -1, "Panel Two", wxPoint(5,5)).SetBackgroundColour(wxBLUE
) 
 319         splitter
.SplitVertically(p1
, p2
) 
 322     def OnCloseWindow(self
, event
): 
 326 #--------------------------------------------------------------------------- 
 328 class CustomStatusBar(wxStatusBar
): 
 329     def __init__(self
, parent
): 
 330         wxStatusBar
.__init
__(self
, parent
, -1) 
 331         self
.SetFieldsCount(3) 
 333         self
.SetStatusText("A Custom StatusBar...", 0) 
 335         self
.cb 
= wxCheckBox(self
, 1001, "toggle clock") 
 336         EVT_CHECKBOX(self
, 1001, self
.OnToggleClock
) 
 337         self
.cb
.SetValue(true
) 
 339         # figure out how tall to make it. 
 340         dc 
= wxClientDC(self
) 
 341         dc
.SetFont(self
.GetFont()) 
 342         (w
,h
) = dc
.GetTextExtent('X') 
 344         self
.SetSize(wxSize(100, h
)) 
 347         self
.timer 
= wxPyTimer(self
.Notify
) 
 348         self
.timer
.Start(1000) 
 354         t 
= time
.localtime(time
.time()) 
 355         st 
= time
.strftime("%d-%b-%Y   %I:%M:%S", t
) 
 356         self
.SetStatusText(st
, 2) 
 358     # the checkbox was clicked 
 359     def OnToggleClock(self
, event
): 
 360         if self
.cb
.GetValue(): 
 361             self
.timer
.Start(1000) 
 366     # reposition the checkbox 
 367     def OnSize(self
, event
): 
 368         rect 
= self
.GetFieldRect(1) 
 369         print "%s, %s" % (rect
.x
, rect
.y
) 
 370         self
.cb
.SetPosition(wxPoint(rect
.x
+2, rect
.y
+2)) 
 371         self
.cb
.SetSize(wxSize(rect
.width
-4, rect
.height
-4)) 
 375 class TestCustomStatusBar(wxFrame
): 
 376     def __init__(self
, parent
): 
 377         wxFrame
.__init
__(self
, parent
, -1, 'Test Custom StatusBar', 
 378                          wxDefaultPosition
, wxSize(500, 300)) 
 379         wxWindow(self
, -1).SetBackgroundColour(wxNamedColour("WHITE")) 
 381         self
.sb 
= CustomStatusBar(self
) 
 382         self
.SetStatusBar(self
.sb
) 
 384     def OnCloseWindow(self
, event
): 
 389 #--------------------------------------------------------------------------- 
 391 class TestToolBar(wxFrame
): 
 392     def __init__(self
, parent
, log
): 
 393         wxFrame
.__init
__(self
, parent
, -1, 'Test ToolBar', 
 394                          wxDefaultPosition
, wxSize(500, 300)) 
 397         wxWindow(self
, -1).SetBackgroundColour(wxNamedColour("WHITE")) 
 399         tb 
= self
.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER
) 
 400         #tb = wxToolBar(self, -1, wxDefaultPosition, wxDefaultSize, 
 401         #               wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT) 
 404         self
.CreateStatusBar() 
 406         tb
.AddTool(10, wxNoRefBitmap('bitmaps/new.bmp',   wxBITMAP_TYPE_BMP
), 
 407                         wxNullBitmap
, false
, -1, -1, "New", "Long help for 'New'") 
 408         EVT_TOOL(self
, 10, self
.OnToolClick
) 
 409         EVT_TOOL_RCLICKED(self
, 10, self
.OnToolRClick
) 
 411         tb
.AddTool(20, wxNoRefBitmap('bitmaps/open.bmp',  wxBITMAP_TYPE_BMP
), 
 412                         wxNullBitmap
, false
, -1, -1, "Open") 
 413         EVT_TOOL(self
, 20, self
.OnToolClick
) 
 414         EVT_TOOL_RCLICKED(self
, 20, self
.OnToolRClick
) 
 417         tb
.AddTool(30, wxNoRefBitmap('bitmaps/copy.bmp',  wxBITMAP_TYPE_BMP
), 
 418                         wxNullBitmap
, false
, -1, -1, "Copy") 
 419         EVT_TOOL(self
, 30, self
.OnToolClick
) 
 420         EVT_TOOL_RCLICKED(self
, 30, self
.OnToolRClick
) 
 422         tb
.AddTool(40, wxNoRefBitmap('bitmaps/paste.bmp', wxBITMAP_TYPE_BMP
), 
 423                         wxNullBitmap
, false
, -1, -1, "Paste") 
 424         EVT_TOOL(self
, 40, self
.OnToolClick
) 
 425         EVT_TOOL_RCLICKED(self
, 40, self
.OnToolRClick
) 
 429         tb
.AddTool(50, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP
), 
 430                         wxNullBitmap
, true
, -1, -1, "Toggle this") 
 431         EVT_TOOL(self
, 50, self
.OnToolClick
) 
 432         EVT_TOOL_RCLICKED(self
, 50, self
.OnToolRClick
) 
 434         tb
.AddTool(60, wxNoRefBitmap('bitmaps/tog1.bmp', wxBITMAP_TYPE_BMP
), 
 435                         wxNoRefBitmap('bitmaps/tog2.bmp', wxBITMAP_TYPE_BMP
), 
 436                         true
, -1, -1, "Toggle with 2 bitmaps") 
 437         EVT_TOOL(self
, 60, self
.OnToolClick
) 
 438         EVT_TOOL_RCLICKED(self
, 60, self
.OnToolRClick
) 
 443     def OnCloseWindow(self
, event
): 
 446     def OnToolClick(self
, event
): 
 447         self
.log
.WriteText("tool %s clicked\n" % event
.GetId()) 
 449     def OnToolRClick(self
, event
): 
 450         self
.log
.WriteText("tool %s right-clicked\n" % event
.GetId()) 
 453 #--------------------------------------------------------------------------- 
 455 class TestTreeCtrlPanel(wxPanel
): 
 456     def __init__(self
, parent
, log
): 
 457         wxPanel
.__init
__(self
, parent
, -1) 
 462         self
.tree 
= wxTreeCtrl(self
, tID
) 
 463         root 
= self
.tree
.AddRoot("The Root Item") 
 465             child 
= self
.tree
.AppendItem(root
, "Item %d" % x
) 
 467                 last 
= self
.tree
.AppendItem(child
, "item %d-%s" % (x
, chr(ord("a")+y
))) 
 469         self
.tree
.Expand(root
) 
 470         EVT_TREE_ITEM_EXPANDED  (self
, tID
, self
.OnItemExpanded
) 
 471         EVT_TREE_ITEM_COLLAPSED (self
, tID
, self
.OnItemCollapsed
) 
 472         EVT_TREE_SEL_CHANGED    (self
, tID
, self
.OnSelChanged
) 
 475     def OnSize(self
, event
): 
 476         w
,h 
= self
.GetClientSizeTuple() 
 477         self
.tree
.SetDimensions(0, 0, w
, h
) 
 480     def OnItemExpanded(self
, event
): 
 481         item 
= event
.GetItem() 
 482         self
.log
.WriteText("OnItemExpanded: %s\n" % self
.tree
.GetItemText(item
)) 
 484     def OnItemCollapsed(self
, event
): 
 485         item 
= event
.GetItem() 
 486         self
.log
.WriteText("OnItemCollapsed: %s\n" % self
.tree
.GetItemText(item
)) 
 488     def OnSelChanged(self
, event
): 
 489         item 
= event
.GetItem() 
 490         self
.log
.WriteText("OnSelChanged: %s\n" % self
.tree
.GetItemText(item
)) 
 495 class TestTreeCtrl(wxFrame
): 
 496     def __init__(self
, parent
, log
): 
 497         wxFrame
.__init
__(self
, parent
, -1, 'Test TreeCtrl', 
 498                          wxDefaultPosition
, wxSize(250, 300)) 
 500         p 
= TestTreeCtrlPanel(self
, log
) 
 503 #--------------------------------------------------------------------------- 
 505 class TestListCtrlPanel(wxPanel
): 
 506     def __init__(self
, parent
, log
): 
 507         wxPanel
.__init
__(self
, parent
, -1) 
 512         self
.il 
= wxImageList(16, 16) 
 513         idx1 
= self
.il
.Add(wxNoRefBitmap('bitmaps/smiles.bmp', wxBITMAP_TYPE_BMP
)) 
 515         self
.list = wxListCtrl(self
, tID
, wxDefaultPosition
, wxDefaultSize
, 
 516                                wxLC_REPORT|wxSUNKEN_BORDER
) 
 517         self
.list.SetImageList(self
.il
, wxIMAGE_LIST_SMALL
) 
 519         #self.list.SetToolTip(wxToolTip("This is a ToolTip!")) 
 520         #wxToolTip_Enable(true) 
 522         self
.list.InsertColumn(0, "Column 0") 
 523         self
.list.InsertColumn(1, "Column 1") 
 524         self
.list.InsertColumn(2, "One More Column (2)") 
 526             self
.list.InsertImageStringItem(x
, "This is item %d" % x
, idx1
) 
 527             self
.list.SetStringItem(x
, 1, "Col 1, item %d" % x
) 
 528             self
.list.SetStringItem(x
, 2, "item %d in column 2" % x
) 
 530         self
.list.SetColumnWidth(0, wxLIST_AUTOSIZE
) 
 531         self
.list.SetColumnWidth(1, wxLIST_AUTOSIZE
) 
 532         self
.list.SetColumnWidth(2, wxLIST_AUTOSIZE
) 
 535     def OnSize(self
, event
): 
 536         w
,h 
= self
.GetClientSizeTuple() 
 537         self
.list.SetDimensions(0, 0, w
, h
) 
 542 class TestListCtrl(wxFrame
): 
 543     def __init__(self
, parent
, log
): 
 544         wxFrame
.__init
__(self
, parent
, -1, 'Test ListCtrl', 
 545                          wxDefaultPosition
, wxSize(250, 300)) 
 547         p 
= TestListCtrlPanel(self
, log
) 
 550 #--------------------------------------------------------------------------- 
 552 class TestSashWindow(wxMDIParentFrame
): 
 557     ID_WINDOW_LEFT1  
= 5101 
 558     ID_WINDOW_LEFT2  
= 5102 
 559     ID_WINDOW_BOTTOM 
= 5103 
 562     def __init__(self
, parent
, log
): 
 563         wxMDIParentFrame
.__init
__(self
, parent
, -1, 'Test Sash Window', 
 564                                   wxDefaultPosition
, wxSize(250, 300)) 
 568         menu
.Append(self
.NEW_WINDOW
, "&New Window") 
 569         menu
.Append(self
.TOGGLE_WINDOW
, "&Toggle window") 
 570         menu
.Append(self
.QUIT
, "E&xit") 
 572         menubar 
= wxMenuBar() 
 573         menubar
.Append(menu
, "&File") 
 575         self
.SetMenuBar(menubar
) 
 576         self
.CreateStatusBar() 
 578         EVT_MENU(self
, self
.NEW_WINDOW
,    self
.OnNewWindow
) 
 579         EVT_MENU(self
, self
.TOGGLE_WINDOW
, self
.OnToggleWindow
) 
 580         EVT_MENU(self
, self
.QUIT
,          self
.OnQuit
) 
 582         EVT_SASH_DRAGGED_RANGE(self
, self
.ID_WINDOW_TOP
, 
 583                                self
.ID_WINDOW_BOTTOM
, self
.OnSashDrag
) 
 586         # Create some layout windows 
 587         # A window like a toolbar 
 588         win 
= wxSashLayoutWindow(self
, self
.ID_WINDOW_TOP
, wxDefaultPosition
, 
 589                                  wxSize(200, 30), wxNO_BORDER|wxSW_3D
) 
 590         win
.SetDefaultSize(wxSize(1000, 30)) 
 591         win
.SetOrientation(wxLAYOUT_HORIZONTAL
) 
 592         win
.SetAlignment(wxLAYOUT_TOP
) 
 593         win
.SetBackgroundColour(wxColour(255, 0, 0)) 
 594         win
.SetSashVisible(wxSASH_BOTTOM
, true
) 
 599         # A window like a statusbar 
 600         win 
= wxSashLayoutWindow(self
, self
.ID_WINDOW_BOTTOM
, 
 601                                  wxDefaultPosition
, wxSize(200, 30), 
 603         win
.SetDefaultSize(wxSize(1000, 30)) 
 604         win
.SetOrientation(wxLAYOUT_HORIZONTAL
) 
 605         win
.SetAlignment(wxLAYOUT_BOTTOM
) 
 606         win
.SetBackgroundColour(wxColour(0, 0, 255)) 
 607         win
.SetSashVisible(wxSASH_TOP
, true
) 
 609         self
.bottomWindow 
= win
 
 612         # A window to the left of the client window 
 613         win 
=  wxSashLayoutWindow(self
, self
.ID_WINDOW_LEFT1
, 
 614                                   wxDefaultPosition
, wxSize(200, 30), 
 616         win
.SetDefaultSize(wxSize(120, 1000)) 
 617         win
.SetOrientation(wxLAYOUT_VERTICAL
) 
 618         win
.SetAlignment(wxLAYOUT_LEFT
) 
 619         win
.SetBackgroundColour(wxColour(0, 255, 0)) 
 620         win
.SetSashVisible(wxSASH_RIGHT
, TRUE
) 
 621         win
.SetExtraBorderSize(10) 
 623         textWindow 
= wxTextCtrl(win
, -1, "", wxDefaultPosition
, wxDefaultSize
, 
 624                                 wxTE_MULTILINE|wxSUNKEN_BORDER
) 
 625         textWindow
.SetValue("A help window") 
 627         self
.leftWindow1 
= win
 
 630         # Another window to the left of the client window 
 631         win 
= wxSashLayoutWindow(self
, self
.ID_WINDOW_LEFT2
, 
 632                                  wxDefaultPosition
, wxSize(200, 30), 
 634         win
.SetDefaultSize(wxSize(120, 1000)) 
 635         win
.SetOrientation(wxLAYOUT_VERTICAL
) 
 636         win
.SetAlignment(wxLAYOUT_LEFT
) 
 637         win
.SetBackgroundColour(wxColour(0, 255, 255)) 
 638         win
.SetSashVisible(wxSASH_RIGHT
, TRUE
) 
 640         self
.leftWindow2 
= win
 
 643     def OnNewWindow(self
, event
): 
 646     def OnToggleWindow(self
, event
): 
 649     def OnQuit(self
, event
): 
 652     def OnSashDrag(self
, event
): 
 653         if event
.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE
: 
 657         if eID 
== self
.ID_WINDOW_TOP
: 
 658             self
.topWindow
.SetDefaultSize(wxSize(1000, event
.GetDragRect().height
)) 
 660         elif eID 
== self
.ID_WINDOW_LEFT1
: 
 661             self
.leftWindow1
.SetDefaultSize(wxSize(event
.GetDragRect().width
, 1000)) 
 664         elif eID 
== self
.ID_WINDOW_LEFT2
: 
 665             self
.leftWindow2
.SetDefaultSize(wxSize(event
.GetDragRect().width
, 1000)) 
 667         elif eID 
== self
.ID_WINDOW_BOTTOM
: 
 668             self
.bottomWindow
.SetDefaultSize(wxSize(1000, event
.GetDragRect().height
)) 
 670         wxLayoutAlgorithm().LayoutMDIFrame(self
) 
 672         # Leaves bits of itself behind sometimes 
 673         self
.GetClientWindow().Refresh() 
 676     def OnSize(self
, event
): 
 677         wxLayoutAlgorithm().LayoutMDIFrame(self
) 
 679 #--------------------------------------------------------------------------- 
 680 #--------------------------------------------------------------------------- 
 681 #--------------------------------------------------------------------------- 
 683 class AppFrame(wxFrame
): 
 684     def __init__(self
, parent
, id, title
): 
 685         wxFrame
.__init
__(self
, parent
, id, title
, wxDefaultPosition
, 
 687         if wxPlatform 
== '__WXMSW__': 
 688             self
.icon 
= wxIcon('bitmaps/mondrian.ico', wxBITMAP_TYPE_ICO
) 
 689             self
.SetIcon(self
.icon
) 
 691         self
.mainmenu 
= wxMenuBar() 
 693         menu
.Append(200, 'E&xit', 'Get the heck outta here!') 
 694         EVT_MENU(self
, 200, self
.OnFileExit
) 
 695         self
.mainmenu
.Append(menu
, '&File') 
 697         menu 
= self
.MakeTestsMenu() 
 698         self
.mainmenu
.Append(menu
, '&Tests') 
 699         self
.SetMenuBar(self
.mainmenu
) 
 701         self
.log 
= wxTextCtrl(self
, -1, '', wxDefaultPosition
, wxDefaultSize
, 
 702                               wxTE_MULTILINE|wxTE_READONLY
) 
 703         self
.log
.WriteText('Test 4:\n') 
 704         (w
, self
.charHeight
) = self
.log
.GetTextExtent('X') 
 707     def MakeTestsMenu(self
): 
 711         menu
.Append(mID
, '&Simple Controls') 
 712         EVT_MENU(self
, mID
, self
.OnTestSimpleControls
) 
 715         menu
.Append(mID
, '&Timer', '', true
) 
 716         EVT_MENU(self
, mID
, self
.OnTestTimer
) 
 721         menu
.Append(mID
, '&Layout Constraints') 
 722         EVT_MENU(self
, mID
, self
.OnTestLayoutConstraints
) 
 725         menu
.Append(mID
, '&Grid') 
 726         EVT_MENU(self
, mID
, self
.OnTestGrid
) 
 729         smenu 
= wxMenu()   # make a sub-menu 
 732         smenu
.Append(mID
, '&Colour') 
 733         EVT_MENU(self
, mID
, self
.OnTestColourDlg
) 
 736         smenu
.Append(mID
, '&Directory') 
 737         EVT_MENU(self
, mID
, self
.OnTestDirDlg
) 
 740         smenu
.Append(mID
, '&File') 
 741         EVT_MENU(self
, mID
, self
.OnTestFileDlg
) 
 744         smenu
.Append(mID
, '&Single Choice') 
 745         EVT_MENU(self
, mID
, self
.OnTestSingleChoiceDlg
) 
 748         smenu
.Append(mID
, '&TextEntry') 
 749         EVT_MENU(self
, mID
, self
.OnTestTextEntryDlg
) 
 752         smenu
.Append(mID
, '&Font') 
 753         EVT_MENU(self
, mID
, self
.OnTestFontDlg
) 
 756         smenu
.Append(mID
, '&PageSetup') 
 757         EVT_MENU(self
, mID
, self
.OnTestPageSetupDlg
) 
 760         smenu
.Append(mID
, '&Print') 
 761         EVT_MENU(self
, mID
, self
.OnTestPrintDlg
) 
 764         smenu
.Append(mID
, '&Message') 
 765         EVT_MENU(self
, mID
, self
.OnTestMessageDlg
) 
 768         menu
.AppendMenu(NewId(), '&Common Dialogs', smenu
) 
 772         menu
.Append(mID
, '&Notebook') 
 773         EVT_MENU(self
, mID
, self
.OnTestNotebook
) 
 776         menu
.Append(mID
, '&Splitter Window') 
 777         EVT_MENU(self
, mID
, self
.OnTestSplitter
) 
 780         menu
.Append(mID
, '&Custom StatusBar') 
 781         EVT_MENU(self
, mID
, self
.OnTestCustomStatusBar
) 
 784         menu
.Append(mID
, '&ToolBar') 
 785         EVT_MENU(self
, mID
, self
.OnTestToolBar
) 
 788         menu
.Append(mID
, 'T&ree Control') 
 789         EVT_MENU(self
, mID
, self
.OnTestTreeCtrl
) 
 792         menu
.Append(mID
, '&List Control') 
 793         EVT_MENU(self
, mID
, self
.OnTestListCtrl
) 
 796         menu
.Append(mID
, 'S&ash Window and Layout Algorithm') 
 797         EVT_MENU(self
, mID
, self
.OnTestSashWindow
) 
 804     def WriteText(self
, str): 
 805         self
.log
.WriteText(str) 
 806         if wxPlatform 
== '__WXMSW__': 
 807             w
, h 
= self
.log
.GetClientSizeTuple() 
 808             numLines 
= h
/self
.charHeight
 
 809             x
, y 
= self
.log
.PositionToXY(self
.log
.GetLastPosition()) 
 810             self
.log
.ShowPosition(self
.log
.XYToPosition(x
, y
-numLines
+1)) 
 812     def OnFileExit(self
, event
): 
 815     def OnCloseWindow(self
, event
): 
 821     def OnTestSimpleControls(self
, event
): 
 822         dlg 
= TestSimpleControlsDlg(self
, self
) 
 827     def OnTestTimer(self
, event
): 
 829             self
.mainmenu
.Check(self
.timerID
, false
) 
 833             self
.mainmenu
.Check(self
.timerID
, true
) 
 834             self
.timer 
= TestTimer(self
) 
 835             self
.timer
.Start(1000) 
 837     def OnTestLayoutConstraints(self
, event
): 
 838         win 
= TestLayoutConstraints(self
) 
 841     def OnTestGrid(self
, event
): 
 842         win 
= TestGrid(self
, self
) 
 844         win
.SetSize(wxSize(505, 300))  # have to force a resize, or the grid doesn't 
 845                                        # show up for some reason.... 
 847     def OnTestColourDlg(self
, event
): 
 848         data 
= wxColourData() 
 849         data
.SetChooseFull(true
) 
 850         dlg 
= wxColourDialog(self
, data
) 
 851         if dlg
.ShowModal() == wxID_OK
: 
 852             data 
= dlg
.GetColourData() 
 853             self
.log
.WriteText('You selected: %s\n' % str(data
.GetColour().Get())) 
 856     def OnTestDirDlg(self
, event
): 
 857         dlg 
= wxDirDialog(self
) 
 858         if dlg
.ShowModal() == wxID_OK
: 
 859             self
.log
.WriteText('You selected: %s\n' % dlg
.GetPath()) 
 862     def OnTestFileDlg(self
, event
): 
 863         dlg 
= wxFileDialog(self
, "Choose a file", ".", "", "*.*", wxOPEN
) 
 864         if dlg
.ShowModal() == wxID_OK
: 
 865             self
.log
.WriteText('You selected: %s\n' % dlg
.GetPath()) 
 868     def OnTestSingleChoiceDlg(self
, event
): 
 869         dlg 
= wxSingleChoiceDialog(self
, 'Test Single Choice', 'The Caption', 
 870                                    ['zero', 'one', 'two', 'three', 'four', 'five', 
 871                                     'six', 'seven', 'eight']) 
 872         if dlg
.ShowModal() == wxID_OK
: 
 873             self
.log
.WriteText('You selected: %s\n' % dlg
.GetStringSelection()) 
 876     def OnTestTextEntryDlg(self
, event
): 
 877         dlg 
= wxTextEntryDialog(self
, 'What is your favorite programming language?', 
 879         #dlg.SetValue("Python is the best!")  #### this doesn't work? 
 880         if dlg
.ShowModal() == wxID_OK
: 
 881             self
.log
.WriteText('You entered: %s\n' % dlg
.GetValue()) 
 885     def OnTestFontDlg(self
, event
): 
 886         dlg 
= wxFontDialog(self
) 
 887         if dlg
.ShowModal() == wxID_OK
: 
 888             data 
= dlg
.GetFontData() 
 889             font 
= data
.GetChosenFont() 
 890             self
.log
.WriteText('You selected: "%s", %d points, color %s\n' % 
 891                                (font
.GetFaceName(), font
.GetPointSize(), 
 892                                 data
.GetColour().Get())) 
 896     def OnTestPageSetupDlg(self
, event
): 
 897         data 
= wxPageSetupDialogData() 
 898         data
.SetMarginTopLeft(wxPoint(50,50)) 
 899         data
.SetMarginBottomRight(wxPoint(50,50)) 
 900         dlg 
= wxPageSetupDialog(self
, data
) 
 901         if dlg
.ShowModal() == wxID_OK
: 
 902             data 
= dlg
.GetPageSetupData() 
 903             tl 
= data
.GetMarginTopLeft() 
 904             br 
= data
.GetMarginBottomRight() 
 905             self
.log
.WriteText('Margins are: %s %s\n' % (str(tl
), str(br
))) 
 908     def OnTestPrintDlg(self
, event
): 
 909         data 
= wxPrintDialogData() 
 910         data
.EnablePrintToFile(true
) 
 911         data
.EnablePageNumbers(true
) 
 912         data
.EnableSelection(true
) 
 913         dlg 
= wxPrintDialog(self
, data
) 
 914         if dlg
.ShowModal() == wxID_OK
: 
 915             self
.log
.WriteText('\n') 
 918     def OnTestMessageDlg(self
, event
): 
 919         dlg 
= wxMessageDialog(self
, 'Hello from Python and wxWindows!', 
 920                               'A Message Box', wxOK | wxICON_INFORMATION
) 
 925     def OnTestNotebook(self
, event
): 
 926         win 
= TestNotebookWindow(self
, self
) 
 929     def OnTestSplitter(self
, event
): 
 930         win 
= TestSplitterWindow(self
) 
 933     def OnTestCustomStatusBar(self
, event
): 
 934         win 
= TestCustomStatusBar(self
) 
 937     def OnTestToolBar(self
, event
): 
 938         win 
= TestToolBar(self
, self
) 
 941     def OnTestTreeCtrl(self
, event
): 
 942         win 
= TestTreeCtrl(self
, self
) 
 945     def OnTestListCtrl(self
, event
): 
 946         win 
= TestListCtrl(self
, self
) 
 949     def OnTestSashWindow(self
, event
): 
 950         win 
= TestSashWindow(self
, self
) 
 953 #--------------------------------------------------------------------------- 
 958         frame 
= AppFrame(NULL
, -1, "Test 4: (lots of little tests...)") 
 960         self
.SetTopWindow(frame
) 
 963 #--------------------------------------------------------------------------- 
 976 # for focused testing... 
 980             frame 
= TestLayoutConstraints(NULL
) 
 982             self
.SetTopWindow(frame
) 
 994 if __name__ 
== '__main__': 
 998 #---------------------------------------------------------------------------- 
1001 # Revision 1.3  2000/10/30 21:05:22  robind 
1002 # Merged wxPython 2.2.2 over to the main branch 
1004 # Revision 1.1.2.1  2000/05/16 02:07:02  RD 
1006 # Moved and reorganized wxPython directories 
1008 # Now builds into an intermediate wxPython package directory before 
1011 # Revision 1.17  1999/08/05 05:06:50  RD 
1015 # Revision 1.16  1999/04/30 03:29:54  RD 
1017 # wxPython 2.0b9, first phase (win32) 
1018 # Added gobs of stuff, see wxPython/README.txt for details 
1020 # Revision 1.15.2.1  1999/03/16 06:05:50  RD 
1024 # Revision 1.15  1999/03/05 07:23:42  RD 
1026 # Minor wxPython changes for wxWin 2.0 
1028 # Revision 1.14  1999/02/27 04:20:50  RD 
1030 # minor tweaks for testing 
1032 # Revision 1.13  1999/02/20 09:04:44  RD 
1033 # Added wxWindow_FromHWND(hWnd) for wxMSW to construct a wxWindow from a 
1034 # window handle.  If you can get the window handle into the python code, 
1035 # it should just work...  More news on this later. 
1037 # Added wxImageList, wxToolTip. 
1039 # Re-enabled wxConfig.DeleteAll() since it is reportedly fixed for the 
1040 # wxRegConfig class. 
1042 # As usual, some bug fixes, tweaks, etc. 
1044 # Revision 1.12  1999/01/30 07:31:33  RD 
1046 # Added wxSashWindow, wxSashEvent, wxLayoutAlgorithm, etc. 
1048 # Various cleanup, tweaks, minor additions, etc. to maintain 
1049 # compatibility with the current wxWindows. 
1051 # Revision 1.11  1999/01/29 16:17:59  HH 
1052 # In test4's toolbar sample, changed NULL to wxNullBitmap to prevent SIGSEVS 
1053 # with wxGTK. The sample works now. 
1055 # Revision 1.10  1998/12/16 22:12:47  RD 
1057 # Tweaks needed to be able to build wxPython with wxGTK. 
1059 # Revision 1.9  1998/12/15 20:44:35  RD 
1060 # Changed the import semantics from "from wxPython import *" to "from 
1061 # wxPython.wx import *"  This is for people who are worried about 
1062 # namespace pollution, they can use "from wxPython import wx" and then 
1063 # prefix all the wxPython identifiers with "wx." 
1065 # Added wxTaskbarIcon for wxMSW. 
1067 # Made the events work for wxGrid. 
1071 # Added wxMiniFrame for wxGTK, (untested.) 
1073 # Changed many of the args and return values that were pointers to gdi 
1074 # objects to references to reflect changes in the wxWindows API. 
1076 # Other assorted fixes and additions. 
1078 # Revision 1.8  1998/11/25 08:47:11  RD 
1080 # Added wxPalette, wxRegion, wxRegionIterator, wxTaskbarIcon 
1081 # Added events for wxGrid 
1082 # Other various fixes and additions 
1084 # Revision 1.7  1998/11/11 03:13:19  RD 
1086 # Additions for wxTreeCtrl 
1088 # Revision 1.6  1998/10/20 06:45:33  RD 
1089 # New wxTreeCtrl wrappers (untested) 
1090 # some changes in helpers 
1093 # Revision 1.5  1998/10/02 06:42:28  RD 
1095 # Version 0.4 of wxPython for MSW. 
1097 # Revision 1.4  1998/08/27 21:59:51  RD 
1098 # Some chicken-and-egg problems solved for wxPython on wxGTK 
1100 # Revision 1.3  1998/08/27 00:01:17  RD 
1102 # - have discovered some problems but not yet discovered solutions... 
1104 # Revision 1.2  1998/08/22 19:51:18  RD 
1105 # some tweaks for wxGTK 
1107 # Revision 1.1  1998/08/09 08:28:05  RD