Index: ScriptBinding.py =================================================================== --- ScriptBinding.py (revision 77980) +++ ScriptBinding.py (working copy) @@ -22,7 +22,9 @@ import string import tabnanny import tokenize +import shlex import tkMessageBox +import tkSimpleDialog import PyShell from configHandler import idleConf @@ -39,6 +41,24 @@ by Format->Untabify Region and specify the number of columns used by each tab. """ + +class QueryCommandLine(tkSimpleDialog._QueryString): + + errormessage = "Malformed command line." + + def body(self, master): + # default Entry widget is too narrow + entry = tkSimpleDialog._QueryString.body(self, master) + entry.configure(width=50) + return entry + + def getresult(self): + result = tkSimpleDialog._QueryString.getresult(self) + # validate it; errors are handled in base class + shlex.split(result) + return result + + class ScriptBinding: menudefs = [ @@ -142,23 +162,30 @@ return 'break' if not self.tabnanny(filename): return 'break' + prev_command_line = idleConf.GetOption("extensions", "ScriptBinding", + "command_line", type="str", default="") + command_line = QueryCommandLine("Run Module", + "Command line arguments", + initialvalue=prev_command_line, + parent=self.editwin.text).result + if command_line is None: + return 'break' + idleConf.SetOption("extensions", "ScriptBinding", + "command_line", value=command_line) + idleConf.userCfg["extensions"].Save() shell = self.shell interp = shell.interp if PyShell.use_subprocess: shell.restart_shell() dirname = os.path.dirname(filename) - # XXX Too often this discards arguments the user just set... + argv = [filename] + shlex.split(command_line) interp.runcommand("""if 1: - _filename = %r 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] + _sys.argv = %r import os as _os _os.chdir(%r) - del _filename, _sys, _basename, _os - \n""" % (filename, dirname)) + del _sys, _os + \n""" % (argv, dirname)) interp.prepend_syspath(filename) # XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still # go to __stderr__. With subprocess, they go to the shell.