Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
redemo.ReDemo Class Reference

List of all members.

Public Member Functions

def __init__
def addoptions
def getflags
def recompile
def reevaluate

Public Attributes

 master
 promptdisplay
 regexdisplay
 statusdisplay
 labeldisplay
 showframe
 showvar
 showfirstradio
 showallradio
 stringdisplay
 grouplabel
 grouplist
 compiled
 frames
 boxes
 vars

Detailed Description

Definition at line 6 of file redemo.py.


Constructor & Destructor Documentation

def redemo.ReDemo.__init__ (   self,
  master 
)

Definition at line 8 of file redemo.py.

00008 
00009     def __init__(self, master):
00010         self.master = master
00011 
00012         self.promptdisplay = Label(self.master, anchor=W,
00013                 text="Enter a Perl-style regular expression:")
00014         self.promptdisplay.pack(side=TOP, fill=X)
00015 
00016         self.regexdisplay = Entry(self.master)
00017         self.regexdisplay.pack(fill=X)
00018         self.regexdisplay.focus_set()
00019 
00020         self.addoptions()
00021 
00022         self.statusdisplay = Label(self.master, text="", anchor=W)
00023         self.statusdisplay.pack(side=TOP, fill=X)
00024 
00025         self.labeldisplay = Label(self.master, anchor=W,
00026                 text="Enter a string to search:")
00027         self.labeldisplay.pack(fill=X)
00028         self.labeldisplay.pack(fill=X)
00029 
00030         self.showframe = Frame(master)
00031         self.showframe.pack(fill=X, anchor=W)
00032 
00033         self.showvar = StringVar(master)
00034         self.showvar.set("first")
00035 
00036         self.showfirstradio = Radiobutton(self.showframe,
00037                                          text="Highlight first match",
00038                                           variable=self.showvar,
00039                                           value="first",
00040                                           command=self.recompile)
00041         self.showfirstradio.pack(side=LEFT)
00042 
00043         self.showallradio = Radiobutton(self.showframe,
00044                                         text="Highlight all matches",
00045                                         variable=self.showvar,
00046                                         value="all",
00047                                         command=self.recompile)
00048         self.showallradio.pack(side=LEFT)
00049 
00050         self.stringdisplay = Text(self.master, width=60, height=4)
00051         self.stringdisplay.pack(fill=BOTH, expand=1)
00052         self.stringdisplay.tag_configure("hit", background="yellow")
00053 
00054         self.grouplabel = Label(self.master, text="Groups:", anchor=W)
00055         self.grouplabel.pack(fill=X)
00056 
00057         self.grouplist = Listbox(self.master)
00058         self.grouplist.pack(expand=1, fill=BOTH)
00059 
00060         self.regexdisplay.bind('<Key>', self.recompile)
00061         self.stringdisplay.bind('<Key>', self.reevaluate)
00062 
00063         self.compiled = None
00064         self.recompile()
00065 
00066         btags = self.regexdisplay.bindtags()
00067         self.regexdisplay.bindtags(btags[1:] + btags[:1])
00068 
00069         btags = self.stringdisplay.bindtags()
00070         self.stringdisplay.bindtags(btags[1:] + btags[:1])

Here is the caller graph for this function:


Member Function Documentation

def redemo.ReDemo.addoptions (   self)

Definition at line 71 of file redemo.py.

00071 
00072     def addoptions(self):
00073         self.frames = []
00074         self.boxes = []
00075         self.vars = []
00076         for name in ('IGNORECASE',
00077                      'LOCALE',
00078                      'MULTILINE',
00079                      'DOTALL',
00080                      'VERBOSE'):
00081             if len(self.boxes) % 3 == 0:
00082                 frame = Frame(self.master)
00083                 frame.pack(fill=X)
00084                 self.frames.append(frame)
00085             val = getattr(re, name)
00086             var = IntVar()
00087             box = Checkbutton(frame,
00088                     variable=var, text=name,
00089                     offvalue=0, onvalue=val,
00090                     command=self.recompile)
00091             box.pack(side=LEFT)
00092             self.boxes.append(box)
00093             self.vars.append(var)

def redemo.ReDemo.getflags (   self)

Definition at line 94 of file redemo.py.

00094 
00095     def getflags(self):
00096         flags = 0
00097         for var in self.vars:
00098             flags = flags | var.get()
00099         flags = flags
00100         return flags

Here is the caller graph for this function:

def redemo.ReDemo.recompile (   self,
  event = None 
)

Definition at line 101 of file redemo.py.

00101 
00102     def recompile(self, event=None):
00103         try:
00104             self.compiled = re.compile(self.regexdisplay.get(),
00105                                        self.getflags())
00106             bg = self.promptdisplay['background']
00107             self.statusdisplay.config(text="", background=bg)
00108         except re.error as msg:
00109             self.compiled = None
00110             self.statusdisplay.config(
00111                     text="re.error: %s" % str(msg),
00112                     background="red")
00113         self.reevaluate()

Here is the call graph for this function:

def redemo.ReDemo.reevaluate (   self,
  event = None 
)

Definition at line 114 of file redemo.py.

00114 
00115     def reevaluate(self, event=None):
00116         try:
00117             self.stringdisplay.tag_remove("hit", "1.0", END)
00118         except TclError:
00119             pass
00120         try:
00121             self.stringdisplay.tag_remove("hit0", "1.0", END)
00122         except TclError:
00123             pass
00124         self.grouplist.delete(0, END)
00125         if not self.compiled:
00126             return
00127         self.stringdisplay.tag_configure("hit", background="yellow")
00128         self.stringdisplay.tag_configure("hit0", background="orange")
00129         text = self.stringdisplay.get("1.0", END)
00130         last = 0
00131         nmatches = 0
00132         while last <= len(text):
00133             m = self.compiled.search(text, last)
00134             if m is None:
00135                 break
00136             first, last = m.span()
00137             if last == first:
00138                 last = first+1
00139                 tag = "hit0"
00140             else:
00141                 tag = "hit"
00142             pfirst = "1.0 + %d chars" % first
00143             plast = "1.0 + %d chars" % last
00144             self.stringdisplay.tag_add(tag, pfirst, plast)
00145             if nmatches == 0:
00146                 self.stringdisplay.yview_pickplace(pfirst)
00147                 groups = list(m.groups())
00148                 groups.insert(0, m.group())
00149                 for i in range(len(groups)):
00150                     g = "%2d: %r" % (i, groups[i])
00151                     self.grouplist.insert(END, g)
00152             nmatches = nmatches + 1
00153             if self.showvar.get() == "first":
00154                 break
00155 
00156         if nmatches == 0:
00157             self.statusdisplay.config(text="(no match)",
00158                                       background="yellow")
00159         else:
00160             self.statusdisplay.config(text="")
00161 
00162 
00163 # Main function, run when invoked as a stand-alone Python program.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 73 of file redemo.py.

Definition at line 62 of file redemo.py.

Definition at line 72 of file redemo.py.

Definition at line 53 of file redemo.py.

Definition at line 56 of file redemo.py.

Definition at line 24 of file redemo.py.

Definition at line 9 of file redemo.py.

Definition at line 11 of file redemo.py.

Definition at line 15 of file redemo.py.

Definition at line 42 of file redemo.py.

Definition at line 35 of file redemo.py.

Definition at line 29 of file redemo.py.

Definition at line 32 of file redemo.py.

Definition at line 21 of file redemo.py.

Definition at line 49 of file redemo.py.

Definition at line 74 of file redemo.py.


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