Advertisement
MizunoBrasil

Gigacopy 2.1

Oct 23rd, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.91 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.            
  25.             with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
  26.                 while chunk := fsrc.read(chunk_size):
  27.                     fdst.write(chunk)
  28.                     copied += len(chunk) / (1024 * 1024 * 1024)
  29.                     progress = (copied / GB) * 100
  30.                     bar['value'] = progress
  31.                     percent.set(f"{int(progress)}%")
  32.                     text.set(f"{round(copied, 2)}/{round(GB, 2)} GB completos")
  33.                     window.update_idletasks()
  34.  
  35.             if operation.get() == "move":
  36.                 os.remove(src)  # Remove o arquivo de origem após a cópia
  37.  
  38.     messagebox.showinfo("Sucesso", f"{'Cópia' if operation.get() == 'copy' else 'Movimento'} concluído com sucesso!")
  39.     os.startfile(dst_folder)
  40.  
  41. def select_src():
  42.     src_files = filedialog.askopenfilenames()
  43.     src_entry.delete(0, END)
  44.     src_entry.insert(0, ";".join(src_files))
  45.  
  46. def select_dst():
  47.     dst_folder = filedialog.askdirectory()
  48.     dst_entry.delete(0, END)
  49.     dst_entry.insert(0, dst_folder)
  50.  
  51. def start_thread():
  52.     threading.Thread(target=start_copy_move).start()
  53.  
  54. def show_about():
  55.     messagebox.showinfo("Sobre", "GigaCopy 2.1Programa para cópia e movimento de múltiplos arquivos\n23/10/2024, Mizuno")
  56.  
  57. def exit_program():
  58.     window.quit()
  59.  
  60. # Configuração da janela
  61. window = Tk()
  62. window.title("GigaCopy 2.1")
  63. window.geometry('500x300')
  64. window.eval('tk::PlaceWindow . center')
  65.  
  66. # Menu superior
  67. menu_bar = Menu(window)
  68. file_menu = Menu(menu_bar, tearoff=0)
  69. file_menu.add_command(label="Sobre", command=show_about)
  70. file_menu.add_separator()
  71. file_menu.add_command(label="Sair", command=exit_program)
  72. menu_bar.add_cascade(label="Arquivo", menu=file_menu)
  73. window.config(menu=menu_bar)
  74.  
  75. # Variáveis para a barra de progresso
  76. percent = StringVar()
  77. text = StringVar()
  78. operation = StringVar(value="copy")  # Variável para armazenar a operação selecionada
  79.  
  80. # Layout em grid
  81. Label(window, text="Origem:").grid(row=0, column=0, padx=10, pady=10, sticky=E)
  82. src_entry = Entry(window, width=50)
  83. src_entry.grid(row=0, column=1, padx=10, pady=10)
  84. Button(window, text="...", command=select_src, width=3).grid(row=0, column=2, padx=10, pady=10)
  85.  
  86. Label(window, text="Destino:").grid(row=1, column=0, padx=10, pady=10, sticky=E)
  87. dst_entry = Entry(window, width=50)
  88. dst_entry.grid(row=1, column=1, padx=10, pady=10)
  89. Button(window, text="...", command=select_dst, width=3).grid(row=1, column=2, padx=10, pady=10)
  90.  
  91. # Opções de operação: copiar ou mover
  92. Label(window, text="Operação:").grid(row=2, column=0, padx=10, pady=10, sticky=E)
  93. Radiobutton(window, text="Copiar", variable=operation, value="copy").grid(row=2, column=1, sticky=W)
  94. Radiobutton(window, text="Mover", variable=operation, value="move").grid(row=2, column=1, padx=80, sticky=W)
  95.  
  96. bar = Progressbar(window, orient=HORIZONTAL, length=400, mode='determinate')
  97. bar.grid(row=3, column=0, columnspan=3, padx=10, pady=10)
  98.  
  99. percentLabel = Label(window, textvariable=percent).grid(row=4, column=0, columnspan=3)
  100. taskLabel = Label(window, textvariable=text).grid(row=5, column=0, columnspan=3)
  101.  
  102. button = Button(window, text="Iniciar", command=start_thread).grid(row=6, column=2, pady=10)
  103.  
  104. window.mainloop()
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement