I have several notebook tabs with wxGrids in them. When I click on a notetab, the first cell of the grid appears to have focus (dark border) but when I hit the right/left arrow key, the note tabs change, not the cell.
I am pretty sure this behaviour changed somewhere between wxPython 2.4 and 2.6.
Any clues on how to fix this please?
def OnPageChanged(evt):
new = evt.GetSelection()
sel = nb.GetSelection()
if new == sel:
nb.GetPage(sel).SetFocus()
evt.Skip()
nb.Bind(wx.EVT_SELECTION_CHANGED, OnPageChanged)
- Josiah
···
paul sorenson <sourceforge@metrak.com> wrote:
I have several notebook tabs with wxGrids in them. When I click on a
notetab, the first cell of the grid appears to have focus (dark border)
but when I hit the right/left arrow key, the note tabs change, not the cell.
I am pretty sure this behaviour changed somewhere between wxPython 2.4
and 2.6.
Any clues on how to fix this please?
Josiah,
Thanks for the tip. I couldn't get it to work and it raises some new questions:
o I have bound EVT_NOTEBOOK_PAGE_CHANGED I couldn't find EVT_SELECTION_CHANGED for a notebook.
o Even when this code is called: nb.GetPage(sel).SetFocus() the behaviour is still the same, notebook tabs themselves have focus and so hitting arrow keys changes tabs. It is as though I need to SetFocus() on the window inside the notebook.
I thought it might have been the way my grid implementation was handling keys but I have a notebook tab without a grid and it behaves the same.
Am I making sense?
Josiah Carlson wrote:
···
paul sorenson <sourceforge@metrak.com> wrote:
I have several notebook tabs with wxGrids in them. When I click on a notetab, the first cell of the grid appears to have focus (dark border) but when I hit the right/left arrow key, the note tabs change, not the cell.
I am pretty sure this behaviour changed somewhere between wxPython 2.4 and 2.6.
Any clues on how to fix this please?
def OnPageChanged(evt):
new = evt.GetSelection()
sel = nb.GetSelection()
if new == sel:
nb.GetPage(sel).SetFocus()
evt.Skip()
nb.Bind(wx.EVT_SELECTION_CHANGED, OnPageChanged)
- Josiah
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Josiah,
Thanks for the tip. I couldn't get it to work and it raises some new
questions:
o I have bound EVT_NOTEBOOK_PAGE_CHANGED I couldn't find
EVT_SELECTION_CHANGED for a notebook.
I mistyped from memory, sorry!
o Even when this code is called: nb.GetPage(sel).SetFocus() the
behaviour is still the same, notebook tabs themselves have focus and so
hitting arrow keys changes tabs. It is as though I need to SetFocus()
on the window inside the notebook.
Try using...
wx.CallAfter(nb.GetPage(sel).SetFocus)
I thought it might have been the way my grid implementation was handling
keys but I have a notebook tab without a grid and it behaves the same.
Am I making sense?
Yes.
- Josiah
···
paul sorenson <sourceforge@metrak.com> wrote:
Josiah Carlson wrote:
> paul sorenson <sourceforge@metrak.com> wrote:
>
>>I have several notebook tabs with wxGrids in them. When I click on a
>>notetab, the first cell of the grid appears to have focus (dark border)
>>but when I hit the right/left arrow key, the note tabs change, not the cell.
>>
>>I am pretty sure this behaviour changed somewhere between wxPython 2.4
>>and 2.6.
>>
>>Any clues on how to fix this please?
>
>
> def OnPageChanged(evt):
> new = evt.GetSelection()
> sel = nb.GetSelection()
> if new == sel:
> nb.GetPage(sel).SetFocus()
> evt.Skip()
>
> nb.Bind(wx.EVT_SELECTION_CHANGED, OnPageChanged)
>
>
> - Josiah
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Thanks again. This time the code does something, but not what I want, now the arrow keys don't do anything.
When I print self.FindFocus() in the event handler, the notebook has the focus. After applying the code (with or without CallAfter) a window (presumably the window inside the notebook) has focus which makes sense but the notebook itself is grabbing arrow keystrokes.
cheers
BTW I am calling this when new != sel (cf new == sel), ie when the page changes.
Josiah Carlson wrote:
···
paul sorenson <sourceforge@metrak.com> wrote:
Josiah,
Thanks for the tip. I couldn't get it to work and it raises some new questions:
o I have bound EVT_NOTEBOOK_PAGE_CHANGED I couldn't find EVT_SELECTION_CHANGED for a notebook.
I mistyped from memory, sorry!
o Even when this code is called: nb.GetPage(sel).SetFocus() the behaviour is still the same, notebook tabs themselves have focus and so hitting arrow keys changes tabs. It is as though I need to SetFocus() on the window inside the notebook.
Try using...
wx.CallAfter(nb.GetPage(sel).SetFocus)
I thought it might have been the way my grid implementation was handling keys but I have a notebook tab without a grid and it behaves the same.
Am I making sense?
Yes.
- Josiah
Josiah Carlson wrote:
paul sorenson <sourceforge@metrak.com> wrote:
I have several notebook tabs with wxGrids in them. When I click on a notetab, the first cell of the grid appears to have focus (dark border) but when I hit the right/left arrow key, the note tabs change, not the cell.
I am pretty sure this behaviour changed somewhere between wxPython 2.4 and 2.6.
Any clues on how to fix this please?
def OnPageChanged(evt):
new = evt.GetSelection()
sel = nb.GetSelection()
if new == sel:
nb.GetPage(sel).SetFocus()
evt.Skip()
nb.Bind(wx.EVT_SELECTION_CHANGED, OnPageChanged)
- Josiah
Get the control that you want to have focus on the page that is selected,
then use the method I already described.
- Josiah
···
paul sorenson <sourceforge@metrak.com> wrote:
Thanks again. This time the code does something, but not what I want,
now the arrow keys don't do anything.
When I print self.FindFocus() in the event handler, the notebook has the
focus. After applying the code (with or without CallAfter) a window
(presumably the window inside the notebook) has focus which makes sense
but the notebook itself is grabbing arrow keystrokes.
cheers
BTW I am calling this when new != sel (cf new == sel), ie when the page
changes.
Josiah Carlson wrote:
> paul sorenson <sourceforge@metrak.com> wrote:
>
>>Josiah,
>>
>>Thanks for the tip. I couldn't get it to work and it raises some new
>>questions:
>>
>> o I have bound EVT_NOTEBOOK_PAGE_CHANGED I couldn't find
>>EVT_SELECTION_CHANGED for a notebook.
>
>
> I mistyped from memory, sorry!
>
>
>> o Even when this code is called: nb.GetPage(sel).SetFocus() the
>>behaviour is still the same, notebook tabs themselves have focus and so
>>hitting arrow keys changes tabs. It is as though I need to SetFocus()
>>on the window inside the notebook.
>
>
> Try using...
>
> wx.CallAfter(nb.GetPage(sel).SetFocus)
>
>
>>I thought it might have been the way my grid implementation was handling
>>keys but I have a notebook tab without a grid and it behaves the same.
>
>
>>Am I making sense?
>
>
> Yes.
>
> - Josiah
>
>
>
>
>
>>Josiah Carlson wrote:
>>
>>>paul sorenson <sourceforge@metrak.com> wrote:
>>>
>>>
>>>>I have several notebook tabs with wxGrids in them. When I click on a
>>>>notetab, the first cell of the grid appears to have focus (dark border)
>>>>but when I hit the right/left arrow key, the note tabs change, not the cell.
>>>>
>>>>I am pretty sure this behaviour changed somewhere between wxPython 2.4
>>>>and 2.6.
>>>>
>>>>Any clues on how to fix this please?
>>>
>>>
>>>def OnPageChanged(evt):
>>> new = evt.GetSelection()
>>> sel = nb.GetSelection()
>>> if new == sel:
>>> nb.GetPage(sel).SetFocus()
>>> evt.Skip()
>>>
>>>nb.Bind(wx.EVT_SELECTION_CHANGED, OnPageChanged)
>>>
>>>
>>> - Josiah
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Josiah Carlson wrote:
Get the control that you want to have focus on the page that is selected,
then use the method I already described.
- Josiah
That was going to be my last resort - it seems like I am doing the work of the windowing environment. I am going to have to find out which control should have the focus then set the focus. Since there are quite different structures in each notebook, it is not obvious how to come up with a generic approach. Also, since I am (almost) certain this used to work 'as expected' in wx 2.4, I wonder if something has become accidentally broken.
cheers
Presumably you create a wx.Panel or wx.Window to insert into the
notebook control for each page. During those creations, you can decide
on a 'default' control to be selected, and assign it to a 'default'
member.
Alternatively, with a bit of work, you can bind some wx.EVT_SET_FOCUS
events to remember the last control focused on in a per-page manner,
then when swapping pages, give that control focus...
def bind_focus_events(root, *controls):
for control in controls:
def f(e, c=control):
root.default = c
e.Skip()
control.Bind(wx.EVT_SET_FOCUS, f)
#in each __init__ method for each page in the notebook...
self.default = self
bind_focus_events(self, *(<list of controls>))
- Josiah
···
paul sorenson <sourceforge@metrak.com> wrote:
Josiah Carlson wrote:
> Get the control that you want to have focus on the page that is selected,
> then use the method I already described.
>
> - Josiah
That was going to be my last resort - it seems like I am doing the work
of the windowing environment. I am going to have to find out which
control should have the focus then set the focus. Since there are quite
different structures in each notebook, it is not obvious how to come up
with a generic approach. Also, since I am (almost) certain this used to
work 'as expected' in wx 2.4, I wonder if something has become
accidentally broken.
Thanks for the ideas. It is clearly doable, but it seems like an inordinate amount of work.
It wouldn't be so bad if the cell with "pseudo focus" didn't look like it had the focus.
Josiah Carlson wrote:
···
paul sorenson <sourceforge@metrak.com> wrote:
Josiah Carlson wrote:
Get the control that you want to have focus on the page that is selected,
then use the method I already described.
- Josiah
That was going to be my last resort - it seems like I am doing the work of the windowing environment. I am going to have to find out which control should have the focus then set the focus. Since there are quite different structures in each notebook, it is not obvious how to come up with a generic approach. Also, since I am (almost) certain this used to work 'as expected' in wx 2.4, I wonder if something has become accidentally broken.
Presumably you create a wx.Panel or wx.Window to insert into the
notebook control for each page. During those creations, you can decide
on a 'default' control to be selected, and assign it to a 'default'
member.
Alternatively, with a bit of work, you can bind some wx.EVT_SET_FOCUS
events to remember the last control focused on in a per-page manner,
then when swapping pages, give that control focus...
def bind_focus_events(root, *controls):
for control in controls:
def f(e, c=control):
root.default = c
e.Skip()
control.Bind(wx.EVT_SET_FOCUS, f)
#in each __init__ method for each page in the notebook...
self.default = self
bind_focus_events(self, *(<list of controls>))
- Josiah
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Tuesday, December 6, 2005, 5:18:30 AM, paul sorenson wrote:
I have several notebook tabs with wxGrids in them. When I click on a
notetab, the first cell of the grid appears to have focus (dark
border) but when I hit the right/left arrow key, the note tabs
change, not the cell.
I am pretty sure this behaviour changed somewhere between wxPython
2.4 and 2.6.
Any clues on how to fix this please?
...
nb = wx.Notebook(spam, eggs)
...
self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
...
def _doAfterPageChanged(self):
self.nb.GetPage(self.nb.GetSelection()).SetFocus()
def OnPageChanged(self, evt):
evt.Skip()
wx.CallAfter(self._doAfterPageChanged)
-- tacao
No bits were harmed during the making of this e-mail.