Mirage2/src/new-src/core/widgets/image_view.py

108 lines
2.9 KiB
Python
Raw Normal View History

2023-04-23 21:47:33 +00:00
# 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
2023-04-23 21:47:33 +00:00
# Application imports
class ImageView(Gtk.Image):
def __init__(self):
super(ImageView, self).__init__()
self.bak_pixbuf = None
self.pixbuf = None
self.animation = None
2023-04-23 21:47:33 +00:00
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)
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)
2023-04-23 21:47:33 +00:00
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.bak_pixbuf = None
self.pixbuf = None
self.animation = None
2023-04-23 21:47:33 +00:00
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.bak_pixbuf = self.pixbuf
2023-04-23 21:47:33 +00:00
self.set_from_pixbuf(self.pixbuf)
2023-04-24 02:18:35 +00:00
event_system.emit("update_path_label", (path,))
def _rotate_left(self):
if self.pixbuf:
self.pixbuf = self.pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
self.set_from_pixbuf(self.pixbuf)
def _vertical_flip(self):
if self.pixbuf:
self.pixbuf = self.pixbuf.flip(False)
self.set_from_pixbuf(self.pixbuf)
def _scale_1_two_1(self):
if self.pixbuf:
...
...
def _fit_to_container(self):
if self.pixbuf:
...
...
def _horizontal_flip(self):
if self.pixbuf:
self.pixbuf = self.pixbuf.flip(True)
self.set_from_pixbuf(self.pixbuf)
def _rotate_right(self):
if self.pixbuf:
self.pixbuf = self.pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.CLOCKWISE)
self.set_from_pixbuf(self.pixbuf)