Hi Everyone,

I am trying to call a function after every T secs . When i use time.wait() , the app hangs, i do not have control over the app.

For now , this programs will do the process once , and then after T secs . But i do not know , how to call the function Mail from inside OnTimer().

I think the logic is not right. Someone , show me the right direction plz.

Here's what i have:

import wx
import time

from email_count import *

class MainWindow(wx.Frame):
        def __init__(self, parent, id, title):
                wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(400,200), style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
                
                
                panel = wx.Panel(self, -1)
                
               

                #Introducting a timer

                self.timer = wx.Timer(self)
                self.Bind(wx.EVT_TIMER,self.OnTimer,self.timer)
                

                
                self.txt_Username = wx.TextCtrl(panel, 1, size=(125, -1))
                lbl_Username = wx.StaticText(panel, -1, "Username:")
                
                
                self.txt_Password = wx.TextCtrl(panel, 1, size=(125, -1), style=wx.TE_PASSWORD)
                lbl_Password = wx.StaticText(panel, -1, "Password:")
                
                
                btn_Process = wx.Button(panel, -1, "Process")
                self.Bind(wx.EVT_BUTTON, self.Process, btn_Process)
                
               
                btn_Close = wx.Button(panel, -1, "Close")
                self.Bind(wx.EVT_BUTTON, self.onExit, btn_Close)

                btn_Reset = wx.Button(panel, -1, "Reset")
                self.Bind(wx.EVT_BUTTON,self.Reset, btn_Reset)

                self.cb_Timer = wx.CheckBox(panel, -1, 'Timer', (250, 10))
                self.cb_Timer.SetValue(False)
                                
                
                
                sizer = wx.FlexGridSizer(rows=4, cols=2, hgap=5, vgap=10)
                sizer.Add(lbl_Username,0,wx.LEFT|wx.TOP| wx.RIGHT, 5)
                sizer.Add(self.txt_Username,0, wx.TOP| wx.RIGHT, 5)
                sizer.Add(lbl_Password,0, wx.LEFT|wx.TOP| wx.RIGHT, 5)
                sizer.Add(self.txt_Password,0, wx.TOP| wx.RIGHT, 5)
                sizer.Add(btn_Process,0, wx.LEFT|wx.TOP| wx.RIGHT, 5)
                sizer.Add(btn_Close,0, wx.TOP| wx.RIGHT, 5)
                sizer.Add(btn_Reset,0,wx.LEFT|wx.TOP,5)
                
                #-- Add the grid to the panel and make it fit
                panel.SetSizer(sizer)
                
                #-- Show the window that we've just built
                self.Show(True)
                
        def Process(self, event):
                
                mail1 = self.txt_Username.GetValue()
                pwd1 = self.txt_Password.GetValue()
                
                if self.cb_Timer.GetValue()==False:
                        self.Mail(event,mail1,pwd1)
                else:
                        self.Mail(event,mail1,pwd1) #Function gets called first time.
                        self.timer.Start(10000)
                        self.cb_Timer.SetValue(False) #I set this off as i want to avoid looping as for now.
                        print"wow this is not right"
                
                        
                        
                                                                                      
                
                                               
        def onExit(self,event):
                self.Close(True)
        def Reset(self,event):
                self.txt_Username.Clear()
                self.txt_Password.Clear()
        def Mail (self,event,m1 ,p1):
                cnt = count(m1,p1)
                message='Unread:'+str(cnt)
                d = wx.MessageDialog(self,message,"New mails:",wx.OK)
                d.ShowModal()
                d.Destroy()
        def OnTimer(self,event):
                print"So we are inside"
                self.timer.Stop()
                
                
        
        

app = wx.PySimpleApp()
frame = MainWindow(None,-1,"Enter Credentials")
app.MainLoop()

Here's the result.

Unread mails = 3
we are back in Process
So we are inside

Now i want the function Mail to be called after say 30 secs repeatedly.

I put (after removing the module for email check I do not have and putting constant value at line 84)

def Process(self, event):
                mail1 = self.txt_Username.GetValue()
                pwd1 = self.txt_Password.GetValue()
                
                self.Mail(event,mail1,pwd1)
                if self.cb_Timer.GetValue():
                        self.timer.Start(1000)                       
                                     
        def OnTimer(self,event):
                print"So we are inside"
                if not self.cb_Timer.GetValue():
                    self.timer.Stop()

I put (after removing the module for email check I do not have and putting constant value at line 84)

def Process(self, event):
                mail1 = self.txt_Username.GetValue()
                pwd1 = self.txt_Password.GetValue()
                
                self.Mail(event,mail1,pwd1)
                if self.cb_Timer.GetValue():
                        self.timer.Start(1000)                       
                                     
        def OnTimer(self,event):
                print"So we are inside"
                if not self.cb_Timer.GetValue():
                    self.timer.Stop()

Thanks Buddy . Your logic was definately working.
But i gave a twist to call the mail function again.

def Process(self, event):
                
                mail1 = self.txt_Username.GetValue()
                pwd1 = self.txt_Password.GetValue()
                
                if self.cb_Timer.GetValue()==False:
                        self.Mail(event,mail1,pwd1)
                else:
                        self.Mail(event,mail1,pwd1) #Function gets called first time.
                        self.timer.Start(30000)
                        self.cb_Timer.SetValue(False) #I set this off as i want to avoid looping as for now.
                        print"wow this is not right"
                
                        
                        
                                                                                      
                
                                               
        def onExit(self,event):
                self.Close(True)
        def Reset(self,event):
                self.txt_Username.Clear()
                self.txt_Password.Clear()
        def Mail (self,event,m1 ,p1):
                cnt = count(m1,p1)
                message='Unread:'+str(cnt)
                d = wx.MessageDialog(self,message,"New mails:",wx.OK)
                d.ShowModal()
                d.Destroy()
        def OnTimer(self,event):
                print"So we are inside"
                self.timer.Stop()
                self.Process(self)  #Calling the 2nd Time
This question has already been answered. Start a new discussion instead.