diff Mac/Tools/IDE/PyConsole.py @ 22030:99341e85017e 2.2

Backport of 1.9-1.11: - Flush screen buffer upon console.flush() and output.flush(). This fixes bug #511992. - Changes by Donovan Preston (and a few minor ones by me) to make IDE run under MachoPython. Mainly making sure we don't call routines that don't exist and representing pathnames in a os.separator-neutral format. These shouldn't interfere too much with Just's work on the next generation IDE, I hope. - Modified version of patch #496882: echo SimpleStdin readline() input to stdout.
author Jack Jansen <jack.jansen@cwi.nl>
date Sun, 24 Feb 2002 23:12:47 +0000
parents 42b2f1936254
children
line wrap: on
line diff
--- a/Mac/Tools/IDE/PyConsole.py	Sun Feb 24 23:11:34 2002 +0000
+++ b/Mac/Tools/IDE/PyConsole.py	Sun Feb 24 23:12:47 2002 +0000
@@ -75,9 +75,11 @@
 			if char == Wkeys.returnkey:
 				text = self.get()[self._inputstart:selstart]
 				text = string.join(string.split(text, "\r"), "\n")
-				saveyield = MacOS.EnableAppswitch(0)
+				if hasattr(MacOS, 'EnableAppswitch'):
+					saveyield = MacOS.EnableAppswitch(0)
 				self.pyinteractive.executeline(text, self, self._namespace)
-				MacOS.EnableAppswitch(saveyield)
+				if hasattr(MacOS, 'EnableAppswitch'):
+					MacOS.EnableAppswitch(saveyield)
 				selstart, selend = self.getselection()
 				self._inputstart = selstart
 	
@@ -106,6 +108,8 @@
 		self._buf = ""
 		self.ted.WEClearUndo()
 		self.updatescrollbars()
+		if Qd.QDIsPortBuffered(self._parentwindow.wid):
+			Qd.QDFlushPortBuffer(self._parentwindow.wid, None)
 	
 	def selection_ok(self):
 		selstart, selend = self.getselection()
@@ -275,13 +279,15 @@
 		self.w.bind("<activate>", self.activate)
 	
 	def write(self, text):
-		oldyield = MacOS.EnableAppswitch(-1)
+		if hasattr(MacOS, 'EnableAppswitch'):
+			oldyield = MacOS.EnableAppswitch(-1)
 		try:
 			self._buf = self._buf + text
 			if '\n' in self._buf:
 				self.flush()
 		finally:
-			MacOS.EnableAppswitch(oldyield)
+			if hasattr(MacOS, 'EnableAppswitch'):
+				MacOS.EnableAppswitch(oldyield)
 	
 	def flush(self):
 		self.show()
@@ -294,6 +300,8 @@
 		self._buf = ""
 		self.w.outputtext.updatescrollbars()
 		self.w.outputtext.ted.WEFeatureFlag(WASTEconst.weFReadOnly, 1)
+		if Qd.QDIsPortBuffered(self.w.wid):
+			Qd.QDFlushPortBuffer(self.w.wid, None)
 	
 	def show(self):
 		if self.closed:
@@ -354,7 +362,9 @@
 		rv = EasyDialogs.AskString(prompt)
 		if rv is None:
 			return ""
-		return rv + '\n'
+		rv = rv + "\n"  # readline should include line terminator
+		sys.stdout.write(rv)  # echo user's reply
+		return rv
 
 
 def installconsole(defaultshow = 1):