Psyduck - 可達鴨 之 鴨力山大2


Server : LiteSpeed
System : Linux premium217.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User : alloknri ( 880)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /opt/alt/python35/lib64/python3.5/idlelib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/alt/python35/lib64/python3.5/idlelib/SearchDialogBase.py
'''Define SearchDialogBase used by Search, Replace, and Grep dialogs.'''

from tkinter import (Toplevel, Frame, Entry, Label, Button,
                     Checkbutton, Radiobutton)

class SearchDialogBase:
    '''Create most of a 3 or 4 row, 3 column search dialog.

    The left and wide middle column contain:
    1 or 2 labeled text entry lines (make_entry, create_entries);
    a row of standard Checkbuttons (make_frame, create_option_buttons),
    each of which corresponds to a search engine Variable;
    a row of dialog-specific Check/Radiobuttons (create_other_buttons).

    The narrow right column contains command buttons
    (make_button, create_command_buttons).
    These are bound to functions that execute the command.

    Except for command buttons, this base class is not limited to items
    common to all three subclasses.  Rather, it is the Find dialog minus
    the "Find Next" command, its execution function, and the
    default_command attribute needed in create_widgets. The other
    dialogs override attributes and methods, the latter to replace and
    add widgets.
    '''

    title = "Search Dialog"  # replace in subclasses
    icon = "Search"
    needwrapbutton = 1  # not in Find in Files

    def __init__(self, root, engine):
        '''Initialize root, engine, and top attributes.

        top (level widget): set in create_widgets() called from open().
        text (Text searched): set in open(), only used in subclasses().
        ent (ry): created in make_entry() called from create_entry().
        row (of grid): 0 in create_widgets(), +1 in make_entry/frame().
        default_command: set in subclasses, used in create_widgers().

        title (of dialog): class attribute, override in subclasses.
        icon (of dialog): ditto, use unclear if cannot minimize dialog.
        '''
        self.root = root
        self.engine = engine
        self.top = None

    def open(self, text, searchphrase=None):
        "Make dialog visible on top of others and ready to use."
        self.text = text
        if not self.top:
            self.create_widgets()
        else:
            self.top.deiconify()
            self.top.tkraise()
        if searchphrase:
            self.ent.delete(0,"end")
            self.ent.insert("end",searchphrase)
        self.ent.focus_set()
        self.ent.selection_range(0, "end")
        self.ent.icursor(0)
        self.top.grab_set()

    def close(self, event=None):
        "Put dialog away for later use."
        if self.top:
            self.top.grab_release()
            self.top.withdraw()

    def create_widgets(self):
        '''Create basic 3 row x 3 col search (find) dialog.

        Other dialogs override subsidiary create_x methods as needed.
        Replace and Find-in-Files add another entry row.
        '''
        top = Toplevel(self.root)
        top.bind("<Return>", self.default_command)
        top.bind("<Escape>", self.close)
        top.protocol("WM_DELETE_WINDOW", self.close)
        top.wm_title(self.title)
        top.wm_iconname(self.icon)
        self.top = top

        self.row = 0
        self.top.grid_columnconfigure(0, pad=2, weight=0)
        self.top.grid_columnconfigure(1, pad=2, minsize=100, weight=100)

        self.create_entries()  # row 0 (and maybe 1), cols 0, 1
        self.create_option_buttons()  # next row, cols 0, 1
        self.create_other_buttons()  # next row, cols 0, 1
        self.create_command_buttons()  # col 2, all rows

    def make_entry(self, label_text, var):
        '''Return (entry, label), .

        entry - gridded labeled Entry for text entry.
        label - Label widget, returned for testing.
        '''
        label = Label(self.top, text=label_text)
        label.grid(row=self.row, column=0, sticky="nw")
        entry = Entry(self.top, textvariable=var, exportselection=0)
        entry.grid(row=self.row, column=1, sticky="nwe")
        self.row = self.row + 1
        return entry, label

    def create_entries(self):
        "Create one or more entry lines with make_entry."
        self.ent = self.make_entry("Find:", self.engine.patvar)[0]

    def make_frame(self,labeltext=None):
        '''Return (frame, label).

        frame - gridded labeled Frame for option or other buttons.
        label - Label widget, returned for testing.
        '''
        if labeltext:
            label = Label(self.top, text=labeltext)
            label.grid(row=self.row, column=0, sticky="nw")
        else:
            label = ''
        frame = Frame(self.top)
        frame.grid(row=self.row, column=1, columnspan=1, sticky="nwe")
        self.row = self.row + 1
        return frame, label

    def create_option_buttons(self):
        '''Return (filled frame, options) for testing.

        Options is a list of SearchEngine booleanvar, label pairs.
        A gridded frame from make_frame is filled with a Checkbutton
        for each pair, bound to the var, with the corresponding label.
        '''
        frame = self.make_frame("Options")[0]
        engine = self.engine
        options = [(engine.revar, "Regular expression"),
                   (engine.casevar, "Match case"),
                   (engine.wordvar, "Whole word")]
        if self.needwrapbutton:
            options.append((engine.wrapvar, "Wrap around"))
        for var, label in options:
            btn = Checkbutton(frame, anchor="w", variable=var, text=label)
            btn.pack(side="left", fill="both")
            if var.get():
                btn.select()
        return frame, options

    def create_other_buttons(self):
        '''Return (frame, others) for testing.

        Others is a list of value, label pairs.
        A gridded frame from make_frame is filled with radio buttons.
        '''
        frame = self.make_frame("Direction")[0]
        var = self.engine.backvar
        others = [(1, 'Up'), (0, 'Down')]
        for val, label in others:
            btn = Radiobutton(frame, anchor="w",
                              variable=var, value=val, text=label)
            btn.pack(side="left", fill="both")
            if var.get() == val:
                btn.select()
        return frame, others

    def make_button(self, label, command, isdef=0):
        "Return command button gridded in command frame."
        b = Button(self.buttonframe,
                   text=label, command=command,
                   default=isdef and "active" or "normal")
        cols,rows=self.buttonframe.grid_size()
        b.grid(pady=1,row=rows,column=0,sticky="ew")
        self.buttonframe.grid(rowspan=rows+1)
        return b

    def create_command_buttons(self):
        "Place buttons in vertical command frame gridded on right."
        f = self.buttonframe = Frame(self.top)
        f.grid(row=0,column=2,padx=2,pady=2,ipadx=2,ipady=2)

        b = self.make_button("close", self.close)
        b.lower()

if __name__ == '__main__':
    import unittest
    unittest.main(
        'idlelib.idle_test.test_searchdialogbase', verbosity=2)
Name
Size
Permissions
Options
Icons
--
drwxr-xr-x
__pycache__
--
drwxr-xr-x
idle_test
--
drwxr-xr-x
AutoComplete.py
8.985 KB
-rw-r--r--
AutoCompleteWindow.py
17.323 KB
-rw-r--r--
AutoExpand.py
3.315 KB
-rw-r--r--
Bindings.py
3.038 KB
-rw-r--r--
CREDITS.txt
1.822 KB
-rw-r--r--
CallTipWindow.py
5.894 KB
-rw-r--r--
CallTips.py
5.793 KB
-rw-r--r--
ChangeLog
55.066 KB
-rw-r--r--
ClassBrowser.py
6.835 KB
-rw-r--r--
CodeContext.py
8.161 KB
-rw-r--r--
ColorDelegator.py
10.35 KB
-rw-r--r--
Debugger.py
18.318 KB
-rw-r--r--
Delegator.py
1.019 KB
-rw-r--r--
EditorWindow.py
64.058 KB
-rw-r--r--
FileList.py
3.724 KB
-rw-r--r--
FormatParagraph.py
7.116 KB
-rw-r--r--
GrepDialog.py
5.004 KB
-rw-r--r--
HISTORY.txt
10.07 KB
-rw-r--r--
HyperParser.py
12.575 KB
-rw-r--r--
IOBinding.py
20.116 KB
-rw-r--r--
IdleHistory.py
3.957 KB
-rw-r--r--
MultiCall.py
18.136 KB
-rw-r--r--
MultiStatusBar.py
1.316 KB
-rw-r--r--
NEWS.txt
15.172 KB
-rw-r--r--
NEWS2x.txt
26.535 KB
-rw-r--r--
ObjectBrowser.py
3.882 KB
-rw-r--r--
OutputWindow.py
4.291 KB
-rw-r--r--
ParenMatch.py
6.557 KB
-rw-r--r--
PathBrowser.py
3.132 KB
-rw-r--r--
Percolator.py
3.104 KB
-rw-r--r--
PyParse.py
19.981 KB
-rw-r--r--
PyShell.py
57.467 KB
-rwxr-xr-x
README.txt
7.706 KB
-rw-r--r--
RemoteDebugger.py
11.726 KB
-rw-r--r--
RemoteObjectBrowser.py
0.941 KB
-rw-r--r--
ReplaceDialog.py
7.306 KB
-rw-r--r--
RstripExtension.py
1.025 KB
-rw-r--r--
ScriptBinding.py
7.872 KB
-rw-r--r--
ScrolledList.py
4.272 KB
-rw-r--r--
SearchDialog.py
3.054 KB
-rw-r--r--
SearchDialogBase.py
6.845 KB
-rw-r--r--
SearchEngine.py
7.31 KB
-rw-r--r--
StackViewer.py
4.322 KB
-rw-r--r--
TODO.txt
8.279 KB
-rw-r--r--
ToolTip.py
3.099 KB
-rw-r--r--
TreeWidget.py
14.672 KB
-rw-r--r--
UndoDelegator.py
10.723 KB
-rw-r--r--
WidgetRedirector.py
6.776 KB
-rw-r--r--
WindowList.py
2.414 KB
-rw-r--r--
ZoomHeight.py
1.27 KB
-rw-r--r--
__init__.py
0.327 KB
-rw-r--r--
__main__.py
0.155 KB
-rw-r--r--
aboutDialog.py
6.823 KB
-rw-r--r--
config-extensions.def
2.896 KB
-rw-r--r--
config-highlight.def
2.456 KB
-rw-r--r--
config-keys.def
7.595 KB
-rw-r--r--
config-main.def
2.503 KB
-rw-r--r--
configDialog.py
63.536 KB
-rw-r--r--
configHandler.py
31.69 KB
-rw-r--r--
configHelpSourceEdit.py
6.657 KB
-rw-r--r--
configSectionNameDialog.py
3.913 KB
-rw-r--r--
dynOptionMenuWidget.py
1.943 KB
-rw-r--r--
extend.txt
3.557 KB
-rw-r--r--
help.html
42.394 KB
-rw-r--r--
help.py
10.695 KB
-rw-r--r--
help.txt
17.48 KB
-rw-r--r--
idle.py
0.442 KB
-rw-r--r--
idle.pyw
0.557 KB
-rw-r--r--
idlever.py
0.405 KB
-rw-r--r--
keybindingDialog.py
12.125 KB
-rw-r--r--
macosxSupport.py
8.48 KB
-rw-r--r--
rpc.py
20.297 KB
-rw-r--r--
run.py
13.544 KB
-rw-r--r--
tabbedpages.py
17.986 KB
-rw-r--r--
textView.py
3.339 KB
-rw-r--r--