Giving an id to an event

Hello,

Some while ago I developed ThreadTimer, to have a timer that is more
reliable even when wxPython is busy. Here's the message:
http://groups.google.com/group/wxpython-users/msg/a50ed1a93c46b2ca

(The code for it has evolved a bit since then, but it's still the same
principle.)

Now I have a problem with it. When I do
`self.Bind(thread_timer.EVT_THREAD_TIMER, some_method)`, I want to be
able to use the id/source parameters of the `Bind` method. I want to
be able to differentiate between different ThreadTimer events.

What would be a good way to this?

I've tried sticking some random number like this: `event =
wx.PyEvent(1138)`, and this works and would let me differentiate as I
wish, but I don't want to conflict with wxPython's id scheme.

Thanks,
Ram.

Hi,

Hello,

Some while ago I developed ThreadTimer, to have a timer that is more
reliable even when wxPython is busy. Here's the message:
http://groups.google.com/group/wxpython-users/msg/a50ed1a93c46b2ca

For some reason I am pretty sure I remember that being somebody else's idea...

(The code for it has evolved a bit since then, but it's still the same
principle.)

Now I have a problem with it. When I do
`self.Bind(thread_timer.EVT_THREAD_TIMER, some_method)`, I want to be
able to use the id/source parameters of the `Bind` method. I want to
be able to differentiate between different ThreadTimer events.

What would be a good way to this?

I've tried sticking some random number like this: `event =
wx.PyEvent(1138)`, and this works and would let me differentiate as I
wish, but I don't want to conflict with wxPython's id scheme.

Just do it like any other widget does. Give the thread an ID when you create it.

ID_THREAD1 = wx.NewId()
ThreadTimer(parent, id)

Then just store the ID and use it when the thread fires its events.

Cody

···

On Apr 2, 2010, at 6:50 AM, cool-RR wrote:

Hi,

Hello,

Some while ago I developed ThreadTimer, to have a timer that is more

reliable even when wxPython is busy. Here’s the message:

http://groups.google.com/group/wxpython-users/msg/a50ed1a93c46b2ca

For some reason I am pretty sure I remember that being somebody else’s idea…

That’s right, ThreadTimer was your idea that you suggested and it solved my problem. You wrote the original code and I developed it further. Thus it can be said we have both developed ThreadTimer. I was not trying to claim I invented it.

(The code for it has evolved a bit since then, but it’s still the same

principle.)

Now I have a problem with it. When I do

self.Bind(thread_timer.EVT_THREAD_TIMER, some_method), I want to be

able to use the id/source parameters of the Bind method. I want to

be able to differentiate between different ThreadTimer events.

What would be a good way to this?

I’ve tried sticking some random number like this: `event =

wx.PyEvent(1138)`, and this works and would let me differentiate as I

wish, but I don’t want to conflict with wxPython’s id scheme.

Just do it like any other widget does. Give the thread an ID when you create it.

ID_THREAD1 = wx.NewId()

ThreadTimer(parent, id)

Then just store the ID and use it when the thread fires its events.

Sounds great, this is exactly what I was hoping wxPython will provide me. I’ll use it.

Thanks.

···

On Fri, Apr 2, 2010 at 2:17 PM, Cody Precord codyprecord@gmail.com wrote:

On Apr 2, 2010, at 6:50 AM, cool-RR wrote:

And if you give ThreadTimer a GetId() method then you can use it as the source parameter in Bind().

···

On 4/2/10 5:28 AM, cool-RR wrote:

    Just do it like any other widget does. Give the thread an ID when
    you create it.

    ID_THREAD1 = wx.NewId()
    ThreadTimer(parent, id)

    Then just store the ID and use it when the thread fires its events.

Sounds great, this is exactly what I was hoping wxPython will provide
me. I'll use it.

--
Robin Dunn
Software Craftsman

Which is exactly what I did :slight_smile:

Ram.

···

On Fri, Apr 2, 2010 at 7:35 PM, Robin Dunn robin@alldunn.com wrote:

Sounds great, this is exactly what I was hoping wxPython will provide

me. I’ll use it.

And if you give ThreadTimer a GetId() method then you can use it as the source parameter in Bind().

Robin Dunn

Software Craftsman

http://wxPython.org