File action menu edits

This commit is contained in:
Maxim Stewart 2019-07-06 19:08:25 -05:00
parent 77872aca35
commit 8d877eb71b
4 changed files with 279 additions and 135 deletions

View File

@ -82,6 +82,11 @@
</object>
</child>
</object>
<object class="GtkImage" id="createImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-new</property>
</object>
<object class="GtkImage" id="trashImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -91,24 +96,28 @@
<property name="can_focus">False</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="window_position">center</property>
<property name="type_hint">splashscreen</property>
<property name="decorated">False</property>
<property name="gravity">center</property>
<signal name="focus-out-event" handler="closePopup" swapped="no"/>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox">
<property name="width_request">500</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkEntry" id="iconRenameInput">
<object class="GtkEntry" id="filenameInput">
<property name="width_request">500</property>
<property name="height_request">26</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_stock">gtk-edit</property>
<signal name="key-release-event" handler="updateFile" swapped="no"/>
<signal name="key-release-event" handler="rename" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
@ -117,7 +126,7 @@
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkBox" id="iconsButtonBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
@ -154,6 +163,126 @@
<property name="position">1</property>
</packing>
</child>
<child type="center">
<object class="GtkButton">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Delete...</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="delete" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</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="tooltip_text" translatable="yes">Move to Trash...</property>
<property name="image">trashImage</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="trash" 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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="menuButtonBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">15</property>
<property name="label" translatable="yes">Folder</property>
<attributes>
<attribute name="size" value="12000"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">15</property>
<property name="label" translatable="yes">File</property>
<attributes>
<attribute name="size" value="12000"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="createSwitch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">File/Folder</property>
<property name="active">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Create</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Create File/Folder...</property>
<property name="image">createImage</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="create" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">gtk-paste</property>
@ -168,48 +297,14 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</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>
<object class="GtkButton">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="deleteFiles" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>

View File

@ -23,11 +23,11 @@ class GridSignals:
self.selectedFiles = []
self.grid = None
self.currentPath = ""
self.pasteType = 1 # copy == 1 and cut == 2
# Add filter to allow only folders to be selected
selectedDirDialog.add_filter(filefilter)
selectedDirDialog.set_filename(self.desktopPath)
self.setIconViewDir(selectedDirDialog)
@ -38,50 +38,64 @@ class GridSignals:
# File control events
def createFile(arg):
pass
def create(self, wdget):
self.currentPath = self.grid.returnCurrentPath()
fileName = self.builder.get_object("filenameInput").get_text().strip()
type = self.builder.get_object("createSwitch").get_state()
def updateFile(self, widget, data):
if fileName != "":
fileName = self.currentPath + "/" + fileName
status = self.filehandler.create(fileName, type)
if status == 0:
self.grid.setIconViewDir(self.currentPath)
def copy(self, widget):
self.pasteType = 1
self.copyCutArry = self.grid.returnSelectedFiles()
def cut(self, widget):
self.pasteType = 2
self.copyCutArry = self.grid.returnSelectedFiles()
def paste(self, widget):
print(len(self.copyCutArry))
self.currentPath = self.grid.returnCurrentPath()
status = self.filehandler.paste(self.copyCutArry, self.currentPath, self.pasteType)
if status == 0:
self.grid.setIconViewDir(self.currentPath)
if self.pasteType == 2: # cut == 2
self.copyCutArry = []
def delete(self, widget):
self.getGridInfo()
status = self.filehandler.delete(self.selectedFiles)
if status == 0:
self.selectedFiles = []
self.grid.setIconViewDir(self.currentPath)
def trash(self, widget):
self.getGridInfo()
status = self.filehandler.trash(self.selectedFiles)
if status == 0:
self.selectedFiles = []
self.grid.setIconViewDir(self.currentPath)
def rename(self, widget, data):
if data.keyval == 65293: # Enter key press
self.getGridInfo()
file = widget.get_text();
if len(self.selectedFiles) == 1:
newName = self.currentPath + "/" + file
status = self.filehandler.updateFile(self.selectedFiles[0], newName)
print("Old Name: " + self.selectedFiles[0])
print("New Name: " + newName)
print("New Name: " + newName.strip())
status = self.filehandler.rename(self.selectedFiles[0], newName.strip())
if status == 0:
self.selectedFiles = [newName]
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)
if status == 0:
self.selectedFiles = []
self.grid.setIconViewDir(self.currentPath)
def copy(self):
self.copyCutArry = self.grid.returnSelectedFiles()
def cut(self):
self.copyCutArry = self.grid.returnSelectedFiles()
def paste(self):
self.currentPath = self.grid.returnCurrentPath()
def getGridInfo(self):
self.selectedFiles = self.grid.returnSelectedFiles()
self.currentPath = self.grid.returnCurrentPath()

View File

@ -55,33 +55,58 @@ class FileHandler:
subprocess.Popen(['xdg-open', file])
def createFile(self, newFileName):
pass
def updateFile(self, oldFileName, newFileName):
def create(self, name, type):
try:
print("Renaming...")
print(oldFileName + " --> " + newFileName)
os.rename(oldFileName, newFileName)
return 0
if type == True: # Create File
open(name, 'w')
else: # Create Folder
os.mkdir(name)
except Exception as e:
print("An error occured renaming the file:")
return 1
return 0
def paste(self, files, toPath, pasteType):
try:
for file in files:
parts = file.split("/")
toBePath = toPath + parts[len(parts) - 1]
finalForm = file + self.dedupPathIter(toBePath)
print(toBePath)
print(finalForm)
except Exception as e:
return 1
# if finalForm != file:
# os.rename(file, finalForm)
#
# if pasteType == 1: # copy paste == 1
# shutil.move(finalForm, toPath)
# if pasteType == 2: # cut paste == 2
# shutil.copy2(finalForm, toPath)
def delete(self, toDeleteFiles):
try:
print("Deleting...")
for file in toDeleteFiles:
print(file)
if os.path.exists(file):
if os.path.isfile(file):
os.remove(file)
elif os.path.isdir(file):
shutil.rmtree(file)
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
def dedupPathIter(self, toBeTrashPath):
i = 0
duplicateFix = ""
return 0
if os.path.exists(toBeTrashPath):
while os.path.exists(toBeTrashPath + duplicateFix) == True:
i+=1
duplicateFix = "-" + str(i)
return duplicateFix
def moveToTrash(self, toTrashFiles):
def trash(self, toTrashFiles):
try:
print("Moving to Trash...")
for file in toTrashFiles:
@ -105,34 +130,30 @@ class FileHandler:
return 0
def deleteFiles(self, toDeleteFiles):
def rename(self, oldFileName, newFileName):
try:
print("Deleting...")
for file in toDeleteFiles:
print(file)
if os.path.exists(file):
if os.path.isfile(file):
os.remove(file)
elif os.path.isdir(file):
shutil.rmtree(file)
else:
print("An error occured deleting the file:")
return 1
if os.path.exists(oldFileName):
print("Renaming...")
print(oldFileName + " --> " + newFileName)
os.rename(oldFileName, newFileName)
else:
print("The folder/file does not exist")
return 1
except Exception as e:
print("An error occured deleting the file:")
print("An error occured renaming the file:")
print(e)
return 1
return 0
def copyFile(self):
pass
def cutFile(self):
pass
def dedupPathIter(self, toBeTrashPath):
duplicateFix = ""
i = 0
def pasteFile(self):
pass
if os.path.exists(toBeTrashPath):
while os.path.exists(toBeTrashPath + duplicateFix) == True:
i+=1
duplicateFix = "-" + str(i)
return duplicateFix

View File

@ -39,14 +39,14 @@ class Grid:
self.threadLock = False # Gtk checks for thread lock
self.helperThread = None # Helper thread object
self.toWorkPool = [] # Thread fills pool and gtk empties it
self.SelectedFiles = []
self.selectedFiles = []
self.currentPath = ""
self.desktop.set_model(self.store)
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.iconRightClick, (self.desktop,))
self.desktop.connect("button_release_event", self.iconSingleClick, (self.desktop,))
def setIconViewDir(self, path):
@ -151,39 +151,53 @@ class Grid:
except Exception as e:
print(e)
def iconRightClick(self, widget, eve, rclicked_icon):
def iconSingleClick(self, widget, eve, rclicked_icon):
try:
if eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3:
input = self.builder.get_object("iconRenameInput")
controls = self.builder.get_object("iconControlsWindow")
if eve.type == gdk.EventType.BUTTON_RELEASE and eve.button == 1:
self.selectedFiles.clear()
items = widget.get_selected_items()
model = widget.get_model()
self.SelectedFiles.clear()
if len(items) == 1:
fileName = model[items[0]][1]
dir = self.currentPath
file = dir + "/" + fileName
self.SelectedFiles.append(file) # Used for return to caller
input.set_text(fileName)
controls.show_all()
elif len(items) > 1:
dir = self.currentPath
for item in items:
fileName = model[item][1]
file = dir + "/" + fileName
self.SelectedFiles.append(file) # Used for return to caller
if fileName != "." and fileName != "..":
file = dir + "/" + fileName
self.selectedFiles.append(file) # Used for return to caller
elif eve.type == gdk.EventType.BUTTON_RELEASE and eve.button == 3:
input = self.builder.get_object("filenameInput")
controls = self.builder.get_object("iconControlsWindow")
iconsButtonBox = self.builder.get_object("iconsButtonBox")
menuButtonBox = self.builder.get_object("menuButtonBox")
if len(self.selectedFiles) == 1:
parts = self.selectedFiles[0].split("/")
input.set_text(parts[len(parts) - 1])
input.show()
iconsButtonBox.show()
menuButtonBox.hide()
controls.show()
elif len(self.selectedFiles) > 1:
input.set_text("")
input.hide()
menuButtonBox.hide()
iconsButtonBox.show()
controls.show()
else:
input.set_text("")
input.show()
menuButtonBox.show()
iconsButtonBox.hide()
controls.show()
except Exception as e:
print(e)
def returnSelectedFiles(self):
return self.SelectedFiles
return self.selectedFiles
def returnCurrentPath(self):
return self.currentPath