summaryrefslogtreecommitdiffstats
path: root/Tools/idle/ScriptBinding.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-01-02 21:28:54 (GMT)
committerGuido van Rossum <guido@python.org>1999-01-02 21:28:54 (GMT)
commit504b0bf066e4fddb21646331e89c2f6836c5c638 (patch)
treef5454648430eb4818810305325561aabb02cf035 /Tools/idle/ScriptBinding.py
parentf07c328c072e62ada8671ec30392572add22d904 (diff)
downloadcpython-504b0bf066e4fddb21646331e89c2f6836c5c638.zip
cpython-504b0bf066e4fddb21646331e89c2f6836c5c638.tar.gz
cpython-504b0bf066e4fddb21646331e89c2f6836c5c638.tar.bz2
Checking in IDLE 0.2.
Much has changed -- too much, in fact, to write down. The big news is that there's a standard way to write IDLE extensions; see extend.txt. Some sample extensions have been provided, and some existing code has been converted to extensions. Probably the biggest new user feature is a new search dialog with more options, search and replace, and even search in files (grep). This is exactly as downloaded from my laptop after returning from the holidays -- it hasn't even been tested on Unix yet.
Diffstat (limited to 'Tools/idle/ScriptBinding.py')
-rw-r--r--Tools/idle/ScriptBinding.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Tools/idle/ScriptBinding.py b/Tools/idle/ScriptBinding.py
new file mode 100644
index 0000000..a112fc5
--- /dev/null
+++ b/Tools/idle/ScriptBinding.py
@@ -0,0 +1,38 @@
+import tkMessageBox
+import os
+import imp
+import sys
+
+class ScriptBinding:
+
+ def __init__(self, editwin):
+ self.editwin = editwin
+ text = editwin.text
+ text.bind("<<run-module>>", self.run_module)
+ text.bind("<<run-script>>", self.run_script)
+ text.bind("<<new-shell>>", self.new_shell)
+
+ def run_module(self, event=None):
+ filename = self.editwin.io.filename
+ if not filename:
+ tkMessageBox.showerror("No file name",
+ "This window has no file name",
+ master=self.editwin.text)
+ return
+ modname, ext = os.path.splitext(os.path.basename(filename))
+ try:
+ mod = sys.modules[modname]
+ except KeyError:
+ mod = imp.new_module(modname)
+ sys.modules[modname] = mod
+ source = self.editwin.text.get("1.0", "end")
+ exec source in mod.__dict__
+
+ def run_script(self, event=None):
+ pass
+
+ def new_shell(self, event=None):
+ import PyShell
+ # XXX Not enough: each shell takes over stdin/stdout/stderr...
+ pyshell = PyShell.PyShell(self.editwin.flist)
+ pyshell.begin()