Modularized a lot of parts

This commit is contained in:
Maxim Stewart 2019-06-09 16:03:38 -05:00
parent 2cc48b8688
commit a675ed05f7
15 changed files with 490 additions and 394 deletions

Binary file not shown.

150
src/debs/pytop-0-0-1-x64/opt/Pytop/PyTop.py Normal file → Executable file
View File

@ -3,24 +3,13 @@
# Gtk Imports # Gtk Imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
gi.require_version('WebKit2', '4.0') gi.require_version('WebKit2', '4.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 GObject as gobject
from gi.repository import WebKit2 as webkit from gi.repository import WebKit2 as webkit
# Python imports # Python imports
import os, threading, subprocess, hashlib from utils import Settings, Events
from utils import Settings, Icon, FileHandler, Dragging
from os.path import isdir, isfile, join
from threading import Thread
from os import listdir
gdk.threads_init()
class Main: class Main:
@ -29,152 +18,19 @@ class Main:
webkit.WebView() webkit.WebView()
self.builder = gtk.Builder() self.builder = gtk.Builder()
self.filehandler = FileHandler()
self.settings = Settings() self.settings = Settings()
# self.drag = Dragging()
self.settings.attachBuilder(self.builder) self.settings.attachBuilder(self.builder)
self.builder.connect_signals(self) self.builder.connect_signals(Events(self.builder, self.settings))
self.currentPath = "" window = self.settings.createWindow()
window = self.settings.createWindow()
self.usrHome = self.settings.returnUserHome()
self.desktopPath = self.settings.returnDesktopPath()
self.ColumnSize = self.settings.returnColumnSize()
self.desktop = self.builder.get_object("Desktop")
# Add filter to allow only folders to be selected
self.loadProgress = self.builder.get_object("loadProgress")
selectedDirDialog = self.builder.get_object("selectedDirDialog")
filefilter = self.builder.get_object("Folders")
selectedDirDialog.add_filter(filefilter)
selectedDirDialog.set_filename(self.desktopPath)
self.setDir(selectedDirDialog)
self.webview = self.builder.get_object("webview")
self.settings.setDefaultWebviewSettings(self.webview, self.webview.get_settings())
self.webview.load_uri(self.settings.returnWebHome())
window.fullscreen() window.fullscreen()
window.show_all() window.show_all()
def setDir(self, widget, data=None):
self.currentPath = widget.get_filename()
self.getDirectoryList(self.currentPath)
# Thread(target=self.getDirectoryList, args=(self.currentPath,)).start()
def getDirectoryList(self, dir):
dirs = ['.', '..']
files = []
for f in listdir(dir):
file = join(dir, f)
if self.settings.isHideHiddenFiles():
if f.startswith('.'):
continue
if isfile(file):
files.append(f)
else:
dirs.append(f)
dirs.sort()
files.sort()
files = dirs + files
fractionTick = 1.0 / 1.0 if len(files) == 0 else len(files)
tickCount = 0.0
row = 0
col = 0
x = 0
y = 0
self.loadProgress.set_text("Loading...")
self.loadProgress.set_fraction(0.0)
self.clear(self.desktop)
for file in files:
eveBox = Icon().createIcon(dir, file)
# self.drag.connectEvents(self.desktop, eveBox)
eveBox.connect("button_press_event", self.clickManager, (eveBox,))
eveBox.connect("enter_notify_event", self.settings.mouseOver, ())
eveBox.connect("leave_notify_event", self.settings.mouseOut, ())
gobject.idle_add(self.addToGrid, (self.desktop, eveBox, col, row,))
tickCount = tickCount + fractionTick
self.loadProgress.set_fraction(tickCount)
col += 1
if col == self.ColumnSize:
col = 0
row += 1
self.desktop.show_all()
self.loadProgress.set_text("Finished...")
def addToGrid(self, args):
args[0].attach(args[1], args[2], args[3], 1, 1)
def clickManager(self, widget, eve, params):
self.settings.setSelected(params[0])
if eve.type == gdk.EventType.DOUBLE_BUTTON_PRESS:
box = widget.get_children()[0]
children = box.get_children()
fileName = children[1].get_text()
dir = self.currentPath
file = dir + "/" + fileName
if fileName == ".":
self.getDirectoryList(dir)
elif fileName == "..":
parentDir = os.path.abspath(os.path.join(dir, os.pardir))
self.currentPath = parentDir
self.getDirectoryList(parentDir)
elif isdir(file):
self.currentPath = file
self.getDirectoryList(file)
# Thread(target=self.getDirectoryList, args=(file,)).start()
else:
self.filehandler.openFile(file)
elif eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3:
box = widget.get_children()[0]
children = box.get_children()
popover = self.builder.get_object("controlsWindow")
popover.set_relative_to(children[1])
popover.set_position(gtk.PositionType.RIGHT)
popover.show_all()
input = self.builder.get_object("renamerInput")
input.set_text(children[1].get_text())
popover.popup()
def showWebview(self, widget):
self.builder.get_object("webViewer").popup()
def loadHome(self, widget):
self.webview.load_uri(self.settings.returnWebHome())
def runSearchWebview(self, widget, data=None):
if data.keyval == 65293:
self.webview.load_uri(widget.get_text().strip())
def refreshPage(self, widget, data=None):
self.webview.load_uri(self.webview.get_uri())
def setUrlBar(self, widget, data=None):
self.builder.get_object("webviewSearch").set_text(widget.get_uri())
def clear(self, object):
while True:
if object.get_child_at(0,0)!= None:
object.remove_row(0)
else:
break
if __name__ == "__main__": if __name__ == "__main__":
main = Main() main = Main()

View File

@ -8,7 +8,24 @@
<mime-type>inode/directory</mime-type> <mime-type>inode/directory</mime-type>
</mime-types> </mime-types>
</object> </object>
<object class="GtkPopover" id="controlsWindow"> <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>
</packing>
</child>
</object>
<object class="GtkPopover" id="iconControlsWindow">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
@ -16,7 +33,7 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkEntry" id="renamerInput"> <object class="GtkEntry" id="iconRenameInput">
<property name="width_request">300</property> <property name="width_request">300</property>
<property name="height_request">26</property> <property name="height_request">26</property>
<property name="visible">True</property> <property name="visible">True</property>
@ -64,19 +81,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton"> <placeholder/>
<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>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
@ -119,11 +124,12 @@
<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>
<child> <child>
<object class="GtkBox"> <object class="GtkBox" id="box1">
<property name="width_request">256</property> <property name="width_request">256</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -133,7 +139,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkSearchEntry"> <object class="GtkSearchEntry" id="searchentry1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property> <property name="primary_icon_name">edit-find-symbolic</property>

View File

@ -0,0 +1,60 @@
# Gtk Imports
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk as gdk
# Python imports
import os, threading
from .Grid import Grid
from .Dragging import Dragging
from threading import Thread
gdk.threads_init()
class Events:
def __init__(self, builder, settings):
self.builder = builder
self.settings = settings
self.desktop = self.builder.get_object("Desktop")
self.desktopPath = self.settings.returnDesktopPath()
self.webview = self.builder.get_object("webview")
self.settings.setDefaultWebviewSettings(self.webview, self.webview.get_settings())
self.webview.load_uri(self.settings.returnWebHome())
# Add filter to allow only folders to be selected
selectedDirDialog = self.builder.get_object("selectedDirDialog")
filefilter = self.builder.get_object("Folders")
selectedDirDialog.add_filter(filefilter)
selectedDirDialog.set_filename(self.desktopPath)
self.setDir(selectedDirDialog)
def setDir(self, widget, data=None):
newPath = widget.get_filename()
Thread(target=Grid(self.desktop, self.settings).generateDirectoryGrid, args=(newPath,)).start()
def showGridControlMenu(self, widget, data=None):
popover = self.builder.get_object("gridControlMenu")
popover.show_all()
popover.popup()
def showWebview(self, widget):
self.builder.get_object("webViewer").popup()
def loadHome(self, widget):
self.webview.load_uri(self.settings.returnWebHome())
def runSearchWebview(self, widget, data=None):
if data.keyval == 65293:
self.webview.load_uri(widget.get_text().strip())
def refreshPage(self, widget, data=None):
self.webview.load_uri(self.webview.get_uri())
def setUrlBar(self, widget, data=None):
self.builder.get_object("webviewSearch").set_text(widget.get_uri())

View File

@ -0,0 +1,122 @@
# Gtk Imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
from gi.repository import GObject as gobject
# Python imports
from .Icon import Icon
from .FileHandler import FileHandler
import os, subprocess
from os.path import isdir, isfile, join
from os import listdir
class Grid:
def __init__(self, desktop, settings):
self.desktop = desktop
self.settings = settings
self.filehandler = FileHandler()
self.currentPath = ""
self.builder = self.settings.returnBuilder()
self.ColumnSize = self.settings.returnColumnSize()
def generateDirectoryGrid(self, dirPath):
dirPaths = ['.', '..']
files = []
# self.desktop.connect("button_press_event", self.showGridControlMenu, ())
for f in listdir(dirPath):
file = join(dirPath, f)
if self.settings.isHideHiddenFiles():
if f.startswith('.'):
continue
if isfile(file):
files.append(f)
else:
dirPaths.append(f)
dirPaths.sort()
files.sort()
files = dirPaths + 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)
self.clearGrid(self.desktop)
for file in files:
eveBox = Icon().createIcon(dirPath, file)
# self.drag.connectEvents(self.desktop, eveBox)
eveBox.connect("button_press_event", self.iconClickEventManager, (eveBox,))
eveBox.connect("enter_notify_event", self.settings.mouseOver, ())
eveBox.connect("leave_notify_event", self.settings.mouseOut, ())
gobject.idle_add(self.addToGrid, (self.desktop, eveBox, col, row,))
tickCount = tickCount + fractionTick
loadProgress.set_fraction(tickCount)
col += 1
if col == self.ColumnSize:
col = 0
row += 1
self.desktop.show_all()
loadProgress.set_text("Finished...")
def addToGrid(self, args):
args[0].attach(args[1], args[2], args[3], 1, 1)
def clearGrid(self, object):
while True:
if object.get_child_at(0,0)!= None:
object.remove_row(0)
else:
break
def iconClickEventManager(self, widget, eve, params):
self.settings.setSelected(params[0])
if eve.type == gdk.EventType.DOUBLE_BUTTON_PRESS:
children = widget.get_children()[0].get_children()
fileName = children[1].get_text()
dir = self.currentPath
file = dir + "/" + fileName
if fileName == ".":
self.generateDirectoryGrid(dir)
elif fileName == "..":
parentDir = os.path.abspath(os.path.join(dir, os.pardir))
self.currentPath = parentDir
self.generateDirectoryGrid(parentDir)
elif isdir(file):
self.currentPath = file
Thread(target=self.generateDirectoryGrid, args=(self.currentPath,)).start()
else:
self.filehandler.openFile(file)
elif eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3:
children = widget.get_children()[0].get_children()
input = self.builder.get_object("iconRenameInput")
popover = self.builder.get_object("iconControlsWindow")
input.set_text(children[1].get_text())
popover.set_relative_to(children[1])
popover.set_position(gtk.PositionType.RIGHT)
popover.show_all()
popover.popup()

View File

@ -14,12 +14,11 @@ from os.path import isdir, isfile, join
class Icon: class Icon:
def __init__(self): def __init__(self):
self.GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1) self.GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
self.iconImageWxH = [128, -1] self.iconContainerWxH = [128, -1]
self.iconSystem = [72, 72] self.systemIconImageWxH = [72, 72]
self.iconWxH = [128, -1] self.viIconWxH = [128, -1]
self.iconMargins = 8 self.usrHome = os.path.expanduser('~')
self.usrHome = os.path.expanduser('~')
def createIcon(self, dir, file): def createIcon(self, dir, file):
@ -27,17 +26,16 @@ class Icon:
eveBox = gtk.EventBox() eveBox = gtk.EventBox()
icon = gtk.Box() icon = gtk.Box()
label = gtk.Label() label = gtk.Label()
thumbnl = self.defineIconImage(file, fullPathFile) thumbnl = self.getIconImage(file, fullPathFile)
label.set_max_width_chars(1) label.set_max_width_chars(1)
label.set_ellipsize(3) # ELLIPSIZE_END (3) label.set_ellipsize(3) # ELLIPSIZE_END (3)
label.set_lines(2) label.set_lines(2)
label.set_line_wrap(True) label.set_line_wrap(True)
label.set_line_wrap_mode(2) # WRAP_WORD (0) WRAP_CHAR (1) WRAP_WORD_CHAR (2) label.set_line_wrap_mode(2) # WRAP_WORD (0) WRAP_CHAR (1) WRAP_WORD_CHAR (2)
label.set_width_chars(1)
label.set_text(file) label.set_text(file)
icon.set_size_request(self.iconWxH[0], self.iconWxH[1]); icon.set_size_request(self.iconContainerWxH[0], self.iconContainerWxH[1]);
icon.set_property('orientation', self.GTK_ORIENTATION) icon.set_property('orientation', self.GTK_ORIENTATION)
icon.add(thumbnl) icon.add(thumbnl)
icon.add(label) icon.add(label)
@ -46,7 +44,7 @@ class Icon:
eveBox.show_all() eveBox.show_all()
return eveBox return eveBox
def defineIconImage(self, file, fullPathFile): def getIconImage(self, file, fullPathFile):
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')
@ -55,17 +53,33 @@ class Icon:
fileHash = hashlib.sha256(str.encode(fullPathFile)).hexdigest() fileHash = hashlib.sha256(str.encode(fullPathFile)).hexdigest()
hashImgpth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png" hashImgpth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
if isfile(hashImgpth) == False: if isfile(hashImgpth) == False:
self.generateThumbnail(fullPathFile, hashImgpth) self.generateVideoThumbnail(fullPathFile, hashImgpth)
thumbnl = self.createGtkImage(hashImgpth, self.iconImageWxH) thumbnl = self.createIconImageFromBuffer(hashImgpth, self.viIconWxH)
elif file.lower().endswith(imagesList): elif file.lower().endswith(imagesList):
thumbnl = self.createGtkImage(fullPathFile, self.iconImageWxH) thumbnl = self.createIconImageFromBuffer(fullPathFile, self.viIconWxH)
else: else:
thumbPth = self.getSystemThumbnail(fullPathFile, self.iconSystem[0]) thumbPth = self.getSystemThumbnail(fullPathFile, self.systemIconImageWxH[0])
thumbnl = self.createGtkImage(thumbPth, self.iconSystem) thumbnl = self.createIconImageFromBuffer(thumbPth, self.systemIconImageWxH)
return thumbnl return thumbnl
def createIconImageFromBuffer(self, path, wxh):
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
filename = path,
width = wxh[0],
height = wxh[1],
preserve_aspect_ratio = True)
return gtk.Image.new_from_pixbuf(pixbuf)
except Exception as e:
print(e)
return gtk.Image()
def generateVideoThumbnail(self, fullPathFile, hashImgpth):
subprocess.call(["ffmpegthumbnailer", "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPathFile, "-o", hashImgpth])
def getSystemThumbnail(self, filename,size): def getSystemThumbnail(self, filename,size):
final_filename = "" final_filename = ""
if os.path.exists(filename): if os.path.exists(filename):
@ -79,19 +93,3 @@ class Icon:
final_filename = icon_file.get_filename() final_filename = icon_file.get_filename()
return final_filename return final_filename
def generateThumbnail(self, fullPathFile, hashImgpth):
subprocess.call(["ffmpegthumbnailer", "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPathFile, "-o", hashImgpth])
def createGtkImage(self, path, wxh):
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
filename = path,
width = wxh[0],
height = wxh[1],
preserve_aspect_ratio = True)
return gtk.Image.new_from_pixbuf(pixbuf)
except Exception as e:
print(e)
return gtk.Image()

View File

@ -62,8 +62,9 @@ class Settings:
return monitors return monitors
def isHideHiddenFiles(self):
return self.hideHiddenFiles def returnBuilder(self):
return self.builder
def returnUserHome(self): def returnUserHome(self):
return self.usrHome return self.usrHome
@ -77,6 +78,9 @@ class Settings:
def returnWebHome(self): def returnWebHome(self):
return self.webHome return self.webHome
def isHideHiddenFiles(self):
return self.hideHiddenFiles
def mouseOver(self, widget, eve, args): def mouseOver(self, widget, eve, args):
hand_cursor = gdk.Cursor(gdk.CursorType.HAND2) hand_cursor = gdk.Cursor(gdk.CursorType.HAND2)
self.builder.get_object("Window").get_window().set_cursor(hand_cursor) self.builder.get_object("Window").get_window().set_cursor(hand_cursor)

View File

@ -1,4 +1,6 @@
from utils.Dragging import Dragging from utils.Dragging import Dragging
from utils.Settings import Settings from utils.Settings import Settings
from utils.Events import Events
from utils.Grid import Grid
from utils.Icon import Icon from utils.Icon import Icon
from utils.FileHandler import FileHandler from utils.FileHandler import FileHandler

View File

@ -3,24 +3,13 @@
# Gtk Imports # Gtk Imports
import gi import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
gi.require_version('WebKit2', '4.0') gi.require_version('WebKit2', '4.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 GObject as gobject
from gi.repository import WebKit2 as webkit from gi.repository import WebKit2 as webkit
# Python imports # Python imports
import os, threading, subprocess, hashlib from utils import Settings, Events
from utils import Settings, Icon, FileHandler, Dragging
from os.path import isdir, isfile, join
from threading import Thread
from os import listdir
gdk.threads_init()
class Main: class Main:
@ -29,152 +18,19 @@ class Main:
webkit.WebView() webkit.WebView()
self.builder = gtk.Builder() self.builder = gtk.Builder()
self.filehandler = FileHandler()
self.settings = Settings() self.settings = Settings()
# self.drag = Dragging()
self.settings.attachBuilder(self.builder) self.settings.attachBuilder(self.builder)
self.builder.connect_signals(self) self.builder.connect_signals(Events(self.builder, self.settings))
self.currentPath = "" window = self.settings.createWindow()
window = self.settings.createWindow()
self.usrHome = self.settings.returnUserHome()
self.desktopPath = self.settings.returnDesktopPath()
self.ColumnSize = self.settings.returnColumnSize()
self.desktop = self.builder.get_object("Desktop")
# Add filter to allow only folders to be selected
self.loadProgress = self.builder.get_object("loadProgress")
selectedDirDialog = self.builder.get_object("selectedDirDialog")
filefilter = self.builder.get_object("Folders")
selectedDirDialog.add_filter(filefilter)
selectedDirDialog.set_filename(self.desktopPath)
self.setDir(selectedDirDialog)
self.webview = self.builder.get_object("webview")
self.settings.setDefaultWebviewSettings(self.webview, self.webview.get_settings())
self.webview.load_uri(self.settings.returnWebHome())
window.fullscreen() window.fullscreen()
window.show_all() window.show_all()
def setDir(self, widget, data=None):
self.currentPath = widget.get_filename()
self.getDirectoryList(self.currentPath)
# Thread(target=self.getDirectoryList, args=(self.currentPath,)).start()
def getDirectoryList(self, dir):
dirs = ['.', '..']
files = []
for f in listdir(dir):
file = join(dir, f)
if self.settings.isHideHiddenFiles():
if f.startswith('.'):
continue
if isfile(file):
files.append(f)
else:
dirs.append(f)
dirs.sort()
files.sort()
files = dirs + files
fractionTick = 1.0 / 1.0 if len(files) == 0 else len(files)
tickCount = 0.0
row = 0
col = 0
x = 0
y = 0
self.loadProgress.set_text("Loading...")
self.loadProgress.set_fraction(0.0)
self.clear(self.desktop)
for file in files:
eveBox = Icon().createIcon(dir, file)
# self.drag.connectEvents(self.desktop, eveBox)
eveBox.connect("button_press_event", self.clickManager, (eveBox,))
eveBox.connect("enter_notify_event", self.settings.mouseOver, ())
eveBox.connect("leave_notify_event", self.settings.mouseOut, ())
gobject.idle_add(self.addToGrid, (self.desktop, eveBox, col, row,))
tickCount = tickCount + fractionTick
self.loadProgress.set_fraction(tickCount)
col += 1
if col == self.ColumnSize:
col = 0
row += 1
self.desktop.show_all()
self.loadProgress.set_text("Finished...")
def addToGrid(self, args):
args[0].attach(args[1], args[2], args[3], 1, 1)
def clickManager(self, widget, eve, params):
self.settings.setSelected(params[0])
if eve.type == gdk.EventType.DOUBLE_BUTTON_PRESS:
box = widget.get_children()[0]
children = box.get_children()
fileName = children[1].get_text()
dir = self.currentPath
file = dir + "/" + fileName
if fileName == ".":
self.getDirectoryList(dir)
elif fileName == "..":
parentDir = os.path.abspath(os.path.join(dir, os.pardir))
self.currentPath = parentDir
self.getDirectoryList(parentDir)
elif isdir(file):
self.currentPath = file
self.getDirectoryList(file)
# Thread(target=self.getDirectoryList, args=(file,)).start()
else:
self.filehandler.openFile(file)
elif eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3:
box = widget.get_children()[0]
children = box.get_children()
popover = self.builder.get_object("controlsWindow")
popover.set_relative_to(children[1])
popover.set_position(gtk.PositionType.RIGHT)
popover.show_all()
input = self.builder.get_object("renamerInput")
input.set_text(children[1].get_text())
popover.popup()
def showWebview(self, widget):
self.builder.get_object("webViewer").popup()
def loadHome(self, widget):
self.webview.load_uri(self.settings.returnWebHome())
def runSearchWebview(self, widget, data=None):
if data.keyval == 65293:
self.webview.load_uri(widget.get_text().strip())
def refreshPage(self, widget, data=None):
self.webview.load_uri(self.webview.get_uri())
def setUrlBar(self, widget, data=None):
self.builder.get_object("webviewSearch").set_text(widget.get_uri())
def clear(self, object):
while True:
if object.get_child_at(0,0)!= None:
object.remove_row(0)
else:
break
if __name__ == "__main__": if __name__ == "__main__":
main = Main() main = Main()

View File

@ -8,7 +8,24 @@
<mime-type>inode/directory</mime-type> <mime-type>inode/directory</mime-type>
</mime-types> </mime-types>
</object> </object>
<object class="GtkPopover" id="controlsWindow"> <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>
</packing>
</child>
</object>
<object class="GtkPopover" id="iconControlsWindow">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
@ -16,7 +33,7 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child> <child>
<object class="GtkEntry" id="renamerInput"> <object class="GtkEntry" id="iconRenameInput">
<property name="width_request">300</property> <property name="width_request">300</property>
<property name="height_request">26</property> <property name="height_request">26</property>
<property name="visible">True</property> <property name="visible">True</property>
@ -64,19 +81,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton"> <placeholder/>
<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>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
@ -119,11 +124,12 @@
<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>
<child> <child>
<object class="GtkBox"> <object class="GtkBox" id="box1">
<property name="width_request">256</property> <property name="width_request">256</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -133,7 +139,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkSearchEntry"> <object class="GtkSearchEntry" id="searchentry1">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property> <property name="primary_icon_name">edit-find-symbolic</property>

View File

@ -0,0 +1,60 @@
# Gtk Imports
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk as gdk
# Python imports
import os, threading
from .Grid import Grid
from .Dragging import Dragging
from threading import Thread
gdk.threads_init()
class Events:
def __init__(self, builder, settings):
self.builder = builder
self.settings = settings
self.desktop = self.builder.get_object("Desktop")
self.desktopPath = self.settings.returnDesktopPath()
self.webview = self.builder.get_object("webview")
self.settings.setDefaultWebviewSettings(self.webview, self.webview.get_settings())
self.webview.load_uri(self.settings.returnWebHome())
# Add filter to allow only folders to be selected
selectedDirDialog = self.builder.get_object("selectedDirDialog")
filefilter = self.builder.get_object("Folders")
selectedDirDialog.add_filter(filefilter)
selectedDirDialog.set_filename(self.desktopPath)
self.setDir(selectedDirDialog)
def setDir(self, widget, data=None):
newPath = widget.get_filename()
Thread(target=Grid(self.desktop, self.settings).generateDirectoryGrid, args=(newPath,)).start()
def showGridControlMenu(self, widget, data=None):
popover = self.builder.get_object("gridControlMenu")
popover.show_all()
popover.popup()
def showWebview(self, widget):
self.builder.get_object("webViewer").popup()
def loadHome(self, widget):
self.webview.load_uri(self.settings.returnWebHome())
def runSearchWebview(self, widget, data=None):
if data.keyval == 65293:
self.webview.load_uri(widget.get_text().strip())
def refreshPage(self, widget, data=None):
self.webview.load_uri(self.webview.get_uri())
def setUrlBar(self, widget, data=None):
self.builder.get_object("webviewSearch").set_text(widget.get_uri())

View File

@ -0,0 +1,122 @@
# Gtk Imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
from gi.repository import GObject as gobject
# Python imports
from .Icon import Icon
from .FileHandler import FileHandler
import os, subprocess
from os.path import isdir, isfile, join
from os import listdir
class Grid:
def __init__(self, desktop, settings):
self.desktop = desktop
self.settings = settings
self.filehandler = FileHandler()
self.currentPath = ""
self.builder = self.settings.returnBuilder()
self.ColumnSize = self.settings.returnColumnSize()
def generateDirectoryGrid(self, dirPath):
dirPaths = ['.', '..']
files = []
# self.desktop.connect("button_press_event", self.showGridControlMenu, ())
for f in listdir(dirPath):
file = join(dirPath, f)
if self.settings.isHideHiddenFiles():
if f.startswith('.'):
continue
if isfile(file):
files.append(f)
else:
dirPaths.append(f)
dirPaths.sort()
files.sort()
files = dirPaths + 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)
self.clearGrid(self.desktop)
for file in files:
eveBox = Icon().createIcon(dirPath, file)
# self.drag.connectEvents(self.desktop, eveBox)
eveBox.connect("button_press_event", self.iconClickEventManager, (eveBox,))
eveBox.connect("enter_notify_event", self.settings.mouseOver, ())
eveBox.connect("leave_notify_event", self.settings.mouseOut, ())
gobject.idle_add(self.addToGrid, (self.desktop, eveBox, col, row,))
tickCount = tickCount + fractionTick
loadProgress.set_fraction(tickCount)
col += 1
if col == self.ColumnSize:
col = 0
row += 1
self.desktop.show_all()
loadProgress.set_text("Finished...")
def addToGrid(self, args):
args[0].attach(args[1], args[2], args[3], 1, 1)
def clearGrid(self, object):
while True:
if object.get_child_at(0,0)!= None:
object.remove_row(0)
else:
break
def iconClickEventManager(self, widget, eve, params):
self.settings.setSelected(params[0])
if eve.type == gdk.EventType.DOUBLE_BUTTON_PRESS:
children = widget.get_children()[0].get_children()
fileName = children[1].get_text()
dir = self.currentPath
file = dir + "/" + fileName
if fileName == ".":
self.generateDirectoryGrid(dir)
elif fileName == "..":
parentDir = os.path.abspath(os.path.join(dir, os.pardir))
self.currentPath = parentDir
self.generateDirectoryGrid(parentDir)
elif isdir(file):
self.currentPath = file
Thread(target=self.generateDirectoryGrid, args=(self.currentPath,)).start()
else:
self.filehandler.openFile(file)
elif eve.type == gdk.EventType.BUTTON_PRESS and eve.button == 3:
children = widget.get_children()[0].get_children()
input = self.builder.get_object("iconRenameInput")
popover = self.builder.get_object("iconControlsWindow")
input.set_text(children[1].get_text())
popover.set_relative_to(children[1])
popover.set_position(gtk.PositionType.RIGHT)
popover.show_all()
popover.popup()

View File

@ -14,12 +14,11 @@ from os.path import isdir, isfile, join
class Icon: class Icon:
def __init__(self): def __init__(self):
self.GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1) self.GTK_ORIENTATION = 1 # HORIZONTAL (0) VERTICAL (1)
self.iconImageWxH = [128, -1] self.iconContainerWxH = [128, -1]
self.iconSystem = [72, 72] self.systemIconImageWxH = [72, 72]
self.iconWxH = [128, -1] self.viIconWxH = [128, -1]
self.iconMargins = 8 self.usrHome = os.path.expanduser('~')
self.usrHome = os.path.expanduser('~')
def createIcon(self, dir, file): def createIcon(self, dir, file):
@ -27,17 +26,16 @@ class Icon:
eveBox = gtk.EventBox() eveBox = gtk.EventBox()
icon = gtk.Box() icon = gtk.Box()
label = gtk.Label() label = gtk.Label()
thumbnl = self.defineIconImage(file, fullPathFile) thumbnl = self.getIconImage(file, fullPathFile)
label.set_max_width_chars(1) label.set_max_width_chars(1)
label.set_ellipsize(3) # ELLIPSIZE_END (3) label.set_ellipsize(3) # ELLIPSIZE_END (3)
label.set_lines(2) label.set_lines(2)
label.set_line_wrap(True) label.set_line_wrap(True)
label.set_line_wrap_mode(2) # WRAP_WORD (0) WRAP_CHAR (1) WRAP_WORD_CHAR (2) label.set_line_wrap_mode(2) # WRAP_WORD (0) WRAP_CHAR (1) WRAP_WORD_CHAR (2)
label.set_width_chars(1)
label.set_text(file) label.set_text(file)
icon.set_size_request(self.iconWxH[0], self.iconWxH[1]); icon.set_size_request(self.iconContainerWxH[0], self.iconContainerWxH[1]);
icon.set_property('orientation', self.GTK_ORIENTATION) icon.set_property('orientation', self.GTK_ORIENTATION)
icon.add(thumbnl) icon.add(thumbnl)
icon.add(label) icon.add(label)
@ -46,7 +44,7 @@ class Icon:
eveBox.show_all() eveBox.show_all()
return eveBox return eveBox
def defineIconImage(self, file, fullPathFile): def getIconImage(self, file, fullPathFile):
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')
@ -55,17 +53,33 @@ class Icon:
fileHash = hashlib.sha256(str.encode(fullPathFile)).hexdigest() fileHash = hashlib.sha256(str.encode(fullPathFile)).hexdigest()
hashImgpth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png" hashImgpth = self.usrHome + "/.thumbnails/normal/" + fileHash + ".png"
if isfile(hashImgpth) == False: if isfile(hashImgpth) == False:
self.generateThumbnail(fullPathFile, hashImgpth) self.generateVideoThumbnail(fullPathFile, hashImgpth)
thumbnl = self.createGtkImage(hashImgpth, self.iconImageWxH) thumbnl = self.createIconImageFromBuffer(hashImgpth, self.viIconWxH)
elif file.lower().endswith(imagesList): elif file.lower().endswith(imagesList):
thumbnl = self.createGtkImage(fullPathFile, self.iconImageWxH) thumbnl = self.createIconImageFromBuffer(fullPathFile, self.viIconWxH)
else: else:
thumbPth = self.getSystemThumbnail(fullPathFile, self.iconSystem[0]) thumbPth = self.getSystemThumbnail(fullPathFile, self.systemIconImageWxH[0])
thumbnl = self.createGtkImage(thumbPth, self.iconSystem) thumbnl = self.createIconImageFromBuffer(thumbPth, self.systemIconImageWxH)
return thumbnl return thumbnl
def createIconImageFromBuffer(self, path, wxh):
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
filename = path,
width = wxh[0],
height = wxh[1],
preserve_aspect_ratio = True)
return gtk.Image.new_from_pixbuf(pixbuf)
except Exception as e:
print(e)
return gtk.Image()
def generateVideoThumbnail(self, fullPathFile, hashImgpth):
subprocess.call(["ffmpegthumbnailer", "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPathFile, "-o", hashImgpth])
def getSystemThumbnail(self, filename,size): def getSystemThumbnail(self, filename,size):
final_filename = "" final_filename = ""
if os.path.exists(filename): if os.path.exists(filename):
@ -79,19 +93,3 @@ class Icon:
final_filename = icon_file.get_filename() final_filename = icon_file.get_filename()
return final_filename return final_filename
def generateThumbnail(self, fullPathFile, hashImgpth):
subprocess.call(["ffmpegthumbnailer", "-t", "65%", "-s", "300", "-c", "jpg", "-i", fullPathFile, "-o", hashImgpth])
def createGtkImage(self, path, wxh):
try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
filename = path,
width = wxh[0],
height = wxh[1],
preserve_aspect_ratio = True)
return gtk.Image.new_from_pixbuf(pixbuf)
except Exception as e:
print(e)
return gtk.Image()

View File

@ -62,8 +62,9 @@ class Settings:
return monitors return monitors
def isHideHiddenFiles(self):
return self.hideHiddenFiles def returnBuilder(self):
return self.builder
def returnUserHome(self): def returnUserHome(self):
return self.usrHome return self.usrHome
@ -77,6 +78,9 @@ class Settings:
def returnWebHome(self): def returnWebHome(self):
return self.webHome return self.webHome
def isHideHiddenFiles(self):
return self.hideHiddenFiles
def mouseOver(self, widget, eve, args): def mouseOver(self, widget, eve, args):
hand_cursor = gdk.Cursor(gdk.CursorType.HAND2) hand_cursor = gdk.Cursor(gdk.CursorType.HAND2)
self.builder.get_object("Window").get_window().set_cursor(hand_cursor) self.builder.get_object("Window").get_window().set_cursor(hand_cursor)

View File

@ -1,4 +1,6 @@
from utils.Dragging import Dragging from utils.Dragging import Dragging
from utils.Settings import Settings from utils.Settings import Settings
from utils.Events import Events
from utils.Grid import Grid
from utils.Icon import Icon from utils.Icon import Icon
from utils.FileHandler import FileHandler from utils.FileHandler import FileHandler