473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Wxpython, using more than 1 timer?

Hi all,

Using wx
When adding a second timer as i have the first, the second timer
adding stops the first timer (updating or stops?) . In this example im
updating a uptime and localtime label. It works fine for displaying the
last "self.startTimer2()" called. But prevents the previous
self.startTimer1() from running . Im doing something fundamentally
wrong i guess?

def __init__(self, parent):
self._init_ctrls(parent)

#Start timers
self.startTimer1()
self.startTimer2()

def startTimer1(self):
self.t1 = wx.Timer(self)
self.t1.Start(360) # 360000 ms = 1/10 hour
self.Bind(wx.EVT_TIMER, self.OnUpTime)

def startTimer2(self):
self.t2 = wx.Timer(self)
self.t2.Start(1000) # run every second
self.Bind(wx.EVT_TIMER, self.OnTime)

def OnTime(self,evt):
self.lblTime.SetLabel(str(time.localtime()))

def OnUpTime(self, evt):
self.lblUptime.SetLabel('Running ' + (str(myTimerText[0])) + '
hours') # 1/10 hour count
myTimerText[0] = myTimerText[0] + .1

Any help appreciated, ta

Jul 22 '06 #1
2 4642
janama wrote:
Hi all,

Using wx
When adding a second timer as i have the first, the second timer
adding stops the first timer (updating or stops?) . In this example im
updating a uptime and localtime label. It works fine for displaying the
last "self.startTimer2()" called. But prevents the previous
self.startTimer1() from running . Im doing something fundamentally
wrong i guess?

def __init__(self, parent):
self._init_ctrls(parent)

#Start timers
self.startTimer1()
self.startTimer2()

def startTimer1(self):
self.t1 = wx.Timer(self)
self.t1.Start(360) # 360000 ms = 1/10 hour
self.Bind(wx.EVT_TIMER, self.OnUpTime)

def startTimer2(self):
self.t2 = wx.Timer(self)
self.t2.Start(1000) # run every second
self.Bind(wx.EVT_TIMER, self.OnTime)

def OnTime(self,evt):
self.lblTime.SetLabel(str(time.localtime()))

def OnUpTime(self, evt):
self.lblUptime.SetLabel('Running ' + (str(myTimerText[0])) + '
hours') # 1/10 hour count
myTimerText[0] = myTimerText[0] + .1

Any help appreciated, ta
The problem is not that the first timer ist stopped, the problem is
that both timers happen to call the same method in the end.

Think of the "Bind" method as an assignment: it assigns a handler
function to an event source. If you call it twice for the same event
source, the second call will overwrite the first event handler. That's
what happens in your code.

The easiest way to change this is by using different ids for the
timers:

def startTimer1(self):
self.t1 = wx.Timer(self, id=1)
self.t1.Start(2000)
self.Bind(wx.EVT_TIMER, self.OnUpTime, id=1)

def startTimer2(self):
self.t2 = wx.Timer(self, id=2)
self.t2.Start(1000)
self.Bind(wx.EVT_TIMER, self.OnTime, id=2)

This way, the timers launch two different events, which are bound to
two different methods.

Jul 22 '06 #2
Thanks for that, cheers

Regards
nikie wrote:
janama wrote:
Hi all,

Using wx
When adding a second timer as i have the first, the second timer
adding stops the first timer (updating or stops?) . In this example im
updating a uptime and localtime label. It works fine for displaying the
last "self.startTimer2()" called. But prevents the previous
self.startTimer1() from running . Im doing something fundamentally
wrong i guess?

def __init__(self, parent):
self._init_ctrls(parent)

#Start timers
self.startTimer1()
self.startTimer2()

def startTimer1(self):
self.t1 = wx.Timer(self)
self.t1.Start(360) # 360000 ms = 1/10 hour
self.Bind(wx.EVT_TIMER, self.OnUpTime)

def startTimer2(self):
self.t2 = wx.Timer(self)
self.t2.Start(1000) # run every second
self.Bind(wx.EVT_TIMER, self.OnTime)

def OnTime(self,evt):
self.lblTime.SetLabel(str(time.localtime()))

def OnUpTime(self, evt):
self.lblUptime.SetLabel('Running ' + (str(myTimerText[0])) + '
hours') # 1/10 hour count
myTimerText[0] = myTimerText[0] + .1

Any help appreciated, ta

The problem is not that the first timer ist stopped, the problem is
that both timers happen to call the same method in the end.

Think of the "Bind" method as an assignment: it assigns a handler
function to an event source. If you call it twice for the same event
source, the second call will overwrite the first event handler. That's
what happens in your code.

The easiest way to change this is by using different ids for the
timers:

def startTimer1(self):
self.t1 = wx.Timer(self, id=1)
self.t1.Start(2000)
self.Bind(wx.EVT_TIMER, self.OnUpTime, id=1)

def startTimer2(self):
self.t2 = wx.Timer(self, id=2)
self.t2.Start(1000)
self.Bind(wx.EVT_TIMER, self.OnTime, id=2)

This way, the timers launch two different events, which are bound to
two different methods.
Jul 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jblazi | last post by:
I am having this problem: I use Python for my teaching and right now we are trying to implement some sort of very simple graphical game the pupils can play across the Internet. For this, we use...
8
by: Erik Johnson | last post by:
I am looking for some input on GUI libraries. I want to build a Python-driven GUI, but don't really understand the playing field very well. I have generally heard good things about wxPython. I...
2
by: Daniel Bickett | last post by:
Hello, I am writing an application using two event-driven libraries: wxPython, and twisted. The first problem I encountered in the program is the confliction between the two all-consuming...
8
by: Jan Danielsson | last post by:
Hello all, I wanted to plot some statistics, so I wrote a simple wxPython class to do it. Then I realized that I would like to draw bar graphs, so I added that too. Since I'm a complete...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
6
by: sbernste | last post by:
I am using wx.Timer to update a clock on a wxPython display. The relevant lines of code look like this: timer = wx.Timer(self, -1) self.Bind(wx.EVT_TIMER, self.onTick, timer) ...
7
by: Terry Carroll | last post by:
I'm trying to use wx.ProgressBar, and the cancel button is not responding. Here is a simple program that exhibits the problem: ######################################################### import...
2
by: whatazor | last post by:
Hi all, I migrate some code from tkinter to wxpython. I need the equivalent Tkinter method Tkinter.Tk.after in wxPython, but I'm not able to find it. It exist or there are other trick to emulate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.