Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
idlelib.ScriptBinding.ScriptBinding Class Reference

List of all members.

Public Member Functions

def __init__
def check_module_event
def tabnanny
def checksyntax
def run_module_event
def getfilename
def ask_save_dialog
def errorbox

Public Attributes

 editwin
 flist
 root
 shell

Static Public Attributes

list menudefs

Private Member Functions

def _run_module_event

Detailed Description

Definition at line 42 of file ScriptBinding.py.


Constructor & Destructor Documentation

def idlelib.ScriptBinding.ScriptBinding.__init__ (   self,
  editwin 
)

Definition at line 49 of file ScriptBinding.py.

00049 
00050     def __init__(self, editwin):
00051         self.editwin = editwin
00052         # Provide instance variables referenced by Debugger
00053         # XXX This should be done differently
00054         self.flist = self.editwin.flist
00055         self.root = self.editwin.root
00056 
00057         if macosxSupport.runningAsOSXApp():
00058             self.editwin.text_frame.bind('<<run-module-event-2>>', self._run_module_event)

Here is the caller graph for this function:


Member Function Documentation

def idlelib.ScriptBinding.ScriptBinding._run_module_event (   self,
  event 
) [private]
Run the module after setting up the environment.

First check the syntax.  If OK, make sure the shell is active and
then transfer the arguments, set the run environment's working
directory to the directory of the module being executed and also
add that directory to its sys.path if not already included.

Definition at line 135 of file ScriptBinding.py.

00135 
00136     def _run_module_event(self, event):
00137         """Run the module after setting up the environment.
00138 
00139         First check the syntax.  If OK, make sure the shell is active and
00140         then transfer the arguments, set the run environment's working
00141         directory to the directory of the module being executed and also
00142         add that directory to its sys.path if not already included.
00143         """
00144 
00145         filename = self.getfilename()
00146         if not filename:
00147             return 'break'
00148         code = self.checksyntax(filename)
00149         if not code:
00150             return 'break'
00151         if not self.tabnanny(filename):
00152             return 'break'
00153         shell = self.shell
00154         interp = shell.interp
00155         if PyShell.use_subprocess:
00156             shell.restart_shell()
00157         dirname = os.path.dirname(filename)
00158         # XXX Too often this discards arguments the user just set...
00159         interp.runcommand("""if 1:
00160             _filename = %r
00161             import sys as _sys
00162             from os.path import basename as _basename
00163             if (not _sys.argv or
00164                 _basename(_sys.argv[0]) != _basename(_filename)):
00165                 _sys.argv = [_filename]
00166             import os as _os
00167             _os.chdir(%r)
00168             del _filename, _sys, _basename, _os
00169             \n""" % (filename, dirname))
00170         interp.prepend_syspath(filename)
00171         # XXX KBK 03Jul04 When run w/o subprocess, runtime warnings still
00172         #         go to __stderr__.  With subprocess, they go to the shell.
00173         #         Need to change streams in PyShell.ModifiedInterpreter.
00174         interp.runcode(code)
00175         return 'break'

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 203 of file ScriptBinding.py.

00203 
00204     def ask_save_dialog(self):
00205         msg = "Source Must Be Saved\n" + 5*' ' + "OK to Save?"
00206         confirm = tkMessageBox.askokcancel(title="Save Before Run or Check",
00207                                            message=msg,
00208                                            default=tkMessageBox.OK,
00209                                            master=self.editwin.text)
00210         return confirm

Here is the caller graph for this function:

Definition at line 59 of file ScriptBinding.py.

00059 
00060     def check_module_event(self, event):
00061         filename = self.getfilename()
00062         if not filename:
00063             return 'break'
00064         if not self.checksyntax(filename):
00065             return 'break'
00066         if not self.tabnanny(filename):
00067             return 'break'

Here is the call graph for this function:

def idlelib.ScriptBinding.ScriptBinding.checksyntax (   self,
  filename 
)

Definition at line 91 of file ScriptBinding.py.

00091 
00092     def checksyntax(self, filename):
00093         self.shell = shell = self.flist.open_shell()
00094         saved_stream = shell.get_warning_stream()
00095         shell.set_warning_stream(shell.stderr)
00096         f = open(filename, 'rb')
00097         source = f.read()
00098         f.close()
00099         if b'\r' in source:
00100             source = source.replace(b'\r\n', b'\n')
00101             source = source.replace(b'\r', b'\n')
00102         if source and source[-1] != ord(b'\n'):
00103             source = source + b'\n'
00104         editwin = self.editwin
00105         text = editwin.text
00106         text.tag_remove("ERROR", "1.0", "end")
00107         try:
00108             # If successful, return the compiled code
00109             return compile(source, filename, "exec")
00110         except (SyntaxError, OverflowError) as value:
00111             msg = value.msg or "<no detail available>"
00112             lineno = value.lineno or 1
00113             offset = value.offset or 0
00114             if offset == 0:
00115                 lineno += 1  #mark end of offending line
00116             pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1)
00117             editwin.colorize_syntax_error(text, pos)
00118             self.errorbox("SyntaxError", "%-20s" % msg)
00119             return False
00120         finally:
00121             shell.set_warning_stream(saved_stream)

Here is the caller graph for this function:

def idlelib.ScriptBinding.ScriptBinding.errorbox (   self,
  title,
  message 
)

Definition at line 211 of file ScriptBinding.py.

00211 
00212     def errorbox(self, title, message):
00213         # XXX This should really be a function of EditorWindow...
00214         tkMessageBox.showerror(title, message, master=self.editwin.text)
00215         self.editwin.text.focus_set()

Here is the caller graph for this function:

Get source filename.  If not saved, offer to save (or create) file

The debugger requires a source file.  Make sure there is one, and that
the current version of the source buffer has been saved.  If the user
declines to save or cancels the Save As dialog, return None.

If the user has configured IDLE for Autosave, the file will be
silently saved if it already exists and is dirty.

Definition at line 176 of file ScriptBinding.py.

00176 
00177     def getfilename(self):
00178         """Get source filename.  If not saved, offer to save (or create) file
00179 
00180         The debugger requires a source file.  Make sure there is one, and that
00181         the current version of the source buffer has been saved.  If the user
00182         declines to save or cancels the Save As dialog, return None.
00183 
00184         If the user has configured IDLE for Autosave, the file will be
00185         silently saved if it already exists and is dirty.
00186 
00187         """
00188         filename = self.editwin.io.filename
00189         if not self.editwin.get_saved():
00190             autosave = idleConf.GetOption('main', 'General',
00191                                           'autosave', type='bool')
00192             if autosave and filename:
00193                 self.editwin.io.save(None)
00194             else:
00195                 confirm = self.ask_save_dialog()
00196                 self.editwin.text.focus_set()
00197                 if confirm:
00198                     self.editwin.io.save(None)
00199                     filename = self.editwin.io.filename
00200                 else:
00201                     filename = None
00202         return filename

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 122 of file ScriptBinding.py.

00122 
00123     def run_module_event(self, event):
00124         if macosxSupport.runningAsOSXApp():
00125             # Tk-Cocoa in MacOSX is broken until at least
00126             # Tk 8.5.9, and without this rather
00127             # crude workaround IDLE would hang when a user
00128             # tries to run a module using the keyboard shortcut
00129             # (the menu item works fine).
00130             self.editwin.text_frame.after(200,
00131                 lambda: self.editwin.text_frame.event_generate('<<run-module-event-2>>'))
00132             return 'break'
00133         else:
00134             return self._run_module_event(event)

Here is the call graph for this function:

def idlelib.ScriptBinding.ScriptBinding.tabnanny (   self,
  filename 
)

Definition at line 68 of file ScriptBinding.py.

00068 
00069     def tabnanny(self, filename):
00070         # XXX: tabnanny should work on binary files as well
00071         with open(filename, 'r', encoding='iso-8859-1') as f:
00072             two_lines = f.readline() + f.readline()
00073         encoding = IOBinding.coding_spec(two_lines)
00074         if not encoding:
00075             encoding = 'utf-8'
00076         f = open(filename, 'r', encoding=encoding)
00077         try:
00078             tabnanny.process_tokens(tokenize.generate_tokens(f.readline))
00079         except tokenize.TokenError as msg:
00080             msgtxt, (lineno, start) = msg
00081             self.editwin.gotoline(lineno)
00082             self.errorbox("Tabnanny Tokenizing Error",
00083                           "Token Error: %s" % msgtxt)
00084             return False
00085         except tabnanny.NannyNag as nag:
00086             # The error messages from tabnanny are too confusing...
00087             self.editwin.gotoline(nag.get_lineno())
00088             self.errorbox("Tab/space error", indent_message)
00089             return False
00090         return True

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 50 of file ScriptBinding.py.

Definition at line 53 of file ScriptBinding.py.

Initial value:
[
        ('run', [None,
                 ('Check Module', '<<check-module>>'),
                 ('Run Module', '<<run-module>>'), ]), ]

Definition at line 44 of file ScriptBinding.py.

Definition at line 54 of file ScriptBinding.py.

Definition at line 92 of file ScriptBinding.py.


The documentation for this class was generated from the following file: