Skip to content

Commit

Permalink
V0.09.0 Added Basic Copy Paste Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
domhnallmorr committed Oct 17, 2021
1 parent 9216bbb commit d4e3f7e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
Binary file modified src/__pycache__/branch_tab.cpython-39.pyc
Binary file not shown.
56 changes: 53 additions & 3 deletions src/branch_tab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from distutils.dir_util import copy_tree
import os
from shutil import copyfile
import subprocess
import tkinter as tk
from tkinter import *
Expand Down Expand Up @@ -113,7 +115,12 @@ def OnRightClick(self, event):
new_menu.add_command(label="New Folder(s)", command=self.new_folders, image=self.mainapp.folder_icon2, compound='left',)
popup_menu.add_separator()
new_menu.add_command(label="File", command=lambda mode='new': self.new_file(mode), image=self.mainapp.new_icon2, compound='left',)


popup_menu.add_separator()
if iid:
popup_menu.add_command(label="Copy", command=lambda file=file_name: self.copy_file(file))
if self.mainapp.file_to_copy != None:
popup_menu.add_command(label="Paste", command=self.paste_file)
#popup_menu.add_command(label="Delete Root Tab", command=lambda tab=clicked_tab: event.widget.mainapp.delete_root_tab(tab))

try:
Expand Down Expand Up @@ -174,7 +181,46 @@ def new_file(self, mode, initialvalue=''):
else:
os.rename(os.path.join(self.explorer.current_directory, self.orig_file_name), os.path.join(self.explorer.current_directory, new_name))
self.update_tab(self.explorer.current_directory)


def copy_file(self, file):
self.mainapp.file_to_copy = [{'Name': file, 'Path': self.explorer.current_directory}]

def paste_file(self):
action_if_duplicate = 'ask'

for file in self.mainapp.file_to_copy:
destination = os.path.join(self.explorer.current_directory, file['Name'])

# Copy File
if os.path.isfile(os.path.join(file['Path'], file['Name'])):
# handle for file already existing in destination
if os.path.isfile(os.path.join(self.explorer.current_directory, file['Name'])):

#if os.path.isfile(os.path.join(self.explorer.current_directory, file['Name']))
#if action_if_duplicate == 'ask':
counter = 1
while True: # Check if File Exists
filename, file_extension = os.path.splitext(file['Name'])
if not os.path.isfile(os.path.join(self.explorer.current_directory, f"{filename}({counter}){file_extension}")):
destination = os.path.join(self.explorer.current_directory, f"{filename}({counter}){file_extension}")
break
counter += 1
copyfile(os.path.join(file['Path'], file['Name']), destination)

# Copy Directory
elif os.path.isdir(os.path.join(file['Path'], file['Name'])):
# handle for folder already existing in destination
if os.path.isdir(os.path.join(self.explorer.current_directory, file['Name'])):
counter = 1
while True: # Check if File Exists
if not os.path.isdir(os.path.join(self.explorer.current_directory, f"{file['Name']}({counter})")):
destination = os.path.join(self.explorer.current_directory, f"{file['Name']}({counter})")
break
counter += 1
copy_tree(os.path.join(file['Path'], file['Name']), destination)

self.update_tab(self.explorer.current_directory)

class AddFoldersWindow(ttk.Frame):
def __init__(self, mainapp, master, branch_tab):
super(AddFoldersWindow, self).__init__()
Expand Down Expand Up @@ -224,4 +270,8 @@ def cleanup(self, button):
else:
messagebox.showerror('Error', message=msg)
else:
self.top.destroy()
self.top.destroy()




26 changes: 22 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, parent, *args, **kwargs):
self.setup_tabs()

def setup_variables(self):
self.version = '0.08.0'
self.version = '0.09.0'
self.parent.title(f"Tk Path Finder V{self.version}")
self.config_data = config_file_manager.load_config_file(self)

Expand All @@ -57,6 +57,8 @@ def setup_variables(self):
'.xlsx': ['Excel Worksheet', self.excel_icon2],
'.zip': ['ZIP File', self.zip_icon2],
}

self.file_to_copy = None

def setup_menu(self):
menu = tk.Menu(self.master)
Expand Down Expand Up @@ -124,8 +126,23 @@ def setup_main_frames(self):
ttk.Label(self.sidebar_frame, text='Quick Access').grid(row=0, column=0, columnspan=8, sticky='NSEW')
#ttk.Button(self.container, text='Add Root', command=self.create_root_tab).pack()


def copy(self, event):
current_root_tab = self.notebook.nametowidget(self.notebook.select())
current_branch_tab = current_root_tab.notebook.nametowidget(current_root_tab.notebook.select())
if current_branch_tab.treeview.selection() != ():
item = current_branch_tab.treeview.selection()[0]
current_branch_tab.copy_file(current_branch_tab.treeview.item(item,"text"))

def paste(self, event):
if self.file_to_copy != None:
current_root_tab, current_branch_tab = self.get_current_tabs()
current_branch_tab.paste_file()

def get_current_tabs(self):
current_root_tab = self.notebook.nametowidget(self.notebook.select())
current_branch_tab = current_root_tab.notebook.nametowidget(current_root_tab.notebook.select())

return current_root_tab, current_branch_tab
if __name__ == "__main__":
root = tk.Tk()
root.resizable(width=tk.TRUE, height=tk.TRUE)
Expand All @@ -137,7 +154,8 @@ def setup_main_frames(self):
# root.bind('<Control-Shift-KeyPress-S>', lambda event, MA=MA: fm.save_as(event, MA))
# root.bind('<Control-z>', MA.states.undo)
# root.bind('<Control-y>', MA.states.redo)

#root.geometry('{}x{}'.format(MA.screen_width, MA.screen_height))
root.bind('<Control-c>', MA.copy)
root.bind('<Control-v>', MA.paste)

root.state('zoomed') #mamimise window
root.mainloop()

0 comments on commit d4e3f7e

Please sign in to comment.