Keyboard only wxFileDialog

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
Rohit Agarwal
Knows some wx things
Knows some wx things
Posts: 48
Joined: Wed May 19, 2021 11:17 pm
Contact:

Keyboard only wxFileDialog

Post by Rohit Agarwal »

I'm trying to make a new dialog that takes all input from the keyboard and not the mouse.
I'm taking the wxFileDialog class as an example and trying to make a keyboard only version.
The problem I'm facing is I can't intercept key events in a wxDialog.
So I can't subclass from a wxDialog but have to go to wxWindow,
in order to be able to process key events.
Which means I can't make it modal (like wxFileDialog).
Also, after the dialog has been used to select a file, and it has been closed,
I have to push the filename to the frame that contains it
instead of the frame pulling the info from the dialog in wxFileDialog.

Am I missing something here?
User avatar
doublemax
Moderator
Moderator
Posts: 16490
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Keyboard only wxFileDialog

Post by doublemax »

The problem I'm facing is I can't intercept key events in a wxDialog.
So I can't subclass from a wxDialog but have to go to wxWindow,
in order to be able to process key events.
That doesn't make any sense. Why shouldn't it be possible to process key events in an dialog? What exactly did you try?

Besides, usually every GUI is automatically keyboard accessible through the underlying OS (using TAB to cycle through control focus). What are you missing?
Use the source, Luke!
Rohit Agarwal
Knows some wx things
Knows some wx things
Posts: 48
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: Keyboard only wxFileDialog

Post by Rohit Agarwal »

I tried to create an event table in my wxDialog subclass
which intercepted paint and keydown messages.
The paint messages were coming through fine
but I was not getting any keydown messages.

Then I switched to wxWindow and this problem went away.

Since a dialog does special processing for certain keys such as escape,
I got the impression that it does not allow it's core keyboard event handling to be bypassed
and hence does not allow subclasses to intercept key events.
The docs about which events are sent by the wxDialog and wxWindow
also seem to suggest this.
It wasn't clear so I just went with what I know works.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5376
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Keyboard only wxFileDialog

Post by ONEEYEMAN »

Hi,
Which controls do you have on the dialog?
How do you bind the key event?

Can you show some code?

Also - are you using a wxPanel as a parent of the control or wxDialog?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 16490
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Keyboard only wxFileDialog

Post by doublemax »

A wxDialog is a toplevel window, and therefore a very different thing compared to a wxWindow, so one normally can't replace the other.

Be aware that most key events don't propagate, only the control that has keyboard focus will receive the event. The only exception is wxEVT_CHAR_HOOK. Read the documentation for wxKeyEvent about that option. https://docs.wxwidgets.org/trunk/classwx_key_event.html
Use the source, Luke!
Rohit Agarwal
Knows some wx things
Knows some wx things
Posts: 48
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: Keyboard only wxFileDialog

Post by Rohit Agarwal »

doublemax wrote: Fri Aug 27, 2021 3:48 pm A wxDialog is a toplevel window, and therefore a very different thing compared to a wxWindow, so one normally can't replace the other.

Be aware that most key events don't propagate, only the control that has keyboard focus will receive the event. The only exception is wxEVT_CHAR_HOOK. Read the documentation for wxKeyEvent about that option. https://docs.wxwidgets.org/trunk/classwx_key_event.html
I'll explore wxEVT_CHAR_HOOK. That might work. Thanks!
Rohit Agarwal
Knows some wx things
Knows some wx things
Posts: 48
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: Keyboard only wxFileDialog

Post by Rohit Agarwal »

ONEEYEMAN wrote: Fri Aug 27, 2021 3:41 pm Hi,
Which controls do you have on the dialog?
How do you bind the key event?

Can you show some code?

Also - are you using a wxPanel as a parent of the control or wxDialog?

Thank you.
I don't have any controls on the dialog.
I'm trying to do this:

Code: Select all

class HexDlg : public wxDialog
{
public:
  HexDlg( MyFrame *parent, float fScrnDiag );
  void OnPaint(wxPaintEvent &event);
  void OnKeyDown(wxKeyEvent &event);
  void Close();
  wxString m_strFileName;
private:
  MyFrame *m_owner;
  wxDECLARE_EVENT_TABLE();
};
wxBEGIN_EVENT_TABLE(HexDlg, wxWindow)
  EVT_PAINT  (HexDlg::OnPaint)
 EVT_KEY_DOWN (HexDlg::OnKeyDown)
wxEND_EVENT_TABLE()
I am using a wxFrame as the parent of the dialog.
Rohit Agarwal
Knows some wx things
Knows some wx things
Posts: 48
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: Keyboard only wxFileDialog

Post by Rohit Agarwal »

Rohit Agarwal wrote: Fri Aug 27, 2021 4:16 pm
doublemax wrote: Fri Aug 27, 2021 3:48 pm A wxDialog is a toplevel window, and therefore a very different thing compared to a wxWindow, so one normally can't replace the other.

Be aware that most key events don't propagate, only the control that has keyboard focus will receive the event. The only exception is wxEVT_CHAR_HOOK. Read the documentation for wxKeyEvent about that option. https://docs.wxwidgets.org/trunk/classwx_key_event.html
I'll explore wxEVT_CHAR_HOOK. That might work. Thanks!
I tried wxEVT_CHAR_HOOK on a wxDialog, that did not work either.
It does work on a wxWindow.
So I guess you can't create your own keyboard event handling mechanism on a wxDialog.
Is it possible to make a wxWindow modal? I guess it is not.
User avatar
[email protected]
Earned some good credits
Earned some good credits
Posts: 144
Joined: Wed Jul 29, 2020 6:06 pm

Re: Keyboard only wxFileDialog

Post by [email protected] »

Try adding a wxPanel to the dialog, and call SetFocus() on it in the dialog constructor.
Rohit Agarwal
Knows some wx things
Knows some wx things
Posts: 48
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: Keyboard only wxFileDialog

Post by Rohit Agarwal »

Thanks.
I'll try that. I think it will work for my purposes.
Post Reply