diff options
| author | jwansek <eddie.atten.ea29@gmail.com> | 2025-12-21 18:07:14 +0000 |
|---|---|---|
| committer | jwansek <eddie.atten.ea29@gmail.com> | 2025-12-21 18:07:14 +0000 |
| commit | 267fc9cb3519d3ad8f66d04a99a57e30a886252a (patch) | |
| tree | e3575086f0be15bd6b54cfc8a2aa167b7c7e1765 /fileTreeBrowser.py | |
| parent | b0c0f5fd0e543f775f1da9509f4ced7a35c7ccfa (diff) | |
| download | tkFileBrowser-267fc9cb3519d3ad8f66d04a99a57e30a886252a.tar.gz tkFileBrowser-267fc9cb3519d3ad8f66d04a99a57e30a886252a.zip | |
Switched to using matplotlib to render the file sizes, displayed files and directories sorted
Diffstat (limited to 'fileTreeBrowser.py')
| -rw-r--r-- | fileTreeBrowser.py | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/fileTreeBrowser.py b/fileTreeBrowser.py index 240a038..f2c3715 100644 --- a/fileTreeBrowser.py +++ b/fileTreeBrowser.py @@ -4,6 +4,7 @@ import tkinter as tk from tkinter import ttk from tkinter import messagebox from PIL import Image, ImageTk +import matplotlib import win32api import os @@ -388,28 +389,34 @@ class FileTree(tk.Frame): recurse(id) def _get_size(self, path): - """Returns the size of a file. From: - https://pyinmyeye.blogspot.co.uk/2012/07/tkinter-multi-column-list-demo.html - - Arguments: - path {str} -- Path to file - - Returns: - str -- file size in bytes/KB/MB/GB - """ - size = os.path.getsize(path) - KB = 1024.0 - MB = KB * KB - GB = MB * KB - if size >= GB: - return ('{:,.1f} GB').format(size / GB) - elif size >= MB: - return ('{:,.1f} MB').format(size / MB) - elif size >= KB: - return ('{:,.1f} KB').format(size / KB) + if size <= 1024: + return "%i bytes" % size else: - return ('{} bytes').format(size) + fmt = matplotlib.ticker.EngFormatter("B", places = 1) + return fmt(os.path.getsize(path)) + # """Returns the size of a file. From: + # https://pyinmyeye.blogspot.co.uk/2012/07/tkinter-multi-column-list-demo.html + + # Arguments: + # path {str} -- Path to file + + # Returns: + # str -- file size in bytes/KB/MB/GB + # """ + + # size = os.path.getsize(path) + # KB = 1024.0 + # MB = KB * KB + # GB = MB * KB + # if size >= GB: + # return ('{:,.1f} GB').format(size / GB) + # elif size >= MB: + # return ('{:,.1f} MB').format(size / MB) + # elif size >= KB: + # return ('{:,.1f} KB').format(size / KB) + # else: + # return ('{} bytes').format(size) def _populate_path(self, path): #if the tree is blank, write to the root @@ -515,7 +522,7 @@ class FileTree(tk.Frame): #print("\n\nfolders: ", folders, "\nfiles: ", files) - return folders, files + return sorted(folders), sorted(files) #for efficiency, it would be better to instatiate this only once, since now it's instatiated #every time the user right clicks |
