From 42c877c4beee124e747603d2ea4946d33261c07c 2011-10-09 12:11:59 From: Christian Boos Date: 2011-10-09 12:11:59 Subject: [PATCH] inputhook: make stdin_ready() function reusable Move it from lib.inputhookwx to lib.inputhook, as the former module can only be loaded if wx itself is available. --- diff --git a/IPython/lib/inputhook.py b/IPython/lib/inputhook.py index 085a271..782b4de 100644 --- a/IPython/lib/inputhook.py +++ b/IPython/lib/inputhook.py @@ -15,8 +15,13 @@ Inputhook management for GUI event loop integration. #----------------------------------------------------------------------------- import ctypes +import os import sys import warnings +if os.name == 'posix': + import select +elif sys.platform == 'win32': + import msvcrt #----------------------------------------------------------------------------- # Constants @@ -33,9 +38,19 @@ GUI_GLUT = 'glut' GUI_PYGLET = 'pyglet' #----------------------------------------------------------------------------- -# Utility classes +# Utilities #----------------------------------------------------------------------------- +def stdin_ready(): + if os.name == 'posix': + infds, outfds, erfds = select.select([sys.stdin],[],[],0) + if infds: + return True + else: + return False + elif sys.platform == 'win32': + return msvcrt.kbhit() + #----------------------------------------------------------------------------- # Main InputHookManager class diff --git a/IPython/lib/inputhookwx.py b/IPython/lib/inputhookwx.py index 8e3d25b..4b9bd02 100644 --- a/IPython/lib/inputhookwx.py +++ b/IPython/lib/inputhookwx.py @@ -24,26 +24,13 @@ import time from timeit import default_timer as clock import wx -if os.name == 'posix': - import select -elif sys.platform == 'win32': - import msvcrt +from IPython.lib.inputhook import stdin_ready + #----------------------------------------------------------------------------- # Code #----------------------------------------------------------------------------- -def stdin_ready(): - if os.name == 'posix': - infds, outfds, erfds = select.select([sys.stdin],[],[],0) - if infds: - return True - else: - return False - elif sys.platform == 'win32': - return msvcrt.kbhit() - - def inputhook_wx1(): """Run the wx event loop by processing pending events only.