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():
- src_files = src_entry.get().split(";") # Divide os arquivos selecionados
- dst_folder = dst_entry.get()
- # Verifica se nenhum arquivo foi selecionado
- if not src_files or src_files == ['']:
- messagebox.showwarning("Aviso", "É necessário escolher um ou mais arquivos para copiar.")
- return
- for src in src_files:
- if os.path.isfile(src):
- filename = os.path.basename(src) # Obtém o nome do arquivo
- dst = os.path.join(dst_folder, filename) # Define o caminho de destino
- GB = os.path.getsize(src) / (1024 * 1024 * 1024)
- copied = 0
- chunk_size = 1024 * 1024 # 1MB
- 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")
- window.update_idletasks()
- # Exibe o alerta ao final da cópia
- messagebox.showinfo("Sucesso", "Cópia concluída com sucesso!")
- os.startfile(dst_folder) # Abre a pasta de destino
- def select_src():
- src_files = filedialog.askopenfilenames() # Permite a seleção de múltiplos arquivos
- src_entry.delete(0, END)
- src_entry.insert(0, ";".join(src_files)) # Insere os arquivos selecionados, separados por ";"
- def select_dst():
- dst_folder = filedialog.askdirectory() # Escolhe a pasta de destino
- dst_entry.delete(0, END)
- dst_entry.insert(0, dst_folder)
- def start_thread():
- threading.Thread(target=start_copy).start()
- def show_about():
- messagebox.showinfo("Sobre", "Programa para cópia de múltiplos arquivos\n29/08/2024, Mizuno")
- def exit_program():
- window.quit()
- # Configuração da janela
- window = Tk()
- window.title("GigaCopy 2.0")
- window.geometry('500x250') # Mantém a altura da janela para 250 pixels e a altura em 500 pixels
- 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()
- # 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) # Largura reduzida
- 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) # Largura reduzida
- bar = Progressbar(window, orient=HORIZONTAL, length=400, mode='determinate')
- bar.grid(row=2, column=0, columnspan=3, padx=10, pady=10)
- percentLabel = Label(window, textvariable=percent).grid(row=3, column=0, columnspan=3)
- taskLabel = Label(window, textvariable=text).grid(row=4, column=0, columnspan=3)
- button = Button(window, text="Copiar", command=start_thread).grid(row=5, column=2, pady=10)
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement