PyWin editor modification

Mark Tolonen metolone+gmane at
Sat Sep 12 16:03:50 CEST 2009

"C or L Smith" <smiles at> wrote in message 
news:0BFE194EDBB6410CB3B319CDDA601EDF at
> The PyWin editor that comes with the Windows distribution is a great 
> little workhorse. If you have used it you perhaps notice how it 
> intelligently works with spaces and indentation, e.g. after typing the 
> word 'pass' and pressing enter it dedents one level as you would probably 
> desire. It also strips trailing space from every line that you 
> enter...unless that line contains ONLY space.
> The following modification to the file in the 
> pythonwin\pywin\idle directory makes the editor strip all trailing space, 
> even if that's all a line contains. With this modification, no line that 
> you enter with the PyWin editor will ever contain trailing space (unless 
> you purposely add it to the end of a line but then don't press <enter>).
> Search for the word "inject" which appears only once in the file and add 
> the line as indicated below:
> if i == n:
>    # the cursor is in or at leading indentation; just inject
>    # an empty line at the start
>    text.delete("insert - %d chars" % i, "insert")  <== add this line
>    text.insert("insert linestart", '\n')
>    return "break"

I like it!  You should post it to pywin32 sourceforge patches.

Here's one I did.  I like to clear the interactive window with CTRL-A, DEL 
before running a script.  However, if the script is run its output uses the 
blue, proportional font that the banner in that window uses when Pythonwin 
is first opened.  This happens whenever the cursor is on the first line of 
the interactive window.  So I would type CTRL-A,DEL, 2xEnter, 4xbackspace to 
move the cursor to the 2nd line and delete the prompt instead.  The diff 
patch below adds four lines to pythonwin\pywin\framework\ to 
correct this problem and use the fixed font used for script output.

(Also posted to pywin32 Patches @

diff -r 108cdf7a1232
--- a/ Fri Jun 26 08:34:29 2009 -0700
+++ b/ Fri Jun 26 08:36:48 2009 -0700
@@ -94,6 +94,7 @@
 class InteractiveFormatter(FormatterParent):
  def __init__(self, scintilla):
   FormatterParent.__init__(self, scintilla)
+  self.bannerDisplayed = False

  def SetStyles(self):
@@ -233,8 +234,11 @@
   if start > 0:
    stylenum = self.scintilla.SCIGetStyleAt(start - 1)
    styleStart = self.GetStyleByNum(stylenum).name
+  elif self.bannerDisplayed:
+   self.bannerDisplayed = True
   self.scintilla.SCIStartStyling(start, 31)
   self.style_buffer = array.array("b", (0,)*len(stringVal))
   self.ColorizeInteractiveCode(stringVal, styleStart, stylePyStart)


More information about the Python-list mailing list