Back to index

python3.2  3.2.2
Classes | Functions | Variables
idlelib.PyShell Namespace Reference

Classes

class  PyShellEditorWindow
class  PyShellFileList
class  ModifiedColorDelegator
class  ModifiedUndoDelegator
class  MyRPCClient
class  ModifiedInterpreter
class  PyShell
class  PseudoFile

Functions

def idle_showwarning
def idle_formatwarning
def extended_linecache_checkcache
def get_standard_extension_names
def set_warning_stream
def get_warning_stream
def toggle_debugger
def set_debugger_indicator
def toggle_jit_stack_viewer
def close_debugger
def open_debugger
def beginexecuting
def endexecuting
def close
def close2
def _close
def ispythonsource
def short_title
def begin
def readline
def isatty
def cancel_callback
def eof_callback
def linefeed_callback
def enter_callback
def recall
def runit
def open_stack_viewer
def view_restart_mark
def restart_shell
def showprompt
def resetoutput
def write
def main

Variables

string HOST = '127.0.0.1'
int PORT = 0
 warning_stream = sys.__stderr__
 text = self.text
 self.config(usetabs=1, indentwidth=8, context_use_ps1=1)
 reading = False
 executing = False
 canceled = False
 pass # ### 11Aug07 KBK if we are expecting exceptions let's find out what they are and be specific.
 endoffile = False
 closing = False
 COPYRIGHT = \
string usage_msg
 interp
 console
 history

Function Documentation

def idlelib.PyShell._close (   self) [private]

Definition at line 942 of file PyShell.py.

00942 
00943     def _close(self):
00944         "Extend EditorWindow._close(), shut down debugger and execution server"
00945         self.close_debugger()
00946         if use_subprocess:
00947             self.interp.kill_subprocess()
00948         # Restore std streams
00949         sys.stdout = self.save_stdout
00950         sys.stderr = self.save_stderr
00951         sys.stdin = self.save_stdin
00952         # Break cycles
00953         self.interp = None
00954         self.console = None
00955         self.flist.pyshell = None
00956         self.history = None
00957         EditorWindow._close(self)

Here is the caller graph for this function:

def idlelib.PyShell.begin (   self)

Definition at line 968 of file PyShell.py.

00968 
00969     def begin(self):
00970         self.text.mark_set("iomark", "insert")
00971         self.resetoutput()
00972         if use_subprocess:
00973             nosub = ''
00974             client = self.interp.start_subprocess()
00975             if not client:
00976                 self.close()
00977                 return False
00978         else:
00979             nosub = "==== No Subprocess ===="
00980         self.write("Python %s on %s\n%s\n%s" %
00981                    (sys.version, sys.platform, self.COPYRIGHT, nosub))
00982         self.showprompt()
00983         import tkinter
00984         tkinter._default_root = None # 03Jan04 KBK What's this?
00985         return True

Here is the caller graph for this function:

Definition at line 911 of file PyShell.py.

00911 
00912     def beginexecuting(self):
00913         "Helper for ModifiedInterpreter"
00914         self.resetoutput()
00915         self.executing = 1

def idlelib.PyShell.cancel_callback (   self,
  event = None 
)

Definition at line 1009 of file PyShell.py.

01009 
01010     def cancel_callback(self, event=None):
01011         try:
01012             if self.text.compare("sel.first", "!=", "sel.last"):
01013                 return # Active selection -- always use default binding
01014         except:
01015             pass
01016         if not (self.executing or self.reading):
01017             self.resetoutput()
01018             self.interp.write("KeyboardInterrupt\n")
01019             self.showprompt()
01020             return "break"
01021         self.endoffile = 0
01022         self.canceled = 1
01023         if (self.executing and self.interp.rpcclt):
01024             if self.interp.getdebugger():
01025                 self.interp.restart_subprocess()
01026             else:
01027                 self.interp.interrupt_subprocess()
01028         if self.reading:
01029             self.top.quit()  # exit the nested mainloop() in readline()
01030         return "break"

def idlelib.PyShell.close (   self)

Definition at line 922 of file PyShell.py.

00922 
00923     def close(self):
00924         "Extend EditorWindow.close()"
00925         if self.executing:
00926             response = tkMessageBox.askokcancel(
00927                 "Kill?",
00928                 "The program is still running!\n Do you want to kill it?",
00929                 default="ok",
00930                 parent=self.text)
00931             if response is False:
00932                 return "cancel"
00933         if self.reading:
00934             self.top.quit()
00935         self.canceled = True
00936         self.closing = True
00937         # Wait for poll_subprocess() rescheduling to stop
00938         self.text.after(2 * self.pollinterval, self.close2)

def idlelib.PyShell.close2 (   self)

Definition at line 939 of file PyShell.py.

00939 
00940     def close2(self):
00941         return EditorWindow.close(self)

Definition at line 886 of file PyShell.py.

00886 
00887     def close_debugger(self):
00888         db = self.interp.getdebugger()
00889         if db:
00890             self.interp.setdebugger(None)
00891             db.close()
00892             if self.interp.rpcclt:
00893                 RemoteDebugger.close_remote_debugger(self.interp.rpcclt)
00894             self.resetoutput()
00895             self.console.write("[DEBUG OFF]\n")
00896             sys.ps1 = ">>> "
00897             self.showprompt()
00898         self.set_debugger_indicator()

Definition at line 916 of file PyShell.py.

00916 
00917     def endexecuting(self):
00918         "Helper for ModifiedInterpreter"
00919         self.executing = 0
00920         self.canceled = 0
00921         self.showprompt()

def idlelib.PyShell.enter_callback (   self,
  event 
)

Definition at line 1055 of file PyShell.py.

01055 
01056     def enter_callback(self, event):
01057         if self.executing and not self.reading:
01058             return # Let the default binding (insert '\n') take over
01059         # If some text is selected, recall the selection
01060         # (but only if this before the I/O mark)
01061         try:
01062             sel = self.text.get("sel.first", "sel.last")
01063             if sel:
01064                 if self.text.compare("sel.last", "<=", "iomark"):
01065                     self.recall(sel, event)
01066                     return "break"
01067         except:
01068             pass
01069         # If we're strictly before the line containing iomark, recall
01070         # the current line, less a leading prompt, less leading or
01071         # trailing whitespace
01072         if self.text.compare("insert", "<", "iomark linestart"):
01073             # Check if there's a relevant stdin range -- if so, use it
01074             prev = self.text.tag_prevrange("stdin", "insert")
01075             if prev and self.text.compare("insert", "<", prev[1]):
01076                 self.recall(self.text.get(prev[0], prev[1]), event)
01077                 return "break"
01078             next = self.text.tag_nextrange("stdin", "insert")
01079             if next and self.text.compare("insert lineend", ">=", next[0]):
01080                 self.recall(self.text.get(next[0], next[1]), event)
01081                 return "break"
01082             # No stdin mark -- just get the current line, less any prompt
01083             indices = self.text.tag_nextrange("console", "insert linestart")
01084             if indices and \
01085                self.text.compare(indices[0], "<=", "insert linestart"):
01086                 self.recall(self.text.get(indices[1], "insert lineend"), event)
01087             else:
01088                 self.recall(self.text.get("insert linestart", "insert lineend"), event)
01089             return "break"
01090         # If we're between the beginning of the line and the iomark, i.e.
01091         # in the prompt area, move to the end of the prompt
01092         if self.text.compare("insert", "<", "iomark"):
01093             self.text.mark_set("insert", "iomark")
01094         # If we're in the current input and there's only whitespace
01095         # beyond the cursor, erase that whitespace first
01096         s = self.text.get("insert", "end-1c")
01097         if s and not s.strip():
01098             self.text.delete("insert", "end-1c")
01099         # If we're in the current input before its last line,
01100         # insert a newline right at the insert point
01101         if self.text.compare("insert", "<", "end-1c linestart"):
01102             self.newline_and_indent_event(event)
01103             return "break"
01104         # We're in the last line; append a newline and submit it
01105         self.text.mark_set("insert", "end-1c")
01106         if self.reading:
01107             self.text.insert("insert", "\n")
01108             self.text.see("insert")
01109         else:
01110             self.newline_and_indent_event(event)
01111         self.text.tag_add("stdin", "iomark", "end-1c")
01112         self.text.update_idletasks()
01113         if self.reading:
01114             self.top.quit() # Break out of recursive mainloop()
01115         else:
01116             self.runit()
01117         return "break"

def idlelib.PyShell.eof_callback (   self,
  event 
)

Definition at line 1031 of file PyShell.py.

01031 
01032     def eof_callback(self, event):
01033         if self.executing and not self.reading:
01034             return # Let the default binding (delete next char) take over
01035         if not (self.text.compare("iomark", "==", "insert") and
01036                 self.text.compare("insert", "==", "end-1c")):
01037             return # Let the default binding (delete next char) take over
01038         if not self.executing:
01039             self.resetoutput()
01040             self.close()
01041         else:
01042             self.canceled = 0
01043             self.endoffile = 1
01044             self.top.quit()
01045         return "break"

def idlelib.PyShell.extended_linecache_checkcache (   filename = None,
  orig_checkcache = linecache.checkcache 
)
Extend linecache.checkcache to preserve the <pyshell#...> entries

Rather than repeating the linecache code, patch it to save the
<pyshell#...> entries, call the original linecache.checkcache()
(skipping them), and then restore the saved entries.

orig_checkcache is bound at definition time to the original
method, allowing it to be patched.

Definition at line 76 of file PyShell.py.

00076 
00077                                   orig_checkcache=linecache.checkcache):
00078     """Extend linecache.checkcache to preserve the <pyshell#...> entries
00079 
00080     Rather than repeating the linecache code, patch it to save the
00081     <pyshell#...> entries, call the original linecache.checkcache()
00082     (skipping them), and then restore the saved entries.
00083 
00084     orig_checkcache is bound at definition time to the original
00085     method, allowing it to be patched.
00086     """
00087     cache = linecache.cache
00088     save = {}
00089     for key in list(cache):
00090         if key[:1] + key[-1:] == '<>':
00091             save[key] = cache.pop(key)
00092     orig_checkcache(filename)
00093     cache.update(save)
00094 
00095 # Patch linecache.checkcache():
00096 linecache.checkcache = extended_linecache_checkcache
00097 

Here is the caller graph for this function:

Definition at line 849 of file PyShell.py.

00849 
00850     def get_standard_extension_names(self):
00851         return idleConf.GetExtensions(shell_only=True)

Definition at line 862 of file PyShell.py.

00862 
00863     def get_warning_stream(self):
00864         return warning_stream

def idlelib.PyShell.idle_formatwarning (   message,
  category,
  filename,
  lineno,
  line = None 
)
Format warnings the IDLE way

Definition at line 62 of file PyShell.py.

00062 
00063     def idle_formatwarning(message, category, filename, lineno, line=None):
00064         """Format warnings the IDLE way"""
00065         s = "\nWarning (from warnings module):\n"
00066         s += '  File \"%s\", line %s\n' % (filename, lineno)
00067         if line is None:
00068             line = linecache.getline(filename, lineno)
00069         line = line.strip()
00070         if line:
00071             s += "    %s\n" % line
00072         s += "%s: %s\n>>> " % (category.__name__, message)
        return s

Here is the call graph for this function:

def idlelib.PyShell.idle_showwarning (   message,
  category,
  filename,
  lineno,
  file = None,
  line = None 
)

Definition at line 53 of file PyShell.py.

00053 
00054                          file=None, line=None):
00055         if file is None:
00056             file = warning_stream
00057         try:
00058             file.write(warnings.formatwarning(message, category, filename,
00059                                               lineno, line=line))
00060         except IOError:
            pass  ## file (probably __stderr__) is invalid, warning dropped.

Here is the call graph for this function:

def idlelib.PyShell.isatty (   self)

Definition at line 1006 of file PyShell.py.

01006 
01007     def isatty(self):
01008         return True

Here is the caller graph for this function:

def idlelib.PyShell.ispythonsource (   self,
  filename 
)

Definition at line 958 of file PyShell.py.

00958 
00959     def ispythonsource(self, filename):
00960         "Override EditorWindow method: never remove the colorizer"
00961         return True

def idlelib.PyShell.linefeed_callback (   self,
  event 
)

Definition at line 1046 of file PyShell.py.

01046 
01047     def linefeed_callback(self, event):
01048         # Insert a linefeed without entering anything (still autoindented)
01049         if self.reading:
01050             self.text.insert("insert", "\n")
01051             self.text.see("insert")
01052         else:
01053             self.newline_and_indent_event(event)
01054         return "break"

Definition at line 1286 of file PyShell.py.

01286 
01287 def main():
01288     global flist, root, use_subprocess
01289 
01290     use_subprocess = True
01291     enable_shell = True
01292     enable_edit = False
01293     debug = False
01294     cmd = None
01295     script = None
01296     startup = False
01297     try:
01298         opts, args = getopt.getopt(sys.argv[1:], "c:deihnr:st:")
01299     except getopt.error as msg:
01300         sys.stderr.write("Error: %s\n" % str(msg))
01301         sys.stderr.write(usage_msg)
01302         sys.exit(2)
01303     for o, a in opts:
01304         if o == '-c':
01305             cmd = a
01306             enable_shell = True
01307         if o == '-d':
01308             debug = True
01309             enable_shell = True
01310         if o == '-e':
01311             enable_edit = True
01312             enable_shell = False
01313         if o == '-h':
01314             sys.stdout.write(usage_msg)
01315             sys.exit()
01316         if o == '-i':
01317             enable_shell = True
01318         if o == '-n':
01319             use_subprocess = False
01320         if o == '-r':
01321             script = a
01322             if os.path.isfile(script):
01323                 pass
01324             else:
01325                 print("No script file: ", script)
01326                 sys.exit()
01327             enable_shell = True
01328         if o == '-s':
01329             startup = True
01330             enable_shell = True
01331         if o == '-t':
01332             PyShell.shell_title = a
01333             enable_shell = True
01334     if args and args[0] == '-':
01335         cmd = sys.stdin.read()
01336         enable_shell = True
01337     # process sys.argv and sys.path:
01338     for i in range(len(sys.path)):
01339         sys.path[i] = os.path.abspath(sys.path[i])
01340     if args and args[0] == '-':
01341         sys.argv = [''] + args[1:]
01342     elif cmd:
01343         sys.argv = ['-c'] + args
01344     elif script:
01345         sys.argv = [script] + args
01346     elif args:
01347         enable_edit = True
01348         pathx = []
01349         for filename in args:
01350             pathx.append(os.path.dirname(filename))
01351         for dir in pathx:
01352             dir = os.path.abspath(dir)
01353             if not dir in sys.path:
01354                 sys.path.insert(0, dir)
01355     else:
01356         dir = os.getcwd()
01357         if dir not in sys.path:
01358             sys.path.insert(0, dir)
01359     # check the IDLE settings configuration (but command line overrides)
01360     edit_start = idleConf.GetOption('main', 'General',
01361                                     'editor-on-startup', type='bool')
01362     enable_edit = enable_edit or edit_start
01363     # start editor and/or shell windows:
01364     root = Tk(className="Idle")
01365 
01366     fixwordbreaks(root)
01367     root.withdraw()
01368     flist = PyShellFileList(root)
01369     macosxSupport.setupApp(root, flist)
01370 
01371     if enable_edit:
01372         if not (cmd or script):
01373             for filename in args:
01374                 flist.open(filename)
01375             if not args:
01376                 flist.new()
01377     if enable_shell:
01378         shell = flist.open_shell()
01379         if not shell:
01380             return # couldn't open shell
01381 
01382         if macosxSupport.runningAsOSXApp() and flist.dict:
01383             # On OSX: when the user has double-clicked on a file that causes
01384             # IDLE to be launched the shell window will open just in front of
01385             # the file she wants to see. Lower the interpreter window when
01386             # there are open files.
01387             shell.top.lower()
01388 
01389     shell = flist.pyshell
01390     # handle remaining options:
01391     if debug:
01392         shell.open_debugger()
01393     if startup:
01394         filename = os.environ.get("IDLESTARTUP") or \
01395                    os.environ.get("PYTHONSTARTUP")
01396         if filename and os.path.isfile(filename):
01397             shell.interp.execfile(filename)
01398     if shell and cmd or script:
01399         shell.interp.runcommand("""if 1:
01400             import sys as _sys
01401             _sys.argv = %r
01402             del _sys
01403             \n""" % (sys.argv,))
01404         if cmd:
01405             shell.interp.execsource(cmd)
01406         elif script:
01407             shell.interp.prepend_syspath(script)
01408             shell.interp.execfile(script)
01409 
01410     # Check for problematic OS X Tk versions and print a warning message
01411     # in the IDLE shell window; this is less intrusive than always opening
01412     # a separate window.
01413     tkversionwarning = macosxSupport.tkVersionWarning(root)
01414     if tkversionwarning:
01415         shell.interp.runcommand(''.join(("print('", tkversionwarning, "')")))
01416 
01417     root.mainloop()
01418     root.destroy()

Here is the call graph for this function:

Definition at line 899 of file PyShell.py.

00899 
00900     def open_debugger(self):
00901         if self.interp.rpcclt:
00902             dbg_gui = RemoteDebugger.start_remote_debugger(self.interp.rpcclt,
00903                                                            self)
00904         else:
00905             dbg_gui = Debugger.Debugger(self)
00906         self.interp.setdebugger(dbg_gui)
00907         dbg_gui.load_breakpoints()
00908         sys.ps1 = "[DEBUG ON]\n>>> "
00909         self.showprompt()
00910         self.set_debugger_indicator()

def idlelib.PyShell.open_stack_viewer (   self,
  event = None 
)

Definition at line 1158 of file PyShell.py.

01158 
01159     def open_stack_viewer(self, event=None):
01160         if self.interp.rpcclt:
01161             return self.interp.remote_stack_viewer()
01162         try:
01163             sys.last_traceback
01164         except:
01165             tkMessageBox.showerror("No stack trace",
01166                 "There is no stack trace yet.\n"
01167                 "(sys.last_traceback is not defined)",
01168                 master=self.text)
01169             return
01170         from idlelib.StackViewer import StackBrowser
01171         sv = StackBrowser(self.root, self.flist)

Here is the call graph for this function:

def idlelib.PyShell.readline (   self)

Definition at line 986 of file PyShell.py.

00986 
00987     def readline(self):
00988         save = self.reading
00989         try:
00990             self.reading = 1
00991             self.top.mainloop()  # nested mainloop()
00992         finally:
00993             self.reading = save
00994         line = self.text.get("iomark", "end-1c")
00995         if len(line) == 0:  # may be EOF if we quit our mainloop with Ctrl-C
00996             line = "\n"
00997         self.resetoutput()
00998         if self.canceled:
00999             self.canceled = 0
01000             if not use_subprocess:
01001                 raise KeyboardInterrupt
01002         if self.endoffile:
01003             self.endoffile = 0
01004             line = ""
01005         return line

def idlelib.PyShell.recall (   self,
  s,
  event 
)

Definition at line 1118 of file PyShell.py.

01118 
01119     def recall(self, s, event):
01120         # remove leading and trailing empty or whitespace lines
01121         s = re.sub(r'^\s*\n', '' , s)
01122         s = re.sub(r'\n\s*$', '', s)
01123         lines = s.split('\n')
01124         self.text.undo_block_start()
01125         try:
01126             self.text.tag_remove("sel", "1.0", "end")
01127             self.text.mark_set("insert", "end-1c")
01128             prefix = self.text.get("insert linestart", "insert")
01129             if prefix.rstrip().endswith(':'):
01130                 self.newline_and_indent_event(event)
01131                 prefix = self.text.get("insert linestart", "insert")
01132             self.text.insert("insert", lines[0].strip())
01133             if len(lines) > 1:
01134                 orig_base_indent = re.search(r'^([ \t]*)', lines[0]).group(0)
01135                 new_base_indent  = re.search(r'^([ \t]*)', prefix).group(0)
01136                 for line in lines[1:]:
01137                     if line.startswith(orig_base_indent):
01138                         # replace orig base indentation with new indentation
01139                         line = new_base_indent + line[len(orig_base_indent):]
01140                     self.text.insert('insert', '\n'+line.rstrip())
01141         finally:
01142             self.text.see("insert")
01143             self.text.undo_block_stop()

Here is the call graph for this function:

Definition at line 1190 of file PyShell.py.

01190 
01191     def resetoutput(self):
01192         source = self.text.get("iomark", "end-1c")
01193         if self.history:
01194             self.history.history_store(source)
01195         if self.text.get("end-2c") != "\n":
01196             self.text.insert("end-1c", "\n")
01197         self.text.mark_set("iomark", "end-1c")
01198         self.set_line_and_column()

def idlelib.PyShell.restart_shell (   self,
  event = None 
)

Definition at line 1176 of file PyShell.py.

01176 
01177     def restart_shell(self, event=None):
01178         self.interp.restart_subprocess()

def idlelib.PyShell.runit (   self)

Definition at line 1144 of file PyShell.py.

01144 
01145     def runit(self):
01146         line = self.text.get("iomark", "end-1c")
01147         # Strip off last newline and surrounding whitespace.
01148         # (To allow you to hit return twice to end a statement.)
01149         i = len(line)
01150         while i > 0 and line[i-1] in " \t":
01151             i = i-1
01152         if i > 0 and line[i-1] == "\n":
01153             i = i-1
01154         while i > 0 and line[i-1] in " \t":
01155             i = i-1
01156         line = line[:i]
01157         more = self.interp.runsource(line)

Definition at line 879 of file PyShell.py.

00879 
00880     def set_debugger_indicator(self):
00881         db = self.interp.getdebugger()
00882         self.setvar("<<toggle-debugger>>", not not db)

def idlelib.PyShell.set_warning_stream (   self,
  stream 
)

Definition at line 858 of file PyShell.py.

00858 
00859     def set_warning_stream(self, stream):
00860         global warning_stream
00861         warning_stream = stream

Definition at line 962 of file PyShell.py.

00962 
00963     def short_title(self):
00964         return self.shell_title

Definition at line 1179 of file PyShell.py.

01179 
01180     def showprompt(self):
01181         self.resetoutput()
01182         try:
01183             s = str(sys.ps1)
01184         except:
01185             s = ""
01186         self.console.write(s)
01187         self.text.mark_set("insert", "end-1c")
01188         self.set_line_and_column()
01189         self.io.reset_undo()

def idlelib.PyShell.toggle_debugger (   self,
  event = None 
)

Definition at line 865 of file PyShell.py.

00865 
00866     def toggle_debugger(self, event=None):
00867         if self.executing:
00868             tkMessageBox.showerror("Don't debug now",
00869                 "You can only toggle the debugger when idle",
00870                 master=self.text)
00871             self.set_debugger_indicator()
00872             return "break"
00873         else:
00874             db = self.interp.getdebugger()
00875             if db:
00876                 self.close_debugger()
00877             else:
00878                 self.open_debugger()

def idlelib.PyShell.toggle_jit_stack_viewer (   self,
  event = None 
)

Definition at line 883 of file PyShell.py.

00883 
00884     def toggle_jit_stack_viewer(self, event=None):
00885         pass # All we need is the variable

def idlelib.PyShell.view_restart_mark (   self,
  event = None 
)

Definition at line 1172 of file PyShell.py.

01172 
01173     def view_restart_mark(self, event=None):
01174         self.text.see("iomark")
01175         self.text.see("restart")

def idlelib.PyShell.write (   self,
  s,
  tags = () 
)

Definition at line 1199 of file PyShell.py.

01199 
01200     def write(self, s, tags=()):
01201         try:
01202             self.text.mark_gravity("iomark", "right")
01203             OutputWindow.write(self, s, tags, "iomark")
01204             self.text.mark_gravity("iomark", "left")
01205         except:
01206             raise ###pass  # ### 11Aug07 KBK if we are expecting exceptions
01207                            # let's find out what they are and be specific.
01208         if self.canceled:
01209             self.canceled = 0
01210             if not use_subprocess:
01211                 raise KeyboardInterrupt


Variable Documentation

pass # ### 11Aug07 KBK if we are expecting exceptions let's find out what they are and be specific.

Definition at line 854 of file PyShell.py.

Definition at line 856 of file PyShell.py.

Definition at line 953 of file PyShell.py.

Definition at line 965 of file PyShell.py.

Definition at line 855 of file PyShell.py.

Definition at line 853 of file PyShell.py.

Definition at line 955 of file PyShell.py.

Definition at line 38 of file PyShell.py.

Definition at line 952 of file PyShell.py.

Definition at line 39 of file PyShell.py.

Definition at line 852 of file PyShell.py.

idlelib.PyShell.text = self.text

self.config(usetabs=1, indentwidth=8, context_use_ps1=1)

Definition at line 810 of file PyShell.py.

Definition at line 1233 of file PyShell.py.

Definition at line 46 of file PyShell.py.