preventing context menu after right dragging in TreeCtrl

Howdy,

I have both wx.EVT_TREE_BEGIN_RDRAG/wx.EVT_TREE_END_DRAG and wx.EVT_TREE_ITEM_MENU bound in a TreeCtrl.

The problem is that the latter (context menu) fires after the right drag. Is there a good way to prevent this
from happening? The only way I can think of, is to put a click time into the context menu code and not
popup if the right drag just ended, but this strikes me as lousy.

TIA,
Danny

The wx.DatePickerCtrl works fine until you give it a style of
wx.DP_ALLOWNONE. When the wx.DP_ALLOWNONE style is given, wxPython
throws an exception (noted below):
    wx.DatePickerCtrl.__init__(self, *args, **kw)
  File "wx\_controls.pyo", line 6381, in __init__
wx._core.PyAssertionError: C++ assertion "IsValid()" failed at
..\..\include\wx/
datetime.h(1675) in wxDateTime::GetTicks(): invalid wxDateTime

This seems like a fundamental bug in the wxWindows code where a
default value isn't given to the wxDatePickerCtrl when the style is
activated.

Christoper L. Spencer
CTO ROXX, LLC
4515 Leslie Ave.
Cincinnati, OH
45242
TEL: 513-545-7057
EMAIL: chris@roxx.biz

Danny Shevitz wrote:

Howdy,

I have both wx.EVT_TREE_BEGIN_RDRAG/wx.EVT_TREE_END_DRAG and wx.EVT_TREE_ITEM_MENU bound in a TreeCtrl.

The problem is that the latter (context menu) fires after the right drag. Is there a good way to prevent this
from happening? The only way I can think of, is to put a click time into the context menu code and not
popup if the right drag just ended, but this strikes me as lousy.

You can set a flag in the wx.EVT_TREE_END_DRAG handler that let's you know to ignore the next EVT_TREE_ITEM_MENU event. Or you can temporarily disconnect the EVT_TREE_ITEM_MENU as needed, etc.

···

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

Chris Spencer wrote:

The wx.DatePickerCtrl works fine until you give it a style of
wx.DP_ALLOWNONE. When the wx.DP_ALLOWNONE style is given, wxPython
throws an exception (noted below):
    wx.DatePickerCtrl.__init__(self, *args, **kw)
  File "wx\_controls.pyo", line 6381, in __init__
wx._core.PyAssertionError: C++ assertion "IsValid()" failed at
..\..\include\wx/
datetime.h(1675) in wxDateTime::GetTicks(): invalid wxDateTime

This seems like a fundamental bug in the wxWindows code where a
default value isn't given to the wxDatePickerCtrl when the style is
activated.

Thanks. I've got a fix for it now.

···

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

thanks for replying.

Or you can temporarily disconnect the EVT_TREE_ITEM_MENU as needed, etc.

How do you do this? Rebind to a no-op function or is there a way to actually switch it off.

I had another idea, but I don't know if it's possible. Is there the opposite of ProcessEvent?
Is there a way to remove an event from an event queue? We know EVT_TREE_ITEM_MENU is
still in the queue, so if there were a DeleteEvent mechanism, it would work. I looked around but
didn't find anything. I probably just don't know where to look.

thanks,
Danny

Hi Danny,

>Or you can temporarily disconnect the EVT_TREE_ITEM_MENU as needed, etc.

How do you do this? Rebind to a no-op function or is there a way to
actually switch it off.

You can try using:

YourControl.Unbind(wx.EVT_TREE_ITEM_MENU)

Help on method Unbind in module wx._core:

Unbind(self, event, source=None, id=-1, id2=-1) unbound wx._windows.Frame method
    Disconencts the event handler binding for event from self.
    Returns True if successful.

I had another idea, but I don't know if it's possible. Is there the
opposite of ProcessEvent?
Is there a way to remove an event from an event queue? We know
EVT_TREE_ITEM_MENU is
still in the queue, so if there were a DeleteEvent mechanism, it would
work. I looked around but
didn't find anything. I probably just don't know where to look.

I don't know if there is a way to do that. If the event is the first
in your event-chain, you might take a look at:

YourControl.PopEventHandler()

But I am no expert in these things, so I would personally go with the
Unbind method. Cheap and easy.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 2/5/07, Danny Shevitz wrote:

You can try using:

YourControl.Unbind(wx.EVT_TREE_ITEM_MENU)

Help on method Unbind in module wx._core:

Thanks for your help, but here's a followup question:

How do I know when/where to rebind?
In the EVT_TREE_END_DROP code, I can unbind. Where is the right place to rebind so that the context menu
will work after the drop code but also after the EVT_TREE_ITEM_MENU is processed and ignored because it is now
unbound?

thanks,
Danny

Hi Danny,

···

On 2/5/07, Danny Shevitz wrote:

>
>You can try using:
>
>YourControl.Unbind(wx.EVT_TREE_ITEM_MENU)
>
>Help on method Unbind in module wx._core:

Thanks for your help, but here's a followup question:

How do I know when/where to rebind?
In the EVT_TREE_END_DROP code, I can unbind. Where is the right place to
rebind so that the context menu
will work after the drop code but also after the EVT_TREE_ITEM_MENU is
processed and ignored because it is now
unbound?

Uhm, in your drop method, what happens if you call:

wx.CallAfter(self.RebindMyControl)

def RebindMyControl(self):

    YourControl.Bind(wx.EVT_TREE_ITEM_MENU, self.OnMyTreeMenu)

At the end of the method? In theory, wx.CallAfter executes the RebindMyControl method when all the events have been processed. Otherwise you can try with wx.CallLater(200, RebindMyControl), where 200 is the time interval in ms after which the RebindMyControl method is called.

Andrea.

_________________________________________
Andrea Gavana (gavana@kpo.kz)
Reservoir Engineer
KPDL
4, Millbank
SW1P 3JA London

Direct Tel: +44 (0) 20 717 08936
Mobile Tel: +44 (0) 77 487 70534
Fax: +44 (0) 20 717 08900
Web: http://xoomer.virgilio.it/infinity77
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Thanks, that's brilliant and it works.

All I needed to do was at the end of my EVT_TREE_END_DROP code
put in:

self.tree.Unbind(wx.EVT_TREE_ITEM_MENU)
wx.CallAfter(self.tree.Bind, wx.EVT_TREE_ITEM_MENU, self.OnItemMenu)

The wx.CallAfter is run after the event queue is processed.

thanks again,
Danny

···

At 05:21 PM 2/5/2007 +0000, you wrote:

Hi Danny,

On 2/5/07, Danny Shevitz wrote:
>
> >
> >You can try using:
> >
> >YourControl.Unbind(wx.EVT_TREE_ITEM_MENU)
> >
> >Help on method Unbind in module wx._core:
>
> Thanks for your help, but here's a followup question:
>
> How do I know when/where to rebind?
> In the EVT_TREE_END_DROP code, I can unbind. Where is the right place to
> rebind so that the context menu
> will work after the drop code but also after the EVT_TREE_ITEM_MENU is
> processed and ignored because it is now
> unbound?

Uhm, in your drop method, what happens if you call:

wx.CallAfter(self.RebindMyControl)

def RebindMyControl(self):

    YourControl.Bind(wx.EVT_TREE_ITEM_MENU, self.OnMyTreeMenu)

At the end of the method? In theory, wx.CallAfter executes the RebindMyControl method when all the events have been processed. Otherwise you can try with wx.CallLater(200, RebindMyControl), where 200 is the time interval in ms after which the RebindMyControl method is called.

Andrea.

_________________________________________
Andrea Gavana (gavana@kpo.kz)
Reservoir Engineer
KPDL
4, Millbank
SW1P 3JA London

Direct Tel: +44 (0) 20 717 08936
Mobile Tel: +44 (0) 77 487 70534
Fax: +44 (0) 20 717 08900
Web: http://xoomer.virgilio.it/infinity77
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org