About how the set the timer in wxpython

hello,

I have faced a problem that is almost as same as the problem below:

((((If I try to define a timer in an ogl.BitmapShape, like this:

class T6963_device (ogl.BitmapShape):
def __init__(self):
ogl.BitmapShapeinit__ (self)
self.t1 = wx.Timer (self)

I get this error

Traceback (most recent call last):
File "D:\data_to_test\smtest2.py", line 516, in ?
LCD_init ( frame )
File "D:\data_to_test\T6963c.py", line 337, in LCD_init
LCD = T6963_device()
File "D:\data_to_test\T6963c.py", line 107, in __init__
self.t1 = wx.Timer (self)
File "P:\Python\Lib\site-packages\wx-2.8-msw-ansi\wx\_misc.py", line
1279, in __init__
_misc_.Timer_swiginit(self,_misc_.new_Timer(*args, **kwargs))
TypeError: in method 'new_Timer', expected argument 1 of type
'wxEvtHandler *'

If I add the same timer definition to my main form, like this

class My_MainForm(wx.Frame):
def __init__(self):
wx.Frameinit__( self, None, -1, 'JAL Functional Simulator' ,
pos=(0,0), size=(640,480))

# Finally show the mainform
self.Show()

self.t1 = wx.Timer (self)
self.Bind(wx.EVT_TIMER, Timer)
self.t1.Start ( 1000 )

def Timer (self, event):
print 'aap'

everything works perfect.

Why can't I define a timer in an ogl.BitmapShape ?
In which (derived) objects can I define a Timer ?)))))

I think the reason is that ((((Because ogl.BitmapShape is not a
subclass of wx.EvtHandler))))

But how can I set it as a subclass of wx.evthandler?

thank you very much

Andy

Why can't I define a timer in an ogl.BitmapShape ?
In which (derived) objects can I define a Timer ?)))))

I think the reason is that ((((Because ogl.BitmapShape is not a
subclass of wx.EvtHandler))))

Correct. That is what the exception is telling you.

But how can I set it as a subclass of wx.evthandler?

You probably can't. Being a subclass of another class is defined by the class hierarchy, not by properties you can set. You can try deriving your shape class from both ogl.BitmapShape and wx.EvtHandler, but that could cause some unforeseen problems.

Instead you could associate the timer with the canvas, Bind the event to the canvas, and use the method in your shape class as the event handler. Something like this:

     if self.GetCanvas():
         self.t1 = wx.Timer(self.GetCanvas())
         self.GetCanvas().Bind(wx.EVT_TIMER, self.Timer, self.t1)

Note that this can't be done until after the shape has been added to the canvas.

···

On 3/30/10 8:51 AM, Andy_long wrote:

--
Robin Dunn
Software Craftsman