It seems that right-clicking on an LC_LIST list control item first generates an item-selected event, THEN an item-right-clicked-on event.
In my item-selected event handler, I need to know how that event was generated, or at least whether it was generated by a left click or by a right click. The reason is that I need a right click on a list item to generate a pop-up menu WITHOUT changing (for more than a super-brief instant) the selected/non-selected status of the list item clicked on.
It seems that right-clicking on an LC_LIST list control item first generates an item-selected event, THEN an item-right-clicked-on event.
In my item-selected event handler, I need to know how that event was generated, or at least whether it was generated by a left click or by a right click. The reason is that I need a right click on a list item to generate a pop-up menu WITHOUT changing (for more than a super-brief instant) the selected/non-selected status of the list item clicked on.
How can I detect that?
Keep track of the previously selected item and then after you show your popup menu reselect the previous item again.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
That's the problem, Robin. How do you suggest I keep track of the previously selected item(s)? The EVT_LIST_ITEM_SELECTED event handler is where I do that now. But that event will have happened just before the EVT_LIST_ITEM_RIGHT_CLICK event does. So it'll look like the right-clicked item =is= a selected item, when, from my application's perspective, it shouldn't.
Right now, capturing time.clock() at both events and comparing is the only way I know to try to detect when an EVT_LIST_ITEM_SELECTED event was generated by a right click. And that's not foolproof.
I'm getting the feeling I'm missing something basic here. ??
Bob
···
At 03:55 PM 2/27/2009, Robin Dunn wrote:
Bob Klahn wrote:
It seems that right-clicking on an LC_LIST list control item first generates an item-selected event, THEN an item-right-clicked-on event.
In my item-selected event handler, I need to know how that event was generated, or at least whether it was generated by a left click or by a right click. The reason is that I need a right click on a list item to generate a pop-up menu WITHOUT changing (for more than a super-brief instant) the selected/non-selected status of the list item clicked on.
How can I detect that?
Keep track of the previously selected item and then after you show your popup menu reselect the previous item again.
How do you suggest I keep track of the
previously selected item(s)? The EVT_LIST_ITEM_SELECTED event handler is
where I do that now. But that event will have happened just before the
EVT_LIST_ITEM_RIGHT_CLICK event does.
<untested>
I think you may want LCtrl.Bind(wx.EVT_RIGHT_DOWN,
self.OnRightDownLCtrl). I am pretty sure that occurs before the
EVT_LIST_ITEM_SELECTED is generated. You should be able to trap for
that and it won't change the currently selected item. If after
processing the right-click you do want the item to change you can
always add evt.Skip() to the callback and an EVT_LIST_ITEM_SELECTED
should be generated. If you need to know (as you probably do) what
item/row was right-clicked, you can always do:
That's what I was missing, Steve, that's what I needed. Thanks! It works.
So, even though it seemed like an item-right-click handler was what I should use -- after all, the user is right-clicking on a list item! -- that was just what I =didn't= want.
Bob
···
At 11:39 PM 2/27/2009, Steve Zatz wrote:
> How do you suggest I keep track of the
> previously selected item(s)? The EVT_LIST_ITEM_SELECTED event handler is
> where I do that now. But that event will have happened just before the
> EVT_LIST_ITEM_RIGHT_CLICK event does.
<untested>
I think you may want LCtrl.Bind(wx.EVT_RIGHT_DOWN,
self.OnRightDownLCtrl). I am pretty sure that occurs before the
EVT_LIST_ITEM_SELECTED is generated. You should be able to trap for
that and it won't change the currently selected item. If after
processing the right-click you do want the item to change you can
always add evt.Skip() to the callback and an EVT_LIST_ITEM_SELECTED
should be generated. If you need to know (as you probably do) what
item/row was right-clicked, you can always do:
It seems that right-clicking on an LC_LIST list control item first generates an item-selected event, THEN an item-right-clicked-on event.
In my item-selected event handler, I need to know how that event was generated, or at least whether it was generated by a left click or by a right click. The reason is that I need a right click on a list item to generate a pop-up menu WITHOUT changing (for more than a super-brief instant) the selected/non-selected status of the list item clicked on.
How can I detect that?
Keep track of the previously selected item and then after you show your popup menu reselect the previous item again.
That's the problem, Robin. How do you suggest I keep track of the previously selected item(s)? The EVT_LIST_ITEM_SELECTED event handler is where I do that now. But that event will have happened just before the EVT_LIST_ITEM_RIGHT_CLICK event does. So it'll look like the right-clicked item =is= a selected item, when, from my application's perspective, it shouldn't.
Right now, capturing time.clock() at both events and comparing is the only way I know to try to detect when an EVT_LIST_ITEM_SELECTED event was generated by a right click. And that's not foolproof.
I'm getting the feeling I'm missing something basic here. ??
Bob
You can also compare the indexes of the items selected, I think. In my handler for EVT_LIST_ITEM_SELECTED, I do something like this:
self.prevItem = event.m_itemIndex
So theoretically, you could do some comparison in your handler for EVT_LIST_ITEM_RIGHT_CLICK:
def rightClickHandler(self, event):
if self.prevItem == event.m_itemIndex:
# do something
pass
Of course, it sounds like Steve had a good answer...