Cleanedup Icon creation

This commit is contained in:
Maxim Stewart 2019-06-16 20:47:15 -05:00
parent 7a03a3dc6a
commit a4c98450f3
11 changed files with 304 additions and 388 deletions

Binary file not shown.

View File

@ -28,10 +28,6 @@ class Main:
window.show_all()
if __name__ == "__main__":
main = Main()
gtk.main()

View File

@ -8,108 +8,6 @@
<mime-type>inode/directory</mime-type>
</mime-types>
</object>
<object class="GtkPopoverMenu" id="gridControlMenu">
<property name="can_focus">False</property>
<property name="position">bottom</property>
<child>
<object class="GtkButton">
<property name="label">gtk-paste</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>
</object>
<packing>
<property name="submenu">main</property>
<property name="position">1</property>
</packing>
</child>
</object>
<object class="GtkPopover" id="iconControlsWindow">
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkEntry" id="iconRenameInput">
<property name="width_request">300</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label">gtk-copy</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">gtk-cut</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</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="margin_left">65</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</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>
</object>
</child>
</object>
<object class="GtkImage" id="webDropDown">
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -125,7 +23,6 @@
<property name="type_hint">desktop</property>
<property name="decorated">False</property>
<property name="gravity">center</property>
<signal name="button-press-event" handler="showGridControlMenu" swapped="no"/>
<child>
<placeholder/>
</child>
@ -190,17 +87,6 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkProgressBar" id="loadProgress">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
@ -223,12 +109,114 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkPopoverMenu" id="iconControlsWindow">
<property name="can_focus">False</property>
<property name="relative_to">Desktop</property>
<property name="position">right</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkEntry" id="iconRenameInput">
<property name="width_request">300</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label">gtk-copy</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">gtk-cut</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>
</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">gtk-paste</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>
</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-delete</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_left">65</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</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>
</object>
<packing>
<property name="submenu">main</property>
</packing>
</child>
</object>
<object class="GtkPopover" id="webViewer">
<property name="can_focus">False</property>
<property name="hexpand">True</property>

View File

@ -1,8 +1,5 @@
# Gtk Imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
# Python imports
from .Grid import Grid
@ -32,10 +29,6 @@ class Events:
newPath = widget.get_filename()
Grid(self.desktop, self.settings, newPath)
def showGridControlMenu(self, widget, data=None):
popover = self.builder.get_object("gridControlMenu")
popover.show_all()
popover.popup()
# File control events
@ -61,9 +54,6 @@ class Events:
def pasteFile(self):
pass
def test(self, widget, data=None):
print(widget)
# Webview events
def showWebview(self, widget):
self.builder.get_object("webViewer").popup()

View File

@ -7,8 +7,8 @@ gi.require_version('Gdk', '3.0')
from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
from gi.repository import GLib as glib
from gi.repository import GdkPixbuf
from gi.repository import GObject as gobject
# Python imports
import os, threading
@ -18,8 +18,6 @@ from .Icon import Icon
from .FileHandler import FileHandler
gdk.threads_init()
def threaded(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
@ -46,7 +44,6 @@ class Grid:
self.setIconViewDir(newPath)
@threaded
def setIconViewDir(self, path):
self.store.clear()
@ -69,25 +66,13 @@ class Grid:
files = dirPaths + files
self.generateDirectoryGrid(path, files)
@threaded
def generateDirectoryGrid(self, dirPath, files):
fractionTick = 1.0 / 1.0 if len(files) == 0 else len(files)
tickCount = 0.0
row = 0
col = 0
x = 0
y = 0
loadProgress = self.builder.get_object('loadProgress')
loadProgress.set_text("Loading...")
loadProgress.set_fraction(0.0)
for file in files:
imgBuffer = Icon(self.settings).createIcon(dirPath, file)
gobject.idle_add(self.addToGrid, (imgBuffer, file,))
# tickCount += fractionTick
# loadProgress.set_fraction(tickCount)
loadProgress.set_text("Finished...")
image = Icon(self.settings).createIcon(dirPath, file)
# NOTE: Passing pixbuf after retreval to keep Icon.py file more universaly usable.
# We can just remove get_pixbuf to get a gtk image
glib.idle_add(self.addToGrid, (image.get_pixbuf(), file,))
def addToGrid(self, args):
self.store.append([args[0], args[1]])
@ -116,6 +101,11 @@ class Grid:
def iconRightClickEventManager(self, widget, eve, params):
try:
if eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3:
popover = self.builder.get_object("iconControlsWindow")
popover.show_all()
popover.popup()
print(popover)
# # NOTE: Need to change name of listview box...
# children = widget.get_children()[0].get_children()
# fileName = children[1].get_text()
@ -123,14 +113,14 @@ class Grid:
# file = dir + "/" + fileName
#
# input = self.builder.get_object("iconRenameInput")
popover = self.builder.get_object("iconControlsWindow")
# popover = self.builder.get_object("iconControlsWindow")
# self.selectedFile = file # Used for return to caller
#
# input.set_text(fileName)
popover.set_relative_to(widget)
popover.set_position(gtk.PositionType.RIGHT)
popover.show_all()
popover.popup()
# popover.set_relative_to(widget)
# popover.set_position(gtk.PositionType.RIGHT)
# popover.show_all()
# popover.popup()
except Exception as e:
print(e)

View File

@ -29,61 +29,55 @@ class Icon:
self.viIconWxH = settings.returnVIIconWH()
def createIcon(self, dir, file):
fullPathFile = dir + "/" + file
thumbnl = self.getIconImage(file, fullPathFile)
fullPath = dir + "/" + file
thumbnl = self.getIconImage(file, fullPath)
return thumbnl
def getIconImage(self, file, fullPathFile):
def getIconImage(self, file, fullPath):
thumbnl = gtk.Image()
vidsList = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
imagesList = ('.png', '.jpg', '.jpeg', '.gif')
if file.lower().endswith(vidsList):
fileHash = hashlib.sha256(str.encode(fullPathFile)).hexdigest()
hashImgpth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
try:
if file.lower().endswith(vidsList):
fileHash = hashlib.sha256(str.encode(fullPath)).hexdigest()
hashImgpth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
# Generate any thumbnails beforehand...
try:
if isfile(hashImgpth) == False:
self.generateVideoThumbnail(fullPathFile, hashImgpth)
thumbnl = self.createIconImageBuffer(hashImgpth, self.viIconWxH)
else:
thumbnl = self.createIconImageBuffer(hashImgpth, self.viIconWxH)
except Exception as e:
print(e)
thumbPth = self.getSystemThumbnail(fullPathFile, self.systemIconImageWxH[0])
thumbnl = self.createIconImageBuffer(thumbPth, self.systemIconImageWxH)
self.generateVideoThumbnail(fullPath, hashImgpth)
elif file.lower().endswith(imagesList):
thumbnl = self.createIconImageBuffer(fullPathFile, self.viIconWxH)
else:
try:
thumbPth = self.getSystemThumbnail(fullPathFile, self.systemIconImageWxH[0])
thumbnl = self.createIconImageBuffer(thumbPth, self.systemIconImageWxH)
except Exception as e:
print(e)
thumbnl = gtk.Image(stock = gtk.STOCK_DIALOG_ERROR)
thumbnl = self.createIconImageBuffer(hashImgpth, self.viIconWxH)
elif file.lower().endswith(imagesList):
thumbnl = self.createIconImageBuffer(fullPath, self.viIconWxH)
else:
thumbnl = self.nonImageOrVideoIcon(fullPath)
except Exception as e:
return gtk.Image.new_from_file("resources/icons/bin.png")
# NOTE: Returning pixbuf through retreval to keep this file more universaly usable.
# We can just remove get_pixbuf to get a gtk image
return thumbnl.get_pixbuf()
if thumbnl == None: # If no system icon, try stock file icon...
thumbnl = gtk.Image.new_from_icon_name("gtk-file", gtk.IconSize.LARGE_TOOLBAR)
if thumbnl == None:
thumbnl = gtk.Image.new_from_file("resources/icons/bin.png")
return thumbnl
def nonImageOrVideoIcon(self, fullPath):
thumbPth = self.getSystemThumbnail(fullPath, self.systemIconImageWxH[0])
return self.createIconImageBuffer(thumbPth, self.systemIconImageWxH)
def createIconImageBuffer(self, path, wxh):
pixbuf = None
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
filename = path,
width = wxh[0],
height = wxh[1],
# preserve_aspect_ratio = False)
preserve_aspect_ratio = True)
filename = path,
width = wxh[0],
height = wxh[1],
preserve_aspect_ratio = False)
return gtk.Image.new_from_pixbuf(pixbuf)
except Exception as e:
print(e)
return gtk.Image.new_from_file("resources/icons/bin.png")
return gtk.Image(stock = gtk.STOCK_DIALOG_ERROR)
def getSystemThumbnail(self, filename,size):
def getSystemThumbnail(self, filename, size):
final_filename = ""
if os.path.exists(filename):
file = gio.File.new_for_path(filename)
@ -97,6 +91,6 @@ class Icon:
return final_filename
def generateVideoThumbnail(self, fullPathFile, hashImgpth):
proc = subprocess.Popen([self.thubnailGen, "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPathFile, "-o", hashImgpth])
def generateVideoThumbnail(self, fullPath, hashImgpth):
proc = subprocess.Popen([self.thubnailGen, "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPath, "-o", hashImgpth])
proc.wait()

View File

@ -28,10 +28,6 @@ class Main:
window.show_all()
if __name__ == "__main__":
main = Main()
gtk.main()

View File

@ -8,108 +8,6 @@
<mime-type>inode/directory</mime-type>
</mime-types>
</object>
<object class="GtkPopoverMenu" id="gridControlMenu">
<property name="can_focus">False</property>
<property name="position">bottom</property>
<child>
<object class="GtkButton">
<property name="label">gtk-paste</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>
</object>
<packing>
<property name="submenu">main</property>
<property name="position">1</property>
</packing>
</child>
</object>
<object class="GtkPopover" id="iconControlsWindow">
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkEntry" id="iconRenameInput">
<property name="width_request">300</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label">gtk-copy</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">gtk-cut</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<placeholder/>
</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="margin_left">65</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</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>
</object>
</child>
</object>
<object class="GtkImage" id="webDropDown">
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -125,7 +23,6 @@
<property name="type_hint">desktop</property>
<property name="decorated">False</property>
<property name="gravity">center</property>
<signal name="button-press-event" handler="showGridControlMenu" swapped="no"/>
<child>
<placeholder/>
</child>
@ -190,17 +87,6 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkProgressBar" id="loadProgress">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
@ -223,12 +109,114 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkPopoverMenu" id="iconControlsWindow">
<property name="can_focus">False</property>
<property name="relative_to">Desktop</property>
<property name="position">right</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkEntry" id="iconRenameInput">
<property name="width_request">300</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton">
<property name="label">gtk-copy</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>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">gtk-cut</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>
</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">gtk-paste</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>
</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-delete</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_left">65</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
</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>
</object>
<packing>
<property name="submenu">main</property>
</packing>
</child>
</object>
<object class="GtkPopover" id="webViewer">
<property name="can_focus">False</property>
<property name="hexpand">True</property>

View File

@ -1,8 +1,5 @@
# Gtk Imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
# Python imports
from .Grid import Grid
@ -32,10 +29,6 @@ class Events:
newPath = widget.get_filename()
Grid(self.desktop, self.settings, newPath)
def showGridControlMenu(self, widget, data=None):
popover = self.builder.get_object("gridControlMenu")
popover.show_all()
popover.popup()
# File control events
@ -61,9 +54,6 @@ class Events:
def pasteFile(self):
pass
def test(self, widget, data=None):
print(widget)
# Webview events
def showWebview(self, widget):
self.builder.get_object("webViewer").popup()

View File

@ -7,8 +7,8 @@ gi.require_version('Gdk', '3.0')
from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
from gi.repository import GLib as glib
from gi.repository import GdkPixbuf
from gi.repository import GObject as gobject
# Python imports
import os, threading
@ -18,8 +18,6 @@ from .Icon import Icon
from .FileHandler import FileHandler
gdk.threads_init()
def threaded(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
@ -46,7 +44,6 @@ class Grid:
self.setIconViewDir(newPath)
@threaded
def setIconViewDir(self, path):
self.store.clear()
@ -69,25 +66,13 @@ class Grid:
files = dirPaths + files
self.generateDirectoryGrid(path, files)
@threaded
def generateDirectoryGrid(self, dirPath, files):
fractionTick = 1.0 / 1.0 if len(files) == 0 else len(files)
tickCount = 0.0
row = 0
col = 0
x = 0
y = 0
loadProgress = self.builder.get_object('loadProgress')
loadProgress.set_text("Loading...")
loadProgress.set_fraction(0.0)
for file in files:
imgBuffer = Icon(self.settings).createIcon(dirPath, file)
gobject.idle_add(self.addToGrid, (imgBuffer, file,))
# tickCount += fractionTick
# loadProgress.set_fraction(tickCount)
loadProgress.set_text("Finished...")
image = Icon(self.settings).createIcon(dirPath, file)
# NOTE: Passing pixbuf after retreval to keep Icon.py file more universaly usable.
# We can just remove get_pixbuf to get a gtk image
glib.idle_add(self.addToGrid, (image.get_pixbuf(), file,))
def addToGrid(self, args):
self.store.append([args[0], args[1]])
@ -116,6 +101,11 @@ class Grid:
def iconRightClickEventManager(self, widget, eve, params):
try:
if eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3:
popover = self.builder.get_object("iconControlsWindow")
popover.show_all()
popover.popup()
print(popover)
# # NOTE: Need to change name of listview box...
# children = widget.get_children()[0].get_children()
# fileName = children[1].get_text()
@ -123,14 +113,14 @@ class Grid:
# file = dir + "/" + fileName
#
# input = self.builder.get_object("iconRenameInput")
popover = self.builder.get_object("iconControlsWindow")
# popover = self.builder.get_object("iconControlsWindow")
# self.selectedFile = file # Used for return to caller
#
# input.set_text(fileName)
popover.set_relative_to(widget)
popover.set_position(gtk.PositionType.RIGHT)
popover.show_all()
popover.popup()
# popover.set_relative_to(widget)
# popover.set_position(gtk.PositionType.RIGHT)
# popover.show_all()
# popover.popup()
except Exception as e:
print(e)

View File

@ -29,61 +29,55 @@ class Icon:
self.viIconWxH = settings.returnVIIconWH()
def createIcon(self, dir, file):
fullPathFile = dir + "/" + file
thumbnl = self.getIconImage(file, fullPathFile)
fullPath = dir + "/" + file
thumbnl = self.getIconImage(file, fullPath)
return thumbnl
def getIconImage(self, file, fullPathFile):
def getIconImage(self, file, fullPath):
thumbnl = gtk.Image()
vidsList = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
imagesList = ('.png', '.jpg', '.jpeg', '.gif')
if file.lower().endswith(vidsList):
fileHash = hashlib.sha256(str.encode(fullPathFile)).hexdigest()
hashImgpth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
try:
if file.lower().endswith(vidsList):
fileHash = hashlib.sha256(str.encode(fullPath)).hexdigest()
hashImgpth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
# Generate any thumbnails beforehand...
try:
if isfile(hashImgpth) == False:
self.generateVideoThumbnail(fullPathFile, hashImgpth)
thumbnl = self.createIconImageBuffer(hashImgpth, self.viIconWxH)
else:
thumbnl = self.createIconImageBuffer(hashImgpth, self.viIconWxH)
except Exception as e:
print(e)
thumbPth = self.getSystemThumbnail(fullPathFile, self.systemIconImageWxH[0])
thumbnl = self.createIconImageBuffer(thumbPth, self.systemIconImageWxH)
self.generateVideoThumbnail(fullPath, hashImgpth)
elif file.lower().endswith(imagesList):
thumbnl = self.createIconImageBuffer(fullPathFile, self.viIconWxH)
else:
try:
thumbPth = self.getSystemThumbnail(fullPathFile, self.systemIconImageWxH[0])
thumbnl = self.createIconImageBuffer(thumbPth, self.systemIconImageWxH)
except Exception as e:
print(e)
thumbnl = gtk.Image(stock = gtk.STOCK_DIALOG_ERROR)
thumbnl = self.createIconImageBuffer(hashImgpth, self.viIconWxH)
elif file.lower().endswith(imagesList):
thumbnl = self.createIconImageBuffer(fullPath, self.viIconWxH)
else:
thumbnl = self.nonImageOrVideoIcon(fullPath)
except Exception as e:
return gtk.Image.new_from_file("resources/icons/bin.png")
# NOTE: Returning pixbuf through retreval to keep this file more universaly usable.
# We can just remove get_pixbuf to get a gtk image
return thumbnl.get_pixbuf()
if thumbnl == None: # If no system icon, try stock file icon...
thumbnl = gtk.Image.new_from_icon_name("gtk-file", gtk.IconSize.LARGE_TOOLBAR)
if thumbnl == None:
thumbnl = gtk.Image.new_from_file("resources/icons/bin.png")
return thumbnl
def nonImageOrVideoIcon(self, fullPath):
thumbPth = self.getSystemThumbnail(fullPath, self.systemIconImageWxH[0])
return self.createIconImageBuffer(thumbPth, self.systemIconImageWxH)
def createIconImageBuffer(self, path, wxh):
pixbuf = None
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
filename = path,
width = wxh[0],
height = wxh[1],
# preserve_aspect_ratio = False)
preserve_aspect_ratio = True)
filename = path,
width = wxh[0],
height = wxh[1],
preserve_aspect_ratio = False)
return gtk.Image.new_from_pixbuf(pixbuf)
except Exception as e:
print(e)
return gtk.Image.new_from_file("resources/icons/bin.png")
return gtk.Image(stock = gtk.STOCK_DIALOG_ERROR)
def getSystemThumbnail(self, filename,size):
def getSystemThumbnail(self, filename, size):
final_filename = ""
if os.path.exists(filename):
file = gio.File.new_for_path(filename)
@ -97,6 +91,6 @@ class Icon:
return final_filename
def generateVideoThumbnail(self, fullPathFile, hashImgpth):
proc = subprocess.Popen([self.thubnailGen, "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPathFile, "-o", hashImgpth])
def generateVideoThumbnail(self, fullPath, hashImgpth):
proc = subprocess.Popen([self.thubnailGen, "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPath, "-o", hashImgpth])
proc.wait()