From 47152340308b8f65a6cfe6040dc9596efbffd94e 2008-08-12 17:20:07
From: gvaroquaux <gvaroquaux@gvaroquaux-desktop>
Date: 2008-08-12 17:20:07
Subject: [PATCH] Fix segfaults under windows.

---

diff --git a/IPython/frontend/linefrontendbase.py b/IPython/frontend/linefrontendbase.py
index 9a35925..fb450e8 100644
--- a/IPython/frontend/linefrontendbase.py
+++ b/IPython/frontend/linefrontendbase.py
@@ -138,10 +138,14 @@ class LineFrontEndBase(FrontEndBase):
             return FrontEndBase.is_complete(self, string.rstrip() + '\n\n')
 
 
-    def write(self, string):
+    def write(self, string, refresh=True):
         """ Write some characters to the display.
 
             Subclass should overide this method.
+
+            The refresh keyword argument is used in frontends with an
+            event loop, to choose whether the write should trigget an UI
+            refresh, and thus be syncrhonous, or not.
         """
         print >>sys.__stderr__, string
 
diff --git a/IPython/frontend/wx/console_widget.py b/IPython/frontend/wx/console_widget.py
index 7fd84b3..abbef36 100644
--- a/IPython/frontend/wx/console_widget.py
+++ b/IPython/frontend/wx/console_widget.py
@@ -337,7 +337,7 @@ class ConsoleWidget(editwindow.EditWindow):
                         event.Modifiers in (wx.MOD_NONE, wx.MOD_WIN):
                 catched = True
                 self.CallTipCancel()
-                self.write('\n')
+                self.write('\n', refresh=False)
                 # Under windows scintilla seems to be doing funny stuff to the 
                 # line returns here, but the getter for input_buffer filters 
                 # this out.
diff --git a/IPython/frontend/wx/ipythonx.py b/IPython/frontend/wx/ipythonx.py
index e4df7f2..ff83ad3 100755
--- a/IPython/frontend/wx/ipythonx.py
+++ b/IPython/frontend/wx/ipythonx.py
@@ -42,13 +42,14 @@ class IPythonXController(WxController):
     def ask_exit(self):
         """ Ask the user whether to exit.
         """
-        self.write('\n')
+        self._input_state = 'subprocess'
+        self.write('\n', refresh=False)
         self.capture_output()
         self.ipython0.shell.exit()
         self.release_output()
-        wx.Yield()
         if not self.ipython0.exit_now:
-            self.new_prompt(self.input_prompt_template.substitute(
+            wx.CallAfter(self.new_prompt,
+                         self.input_prompt_template.substitute(
                                 number=self.last_result['number'] + 1))
  
 
@@ -87,6 +88,10 @@ Simple graphical frontend to IPython, using WxWidgets."""
 
     options, args = parser.parse_args()
 
+    # Clear the options, to avoid having the ipython0 instance complain
+    import sys
+    sys.argv = sys.argv[:1]
+
     app = wx.PySimpleApp()
     frame = IPythonX(None, wx.ID_ANY, 'IPythonX')
     frame.shell.debug = options.debug
diff --git a/IPython/frontend/wx/wx_frontend.py b/IPython/frontend/wx/wx_frontend.py
index 7704ee3..e4f2fae 100644
--- a/IPython/frontend/wx/wx_frontend.py
+++ b/IPython/frontend/wx/wx_frontend.py
@@ -90,7 +90,6 @@ class WxController(ConsoleWidget, PrefilterFrontEnd):
     # inheritence
     def _set_input_buffer(self, string):
         ConsoleWidget._set_input_buffer(self, string)
-        wx.Yield()
         self._colorize_input_buffer()
 
     def _get_input_buffer(self):