2012-10-23 9 views
0

Je veux utiliser wx.CallLater: J'ai deux fonctions et ils doivent s'appeler en boucle, mais avec une pause de 3 secondes avant chaque appel. Le problème est: Quand mon programme est dans "goto01" il attend correctement 3 secondes avant que "Notify" ne soit appelé. Mais quand le programme est dans "Notify" alors "goto01" est appelé immédiatement. Pourquoi n'y a-t-il pas de pause de 3 secondes à ce stade? Voici mon code & dans la dernière ligne de chacune des fonctions tant que j'ai un événement wx.CallLater:wx.CallLater ne fonctionne pas pour moi

self.speed = 3000 

def Notify(self): 
    self.zeit.Destroy() 
    self.zeitint = self.zeitint + 1 
    time = round(self.zeitint/2) 
    self.zeit = wx.StaticText(self.friendlygamepanel, -1, '%d. Spielminute'%(time), (325+self.dx,9)) 
    try: 
     self.ticker.Destroy() 
     self.picplayer1but.Destroy() 

    except: 
     pass 
    if self.zeitint % 2 == 1: 
     self.ticker = wx.TextCtrl(self, -1, teamname[0]+' ist im Ballbesitz.', 
        size=(340, 320), pos=(195+self.dx,160), style=wx.TE_RICH2|wx.TE_MULTILINE|wx.TE_NO_VSCROLL) 
     self.ticker.SetBackgroundColour((128,191,130)) 
     self.ticker.SetStyle(0, len(teamname[0]), wx.TextAttr("BLACK", wx.NullColour, self.font)) 
     wx.CallLater(int(self.speed),self.goto01(players,self.playerpics)) 

    else: 
     self.ticker = wx.TextCtrl(self, -1, oppteamname[0]+' ist im Ballbesitz.', 
        size=(340, 320), pos=(195+self.dx,160), style=wx.TE_RICH2|wx.TE_MULTILINE|wx.TE_NO_VSCROLL) 
     self.ticker.SetBackgroundColour((205,173,65)) 
     self.ticker.SetStyle(0, len(oppteamname[0]), wx.TextAttr("BLACK", wx.NullColour, self.font)) 
     wx.CallLater(int(self.speed),self.goto01(oppplayers,self.oppplayerpics)) 


def goto01(self,theplayer,thepicture): 
    if self.zeitint % 2 == 1: 
     picpos = 0 
    else: 
     picpos = 460 
    self.whichplayer = random.randint(0,2) 
    self.whichoppplayer = random.randint(0,2) 
    last = self.ticker.GetLastPosition() 
    self.ticker.AppendText('\n\n'+theplayer[self.whichplayer][0]+' hat den Ball.') 
    self.ticker.SetStyle(last, last+2+len(theplayer[self.whichplayer][0]), wx.TextAttr("BLACK", wx.NullColour, self.font)) 
    self.picplayer1 = wx.Image(thepicture[self.whichplayer], wx.BITMAP_TYPE_BMP).ConvertToBitmap() 
    self.picplayer1but = wx.BitmapButton(self.friendlygamepanel,-1,self.picplayer1,pos=(90+self.dx+picpos,180)) 
    if self.zeitint < 60: 
     wx.CallLater(int(self.speed),self.Notify) 

Répondre

3

C'est comme lorsque vous appelez normalement une fonction. Vous pouvez passer des arguments à bien:

http://wxpython-users.1045709.n5.nabble.com/wx-CallLater-issue-td4885884.html

Comme ce lien souligne, la signature pour callLater est:

(auto, Millis, appelable * args, ** kwargs)

qui signifie que vous devriez être en mesure de faire quelque chose comme

wx.CallLater(numberOfMilliSecs, myFunction, arg1, arg2) 
+0

millisecondes Ca y est, vous avez écrit 'numberOfSecs' – FogleBird

+0

Trop vrai. Désolé pour ça. Fixé! –

0

Je vois, quand je viens d'appeler « goto01 » au lieu de « goto01 (variable1, variable2) "alors ça marche. J'ai été capable de changer mon code pour ne pas avoir à utiliser ces variables lors de l'appel de "goto", mais je ne sais toujours pas pourquoi wx.CallLater ne fonctionne pas avec les variables ?! Lorsque vous appelez la fonction avec des variables, vous dites à wxPython de l'appeler immédiatement.