[Python-checkins] CVS: python/dist/src/Mac/Tools/IDE PyEdit.py,1.30,1.31

Jack Jansen jackjansen@users.sourceforge.net
Sun, 31 Mar 2002 14:01:36 -0800


Update of /cvsroot/python/python/dist/src/Mac/Tools/IDE
In directory usw-pr-cvs1:/tmp/cvs-serv12224

Modified Files:
	PyEdit.py 
Log Message:
Added a "run with commandline Python" flag. Works in MachoPython, should work
in OSX MacPython (untested), and should be disabled/removed in OS9 (but
that doesn't happen yet).


Index: PyEdit.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Tools/IDE/PyEdit.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** PyEdit.py	29 Mar 2002 21:48:42 -0000	1.30
--- PyEdit.py	31 Mar 2002 22:01:33 -0000	1.31
***************
*** 111,122 ****
  		self.debugging = 0
  		self.profiling = 0
! 		if self.settings.has_key("run_as_main"):
! 			self.run_as_main = self.settings["run_as_main"]
! 		else:
! 			self.run_as_main = 0
! 		if self.settings.has_key("run_with_interpreter"):
! 			self.run_with_interpreter = self.settings["run_with_interpreter"]
! 		else:
! 			self.run_with_interpreter = 0
  		self._threadstate = (0, 0)
  		self._thread = None
--- 111,117 ----
  		self.debugging = 0
  		self.profiling = 0
! 		self.run_as_main = self.settings.get("run_as_main", 0)
! 		self.run_with_interpreter = self.settings.get("run_with_interpreter", 0)
! 		self.run_with_cl_interpreter = self.settings.get("run_with_cl_interpreter", 0)
  		self._threadstate = (0, 0)
  		self._thread = None
***************
*** 162,165 ****
--- 157,161 ----
  		self.settings["run_as_main"] = self.run_as_main
  		self.settings["run_with_interpreter"] = self.run_with_interpreter
+ 		self.settings["run_with_cl_interpreter"] = self.run_with_cl_interpreter
  	
  	def get(self):
***************
*** 231,236 ****
  				'-',
  				('\0' + chr(self.run_as_main) + 'Run as __main__', self.domenu_toggle_run_as_main), 
! 				#('\0' + chr(self.run_with_interpreter) + 'Run with Interpreter', self.domenu_toggle_run_with_interpreter), 
! 				#'-',
  				('Modularize', self.domenu_modularize),
  				('Browse namespace\xc9', self.domenu_browsenamespace), 
--- 227,233 ----
  				'-',
  				('\0' + chr(self.run_as_main) + 'Run as __main__', self.domenu_toggle_run_as_main), 
! 				#('\0' + chr(self.run_with_interpreter) + 'Run with Interpreter', self.domenu_dtoggle_run_with_interpreter), 
! 				('\0' + chr(self.run_with_cl_interpreter) + 'Run with commandline Python', self.domenu_toggle_run_with_cl_interpreter), 
! 				'-',
  				('Modularize', self.domenu_modularize),
  				('Browse namespace\xc9', self.domenu_browsenamespace), 
***************
*** 251,259 ****
  		self.run_as_main = not self.run_as_main
  		self.run_with_interpreter = 0
  		self.editgroup.editor.selectionchanged()
  	
! 	def domenu_toggle_run_with_interpreter(self):
  		self.run_with_interpreter = not self.run_with_interpreter
  		self.run_as_main = 0
  		self.editgroup.editor.selectionchanged()
  	
--- 248,264 ----
  		self.run_as_main = not self.run_as_main
  		self.run_with_interpreter = 0
+ 		self.run_with_cl_interpreter = 0
  		self.editgroup.editor.selectionchanged()
  	
! 	def XXdomenu_toggle_run_with_interpreter(self):
  		self.run_with_interpreter = not self.run_with_interpreter
  		self.run_as_main = 0
+ 		self.run_with_cl_interpreter = 0
+ 		self.editgroup.editor.selectionchanged()
+ 	
+ 	def domenu_toggle_run_with_cl_interpreter(self):
+ 		self.run_with_cl_interpreter = not self.run_with_cl_interpreter
+ 		self.run_as_main = 0
+ 		self.run_with_interpreter = 0
  		self.editgroup.editor.selectionchanged()
  	
***************
*** 515,518 ****
--- 520,543 ----
  				raise W.AlertError, "Can't run unsaved file"
  			self._run_with_interpreter()
+ 		elif self.run_with_cl_interpreter:
+ 			# Until universal newline support
+ 			if self._eoln != '\n':
+ 				import EasyDialogs
+ 				ok = EasyDialogs.AskYesNoCancel('Warning: "%s" does not have Unix line-endings'
+ 					% self.title, 1, yes='OK', no='')
+ 				if not ok:
+ 					return
+ 			if self.editgroup.editor.changed:
+ 				import EasyDialogs
+ 				import Qd; Qd.InitCursor()
+ 				save = EasyDialogs.AskYesNoCancel('Save "%s" before running?' % self.title, 1)
+ 				if save > 0:
+ 					if self.domenu_save():
+ 						return
+ 				elif save < 0:
+ 					return
+ 			if not self.path:
+ 				raise W.AlertError, "Can't run unsaved file"
+ 			self._run_with_cl_interpreter()
  		else:
  			pytext = self.editgroup.editor.get()
***************
*** 526,529 ****
--- 551,571 ----
  		import findertools
  		XXX
+ 
+ 	def _run_with_cl_interpreter(self):
+ 		import Terminal
+ 		interp_path = os.path.join(sys.exec_prefix, "bin", "python")
+ 		file_path = self.path
+ 		if not os.path.exists(interp_path):
+ 			# This "can happen" if we are running IDE under MacPython. Try
+ 			# the standard location.
+ 			interp_path = "/Library/Frameworks/Python.framework/Versions/2.3/bin/python"
+ 			try:
+ 				fsr = macfs.FSRef(interp_path)
+ 			except macfs.Error:
+ 				raise W.AlertError, "Can't find command-line Python"
+ 			file_path = macfs.FSRef(macfs.FSSpec(self.path)).as_pathname()
+ 		cmd = '"%s" "%s" ; exit' % (interp_path, file_path)
+ 		t = Terminal.Terminal()
+ 		t.do_script(with_command=cmd)
  	
  	def runselection(self):
***************
*** 538,542 ****
  	
  	def _runselection(self):
! 		if self.run_with_interpreter:
  			raise W.AlertError, "Can't run selection with Interpreter"
  		globals, file, modname = self.getenvironment()
--- 580,584 ----
  	
  	def _runselection(self):
! 		if self.run_with_interpreter or self.run_with_cl_interpreter:
  			raise W.AlertError, "Can't run selection with Interpreter"
  		globals, file, modname = self.getenvironment()