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

Skip to content

Commit 0f2fd16

Browse files
author
Just van Rossum
committed
Hm, I never checked in my incomplete "run with interpreter" mods. UI is there (but is disabled), functionality is not there.
1 parent 6508c7c commit 0f2fd16

1 file changed

Lines changed: 63 additions & 22 deletions

File tree

Mac/Tools/IDE/PyEdit.py

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
import regex
1818

1919
try:
20-
# experimental microthread support
21-
import uthread2
20+
import Wthreading
2221
except ImportError:
23-
uthread2 = None
22+
haveThreading = 0
23+
else:
24+
haveThreading = Wthreading.haveThreading
2425

2526
_scriptuntitledcounter = 1
2627
_wordchars = string.letters + string.digits + "_"
@@ -109,6 +110,10 @@ def __init__(self, path = "", title = ""):
109110
self.run_as_main = self.settings["run_as_main"]
110111
else:
111112
self.run_as_main = 0
113+
if self.settings.has_key("run_with_interpreter"):
114+
self.run_with_interpreter = self.settings["run_with_interpreter"]
115+
else:
116+
self.run_with_interpreter = 0
112117
self._threadstate = (0, 0)
113118
self._thread = None
114119

@@ -151,6 +156,7 @@ def getsettings(self):
151156
self.settings["fontsettings"] = self.editgroup.editor.getfontsettings()
152157
self.settings["tabsize"] = self.editgroup.editor.gettabsettings()
153158
self.settings["run_as_main"] = self.run_as_main
159+
self.settings["run_with_interpreter"] = self.run_with_interpreter
154160

155161
def get(self):
156162
return self.editgroup.editor.get()
@@ -220,6 +226,8 @@ def makeoptionsmenu(self):
220226
("Save optionsŠ", self.domenu_options),
221227
'-',
222228
('\0' + chr(self.run_as_main) + 'Run as __main__', self.domenu_toggle_run_as_main),
229+
#('\0' + chr(self.run_with_interpreter) + 'Run with Interpreter', self.domenu_toggle_run_with_interpreter),
230+
#'-',
223231
('Modularize', self.domenu_modularize),
224232
('Browse namespaceŠ', self.domenu_browsenamespace),
225233
'-']
@@ -237,6 +245,12 @@ def makeoptionsmenu(self):
237245

238246
def domenu_toggle_run_as_main(self):
239247
self.run_as_main = not self.run_as_main
248+
self.run_with_interpreter = 0
249+
self.editgroup.editor.selchanged = 1
250+
251+
def domenu_toggle_run_with_interpreter(self):
252+
self.run_with_interpreter = not self.run_with_interpreter
253+
self.run_as_main = 0
240254
self.editgroup.editor.selchanged = 1
241255

242256
def showbreakpoints(self, onoff):
@@ -476,28 +490,52 @@ def run(self):
476490
if self._threadstate == (0, 0):
477491
self._run()
478492
else:
479-
uthread2.globalLock()
480-
self._thread.raiseException(KeyboardInterrupt)
481-
if self._thread.isPaused():
493+
lock = Wthreading.Lock()
494+
lock.acquire()
495+
self._thread.postException(KeyboardInterrupt)
496+
if self._thread.isBlocked():
482497
self._thread.start()
483-
uthread2.globalUnlock()
498+
lock.release()
484499

485500
def _run(self):
486-
pytext = self.editgroup.editor.get()
487-
globals, file, modname = self.getenvironment()
488-
self.execstring(pytext, globals, globals, file, modname)
501+
if self.run_with_interpreter:
502+
if self.editgroup.editor.changed:
503+
import EasyDialogs
504+
import Qd; Qd.InitCursor()
505+
save = EasyDialogs.AskYesNoCancel('Save ³%s² before running?' % self.title, 1)
506+
if save > 0:
507+
if self.domenu_save():
508+
return
509+
elif save < 0:
510+
return
511+
if not self.path:
512+
raise W.AlertError, "Can't run unsaved file"
513+
self._run_with_interpreter()
514+
else:
515+
pytext = self.editgroup.editor.get()
516+
globals, file, modname = self.getenvironment()
517+
self.execstring(pytext, globals, globals, file, modname)
518+
519+
def _run_with_interpreter(self):
520+
interp_path = os.path.join(sys.exec_prefix, "PythonInterpreter")
521+
if not os.path.exists(interp_path):
522+
raise W.AlertError, "Can't find interpreter"
523+
import findertools
524+
XXX
489525

490526
def runselection(self):
491527
if self._threadstate == (0, 0):
492528
self._runselection()
493529
elif self._threadstate == (1, 1):
494-
self._thread.pause()
530+
self._thread.block()
495531
self.setthreadstate((1, 2))
496532
elif self._threadstate == (1, 2):
497533
self._thread.start()
498534
self.setthreadstate((1, 1))
499535

500536
def _runselection(self):
537+
if self.run_with_interpreter:
538+
raise W.AlertError, "Can't run selection with Interpreter"
501539
globals, file, modname = self.getenvironment()
502540
locals = globals
503541
# select whole lines
@@ -571,8 +609,8 @@ def execstring(self, pytext, globals, locals, file, modname):
571609
else:
572610
cwdindex = None
573611
try:
574-
if uthread2 and uthread2.currentThread() is not None:
575-
self._thread = uthread2.Thread(file,
612+
if haveThreading:
613+
self._thread = Wthreading.Thread(os.path.basename(file),
576614
self._exec_threadwrapper, pytext, globals, locals, file, self.debugging,
577615
modname, self.profiling)
578616
self.setthreadstate((1, 1))
@@ -1082,13 +1120,14 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
10821120
return
10831121
try:
10841122
if debugging:
1085-
if uthread2:
1086-
uthread2.globalLock()
1123+
if haveThreading:
1124+
lock = Wthreading.Lock()
1125+
lock.acquire()
10871126
PyDebugger.startfromhere()
1088-
uthread2.globalUnlock()
1127+
lock.release()
10891128
else:
10901129
PyDebugger.startfromhere()
1091-
elif not uthread2:
1130+
elif not haveThreading:
10921131
MacOS.EnableAppswitch(0)
10931132
try:
10941133
if profiling:
@@ -1105,23 +1144,25 @@ def execstring(pytext, globals, locals, filename="<string>", debugging=0,
11051144
else:
11061145
exec code in globals, locals
11071146
finally:
1108-
if not uthread2:
1147+
if not haveThreading:
11091148
MacOS.EnableAppswitch(-1)
11101149
except W.AlertError, detail:
11111150
raise W.AlertError, detail
11121151
except (KeyboardInterrupt, BdbQuit):
11131152
pass
11141153
except:
1115-
if uthread2:
1116-
uthread2.globalLock()
1154+
if haveThreading:
1155+
import continuation
1156+
lock = Wthreading.Lock()
1157+
lock.acquire()
11171158
if debugging:
11181159
sys.settrace(None)
11191160
PyDebugger.postmortem(sys.exc_type, sys.exc_value, sys.exc_traceback)
11201161
return
11211162
else:
11221163
tracebackwindow.traceback(1, filename)
1123-
if uthread2:
1124-
uthread2.globalUnlock()
1164+
if haveThreading:
1165+
lock.release()
11251166
if debugging:
11261167
sys.settrace(None)
11271168
PyDebugger.stop()

0 commit comments

Comments
 (0)