Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import threading
- import time
- from tkinter import *
- from tkinter.ttk import *
- from tkinter import filedialog, messagebox
- def start_copy_move():
- src_files = src_entry.get().split(";")
- dst_folder = dst_entry.get()
- if not src_files or src_files == ['']:
- messagebox.showwarning("Aviso", "É necessário escolher um ou mais arquivos para copiar ou mover.")
- return
- for src in src_files:
- if os.path.isfile(src):
- filename = os.path.basename(src)
- dst = os.path.join(dst_folder, filename)
- GB = os.path.getsize(src) / (1024 * 1024 * 1024)
- copied = 0
- chunk_size = 1024 * 1024 # 1MB
- start_time = time.time() # Início da contagem do tempo
- with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
- while chunk := fsrc.read(chunk_size):
- fdst.write(chunk)
- copied += len(chunk) / (1024 * 1024 * 1024)
- progress = (copied / GB) * 100
- bar['value'] = progress
- percent.set(f"{int(progress)}%")
- text.set(f"{round(copied, 2)}/{round(GB, 2)} GB completos")
- # Cálculo de tempo restante
- elapsed_time = time.time() - start_time
- if copied > 0 and elapsed_time > 0:
- transfer_speed = copied / elapsed_time # GB/s
- remaining_time = (GB - copied) / transfer_speed # Tempo restante em segundos
- time_remaining.set(f"Tempo restante: {time.strftime('%H:%M:%S', time.gmtime(remaining_time))}")
- window.update_idletasks()
- if operation.get() == "move":
- os.remove(src) # Remove o arquivo de origem após a cópia
- messagebox.showinfo("Sucesso", f"{'Copiado' if operation.get() == 'copy' else 'Movido'} com sucesso!")
- os.startfile(dst_folder)
- def select_src():
- src_files = filedialog.askopenfilenames()
- src_entry.delete(0, END)
- src_entry.insert(0, ";".join(src_files))
- def select_dst():
- dst_folder = filedialog.askdirectory()
- dst_entry.delete(0, END)
- dst_entry.insert(0, dst_folder)
- def start_thread():
- threading.Thread(target=start_copy_move).start()
- def show_about():
- messagebox.showinfo("Sobre", "GigaCopy 2.2 - Programa para copiar ou mover múltiplos arquivos\n25/10/2024, Mizuno")
- def exit_program():
- window.quit()
- # Configuração da janela
- window = Tk()
- window.title("GigaCopy 2.2")
- window.geometry('535x300')
- window.eval('tk::PlaceWindow . center')
- # Menu superior
- menu_bar = Menu(window)
- file_menu = Menu(menu_bar, tearoff=0)
- file_menu.add_command(label="Sobre", command=show_about)
- file_menu.add_separator()
- file_menu.add_command(label="Sair", command=exit_program)
- menu_bar.add_cascade(label="Arquivo", menu=file_menu)
- window.config(menu=menu_bar)
- # Variáveis para a barra de progresso
- percent = StringVar()
- text = StringVar()
- time_remaining = StringVar() # Variável para o tempo restante
- operation = StringVar(value="copy") # Variável para armazenar a operação selecionada
- # Layout em grid
- Label(window, text="Origem:").grid(row=0, column=0, padx=10, pady=10, sticky=E)
- src_entry = Entry(window, width=50)
- src_entry.grid(row=0, column=1, padx=10, pady=10)
- Button(window, text="...", command=select_src, width=3).grid(row=0, column=2, padx=10, pady=10)
- Label(window, text="Destino:").grid(row=1, column=0, padx=10, pady=10, sticky=E)
- dst_entry = Entry(window, width=50)
- dst_entry.grid(row=1, column=1, padx=10, pady=10)
- Button(window, text="...", command=select_dst, width=3).grid(row=1, column=2, padx=10, pady=10)
- # Opções de operação: copiar ou mover
- Label(window, text="Operação:").grid(row=2, column=0, padx=10, pady=10, sticky=E)
- Radiobutton(window, text="Copiar arquivo(s)", variable=operation, value="copy").grid(row=2, column=1, sticky=W, padx=5)
- Radiobutton(window, text="Mover arquivo(s)", variable=operation, value="move").grid(row=2, column=1, padx=130, sticky=W)
- bar = Progressbar(window, orient=HORIZONTAL, length=400, mode='determinate')
- bar.grid(row=3, column=0, columnspan=3, padx=10, pady=10)
- percentLabel = Label(window, textvariable=percent).grid(row=4, column=0, columnspan=3)
- taskLabel = Label(window, textvariable=text).grid(row=5, column=0, columnspan=3)
- timeLabel = Label(window, textvariable=time_remaining).grid(row=6, column=0, columnspan=3) # Exibição do tempo estimado
- button = Button(window, text="Iniciar", command=start_thread).grid(row=7, column=2, pady=10)
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement