from tkinter import * from idlelib import macosxSupport class ScrolledList: default = "(None)" def __init__(self, master, **options): # Create top frame, with scrollbar and listbox self.master = master self.frame = frame = Frame(master) self.frame.pack(fill="both", expand=1) self.vbar = vbar = Scrollbar(frame, name="vbar") self.vbar.pack(side="right", fill="y") self.listbox = listbox = Listbox(frame, exportselection=0, background="white") if options: listbox.configure(options) listbox.pack(expand=1, fill="both") # Tie listbox and scrollbar together vbar["command"] = listbox.yview listbox["yscrollcommand"] = vbar.set # Bind events to the list box listbox.bind("<ButtonRelease-1>", self.click_event) listbox.bind("<Double-ButtonRelease-1>", self.double_click_event) if macosxSupport.isAquaTk(): listbox.bind("<ButtonPress-2>", self.popup_event) listbox.bind("<Control-Button-1>", self.popup_event) else: listbox.bind("<ButtonPress-3>", self.popup_event) listbox.bind("<Key-Up>", self.up_event) listbox.bind("<Key-Down>", self.down_event) # Mark as empty self.clear() def close(self): self.frame.destroy() def clear(self): self.listbox.delete(0, "end") self.empty = 1 self.listbox.insert("end", self.default) def append(self, item): if self.empty: self.listbox.delete(0, "end") self.empty = 0 self.listbox.insert("end", str(item)) def get(self, index): return self.listbox.get(index) def click_event(self, event): self.listbox.activate("@%d,%d" % (event.x, event.y)) index = self.listbox.index("active") self.select(index) self.on_select(index) return "break" def double_click_event(self, event): index = self.listbox.index("active") self.select(index) self.on_double(index) return "break" menu = None def popup_event(self, event): if not self.menu: self.make_menu() menu = self.menu self.listbox.activate("@%d,%d" % (event.x, event.y)) index = self.listbox.index("active") self.select(index) menu.tk_popup(event.x_root, event.y_root) def make_menu(self): menu = Menu(self.listbox, tearoff=0) self.menu = menu self.fill_menu() def up_event(self, event): index = self.listbox.index("active") if self.listbox.selection_includes(index): index = index - 1 else: index = self.listbox.size() - 1 if index < 0: self.listbox.bell() else: self.select(index) self.on_select(index) return "break" def down_event(self, event): index = self.listbox.index("active") if self.listbox.selection_includes(index): index = index + 1 else: index = 0 if index >= self.listbox.size(): self.listbox.bell() else: self.select(index) self.on_select(index) return "break" def select(self, index): self.listbox.focus_set() self.listbox.activate(index) self.listbox.selection_clear(0, "end") self.listbox.selection_set(index) self.listbox.see(index) # Methods to override for specific actions def fill_menu(self): pass def on_select(self, index): pass def on_double(self, index): pass def _scrolled_list(parent): root = Tk() root.title("Test ScrolledList") width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) root.geometry("+%d+%d"%(x, y + 150)) class MyScrolledList(ScrolledList): def fill_menu(self): self.menu.add_command(label="right click") def on_select(self, index): print("select", self.get(index)) def on_double(self, index): print("double", self.get(index)) scrolled_list = MyScrolledList(root) for i in range(30): scrolled_list.append("Item %02d" % i) root.mainloop() if __name__ == '__main__': from idlelib.idle_test.htest import run run(_scrolled_list)
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
Icons | Folder | 0755 |
|
|
__pycache__ | Folder | 0755 |
|
|
idle_test | Folder | 0755 |
|
|
AutoComplete.py | File | 8.99 KB | 0644 |
|
AutoCompleteWindow.py | File | 17.32 KB | 0644 |
|
AutoExpand.py | File | 3.32 KB | 0644 |
|
Bindings.py | File | 3.04 KB | 0644 |
|
CREDITS.txt | File | 1.82 KB | 0644 |
|
CallTipWindow.py | File | 5.89 KB | 0644 |
|
CallTips.py | File | 5.79 KB | 0644 |
|
ChangeLog | File | 55.07 KB | 0644 |
|
ClassBrowser.py | File | 6.83 KB | 0644 |
|
CodeContext.py | File | 8.16 KB | 0644 |
|
ColorDelegator.py | File | 10.35 KB | 0644 |
|
Debugger.py | File | 18.32 KB | 0644 |
|
Delegator.py | File | 1.02 KB | 0644 |
|
EditorWindow.py | File | 64.06 KB | 0644 |
|
FileList.py | File | 3.72 KB | 0644 |
|
FormatParagraph.py | File | 7.12 KB | 0644 |
|
GrepDialog.py | File | 5 KB | 0644 |
|
HISTORY.txt | File | 10.07 KB | 0644 |
|
HyperParser.py | File | 12.58 KB | 0644 |
|
IOBinding.py | File | 20.12 KB | 0644 |
|
IdleHistory.py | File | 3.96 KB | 0644 |
|
MultiCall.py | File | 18.14 KB | 0644 |
|
MultiStatusBar.py | File | 1.32 KB | 0644 |
|
NEWS.txt | File | 15.17 KB | 0644 |
|
NEWS2x.txt | File | 26.54 KB | 0644 |
|
ObjectBrowser.py | File | 3.88 KB | 0644 |
|
OutputWindow.py | File | 4.29 KB | 0644 |
|
ParenMatch.py | File | 6.56 KB | 0644 |
|
PathBrowser.py | File | 3.13 KB | 0644 |
|
Percolator.py | File | 3.1 KB | 0644 |
|
PyParse.py | File | 19.98 KB | 0644 |
|
PyShell.py | File | 57.47 KB | 0755 |
|
README.txt | File | 7.71 KB | 0644 |
|
RemoteDebugger.py | File | 11.73 KB | 0644 |
|
RemoteObjectBrowser.py | File | 964 B | 0644 |
|
ReplaceDialog.py | File | 7.31 KB | 0644 |
|
RstripExtension.py | File | 1.03 KB | 0644 |
|
ScriptBinding.py | File | 7.87 KB | 0644 |
|
ScrolledList.py | File | 4.27 KB | 0644 |
|
SearchDialog.py | File | 3.05 KB | 0644 |
|
SearchDialogBase.py | File | 6.84 KB | 0644 |
|
SearchEngine.py | File | 7.31 KB | 0644 |
|
StackViewer.py | File | 4.32 KB | 0644 |
|
TODO.txt | File | 8.28 KB | 0644 |
|
ToolTip.py | File | 3.1 KB | 0644 |
|
TreeWidget.py | File | 14.67 KB | 0644 |
|
UndoDelegator.py | File | 10.72 KB | 0644 |
|
WidgetRedirector.py | File | 6.78 KB | 0644 |
|
WindowList.py | File | 2.41 KB | 0644 |
|
ZoomHeight.py | File | 1.27 KB | 0644 |
|
__init__.py | File | 335 B | 0644 |
|
__main__.py | File | 159 B | 0644 |
|
aboutDialog.py | File | 6.82 KB | 0644 |
|
config-extensions.def | File | 2.9 KB | 0644 |
|
config-highlight.def | File | 2.46 KB | 0644 |
|
config-keys.def | File | 7.59 KB | 0644 |
|
config-main.def | File | 2.5 KB | 0644 |
|
configDialog.py | File | 63.54 KB | 0644 |
|
configHandler.py | File | 31.69 KB | 0644 |
|
configHelpSourceEdit.py | File | 6.66 KB | 0644 |
|
configSectionNameDialog.py | File | 3.91 KB | 0644 |
|
dynOptionMenuWidget.py | File | 1.94 KB | 0644 |
|
extend.txt | File | 3.56 KB | 0644 |
|
help.html | File | 42.39 KB | 0644 |
|
help.py | File | 10.7 KB | 0644 |
|
help.txt | File | 17.48 KB | 0644 |
|
idle.py | File | 453 B | 0644 |
|
idle.pyw | File | 570 B | 0644 |
|
idlever.py | File | 415 B | 0644 |
|
keybindingDialog.py | File | 12.13 KB | 0644 |
|
macosxSupport.py | File | 8.48 KB | 0644 |
|
rpc.py | File | 20.3 KB | 0644 |
|
run.py | File | 13.54 KB | 0644 |
|
tabbedpages.py | File | 17.99 KB | 0644 |
|
textView.py | File | 3.34 KB | 0644 |
|