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

67 lines
1.5 KiB
Python

# 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)