Added DnD processing, args loading

This commit is contained in:
itdominator 2023-04-23 16:47:33 -05:00
parent 642f96f9ca
commit a13607174c
11 changed files with 325 additions and 38 deletions

View File

@ -6,8 +6,8 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .left_box import LeftBox
from .right_box import RightBox
class BaseContainer(Gtk.Box):
@ -22,10 +22,11 @@ class BaseContainer(Gtk.Box):
def _setup_styling(self):
self.set_orientation(1)
self.set_orientation(Gtk.Orientation.HORIZONTAL)
def _setup_signals(self):
...
def _load_widgets(self):
...
self.add(LeftBox())
self.add(RightBox())

View File

@ -0,0 +1,34 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.image_list import ImageList
class ImageListScroll(Gtk.ScrolledWindow):
def __init__(self):
super(ImageListScroll, self).__init__()
self._setup_styling()
self._setup_signals()
self._load_widgets()
self.show_all()
def _setup_styling(self):
...
def _setup_signals(self):
...
def _load_widgets(self):
viewport = Gtk.Viewport()
viewport.add(ImageList())
self.add(viewport)

View File

@ -0,0 +1,103 @@
# Python imports
import os
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
# Application imports
from ..widgets.image_view import ImageView
class ImageViewScroll(Gtk.ScrolledWindow):
def __init__(self):
super(ImageViewScroll, self).__init__()
self.fimages = settings.get_images_filter()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
ctx = self.get_style_context()
ctx.add_class("image-view")
self.set_vexpand(True)
self.set_hexpand(True)
def _setup_signals(self):
self._set_up_dnd()
def _load_widgets(self):
viewport = Gtk.Viewport()
viewport.add(ImageView())
self.add(viewport)
def _subscribe_to_events(self):
event_system.subscribe("do_filter_open", self._do_filter_open)
def _set_up_dnd(self):
flags = Gtk.DestDefaults.ALL
URI_TARGET_TYPE = 80
uri_target = Gtk.TargetEntry.new('text/uri-list', Gtk.TargetFlags(0), URI_TARGET_TYPE)
targets = [ uri_target ]
action = Gdk.DragAction.COPY
self.drag_dest_set(flags, targets, action)
self.connect("drag-data-received", self._on_drag_data_received)
def _on_drag_data_received(self, widget, drag_context, _x, _y, data, info, time):
if info == 80:
uris = data.get_uris()
if len(uris) == 0:
uris = data.get_text().split("\n")
self._do_filter_open(uris)
def _do_filter_open(self, uris: [] = []):
path, img_list = self.filter_for_images(uris)
self._handle_open(path, img_list)
def filter_for_images(self, files):
path = files[0].replace("file://", "")
img_list = []
listedDir = False
if len(files) == 1:
if os.path.isdir(path):
listedDir = True
files = os.listdir(path)
if not os.path.isdir(path):
path = os.path.dirname(path)
for file in files:
if file.endswith(self.fimages):
if listedDir:
img_list.append(file)
else:
img_list.append(file.replace("file://", "").replace(f"{path}/", ""))
return path, img_list
def _handle_open(self,path, img_list):
if len(img_list) == 0:
return
if len(img_list) == 1:
img = img_list[0]
target = os.path.join(path, img)
event_system.emit("handle_file_from_dnd", target)
return
event_system.emit("load_image_list", (path, img_list))

View File

@ -0,0 +1,33 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .image_list_scroll import ImageListScroll
class LeftBox(Gtk.Box):
def __init__(self):
super(LeftBox, self).__init__()
self._setup_styling()
self._setup_signals()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_size_request(96, -1)
self.set_vexpand(True)
self.set_orientation(Gtk.Orientation.VERTICAL)
def _setup_signals(self):
...
def _load_widgets(self):
self.add(ImageListScroll())

View File

@ -0,0 +1,35 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
# Application imports
from .image_view_scroll import ImageViewScroll
class RightBox(Gtk.Box):
def __init__(self):
super(RightBox, self).__init__()
self._setup_styling()
self._setup_signals()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_vexpand(True)
self.set_hexpand(True)
self.set_orientation(Gtk.Orientation.VERTICAL)
def _setup_signals(self):
...
def _load_widgets(self):
self.add(ImageViewScroll())

View File

@ -27,17 +27,7 @@ class Controller(SignalsMixins, ControllerData):
if args.no_plugins == "false":
self.plugins.launch_plugins()
for arg in unknownargs + [args.new_tab,]:
if os.path.isfile(arg):
message = f"FILE|{arg}"
event_system.emit("post_file_to_ipc", message)
if os.path.isdir(arg):
message = f"DIR|{arg}"
event_system.emit("post_file_to_ipc", message)
logger.info(f"Made it past {self.__class__} loading...")
event_system.emit("do_filter_open", (unknownargs + [args.new_tab],))
def _setup_styling(self):
...

View File

@ -15,6 +15,8 @@ class IPCSignalsMixin:
def handle_file_from_ipc(self, path: str) -> None:
print(f"File From IPC: {path}")
event_system.emit("do_filter_open", ([path],))
def handle_dir_from_ipc(self, path: str) -> None:
print(f"Dir From IPC: {path}")
event_system.emit("do_filter_open", ([path],))

View File

@ -0,0 +1,43 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class ImageList(Gtk.Box):
def __init__(self):
super(ImageList, self).__init__()
self.path = None
self.img_list = None
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
def _setup_styling(self):
...
def _setup_signals(self):
...
def _subscribe_to_events(self):
event_system.subscribe("load_image_list", self.load_image_list)
def _load_widgets(self):
...
def load_image_list(self, path = None, img_list = []):
if not path or len(img_list) == 0:
return
logger.debug(f"Loading images from: {path}\nList: {img_list}")
self.path = path
self.img_list = img_list

View File

@ -0,0 +1,66 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
# Application imports
class ImageView(Gtk.Image):
def __init__(self):
super(ImageView, self).__init__()
self.pixbuf = None
self.animation = None
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
...
def _setup_signals(self):
...
def _subscribe_to_events(self):
event_system.subscribe("handle_file_from_dnd", self._handle_file_from_dnd)
def _load_widgets(self):
...
def _handle_file_from_dnd(self, path = None):
logger.debug(f"Loading image from: {path}")
self.load_path(path)
if self.animation:
logger.debug("Start animation stub...")
def load_path(self, path):
self.pixbuf = None
self.animation = None
if path.endswith(".gif"):
try:
self.animation = Gtk.Image.new_from_file(path).get_animation()
except Exception:
self.animation = Gtk.Image.new_from_resource(path).get_animation()
return
try:
self.pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
except Exception:
self.pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf()
self.set_from_pixbuf(self.pixbuf)

View File

@ -2,22 +2,10 @@
"keybindings": {
"help" : "F1",
"rename_files" : ["F2", "<Control>e"],
"open_terminal" : "F4",
"refresh_tab" : ["F5", "<Control>r"],
"delete_files" : "Delete",
"tggl_top_main_menubar" : "Alt_L",
"trash_files" : "<Shift><Control>t",
"tear_down" : "<Control>q",
"go_up" : "<Control>Up",
"go_home" : "<Control>slash",
"grab_focus_path_entry" : "<Control>l",
"open_files" : "<Control>o",
"show_hide_hidden_files" : "<Control>h",
"keyboard_create_tab" : "<Control>t",
"keyboard_close_tab" : "<Control>w",
"keyboard_copy_files" : "<Control>c",
"keyboard_cut_files" : "<Control>x",
"paste_files" : "<Control>v",
"show_new_file_menu" : "<Control>n"
"paste_files" : "<Control>v"
}
}

View File

@ -1,12 +1,6 @@
{
"config": {
"base_of_home": "",
"hide_hidden_files": "true",
"thumbnailer_path": "ffmpegthumbnailer",
"go_past_home": "true",
"lock_folder": "false",
"locked_folders": "venv::::flasks",
"mplayer_options": "-quiet -really-quiet -xy 1600 -geometry 50%:50%",
"music_app": "/opt/deadbeef/bin/deadbeef",
"media_app": "mpv",
"image_app": "mirage",
@ -14,11 +8,10 @@
"pdf_app": "evince",
"text_app": "leafpad",
"file_manager_app": "solarfm",
"terminal_app": "terminator",
"remux_folder_max_disk_usage": "8589934592"
"terminal_app": "terminator"
},
"filters": {
"meshs": [".blend", ".dae", ".fbx", ".gltf", ".obj", ".stl"],
"meshs": [".dae", ".fbx", ".gltf", ".obj", ".stl"],
"code": [".cpp", ".css", ".c", ".go", ".html", ".htm", ".java", ".js", ".json", ".lua", ".md", ".py", ".rs", ".toml", ".xml", ".pom"],
"videos": [".mkv", ".mp4", ".webm", ".avi", ".mov", ".m4v", ".mpg", ".mpeg", ".wmv", ".flv"],
"office": [".doc", ".docx", ".xls", ".xlsx", ".xlt", ".xltx", ".xlm", ".ppt", ".pptx", ".pps", ".ppsx", ".odt", ".rtf"],
@ -26,7 +19,6 @@
"text": [".txt", ".text", ".sh", ".cfg", ".conf", ".log"],
"music": [".psf", ".mp3", ".ogg", ".flac", ".m4a"],
"pdf": [".pdf"]
},
"theming":{
"success_color":"#88cc27",