wx.ListCtrl() Event Handler Macros

I thought I understood the differences between 'focus,' 'selected,' and
'activated,' but I can't find a relevant message in my saved mail.

   According to the 2.6 docs, wx.EVT_LIST_ITEM_SELECTED(id, func) is
triggered when the item has been selected, wx.EVT_LIST_ITEM_DESELECTED(id,
func) when the item has been deselected, and wx.EVT_LIST_ITEM_FOCUSED(id,
func) is triggered when the focused item has changed.

   Then, wx.EVT_LIST_ITEM_ACTIVATED(id, func) means that the [Enter] key (or
a double-click of the trackball) has been pressed when the cursor is over a
particular item.

   The last event is unambiguous. But, I miss the distinction between
selected/deselected and changed focus. What is the sequence of events
triggered as the cursor is moved down the list of items in the widget?

   I'm wondering if I need the first three, or only the last one to identify
the item that needs to be fed to a method.

TIA,

Rich

···

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

I believe it will vary based on the native control - using arrow keys
to scroll down might only move focus, but not activation, on some
platforms. On others it might move both. I haven't tested this in
detail, because I had some trouble tracking the "current" item and
decided that I didn't need to do it at all - instead of trying to keep
track of the selected item, I simple retrieve the selection when I
need to do something with it.

···

On 1/11/07, Rich Shepard <rshepard@appl-ecosys.com> wrote:

   I thought I understood the differences between 'focus,' 'selected,' and
'activated,' but I can't find a relevant message in my saved mail.

   According to the 2.6 docs, wx.EVT_LIST_ITEM_SELECTED(id, func) is
triggered when the item has been selected, wx.EVT_LIST_ITEM_DESELECTED(id,
func) when the item has been deselected, and wx.EVT_LIST_ITEM_FOCUSED(id,
func) is triggered when the focused item has changed.

   Then, wx.EVT_LIST_ITEM_ACTIVATED(id, func) means that the [Enter] key (or
a double-click of the trackball) has been pressed when the cursor is over a
particular item.

   The last event is unambiguous. But, I miss the distinction between
selected/deselected and changed focus. What is the sequence of events
triggered as the cursor is moved down the list of items in the widget?

   I'm wondering if I need the first three, or only the last one to identify
the item that needs to be fed to a method.

TIA,

Rich

Chris,

   I understand, but I would like to understand the difference between
selected and activated. If I correctly understand the meaning of 'focus,'
that's when an item in the list has been highlighted by having the pointer
over it (trackball paused or arrow key use).

   The next step -- as I understand the meanings -- is to 'select' that
choice by clicking the left trackball button or the [Enter] key. This, in
effect, 'activates' that selection.

   Perhaps I'm just dense so I need help understanding the difference(s)
among these terms so I can capture the proper events.

Thanks,

Rich

···

On Fri, 12 Jan 2007, Chris Mellon wrote:

I believe it will vary based on the native control - using arrow keys to
scroll down might only move focus, but not activation, on some platforms.
On others it might move both. I haven't tested this in detail, because I
had some trouble tracking the "current" item and decided that I didn't
need to do it at all - instead of trying to keep track of the selected
item, I simple retrieve the selection when I need to do something with it.

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Not all platforms make the distinction, to my knowledge, but some do.
I'm on Windows XP right now, which has the distinction in it's API but
(like 3 state check controls) it's not possible to exercise them
unless you override the control behavior.

But imagine the following, which (I *think*) is how it works on Gtk (I
can't confirm this right now). You click on the first element, which
selects and focuses it, it has a dark blue background. You then hit
the down arrow. A focus rect appears around each item in turn, and the
focus changes, but the top item keeps it's dark blue background and
the selection doesn't change. Hitting enter changes the focused item
to selected.

Activated, as I understand it, is an action, not a state. An item
which is activated is moved to the selected state.

···

On 1/12/07, Rich Shepard <rshepard@appl-ecosys.com> wrote:

On Fri, 12 Jan 2007, Chris Mellon wrote:

> I believe it will vary based on the native control - using arrow keys to
> scroll down might only move focus, but not activation, on some platforms.
> On others it might move both. I haven't tested this in detail, because I
> had some trouble tracking the "current" item and decided that I didn't
> need to do it at all - instead of trying to keep track of the selected
> item, I simple retrieve the selection when I need to do something with it.

Chris,

   I understand, but I would like to understand the difference between
selected and activated. If I correctly understand the meaning of 'focus,'
that's when an item in the list has been highlighted by having the pointer
over it (trackball paused or arrow key use).

   The next step -- as I understand the meanings -- is to 'select' that
choice by clicking the left trackball button or the [Enter] key. This, in
effect, 'activates' that selection.

   Perhaps I'm just dense so I need help understanding the difference(s)
among these terms so I can capture the proper events.

Thanks,

Rich

Not all platforms make the distinction, to my knowledge, but some do.

   This may be (I work on only linux), but the class has separate event
handlers and I'm trying to determine which I need.

But imagine the following, which (I *think*) is how it works on Gtk (I
can't confirm this right now). You click on the first element, which
selects and focuses it, it has a dark blue background. You then hit the
down arrow. A focus rect appears around each item in turn, and the focus
changes, but the top item keeps it's dark blue background and the
selection doesn't change. Hitting enter changes the focused item to
selected.

   OK. This makes very good sense. Since I don't care which item has the
focus (because that carries no meaning to the model).

Activated, as I understand it, is an action, not a state. An item which is
activated is moved to the selected state.

   Now you've lost me. :slight_smile: Selecting an item is also an action that results
in a changed item state. So, do I want EVT_LIST_ITEM_SELECTED(id, func) or
EVT_LIST_ITEM_ACTIVATED(id, func)?

Rich

···

On Fri, 12 Jan 2007, Chris Mellon wrote:

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

I believe you want the former. In fact, I'm not even sure I'm right
any more about activation - on my WinXP box, activation fires when I
double-click an item, but not on a simple click, that only fires
selection.

···

On 1/12/07, Rich Shepard <rshepard@appl-ecosys.com> wrote:

On Fri, 12 Jan 2007, Chris Mellon wrote:

> Not all platforms make the distinction, to my knowledge, but some do.

   This may be (I work on only linux), but the class has separate event
handlers and I'm trying to determine which I need.

> But imagine the following, which (I *think*) is how it works on Gtk (I
> can't confirm this right now). You click on the first element, which
> selects and focuses it, it has a dark blue background. You then hit the
> down arrow. A focus rect appears around each item in turn, and the focus
> changes, but the top item keeps it's dark blue background and the
> selection doesn't change. Hitting enter changes the focused item to
> selected.

   OK. This makes very good sense. Since I don't care which item has the
focus (because that carries no meaning to the model).

> Activated, as I understand it, is an action, not a state. An item which is
> activated is moved to the selected state.

   Now you've lost me. :slight_smile: Selecting an item is also an action that results
in a changed item state. So, do I want EVT_LIST_ITEM_SELECTED(id, func) or
EVT_LIST_ITEM_ACTIVATED(id, func)?

Chris, et al.:

   The answer is in the wPIA book, but I did not see it until now.

   focus == the cursor is hovering over an item.
   selected == a single-left click occurred on that item.
   activated == a double-left click or press of the [Enter] key occurred on
     that item.

   That tells me what I need to know. My apologies for bringing this up on
the list as I did.

Carpe weekend,

Rich

···

On Fri, 12 Jan 2007, Chris Mellon wrote:

I believe you want the former. In fact, I'm not even sure I'm right any
more about activation - on my WinXP box, activation fires when I
double-click an item, but not on a simple click, that only fires
selection.

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerator(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863

Chris Mellon wrote:

Not all platforms make the distinction, to my knowledge, but some do.
I'm on Windows XP right now, which has the distinction in it's API but
(like 3 state check controls) it's not possible to exercise them
unless you override the control behavior.

But imagine the following, which (I *think*) is how it works on Gtk (I
can't confirm this right now). You click on the first element, which
selects and focuses it, it has a dark blue background. You then hit
the down arrow. A focus rect appears around each item in turn, and the
focus changes, but the top item keeps it's dark blue background and
the selection doesn't change.

Correct.

Hitting enter changes the focused item
to selected.

Actually, I think it is the spacebar that makes selections. (Or mouse click.)

Activated, as I understand it, is an action, not a state. An item
which is activated is moved to the selected state.

No, activation (which also selects if the item is not selected yet) is done by pressing enter or double clicking. It is basically meant to behave similarly to how the default button in a dialog does. IOW, when you activate an item in a listctrl your app should do some default behavior on the item. What that behavior is (if anything) depends entirely on the context and your app. For example, an activation in list ctrl in a dialog might select the item and then complete the dialog, as if the Ok button had also been clicked.

···

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