Entry
How do I make a cursor or selected item blink?
Jun 5th, 2002 06:29
Michael Chermside,
Most of the time, you won't need to, since the existing controls already
have this kind of thing built in. But if you are creating your own
control, you may find it necessary. Here is a solution:
* Use a variable to track what is selected/where the cursor is
* Create a timer
* In processing the timer's event, draw with the logic mode set to
inverse
An example is worth 1000 words:
<In the __init__ for my control: >
self.selected = None # at first...
timerId = wxNewId()
self.timer = wxTimer(self, timerId)
self.timer.Start(500) # every 500 milliseconds
EVT_TIMER(self, timerId, self.onTimer)
<In my onClick method, where an item gets selected: >
def onClick(self, event):
if self.selected:
# Clear hilighting from previous selection
dc = wxClientDC(self)
self.selected.draw(dc)
x, y = event.GetPosition()
self.selected = self.findItemAt(x, y)
<The onTimer method: >
def onTimer(self, event):
if self.selected:
dc = wxClientDC(self)
dc.SetLogicalFunction(wxINVERT)
self.selected.drawInBlack(dc)