summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/ScriptBinding.py
diff options
context:
space:
mode:
authorChui Tey <chui.tey@advdata.com.au>2002-05-26 13:36:41 (GMT)
committerChui Tey <chui.tey@advdata.com.au>2002-05-26 13:36:41 (GMT)
commit5d2af63cc36ca1141e1ec7412fc33866f3908408 (patch)
tree016d52a42559ae57d279719f711df48ad45bd204 /Lib/idlelib/ScriptBinding.py
parent38d53451b74d10f5b2045878e907ea510d94aed0 (diff)
downloadcpython-5d2af63cc36ca1141e1ec7412fc33866f3908408.zip
cpython-5d2af63cc36ca1141e1ec7412fc33866f3908408.tar.gz
cpython-5d2af63cc36ca1141e1ec7412fc33866f3908408.tar.bz2
GvR's rpc patch
Diffstat (limited to 'Lib/idlelib/ScriptBinding.py')
-rw-r--r--Lib/idlelib/ScriptBinding.py55
1 files changed, 36 insertions, 19 deletions
diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py
index 2b3bf99..906b4f2 100644
--- a/Lib/idlelib/ScriptBinding.py
+++ b/Lib/idlelib/ScriptBinding.py
@@ -14,6 +14,14 @@ namespace. Output goes to the shell window.
- Run module (Control-F5) does the same but executes the module's
code in the __main__ namespace.
+XXX Redesign this interface (yet again) as follows:
+
+- Present a dialog box for ``Run script''
+
+- Allow specify command line arguments in the dialog box
+
+- Restart the interpreter when running a script
+
"""
import sys
@@ -25,9 +33,9 @@ indent_message = """Error: Inconsistent indentation detected!
This means that either:
-(1) your indentation is outright incorrect (easy to fix), or
+1) your indentation is outright incorrect (easy to fix), or
-(2) your indentation mixes tabs and spaces in a way that depends on \
+2) your indentation mixes tabs and spaces in a way that depends on \
how many spaces a tab is worth.
To fix case 2, change all tabs to spaces by using Select All followed \
@@ -105,28 +113,31 @@ class ScriptBinding:
return 1
def import_module_event(self, event):
+ flist = self.editwin.flist
+ shell = flist.open_shell()
+ interp = shell.interp
+
filename = self.getfilename()
if not filename:
return
modname, ext = os.path.splitext(os.path.basename(filename))
- if sys.modules.has_key(modname):
- mod = sys.modules[modname]
- else:
- mod = imp.new_module(modname)
- sys.modules[modname] = mod
- mod.__file__ = filename
- setattr(sys.modules['__main__'], modname, mod)
dir = os.path.dirname(filename)
dir = os.path.normpath(os.path.abspath(dir))
- if dir not in sys.path:
- sys.path.insert(0, dir)
- flist = self.editwin.flist
- shell = flist.open_shell()
- interp = shell.interp
- interp.runcode("reload(%s)" % modname)
+ interp.runcode("""if 1:
+ import sys as _sys
+ if %s not in _sys.path:
+ _sys.path.insert(0, %s)
+ if _sys.modules.get(%s):
+ del _sys
+ import %s
+ reload(%s)
+ else:
+ del _sys
+ import %s
+ \n""" % (`dir`, `dir`, `modname`, modname, modname, modname))
def run_script_event(self, event):
filename = self.getfilename()
@@ -136,10 +147,16 @@ class ScriptBinding:
flist = self.editwin.flist
shell = flist.open_shell()
interp = shell.interp
- if (not sys.argv or
- os.path.basename(sys.argv[0]) != os.path.basename(filename)):
- # XXX Too often this discards arguments the user just set...
- sys.argv = [filename]
+ # XXX Too often this discards arguments the user just set...
+ interp.runcommand("""if 1:
+ _filename = %s
+ import sys as _sys
+ from os.path import basename as _basename
+ if (not _sys.argv or
+ _basename(_sys.argv[0]) != _basename(_filename)):
+ _sys.argv = [_filename]
+ del _filename, _sys, _basename
+ \n""" % `filename`)
interp.execfile(filename)
def getfilename(self):