determine the absolute position of a cell

30 views
Skip to first unread message

Fabio Spadaro

unread,
Dec 15, 2009, 5:05:54 PM12/15/09
to wxPytho...@googlegroups.com

Many people know that to determine the absolute position (relative to the screen) of a window using the method getscreenposition. Unfortunately, this method can not be used to determine the precise location of grid's cell.
I need to know the cell's location because I load a frame the time of creation of CreateCellEditor.
there is some other solution to getscreenposition?

--
Fabio Spadaro
www.fabiospadaro.com

Mike Driscoll

unread,
Dec 16, 2009, 10:38:55 AM12/16/09
to wxPython-users
Hi Fabio,
What you probably want to do it this:

1) Bind your grid to EVT_MOTION like this:

self.MyGrid.GetGridColLabelWindow().Bind(wx.EVT_MOTION,
self.onMouseOver)

2) In the event handler, grab the mouse position using something like
this:

pos = event.GetX()

3) Use that information to know where to put your frame.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Fabio Spadaro

unread,
Dec 16, 2009, 10:56:52 AM12/16/09
to wxpytho...@googlegroups.com
Hi,

2009/12/16 Mike Driscoll <kyos...@gmail.com>
> --
> To unsubscribe, send email to wxPython-user...@googlegroups.com
> or visit http://groups.google.com/group/wxPython-users?hl=en

But the mouse event is not the only possible event as you may also use
the key event ...

--
Fabio Spadaro
www.fabiospadaro.com

Mike Driscoll

unread,
Dec 16, 2009, 12:02:26 PM12/16/09
to wxPython-users
Hi,

On Dec 16, 9:56 am, Fabio Spadaro <fabiolinos...@gmail.com> wrote:
> Hi,
>
> 2009/12/16 Mike Driscoll <kyoso...@gmail.com>
>
>
>
>
>
> > Hi Fabio,
>
> > On Dec 15, 4:05 pm, Fabio Spadaro <fabiolinos...@gmail.com> wrote:
> > > Many people know that to determine the absolute position (relative to the
> > > screen) of a window using the method getscreenposition. Unfortunately, this
> > > method can not be used to determine the precise location of grid's cell.
> > > I need to know the cell's location because I load a frame the time of
> > > creation of CreateCellEditor.
> > > there is some other solution to getscreenposition?
>
> > > --
> > > Fabio Spadaro
>
> > What you probably want to do it this:
>
> > 1) Bind your grid to EVT_MOTION like this:
>
> > self.MyGrid.GetGridColLabelWindow().Bind(wx.EVT_MOTION,
> > self.onMouseOver)
>
> > 2) In the event handler, grab the mouse position using something like
> > this:
>
> > pos = event.GetX()
>
> > 3) Use that information to know where to put your frame.
>
> > -------------------
> > Mike Driscoll
>
> > Blog:  http://blog.pythonlibrary.org
>
> > --
> > To unsubscribe, send email to wxPython-user...@googlegroups.com
> > or visithttp://groups.google.com/group/wxPython-users?hl=en
>
> But the mouse event is not the only possible event as you may also use
> the key event ...
>
> --
> Fabio Spadaro

Well, you could bind to this instead:

self.myGrid.Bind(gridlib.EVT_GRID_EDITOR_CREATED, self.onCellEdit)

Then in the handler, get a handle on the control:

editor = event.GetControl()

and maybe this will work:

editor.GetScreenPosition()

I'm not sure though.

Robin Dunn

unread,
Dec 16, 2009, 3:48:35 PM12/16/09
to wxpytho...@googlegroups.com
Something like this should do it:

r = theGrid.CellToRect(row, col)
screenPos = theGrid.GetGridWindow().ClientToScreen(r.position)


--
Robin Dunn
Software Craftsman
http://wxPython.org

Fabio Spadaro

unread,
Dec 16, 2009, 5:13:44 PM12/16/09
to wxpytho...@googlegroups.com
Hi

2009/12/16 Robin Dunn <ro...@alldunn.com>:
ok your solution does work but How do I calculate the displacement of
scrolled coordinates ?

--
Fabio Spadaro
www.fabiospadaro.com
Reply all
Reply to author
Forward
0 new messages