]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/ListCtrl.py
The great wxVScrolledWindow refactoring: allow using it both horizontal and
[wxWidgets.git] / wxPython / demo / ListCtrl.py
index b46bc3d87ab0332c166e18c00c462dc453cc37c6..c766332fe9a7f00a408f5a936cc26f55b4f0915a 100644 (file)
@@ -10,6 +10,7 @@
 # Licence:      wxWindows license
 #----------------------------------------------------------------------------
 
+import sys
 import  wx
 import  wx.lib.mixins.listctrl  as  listmix
 
@@ -89,7 +90,17 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
 
         self.log = log
         tID = wx.NewId()
-
+        
+        sizer = wx.BoxSizer(wx.VERTICAL)
+        
+        if wx.Platform == "__WXMAC__" and \
+               hasattr(wx.GetApp().GetTopWindow(), "LoadDemo"):
+            self.useNative = wx.CheckBox(self, -1, "Use native listctrl")
+            self.useNative.SetValue( 
+                not wx.SystemOptions.GetOptionInt("mac.listctrl.always_use_generic") )
+            self.Bind(wx.EVT_CHECKBOX, self.OnUseNative, self.useNative)
+            sizer.Add(self.useNative, 0, wx.ALL | wx.ALIGN_RIGHT, 4)
+            
         self.il = wx.ImageList(16, 16)
 
         self.idx1 = self.il.Add(images.getSmilesBitmap())
@@ -98,23 +109,29 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
 
         self.list = TestListCtrl(self, tID,
                                  style=wx.LC_REPORT 
-                                 | wx.SUNKEN_BORDER
+                                 #| wx.BORDER_SUNKEN
+                                 | wx.BORDER_NONE
                                  | wx.LC_EDIT_LABELS
-                                 #| wxLC_NO_HEADER
-                                 #| wxLC_VRULES | wxLC_HRULES
+                                 | wx.LC_SORT_ASCENDING
+                                 #| wx.LC_NO_HEADER
+                                 #| wx.LC_VRULES
+                                 #| wx.LC_HRULES
+                                 #| wx.LC_SINGLE_SEL
                                  )
-
+        
         self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL)
+        sizer.Add(self.list, 1, wx.EXPAND)
 
         self.PopulateList()
 
         # Now that the list exists we can init the other base class,
-        # see wxPython/lib/mixins/listctrl.py
+        # see wx/lib/mixins/listctrl.py
         self.itemDataMap = musicdata
         listmix.ColumnSorterMixin.__init__(self, 3)
         #self.SortListItems(0, True)
 
-        self.Bind(wx.EVT_SIZE, self.OnSize)
+        self.SetSizer(sizer)
+        self.SetAutoLayout(True)
 
         self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list)
         self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.list)
@@ -137,6 +154,10 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
         self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
 
 
+    def OnUseNative(self, event):
+        wx.SystemOptions.SetOptionInt("mac.listctrl.always_use_generic", not event.IsChecked())
+        wx.GetApp().GetTopWindow().LoadDemo("ListCtrl")
+
     def PopulateList(self):
         if 0:
             # for normal, simple columns, you can add them like this:
@@ -161,12 +182,11 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
             self.list.InsertColumnInfo(2, info)
 
         items = musicdata.items()
-        for x in range(len(items)):
-            key, data = items[x]
-            self.list.InsertImageStringItem(x, data[0], self.idx1)
-            self.list.SetStringItem(x, 1, data[1])
-            self.list.SetStringItem(x, 2, data[2])
-            self.list.SetItemData(x, key)
+        for key, data in items:
+            index = self.list.InsertImageStringItem(sys.maxint, data[0], self.idx1)
+            self.list.SetStringItem(index, 1, data[1])
+            self.list.SetStringItem(index, 2, data[2])
+            self.list.SetItemData(index, key)
 
         self.list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
         self.list.SetColumnWidth(1, wx.LIST_AUTOSIZE)
@@ -186,22 +206,22 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
         self.currentItem = 0
 
 
-    # Used by the ColumnSorterMixin, see wxPython/lib/mixins/listctrl.py
+    # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
     def GetListCtrl(self):
         return self.list
 
-    # Used by the ColumnSorterMixin, see wxPython/lib/mixins/listctrl.py
+    # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
     def GetSortImages(self):
         return (self.sm_dn, self.sm_up)
 
 
     def OnRightDown(self, event):
-        self.x = event.GetX()
-        self.y = event.GetY()
-        self.log.WriteText("x, y = %s\n" % str((self.x, self.y)))
-        item, flags = self.list.HitTest((self.x, self.y))
+        x = event.GetX()
+        y = event.GetY()
+        self.log.WriteText("x, y = %s\n" % str((x, y)))
+        item, flags = self.list.HitTest((x, y))
 
-        if flags & wx.LIST_HITTEST_ONITEM:
+        if item != wx.NOT_FOUND and flags & wx.LIST_HITTEST_ONITEM:
             self.list.Select(item)
 
         event.Skip()
@@ -309,7 +329,7 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
 
         # Popup the menu.  If an item is selected then its handler
         # will be called before PopupMenu returns.
-        self.PopupMenu(menu, (self.x, self.y))
+        self.PopupMenu(menu)
         menu.Destroy()
 
 
@@ -342,12 +362,6 @@ class TestListCtrlPanel(wx.Panel, listmix.ColumnSorterMixin):
         self.list.EditLabel(self.currentItem)
 
 
-    def OnSize(self, event):
-        w,h = self.GetClientSizeTuple()
-        self.list.SetDimensions(0, 0, w, h)
-
-
-
 #---------------------------------------------------------------------------
 
 def runTest(frame, nb, log):