From 6625a4d6c1c53df0518abd89cb319aff0a0f22c8 Mon Sep 17 00:00:00 2001 From: cheezedoodle2 Date: Wed, 19 Apr 2023 02:12:26 -0700 Subject: [PATCH] Working version of module inspector. --- module-inspector/module-inspector.py | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 module-inspector/module-inspector.py diff --git a/module-inspector/module-inspector.py b/module-inspector/module-inspector.py new file mode 100644 index 0000000..9438469 --- /dev/null +++ b/module-inspector/module-inspector.py @@ -0,0 +1,39 @@ +import sys +import tkinter as tk +from tkinter import ttk + +def on_treeview_heading_click(column, tree): + data = [(tree.set(child, column), child) for child in tree.get_children("")] + reverse = (column == tree.heading(column)["text"]) and not column.startswith("_") + data.sort(reverse=reverse, key=lambda t: t[0].lower()) + + for index, (val, child_id) in enumerate(data): + tree.move(child_id, "", index) + + tree.heading(column, text=("_" if not tree.heading(column, option="text").startswith("_") else "") + column) + +root = tk.Tk() +root.title('Module explorer') +root.geometry('640x480') +tree = ttk.Treeview(root, columns=('module', 'path')) +tree.heading('module', text='Module Name', anchor=tk.W) +tree.heading('path', text='Path', anchor=tk.W) +for module in sys.modules: + if hasattr(sys.modules[module], '__spec__') and hasattr(sys.modules[module].__spec__, 'origin'): + origin = sys.modules[module].__spec__.origin + else: + origin = "None" + iid = tree.insert('', tk.END, values=(module, origin)) + +tree.grid(row=0, column=0, sticky='nsew') + +root.grid_rowconfigure(0, weight=1) +root.grid_columnconfigure(0, weight=1) +tree.column('#0', width=20, stretch=False) + +tree.tag_configure("selected", background="#ccc") + +# Call the on_treeview_heading_click function when a column heading is clicked +for col in tree["columns"]: + tree.heading(col, text=col, anchor=tk.W, command=lambda col=col: on_treeview_heading_click(col, tree)) +root.mainloop() \ No newline at end of file