I've been having difficulty getting custom cursors to display
correctly on my Linux box (RHEL 5.0). I've read elsewhere that custom
cursors don't always display correctly on Macs, but haven't seen any
complaints for Linux installs. I am using wxPython 2.8.10.1. Below
is an example application where I set the cursor to invisible, so if
it works correctly, the mouse cursor should disappear when you mouse
over the window. Custom cursors do work correctly on my WinXP box,
which is also using wxPython 2.8.10.1
*Note - In the interest of full disclosure, I didn't write this
application; I just added the custom cursor. It was lifted from a
forum some time ago, and I just think it's neat.
import wx
class CanvasItem(object):
"""A virtual base class. All child classes need to define
self.DrawMethod
and set self.type"""
def __init__(self, parent, bbox, pen, brush):
self.parent = parent
self.bbox = bbox
self.pen = pen
self.brush = brush
def draw(self, DC):
DC.SetPen(self.pen)
DC.SetBrush(self.brush)
self.DrawMethod(DC, self.bbox)
class Oval(CanvasItem):
def __init__(self, parent, bbox, pen, brush):
CanvasItem.__init__(self, parent, bbox, pen, brush)
def DrawMethod(self, dc, bbox):
dc.DrawEllipse(bbox.x, bbox.y, bbox.width, bbox.height)
class Canvas(wx.Panel):
# Store IDS in order by leftmost edge for more efficient collision
detections.
def __init__(self, parent=None,id=wx.ID_ANY, pos =
wx.DefaultPosition,
size=wx.DefaultSize,style=wx.TAB_TRAVERSAL,name="panel"):
wx.Panel.__init__(self,parent,id,pos,size,style,name)
self.IDS = []
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self,event):
DC = wx.PaintDC(self)
for ID in self.IDS:
ID.draw(DC)
def create_oval(self, x0,y0,x1,y1,outline="black", fill="",
stipple="",
width=1,style=wx.SOLID):
print "Creating oval:",
x0,y0,x1,y1,outline,fill,stipple,width,style
pen = wx.Pen(outline.upper(),width,style)
if not fill:
fill = "BLACK"
style=wx.TRANSPARENT
elif stipple == "":
fill = outline.upper()
style = wx.SOLID
else:
fill = outline.upper()
style = wx.CROSS_HATCH # need to fix this with bitmap
stippling?!
brush = wx.Brush(fill,style)
self.IDS.append(Oval(self, wx.Rect(x0,y0,x1,y1), pen, brush))
app = wx.PySimpleApp(0)
app.frame = wx.Frame(parent=None, id=-1, size=(300,400))
app.frame.canvas = Canvas(parent=app.frame)
for i in range(10,300,10):
app.frame.canvas.create_oval(10,10,i,i)
myCursor= wx.StockCursor(wx.CURSOR_BLANK)
app.frame.SetCursor(myCursor)
app.frame.Show()
app.MainLoop()