Cleared out old files
This commit is contained in:
3
src/core/widgets/__init__.py
Normal file
3
src/core/widgets/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Widgets Module
|
||||
"""
|
||||
134
src/core/widgets/button_controls.py
Normal file
134
src/core/widgets/button_controls.py
Normal file
@@ -0,0 +1,134 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class ButtonControls(Gtk.ButtonBox):
|
||||
def __init__(self):
|
||||
super(ButtonControls, self).__init__()
|
||||
|
||||
self.one2one_button = None
|
||||
self.fit_button = None
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
icons_path = settings.get_icons_path()
|
||||
center_widget = Gtk.ButtonBox()
|
||||
zoomout_button = Gtk.Button()
|
||||
lrotate_button = Gtk.Button()
|
||||
vflip_button = Gtk.Button()
|
||||
# NOTE: Toggle Buttons are acting broken for me so workaround ith regular buttons
|
||||
self.one2one_button = Gtk.Button()
|
||||
self.fit_button = Gtk.Button()
|
||||
hflip_button = Gtk.Button()
|
||||
rrotate_button = Gtk.Button()
|
||||
zoomin_button = Gtk.Button()
|
||||
|
||||
# TODO: add if check against settings pull to set 1:1 or fit
|
||||
self._set_class(self.one2one_button)
|
||||
# self._set_class(self.fit_button)
|
||||
|
||||
zoomout_button.set_tooltip_text("Zoom Out")
|
||||
lrotate_button.set_tooltip_text("Rotate Left")
|
||||
vflip_button.set_tooltip_text("Flip Vertical")
|
||||
self.one2one_button.set_tooltip_text("Zoom 1:1")
|
||||
self.fit_button.set_tooltip_text("Zoom Fit")
|
||||
hflip_button.set_tooltip_text("Flip Horizontal")
|
||||
rrotate_button.set_tooltip_text("Rotate Right")
|
||||
zoomin_button.set_tooltip_text("Zoom In")
|
||||
|
||||
zoomout_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-out.png") )
|
||||
lrotate_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/rotate-left.png") )
|
||||
vflip_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/flip-virtical.png") )
|
||||
self.one2one_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-original.png") )
|
||||
self.fit_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-fit.png") )
|
||||
hflip_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/flip-horizontal.png") )
|
||||
rrotate_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/rotate-right.png") )
|
||||
zoomin_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-in.png") )
|
||||
|
||||
zoomout_button.set_always_show_image(True)
|
||||
lrotate_button.set_always_show_image(True)
|
||||
vflip_button.set_always_show_image(True)
|
||||
self.one2one_button.set_always_show_image(True)
|
||||
self.fit_button.set_always_show_image(True)
|
||||
hflip_button.set_always_show_image(True)
|
||||
rrotate_button.set_always_show_image(True)
|
||||
zoomin_button.set_always_show_image(True)
|
||||
|
||||
zoomout_button.connect("clicked", self._zoom_out)
|
||||
lrotate_button.connect("clicked", self._rotate_left)
|
||||
vflip_button.connect("clicked", self._vertical_flip)
|
||||
self.one2one_button.connect("button-release-event", self._scale_1_two_1)
|
||||
self.fit_button.connect("button-release-event", self._fit_to_container)
|
||||
hflip_button.connect("clicked", self._horizontal_flip)
|
||||
rrotate_button.connect("clicked", self._rotate_right)
|
||||
zoomin_button.connect("clicked", self._zoom_in)
|
||||
|
||||
center_widget.add(zoomout_button)
|
||||
center_widget.add(lrotate_button)
|
||||
center_widget.add(vflip_button)
|
||||
center_widget.add(self.one2one_button)
|
||||
center_widget.add(self.fit_button)
|
||||
center_widget.add(hflip_button)
|
||||
center_widget.add(rrotate_button)
|
||||
center_widget.add(zoomin_button)
|
||||
|
||||
self.set_center_widget(center_widget)
|
||||
|
||||
def _zoom_out(self, widget = None, eve = None):
|
||||
event_system.emit("zoom_out")
|
||||
|
||||
def _rotate_left(self, widget = None, eve = None):
|
||||
event_system.emit("rotate_left")
|
||||
|
||||
def _vertical_flip(self, widget = None, eve = None):
|
||||
event_system.emit("vertical_flip")
|
||||
|
||||
def _scale_1_two_1(self, widget = None, eve = None):
|
||||
if eve.button == 1:
|
||||
self._unset_class(self.fit_button)
|
||||
self._set_class(self.one2one_button)
|
||||
|
||||
event_system.emit("scale_1_two_1")
|
||||
|
||||
def _fit_to_container(self, widget = None, eve = None):
|
||||
if eve.button == 1:
|
||||
self._unset_class(self.one2one_button)
|
||||
self._set_class(self.fit_button)
|
||||
|
||||
event_system.emit("fit_to_container")
|
||||
|
||||
def _horizontal_flip(self, widget = None, eve = None):
|
||||
event_system.emit("horizontal_flip")
|
||||
|
||||
def _rotate_right(self, widget = None, eve = None):
|
||||
event_system.emit("rotate_right")
|
||||
|
||||
def _zoom_in(self, widget = None, eve = None):
|
||||
event_system.emit("zoom_in")
|
||||
|
||||
def _set_class(self, target):
|
||||
ctx = target.get_style_context()
|
||||
ctx.add_class("button-highlighted")
|
||||
|
||||
def _unset_class(self, target):
|
||||
ctx = target.get_style_context()
|
||||
ctx.remove_class("button-highlighted")
|
||||
86
src/core/widgets/image.py
Normal file
86
src/core/widgets/image.py
Normal file
@@ -0,0 +1,86 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('GdkPixbuf', '2.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
try:
|
||||
from PIL import Image as PImage
|
||||
except Exception as e:
|
||||
PImage = None
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class Image(Gtk.EventBox):
|
||||
def __init__(self, path = None):
|
||||
super(Image, self).__init__()
|
||||
|
||||
self._thumbnail_with = settings.get_thumbnail_with()
|
||||
self._thumbnail_height = settings.get_thumbnail_height()
|
||||
self.is_loaded = False
|
||||
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_image_to_view(self, widget = None, eve = None):
|
||||
if eve.button == 1:
|
||||
event_system.emit("handle_file_from_dnd", (self.path, ))
|
||||
|
||||
def load_pixbuf(self):
|
||||
self.set_from_pixbuf( self.get_pixbuf_data(self.path, \
|
||||
self._thumbnail_with, \
|
||||
self._thumbnail_height) )
|
||||
self.is_loaded = True
|
||||
|
||||
def set_from_pixbuf(self, pixbuf):
|
||||
self.image.set_from_pixbuf(pixbuf)
|
||||
|
||||
def get_pixbuf_data(self, path, w = 126, h = 126):
|
||||
path = self.path if not path else path
|
||||
pixbuf = None
|
||||
|
||||
if PImage and path.endswith(".webp"):
|
||||
return self.image2pixbuf(path, w, h)
|
||||
|
||||
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 image2pixbuf(self, path, _w, _h):
|
||||
"""Convert Pillow image to GdkPixbuf"""
|
||||
im = PImage.open(path)
|
||||
data = im.tobytes()
|
||||
data = GLib.Bytes.new(data)
|
||||
w, h = im.size
|
||||
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
|
||||
False, 8, w, h, w * 3)
|
||||
|
||||
return pixbuf.scale_simple(_w, _h, 2) # 2 = BILINEAR and is best by default
|
||||
85
src/core/widgets/image_list.py
Normal file
85
src/core/widgets/image_list.py
Normal file
@@ -0,0 +1,85 @@
|
||||
# Python imports
|
||||
import os
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
|
||||
# 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._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
self.set_spacing(15)
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("load_image_list", self.load_image_list)
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
|
||||
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) )
|
||||
|
||||
event_system.emit("update_list_size_constraints", (len(paths),))
|
||||
self.show_range()
|
||||
|
||||
# TODO: Setup to load range start/end values from settings
|
||||
def show_range(self, i = 0, j = settings.get_max_ring_thumbnail_list()):
|
||||
children = self.get_children()
|
||||
if len(children) <= j:
|
||||
j = len(children) - 1
|
||||
|
||||
while i <= j:
|
||||
child = children[i]
|
||||
self.load_child_pixbuf_threaded(child)
|
||||
i += 1
|
||||
|
||||
@daemon_threaded
|
||||
def load_child_pixbuf_threaded(self, child):
|
||||
GLib.idle_add(child.load_pixbuf)
|
||||
GLib.idle_add(child.show)
|
||||
Gtk.main_iteration()
|
||||
170
src/core/widgets/image_view.py
Normal file
170
src/core/widgets/image_view.py
Normal file
@@ -0,0 +1,170 @@
|
||||
# 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
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class ImageView(Gtk.Image):
|
||||
def __init__(self):
|
||||
super(ImageView, self).__init__()
|
||||
|
||||
self.pixbuf = None
|
||||
self.work_pixbuf = None
|
||||
self.animation = None
|
||||
self.fit_to_win = False
|
||||
|
||||
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("zoom_out", self._zoom_out)
|
||||
event_system.subscribe("handle_file_from_dnd", self._handle_file_from_dnd)
|
||||
event_system.subscribe("vertical_flip", self._vertical_flip)
|
||||
event_system.subscribe("rotate_left", self._rotate_left)
|
||||
event_system.subscribe("scale_1_two_1", self._scale_1_two_1)
|
||||
event_system.subscribe("fit_to_container", self._fit_to_container)
|
||||
event_system.subscribe("horizontal_flip", self._horizontal_flip)
|
||||
event_system.subscribe("rotate_right", self._rotate_right)
|
||||
event_system.subscribe("zoom_in", self._zoom_in)
|
||||
|
||||
event_system.subscribe("size_allocate", self._size_allocate)
|
||||
|
||||
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.work_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.work_pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
|
||||
except Exception:
|
||||
self.work_pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf()
|
||||
|
||||
self.pixbuf = self.work_pixbuf
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
if self.fit_to_win:
|
||||
self._fit_to_container()
|
||||
|
||||
event_system.emit("update_path_label", (path,))
|
||||
|
||||
|
||||
def _zoom_out(self):
|
||||
if self.work_pixbuf:
|
||||
# TODO: Setup scale factor setting to pull from settings...
|
||||
stepx = self.work_pixbuf.get_width() * 0.05
|
||||
stepy = self.work_pixbuf.get_height() * 0.05
|
||||
|
||||
w = self.work_pixbuf.get_width() - stepx
|
||||
h = self.work_pixbuf.get_height() - stepy
|
||||
|
||||
self.work_pixbuf = self.pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _rotate_left(self):
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.work_pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
|
||||
self.pixbuf = self.pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _vertical_flip(self):
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.work_pixbuf.flip(True)
|
||||
self.pixbuf = self.pixbuf.flip(True)
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _scale_1_two_1(self):
|
||||
self.fit_to_win = False
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.pixbuf
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _fit_to_container(self):
|
||||
self.fit_to_win = True
|
||||
if self.work_pixbuf:
|
||||
parent_aloc = self.get_parent().get_parent().get_allocation()
|
||||
pw = parent_aloc.width
|
||||
ph = parent_aloc.height
|
||||
iw = self.pixbuf.get_width()
|
||||
ih = self.pixbuf.get_height()
|
||||
w = 0
|
||||
h = 0
|
||||
|
||||
if iw == 0 or ih == 0:
|
||||
return
|
||||
|
||||
w = pw;
|
||||
h = ((ih * w) / iw + 0.5)
|
||||
|
||||
if h > ph:
|
||||
h = ph
|
||||
w = (iw * h) / ih + 0.5
|
||||
|
||||
|
||||
self.work_pixbuf = self.pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _horizontal_flip(self):
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.work_pixbuf.flip(False)
|
||||
self.pixbuf = self.pixbuf.flip(False)
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _rotate_right(self):
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.work_pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.CLOCKWISE)
|
||||
self.pixbuf = self.pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.CLOCKWISE)
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _zoom_in(self):
|
||||
if self.work_pixbuf:
|
||||
# TODO: Setup scale factor setting to pull from settings...
|
||||
stepx = self.work_pixbuf.get_width() * 0.05
|
||||
stepy = self.work_pixbuf.get_height() * 0.05
|
||||
|
||||
w = self.work_pixbuf.get_width() + stepx
|
||||
h = self.work_pixbuf.get_height() + stepy
|
||||
|
||||
self.work_pixbuf = self.pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _size_allocate(self):
|
||||
if self.fit_to_win:
|
||||
self._fit_to_container()
|
||||
46
src/core/widgets/path_label.py
Normal file
46
src/core/widgets/path_label.py
Normal 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)
|
||||
Reference in New Issue
Block a user