Completed delete and rename actions.

This commit is contained in:
Maxim Stewart 2019-06-10 22:44:15 -05:00
parent 7fa8d2081e
commit 36d45d1bdf
7 changed files with 104 additions and 34 deletions

Binary file not shown.

View File

@ -31,9 +31,7 @@ class Events:
selectedDirDialog.add_filter(filefilter)
selectedDirDialog.set_filename(self.desktopPath)
self.grid = None
self.selectedFile = None
self.grid = None
self.setDir(selectedDirDialog)
@ -44,19 +42,21 @@ class Events:
# Grid(self.desktop, self.settings).generateDirectoryGrid(newPath)
def showGridControlMenu(self, widget, data=None):
self.selectedFile = widget
popover = self.builder.get_object("gridControlMenu")
popover.show_all()
popover.popup()
# File control events
def renameFile(self, widget, data=None):
def createFile(self):
pass
def updateFile(self, widget, data=None):
newName = widget.get_text().strip()
if data and data.keyval == 65293: # Enter key event
self.grid.renameFile(newName)
self.grid.updateFile(newName)
elif data == None: # Save button 'event'
self.grid.renameFile(newName)
self.grid.updateFile(newName)
def deleteFile(self, widget, data=None):
self.grid.deleteFile()
@ -67,6 +67,9 @@ class Events:
def cutFile(self):
pass
def pasteFile(self):
pass
# Webview events
def showWebview(self, widget):

View File

@ -1,6 +1,5 @@
import subprocess
import os, shutil, subprocess
class FileHandler:
def __init__(self):
@ -23,9 +22,6 @@ class FileHandler:
self.MPLAYER_WH = " -xy 1600 -geometry 50%:50% ";
self.MPV_WH = " -geometry 50%:50% ";
self.selectedFile = None
def openFile(self, file):
print("Opening: " + file)
@ -45,10 +41,14 @@ class FileHandler:
subprocess.Popen(['xdg-open', file])
def renameFile(self, oldFileName, newFileName):
def createFile(self, newFileName):
pass
def updateFile(self, oldFileName, newFileName):
try:
print("Renaming...")
print(oldFileName + " --> " + newFileName)
os.rename(oldFileName, newFileName)
return 0
except Exception as e:
print("An error occured renaming the file:")
@ -59,8 +59,29 @@ class FileHandler:
try:
print("Deleting...")
print(toDeleteFile)
return 0
if os.path.exists(toDeleteFile):
if os.path.isfile(toDeleteFile):
os.remove(toDeleteFile)
elif os.path.isdir(toDeleteFile):
shutil.rmtree(toDeleteFile)
else:
print("An error occured deleting the file:")
return 1
else:
print("The folder/file does not exist")
return 1
except Exception as e:
print("An error occured deleting the file:")
print(e)
return 1
return 0
def copyFile(self):
pass
def cutFile(self):
pass
def pasteFile(self):
pass

View File

@ -155,18 +155,29 @@ class Grid:
# Pass through file control events
def renameFile(self, file):
def createFile(arg):
pass
def updateFile(self, file):
newName = self.currentPath + "/" + file
status = self.filehandler.renameFile(self.selectedFile, newName)
status = self.filehandler.updateFile(self.selectedFile, newName)
if status == 0:
self.selectedFile = newName
self.generateDirectoryGrid(self.currentPath)
def deleteFile(self):
status = self.filehandler.deleteFile(self.selectedFile)
if status == 0:
self.selectedFile = ""
self.generateDirectoryGrid(self.currentPath)
def copyFile(self):
pass
def cutFile(self):
pass
def pasteFile(self):
pass

View File

@ -31,9 +31,7 @@ class Events:
selectedDirDialog.add_filter(filefilter)
selectedDirDialog.set_filename(self.desktopPath)
self.grid = None
self.selectedFile = None
self.grid = None
self.setDir(selectedDirDialog)
@ -44,19 +42,21 @@ class Events:
# Grid(self.desktop, self.settings).generateDirectoryGrid(newPath)
def showGridControlMenu(self, widget, data=None):
self.selectedFile = widget
popover = self.builder.get_object("gridControlMenu")
popover.show_all()
popover.popup()
# File control events
def renameFile(self, widget, data=None):
def createFile(self):
pass
def updateFile(self, widget, data=None):
newName = widget.get_text().strip()
if data and data.keyval == 65293: # Enter key event
self.grid.renameFile(newName)
self.grid.updateFile(newName)
elif data == None: # Save button 'event'
self.grid.renameFile(newName)
self.grid.updateFile(newName)
def deleteFile(self, widget, data=None):
self.grid.deleteFile()
@ -67,6 +67,9 @@ class Events:
def cutFile(self):
pass
def pasteFile(self):
pass
# Webview events
def showWebview(self, widget):

View File

@ -1,6 +1,5 @@
import subprocess
import os, shutil, subprocess
class FileHandler:
def __init__(self):
@ -23,9 +22,6 @@ class FileHandler:
self.MPLAYER_WH = " -xy 1600 -geometry 50%:50% ";
self.MPV_WH = " -geometry 50%:50% ";
self.selectedFile = None
def openFile(self, file):
print("Opening: " + file)
@ -45,10 +41,14 @@ class FileHandler:
subprocess.Popen(['xdg-open', file])
def renameFile(self, oldFileName, newFileName):
def createFile(self, newFileName):
pass
def updateFile(self, oldFileName, newFileName):
try:
print("Renaming...")
print(oldFileName + " --> " + newFileName)
os.rename(oldFileName, newFileName)
return 0
except Exception as e:
print("An error occured renaming the file:")
@ -59,8 +59,29 @@ class FileHandler:
try:
print("Deleting...")
print(toDeleteFile)
return 0
if os.path.exists(toDeleteFile):
if os.path.isfile(toDeleteFile):
os.remove(toDeleteFile)
elif os.path.isdir(toDeleteFile):
shutil.rmtree(toDeleteFile)
else:
print("An error occured deleting the file:")
return 1
else:
print("The folder/file does not exist")
return 1
except Exception as e:
print("An error occured deleting the file:")
print(e)
return 1
return 0
def copyFile(self):
pass
def cutFile(self):
pass
def pasteFile(self):
pass

View File

@ -155,18 +155,29 @@ class Grid:
# Pass through file control events
def renameFile(self, file):
def createFile(arg):
pass
def updateFile(self, file):
newName = self.currentPath + "/" + file
status = self.filehandler.renameFile(self.selectedFile, newName)
status = self.filehandler.updateFile(self.selectedFile, newName)
if status == 0:
self.selectedFile = newName
self.generateDirectoryGrid(self.currentPath)
def deleteFile(self):
status = self.filehandler.deleteFile(self.selectedFile)
if status == 0:
self.selectedFile = ""
self.generateDirectoryGrid(self.currentPath)
def copyFile(self):
pass
def cutFile(self):
pass
def pasteFile(self):
pass