473,473 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

wxGrid and Focus Event

lux
Hi,
How can I capture the EVT_SET_FOCUS on a wxGrid?

Tank's in advance
Luca

Nov 29 '05 #1
10 4613
lux wrote:
How can I capture the EVT_SET_FOCUS on a wxGrid?


If you want to catch when the grid as a whole gets the focus, use:
grid.Bind(wx.grid.EVT_SET_FOCUS, self.onGridFocus)

If you want to catch when a cell in the grid gets the focus, use:
grid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.onCellSelected)

And, your questions will be better on the wxpython-users list at
http://wxpython.org/maillist.php
--
Paul McNett
http://paulmcnett.com
http://dabodev.com

Nov 29 '05 #2
Paul McNett wrote:
lux wrote:
How can I capture the EVT_SET_FOCUS on a wxGrid?

If you want to catch when the grid as a whole gets the focus, use:
>>> grid.Bind(wx.grid.EVT_SET_FOCUS, self.onGridFocus)
Oops, my bad:
grid.Bind(wx.EVT_SET_FOCUS, self.onGridFocus)

If you want to catch when a cell in the grid gets the focus, use:
>>> grid.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.onCellSelected)

And, your questions will be better on the wxpython-users list at
http://wxpython.org/maillist.php

--
Paul McNett
http://paulmcnett.com
http://dabodev.com

Nov 29 '05 #3
lux
Can you try this code?

If you press only the TAB key
the focus go from the TextCtrl to the Grid (I suppose)
but onGridFocus in not called.

any idea?
Luca.
##################

import wx
import wx.grid

app = wx.PySimpleApp()

f = wx.Frame(None, -1, "")
p = wx.Panel(f, -1)
s = wx.BoxSizer(wx.VERTICAL)

t1 = wx.TextCtrl(p)
s.Add(t1)

g = wx.grid.Grid(p, -1)
g.CreateGrid(2, 2)
s.Add(g, 1, wx.EXPAND)

def onGridFocus(evt):
print "onGridFocus"
evt.Skip()

def onCellSelected(evt):
print "onCellSelected"
evt.Skip()

g.Bind(wx.grid.EVT_GRID_SELECT_CELL, onCellSelected)
g.Bind(wx.EVT_SET_FOCUS, onGridFocus)

p.SetSizer(s)
f.Show()

app.MainLoop()

##################

Nov 29 '05 #4
lux wrote:
Can you try this code?
Sure, thanks for posting it!

If you press only the TAB key
the focus go from the TextCtrl to the Grid (I suppose)
but onGridFocus in not called.
Confirmed, at least on Gtk.

any idea?


Yep, the grid is actually a collection of subwindows, and I made the guess that
the first window to get the focus is actually that little corner window at the
intersection of the column labels and the row labels. Try this instead:
g.GetGridCornerLabelWindow().Bind(wx.EVT_SET_FOCUS , onGridFocus)

--
Paul McNett
http://paulmcnett.com
http://dabodev.com

Nov 29 '05 #5
lux
TANKS!!!
Now it work!!!

Luca

Nov 29 '05 #6
lux wrote:
TANKS!!!
Now it work!!!


Not so fast. I've found out that I had to do the following ugly workaround to
ensure it works in all cases:

def _initEvents(self):
...
if self.BaseClass.__name__ == "dGrid":
## Ugly workaround for grids not firing focus events from the keyboard
## correctly.
self._lastGridFocusTimestamp = 0.0
self.GetGridCornerLabelWindow().Bind(wx.EVT_SET_FO CUS, self.__onWxGotFocus)
self.GetGridColLabelWindow().Bind(wx.EVT_SET_FOCUS , self.__onWxGotFocus)
self.GetGridRowLabelWindow().Bind(wx.EVT_SET_FOCUS , self.__onWxGotFocus)
self.GetGridWindow().Bind(wx.EVT_SET_FOCUS, self.__onWxGotFocus)
self.Bind(wx.EVT_SET_FOCUS, self.__onWxGotFocus)
...
def __onWxGotFocus(self, evt):
if self.BaseClass.__name__ == "dGrid":
## Continuation of ugly workaround for grid focus event. Only raise the
## Dabo event if we are reasonably sure it isn't a repeat.
prev = self._lastGridFocusTimestamp
now = self._lastGridFocusTimestamp = time.time()
if now-prev < .05:
return
self.raiseEvent(dEvents.GotFocus, evt)

--
Paul McNett
http://paulmcnett.com
http://dabodev.com

Nov 29 '05 #7
So Paul, are you saying there's a bug with the wxGrid control and if so,
do you know if there's been a bug-report submitted to the wxWidgets
and/or wxPython folks?
Or is this just the way the wxGrid control works?
Thanks!
Paul McNett wrote:
Not so fast. I've found out that I had to do the following ugly
workaround to ensure it works in all cases:

Nov 30 '05 #8
Bugs wrote:
So Paul, are you saying there's a bug with the wxGrid control and if so,
Yes, I think it is a bug.

do you know if there's been a bug-report submitted to the wxWidgets
and/or wxPython folks?
I don't know, but I've been meaning to check.

Or is this just the way the wxGrid control works?
Thanks!


wxPython/wxWidgets, like any GUI toolkit, is pretty complex. For the most part
all the commonly-needed things work just fine - it is when you venture into the
less-used things that you get into trouble.

If I filed a proper bug report for everything wrong with wxPython/wxWidgets, I'd
probably not get anything else done. But on the other hand you couldn't force me
to stop using wxPython if you tried!
--
Paul McNett
http://paulmcnett.com
http://dabodev.com

Nov 30 '05 #9
Paul McNett wrote:

If I filed a proper bug report for everything wrong with
wxPython/wxWidgets, I'd probably not get anything else done. But on the
other hand you couldn't force me to stop using wxPython if you tried!


Like any open-source software, the community is what makes it better.
I agree, it's still a great toolkit even with the bugs.
But think how much better a toolkit it would be with fewer bugs! =)

Thanks Paul
Nov 30 '05 #10
Paul McNett wrote:
Bugs wrote:
So Paul, are you saying there's a bug with the wxGrid control and if so,


Yes, I think it is a bug.


I'm not so sure. I seem to remember being told on the mailing list
that I had to check the specific sub-window for events. Even if it's
by design, it's certainly questionable whether this behaviour is
sane though. I guess it's a wxWidgets issue rather than a wxPython
issue though.
Dec 5 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tom Lee | last post by:
# # Python 2.2.3, wxWindows/wxPython 2.4.1 # # The code: # from wxPython.wx import * class TestFrame( wxFrame ): def __init__( self ):
0
by: Kepes Krisztian | last post by:
Hi ! My problem is that: 1.) I want to create a frame with some buttons, and client area. If the user clicked on a button, the procedure create components on client area, and show results.
1
by: matthiasjanes | last post by:
dear all, I just need a little help. could anyone give real code example (simple) how to read the value of a grid cell. i could not figure it out and really would like to do a simple...
4
by: Piet | last post by:
Hello. I am working on an XML editor that will not display the xml file as plain text, but will rather work with a combination of a tree view for the main element nodes and some kind of tabular...
1
by: James | last post by:
wxpython 2.5.3 hi, anyone know how to make a multiline cell editor for wxgrid? thank you :) best regards, James
2
by: Peter Wright | last post by:
Hi all. Hopefully this should demonstrate the problem I'm having: http://flooble.net/~pete/focus-problem-demo/ (I'm testing it in Mozilla only, but I'm not sure if it's actually a...
17
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
3
Subsciber123
by: Subsciber123 | last post by:
Hi, I'm using Python 2.6, and I'm trying to write a gui program that uses wxGrid. I have made it so that the columns can be dragged around to different locations, but I need to bind to an event that...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.