WIP Most functionality added

This commit is contained in:
itdominator 2023-04-23 21:18:35 -05:00
parent a13607174c
commit 19ae2974c3
12 changed files with 179 additions and 16 deletions

View File

@ -33,8 +33,7 @@ if __name__ == "__main__":
parser.add_argument("--debug", "-d", default="false", help="Do extra console messaging.")
parser.add_argument("--trace-debug", "-td", default="false", help="Disable saves, ignore IPC lock, do extra console messaging.")
parser.add_argument("--no-plugins", "-np", default="false", help="Do not load plugins.")
parser.add_argument("--new-tab", "-nt", default="false", help="Opens a 'New Tab' if a handler is set for it.")
parser.add_argument("--file", "-f", default="default", help="JUST SOME FILE ARG.")
parser.add_argument("--file", "-f", default=None, help="Pass an Image file directly.")
# Read arguments (If any...)
args, unknownargs = parser.parse_known_args()

View File

@ -8,6 +8,7 @@ from gi.repository import Gtk
# Application imports
from .left_box import LeftBox
from .right_box import RightBox
from ..widgets.path_label import PathLabel
class BaseContainer(Gtk.Box):
@ -22,11 +23,17 @@ class BaseContainer(Gtk.Box):
def _setup_styling(self):
self.set_orientation(Gtk.Orientation.HORIZONTAL)
self.set_orientation(Gtk.Orientation.VERTICAL)
def _setup_signals(self):
...
def _load_widgets(self):
self.add(LeftBox())
self.add(RightBox())
box = Gtk.Box()
box.set_orientation(Gtk.Orientation.HORIZONTAL)
box.add(LeftBox())
box.add(RightBox())
self.add(PathLabel())
self.add(box)

View File

@ -22,8 +22,7 @@ class ImageListScroll(Gtk.ScrolledWindow):
def _setup_styling(self):
...
self.set_vexpand(True)
def _setup_signals(self):
...

View File

@ -22,9 +22,9 @@ class LeftBox(Gtk.Box):
def _setup_styling(self):
self.set_size_request(96, -1)
self.set_vexpand(True)
self.set_orientation(Gtk.Orientation.VERTICAL)
self.set_size_request(settings.get_thumbnail_with(), -1)
self.set_vexpand(True)
def _setup_signals(self):
...

View File

@ -27,7 +27,8 @@ class Controller(SignalsMixins, ControllerData):
if args.no_plugins == "false":
self.plugins.launch_plugins()
event_system.emit("do_filter_open", (unknownargs + [args.new_tab],))
collection = unknownargs + [args.file] if args.file and os.path.isfile(args.file) else unknownargs
event_system.emit("do_filter_open", (collection,))
def _setup_styling(self):
...

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 Image(Gtk.EventBox):
def __init__(self, path = None):
super(Image, self).__init__()
self.image = None
self.path = path
self._setup_styling()
self._setup_signals()
self._load_widgets()
def _setup_styling(self):
...
def _setup_signals(self):
self.connect("button-release-event", self.set_image_to_view)
def _subscribe_to_events(self):
...
def _load_widgets(self):
self.image = Gtk.Image()
self.image.show()
self.add(self.image)
def set_from_pixbuf(self, pixbuf):
self.image.set_from_pixbuf(pixbuf)
def set_image_to_view(self, widget = None, eve = None):
if eve.button == 1:
event_system.emit("handle_file_from_dnd", (self.path, ))

View File

@ -1,4 +1,5 @@
# Python imports
import os
# Lib imports
import gi
@ -6,15 +7,17 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.image import Image
class ImageList(Gtk.Box):
def __init__(self):
super(ImageList, self).__init__()
self.path = None
self.img_list = None
self.path = None
self.img_list = None
self._thumbnail_with = settings.get_thumbnail_with()
self._thumbnail_height = settings.get_thumbnail_height()
self._setup_styling()
self._setup_signals()
@ -23,7 +26,8 @@ class ImageList(Gtk.Box):
def _setup_styling(self):
...
self.set_orientation(Gtk.Orientation.VERTICAL)
self.set_spacing(15)
def _setup_signals(self):
...
@ -34,10 +38,67 @@ class ImageList(Gtk.Box):
def _load_widgets(self):
...
def load_image_list(self, path = None, img_list = []):
def _clear_children(self, widget: type) -> None:
''' Clear children of a gtk widget. '''
for child in widget.get_children():
widget.remove(child)
def _marshal_paths(self):
paths = []
for img in self.img_list:
path = os.path.join(self.path, img)
paths.append(path)
return paths
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
paths = self._marshal_paths()
self._clear_children(self)
for file in paths:
self.add( Image(file) )
self.pre_fill_gtkimgs(paths)
def pre_fill_gtkimgs(self, paths: [] = []):
children = self.get_children()
for i, path in enumerate(paths):
self.load_pixbuf_to_target(path, children[i])
self.show_range()
@daemon_threaded
def load_pixbuf_to_target(self, path, child):
pixbuf = self.get_pixbuf_data(path, self._thumbnail_with, self._thumbnail_height)
child.set_from_pixbuf(pixbuf)
def get_pixbuf_data(self, path, w = 126, h = 126):
pixbuf = None
try:
pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
except Exception:
pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf()
return pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
def show_range(self, i = 0, j = 9):
children = self.get_children()
if len(children) <= j:
j = len(children) - 1
while i <= j:
self.show_at_index(children[i])
i += 1
def show_at_index(self, child = None):
if not child:
return
child.show()

View File

@ -64,3 +64,4 @@ class ImageView(Gtk.Image):
self.pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf()
self.set_from_pixbuf(self.pixbuf)
event_system.emit("update_path_label", (path,))

View File

@ -0,0 +1,46 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class PathLabel(Gtk.Label):
def __init__(self):
super(PathLabel, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_line_wrap(False)
self.set_ellipsize(1) # NONE = 0¶, START = 1¶, MIDDLE = 2¶, END = 3¶
def _setup_signals(self):
self.set_margin_left(25)
self.set_margin_right(25)
self.set_margin_top(5)
self.set_margin_bottom(10)
def _subscribe_to_events(self):
event_system.subscribe("update_path_label", self.update_path_label)
def _load_widgets(self):
...
def update_path_label(self, path = None):
if not path:
return
self.set_label(path)
self.set_tooltip_text(path)

View File

@ -41,6 +41,7 @@ class Window(Gtk.ApplicationWindow):
def _setup_styling(self):
self.set_size_request(720, 480)
self.set_default_size(settings.get_main_window_width(),
settings.get_main_window_height())
self.set_title(f"{app_name}")

View File

@ -143,6 +143,9 @@ class Settings(StartCheckMixin, Singleton):
def get_window_icon(self) -> str: return self._WINDOW_ICON
def get_home_path(self) -> str: return self._USER_HOME
def get_thumbnail_with(self) -> int: return self._config["thumbnail_with"]
def get_thumbnail_height(self) -> int: return self._config["thumbnail_height"]
# Filter returns
def get_office_filter(self) -> tuple: return tuple(self._settings["filters"]["office"])
def get_vids_filter(self) -> tuple: return tuple(self._settings["filters"]["videos"])

View File

@ -8,7 +8,9 @@
"pdf_app": "evince",
"text_app": "leafpad",
"file_manager_app": "solarfm",
"terminal_app": "terminator"
"terminal_app": "terminator",
"thumbnail_with": 256,
"thumbnail_height": 256
},
"filters": {
"meshs": [".dae", ".fbx", ".gltf", ".obj", ".stl"],