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() window.show_all()
if __name__ == "__main__": if __name__ == "__main__":
main = Main() main = Main()
gtk.main() gtk.main()

View File

@ -8,108 +8,6 @@
<mime-type>inode/directory</mime-type> <mime-type>inode/directory</mime-type>
</mime-types> </mime-types>
</object> </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"> <object class="GtkImage" id="webDropDown">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -125,7 +23,6 @@
<property name="type_hint">desktop</property> <property name="type_hint">desktop</property>
<property name="decorated">False</property> <property name="decorated">False</property>
<property name="gravity">center</property> <property name="gravity">center</property>
<signal name="button-press-event" handler="showGridControlMenu" swapped="no"/>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
@ -190,17 +87,6 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </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> <child>
<object class="GtkScrolledWindow"> <object class="GtkScrolledWindow">
<property name="visible">True</property> <property name="visible">True</property>
@ -223,12 +109,114 @@
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">2</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
</object> </object>
</child> </child>
</object> </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"> <object class="GtkPopover" id="webViewer">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>

View File

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

View File

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

View File

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

View File

@ -8,108 +8,6 @@
<mime-type>inode/directory</mime-type> <mime-type>inode/directory</mime-type>
</mime-types> </mime-types>
</object> </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"> <object class="GtkImage" id="webDropDown">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -125,7 +23,6 @@
<property name="type_hint">desktop</property> <property name="type_hint">desktop</property>
<property name="decorated">False</property> <property name="decorated">False</property>
<property name="gravity">center</property> <property name="gravity">center</property>
<signal name="button-press-event" handler="showGridControlMenu" swapped="no"/>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>
@ -190,17 +87,6 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </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> <child>
<object class="GtkScrolledWindow"> <object class="GtkScrolledWindow">
<property name="visible">True</property> <property name="visible">True</property>
@ -223,12 +109,114 @@
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">2</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
</object> </object>
</child> </child>
</object> </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"> <object class="GtkPopover" id="webViewer">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>

View File

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

View File

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