Hi all,
I just stumbled on a possible cross platform inconsistency regarding
evt.GetPosition() (wx.EVT_LEFT_UP).
I need to get the position, where the image (placed in a
ScrolledWindow) was clicked on.
on windows (XPp SP3) I used the obvious evt.GetPosition(), but on
Linux (Kubuntu 8.04) the scrolled offset isn't taken into account.
(wxpython 2.8.10.1).
The attached file should demonstrate the problem. After scrolling the
image a bit and clicking on it, the clicked position relative to the
image is shown in title bar.
On windows both values are the same, on linux the second one is
relative to the visible rectangle (even on if the image is scrolled
away from the initial position).
A replacement:
evt.GetEventObject().ScreenToClient(wx.GetMousePosition())
seems to be working identically on both platforms.
Did I used the event method wrongly or is it a known issue?
Aren't there any drawbacks of the workaround, which I am missing now?
Thanks in advance,
Vlasta
ScrolledWindow_evt_position.py (794 Bytes)
···
##############################################
#! Python
# -*- coding: utf-8 -*-
import wx
def test_mouse_pos(evt):
bmp_mouse_pos = evt.GetEventObject().ScreenToClient(wx.GetMousePosition())
evt_pos = evt.GetPosition()
frm.SetTitle("mouse-pos: " + str(bmp_mouse_pos)+ " - evt-pos: " +
str(evt_pos))
evt.Skip()
appl = wx.App(redirect=False)
frm = wx.Frame(None, -1, "ShowPosition - test")
scr_win = wx.ScrolledWindow(frm)
scr_win.SetScrollbars(1, 1, 2000, 2000, 0, 0)
static_bmp = wx.StaticBitmap(scr_win, -1,
wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, size=(1820,1800)))
scr_win.SetScrollbars(1, 1, 2000, 2000, 0, 0)
img_sizer = wx.BoxSizer(wx.VERTICAL)
img_sizer.Add(static_bmp)
scr_win.SetSizer(img_sizer)
static_bmp.Bind(wx.EVT_LEFT_UP, test_mouse_pos)
frm.Show()
appl.MainLoop()
##############################################