Hi Steve,
When I tried the cursor’s IsSameAs()
method on linux, it gave some interesting results.
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Cursor Check')
self.panel = wx.Panel(self)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.text_ctrl = wx.TextCtrl(self.panel, -1)
self.sizer.Add(self.text_ctrl)
self.panel.SetSizer(self.sizer)
self.Bind(wx.EVT_CHAR_HOOK, self.OnKey)
self.cross_cursor = wx.Cursor(wx.CROSS_CURSOR)
self.arrow_cursor = wx.Cursor(wx.CURSOR_ARROW)
self.ibeam_cursor = wx.Cursor(wx.CURSOR_IBEAM)
self.panel.SetCursor(self.cross_cursor)
def OnKey(self, event):
keycode = event.GetKeyCode()
modifiers = event.GetModifiers()
if modifiers == wx.MOD_CONTROL and keycode == ord('P'):
panel_cursor = self.panel.GetCursor()
print("CROSS_CURSOR", panel_cursor.IsSameAs(self.cross_cursor))
print("ARROW_CURSOR", panel_cursor.IsSameAs(self.arrow_cursor))
print("IBEAM_CURSOR", panel_cursor.IsSameAs(self.ibeam_cursor))
elif modifiers == wx.MOD_CONTROL and keycode == ord('S'):
self.panel.SetCursor(self.arrow_cursor)
else:
event.Skip()
if __name__ == "__main__":
app = wx.App()
frame = MyFrame()
frame.Show()
app.MainLoop()
If I run the above code, it sets the panel’s cursor to wx.CROSS_CURSOR
. If I then press Ctrl+P
it prints out:
CROSS_CURSOR True
ARROW_CURSOR False
IBEAM_CURSOR False
If I then press Ctrl+S
it sets the panel’s cursor to wx.CURSOR_ARROW
. If I then press Ctrl+P
it prints out:
CROSS_CURSOR False
ARROW_CURSOR True
IBEAM_CURSOR False
However, if I then position the mouse pointer over the TextCtrl
and press Ctrl+P
it still prints out:
CROSS_CURSOR False
ARROW_CURSOR True
IBEAM_CURSOR False
I assume that, although the visible cursor in the TextCtrl
is different, the Panel
itself is still set to the ARROW_CURSOR.
[Tested using Python 3.10.6 + wxPython 4.2.1 gtk3 (phoenix) wxWidgets 3.2.2.1 on Linux Mint 21.1]