Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff773eb

Browse files
committed
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).
1 parent 767f835 commit ff773eb

1 file changed

Lines changed: 54 additions & 12 deletions

File tree

Mac/Tools/IDE/PyEdit.py

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,9 @@ def __init__(self, path = "", title = ""):
110110
self._buf = "" # for write method
111111
self.debugging = 0
112112
self.profiling = 0
113-
if self.settings.has_key("run_as_main"):
114-
self.run_as_main = self.settings["run_as_main"]
115-
else:
116-
self.run_as_main = 0
117-
if self.settings.has_key("run_with_interpreter"):
118-
self.run_with_interpreter = self.settings["run_with_interpreter"]
119-
else:
120-
self.run_with_interpreter = 0
113+
self.run_as_main = self.settings.get("run_as_main", 0)
114+
self.run_with_interpreter = self.settings.get("run_with_interpreter", 0)
115+
self.run_with_cl_interpreter = self.settings.get("run_with_cl_interpreter", 0)
121116
self._threadstate = (0, 0)
122117
self._thread = None
123118

@@ -161,6 +156,7 @@ def getsettings(self):
161156
self.settings["tabsize"] = self.editgroup.editor.gettabsettings()
162157
self.settings["run_as_main"] = self.run_as_main
163158
self.settings["run_with_interpreter"] = self.run_with_interpreter
159+
self.settings["run_with_cl_interpreter"] = self.run_with_cl_interpreter
164160

165161
def get(self):
166162
return self.editgroup.editor.get()
@@ -230,8 +226,9 @@ def makeoptionsmenu(self):
230226
("Save options\xc9", self.domenu_options),
231227
'-',
232228
('\0' + chr(self.run_as_main) + 'Run as __main__', self.domenu_toggle_run_as_main),
233-
#('\0' + chr(self.run_with_interpreter) + 'Run with Interpreter', self.domenu_toggle_run_with_interpreter),
234-
#'-',
229+
#('\0' + chr(self.run_with_interpreter) + 'Run with Interpreter', self.domenu_dtoggle_run_with_interpreter),
230+
('\0' + chr(self.run_with_cl_interpreter) + 'Run with commandline Python', self.domenu_toggle_run_with_cl_interpreter),
231+
'-',
235232
('Modularize', self.domenu_modularize),
236233
('Browse namespace\xc9', self.domenu_browsenamespace),
237234
'-']
@@ -250,11 +247,19 @@ def makeoptionsmenu(self):
250247
def domenu_toggle_run_as_main(self):
251248
self.run_as_main = not self.run_as_main
252249
self.run_with_interpreter = 0
250+
self.run_with_cl_interpreter = 0
253251
self.editgroup.editor.selectionchanged()
254252

255-
def domenu_toggle_run_with_interpreter(self):
253+
def XXdomenu_toggle_run_with_interpreter(self):
256254
self.run_with_interpreter = not self.run_with_interpreter
257255
self.run_as_main = 0
256+
self.run_with_cl_interpreter = 0
257+
self.editgroup.editor.selectionchanged()
258+
259+
def domenu_toggle_run_with_cl_interpreter(self):
260+
self.run_with_cl_interpreter = not self.run_with_cl_interpreter
261+
self.run_as_main = 0
262+
self.run_with_interpreter = 0
258263
self.editgroup.editor.selectionchanged()
259264

260265
def showbreakpoints(self, onoff):
@@ -514,6 +519,26 @@ def _run(self):
514519
if not self.path:
515520
raise W.AlertError, "Can't run unsaved file"
516521
self._run_with_interpreter()
522+
elif self.run_with_cl_interpreter:
523+
# Until universal newline support
524+
if self._eoln != '\n':
525+
import EasyDialogs
526+
ok = EasyDialogs.AskYesNoCancel('Warning: "%s" does not have Unix line-endings'
527+
% self.title, 1, yes='OK', no='')
528+
if not ok:
529+
return
530+
if self.editgroup.editor.changed:
531+
import EasyDialogs
532+
import Qd; Qd.InitCursor()
533+
save = EasyDialogs.AskYesNoCancel('Save "%s" before running?' % self.title, 1)
534+
if save > 0:
535+
if self.domenu_save():
536+
return
537+
elif save < 0:
538+
return
539+
if not self.path:
540+
raise W.AlertError, "Can't run unsaved file"
541+
self._run_with_cl_interpreter()
517542
else:
518543
pytext = self.editgroup.editor.get()
519544
globals, file, modname = self.getenvironment()
@@ -525,6 +550,23 @@ def _run_with_interpreter(self):
525550
raise W.AlertError, "Can't find interpreter"
526551
import findertools
527552
XXX
553+
554+
def _run_with_cl_interpreter(self):
555+
import Terminal
556+
interp_path = os.path.join(sys.exec_prefix, "bin", "python")
557+
file_path = self.path
558+
if not os.path.exists(interp_path):
559+
# This "can happen" if we are running IDE under MacPython. Try
560+
# the standard location.
561+
interp_path = "/Library/Frameworks/Python.framework/Versions/2.3/bin/python"
562+
try:
563+
fsr = macfs.FSRef(interp_path)
564+
except macfs.Error:
565+
raise W.AlertError, "Can't find command-line Python"
566+
file_path = macfs.FSRef(macfs.FSSpec(self.path)).as_pathname()
567+
cmd = '"%s" "%s" ; exit' % (interp_path, file_path)
568+
t = Terminal.Terminal()
569+
t.do_script(with_command=cmd)
528570

529571
def runselection(self):
530572
if self._threadstate == (0, 0):
@@ -537,7 +579,7 @@ def runselection(self):
537579
self.setthreadstate((1, 1))
538580

539581
def _runselection(self):
540-
if self.run_with_interpreter:
582+
if self.run_with_interpreter or self.run_with_cl_interpreter:
541583
raise W.AlertError, "Can't run selection with Interpreter"
542584
globals, file, modname = self.getenvironment()
543585
locals = globals

0 commit comments

Comments
 (0)