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
Earned some good credits
Earned some good credits
Posts: 119
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: 19102
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
Earned some good credits
Earned some good credits
Posts: 119
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: 7449
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: 19102
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
Earned some good credits
Earned some good credits
Posts: 119
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
Earned some good credits
Earned some good credits
Posts: 119
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
Earned some good credits
Earned some good credits
Posts: 119
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
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 470
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: Keyboard only wxFileDialog

Post by doublemax@work »

Try adding a wxPanel to the dialog, and call SetFocus() on it in the dialog constructor.
Rohit Agarwal
Earned some good credits
Earned some good credits
Posts: 119
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.
Rohit Agarwal
Earned some good credits
Earned some good credits
Posts: 119
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: Keyboard only wxFileDialog

Post by Rohit Agarwal »

Hi.

I'm in the process of making a toolkit for extending wxWidgets
with the ability to design "Modal" UIs which can be completely keyboard-based
and do not require any mouse input.

I've created a modal app using wxWidgets and this toolkit called ModalWX.
If you Google ModalWX, you will find it.
https://github.com/Rohit-Agarwal-Khitchdee/Modal

At present this app only demonstrates it's ability to navigate a Modal codebase.
I'm looking for early feedback on the usability of these features.

ModalWX is licensed under the MIT licence so it's open source.

Since this component is intended for wx developers, I'm posting here to get early feedback.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Keyboard only wxFileDialog

Post by ONEEYEMAN »

Hi,
What would be the purpose?
Something like this should make the life of developer easier not harder. And mouse makes it so.

Is there any machine now in the XXI century that doesn't have a mouse?

Even blind people use mouse from time to time. (No offense)

Thank you.
Rohit Agarwal
Earned some good credits
Earned some good credits
Posts: 119
Joined: Wed May 19, 2021 11:17 pm
Contact:

Re: Keyboard only wxFileDialog

Post by Rohit Agarwal »

The purpose of this posting is to demonstrate
that in the context of source-code navigation inside an IDE
something which we all have to do,
a Modal, kybd-only approach is a lot more efficient than a WIMP, mouse-based one.

If you build ModalWX.cpp, (using the same settings as the minimal sample),
It's just a code navigation demo that navigates itself using a Modal UI approach
and demonstrates the efficiency advantage that I'm claiming.
Post Reply