]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxPython/demo/wxListCtrl.py
Fixed bug in DnD. wxDragSource will now delete itself when done.
[wxWidgets.git] / utils / wxPython / demo / wxListCtrl.py
index a3d4daed82d9f9513b7a1efdd489546d97a7630e..7fe5c5387aaf97ea3f6077f66c2f96bb093dadf9 100644 (file)
@@ -39,11 +39,81 @@ class TestListCtrlPanel(wxPanel):
             self.list.InsertImageStringItem(x, "This is item %d" % x, idx1)
             self.list.SetStringItem(x, 1, "Col 1, item %d" % x)
             self.list.SetStringItem(x, 2, "item %d in column 2" % x)
             self.list.InsertImageStringItem(x, "This is item %d" % x, idx1)
             self.list.SetStringItem(x, 1, "Col 1, item %d" % x)
             self.list.SetStringItem(x, 2, "item %d in column 2" % x)
+            self.list.SetItemData(x, x*2)
 
         self.list.SetColumnWidth(0, wxLIST_AUTOSIZE)
         self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
         self.list.SetColumnWidth(2, wxLIST_AUTOSIZE)
 
 
         self.list.SetColumnWidth(0, wxLIST_AUTOSIZE)
         self.list.SetColumnWidth(1, wxLIST_AUTOSIZE)
         self.list.SetColumnWidth(2, wxLIST_AUTOSIZE)
 
+        self.list.SetItemState(5, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED)
+
+        self.currentItem = 0
+        EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected)
+        EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete)
+        EVT_LEFT_DCLICK(self.list, self.OnDoubleClick)
+        EVT_RIGHT_DOWN(self.list, self.OnRightDown)
+
+        # for wxMSW
+        EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick)
+
+        # for wxGTK
+        EVT_RIGHT_UP(self.list, self.OnRightClick)
+
+
+    def OnRightDown(self, event):
+        self.x = event.GetX()
+        self.y = event.GetY()
+        self.log.WriteText("x, y = %s\n" % str((self.x, self.y)))
+        event.Skip()
+
+    def OnItemSelected(self, event):
+        self.currentItem = event.m_itemIndex
+        self.log.WriteText("OnItemSelected: %s\n" % self.list.GetItemText(self.currentItem))
+
+    def OnItemDelete(self, event):
+        self.log.WriteText("OnItemDelete\n")
+
+
+    def OnDoubleClick(self, event):
+        self.log.WriteText("OnDoubleClick item %s\n" % self.list.GetItemText(self.currentItem))
+
+
+    def OnRightClick(self, event):
+        self.log.WriteText("OnRightClick %s\n" % self.list.GetItemText(self.currentItem))
+        menu = wxMenu()
+        tPopupID1 = 0
+        tPopupID2 = 1
+        tPopupID3 = 2
+        tPopupID4 = 3
+        tPopupID5 = 5
+        menu.Append(tPopupID1, "One")
+        menu.Append(tPopupID2, "Two")
+        menu.Append(tPopupID3, "Three")
+        menu.Append(tPopupID4, "DeleteAllItems")
+        menu.Append(tPopupID5, "GetItem")
+        EVT_MENU(self, tPopupID1, self.OnPopupOne)
+        EVT_MENU(self, tPopupID2, self.OnPopupTwo)
+        EVT_MENU(self, tPopupID3, self.OnPopupThree)
+        EVT_MENU(self, tPopupID4, self.OnPopupFour)
+        EVT_MENU(self, tPopupID5, self.OnPopupFive)
+        self.PopupMenu(menu, wxPoint(self.x, self.y))
+        menu.Destroy()
+
+    def OnPopupOne(self, event):
+        self.log.WriteText("Popup one\n")
+
+    def OnPopupTwo(self, event):
+        self.log.WriteText("Popup two\n")
+
+    def OnPopupThree(self, event):
+        self.log.WriteText("Popup three\n")
+
+    def OnPopupFour(self, event):
+        self.list.DeleteAllItems()
+
+    def OnPopupFive(self, event):
+        item = self.list.GetItem(self.currentItem)
+        print item.m_text, item.m_itemId, self.list.GetItemData(self.currentItem)
 
     def OnSize(self, event):
         w,h = self.GetClientSizeTuple()
 
     def OnSize(self, event):
         w,h = self.GetClientSizeTuple()
@@ -52,6 +122,8 @@ class TestListCtrlPanel(wxPanel):
 
 
 
 
 
 
+
+
 #---------------------------------------------------------------------------
 
 def runTest(frame, nb, log):
 #---------------------------------------------------------------------------
 
 def runTest(frame, nb, log):