Cursor offset issue

Hi there,

Have been creating an application on Mac OS X using wxPython recently and
came across a slight oddity where the cursor click events on a panel seemed
to be offset by a few pixels to the actual generated drawing. Thus it would
seem like a click was generated outside of a window/panel.

E.g.

X clicked here
  ----------------------- : Panel

···

o drew point here |

  > >
  > >
  -----------------------

To illustrate this I created a test (see below) where I began to wonder if
the mouse event position and the paint position were in fact the same and it
was the cursor icon itself that was offset. It seems that with my setup the
cursor hotspot for the mouse down event is out by 1x, 2y pixels.

Is there a way to globally change the hotspot offset or fix this some how if
indeed I am on the right path here?

Ta,

Martin Pengelly-Phillips

Example App
-----------------

import wx

# MyPanel
#----------------------------------------------
class MyPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)
        self.points = []
        self.SetMinSize(wx.Size(200, 200))
        self.Bind(wx.EVT_PAINT, self.onPaint)
        self.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown)
        
    def onPaint(self, event):
        w, h = self.GetClientSize()
        dc = wx.BufferedPaintDC(self)
        dc.SetBackground(wx.Brush(wx.WHITE))
        dc.Clear()
        for point in self.points:
            dc.DrawPoint(point.x, point.y)
            dc.DrawText("%d,%d" % (point.x, point.y), point.x, point.y)
        
    def onLeftDown(self, event):
        self.points.append(event.GetPosition())
        self.Refresh()
    
# MyFrame
#----------------------------------------------
class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.box = wx.BoxSizer(wx.VERTICAL)
        self.panel = MyPanel(self)
        self.clear = wx.Button(self, label="Clear")
        self.box.Add(self.panel, 1, wx.EXPAND|wx.ALL, border=15)
        self.box.Add(self.clear, 0, wx.EXPAND|wx.ALL, border=5)
        self.clear.Bind(wx.EVT_BUTTON, self.onClear)
        self.SetSizerAndFit(self.box)
        
    def onClear(self, event):
        self.panel.points = []
        self.panel.Refresh()

# main entry
#----------------------------------------------
if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(None, title="Mismatched")
    frame.Centre()
    frame.Show()
    app.MainLoop()

Martin wrote:

Hi there,

Have been creating an application on Mac OS X using wxPython recently and
came across a slight oddity where the cursor click events on a panel seemed
to be offset by a few pixels to the actual generated drawing. Thus it would
seem like a click was generated outside of a window/panel.

E.g.

X clicked here ----------------------- : Panel
  > o drew point here |
  > >
  -----------------------

To illustrate this I created a test (see below) where I began to wonder if
the mouse event position and the paint position were in fact the same and it
was the cursor icon itself that was offset. It seems that with my setup the
cursor hotspot for the mouse down event is out by 1x, 2y pixels.

It looks to me like the hotspot is under the black tip of the arrow, not at the point of the image (in the white or grey area.) I expect that it is this way by design.

Is there a way to globally change the hotspot offset or fix this some how if
indeed I am on the right path here?

You can create your own cursor image, specify the hotspot where you want it, and set that cursor for your window. See the sample in the demo.

···

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

Hi Robin,

Thanks for the quick reply, comments in place:

Martin wrote:

Hi there,

Have been creating an application on Mac OS X using wxPython recently and
came across a slight oddity where the cursor click events on a panel seemed
to be offset by a few pixels to the actual generated drawing. Thus it would
seem like a click was generated outside of a window/panel.

E.g.

X clicked here
  ----------------------- : Panel
  > o drew point here |
  > >
  > >
  -----------------------

To illustrate this I created a test (see below) where I began to wonder if
the mouse event position and the paint position were in fact the same and it
was the cursor icon itself that was offset. It seems that with my setup the
cursor hotspot for the mouse down event is out by 1x, 2y pixels.

It looks to me like the hotspot is under the black tip of the arrow, not
at the point of the image (in the white or grey area.) I expect that it
is this way by design.

Makes sense I guess as only the black area would be clearly visible in
certain conditions.

Is there a way to globally change the hotspot offset or fix this some how if
indeed I am on the right path here?

You can create your own cursor image, specify the hotspot where you want
it, and set that cursor for your window. See the sample in the demo.

Will do,

Ta,

Martin Pengelly-Phillips

···

On 28/6/06 21:34, "Robin Dunn" <robin@alldunn.com> wrote: