Permalink
Browse files

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.
  • Loading branch information...
1 parent a3229f5 commit 42c877c4beee124e747603d2ea4946d33261c07c @cboos committed Sep 21, 2011
Showing with 18 additions and 16 deletions.
  1. +16 −1 IPython/lib/inputhook.py
  2. +2 −15 IPython/lib/inputhookwx.py
@@ -15,8 +15,13 @@
#-----------------------------------------------------------------------------
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_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
@@ -24,26 +24,13 @@
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.

0 comments on commit 42c877c

Please sign in to comment.