Merge branch 'threads'

Conflicts:
	weboob/frontends/videoob/application.py
This commit is contained in:
Romain Bignon 2010-04-29 11:10:19 +02:00
commit 926a25b992
14 changed files with 305 additions and 65 deletions

View file

@ -164,3 +164,4 @@ class BaseApplication(object):
print 'Program killed by SIGINT'
except ConfigError, e:
print 'Configuration error: %s' % e
sys.exit(1)

View file

@ -18,9 +18,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
import sched
import time
import select
import sys
from weboob import Weboob
@ -34,18 +31,18 @@ __all__ = ['PromptApplication']
class PromptScheduler(Scheduler):
def __init__(self, prompt_cb, read_cb):
self.scheduler = sched.scheduler(time.time, self.sleep)
Scheduler.__init__(self)
self.read_cb = read_cb
self.prompt_cb = prompt_cb
def sleep(self, d):
self.prompt_cb()
def run(self):
try:
read, write, excepts = select.select([sys.stdin], [], [], d or None)
if read:
while not self.stop_event.isSet():
self.prompt_cb()
line = sys.stdin.readline()
if not line:
self.want_stop()
sys.stdout.write('\n')
else:
self.read_cb(line.strip())
except KeyboardInterrupt:
@ -55,6 +52,13 @@ class PromptApplication(ConsoleApplication):
def create_weboob(self):
return Weboob(self.APPNAME, scheduler=PromptScheduler(self.prompt, self.read_cb))
@ConsoleApplication.command("Display this notice")
def command_help(self):
print 'Available commands:'
for name, arguments, doc_string in self._commands:
command = '%s %s' % (name, arguments)
print ' %-30s %s' % (command, doc_string)
def prompt(self):
sys.stdout.write('> ')
sys.stdout.flush()
@ -64,4 +68,5 @@ class PromptApplication(ConsoleApplication):
def read_cb(self, line):
line = line.split()
self.process_command(*line)
if line:
self.process_command(*line)

View file

@ -23,13 +23,13 @@ from PyQt4.QtCore import QTimer, SIGNAL
from PyQt4.QtGui import QMainWindow, QApplication
from weboob import Weboob
from weboob.scheduler import Scheduler
from weboob.scheduler import IScheduler
from .base import BaseApplication
__all__ = ['QtApplication']
class QtScheduler(Scheduler):
class QtScheduler(IScheduler):
def __init__(self, app):
self.app = app
self.timers = {}