New to Python, new to wxWindows, new to wxPython but blown away by just how
good
this combination is!
I am trying to model a number of popup widgets after the wxPopupControl demo
program.
It works almost perfectly for my purposes but does not respond to the escape
character. I
(really want) the user to be able to simply hit escape and have the popup go
away.
What I have tried...
1) Cloned the code from the wxPopupControl (so I can get at its guts) and
used the wxPopupControl
demo to test it out (it puts wxCalendarCtrl into the popup). I have tried
to attach key events to the
wxCalendar control, its window, the wxPopupControl's window, and its
wxPopupControl's wxDialog
all to no avail. The popup is a wxDialog for the popup and not a
wxPopupWindow since the author's
comments in the source code metion that wxPopupWindow misbehaved on MSW.
2) Reading the wxWindows api documentation it seems that the wxDialog has an
wxDialog::OnCharHook
method that is probably exactly what I want -- however it does not seem to
be implemented in the python
wrapper 'dialogs.py' (and I have no clue as to how to go about adding it
in). From the api docs
wxDialog::OnCharHook
void OnCharHook(wxKeyEvent& event)
This member is called to allow the window to intercept keyboard events
before
they are processed by child windows.
Remarks
wxDialog implements this handler to fake a cancel command if the escape
key has been pressed. This will dismiss the dialog.
Any idea how to get OnCharHook to work from python, or any trick that
achieves the same?
I believe you want to use the style wxWANTS_CHARS then setup an
EVT_CHAR() event handler and you should get what you desire.
- Jim
···
On Mon, 2003-11-17 at 12:20, tim.mothery-wxPython@westpointair.com wrote:
Hello.
New to Python, new to wxWindows, new to wxPython but blown away by just how
good
this combination is!
I am trying to model a number of popup widgets after the wxPopupControl demo
program.
It works almost perfectly for my purposes but does not respond to the escape
character. I
(really want) the user to be able to simply hit escape and have the popup go
away.
What I have tried...
1) Cloned the code from the wxPopupControl (so I can get at its guts) and
used the wxPopupControl
demo to test it out (it puts wxCalendarCtrl into the popup). I have tried
to attach key events to the
wxCalendar control, its window, the wxPopupControl's window, and its
wxPopupControl's wxDialog
all to no avail. The popup is a wxDialog for the popup and not a
wxPopupWindow since the author's
comments in the source code metion that wxPopupWindow misbehaved on MSW.
2) Reading the wxWindows api documentation it seems that the wxDialog has an
wxDialog::OnCharHook
method that is probably exactly what I want -- however it does not seem to
be implemented in the python
wrapper 'dialogs.py' (and I have no clue as to how to go about adding it
in). From the api docs
wxDialog::OnCharHook
void OnCharHook(wxKeyEvent& event)
This member is called to allow the window to intercept keyboard events
before
they are processed by child windows.
Remarks
wxDialog implements this handler to fake a cancel command if the escape
key has been pressed. This will dismiss the dialog.
Any idea how to get OnCharHook to work from python, or any trick that
achieves the same?
Thanks, in advance
Tim Mothery.
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
Dialogs should already have support for the ESC key to cause the dialog to be canceled. Actually it generates a button event with an ID of wxID_CANCEL and there is a default EVT_BUTTON handler for it that calls EndModal. In short, I'm a bit surprised that it isn't working wxPopupControl already. I don't have time to look into it right now, but there should be a way to make it work. Perhaps a missing style, or something.
···
tim.mothery-wxPython@westpointair.com wrote:
Hello.
New to Python, new to wxWindows, new to wxPython but blown away by just how
good
this combination is!
I am trying to model a number of popup widgets after the wxPopupControl demo
program.
It works almost perfectly for my purposes but does not respond to the escape
character. I
(really want) the user to be able to simply hit escape and have the popup go
away.
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Unfortunately I have not yet met with success. I have put the whole test
case into a single runnable .py file which is available at http://piper.westpointair.com/~tmothery. I have left the popupDialog class
in a state where it will recognize the escape (or any) key the very first
time it is used but it seems that once the calendar control gets the focus
all subseqent key events are blocked and not passed up through the
containment hierarchy.
Note: if relevant, I am testing and doing this devel on W2K
I have tried using Jim's suggestion
I believe you want to use the style wxWANTS_CHARS then setup an
EVT_CHAR() event handler and you should get what you desire.
but wxWANTS_CHARS didn't seem to make a difference one way or the other (I
tried both on the dialog and the contained window (lines 1 and 6 of class
PopupDialog).
Dialogs should already have support for the ESC key to cause the dialog
to be canceled. Actually it generates a button event with an ID of
wxID_CANCEL and there is a default EVT_BUTTON handler for it that calls
EndModal. In short, I'm a bit surprised that it isn't working
wxPopupControl already.
I'm too new wxPython to be surprised but I am frustrated with this one
little blemish
I don't have time to look into it right now,
but there should be a way to make it work. Perhaps a missing style, or
something.
I appreciate your answer anyways. But,.... if you do manage to have a
moment to take a peek I have tried to make checking it our as simple as I
know how. The single test file above is all that is needed to see and
experiment with the behaviour. And it is probably just the first few lines
of PopupDialog that need a tweak or a little magic.