Refactor plus fixed thumbnail generation crashing stuff
This commit is contained in:
parent
00c207a153
commit
3825892405
@ -19,15 +19,16 @@ from . import Path
|
||||
class View(Settings, FileHandler, Launcher, Icon, Path):
|
||||
def __init__(self):
|
||||
self. logger = None
|
||||
self.id_length = 10
|
||||
self.id_length = 10
|
||||
|
||||
self.id = ""
|
||||
self.files = []
|
||||
self.dirs = []
|
||||
self.vids = []
|
||||
self.images = []
|
||||
self.desktop = []
|
||||
self.ungrouped = []
|
||||
self.id = ""
|
||||
self.hide_hidden = self.HIDE_HIDDEN_FILES
|
||||
self.files = []
|
||||
self.dirs = []
|
||||
self.vids = []
|
||||
self.images = []
|
||||
self.desktop = []
|
||||
self.ungrouped = []
|
||||
|
||||
self.generate_id()
|
||||
self.set_to_home()
|
||||
@ -59,7 +60,7 @@ class View(Settings, FileHandler, Launcher, Icon, Path):
|
||||
|
||||
for f in listdir(path):
|
||||
file = join(path, f)
|
||||
if self.HIDE_HIDDEN_FILES:
|
||||
if self.hide_hidden:
|
||||
if f.startswith('.'):
|
||||
continue
|
||||
|
||||
|
@ -6,7 +6,8 @@ from os.path import isfile
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
|
||||
from gi.repository import Gtk
|
||||
# from gi.repository import Gtk
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
# Application imports
|
||||
from .mixins import *
|
||||
@ -34,17 +35,10 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
||||
thumbnl = self.create_scaled_image(full_path, self.VIDEO_ICON_WH)
|
||||
elif full_path.lower().endswith( ('.desktop',) ): # .desktop file parsing
|
||||
thumbnl = self.parse_desktop_files(full_path)
|
||||
else: # System icons
|
||||
thumbnl = self.get_system_thumbnail(full_path, self.SYS_ICON_WH[0])
|
||||
|
||||
if thumbnl == None: # If no icon whatsoever, return internal default
|
||||
thumbnl = Gtk.Image.new_from_file(self.DEFAULT_ICON)
|
||||
|
||||
return thumbnl
|
||||
except Exception as e:
|
||||
print("Icon generation issue:")
|
||||
print( repr(e) )
|
||||
return Gtk.Image.new_from_file(self.DEFAULT_ICON)
|
||||
return None
|
||||
|
||||
def create_thumbnail(self, dir, file):
|
||||
full_path = dir + "/" + file
|
||||
@ -56,20 +50,20 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
||||
|
||||
thumbnl = self.create_scaled_image(hash_img_pth, self.VIDEO_ICON_WH)
|
||||
if thumbnl == None: # If no icon whatsoever, return internal default
|
||||
thumbnl = Gtk.Image.new_from_file(self.DEFAULT_ICONS + "/video.png")
|
||||
thumbnl = GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICONS + "/video.png")
|
||||
|
||||
return thumbnl
|
||||
except Exception as e:
|
||||
print("Thumbnail generation issue:")
|
||||
print( repr(e) )
|
||||
return Gtk.Image.new_from_file(self.DEFAULT_ICONS + "/video.png")
|
||||
return GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICONS + "/video.png")
|
||||
|
||||
|
||||
def create_scaled_image(self, path, wxh):
|
||||
try:
|
||||
pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)#.get_pixbuf()
|
||||
scaled_pixbuf = pixbuf.scale_simple(wxh[0], wxh[1], 2) # 2 = BILINEAR and is best by default
|
||||
return Gtk.Image.new_from_pixbuf(scaled_pixbuf)
|
||||
return scaled_pixbuf # Gtk.Image.new_from_pixbuf(scaled_pixbuf)
|
||||
except Exception as e:
|
||||
print("Image Scaling Issue:")
|
||||
print( repr(e) )
|
||||
@ -77,11 +71,11 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
||||
|
||||
def create_from_file(self, path):
|
||||
try:
|
||||
return Gtk.Image.new_from_file(path)
|
||||
return GdkPixbuf.Pixbuf.new_from_file(path)
|
||||
except Exception as e:
|
||||
print("Image from file Issue:")
|
||||
print( repr(e) )
|
||||
return None
|
||||
|
||||
def return_generic_icon(self):
|
||||
return Gtk.Image.new_from_file(self.DEFAULT_ICON)
|
||||
return GdkPixbuf.Pixbuf.new_from_file(self.DEFAULT_ICON)
|
||||
|
@ -5,8 +5,6 @@ from os.path import isfile
|
||||
# Gtk imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
|
||||
from gi.repository import Gio
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
@ -14,26 +12,6 @@ from .xdg.DesktopEntry import DesktopEntry
|
||||
|
||||
|
||||
class DesktopIconMixin:
|
||||
def get_system_thumbnail(self, filename, size):
|
||||
try:
|
||||
if os.path.exists(filename):
|
||||
gioFile = Gio.File.new_for_path(filename)
|
||||
info = gioFile.query_info('standard::icon' , 0, Gio.Cancellable())
|
||||
icon = info.get_icon().get_names()[0]
|
||||
iconTheme = Gtk.IconTheme.get_default()
|
||||
iconData = iconTheme.lookup_icon(icon , size , 0)
|
||||
if iconData:
|
||||
iconPath = iconData.get_filename()
|
||||
return Gtk.Image.new_from_file(iconPath)
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
except Exception as e:
|
||||
print("system icon generation issue:")
|
||||
print( repr(e) )
|
||||
return None
|
||||
|
||||
def parse_desktop_files(self, full_path):
|
||||
try:
|
||||
xdgObj = DesktopEntry(full_path)
|
||||
|
@ -40,7 +40,6 @@ class Signals(WindowMixin, PaneMixin):
|
||||
self.is_pane2_hidden = False
|
||||
self.is_pane3_hidden = False
|
||||
self.is_pane4_hidden = False
|
||||
self.refresh_lock = False
|
||||
|
||||
self.window.show()
|
||||
self.generate_windows(self.state)
|
||||
|
@ -1,11 +1,6 @@
|
||||
# Python imports
|
||||
import copy
|
||||
from os.path import isdir, isfile
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
from gi.repository import Gdk
|
||||
|
||||
# Application imports
|
||||
from . import WidgetMixin
|
||||
@ -14,9 +9,6 @@ from . import WidgetMixin
|
||||
class TabMixin(WidgetMixin):
|
||||
"""docstring for TabMixin"""
|
||||
|
||||
def get_fm_window(self, wid):
|
||||
return self.window_controller.get_window_by_nickname(f"window_{wid}")
|
||||
|
||||
def create_tab(self, wid, path=None):
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
path_entry = self.builder.get_object(f"path_entry")
|
||||
@ -50,127 +42,19 @@ class TabMixin(WidgetMixin):
|
||||
self.window_controller.save_state()
|
||||
self.set_window_title()
|
||||
|
||||
def set_window_title(self):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
dir = view.get_current_directory()
|
||||
self.window.set_title(dir)
|
||||
|
||||
def grid_icon_single_click(self, widget, eve):
|
||||
try:
|
||||
wid, tid = widget.get_name().split("|")
|
||||
self.window_controller.set_active_data(wid, tid)
|
||||
|
||||
if eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 1: # l-click
|
||||
self.set_path_text(wid, tid)
|
||||
self.set_window_title()
|
||||
|
||||
if self.single_click_open: # FIXME: need to find a way to pass the model index
|
||||
self.icon_double_left_click(widget)
|
||||
elif eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 3: # r-click
|
||||
pass
|
||||
# input = self.builder.get_object("filenameInput")
|
||||
# controls = self.builder.get_object("iconControlsWindow")
|
||||
# iconsButtonBox = self.builder.get_object("iconsButtonBox")
|
||||
# menuButtonBox = self.builder.get_object("menuButtonBox")
|
||||
#
|
||||
#
|
||||
# if len(self.selectedFiles) == 1:
|
||||
# parts = self.selectedFiles[0].split("/")
|
||||
# input.set_text(parts[len(parts) - 1])
|
||||
# input.show()
|
||||
# iconsButtonBox.show()
|
||||
# menuButtonBox.hide()
|
||||
# controls.show()
|
||||
# elif len(self.selectedFiles) > 1:
|
||||
# input.set_text("")
|
||||
# input.hide()
|
||||
# menuButtonBox.hide()
|
||||
# iconsButtonBox.show()
|
||||
# controls.show()
|
||||
# else:
|
||||
# input.set_text("")
|
||||
# input.show()
|
||||
# menuButtonBox.show()
|
||||
# iconsButtonBox.hide()
|
||||
# controls.show()
|
||||
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
|
||||
def grid_icon_double_left_click(self, widget, item):
|
||||
try:
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
path_entry = self.builder.get_object(f"path_entry")
|
||||
tab_label = self.get_tab_label_widget_from_widget(notebook, widget)
|
||||
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
model = widget.get_model()
|
||||
|
||||
fileName = model[item][1]
|
||||
dir = view.get_current_directory()
|
||||
file = dir + "/" + fileName
|
||||
refresh = True
|
||||
|
||||
if isdir(file):
|
||||
view.set_path(file)
|
||||
elif isfile(file):
|
||||
refresh = False
|
||||
view.open_file_locally(file)
|
||||
|
||||
if refresh == True:
|
||||
self.load_store(view, model)
|
||||
tab_label.set_label(view.get_end_of_path())
|
||||
path_entry.set_text(view.get_current_directory())
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
|
||||
def grid_on_drag_set(self, widget, drag_context, data, info, time):
|
||||
action = widget.get_name()
|
||||
store = widget.get_model()
|
||||
treePaths = widget.get_selected_items()
|
||||
wid, tid = action.split("|")
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
dir = view.get_current_directory()
|
||||
uris = []
|
||||
|
||||
for path in treePaths:
|
||||
itr = store.get_iter(path)
|
||||
file = store.get(itr, 1)[0]
|
||||
fpath = f"file://{dir}/{file}"
|
||||
uris.append(fpath)
|
||||
|
||||
data.set_uris(uris)
|
||||
event_system.push_gui_event(["refresh_tab", None, action])
|
||||
|
||||
def grid_on_drag_motion(self, widget, drag_context, x, y, data):
|
||||
wid, tid = widget.get_name().split("|")
|
||||
def on_tab_switch_update(self, notebook, content=None, index=None):
|
||||
wid, tid = content.get_children()[0].get_name().split("|")
|
||||
self.window_controller.set_active_data(wid, tid)
|
||||
self.set_path_text(wid, tid)
|
||||
self.set_window_title()
|
||||
|
||||
def grid_on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
|
||||
if info == 80:
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
icon_view, tab_label = self.get_icon_view_and_label_from_notebook(notebook, f"{wid}|{tid}")
|
||||
def get_tab_id_from_widget(self, tab_box):
|
||||
tid = tab_box.get_children()[2]
|
||||
return tid.get_text()
|
||||
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
store = icon_view.get_model()
|
||||
uris = data.get_uris()
|
||||
dest = view.get_current_directory()
|
||||
def get_tab_label_widget_from_widget(self, notebook, widget):
|
||||
return notebook.get_tab_label(widget.get_parent()).get_children()[0]
|
||||
|
||||
print(f"{wid}|{tid}")
|
||||
if len(uris) > 0:
|
||||
print(f"Target Move Path: {dest}")
|
||||
self.refresh_lock = True
|
||||
for uri in uris:
|
||||
print(f"URI: {uri}")
|
||||
self.move_file(view, uri, dest)
|
||||
|
||||
# Reloads new directory
|
||||
view.load_directory()
|
||||
self.load_store(view, store)
|
||||
self.refresh_lock = False
|
||||
|
||||
def do_action_from_bar_controls(self, widget, eve=None):
|
||||
action = widget.get_name()
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Python imports
|
||||
import threading, subprocess
|
||||
import os, threading, subprocess
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
@ -9,6 +9,7 @@ gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import Gio
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
# Application imports
|
||||
@ -27,30 +28,55 @@ class WidgetMixin:
|
||||
store.clear()
|
||||
dir = view.get_current_directory()
|
||||
files = view.get_files()
|
||||
|
||||
icon = GdkPixbuf.Pixbuf.new_from_file(view.DEFAULT_ICON)
|
||||
for i, file in enumerate(files):
|
||||
generic_icon = Gtk.Image.new_from_file(view.DEFAULT_ICON).get_pixbuf()
|
||||
store.append([generic_icon, file[0]])
|
||||
store.append([icon, file[0]])
|
||||
self.create_icon(i, view, store, dir, file[0])
|
||||
|
||||
# Not likely called often here but could be useful
|
||||
# NOTE: Not likely called often from here but it could be useful
|
||||
if save_state:
|
||||
self.window_controller.save_state()
|
||||
|
||||
@threaded
|
||||
def create_icon(self, i, view, store, dir, file):
|
||||
icon = None
|
||||
try:
|
||||
icon = view.create_icon(dir, file).get_pixbuf()
|
||||
except Exception as e:
|
||||
return
|
||||
GLib.idle_add(self.update_store, (i, store, icon,))
|
||||
icon = view.create_icon(dir, file)
|
||||
fpath = dir + "/" + file
|
||||
GLib.idle_add(self.update_store, (i, store, icon, view, fpath,))
|
||||
|
||||
def update_store(self, item):
|
||||
i, store, icon = item
|
||||
i, store, icon, view, fpath = item
|
||||
itr = store.get_iter(i)
|
||||
|
||||
if not icon:
|
||||
icon = self.get_system_thumbnail(fpath, view.SYS_ICON_WH[0])
|
||||
if not icon:
|
||||
icon = GdkPixbuf.Pixbuf.new_from_file(view.DEFAULT_ICON)
|
||||
|
||||
store.set_value(itr, 0, icon)
|
||||
|
||||
|
||||
def get_system_thumbnail(self, filename, size):
|
||||
try:
|
||||
if os.path.exists(filename):
|
||||
gioFile = Gio.File.new_for_path(filename)
|
||||
info = gioFile.query_info('standard::icon' , 0, Gio.Cancellable())
|
||||
icon = info.get_icon().get_names()[0]
|
||||
iconTheme = Gtk.IconTheme.get_default()
|
||||
iconData = iconTheme.lookup_icon(icon , size , 0)
|
||||
if iconData:
|
||||
iconPath = iconData.get_filename()
|
||||
return GdkPixbuf.Pixbuf.new_from_file(iconPath)
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
except Exception as e:
|
||||
print("System icon generation issue:")
|
||||
print( repr(e) )
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
def create_tab_widget(self, view):
|
||||
@ -148,26 +174,6 @@ class WidgetMixin:
|
||||
return scroll, store
|
||||
|
||||
|
||||
|
||||
|
||||
def on_tab_switch_update(self, notebook, content=None, index=None):
|
||||
wid, tid = content.get_children()[0].get_name().split("|")
|
||||
self.window_controller.set_active_data(wid, tid)
|
||||
self.set_path_text(wid, tid)
|
||||
self.set_window_title()
|
||||
|
||||
def set_path_text(self, wid, tid):
|
||||
path_entry = self.builder.get_object("path_entry")
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
path_entry.set_text(view.get_current_directory())
|
||||
|
||||
def get_tab_id_from_widget(self, tab_box):
|
||||
tid = tab_box.get_children()[2]
|
||||
return tid.get_text()
|
||||
|
||||
def get_tab_label_widget_from_widget(self, notebook, widget):
|
||||
return notebook.get_tab_label(widget.get_parent()).get_children()[0]
|
||||
|
||||
def get_icon_view_and_label_from_notebook(self, notebook, _name):
|
||||
icon_view = None
|
||||
tab_label = None
|
||||
|
@ -1,8 +1,148 @@
|
||||
# Python imports
|
||||
import copy
|
||||
from os.path import isdir, isfile
|
||||
|
||||
|
||||
# Lib imports
|
||||
from . import TabMixin
|
||||
|
||||
import gi
|
||||
|
||||
from gi.repository import Gdk
|
||||
|
||||
# Application imports
|
||||
from . import WidgetMixin
|
||||
|
||||
|
||||
|
||||
class WindowMixin(TabMixin):
|
||||
"""docstring for WindowMixin"""
|
||||
def get_fm_window(self, wid):
|
||||
return self.window_controller.get_window_by_nickname(f"window_{wid}")
|
||||
|
||||
def set_window_title(self):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
dir = view.get_current_directory()
|
||||
self.window.set_title(dir)
|
||||
|
||||
def set_path_text(self, wid, tid):
|
||||
path_entry = self.builder.get_object("path_entry")
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
path_entry.set_text(view.get_current_directory())
|
||||
|
||||
def grid_icon_single_click(self, widget, eve):
|
||||
try:
|
||||
wid, tid = widget.get_name().split("|")
|
||||
self.window_controller.set_active_data(wid, tid)
|
||||
|
||||
if eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 1: # l-click
|
||||
self.set_path_text(wid, tid)
|
||||
self.set_window_title()
|
||||
|
||||
if self.single_click_open: # FIXME: need to find a way to pass the model index
|
||||
self.grid_icon_double_left_click(widget)
|
||||
elif eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 3: # r-click
|
||||
pass
|
||||
# input = self.builder.get_object("filenameInput")
|
||||
# controls = self.builder.get_object("iconControlsWindow")
|
||||
# iconsButtonBox = self.builder.get_object("iconsButtonBox")
|
||||
# menuButtonBox = self.builder.get_object("menuButtonBox")
|
||||
#
|
||||
#
|
||||
# if len(self.selectedFiles) == 1:
|
||||
# parts = self.selectedFiles[0].split("/")
|
||||
# input.set_text(parts[len(parts) - 1])
|
||||
# input.show()
|
||||
# iconsButtonBox.show()
|
||||
# menuButtonBox.hide()
|
||||
# controls.show()
|
||||
# elif len(self.selectedFiles) > 1:
|
||||
# input.set_text("")
|
||||
# input.hide()
|
||||
# menuButtonBox.hide()
|
||||
# iconsButtonBox.show()
|
||||
# controls.show()
|
||||
# else:
|
||||
# input.set_text("")
|
||||
# input.show()
|
||||
# menuButtonBox.show()
|
||||
# iconsButtonBox.hide()
|
||||
# controls.show()
|
||||
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
|
||||
def grid_icon_double_left_click(self, widget, item):
|
||||
try:
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
path_entry = self.builder.get_object(f"path_entry")
|
||||
tab_label = self.get_tab_label_widget_from_widget(notebook, widget)
|
||||
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
model = widget.get_model()
|
||||
|
||||
fileName = model[item][1]
|
||||
dir = view.get_current_directory()
|
||||
file = dir + "/" + fileName
|
||||
refresh = True
|
||||
|
||||
if isdir(file):
|
||||
view.set_path(file)
|
||||
elif isfile(file):
|
||||
refresh = False
|
||||
view.open_file_locally(file)
|
||||
|
||||
if refresh == True:
|
||||
self.load_store(view, model)
|
||||
tab_label.set_label(view.get_end_of_path())
|
||||
path_entry.set_text(view.get_current_directory())
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
|
||||
def grid_on_drag_set(self, widget, drag_context, data, info, time):
|
||||
action = widget.get_name()
|
||||
store = widget.get_model()
|
||||
treePaths = widget.get_selected_items()
|
||||
wid, tid = action.split("|")
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
dir = view.get_current_directory()
|
||||
uris = []
|
||||
|
||||
for path in treePaths:
|
||||
itr = store.get_iter(path)
|
||||
file = store.get(itr, 1)[0]
|
||||
fpath = f"file://{dir}/{file}"
|
||||
uris.append(fpath)
|
||||
|
||||
data.set_uris(uris)
|
||||
event_system.push_gui_event(["refresh_tab", None, action])
|
||||
|
||||
def grid_on_drag_motion(self, widget, drag_context, x, y, data):
|
||||
wid, tid = widget.get_name().split("|")
|
||||
self.window_controller.set_active_data(wid, tid)
|
||||
|
||||
def grid_on_drag_data_received(self, widget, drag_context, x, y, data, info, time):
|
||||
if info == 80:
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
notebook = self.builder.get_object(f"window_{wid}")
|
||||
icon_view, tab_label = self.get_icon_view_and_label_from_notebook(notebook, f"{wid}|{tid}")
|
||||
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
store = icon_view.get_model()
|
||||
uris = data.get_uris()
|
||||
dest = view.get_current_directory()
|
||||
|
||||
if len(uris) > 0:
|
||||
print(f"Target Move Path: {dest}")
|
||||
for uri in uris:
|
||||
print(f"URI: {uri}")
|
||||
self.move_file(view, uri, dest)
|
||||
|
||||
# Reloads new directory
|
||||
view.load_directory()
|
||||
self.load_store(view, store)
|
||||
|
||||
def create_new_view_notebook(self, widget=None, wid=None, path=None):
|
||||
self.create_tab(wid, path)
|
||||
|
Loading…
Reference in New Issue
Block a user