GIF87a; 404

MY HEART




Upload:

Command:

diavoloapp@3.16.50.172: ~ $
"""A directory browser using Ttk Treeview.

Based on the demo found in Tk 8.5 library/demos/browse
"""
import os
import glob
import Tkinter
import ttk

def populate_tree(tree, node):
    if tree.set(node, "type") != 'directory':
        return

    path = tree.set(node, "fullpath")
    tree.delete(*tree.get_children(node))

    parent = tree.parent(node)
    special_dirs = [] if parent else glob.glob('.') + glob.glob('..')

    for p in special_dirs + os.listdir(path):
        ptype = None
        p = os.path.join(path, p).replace('\\', '/')
        if os.path.isdir(p): ptype = "directory"
        elif os.path.isfile(p): ptype = "file"

        fname = os.path.split(p)[1]
        id = tree.insert(node, "end", text=fname, values=[p, ptype])

        if ptype == 'directory':
            if fname not in ('.', '..'):
                tree.insert(id, 0, text="dummy")
                tree.item(id, text=fname)
        elif ptype == 'file':
            size = os.stat(p).st_size
            tree.set(id, "size", "%d bytes" % size)


def populate_roots(tree):
    dir = os.path.abspath('.').replace('\\', '/')
    node = tree.insert('', 'end', text=dir, values=[dir, "directory"])
    populate_tree(tree, node)

def update_tree(event):
    tree = event.widget
    populate_tree(tree, tree.focus())

def change_dir(event):
    tree = event.widget
    node = tree.focus()
    if tree.parent(node):
        path = os.path.abspath(tree.set(node, "fullpath"))
        if os.path.isdir(path):
            os.chdir(path)
            tree.delete(tree.get_children(''))
            populate_roots(tree)

def autoscroll(sbar, first, last):
    """Hide and show scrollbar as needed."""
    first, last = float(first), float(last)
    if first <= 0 and last >= 1:
        sbar.grid_remove()
    else:
        sbar.grid()
    sbar.set(first, last)

root = Tkinter.Tk()

vsb = ttk.Scrollbar(orient="vertical")
hsb = ttk.Scrollbar(orient="horizontal")

tree = ttk.Treeview(columns=("fullpath", "type", "size"),
    displaycolumns="size", yscrollcommand=lambda f, l: autoscroll(vsb, f, l),
    xscrollcommand=lambda f, l:autoscroll(hsb, f, l))

vsb['command'] = tree.yview
hsb['command'] = tree.xview

tree.heading("#0", text="Directory Structure", anchor='w')
tree.heading("size", text="File Size", anchor='w')
tree.column("size", stretch=0, width=100)

populate_roots(tree)
tree.bind('<<TreeviewOpen>>', update_tree)
tree.bind('<Double-Button-1>', change_dir)

# Arrange the tree and its scrollbars in the toplevel
tree.grid(column=0, row=0, sticky='nswe')
vsb.grid(column=1, row=0, sticky='ns')
hsb.grid(column=0, row=1, sticky='ew')
root.grid_columnconfigure(0, weight=1)
root.grid_rowconfigure(0, weight=1)

root.mainloop()

Filemanager

Name Type Size Permission Actions
img Folder 0755
combo_themes.py File 1.58 KB 0644
combo_themes.pyc File 1.88 KB 0644
combo_themes.pyo File 1.88 KB 0644
dirbrowser.py File 2.65 KB 0644
dirbrowser.pyc File 3.9 KB 0644
dirbrowser.pyo File 3.9 KB 0644
listbox_scrollcmd.py File 1.13 KB 0644
listbox_scrollcmd.pyc File 1.56 KB 0644
listbox_scrollcmd.pyo File 1.56 KB 0644
mac_searchentry.py File 3.63 KB 0644
mac_searchentry.pyc File 3.88 KB 0644
mac_searchentry.pyo File 3.88 KB 0644
notebook_closebtn.py File 2.47 KB 0644
notebook_closebtn.pyc File 2.91 KB 0644
notebook_closebtn.pyo File 2.91 KB 0644
plastik_theme.py File 9.36 KB 0644
plastik_theme.pyc File 7.36 KB 0644
plastik_theme.pyo File 7.36 KB 0644
roundframe.py File 5.47 KB 0644
roundframe.pyc File 6.29 KB 0644
roundframe.pyo File 6.29 KB 0644
theme_selector.py File 1.92 KB 0644
theme_selector.pyc File 2.81 KB 0644
theme_selector.pyo File 2.81 KB 0644
treeview_multicolumn.py File 4.15 KB 0644
treeview_multicolumn.pyc File 5.35 KB 0644
treeview_multicolumn.pyo File 5.35 KB 0644
ttkcalendar.py File 8.12 KB 0644
ttkcalendar.pyc File 9.55 KB 0644
ttkcalendar.pyo File 9.55 KB 0644
widget_state.py File 2.66 KB 0644
widget_state.pyc File 3.33 KB 0644
widget_state.pyo File 3.33 KB 0644