2019-06-23 03:23:17 +00:00
|
|
|
# Gtk imports
|
2019-06-09 21:03:38 +00:00
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
gi.require_version('Gdk', '3.0')
|
|
|
|
|
|
|
|
from gi.repository import Gtk as gtk
|
|
|
|
from gi.repository import Gdk as gdk
|
2019-06-17 01:47:15 +00:00
|
|
|
from gi.repository import GLib as glib
|
2019-06-15 02:48:32 +00:00
|
|
|
from gi.repository import GdkPixbuf
|
2019-06-09 21:03:38 +00:00
|
|
|
|
|
|
|
# Python imports
|
2019-06-21 04:07:30 +00:00
|
|
|
import os, threading, time
|
2019-06-09 21:03:38 +00:00
|
|
|
from os.path import isdir, isfile, join
|
|
|
|
from os import listdir
|
2019-06-23 03:23:17 +00:00
|
|
|
|
|
|
|
# Application imports
|
2019-06-11 03:18:30 +00:00
|
|
|
from .Icon import Icon
|
2019-06-23 00:21:18 +00:00
|
|
|
from utils.FileHandler import FileHandler
|
2019-06-09 21:03:38 +00:00
|
|
|
|
|
|
|
|
2019-06-15 02:48:32 +00:00
|
|
|
def threaded(fn):
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
|
2019-07-07 23:18:51 +00:00
|
|
|
|
2019-06-15 02:48:32 +00:00
|
|
|
return wrapper
|
2019-06-09 21:03:38 +00:00
|
|
|
|
2019-07-07 23:18:51 +00:00
|
|
|
|
2019-06-15 02:48:32 +00:00
|
|
|
class Grid:
|
2019-07-07 20:03:44 +00:00
|
|
|
def __init__(self, grid, settings):
|
2019-07-07 23:18:51 +00:00
|
|
|
self.grid = grid
|
|
|
|
self.settings = settings
|
|
|
|
self.fileHandler = FileHandler(self.settings)
|
|
|
|
|
|
|
|
self.store = gtk.ListStore(GdkPixbuf.Pixbuf, str)
|
|
|
|
self.usrHome = settings.returnUserHome()
|
|
|
|
self.hideHiddenFiles = settings.isHideHiddenFiles()
|
|
|
|
self.builder = settings.returnBuilder()
|
|
|
|
self.ColumnSize = settings.returnColumnSize()
|
|
|
|
self.vidsFilter = settings.returnVidsFilter()
|
|
|
|
self.imagesFilter = settings.returnImagesFilter()
|
|
|
|
self.iconFactory = Icon(settings)
|
|
|
|
self.helperThread = None # Helper thread object
|
|
|
|
self.selectedFiles = []
|
|
|
|
self.currentPath = ""
|
2019-06-16 09:28:58 +00:00
|
|
|
|
2019-07-07 20:03:44 +00:00
|
|
|
self.grid.set_model(self.store)
|
|
|
|
self.grid.set_pixbuf_column(0)
|
|
|
|
self.grid.set_text_column(1)
|
|
|
|
self.grid.connect("item-activated", self.iconDblLeftClick)
|
|
|
|
self.grid.connect("button_release_event", self.iconSingleClick, (self.grid,))
|
2019-06-09 21:03:38 +00:00
|
|
|
|
2019-09-29 00:14:32 +00:00
|
|
|
# @threaded
|
2019-07-07 20:03:44 +00:00
|
|
|
def setNewDirectory(self, path):
|
2019-10-15 02:40:25 +00:00
|
|
|
self.store.clear()
|
2019-06-15 02:48:32 +00:00
|
|
|
self.currentPath = path
|
2019-06-16 20:12:06 +00:00
|
|
|
dirPaths = ['.', '..']
|
2019-06-19 00:17:29 +00:00
|
|
|
vids = []
|
|
|
|
images = []
|
|
|
|
desktop = []
|
2019-06-11 03:18:30 +00:00
|
|
|
files = []
|
2019-06-09 21:03:38 +00:00
|
|
|
|
2019-06-15 02:48:32 +00:00
|
|
|
for f in listdir(path):
|
|
|
|
file = join(path, f)
|
2019-07-07 23:18:51 +00:00
|
|
|
if self.hideHiddenFiles:
|
2019-06-09 21:03:38 +00:00
|
|
|
if f.startswith('.'):
|
|
|
|
continue
|
2019-07-07 23:18:51 +00:00
|
|
|
|
2019-06-09 21:03:38 +00:00
|
|
|
if isfile(file):
|
2019-07-07 23:18:51 +00:00
|
|
|
lowerName = file.lower()
|
|
|
|
|
|
|
|
if lowerName.endswith(self.vidsFilter):
|
2019-06-19 00:17:29 +00:00
|
|
|
vids.append(f)
|
2019-07-07 23:18:51 +00:00
|
|
|
elif lowerName.endswith(self.imagesFilter):
|
2019-06-19 00:17:29 +00:00
|
|
|
images.append(f)
|
2019-07-07 23:18:51 +00:00
|
|
|
elif lowerName.endswith((".desktop",)):
|
2019-06-19 00:17:29 +00:00
|
|
|
desktop.append(f)
|
|
|
|
else:
|
|
|
|
files.append(f)
|
2019-06-09 21:03:38 +00:00
|
|
|
else:
|
2019-06-16 20:12:06 +00:00
|
|
|
dirPaths.append(f)
|
2019-06-09 21:03:38 +00:00
|
|
|
|
2019-06-16 20:12:06 +00:00
|
|
|
dirPaths.sort()
|
2019-06-19 00:17:29 +00:00
|
|
|
vids.sort()
|
|
|
|
images.sort()
|
|
|
|
desktop.sort()
|
2019-06-15 02:48:32 +00:00
|
|
|
files.sort()
|
2019-06-21 04:07:30 +00:00
|
|
|
|
2019-07-07 23:18:51 +00:00
|
|
|
files = dirPaths + vids + images + desktop + files
|
2019-10-15 02:40:25 +00:00
|
|
|
self.generateGridIcons(path, files)
|
2019-06-21 04:07:30 +00:00
|
|
|
|
2019-06-15 02:48:32 +00:00
|
|
|
|
2019-10-15 02:40:25 +00:00
|
|
|
@threaded
|
2019-07-07 23:18:51 +00:00
|
|
|
def generateGridIcons(self, dirPath, files):
|
2019-06-15 02:48:32 +00:00
|
|
|
for file in files:
|
2019-10-15 02:40:25 +00:00
|
|
|
image = self.iconFactory.createIcon(dirPath, file).get_pixbuf()
|
|
|
|
glib.idle_add(self.addToGrid, (image, file,))
|
2019-09-29 00:14:32 +00:00
|
|
|
|
2019-10-15 02:40:25 +00:00
|
|
|
def addToGrid(self, dataSet):
|
|
|
|
self.store.append([dataSet[0], dataSet[1]])
|
2019-06-21 02:58:19 +00:00
|
|
|
|
2019-07-05 19:34:15 +00:00
|
|
|
def iconDblLeftClick(self, widget, item):
|
2019-06-11 03:18:30 +00:00
|
|
|
try:
|
2019-06-16 20:12:06 +00:00
|
|
|
model = widget.get_model()
|
|
|
|
fileName = model[item][1]
|
|
|
|
dir = self.currentPath
|
|
|
|
file = dir + "/" + fileName
|
2019-06-09 21:03:38 +00:00
|
|
|
|
2019-06-15 02:48:32 +00:00
|
|
|
if fileName == ".":
|
2019-07-07 20:03:44 +00:00
|
|
|
self.setNewDirectory(dir)
|
2019-06-15 02:48:32 +00:00
|
|
|
elif fileName == "..":
|
|
|
|
parentDir = os.path.abspath(os.path.join(dir, os.pardir))
|
|
|
|
self.currentPath = parentDir
|
2019-07-07 20:03:44 +00:00
|
|
|
self.setNewDirectory(parentDir)
|
2019-06-15 02:48:32 +00:00
|
|
|
elif isdir(file):
|
|
|
|
self.currentPath = file
|
2019-07-07 20:03:44 +00:00
|
|
|
self.setNewDirectory(self.currentPath)
|
2019-06-15 02:48:32 +00:00
|
|
|
elif isfile(file):
|
2019-07-05 19:34:15 +00:00
|
|
|
self.fileHandler.openFile(file)
|
2019-06-15 02:48:32 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2019-06-11 03:18:30 +00:00
|
|
|
|
2019-07-07 00:08:25 +00:00
|
|
|
def iconSingleClick(self, widget, eve, rclicked_icon):
|
2019-06-15 02:48:32 +00:00
|
|
|
try:
|
2019-07-07 00:08:25 +00:00
|
|
|
if eve.type == gdk.EventType.BUTTON_RELEASE and eve.button == 1:
|
|
|
|
self.selectedFiles.clear()
|
2019-06-30 03:50:29 +00:00
|
|
|
items = widget.get_selected_items()
|
|
|
|
model = widget.get_model()
|
2019-07-07 00:08:25 +00:00
|
|
|
dir = self.currentPath
|
2019-06-30 03:50:29 +00:00
|
|
|
|
2019-07-07 00:08:25 +00:00
|
|
|
for item in items:
|
|
|
|
fileName = model[item][1]
|
|
|
|
|
|
|
|
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:
|
2019-06-30 03:50:29 +00:00
|
|
|
input.set_text("")
|
|
|
|
input.hide()
|
2019-07-07 00:08:25 +00:00
|
|
|
menuButtonBox.hide()
|
|
|
|
iconsButtonBox.show()
|
|
|
|
controls.show()
|
|
|
|
else:
|
|
|
|
input.set_text("")
|
|
|
|
input.show()
|
|
|
|
menuButtonBox.show()
|
|
|
|
iconsButtonBox.hide()
|
2019-06-30 03:50:29 +00:00
|
|
|
controls.show()
|
|
|
|
|
2019-06-11 03:18:30 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
2019-07-05 19:34:15 +00:00
|
|
|
|
|
|
|
def returnSelectedFiles(self):
|
2019-07-07 02:18:32 +00:00
|
|
|
# NOTE: Just returning selectedFiles looks like it returns a "pointer"
|
2019-10-15 02:40:25 +00:00
|
|
|
# to the children. This means we lose the list if any left click occures
|
2019-07-07 02:18:32 +00:00
|
|
|
# in this class.
|
|
|
|
files = []
|
|
|
|
for file in self.selectedFiles:
|
|
|
|
files.append(file)
|
|
|
|
return files
|
2019-07-05 19:34:15 +00:00
|
|
|
|
|
|
|
def returnCurrentPath(self):
|
2019-10-15 02:40:25 +00:00
|
|
|
currentPath = self.currentPath
|
|
|
|
return currentPath
|