Advertisement
MizunoBrasil

Gigacopy 2.2 25/10/2024

Oct 24th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.62 KB | None | 0 0
  1. import os
  2. import threading
  3. import time
  4. from tkinter import *
  5. from tkinter.ttk import *
  6. from tkinter import filedialog, messagebox
  7.  
  8. def start_copy_move():
  9.     src_files = src_entry.get().split(";")
  10.     dst_folder = dst_entry.get()
  11.  
  12.     if not src_files or src_files == ['']:
  13.         messagebox.showwarning("Aviso", "É necessário escolher um ou mais arquivos para copiar ou mover.")
  14.         return
  15.  
  16.     for src in src_files:
  17.         if os.path.isfile(src):
  18.             filename = os.path.basename(src)
  19.             dst = os.path.join(dst_folder, filename)
  20.  
  21.             GB = os.path.getsize(src) / (1024 * 1024 * 1024)
  22.             copied = 0
  23.             chunk_size = 1024 * 1024  # 1MB
  24.             start_time = time.time()  # Início da contagem do tempo
  25.  
  26.             with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
  27.                 while chunk := fsrc.read(chunk_size):
  28.                     fdst.write(chunk)
  29.                     copied += len(chunk) / (1024 * 1024 * 1024)
  30.                     progress = (copied / GB) * 100
  31.                     bar['value'] = progress
  32.                     percent.set(f"{int(progress)}%")
  33.                     text.set(f"{round(copied, 2)}/{round(GB, 2)} GB completos")
  34.  
  35.                     # Cálculo de tempo restante
  36.                     elapsed_time = time.time() - start_time
  37.                     if copied > 0 and elapsed_time > 0:
  38.                         transfer_speed = copied / elapsed_time  # GB/s
  39.                         remaining_time = (GB - copied) / transfer_speed  # Tempo restante em segundos
  40.                         time_remaining.set(f"Tempo restante: {time.strftime('%H:%M:%S', time.gmtime(remaining_time))}")
  41.  
  42.                     window.update_idletasks()
  43.  
  44.             if operation.get() == "move":
  45.                 os.remove(src)  # Remove o arquivo de origem após a cópia
  46.  
  47.     messagebox.showinfo("Sucesso", f"{'Copiado' if operation.get() == 'copy' else 'Movido'} com sucesso!")
  48.     os.startfile(dst_folder)
  49.  
  50. def select_src():
  51.     src_files = filedialog.askopenfilenames()
  52.     src_entry.delete(0, END)
  53.     src_entry.insert(0, ";".join(src_files))
  54.  
  55. def select_dst():
  56.     dst_folder = filedialog.askdirectory()
  57.     dst_entry.delete(0, END)
  58.     dst_entry.insert(0, dst_folder)
  59.  
  60. def start_thread():
  61.     threading.Thread(target=start_copy_move).start()
  62.  
  63. def show_about():
  64.     messagebox.showinfo("Sobre", "GigaCopy 2.2 - Programa para copiar ou mover múltiplos arquivos\n25/10/2024, Mizuno")
  65.  
  66. def exit_program():
  67.     window.quit()
  68.  
  69. # Configuração da janela
  70. window = Tk()
  71. window.title("GigaCopy 2.2")
  72. window.geometry('535x300')
  73. window.eval('tk::PlaceWindow . center')
  74.  
  75. # Menu superior
  76. menu_bar = Menu(window)
  77. file_menu = Menu(menu_bar, tearoff=0)
  78. file_menu.add_command(label="Sobre", command=show_about)
  79. file_menu.add_separator()
  80. file_menu.add_command(label="Sair", command=exit_program)
  81. menu_bar.add_cascade(label="Arquivo", menu=file_menu)
  82. window.config(menu=menu_bar)
  83.  
  84. # Variáveis para a barra de progresso
  85. percent = StringVar()
  86. text = StringVar()
  87. time_remaining = StringVar()  # Variável para o tempo restante
  88. operation = StringVar(value="copy")  # Variável para armazenar a operação selecionada
  89.  
  90. # Layout em grid
  91. Label(window, text="Origem:").grid(row=0, column=0, padx=10, pady=10, sticky=E)
  92. src_entry = Entry(window, width=50)
  93. src_entry.grid(row=0, column=1, padx=10, pady=10)
  94. Button(window, text="...", command=select_src, width=3).grid(row=0, column=2, padx=10, pady=10)
  95.  
  96. Label(window, text="Destino:").grid(row=1, column=0, padx=10, pady=10, sticky=E)
  97. dst_entry = Entry(window, width=50)
  98. dst_entry.grid(row=1, column=1, padx=10, pady=10)
  99. Button(window, text="...", command=select_dst, width=3).grid(row=1, column=2, padx=10, pady=10)
  100.  
  101. # Opções de operação: copiar ou mover
  102. Label(window, text="Operação:").grid(row=2, column=0, padx=10, pady=10, sticky=E)
  103. Radiobutton(window, text="Copiar arquivo(s)", variable=operation, value="copy").grid(row=2, column=1, sticky=W, padx=5)
  104. Radiobutton(window, text="Mover arquivo(s)", variable=operation, value="move").grid(row=2, column=1, padx=130, sticky=W)
  105.  
  106. bar = Progressbar(window, orient=HORIZONTAL, length=400, mode='determinate')
  107. bar.grid(row=3, column=0, columnspan=3, padx=10, pady=10)
  108.  
  109. percentLabel = Label(window, textvariable=percent).grid(row=4, column=0, columnspan=3)
  110. taskLabel = Label(window, textvariable=text).grid(row=5, column=0, columnspan=3)
  111. timeLabel = Label(window, textvariable=time_remaining).grid(row=6, column=0, columnspan=3)  # Exibição do tempo estimado
  112.  
  113. button = Button(window, text="Iniciar", command=start_thread).grid(row=7, column=2, pady=10)
  114.  
  115. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement