Back to index

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

List of all members.

Public Member Functions

def __init__
def getpat
def setpat
def isre
def iscase
def isword
def iswrap
def isback
def getcookedpat
def getprog
def report_error
def setcookedpat
def search_text
def search_forward
def search_backward

Public Attributes

 root
 patvar
 revar
 casevar
 wordvar
 wrapvar
 backvar

Detailed Description

Definition at line 11 of file SearchEngine.py.


Constructor & Destructor Documentation

def idlelib.SearchEngine.SearchEngine.__init__ (   self,
  root 
)

Definition at line 13 of file SearchEngine.py.

00013 
00014     def __init__(self, root):
00015         self.root = root
00016         # State shared by search, replace, and grep;
00017         # the search dialogs bind these to UI elements.
00018         self.patvar = StringVar(root)           # search pattern
00019         self.revar = BooleanVar(root)           # regular expression?
00020         self.casevar = BooleanVar(root)         # match case?
00021         self.wordvar = BooleanVar(root)         # match whole word?
00022         self.wrapvar = BooleanVar(root)         # wrap around buffer?
00023         self.wrapvar.set(1)                     # (on by default)
00024         self.backvar = BooleanVar(root)         # search backwards?

Here is the caller graph for this function:


Member Function Documentation

Definition at line 50 of file SearchEngine.py.

00050 
00051     def getcookedpat(self):
00052         pat = self.getpat()
00053         if not self.isre():
00054             pat = re.escape(pat)
00055         if self.isword():
00056             pat = r"\b%s\b" % pat
00057         return pat

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 27 of file SearchEngine.py.

00027 
00028     def getpat(self):
00029         return self.patvar.get()

Here is the caller graph for this function:

Definition at line 58 of file SearchEngine.py.

00058 
00059     def getprog(self):
00060         pat = self.getpat()
00061         if not pat:
00062             self.report_error(pat, "Empty regular expression")
00063             return None
00064         pat = self.getcookedpat()
00065         flags = 0
00066         if not self.iscase():
00067             flags = flags | re.IGNORECASE
00068         try:
00069             prog = re.compile(pat, flags)
00070         except re.error as what:
00071             try:
00072                 msg, col = what
00073             except:
00074                 msg = str(what)
00075                 col = -1
00076             self.report_error(pat, msg, col)
00077             return None
00078         return prog

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 45 of file SearchEngine.py.

00045 
00046     def isback(self):
00047         return self.backvar.get()

Here is the caller graph for this function:

Definition at line 36 of file SearchEngine.py.

00036 
00037     def iscase(self):
00038         return self.casevar.get()

Here is the caller graph for this function:

Definition at line 33 of file SearchEngine.py.

00033 
00034     def isre(self):
00035         return self.revar.get()

Here is the caller graph for this function:

Definition at line 39 of file SearchEngine.py.

00039 
00040     def isword(self):
00041         return self.wordvar.get()

Here is the caller graph for this function:

Definition at line 42 of file SearchEngine.py.

00042 
00043     def iswrap(self):
00044         return self.wrapvar.get()

def idlelib.SearchEngine.SearchEngine.report_error (   self,
  pat,
  msg,
  col = -1 
)

Definition at line 79 of file SearchEngine.py.

00079 
00080     def report_error(self, pat, msg, col=-1):
00081         # Derived class could overrid this with something fancier
00082         msg = "Error: " + str(msg)
00083         if pat:
00084             msg = msg + "\np\Pattern: " + str(pat)
00085         if col >= 0:
00086             msg = msg + "\nOffset: " + str(col)
00087         tkMessageBox.showerror("Regular expression error",
00088                                msg, master=self.root)

Here is the caller graph for this function:

def idlelib.SearchEngine.SearchEngine.search_backward (   self,
  text,
  prog,
  line,
  col,
  wrap,
  ok = 0 
)

Definition at line 158 of file SearchEngine.py.

00158 
00159     def search_backward(self, text, prog, line, col, wrap, ok=0):
00160         wrapped = 0
00161         startline = line
00162         chars = text.get("%d.0" % line, "%d.0" % (line+1))
00163         while 1:
00164             m = search_reverse(prog, chars[:-1], col)
00165             if m:
00166                 if ok or m.start() < col:
00167                     return line, m
00168             line = line - 1
00169             if wrapped and line < startline:
00170                 break
00171             ok = 1
00172             if line <= 0:
00173                 if not wrap:
00174                     break
00175                 wrapped = 1
00176                 wrap = 0
00177                 pos = text.index("end-1c")
00178                 line, col = map(int, pos.split("."))
00179             chars = text.get("%d.0" % line, "%d.0" % (line+1))
00180             col = len(chars) - 1
00181         return None
00182 
00183 # Helper to search backwards in a string.
00184 # (Optimized for the case where the pattern isn't found.)

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.SearchEngine.SearchEngine.search_forward (   self,
  text,
  prog,
  line,
  col,
  wrap,
  ok = 0 
)

Definition at line 136 of file SearchEngine.py.

00136 
00137     def search_forward(self, text, prog, line, col, wrap, ok=0):
00138         wrapped = 0
00139         startline = line
00140         chars = text.get("%d.0" % line, "%d.0" % (line+1))
00141         while chars:
00142             m = prog.search(chars[:-1], col)
00143             if m:
00144                 if ok or m.end() > col:
00145                     return line, m
00146             line = line + 1
00147             if wrapped and line > startline:
00148                 break
00149             col = 0
00150             ok = 1
00151             chars = text.get("%d.0" % line, "%d.0" % (line+1))
00152             if not chars and wrap:
00153                 wrapped = 1
00154                 wrap = 0
00155                 line = 1
00156                 chars = text.get("1.0", "2.0")
00157         return None

Here is the caller graph for this function:

def idlelib.SearchEngine.SearchEngine.search_text (   self,
  text,
  prog = None,
  ok = 0 
)
Search a text widget for the pattern.

If prog is given, it should be the precompiled pattern.
Return a tuple (lineno, matchobj); None if not found.

This obeys the wrap and direction (back) settings.

The search starts at the selection (if there is one) or
at the insert mark (otherwise).  If the search is forward,
it starts at the right of the selection; for a backward
search, it starts at the left end.  An empty match exactly
at either end of the selection (or at the insert mark if
there is no selection) is ignored  unless the ok flag is true
-- this is done to guarantee progress.

If the search is allowed to wrap around, it will return the
original selection if (and only if) it is the only match.

Definition at line 94 of file SearchEngine.py.

00094 
00095     def search_text(self, text, prog=None, ok=0):
00096         """Search a text widget for the pattern.
00097 
00098         If prog is given, it should be the precompiled pattern.
00099         Return a tuple (lineno, matchobj); None if not found.
00100 
00101         This obeys the wrap and direction (back) settings.
00102 
00103         The search starts at the selection (if there is one) or
00104         at the insert mark (otherwise).  If the search is forward,
00105         it starts at the right of the selection; for a backward
00106         search, it starts at the left end.  An empty match exactly
00107         at either end of the selection (or at the insert mark if
00108         there is no selection) is ignored  unless the ok flag is true
00109         -- this is done to guarantee progress.
00110 
00111         If the search is allowed to wrap around, it will return the
00112         original selection if (and only if) it is the only match.
00113 
00114         """
00115         if not prog:
00116             prog = self.getprog()
00117             if not prog:
00118                 return None # Compilation failed -- stop
00119         wrap = self.wrapvar.get()
00120         first, last = get_selection(text)
00121         if self.isback():
00122             if ok:
00123                 start = last
00124             else:
00125                 start = first
00126             line, col = get_line_col(start)
00127             res = self.search_backward(text, prog, line, col, wrap, ok)
00128         else:
00129             if ok:
00130                 start = first
00131             else:
00132                 start = last
00133             line, col = get_line_col(start)
00134             res = self.search_forward(text, prog, line, col, wrap, ok)
00135         return res

Here is the call graph for this function:

Definition at line 89 of file SearchEngine.py.

00089 
00090     def setcookedpat(self, pat):
00091         if self.isre():
00092             pat = re.escape(pat)
00093         self.setpat(pat)

Here is the call graph for this function:

def idlelib.SearchEngine.SearchEngine.setpat (   self,
  pat 
)

Definition at line 30 of file SearchEngine.py.

00030 
00031     def setpat(self, pat):
00032         self.patvar.set(pat)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 23 of file SearchEngine.py.

Definition at line 19 of file SearchEngine.py.

Definition at line 17 of file SearchEngine.py.

Definition at line 18 of file SearchEngine.py.

Definition at line 14 of file SearchEngine.py.

Definition at line 20 of file SearchEngine.py.

Definition at line 21 of file SearchEngine.py.


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