Skip to content

Commit

Permalink
WIN: prompt_toolkit support
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Brodbeck authored and christianbrodbeck committed Jan 21, 2017
1 parent a60a82e commit 50c2eac
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions eelbrain/_wxgui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import select
import sys
from threading import Thread
from time import sleep
import webbrowser

import wx
Expand All @@ -15,6 +16,7 @@

APP = None # hold the App instance
IS_OSX = sys.platform == 'darwin'
IS_WINDOWS = sys.platform.startswith('win')


def wildcard(filetypes):
Expand All @@ -26,7 +28,6 @@ def wildcard(filetypes):

class App(wx.App):
def OnInit(self):
self.SetExitOnFrameDelete(False)
self.SetAppName("Eelbrain")
self.SetAppDisplayName("Eelbrain")

Expand Down Expand Up @@ -162,17 +163,25 @@ def OnInit(self):
# qt4 backend can cause conflicts in IPython
from .. import plot
plot.configure(ets_toolkit='wx')
self.SetExitOnFrameDelete(not self.using_prompt_toolkit)

return True

def pt_inputhook(self, context):
"""prompt_toolkit inputhook"""
# prompt_toolkit.eventloop.inputhook.InputHookContext
def thread():
poll = select.poll()
poll.register(context.fileno(), select.POLLIN)
poll.poll(-1)
wx.CallAfter(self.pt_yield)
if IS_WINDOWS:
# On Windows, select.poll() is not available
def thread():
while not context.input_is_ready():
sleep(.02)
wx.CallAfter(self.pt_yield)
else:
def thread():
poll = select.poll()
poll.register(context.fileno(), select.POLLIN)
poll.poll(-1)
wx.CallAfter(self.pt_yield)

Thread(target=thread).start()
self.MainLoop()
Expand Down Expand Up @@ -612,5 +621,7 @@ def __init__(self, app):
self.imgidx = 1

def CreatePopupMenu(self):
menu = wx.Menu()
return menu
if not self.app.using_prompt_toolkit:
menu = wx.Menu()
menu.Append(ID.YIELD_TO_TERMINAL, '&Yield to Terminal')
return menu

0 comments on commit 50c2eac

Please sign in to comment.