def __init__(self, flist=None):
     if use_subprocess:
         ms = self.menu_specs
         if ms[2][0] != 'shell':
             ms.insert(2, ('shell', 'She_ll'))
     self.interp = ModifiedInterpreter(self)
     if flist is None:
         root = Tk()
         fixwordbreaks(root)
         root.withdraw()
         flist = PyShellFileList(root)
     OutputWindow.__init__(self, flist, None, None)
     self.usetabs = True
     self.indentwidth = 8
     self.context_use_ps1 = True
     text = self.text
     text.configure(wrap='char')
     text.bind('<<newline-and-indent>>', self.enter_callback)
     text.bind('<<plain-newline-and-indent>>', self.linefeed_callback)
     text.bind('<<interrupt-execution>>', self.cancel_callback)
     text.bind('<<end-of-file>>', self.eof_callback)
     text.bind('<<open-stack-viewer>>', self.open_stack_viewer)
     text.bind('<<toggle-debugger>>', self.toggle_debugger)
     text.bind('<<toggle-jit-stack-viewer>>', self.toggle_jit_stack_viewer)
     if use_subprocess:
         text.bind('<<view-restart>>', self.view_restart_mark)
         text.bind('<<restart-shell>>', self.restart_shell)
     self.save_stdout = sys.stdout
     self.save_stderr = sys.stderr
     self.save_stdin = sys.stdin
     from idlelib import iomenu
     self.stdin = PseudoInputFile(self, 'stdin', iomenu.encoding)
     self.stdout = PseudoOutputFile(self, 'stdout', iomenu.encoding)
     self.stderr = PseudoOutputFile(self, 'stderr', iomenu.encoding)
     self.console = PseudoOutputFile(self, 'console', iomenu.encoding)
     if not use_subprocess:
         sys.stdout = self.stdout
         sys.stderr = self.stderr
         sys.stdin = self.stdin
     try:
         import pydoc
         pydoc.pager = pydoc.plainpager
     except:
         sys.stderr = sys.__stderr__
         raise
     self.history = self.History(self.text)
     self.pollinterval = 50
 def default_command(self, event=None):
     prog = self.engine.getprog()
     if not prog:
         return
     path = self.globvar.get()
     if not path:
         self.top.bell()
         return
     from idlelib.outwin import OutputWindow  # leave here!
     save = sys.stdout
     try:
         sys.stdout = OutputWindow(self.flist)
         self.grep_it(prog, path)
     finally:
         sys.stdout = save
 def write(self, s, tags=()):
     if isinstance(s, str) and len(s) and max(s) > '\uffff':
         for start, char in enumerate(s):
             if char > '\uffff':
                 break
         raise UnicodeEncodeError('UCS-2', char, start, start + 1,
                                  'Non-BMP character not supported in Tk')
     try:
         self.text.mark_gravity('iomark', 'right')
         count = OutputWindow.write(self, s, tags, 'iomark')
         self.text.mark_gravity('iomark', 'left')
     except:
         raise
     if self.canceled:
         self.canceled = 0
         if not use_subprocess:
             raise KeyboardInterrupt
     return count
Exemple #4
0
    def default_command(self, event=None):
        """Grep for search pattern in file path. The default command is bound
        to <Return>.

        If entry values are populated, set OutputWindow as stdout
        and perform search.  The search dialog is closed automatically
        when the search begins.
        """
        prog = self.engine.getprog()
        if not prog:
            return
        path = self.globvar.get()
        if not path:
            self.top.bell()
            return
        from idlelib.outwin import OutputWindow  # leave here!
        save = sys.stdout
        try:
            sys.stdout = OutputWindow(self.flist)
            self.grep_it(prog, path)
        finally:
            sys.stdout = save