Integrating trash option

This commit is contained in:
Maxim Stewart 2019-07-05 16:24:00 -05:00
parent 55d2bc9cd1
commit 77872aca35
6 changed files with 60 additions and 9 deletions

View File

@ -82,6 +82,11 @@
</object> </object>
</child> </child>
</object> </object>
<object class="GtkImage" id="trashImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixbuf">icons/trash.png</property>
</object>
<object class="GtkWindow" id="iconControlsWindow"> <object class="GtkWindow" id="iconControlsWindow">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="resizable">False</property> <property name="resizable">False</property>
@ -98,7 +103,7 @@
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkEntry" id="iconRenameInput"> <object class="GtkEntry" id="iconRenameInput">
<property name="width_request">300</property> <property name="width_request">500</property>
<property name="height_request">26</property> <property name="height_request">26</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
@ -121,6 +126,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Copy...</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
<signal name="clicked" handler="copy" swapped="no"/> <signal name="clicked" handler="copy" swapped="no"/>
@ -137,6 +143,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Cut...</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
<signal name="clicked" handler="cut" swapped="no"/> <signal name="clicked" handler="cut" swapped="no"/>
@ -153,6 +160,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Paste...</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
<signal name="clicked" handler="paste" swapped="no"/> <signal name="clicked" handler="paste" swapped="no"/>
@ -163,13 +171,29 @@
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Trash</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">trashImage</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="trashFiles" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">3</property>
</packing>
</child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
<property name="label">gtk-delete</property> <property name="label">gtk-delete</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="margin_left">65</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
<signal name="clicked" handler="deleteFiles" swapped="no"/> <signal name="clicked" handler="deleteFiles" swapped="no"/>
@ -178,7 +202,7 @@
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="pack_type">end</property> <property name="pack_type">end</property>
<property name="position">3</property> <property name="position">4</property>
</packing> </packing>
</child> </child>
</object> </object>

Binary file not shown.

After

Width:  |  Height:  |  Size: 989 B

View File

@ -56,6 +56,15 @@ class GridSignals:
self.grid.setIconViewDir(self.currentPath) 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): def deleteFiles(self, widget):
self.getGridInfo() self.getGridInfo()
status = self.filehandler.deleteFiles(self.selectedFiles) status = self.filehandler.deleteFiles(self.selectedFiles)

View File

@ -69,13 +69,32 @@ class FileHandler:
print(e) print(e)
return 1 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: try:
print("Moving to Trash...") print("Moving to Trash...")
for file in toDeleteFiles: for file in toTrashFiles:
print(file) print(file)
if os.path.exists(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: else:
print("The folder/file does not exist") print("The folder/file does not exist")
return 1 return 1

View File

@ -110,7 +110,6 @@ class Settings:
def returnSystemIconImageWH(self): return self.systemIconImageWxH def returnSystemIconImageWH(self): return self.systemIconImageWxH
def returnVIIconWH(self): return self.viIconWxH def returnVIIconWH(self): return self.viIconWxH
def isHideHiddenFiles(self): return self.hideHiddenFiles def isHideHiddenFiles(self): return self.hideHiddenFiles
def returnImagesExtensionList(self): return self.imagesExtensionList
# Filter returns # Filter returns
def returnOfficeFilter(self): return self.office def returnOfficeFilter(self): return self.office

View File

@ -46,7 +46,7 @@ class Grid:
self.desktop.set_pixbuf_column(0) self.desktop.set_pixbuf_column(0)
self.desktop.set_text_column(1) self.desktop.set_text_column(1)
self.desktop.connect("item-activated", self.iconDblLeftClick) 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): def setIconViewDir(self, path):
@ -151,7 +151,7 @@ class Grid:
except Exception as e: except Exception as e:
print(e) print(e)
def iconClickRight(self, widget, eve, rclicked_icon): def iconRightClick(self, widget, eve, rclicked_icon):
try: try:
if eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3: if eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3:
input = self.builder.get_object("iconRenameInput") input = self.builder.get_object("iconRenameInput")