WindowSched.py :  » Mobile » Python-for-PalmOS » Python-1.5.2+reduced-1.0 » Lib » lib-stdwin » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Mobile » Python for PalmOS 
Python for PalmOS » Python 1.5.2 reduced 1.0 » Lib » lib stdwin » WindowSched.py
# Combine a real-time scheduling queue and stdwin event handling.
# Keeps times in milliseconds.

import stdwin, stdwinq
from stdwinevents import WE_TIMER
import mainloop
import sched
import time

# Delay function called by the scheduler when it has nothing to do.
# Return immediately when something is done, or when the delay is up.
#
def delayfunc(msecs):
  msecs = int(msecs)
  #
  # Check for immediate stdwin event
  #
  event = stdwinq.pollevent()
  if event:
    mainloop.dispatch(event)
    return
  #
  # Use sleep for very short delays or if there are no windows
  #
  if msecs < 100 or mainloop.countwindows() == 0:
    if msecs > 0:
      time.sleep(msecs * 0.001)
    return
  #
  # Post a timer event on an arbitrary window and wait for it
  #
  window = mainloop.anywindow()
  window.settimer(msecs/100)
  event = stdwinq.getevent()
  window.settimer(0)
  if event[0] <> WE_TIMER:
    mainloop.dispatch(event)

def millitimer():
  return time.time() * 1000

q = sched.scheduler(millitimer, delayfunc)

# Export functions enter, enterabs and cancel just like a scheduler
#
enter = q.enter
enterabs = q.enterabs
cancel = q.cancel

# Emptiness check must check both queues
#
def empty():
  return q.empty() and mainloop.countwindows() == 0

# Run until there is nothing left to do
#
def run():
  while not empty():
    if q.empty():
      mainloop.dispatch(stdwinq.getevent())
    else:
      q.run()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.