GridCellBoolEditor still not quite right - MSW only

Hi all

Robin recently helped me to get a GridCellBoolEditor to behave the same as a
normal CheckBox - i.e. you can toggle the CheckBox with a single mouse
click, and you can get access to the CheckBox event when it is activated.

I got it working in a stand-alone test program, but when I moved it to my
live app I found a problem with MSW (GTK2 works correctly). If the cell with
the checkbox has focus, I want to navigate off the cell using the arrow
keys, as is normal with a grid. In my test program, I initially found that
it did not respond to the arrow keys at all, but then I found that if I
create a handler for EVT_KEY_DOWN I can trap the arrow key, close the
editor, and force a navigation. In my live app, EVT_KEY_DOWN does not get
trigggered by the arrow key, the editor is closed automatically, and the
cursor stays on the cell.

I found that the difference is caused by the difference in window hierarchy.
My test app looks like this -

    Frame
      >
       -- Panel (style=0)
            >
             -- Grid

My live app looks like this -

    Frame
      >
       -- Panel (normal style)
            >
             -- TextCtrl
            >
             -- Sub-Panel (style=0)
                  >
                   -- Grid

You can see the difference in the attached programs. fm51.py is my original
test program, which works the way I want. fm52.py is modified to resemble my
live app. The only difference is on creation of the frame -

    fm51.py has this -
        panel = wx.Panel(self,style=0)
        grid = MyGrid(panel)

    fm52.py has this -
        panel = wx.Panel(self)
        wx.TextCtrl(panel,-1,size=(60,-1))
        panel2 = wx.Panel(panel,pos=(10,30),size=(300,200),style=0)
        grid = MyGrid(panel2)

I have figured out part of the reason. With MSW, if a normal CheckBox has
focus, it responds to the arrow keys - down and right are treated like tab,
up and left are treated like shift+tab. GTK2 does not do this - it ignores
the arrow keys and only responds to tab and shift+tab.

It seems that on MSW the GridCellBoolEditor is doing something similar - the
checkbox responds to the arrow key by closing the editor. This is the effect
that you see if you run fm52. Why it does not do this in fm51 I have no
idea. Is there any way to modify fm52 so that it behaves the same as fm51?

Thanks

Frank Millman

fm51.py (2.74 KB)

fm52.py (2.85 KB)

Hi Frank,

You can see the difference in the attached programs. fm51.py is my original
test program, which works the way I want. fm52.py is modified to resemble my
live app. The only difference is on creation of the frame -

   fm51.py has this -
       panel = wx.Panel(self,style=0)
       grid = MyGrid(panel)

   fm52.py has this -
       panel = wx.Panel(self)
       wx.TextCtrl(panel,-1,size=(60,-1))
       panel2 = wx.Panel(panel,pos=(10,30),size=(300,200),style=0)
       grid = MyGrid(panel2)

It seems that on MSW the GridCellBoolEditor is doing something similar - the
checkbox responds to the arrow key by closing the editor. This is the effect
that you see if you run fm52. Why it does not do this in fm51 I have no
idea. Is there any way to modify fm52 so that it behaves the same as fm51?

The only way I found to make fm52.py working as fm51.py is to set a
"style=0" style also for the first panel, i.e.:

        panel = wx.Panel(self, style=0)
        wx.TextCtrl(panel,-1,size=(60,-1))
        panel2 = wx.Panel(panel,pos=(10,30),size=(300,200),style=0)
        grid = MyGrid(panel2)

I have no idea why the first panel should have anything to share with
the other panel, but I wasn't able to obtain a better/nicer
solution...

This is wxPython 2.8.1.1, Python 2.5, Windows XP.

Andrea.

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

Frank Millman wrote:

Hi all

Robin recently helped me to get a GridCellBoolEditor to behave the same as a
normal CheckBox - i.e. you can toggle the CheckBox with a single mouse
click, and you can get access to the CheckBox event when it is activated.

I got it working in a stand-alone test program, but when I moved it to my
live app I found a problem with MSW (GTK2 works correctly). If the cell with
the checkbox has focus, I want to navigate off the cell using the arrow
keys, as is normal with a grid. In my test program, I initially found that
it did not respond to the arrow keys at all, but then I found that if I
create a handler for EVT_KEY_DOWN I can trap the arrow key, close the
editor, and force a navigation. In my live app, EVT_KEY_DOWN does not get
trigggered by the arrow key, the editor is closed automatically, and the
cursor stays on the cell.

I've narrowed down the cause of this, but I'll need to ask about it on wx-dev to know the proper way to fix this.

http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?5:mss:83513:200702:fcaebgidocnjcdfmoikl

···

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

Andrea Gavana wrote:

Hi Frank,

The only way I found to make fm52.py working as fm51.py is to
set a "style=0" style also for the first panel

Thanks for the reply, Andrea. Unfortunately it does not help me.

To get GridCellBoolEditor working the way I want, I need to set the panel
style to 0. This has the effect of switching off wx.TAB_TRAVERSAL, which
then messes up tabbing between all the other elements on the panel. My
solution is to leave the main panel with the default style, and create a
sub-panel for the grid with a style of 0. Your idea puts me back in the
situation I was in in the first place.

See a later post for Robin's comments. I had tried setting the WANTS_CHARS
style on the check box, to see if I could trap the arrow keys that way, but
it did not work. Robin is investigating the possibility of getting that
working. If he succeeds, my problem will be solved.

Thanks again

Frank

Robin Dunn wrote:

Frank Millman wrote:
> Hi all
>
> Robin recently helped me to get a GridCellBoolEditor to behave the
> same as a normal CheckBox - i.e. you can toggle the CheckBox with a
> single mouse click, and you can get access to the CheckBox
event when it is activated.
>
> I got it working in a stand-alone test program, but when I
moved it to
> my live app I found a problem with MSW (GTK2 works
correctly). If the
> cell with the checkbox has focus, I want to navigate off the cell
> using the arrow keys, as is normal with a grid. In my test
program, I
> initially found that it did not respond to the arrow keys
at all, but
> then I found that if I create a handler for EVT_KEY_DOWN I can trap
> the arrow key, close the editor, and force a navigation. In my live
> app, EVT_KEY_DOWN does not get trigggered by the arrow key,
the editor
> is closed automatically, and the cursor stays on the cell.

I've narrowed down the cause of this, but I'll need to ask
about it on wx-dev to know the proper way to fix this.

http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?5:mss:83513:20070
2:fcaebgidocnjcdfmoikl

Many thanks for this. I read the message, and if you can get it working, it
will definitely solve my problem. I look forward to hearing the outcome.

Frank

Frank Millman wrote:

Many thanks for this. I read the message, and if you can get it working, it
will definitely solve my problem. I look forward to hearing the outcome.

I did get it working. In the next release you'll just need to add something like this to your sample:

             self.cb = evt.GetControl()
             self.cb.SetWindowStyleFlag(self.cb.GetWindowStyleFlag() | wx.WANTS_CHARS)

Or you can add it now and just wait for it to magically start working :wink:

···

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

Robin Dunn wrote:

Frank Millman wrote:

> Many thanks for this. I read the message, and if you can get it
> working, it will definitely solve my problem. I look
forward to hearing the outcome.

I did get it working. In the next release you'll just need
to add something like this to your sample:

             self.cb = evt.GetControl()
             self.cb.SetWindowStyleFlag(self.cb.GetWindowStyleFlag() |
wx.WANTS_CHARS)

Or you can add it now and just wait for it to magically start
working :wink:

Wonderful - thank you very much!

BTW, can you use the new 'object property' syntax here? -

    self.cb = evt.GetControl()
    self.cb.WindowStyle |= wx.WANTS_CHARS

Just curious.

Frank

Frank Millman wrote:

BTW, can you use the new 'object property' syntax here? -

    self.cb = evt.GetControl()
    self.cb.WindowStyle |= wx.WANTS_CHARS

Just curious.

Yes, that should work too.

···

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

[snip]

Wonderful - thank you very much!

BTW, can you use the new 'object property' syntax here? -

    self.cb = evt.GetControl()
    self.cb.WindowStyle |= wx.WANTS_CHARS

Just curious.

Try it. Does it work? If yes, then you can use it. If it doesn't work,
then you cannot use it.

- Josiah

···

"Frank Millman" <frank@chagford.com> wrote:

Could this fix be done for wx.RadioButtons too? IE, can they also be
fixed to WANT_CHARS?

Hank

Frank Millman wrote:

···

wxPython-users-unsubscribe@lists.wxwidgets.orgwxPython-users-help@lists.wxwidgets.org

Hank Knox wrote:

Could this fix be done for wx.RadioButtons too? IE, can they also be fixed to WANT_CHARS?

Yes, the fix will apply to all native widgets on Windows.

···

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