Added DnD processing, args loading
This commit is contained in:
@@ -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())
|
||||
|
34
src/new-src/core/containers/image_list_scroll.py
Normal file
34
src/new-src/core/containers/image_list_scroll.py
Normal 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)
|
103
src/new-src/core/containers/image_view_scroll.py
Normal file
103
src/new-src/core/containers/image_view_scroll.py
Normal 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))
|
33
src/new-src/core/containers/left_box.py
Normal file
33
src/new-src/core/containers/left_box.py
Normal 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())
|
35
src/new-src/core/containers/right_box.py
Normal file
35
src/new-src/core/containers/right_box.py
Normal 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())
|
@@ -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):
|
||||
...
|
||||
|
@@ -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],))
|
||||
|
43
src/new-src/core/widgets/image_list.py
Normal file
43
src/new-src/core/widgets/image_list.py
Normal 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
|
66
src/new-src/core/widgets/image_view.py
Normal file
66
src/new-src/core/widgets/image_view.py
Normal 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)
|
Reference in New Issue
Block a user