From 77872aca3570169d0072a93b9c93210173a91f65 Mon Sep 17 00:00:00 2001 From: Maxim Stewart Date: Fri, 5 Jul 2019 16:24:00 -0500 Subject: [PATCH] Integrating trash option --- src/pytop-0.0.1/Pytop/resources/PyTop.glade | 30 ++++++++++++++++-- .../Pytop/resources/icons/trash.png | Bin 0 -> 989 bytes .../Pytop/signal_classes/GridSignals.py | 9 ++++++ src/pytop-0.0.1/Pytop/utils/FileHandler.py | 25 +++++++++++++-- src/pytop-0.0.1/Pytop/utils/Settings.py | 1 - src/pytop-0.0.1/Pytop/widgets/Grid.py | 4 +-- 6 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 src/pytop-0.0.1/Pytop/resources/icons/trash.png diff --git a/src/pytop-0.0.1/Pytop/resources/PyTop.glade b/src/pytop-0.0.1/Pytop/resources/PyTop.glade index ee62283..5436b5c 100644 --- a/src/pytop-0.0.1/Pytop/resources/PyTop.glade +++ b/src/pytop-0.0.1/Pytop/resources/PyTop.glade @@ -82,6 +82,11 @@ + + True + False + icons/trash.png + False False @@ -98,7 +103,7 @@ vertical - 300 + 500 26 True True @@ -121,6 +126,7 @@ True True True + Copy... True True @@ -137,6 +143,7 @@ True True True + Cut... True True @@ -153,6 +160,7 @@ True True True + Paste... True True @@ -163,13 +171,29 @@ 2 + + + Trash + True + True + True + trashImage + True + + + + False + True + end + 3 + + gtk-delete True True True - 65 True True @@ -178,7 +202,7 @@ False True end - 3 + 4 diff --git a/src/pytop-0.0.1/Pytop/resources/icons/trash.png b/src/pytop-0.0.1/Pytop/resources/icons/trash.png new file mode 100644 index 0000000000000000000000000000000000000000..c6514b98b5644a1398e5b94566627683bdf8313c GIT binary patch literal 989 zcmV<310wv1P)15yzTLCe34-$-L*zeV%iVi<#7%{pXzDkMHky2mk=z;1Ymqjw*`_ z;l=cX!@yxS)3eMo)!7q(s1S;8XDeoIfk&q@7uoI?s zN^{=g#zud^U7~af3UN1l@tmQLOr|QHWPuroi5&@B4xE5LwSSN~G+$j==zSl}UMNQg zyH_50>t(Oi+-x&5w89uZw-ptSj&|nuPG2fiPCt#GwwmD#Jm6oxx$^wCcxirh-cQ9a ziluU6K|Pn5D~^E<4p7JT?N5^#IMVgKv(20OG$aWqB{-E1 z9oKKm#x_8Yf!EY3G??PhH00od3`|8Cr#dh|?Xc^Z-nF9>;EQ2fnv!5>XX9e5(~w%Q zWxxzw@&_hiR$9Lcoc|vHx!)lO6-mr}?nq6T47i&p1j1BE6+d+ySi293cx+=BS^bPd z2pc)RW6($#nyaDBQ#bUD)T*xo(~>w=@g&O4P0907%sO^H(WGl-(aW~-b3x1wa&{7m zuWn2M!9yrPfv)`{h@?zgx|KUDMpnH#&O}b58kogEan(fp3IGm{0yF@Eai?E1TUpQI zP%w=Iic?7KIfYR^3~mA204Ox%tPdgo9_IQMM*@lfDHI}T5|U27TT;IPe*mD6XwTM& zhIg`@LxX@qgMnb0tVSaItJ7O4fL$Dd0pPc<&*3~0q)-r0(BKH6aSoNuc<)UB0GrMp z6mp=g$)0LI{yHl_Lcst-1y5iV&y7F1{N=AVPXJ(u4pd6_>+}0v$EYsS1=O&N8hVrM zpZ|RC94JwwF%&23;_5K`+J-nN-|HR00000 LNkvXXu0mjfZ-lz6 literal 0 HcmV?d00001 diff --git a/src/pytop-0.0.1/Pytop/signal_classes/GridSignals.py b/src/pytop-0.0.1/Pytop/signal_classes/GridSignals.py index 5d07099..1117f4f 100644 --- a/src/pytop-0.0.1/Pytop/signal_classes/GridSignals.py +++ b/src/pytop-0.0.1/Pytop/signal_classes/GridSignals.py @@ -56,6 +56,15 @@ class GridSignals: self.grid.setIconViewDir(self.currentPath) + def trashFiles(self, widget): + self.getGridInfo() + status = self.filehandler.moveToTrash(self.selectedFiles) + + if status == 0: + self.selectedFiles = [] + self.grid.setIconViewDir(self.currentPath) + + def deleteFiles(self, widget): self.getGridInfo() status = self.filehandler.deleteFiles(self.selectedFiles) diff --git a/src/pytop-0.0.1/Pytop/utils/FileHandler.py b/src/pytop-0.0.1/Pytop/utils/FileHandler.py index 1554232..85096ea 100644 --- a/src/pytop-0.0.1/Pytop/utils/FileHandler.py +++ b/src/pytop-0.0.1/Pytop/utils/FileHandler.py @@ -69,13 +69,32 @@ class FileHandler: print(e) return 1 - def moveToTrash(arg): + def dedupPathIter(self, toBeTrashPath): + i = 0 + duplicateFix = "" + + if os.path.exists(toBeTrashPath): + while os.path.exists(toBeTrashPath + duplicateFix) == True: + i+=1 + duplicateFix = "-" + str(i) + + return duplicateFix + + + def moveToTrash(self, toTrashFiles): try: print("Moving to Trash...") - for file in toDeleteFiles: + for file in toTrashFiles: print(file) if os.path.exists(file): - shutil.move(file, self.TRASHFILESFOLDER) + parts = file.split("/") + toBeTrashPath = self.TRASHFILESFOLDER + parts[len(parts) - 1] + finalForm = file + self.dedupPathIter(toBeTrashPath) + + if finalForm != file: + os.rename(file, finalForm) + + shutil.move(finalForm, self.TRASHFILESFOLDER) else: print("The folder/file does not exist") return 1 diff --git a/src/pytop-0.0.1/Pytop/utils/Settings.py b/src/pytop-0.0.1/Pytop/utils/Settings.py index 4792b04..d1f1ff7 100644 --- a/src/pytop-0.0.1/Pytop/utils/Settings.py +++ b/src/pytop-0.0.1/Pytop/utils/Settings.py @@ -110,7 +110,6 @@ class Settings: def returnSystemIconImageWH(self): return self.systemIconImageWxH def returnVIIconWH(self): return self.viIconWxH def isHideHiddenFiles(self): return self.hideHiddenFiles - def returnImagesExtensionList(self): return self.imagesExtensionList # Filter returns def returnOfficeFilter(self): return self.office diff --git a/src/pytop-0.0.1/Pytop/widgets/Grid.py b/src/pytop-0.0.1/Pytop/widgets/Grid.py index 6fbb58f..bdfc736 100644 --- a/src/pytop-0.0.1/Pytop/widgets/Grid.py +++ b/src/pytop-0.0.1/Pytop/widgets/Grid.py @@ -46,7 +46,7 @@ class Grid: self.desktop.set_pixbuf_column(0) self.desktop.set_text_column(1) self.desktop.connect("item-activated", self.iconDblLeftClick) - self.desktop.connect("button_press_event", self.iconClickRight, (self.desktop,)) + self.desktop.connect("button_press_event", self.iconRightClick, (self.desktop,)) def setIconViewDir(self, path): @@ -151,7 +151,7 @@ class Grid: except Exception as e: print(e) - def iconClickRight(self, widget, eve, rclicked_icon): + def iconRightClick(self, widget, eve, rclicked_icon): try: if eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3: input = self.builder.get_object("iconRenameInput")