Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: SearchDialogBase.py
'''Define SearchDialogBase used by Search, Replace, and Grep dialogs.'''
[0] Fix | Delete
[1] Fix | Delete
from Tkinter import (Toplevel, Frame, Entry, Label, Button,
[2] Fix | Delete
Checkbutton, Radiobutton)
[3] Fix | Delete
[4] Fix | Delete
class SearchDialogBase:
[5] Fix | Delete
'''Create most of a 3 or 4 row, 3 column search dialog.
[6] Fix | Delete
[7] Fix | Delete
The left and wide middle column contain:
[8] Fix | Delete
1 or 2 labeled text entry lines (make_entry, create_entries);
[9] Fix | Delete
a row of standard Checkbuttons (make_frame, create_option_buttons),
[10] Fix | Delete
each of which corresponds to a search engine Variable;
[11] Fix | Delete
a row of dialog-specific Check/Radiobuttons (create_other_buttons).
[12] Fix | Delete
[13] Fix | Delete
The narrow right column contains command buttons
[14] Fix | Delete
(make_button, create_command_buttons).
[15] Fix | Delete
These are bound to functions that execute the command.
[16] Fix | Delete
[17] Fix | Delete
Except for command buttons, this base class is not limited to items
[18] Fix | Delete
common to all three subclasses. Rather, it is the Find dialog minus
[19] Fix | Delete
the "Find Next" command, its execution function, and the
[20] Fix | Delete
default_command attribute needed in create_widgets. The other
[21] Fix | Delete
dialogs override attributes and methods, the latter to replace and
[22] Fix | Delete
add widgets.
[23] Fix | Delete
'''
[24] Fix | Delete
[25] Fix | Delete
title = "Search Dialog" # replace in subclasses
[26] Fix | Delete
icon = "Search"
[27] Fix | Delete
needwrapbutton = 1 # not in Find in Files
[28] Fix | Delete
[29] Fix | Delete
def __init__(self, root, engine):
[30] Fix | Delete
'''Initialize root, engine, and top attributes.
[31] Fix | Delete
[32] Fix | Delete
top (level widget): set in create_widgets() called from open().
[33] Fix | Delete
text (Text searched): set in open(), only used in subclasses().
[34] Fix | Delete
ent (ry): created in make_entry() called from create_entry().
[35] Fix | Delete
row (of grid): 0 in create_widgets(), +1 in make_entry/frame().
[36] Fix | Delete
default_command: set in subclasses, used in create_widgers().
[37] Fix | Delete
[38] Fix | Delete
title (of dialog): class attribute, override in subclasses.
[39] Fix | Delete
icon (of dialog): ditto, use unclear if cannot minimize dialog.
[40] Fix | Delete
'''
[41] Fix | Delete
self.root = root
[42] Fix | Delete
self.engine = engine
[43] Fix | Delete
self.top = None
[44] Fix | Delete
[45] Fix | Delete
def open(self, text, searchphrase=None):
[46] Fix | Delete
"Make dialog visible on top of others and ready to use."
[47] Fix | Delete
self.text = text
[48] Fix | Delete
if not self.top:
[49] Fix | Delete
self.create_widgets()
[50] Fix | Delete
else:
[51] Fix | Delete
self.top.deiconify()
[52] Fix | Delete
self.top.tkraise()
[53] Fix | Delete
self.top.transient(text.winfo_toplevel())
[54] Fix | Delete
if searchphrase:
[55] Fix | Delete
self.ent.delete(0,"end")
[56] Fix | Delete
self.ent.insert("end",searchphrase)
[57] Fix | Delete
self.ent.focus_set()
[58] Fix | Delete
self.ent.selection_range(0, "end")
[59] Fix | Delete
self.ent.icursor(0)
[60] Fix | Delete
self.top.grab_set()
[61] Fix | Delete
[62] Fix | Delete
def close(self, event=None):
[63] Fix | Delete
"Put dialog away for later use."
[64] Fix | Delete
if self.top:
[65] Fix | Delete
self.top.grab_release()
[66] Fix | Delete
self.top.transient('')
[67] Fix | Delete
self.top.withdraw()
[68] Fix | Delete
[69] Fix | Delete
def create_widgets(self):
[70] Fix | Delete
'''Create basic 3 row x 3 col search (find) dialog.
[71] Fix | Delete
[72] Fix | Delete
Other dialogs override subsidiary create_x methods as needed.
[73] Fix | Delete
Replace and Find-in-Files add another entry row.
[74] Fix | Delete
'''
[75] Fix | Delete
top = Toplevel(self.root)
[76] Fix | Delete
top.bind("<Return>", self.default_command)
[77] Fix | Delete
top.bind("<Escape>", self.close)
[78] Fix | Delete
top.protocol("WM_DELETE_WINDOW", self.close)
[79] Fix | Delete
top.wm_title(self.title)
[80] Fix | Delete
top.wm_iconname(self.icon)
[81] Fix | Delete
self.top = top
[82] Fix | Delete
[83] Fix | Delete
self.row = 0
[84] Fix | Delete
self.top.grid_columnconfigure(0, pad=2, weight=0)
[85] Fix | Delete
self.top.grid_columnconfigure(1, pad=2, minsize=100, weight=100)
[86] Fix | Delete
[87] Fix | Delete
self.create_entries() # row 0 (and maybe 1), cols 0, 1
[88] Fix | Delete
self.create_option_buttons() # next row, cols 0, 1
[89] Fix | Delete
self.create_other_buttons() # next row, cols 0, 1
[90] Fix | Delete
self.create_command_buttons() # col 2, all rows
[91] Fix | Delete
[92] Fix | Delete
def make_entry(self, label_text, var):
[93] Fix | Delete
'''Return (entry, label), .
[94] Fix | Delete
[95] Fix | Delete
entry - gridded labeled Entry for text entry.
[96] Fix | Delete
label - Label widget, returned for testing.
[97] Fix | Delete
'''
[98] Fix | Delete
label = Label(self.top, text=label_text)
[99] Fix | Delete
label.grid(row=self.row, column=0, sticky="nw")
[100] Fix | Delete
entry = Entry(self.top, textvariable=var, exportselection=0)
[101] Fix | Delete
entry.grid(row=self.row, column=1, sticky="nwe")
[102] Fix | Delete
self.row = self.row + 1
[103] Fix | Delete
return entry, label
[104] Fix | Delete
[105] Fix | Delete
def create_entries(self):
[106] Fix | Delete
"Create one or more entry lines with make_entry."
[107] Fix | Delete
self.ent = self.make_entry("Find:", self.engine.patvar)[0]
[108] Fix | Delete
[109] Fix | Delete
def make_frame(self,labeltext=None):
[110] Fix | Delete
'''Return (frame, label).
[111] Fix | Delete
[112] Fix | Delete
frame - gridded labeled Frame for option or other buttons.
[113] Fix | Delete
label - Label widget, returned for testing.
[114] Fix | Delete
'''
[115] Fix | Delete
if labeltext:
[116] Fix | Delete
label = Label(self.top, text=labeltext)
[117] Fix | Delete
label.grid(row=self.row, column=0, sticky="nw")
[118] Fix | Delete
else:
[119] Fix | Delete
label = ''
[120] Fix | Delete
frame = Frame(self.top)
[121] Fix | Delete
frame.grid(row=self.row, column=1, columnspan=1, sticky="nwe")
[122] Fix | Delete
self.row = self.row + 1
[123] Fix | Delete
return frame, label
[124] Fix | Delete
[125] Fix | Delete
def create_option_buttons(self):
[126] Fix | Delete
'''Return (filled frame, options) for testing.
[127] Fix | Delete
[128] Fix | Delete
Options is a list of SearchEngine booleanvar, label pairs.
[129] Fix | Delete
A gridded frame from make_frame is filled with a Checkbutton
[130] Fix | Delete
for each pair, bound to the var, with the corresponding label.
[131] Fix | Delete
'''
[132] Fix | Delete
frame = self.make_frame("Options")[0]
[133] Fix | Delete
engine = self.engine
[134] Fix | Delete
options = [(engine.revar, "Regular expression"),
[135] Fix | Delete
(engine.casevar, "Match case"),
[136] Fix | Delete
(engine.wordvar, "Whole word")]
[137] Fix | Delete
if self.needwrapbutton:
[138] Fix | Delete
options.append((engine.wrapvar, "Wrap around"))
[139] Fix | Delete
for var, label in options:
[140] Fix | Delete
btn = Checkbutton(frame, anchor="w", variable=var, text=label)
[141] Fix | Delete
btn.pack(side="left", fill="both")
[142] Fix | Delete
if var.get():
[143] Fix | Delete
btn.select()
[144] Fix | Delete
return frame, options
[145] Fix | Delete
[146] Fix | Delete
def create_other_buttons(self):
[147] Fix | Delete
'''Return (frame, others) for testing.
[148] Fix | Delete
[149] Fix | Delete
Others is a list of value, label pairs.
[150] Fix | Delete
A gridded frame from make_frame is filled with radio buttons.
[151] Fix | Delete
'''
[152] Fix | Delete
frame = self.make_frame("Direction")[0]
[153] Fix | Delete
var = self.engine.backvar
[154] Fix | Delete
others = [(1, 'Up'), (0, 'Down')]
[155] Fix | Delete
for val, label in others:
[156] Fix | Delete
btn = Radiobutton(frame, anchor="w",
[157] Fix | Delete
variable=var, value=val, text=label)
[158] Fix | Delete
btn.pack(side="left", fill="both")
[159] Fix | Delete
if var.get() == val:
[160] Fix | Delete
btn.select()
[161] Fix | Delete
return frame, others
[162] Fix | Delete
[163] Fix | Delete
def make_button(self, label, command, isdef=0):
[164] Fix | Delete
"Return command button gridded in command frame."
[165] Fix | Delete
b = Button(self.buttonframe,
[166] Fix | Delete
text=label, command=command,
[167] Fix | Delete
default=isdef and "active" or "normal")
[168] Fix | Delete
cols,rows=self.buttonframe.grid_size()
[169] Fix | Delete
b.grid(pady=1,row=rows,column=0,sticky="ew")
[170] Fix | Delete
self.buttonframe.grid(rowspan=rows+1)
[171] Fix | Delete
return b
[172] Fix | Delete
[173] Fix | Delete
def create_command_buttons(self):
[174] Fix | Delete
"Place buttons in vertical command frame gridded on right."
[175] Fix | Delete
f = self.buttonframe = Frame(self.top)
[176] Fix | Delete
f.grid(row=0,column=2,padx=2,pady=2,ipadx=2,ipady=2)
[177] Fix | Delete
[178] Fix | Delete
b = self.make_button("close", self.close)
[179] Fix | Delete
b.lower()
[180] Fix | Delete
[181] Fix | Delete
if __name__ == '__main__':
[182] Fix | Delete
import unittest
[183] Fix | Delete
unittest.main(
[184] Fix | Delete
'idlelib.idle_test.test_searchdialogbase', verbosity=2)
[185] Fix | Delete
[186] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function