Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import simpledialog as spd
- from tkinter import messagebox as mb
- import os
- from threading import Thread
- import time
- try:
- import shutil
- except ModuleNotFoundError:
- os.system('pip install shutil')
- import shutil
- _root = frame1
- topbar = tk.Frame(_root, bd=1, relief='solid', bg='white', height=30)
- content = tk.Frame(_root, bg='white', bd=0)
- content.pack_propagate(0)
- canvas = tk.Canvas(content, bg='white', bd=0, highlightthickness=0)
- scrollbar = tk.Scrollbar(_root, orient="vertical", command=canvas.yview, troughcolor='white', width=12, bd=0)
- dfcontainer = tk.Frame(canvas, bd=0, bg='white')
- dirframe = tk.Frame(dfcontainer, bd=0, bg='white')
- dcwindow = None
- def updatecanvas(e):
- global canvas, scrollbar, content, dirframe, dcwindow
- try:
- canvas.itemconfigure(dcwindow, width=canvas.winfo_width())
- ncheight = dirframe.winfo_children()[0].winfo_height() * len(dirframe.winfo_children())
- if ncheight < canvas.winfo_height():
- canvas.itemconfigure(dcwindow, height=canvas.winfo_height())
- else:
- canvas.itemconfigure(dcwindow, height=ncheight)
- canvas.configure(scrollregion=canvas.bbox("all"))
- canvas.update()
- scrollbar.update()
- except IndexError:
- pass
- canvas.configure(yscrollcommand=scrollbar.set)
- def _on_mousewheel(event):
- global time
- ysi = 1
- for i in range(3):
- canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
- ysi += 1
- canvas.config(yscrollincrement=ysi)
- root.update()
- time.sleep(0.01)
- for i in range(4):
- canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
- root.update()
- time.sleep(0.01)
- for i in range(3):
- canvas.yview_scroll(int(-1 * (event.delta / 120)), "units")
- ysi -= 1
- canvas.config(yscrollincrement=ysi)
- root.update()
- time.sleep(0.01)
- canvas.config(yscrollincrement=1)
- def mswthread(e):
- global Thread, _on_mousewheel
- Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start()
- canvas.bind("<MouseWheel>", mswthread)
- topbar.pack(side='top', fill='x')
- content.pack(side='left', expand=True, fill='both')
- canvas.pack(side='left', expand=True, fill='both')
- _root.update_idletasks()
- dcwindow = canvas.create_window((0, 0), window=dfcontainer, anchor="nw", width=canvas.winfo_width())
- dirframe.pack(fill='x')
- scrollbar.pack(side="left", fill="y", anchor='e')
- scrollbar.update()
- for child in canvas.winfo_children():
- child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
- dirframe.bind("<Configure>", updatecanvas)
- canvas.bind("<Configure>", updatecanvas)
- global CURRENT_PATH
- CURRENT_PATH = 'T:\\Storage'
- SYSTEM_DIRECTORIES = [
- r"T:\BIOS Programs",
- r"T:\TechOS",
- r"T:\ProgramData",
- r"T:\ProgramData\Info",
- r"T:\TechOS\Virtual",
- r"T:\TechOS\Virtual\Images",
- r"T:\TechOS\Virtual\Images\Wallpapers",
- r"T:\TechOS\Virtual\Info",
- r"T:\TechOS\Virtual\Settings",
- r"T:\TechOS\Virtual\Cursors"
- ]
- def goback():
- prvpath = os.path.dirname(CURRENT_PATH)
- global directory
- directory(prvpath)
- back = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', font='TkDefaultFont 20', width=30, height=30, command=goback)
- back.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/Back.png')
- back.config(image=back.image)
- back.pack(side='left', anchor='w', fill='y')
- dirlabel = tk.Label(topbar, bg='white', text=CURRENT_PATH)
- dirlabel.pack(side='left', anchor='w', fill='y')
- def rename(path):
- global SYSTEM_DIRECTORIES
- global os
- global mb
- global spd
- global CURRENT_PATH
- if any(i in path for i in SYSTEM_DIRECTORIES):
- mb.showinfo("Permission Denied", "You do not have permission to rename this file.")
- else:
- newfilename = spd.askstring("Rename file", "Rename \"" + os.path.basename(path) + "\":")
- if newfilename == None:
- pass
- else:
- path0 = os.path.dirname(path)
- try:
- os.rename(path, os.path.join(path0, newfilename))
- except:
- mb.showinfo("Error", "Could not rename file")
- directory(CURRENT_PATH)
- def delete(path):
- global SYSTEM_DIRECTORIES
- global os
- global mb
- global CURRENT_PATH
- global directory
- global shutil
- if any(i in path for i in SYSTEM_DIRECTORIES):
- mb.showinfo("Permission Denied", "You do not have permission to delete this file.")
- else:
- if os.path.isfile(path):
- try:
- os.remove(path)
- except:
- mb.showinfo("Error", "Could not delete file")
- elif os.path.isdir(path):
- continuedelete = mb.askyesno("Delete Folder", "Are you sure you want to delete this folder and all its files?")
- if continuedelete == True:
- try:
- shutil.rmtree(path)
- except:
- mb.showinfo("Error", "Could not delete folder")
- else:
- pass
- directory(CURRENT_PATH)
- def newfile():
- global CURRENT_PATH
- global directory
- filepath1 = os.path.join(CURRENT_PATH, 'Untitled')
- rep = 0
- while True:
- if os.path.exists(filepath1 + str(rep) + '.txt'):
- rep += 1
- else:
- filepath0 = filepath1 + str(rep) + '.txt'
- break
- NEW_FILE = open(filepath0, 'x')
- NEW_FILE.close()
- directory(CURRENT_PATH)
- def newfolder():
- global CURRENT_PATH
- global directory
- folderpath1 = os.path.join(CURRENT_PATH, 'New Folder')
- if os.path.exists(folderpath1):
- rep = 1
- while True:
- if os.path.exists(folderpath1 + ' (' + str(rep) + ')'):
- rep += 1
- else:
- folderpath0 = folderpath1 + ' (' + str(rep) + ')'
- break
- os.mkdir(folderpath0)
- else:
- os.mkdir(folderpath1)
- directory(CURRENT_PATH)
- newfilebutton = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', text='+ File ', command=newfile)
- newfilebutton.pack(side='right', anchor='e', fill='y')
- newfolderbutton = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', text='+ Folder', command=newfolder)
- newfolderbutton.pack(side='right', anchor='e', fill='y')
- def directory(path):
- global spd
- global mb
- global dirframe
- global dirlabel
- global CURRENT_PATH
- global _root
- global SYSTEM_DIRECTORIES
- global rename
- global delete
- global tk
- global updatecanvas
- global goback
- if any(path == i for i in SYSTEM_DIRECTORIES):
- mb.showinfo("Careful!", "The directory you are about to enter contains system files. Modifying these files might cause irreparable damage to your system.")
- CURRENT_PATH = path
- dirlabel.config(text=path)
- for child in dirframe.winfo_children():
- child.destroy()
- try:
- fullcontents = os.listdir(path)
- contents = [file for file in fullcontents if not file == 'desktop.ini' and not file == 'System Volume Information' and not file == '$RECYCLE.BIN' and not file.endswith('.{SYSTEM}')]
- for element in contents:
- fullpath = os.path.join(path, element)
- if os.path.isdir(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: directory(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/Folder.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, fullpath=fullpath: rename(fullpath))
- tempbutton.bind("<Button-2>", lambda event, fullpath=fullpath: delete(fullpath))
- elif os.path.isfile(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: openfile(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/File.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, fullpath=fullpath: rename(fullpath))
- tempbutton.bind("<Button-2>", lambda event, fullpath=fullpath: delete(fullpath))
- for child in dirframe.winfo_children():
- child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
- updatecanvas("")
- except OSError as e:
- if e.errno == 13:
- mb.showinfo("Error", "Permission Denied")
- goback()
- elif e.errno == 2:
- mb.showinfo("Error", "The folder you tried to open no longer exists or it is formatted incorrectly.")
- goback()
- else:
- mb.showinfo("Error", "An unknown error has occurred.")
- def directory_reload(e):
- global CURRENT_PATH, directory
- directory(CURRENT_PATH)
- def directory_rename():
- global spd
- global mb
- global dirframe
- global dirlabel
- global CURRENT_PATH
- global _root
- global SYSTEM_DIRECTORIES
- global rename
- global delete
- global tk
- global directory
- global updatecanvas
- global goback
- path = CURRENT_PATH
- dirlabel.config(text=path)
- for child in dirframe.winfo_children():
- child.destroy()
- try:
- fullcontents = os.listdir(path)
- contents = [file for file in fullcontents if not file == 'desktop.ini' and not file == 'System Volume Information' and not file == '$RECYCLE.BIN' and not file.endswith('.{SYSTEM}')]
- for element in contents:
- fullpath = os.path.join(path, element)
- if os.path.isdir(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: rename(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/FolderRename.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, path=path: directory(path))
- tempbutton.bind("<Button-2>", lambda event, path=path: directory(path))
- elif os.path.isfile(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: rename(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/FileRename.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, path=path: directory(path))
- tempbutton.bind("<Button-2>", lambda event, path=path: directory(path))
- for child in dirframe.winfo_children():
- child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
- updatecanvas("")
- except OSError as e:
- if e.errno == 13:
- mb.showinfo("Error", "Permission Denied")
- goback()
- elif e.errno == 2:
- mb.showinfo("Error", "The folder you tried to open no longer exists or it is formatted incorrectly.")
- goback()
- else:
- mb.showinfo("Error", "An unknown error has occurred.")
- def directory_delete():
- global spd
- global mb
- global dirframe
- global dirlabel
- global CURRENT_PATH
- global _root
- global SYSTEM_DIRECTORIES
- global rename
- global delete
- global tk
- global directory
- global updatecanvas
- global goback
- path = CURRENT_PATH
- dirlabel.config(text=path)
- for child in dirframe.winfo_children():
- child.destroy()
- try:
- fullcontents = os.listdir(path)
- contents = [file for file in fullcontents if not file == 'desktop.ini' and not file == 'System Volume Information' and not file == '$RECYCLE.BIN' and not file.endswith('.{SYSTEM}')]
- for element in contents:
- fullpath = os.path.join(path, element)
- if os.path.isdir(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: delete(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/FolderDelete.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, path=path: directory(path))
- tempbutton.bind("<Button-2>", lambda event, path=path: directory(path))
- elif os.path.isfile(fullpath):
- tempbutton = tk.Button(dirframe, text=' ' + element, anchor='w', bd=0, bg='white', activebackground='lightgray', compound='left', command=lambda fullpath=fullpath: delete(fullpath), padx=5, pady=2)
- tempbutton.image = tk.PhotoImage(file='T:/TechOS/Virtual/Images/FileDelete.png')
- tempbutton.config(image=tempbutton.image)
- tempbutton.pack(fill='x', anchor='w', side='top')
- tempbutton.bind("<Button-3>", lambda event, path=path: directory(path))
- tempbutton.bind("<Button-2>", lambda event, path=path: directory(path))
- for child in dirframe.winfo_children():
- child.bind("<MouseWheel>", lambda e: Thread(target=lambda e=e: _on_mousewheel(e), daemon=True).start())
- updatecanvas("")
- except OSError as e:
- if e.errno == 13:
- mb.showinfo("Error", "Permission Denied")
- goback()
- elif e.errno == 2:
- mb.showinfo("Error", "The folder you tried to open no longer exists or it is formatted incorrectly.")
- goback()
- else:
- mb.showinfo("Error", "An unknown error has occurred.")
- deletebutton = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', text='Delete', command=directory_delete)
- deletebutton.pack(side='right', anchor='e', fill='y')
- renamebutton = tk.Button(topbar, bd=0, bg='white', activebackground='lightgray', text='Rename', command=directory_rename)
- renamebutton.pack(side='right', anchor='e', fill='y')
- dfcontainer.bind("<Button>", directory_reload)
- directory(CURRENT_PATH)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement