EVT_LIST_ITEM_DESELECTED doesn't fire

I’m trying to use wxListCtrl in my application, following the example in the demo. I’m running wxPython 2.3.3.1 on Python 2.2.1, on WinXP. In the demo (and my own code), I’m unable to trigger the EVT_LIST_ITEM_DESELECTED event. I would expect it to fire e.g. when clicking row 1 (EVT_LIST_ITEM_SELECTED), then row 2 (EVT_LIST_ITEM_DESELECTED on row 1, EVT_LIST_ITEM_SELECTED on row 2). Also when ctrl-clicking several rows to select them, then ctrl-clicking one of them to deselect. The GUI shows what I would expect, but the event never fires. Any help hugely appreciated!

In another matter related to the wxListCtrl and the demo, I got the mixin working (thanks to help from the list), but the arrow icons aren’t working for me. I’ve copied the following lines from the demo:

    self.il = wxImageList(16, 16)
    self.sm_up = self.il.Add(images.getSmallUpArrowBitmap())
    self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap())

self.il.Add() results in an assert dialog due to “invalid image”. Any thoughts? I’m afraid I’m pretty well out of my depth, here.

Thanks,

John Hopkins

···

John Hopkins wrote:

I'm trying to use wxListCtrl in my application, following the example in the demo. I'm running wxPython 2.3.3.1 on Python 2.2.1, on WinXP. In the demo (and my own code), I'm unable to trigger the EVT_LIST_ITEM_DESELECTED event. I would expect it to fire e.g. when clicking row 1 (EVT_LIST_ITEM_SELECTED), then row 2 (EVT_LIST_ITEM_DESELECTED on row 1, EVT_LIST_ITEM_SELECTED on row 2). Also when ctrl-clicking several rows to select them, then ctrl-clicking one of them to deselect. The GUI shows what I would expect, but the event never fires. Any help hugely appreciated!

Hmm... Works for me. I updated the demo to wrte a log message in OnItemDeselected, (not sure why it wasn't already,) then played with it a bit and got this:

[C:\projects\wx\wxPython\demo] wxListCtrl.py
16:34:20: OnItemDeselected: 5
16:34:20: OnItemSelected: 19, Billy Joel, Lullabye (Goodnight, My Angel), Rock
16:34:22: OnItemSelected: 12, Sinead O'Connor, Nothing Compares 2 U, Rock
16:34:22: OnItemSelected: 13, Stevie B., Because I Love You, Rock
16:34:22: OnItemSelected: 14, Taylor Dayne, Love Will Lead You Back, Rock
16:34:22: OnItemSelected: 15, The Bangles, Eternal Flame, Rock
16:34:22: OnItemSelected: 16, Wilson Phillips, Release Me, Rock
16:34:22: OnItemSelected: 17, Billy Joel, Blonde Over Blue, Rock
16:34:22: OnItemSelected: 18, Billy Joel, Famous Last Words, Rock
16:34:25: OnItemDeselected: 15
16:34:28: OnItemDeselected: 18
16:34:30: OnItemDeselected: 12
16:34:30: OnItemDeselected: 13
16:34:30: OnItemDeselected: 14
16:34:30: OnItemDeselected: 16
16:34:30: OnItemDeselected: 17
16:34:30: OnItemDeselected: 19
16:34:30: OnItemSelected: 22, Janet Jackson, Alright, Rock

I have Win2k. Maybe WinXP's version of the common controls is broken, (or microsoft "enhanced" it in a non-backwards compatible way...)

In another matter related to the wxListCtrl and the demo, I got the mixin working (thanks to help from the list), but the arrow icons aren't working for me. I've copied the following lines from the demo:
        self.il = wxImageList(16, 16)
        self.sm_up = self.il.Add(images.getSmallUpArrowBitmap())
        self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap())
self.il.Add() results in an assert dialog due to "invalid image".

What do you get for these?

  print images.getSmallUpArrowBitmap().Ok()
  print images.getSmallDnArrowBitmap().Ok()

Do you call wxInitAllImageHandlers() when your app starts up?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Do you call wxInitAllImageHandlers() when your app starts up?

Thanks, that was the key. That wasn't in the demo pane, of course, and I
didn't know enough to look for it ...

Now I more questions. The following code snippets result in a list control
that does just what I want (and sorts 1200 rows quite quickly -- I LOVE
Python/wxPython!), except the UpArrow icon appears in the first column of
each row, where the "smiley" is in the demo. I can't figure out why, since
I'm using InsertStringItem rather than InsertImageStringItem() for that
column. Is this maybe a default behavior, and can I turn it off?

Also, the up/dn icons appear on the left of the text in the first column,
but on the right on subsequent columns both on my list and the demo. Is
that locked-in, or can I change it for better alignment between titles and
data?

Thanks again,

John Hopkins

        self.il = wxImageList(16, 16)
        self.sm_up = self.il.Add(images.getSmallUpArrowBitmap())
        self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap())

        self.ClientList = wxListCtrl(panel, 200, wxPoint(100, 35),
wxSize(450, 200),
                                     style=wxLC_REPORT|wxSUNKEN_BORDER)
        self.ClientList.SetImageList(self.il, wxIMAGE_LIST_SMALL)

        info = wxListItem()
        info.m_mask = wxLIST_MASK_TEXT | wxLIST_MASK_IMAGE |
wxLIST_MASK_FORMAT
        info.m_image = -1
        info.m_format = wxLIST_FORMAT_LEFT
        info.m_text = "Name"
        self.ClientList.InsertColumnInfo(0, info)

        info.m_text = "Birth Date"
        self.ClientList.InsertColumnInfo(1, info)

        info.m_format = wxLIST_FORMAT_RIGHT
        info.m_text = "User ID"
        self.ClientList.InsertColumnInfo(2, info)

        self.ClientList.SetColumnWidth(0, 195)
        self.ClientList.SetColumnWidth(1, 100)
        self.ClientList.SetColumnWidth(2, 80)

<fill the dictionary with data>

        for x in range(len(items)):
            key, data = items
            self.ClientList.InsertStringItem(x, data[0])
            self.ClientList.SetStringItem(x, 1, data[1])
            self.ClientList.SetStringItem(x, 2, str(data[2]))
            self.ClientList.SetItemData(x, key)

John Hopkins wrote:

Now I more questions. The following code snippets result in a list control
that does just what I want (and sorts 1200 rows quite quickly -- I LOVE
Python/wxPython!), except the UpArrow icon appears in the first column of
each row, where the "smiley" is in the demo. I can't figure out why, since
I'm using InsertStringItem rather than InsertImageStringItem() for that
column. Is this maybe a default behavior, and can I turn it off?

I think that the MS native control has a "feature" that if there is an image list then you must use an image for the items. So add an image to your image list that is totally transparent and use that.

Also, the up/dn icons appear on the left of the text in the first column,
but on the right on subsequent columns both on my list and the demo. Is
that locked-in, or can I change it for better alignment between titles and
data?

That's another unchangable "feature" of the MS native list control.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!