Back to index

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

List of all members.

Public Member Functions

def __init__
def close
def format_paragraph_event

Public Attributes

 editwin

Static Public Attributes

list menudefs

Detailed Description

Definition at line 20 of file FormatParagraph.py.


Constructor & Destructor Documentation

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

Definition at line 28 of file FormatParagraph.py.

00028 
00029     def __init__(self, editwin):
00030         self.editwin = editwin

Here is the caller graph for this function:


Member Function Documentation

Definition at line 31 of file FormatParagraph.py.

00031 
00032     def close(self):
00033         self.editwin = None

Here is the caller graph for this function:

Definition at line 34 of file FormatParagraph.py.

00034 
00035     def format_paragraph_event(self, event):
00036         maxformatwidth = int(idleConf.GetOption('main','FormatParagraph','paragraph'))
00037         text = self.editwin.text
00038         first, last = self.editwin.get_selection_indices()
00039         if first and last:
00040             data = text.get(first, last)
00041             comment_header = ''
00042         else:
00043             first, last, comment_header, data = \
00044                     find_paragraph(text, text.index("insert"))
00045         if comment_header:
00046             # Reformat the comment lines - convert to text sans header.
00047             lines = data.split("\n")
00048             lines = map(lambda st, l=len(comment_header): st[l:], lines)
00049             data = "\n".join(lines)
00050             # Reformat to maxformatwidth chars or a 20 char width, whichever is greater.
00051             format_width = max(maxformatwidth - len(comment_header), 20)
00052             newdata = reformat_paragraph(data, format_width)
00053             # re-split and re-insert the comment header.
00054             newdata = newdata.split("\n")
00055             # If the block ends in a \n, we dont want the comment
00056             # prefix inserted after it. (Im not sure it makes sense to
00057             # reformat a comment block that isnt made of complete
00058             # lines, but whatever!)  Can't think of a clean solution,
00059             # so we hack away
00060             block_suffix = ""
00061             if not newdata[-1]:
00062                 block_suffix = "\n"
00063                 newdata = newdata[:-1]
00064             builder = lambda item, prefix=comment_header: prefix+item
00065             newdata = '\n'.join(map(builder, newdata)) + block_suffix
00066         else:
00067             # Just a normal text format
00068             newdata = reformat_paragraph(data, maxformatwidth)
00069         text.tag_remove("sel", "1.0", "end")
00070         if newdata != data:
00071             text.mark_set("insert", first)
00072             text.undo_block_start()
00073             text.delete(first, last)
00074             text.insert(first, newdata)
00075             text.undo_block_stop()
00076         else:
00077             text.mark_set("insert", last)
00078         text.see("insert")
00079         return "break"

Here is the call graph for this function:


Member Data Documentation

Definition at line 29 of file FormatParagraph.py.

Initial value:
[
        ('format', [   # /s/edit/format   dscherer@cmu.edu
            ('Format Paragraph', '<<format-paragraph>>'),
         ])
    ]

Definition at line 22 of file FormatParagraph.py.


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