Back to index

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

$ event <<expand-word>> $ win <Alt-slash> $ unix <Alt-slash> More...

Collaboration diagram for idlelib.AutoExpand.AutoExpand:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def expand_word_event
def getwords
def getprevword

Public Attributes

 text
 state

Static Public Attributes

list menudefs
string wordchars = "_"

Detailed Description

$ event <<expand-word>> $ win <Alt-slash> $ unix <Alt-slash>

Definition at line 8 of file AutoExpand.py.


Constructor & Destructor Documentation

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

Definition at line 18 of file AutoExpand.py.

00018 
00019     def __init__(self, editwin):
00020         self.text = editwin.text
00021         self.state = None

Here is the caller graph for this function:


Member Function Documentation

Definition at line 22 of file AutoExpand.py.

00022 
00023     def expand_word_event(self, event):
00024         curinsert = self.text.index("insert")
00025         curline = self.text.get("insert linestart", "insert lineend")
00026         if not self.state:
00027             words = self.getwords()
00028             index = 0
00029         else:
00030             words, index, insert, line = self.state
00031             if insert != curinsert or line != curline:
00032                 words = self.getwords()
00033                 index = 0
00034         if not words:
00035             self.text.bell()
00036             return "break"
00037         word = self.getprevword()
00038         self.text.delete("insert - %d chars" % len(word), "insert")
00039         newword = words[index]
00040         index = (index + 1) % len(words)
00041         if index == 0:
00042             self.text.bell()            # Warn we cycled around
00043         self.text.insert("insert", newword)
00044         curinsert = self.text.index("insert")
00045         curline = self.text.get("insert linestart", "insert lineend")
00046         self.state = words, index, curinsert, curline
00047         return "break"

Here is the call graph for this function:

Definition at line 78 of file AutoExpand.py.

00078 
00079     def getprevword(self):
00080         line = self.text.get("insert linestart", "insert")
00081         i = len(line)
00082         while i > 0 and line[i-1] in self.wordchars:
00083             i = i-1
00084         return line[i:]

Here is the caller graph for this function:

Definition at line 48 of file AutoExpand.py.

00048 
00049     def getwords(self):
00050         word = self.getprevword()
00051         if not word:
00052             return []
00053         before = self.text.get("1.0", "insert wordstart")
00054         wbefore = re.findall(r"\b" + word + r"\w+\b", before)
00055         del before
00056         after = self.text.get("insert wordend", "end")
00057         wafter = re.findall(r"\b" + word + r"\w+\b", after)
00058         del after
00059         if not wbefore and not wafter:
00060             return []
00061         words = []
00062         dict = {}
00063         # search backwards through words before
00064         wbefore.reverse()
00065         for w in wbefore:
00066             if dict.get(w):
00067                 continue
00068             words.append(w)
00069             dict[w] = w
00070         # search onwards through words after
00071         for w in wafter:
00072             if dict.get(w):
00073                 continue
00074             words.append(w)
00075             dict[w] = w
00076         words.append(word)
00077         return words

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Initial value:
[
        ('edit', [
            ('E_xpand Word', '<<expand-word>>'),
         ]),
    ]

Definition at line 10 of file AutoExpand.py.

Definition at line 20 of file AutoExpand.py.

Definition at line 19 of file AutoExpand.py.

Definition at line 16 of file AutoExpand.py.


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