Thanks Robin,
I had looked for methods like this in the documentation that came with
wxPython (Start > All Programs > wxPython 2.4 for Python 2.2 > wxWindows
Reference) and didn't find them. The list of methods for wxListCtrl was
So my next question is: which documentation should I consult to find more
about the other goodies I might not know about?
Alain Désilets
···
-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Saturday, October 30, 2004 3:00 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Programmatic selection in wxListCtrl
Desilets, Alain wrote:
I am writing a wxListCtrl subclass with helper methods for unit
testing GUI that use list controls.Right now, I need methods to programmatically:
1. set the selected item in the list
2. query the list for its selected item
wx.ListCtrl already has some helper methods for doing things like this.
I've copied them below.
I have gotten 2. to work, but 1. doesn't. In the code below, when I
invoke DoSelectItem(), both SelectedItem() and DoSelectItem() print
-1. Yet, when I manually click on an item in the list, SelectedItem()
prints the correct item index.What am I doing wrong?
You aren't using the second parameter of SetItemState correctly.
def Select(self, idx, on=1):
'''[de]select an item'''
if on: state = wx.LIST_STATE_SELECTED
else: state = 0
self.SetItemState(idx, state, wx.LIST_STATE_SELECTED)
def Focus(self, idx):
'''Focus and show the given item'''
self.SetItemState(idx, wx.LIST_STATE_FOCUSED,
wx.LIST_STATE_FOCUSED)
self.EnsureVisible(idx)
def GetFocusedItem(self):
'''get the currently focused item or -1 if none'''
return self.GetNextItem(-1, wx.LIST_NEXT_ALL,
wx.LIST_STATE_FOCUSED)
def GetFirstSelected(self, *args):
'''return first selected item, or -1 when none'''
return self.GetNextSelected(-1)
def GetNextSelected(self, item):
'''return subsequent selected items, or -1 when no more'''
return self.GetNextItem(item, wx.LIST_NEXT_ALL,
wx.LIST_STATE_SELECTED)
def IsSelected(self, idx):
'''return True if the item is selected'''
return self.GetItemState(idx, wx.LIST_STATE_SELECTED) != 0
def SetColumnImage(self, col, image):
item = self.GetColumn(col)
# preserve all other attributes too
item.SetMask( wx.LIST_MASK_STATE |
wx.LIST_MASK_TEXT |
wx.LIST_MASK_IMAGE |
wx.LIST_MASK_DATA |
wx.LIST_SET_ITEM |
wx.LIST_MASK_WIDTH |
wx.LIST_MASK_FORMAT )
item.SetImage(image)
self.SetColumn(col, item)
def ClearColumnImage(self, col):
self.SetColumnImage(col, -1)
def Append(self, entry):
'''Append an item to the list control. The entry parameter
should be a
sequence with an item for each column'''
if len(entry):
if wx.USE_UNICODE:
cvtfunc = unicode
else:
cvtfunc = str
pos = self.GetItemCount()
self.InsertStringItem(pos, cvtfunc(entry[0]))
for i in range(1, len(entry)):
self.SetStringItem(pos, i, cvtfunc(entry[i]))
return pos
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org