Jump to content

Recommended Posts

  • 2 weeks later...
  • Bronze
import time
 
class Wait(ui.ScriptWindow):
    def __init__(self):
        ui.ScriptWindow.__init__(self)
        self.eventTimeOver = lambda * arg: None
        self.eventExit = lambda * arg: None
         
    def __del__(self):
        ui.ScriptWindow.__del__(self)
         
    def Open(self,waitTime):
        curTime = time.clock()
        self.endTime = curTime + waitTime
        self.Show()
     
    def Close(self):
        self.Hide()
         
    def Destroy(self):
        self.Hide()
         
    def EmptyFunc(self):
        pass
         
    def SAFE_SetTimeOverEvent(self,event = 0):
        if(not event):
            self.eventTimeOver = self.EmptyFunc
             
        self.eventTimeOver = ui.__mem_func__(event)
         
    def SAFE_SetExitEvent(self,event = 0):
        if(not event):
            self.eventExit = self.EmptyFunc
         
        self.eventExit = ui.__mem_func__(event)
         
    def OnUpdate(self):
        lastTime = max(0,self.endTime - time.clock())
        if(lastTime == 0):
            self.Close()
        else:
            return
             
    def OnPressExitKey(self):
        self.Close()
        return True
         
         
 
## Example ;
 
self.waitFor = Wait()
self.waitFor.Open(20.0)
self.waitFor.SAFE_SetTimeOverEvent(self.SecondFinished)
self.waitFor.SAFE_SetExitEvent(self.ExitKey)
 
def SecondFinished(self):
    print "======================================================"
    print "Second is finished."
    print "======================================================"
     
def ExitKey(self):
    print "======================================================"
    print "Exit Key -- Write Something"
    print "======================================================"

maybe you could work on your business

 

Best Regards

Aveline

  • Love 1

Plain logic saves lives.

Link to comment
Share on other sites

import time
 
class Wait(ui.ScriptWindow):
    def __init__(self):
        ui.ScriptWindow.__init__(self)
        self.eventTimeOver = lambda * arg: None
        self.eventExit = lambda * arg: None
         
    def __del__(self):
        ui.ScriptWindow.__del__(self)
         
    def Open(self,waitTime):
        curTime = time.clock()
        self.endTime = curTime + waitTime
        self.Show()
     
    def Close(self):
        self.Hide()
         
    def Destroy(self):
        self.Hide()
         
    def EmptyFunc(self):
        pass
         
    def SAFE_SetTimeOverEvent(self,event = 0):
        if(not event):
            self.eventTimeOver = self.EmptyFunc
             
        self.eventTimeOver = ui.__mem_func__(event)
         
    def SAFE_SetExitEvent(self,event = 0):
        if(not event):
            self.eventExit = self.EmptyFunc
         
        self.eventExit = ui.__mem_func__(event)
         
    def OnUpdate(self):
        lastTime = max(0,self.endTime - time.clock())
        if(lastTime == 0):
            self.Close()
        else:
            return
             
    def OnPressExitKey(self):
        self.Close()
        return True
         
         
 
## Example ;
 
self.waitFor = Wait()
self.waitFor.Open(20.0)
self.waitFor.SAFE_SetTimeOverEvent(self.SecondFinished)
self.waitFor.SAFE_SetExitEvent(self.ExitKey)
 
def SecondFinished(self):
    print "======================================================"
    print "Second is finished."
    print "======================================================"
     
def ExitKey(self):
    print "======================================================"
    print "Exit Key -- Write Something"
    print "======================================================"

maybe you could work on your business

 

Best Regards

Aveline

 

There is no need to make that, he can simply write this:

define a variable for your action, for example you whant to make a timer when you buy.
When you buy a thing you define sothing like this:
self.buytime = app.GetTime()

and then you whant to wait like 30 seconds before you can buy, you can write this:

import time
if app.GetTime() < self.buytime+30:
               code the part when the timer is running
else:
            after timer stopped
            Here you make a action so he can buy again.
Link to comment
Share on other sites

  • 1 month later...

There is a simple way:

def myfunction_took_long_to_execute():
     for i in range(500000000000000000000000000000000000):
          print i
     return i
def myfunction_took_long_to_execute_with_yield():
     for i in range(500000000000000000000000000000000000):
          print i
          yield None
     return i

 

https://docs.python.org/release/2.5.2/ref/yield.html

 

I would post a better example, but Ymir Client times are long ago...

  • Good 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.