X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6d19860fe80bf06f3737d4ca04173c96f2f3a3ea..830efc9b0cb87eae22d4435af7858175017522ab:/wxPython/demo/wxListCtrl.py diff --git a/wxPython/demo/wxListCtrl.py b/wxPython/demo/wxListCtrl.py index f5fad6d8ed..d1b9cf245f 100644 --- a/wxPython/demo/wxListCtrl.py +++ b/wxPython/demo/wxListCtrl.py @@ -1,4 +1,3 @@ -#!/bin/env python #---------------------------------------------------------------------------- # Name: ListCtrl.py # Purpose: Testing lots of stuff, controls, window types, etc. @@ -12,7 +11,7 @@ #---------------------------------------------------------------------------- from wxPython.wx import * -from wxPython.lib.mixins.listctrl import wxColumnSorterMixin +from wxPython.lib.mixins.listctrl import wxColumnSorterMixin, wxListCtrlAutoWidthMixin #--------------------------------------------------------------------------- @@ -56,10 +55,34 @@ musicdata = { 37: ("Spyro Gyra", "Song for Lorraine", "Jazz"), 38: ("Yes", "Owner Of A Lonely Heart", "Rock"), 39: ("Yes", "Rhythm Of Love", "Rock"), +40: ("Cusco", "Dream Catcher", "New Age"), +41: ("Cusco", "Geronimos Laughter", "New Age"), +42: ("Cusco", "Ghost Dance", "New Age"), +43: ("Blue Man Group", "Drumbone", "New Age"), +44: ("Blue Man Group", "Endless Column", "New Age"), +45: ("Blue Man Group", "Klein Mandelbrot", "New Age"), +46: ("Kenny G", "Silhouette", "Jazz"), +47: ("Sade", "Smooth Operator", "Jazz"), +48: ("David Arkenstone", "Papillon (On The Wings Of The Butterfly)", "New Age"), +49: ("David Arkenstone", "Stepping Stars", "New Age"), +50: ("David Arkenstone", "Carnation Lily Lily Rose", "New Age"), +51: ("David Lanz", "Behind The Waterfall", "New Age"), +52: ("David Lanz", "Cristofori's Dream", "New Age"), +53: ("David Lanz", "Heartsounds", "New Age"), +54: ("David Lanz", "Leaves on the Seine", "New Age"), } import images + +class TestListCtrl(wxListCtrl, wxListCtrlAutoWidthMixin): + def __init__(self, parent, ID, pos=wxDefaultPosition, + size=wxDefaultSize, style=0): + wxListCtrl.__init__(self, parent, ID, pos, size, style) + wxListCtrlAutoWidthMixin.__init__(self) + + + class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): def __init__(self, parent, log): wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS) @@ -68,24 +91,24 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): tID = wxNewId() self.il = wxImageList(16, 16) - bmp = images.getSmilesBitmap() - #idx1 = self.il.AddWithColourMask(bmp, wxWHITE) - idx1 = self.il.Add(bmp) - bmp = images.getSmallUpArrowBitmap() - self.sm_up = self.il.Add(bmp) - bmp = images.getSmallDnArrowBitmap() - self.sm_dn = self.il.Add(bmp) + idx1 = self.il.Add(images.getSmilesBitmap()) + self.sm_up = self.il.Add(images.getSmallUpArrowBitmap()) + self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap()) + + #idx1 = self.il.AddIcon(wxIconFromXPMData(images.getSmilesData())) + #self.sm_up = self.il.AddIcon(wxIconFromXPMData(images.getSmallUpArrowData())) + #self.sm_dn = self.il.AddIcon(wxIconFromXPMData(images.getSmallDnArrowData())) - self.list = wxListCtrl(self, tID, + self.list = TestListCtrl(self, tID, style=wxLC_REPORT|wxSUNKEN_BORDER)#|wxLC_VRULES|wxLC_HRULES) self.list.SetImageList(self.il, wxIMAGE_LIST_SMALL) # Why doesn't this show up on MSW??? - self.list.SetToolTip(wxToolTip("This is a ToolTip!")) + #self.list.SetToolTip(wxToolTip("This is a ToolTip!")) if 0: - # for normal simple columns, you can add them like this: + # for normal, simple columns, you can add them like this: self.list.InsertColumn(0, "Artist") self.list.InsertColumn(1, "Title", wxLIST_FORMAT_RIGHT) self.list.InsertColumn(2, "Genre") @@ -107,6 +130,7 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): self.list.InsertColumnInfo(2, info) + items = musicdata.items() for x in range(len(items)): key, data = items[x] @@ -123,6 +147,7 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): self.list.SetColumnWidth(0, wxLIST_AUTOSIZE) self.list.SetColumnWidth(1, wxLIST_AUTOSIZE) + self.list.SetColumnWidth(2, 100) # show how to select an item self.list.SetItemState(5, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED) @@ -138,6 +163,7 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): self.currentItem = 0 EVT_SIZE(self, self.OnSize) EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected) + EVT_LIST_ITEM_DESELECTED(self, tID, self.OnItemDeselected) EVT_LIST_ITEM_ACTIVATED(self, tID, self.OnItemActivated) EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete) EVT_LIST_COL_CLICK(self, tID, self.OnColClick) @@ -170,6 +196,7 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): self.x = event.GetX() self.y = event.GetY() self.log.WriteText("x, y = %s\n" % str((self.x, self.y))) + print event.GetEventObject() event.Skip() @@ -191,6 +218,13 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): # this does self.list.SetItemState(10, 0, wxLIST_STATE_SELECTED) + # Show how to reselect something we don't want deselected + def OnItemDeselected(self, evt): + item = evt.GetItem() + if evt.m_itemIndex == 11: + wxCallAfter(self.list.SetItemState, 11, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED) + + def OnItemActivated(self, event): self.currentItem = event.m_itemIndex self.log.WriteText("OnItemActivated: %s\n" % self.list.GetItemText(self.currentItem)) @@ -202,10 +236,17 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): self.log.WriteText("OnColClick: %d\n" % event.GetColumn()) def OnColRightClick(self, event): - self.log.WriteText("OnColRightClick: %d\n" % event.GetColumn()) + item = self.list.GetColumn(event.GetColumn()) + self.log.WriteText("OnColRightClick: %d %s\n" % + (event.GetColumn(), (item.GetText(), item.GetAlign(), + item.GetWidth(), item.GetImage()))) def OnColBeginDrag(self, event): self.log.WriteText("OnColBeginDrag\n") + ## Show how to not allow a column to be resized + #if event.GetColumn() == 0: + # event.Veto() + def OnColDragging(self, event): self.log.WriteText("OnColDragging\n") @@ -225,9 +266,12 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): tPopupID3 = 2 tPopupID4 = 3 tPopupID5 = 5 - #menu.Append(tPopupID1, "One") + + # Show how to put an icon in the menu item = wxMenuItem(menu, tPopupID1,"One") - item.SetBitmap(images.getSmilesBitmap()) + if wxPlatform == '__WXMSW__': + item.SetBitmap(images.getSmilesBitmap()) + menu.AppendItem(item) menu.Append(tPopupID2, "Two") menu.Append(tPopupID3, "Three") @@ -244,6 +288,8 @@ class TestListCtrlPanel(wxPanel, wxColumnSorterMixin): def OnPopupOne(self, event): self.log.WriteText("Popup one\n") + print "FindItem:", self.list.FindItem(-1, "Roxette") + print "FindItemData:", self.list.FindItemData(-1, 11) def OnPopupTwo(self, event): self.log.WriteText("Popup two\n") @@ -278,19 +324,17 @@ def runTest(frame, nb, log): +overview = """\ +A list control presents lists in a number of formats: list view, report view, icon view and small icon view. Elements are numbered from zero. +""" +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])]) - - - - - -overview = """\ -A list control presents lists in a number of formats: list view, report view, icon view and small icon view. Elements are numbered from zero. - -"""