]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxPython/tests/test4.py
New DnD and Clipboard code
[wxWidgets.git] / utils / wxPython / tests / test4.py
index e9e4b3745e96fec5089f9bfbeb4c8b34a60082a5..564edb31595b8d3916439c671da489f6341818cc 100644 (file)
@@ -12,7 +12,7 @@
 #----------------------------------------------------------------------------
 
 
-from wxPython import *
+from wxPython.wx import *
 
 import time
 
@@ -36,14 +36,14 @@ class TestSimpleControlsDlg(wxDialog):
         EVT_TEXT(self, 10, self.EvtText)
         y_pos = y_pos + delta
 
-        wxCheckBox(self, 20, "wxCheckBox", wxPoint(80, y_pos), wxSize(150, 20))
+        wxCheckBox(self, 20, "wxCheckBox", wxPoint(80, y_pos), wxSize(150, 20), wxNO_BORDER)
         EVT_CHECKBOX(self, 20, self.EvtCheckBox)
         y_pos = y_pos + delta
 
         rb = wxRadioBox(self, 30, "wxRadioBox", wxPoint(80, y_pos), wxPyDefaultSize,
-                        sampleList, 3, wxRA_HORIZONTAL)
+                        sampleList, 3, wxRA_HORIZONTAL| wxNO_BORDER)
         EVT_RADIOBOX(self, 30, self.EvtRadioBox)
-        width, height = rb.GetSize()
+        width, height = rb.GetSizeTuple()
         y_pos = y_pos + height + 5
 
         wxStaticText(self, -1, "wxChoice", wxPoint(5, y_pos), wxSize(75, 20))
@@ -64,7 +64,7 @@ class TestSimpleControlsDlg(wxDialog):
         EVT_LISTBOX(self, 60, self.EvtListBox)
         EVT_LISTBOX_DCLICK(self, 60, self.EvtListBoxDClick)
         lb.SetSelection(0)
-        width, height = lb.GetSize()
+        width, height = lb.GetSizeTuple()
         y_pos = y_pos + height + 5
 
 
@@ -197,9 +197,10 @@ class TestLayoutConstraints(wxFrame):
 #---------------------------------------------------------------------------
 
 class TestGrid(wxFrame):
-    def __init__(self, parent):
+    def __init__(self, parent, log):
         wxFrame.__init__(self, parent, -1, 'Test Grid',
                          wxPyDefaultPosition, wxSize(500, 300))
+        self.log = log
 
         grid = wxGrid(self, -1)
 
@@ -215,10 +216,27 @@ class TestGrid(wxFrame):
         grid.UpdateDimensions()
         grid.AdjustScrollbars()
 
+        EVT_GRID_SELECT_CELL(grid, self.OnSelectCell)
+        EVT_GRID_CELL_CHANGE(grid, self.OnCellChange)
+        EVT_GRID_CELL_LCLICK(grid, self.OnCellClick)
+        EVT_GRID_LABEL_LCLICK(grid, self.OnLabelClick)
+
+
 
     def OnCloseWindow(self, event):
         self.Destroy()
 
+    def OnSelectCell(self, event):
+        self.log.WriteText("OnSelectCell: (%d, %d)\n" % (event.m_row, event.m_col))
+
+    def OnCellChange(self, event):
+        self.log.WriteText("OnCellChange: (%d, %d)\n" % (event.m_row, event.m_col))
+
+    def OnCellClick(self, event):
+        self.log.WriteText("OnCellClick: (%d, %d)\n" % (event.m_row, event.m_col))
+
+    def OnLabelClick(self, event):
+        self.log.WriteText("OnLabelClick: (%d, %d)\n" % (event.m_row, event.m_col))
 
 #---------------------------------------------------------------------------
 
@@ -231,7 +249,7 @@ class ColoredPanel(wxWindow):
 
 
 class TestNotebookWindow(wxFrame):
-    def __init__(self, parent):
+    def __init__(self, parent, log):
         wxFrame.__init__(self, parent, -1, 'Test wxNotebook',
                          wxPyDefaultPosition, wxPyDefaultSize)
 
@@ -239,9 +257,19 @@ class TestNotebookWindow(wxFrame):
 
         win = ColoredPanel(nb, wxBLUE)
         nb.AddPage(win, "Blue")
-        st = wxStaticText(win, -1, "You can put any type of window here!", wxPoint(10, 10))
+        st = wxStaticText(win, -1,
+                          "You can put nearly any type of window here!",
+                          wxPoint(10, 10))
         st.SetForegroundColour(wxWHITE)
         st.SetBackgroundColour(wxBLUE)
+        st = wxStaticText(win, -1,
+                          "Check the next tab for an example...",
+                          wxPoint(10, 30))
+        st.SetForegroundColour(wxWHITE)
+        st.SetBackgroundColour(wxBLUE)
+
+        win = TestTreeCtrlPanel(nb, log)
+        nb.AddPage(win, "TreeCtrl")
 
         win = ColoredPanel(nb, wxRED)
         nb.AddPage(win, "Red")
@@ -266,7 +294,7 @@ class TestNotebookWindow(wxFrame):
 
 
         nb.SetSelection(0)
-        self.SetSize(wxSize(300, 300))  # force a redraw so the notebook will draw
+        self.SetSize(wxSize(350, 300))  # force a redraw so the notebook will draw
 
 
     def OnCloseWindow(self, event):
@@ -337,6 +365,7 @@ class CustomStatusBar(wxStatusBar):
     # reposition the checkbox
     def OnSize(self, event):
         rect = self.GetFieldRect(1)
+        print "%s, %s" % (rect.x, rect.y)
         self.cb.SetPosition(wxPoint(rect.x+2, rect.y+2))
         self.cb.SetSize(wxSize(rect.width-4, rect.height-4))
 
@@ -346,7 +375,7 @@ class TestCustomStatusBar(wxFrame):
     def __init__(self, parent):
         wxFrame.__init__(self, parent, -1, 'Test Custom StatusBar',
                          wxPyDefaultPosition, wxSize(500, 300))
-        wxWindow(self, -1)
+        wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
 
         self.sb = CustomStatusBar(self)
         self.SetStatusBar(self.sb)
@@ -364,9 +393,9 @@ class TestToolBar(wxFrame):
                          wxPyDefaultPosition, wxSize(500, 300))
         self.log = log
 
-        wxWindow(self, -1)
+        wxWindow(self, -1).SetBackgroundColour(wxNamedColour("WHITE"))
 
-        tb = self.CreateToolBar()
+        tb = self.CreateToolBar(wxTB_HORIZONTAL|wxNO_BORDER)
         #tb = wxToolBar(self, -1, wxPyDefaultPosition, wxPyDefaultSize,
         #               wxTB_HORIZONTAL | wxNO_BORDER | wxTB_FLAT)
         #self.SetToolBar(tb)
@@ -418,6 +447,56 @@ class TestToolBar(wxFrame):
         self.log.WriteText("tool %s right-clicked\n" % event.GetId())
 
 
+#---------------------------------------------------------------------------
+
+class TestTreeCtrlPanel(wxPanel):
+    def __init__(self, parent, log):
+        wxPanel.__init__(self, parent, -1)
+
+        self.log = log
+        tID = 1101
+
+        self.tree = wxTreeCtrl(self, tID)
+        root = self.tree.AddRoot("The Root Item")
+        for x in range(10):
+            child = self.tree.AppendItem(root, "Item %d" % x)
+            for y in range(5):
+                last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y)))
+
+        self.tree.Expand(root)
+        EVT_TREE_ITEM_EXPANDED  (self, tID, self.OnItemExpanded)
+        EVT_TREE_ITEM_COLLAPSED (self, tID, self.OnItemCollapsed)
+        EVT_TREE_SEL_CHANGED    (self, tID, self.OnSelChanged)
+
+
+    def OnSize(self, event):
+        w,h = self.GetClientSizeTuple()
+        self.tree.SetDimensions(0, 0, w, h)
+
+
+    def OnItemExpanded(self, event):
+        item = event.GetItem()
+        self.log.WriteText("OnItemExpanded: %s\n" % self.tree.GetItemText(item))
+
+    def OnItemCollapsed(self, event):
+        item = event.GetItem()
+        self.log.WriteText("OnItemCollapsed: %s\n" % self.tree.GetItemText(item))
+
+    def OnSelChanged(self, event):
+        item = event.GetItem()
+        self.log.WriteText("OnSelChanged: %s\n" % self.tree.GetItemText(item))
+
+
+
+
+class TestTreeCtrl(wxFrame):
+    def __init__(self, parent, log):
+        wxFrame.__init__(self, parent, -1, 'Test TreeCtrl',
+                         wxPyDefaultPosition, wxSize(250, 300))
+
+        p = TestTreeCtrlPanel(self, log)
+
+
 #---------------------------------------------------------------------------
 #---------------------------------------------------------------------------
 #---------------------------------------------------------------------------
@@ -526,6 +605,10 @@ class AppFrame(wxFrame):
         menu.Append(mID, '&ToolBar')
         EVT_MENU(self, mID, self.OnTestToolBar)
 
+        mID = NewId()
+        menu.Append(mID, 'T&ree Control')
+        EVT_MENU(self, mID, self.OnTestTreeCtrl)
+
         return menu
 
 
@@ -534,7 +617,7 @@ class AppFrame(wxFrame):
     def WriteText(self, str):
         self.log.WriteText(str)
         if wxPlatform == '__WXMSW__':
-            w, h = self.log.GetClientSize()
+            w, h = self.log.GetClientSizeTuple()
             numLines = h/self.charHeight
             x, y = self.log.PositionToXY(self.log.GetLastPosition())
             self.log.ShowPosition(self.log.XYToPosition(x, y-numLines+1))
@@ -569,7 +652,7 @@ class AppFrame(wxFrame):
         win.Show(true)
 
     def OnTestGrid(self, event):
-        win = TestGrid(self)
+        win = TestGrid(self, self)
         win.Show(true)
         win.SetSize(wxSize(505, 300))  # have to force a resize, or the grid doesn't
                                        # show up for some reason....
@@ -653,7 +736,7 @@ class AppFrame(wxFrame):
 
 
     def OnTestNotebook(self, event):
-        win = TestNotebookWindow(self)
+        win = TestNotebookWindow(self, self)
         win.Show(true)
 
     def OnTestSplitter(self, event):
@@ -668,6 +751,10 @@ class AppFrame(wxFrame):
         win = TestToolBar(self, self)
         win.Show(true)
 
+    def OnTestTreeCtrl(self, event):
+        win = TestTreeCtrl(self, self)
+        win.Show(true)
+
 
 #---------------------------------------------------------------------------
 
@@ -717,7 +804,45 @@ if __name__ == '__main__':
 #----------------------------------------------------------------------------
 #
 # $Log$
+# Revision 1.10  1998/12/16 22:12:47  RD
+# Tweaks needed to be able to build wxPython with wxGTK.
+#
+# Revision 1.9  1998/12/15 20:44:35  RD
+# Changed the import semantics from "from wxPython import *" to "from
+# wxPython.wx import *"  This is for people who are worried about
+# namespace pollution, they can use "from wxPython import wx" and then
+# prefix all the wxPython identifiers with "wx."
+#
+# Added wxTaskbarIcon for wxMSW.
+#
+# Made the events work for wxGrid.
+#
+# Added wxConfig.
+#
+# Added wxMiniFrame for wxGTK, (untested.)
+#
+# Changed many of the args and return values that were pointers to gdi
+# objects to references to reflect changes in the wxWindows API.
+#
+# Other assorted fixes and additions.
+#
+# Revision 1.8  1998/11/25 08:47:11  RD
+#
+# Added wxPalette, wxRegion, wxRegionIterator, wxTaskbarIcon
+# Added events for wxGrid
+# Other various fixes and additions
+#
+# Revision 1.7  1998/11/11 03:13:19  RD
+#
+# Additions for wxTreeCtrl
+#
+# Revision 1.6  1998/10/20 06:45:33  RD
+# New wxTreeCtrl wrappers (untested)
+# some changes in helpers
+# etc.
+#
 # Revision 1.5  1998/10/02 06:42:28  RD
+#
 # Version 0.4 of wxPython for MSW.
 #
 # Revision 1.4  1998/08/27 21:59:51  RD