Fixed webp display, added scroll functionality, cleanup
This commit is contained in:
parent
d2c8c1a426
commit
7d30a678ca
|
@ -39,6 +39,7 @@ class ImageViewScroll(Gtk.ScrolledWindow):
|
||||||
def _setup_signals(self):
|
def _setup_signals(self):
|
||||||
self._set_up_dnd()
|
self._set_up_dnd()
|
||||||
self.connect("size-allocate", self._size_request_change)
|
self.connect("size-allocate", self._size_request_change)
|
||||||
|
self.connect('scroll-event', self.on_scroll)
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
self.add(ImageView())
|
self.add(ImageView())
|
||||||
|
@ -116,3 +117,21 @@ class ImageViewScroll(Gtk.ScrolledWindow):
|
||||||
if self.size_request.width != rect.width or self.size_request.height != rect.height:
|
if self.size_request.width != rect.width or self.size_request.height != rect.height:
|
||||||
self.size_request = rect
|
self.size_request = rect
|
||||||
GLib.idle_add(event_system.emit, *("size_allocate",))
|
GLib.idle_add(event_system.emit, *("size_allocate",))
|
||||||
|
|
||||||
|
def on_scroll(self, widget = None, event = None):
|
||||||
|
accel_mask = Gtk.accelerator_get_default_mod_mask()
|
||||||
|
direction = event.get_scroll_deltas()[2]
|
||||||
|
if event.state & accel_mask == Gdk.ModifierType.CONTROL_MASK:
|
||||||
|
adjustment = self.get_hadjustment()
|
||||||
|
current_val = adjustment.get_value()
|
||||||
|
step_val = adjustment.get_step_increment()
|
||||||
|
|
||||||
|
if direction > 0: # NOTE: scroll left
|
||||||
|
adjustment.set_value(current_val - step_val)
|
||||||
|
else: # NOTE: scroll right
|
||||||
|
adjustment.set_value(current_val + step_val)
|
||||||
|
else:
|
||||||
|
if direction > 0:
|
||||||
|
event_system.emit("zoom_out")
|
||||||
|
else:
|
||||||
|
event_system.emit("zoom_in")
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Controller(SignalsMixins, ControllerData):
|
||||||
event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar)
|
event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar)
|
||||||
|
|
||||||
def _tggl_top_main_menubar(self):
|
def _tggl_top_main_menubar(self):
|
||||||
print("_tggl_top_main_menubar > stub...")
|
logger.debug("_tggl_top_main_menubar > stub...")
|
||||||
|
|
||||||
def setup_builder_and_container(self):
|
def setup_builder_and_container(self):
|
||||||
self.builder = Gtk.Builder()
|
self.builder = Gtk.Builder()
|
||||||
|
|
|
@ -61,7 +61,7 @@ class Image(Gtk.EventBox):
|
||||||
pixbuf = None
|
pixbuf = None
|
||||||
|
|
||||||
if PImage and path.endswith(".webp"):
|
if PImage and path.endswith(".webp"):
|
||||||
return ImageView.image2pixbuf(path, w, h)
|
pixbuf = ImageView.image2pixbuf(path)
|
||||||
|
|
||||||
if path.endswith(".gif"):
|
if path.endswith(".gif"):
|
||||||
pixbuf = GdkPixbuf.PixbufAnimation.new_from_file(path).get_static_image()
|
pixbuf = GdkPixbuf.PixbufAnimation.new_from_file(path).get_static_image()
|
||||||
|
|
|
@ -42,7 +42,6 @@ class ImageView(ImageViewMixin, Gtk.Image):
|
||||||
def _setup_styling(self):
|
def _setup_styling(self):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
def _setup_signals(self):
|
def _setup_signals(self):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
@ -106,19 +105,15 @@ class ImageView(ImageViewMixin, Gtk.Image):
|
||||||
self.work_pixbuff = Gtk.Image.new_from_resource(path).get_pixbuf()
|
self.work_pixbuff = Gtk.Image.new_from_resource(path).get_pixbuf()
|
||||||
|
|
||||||
def set_as_webp(self, path):
|
def set_as_webp(self, path):
|
||||||
w = settings.get_thumbnail_with()
|
self.work_pixbuff = self.image2pixbuf(path)
|
||||||
h = settings.get_thumbnail_height()
|
|
||||||
self.work_pixbuff = self.image2pixbuf(path, w, h)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def image2pixbuf(path, _w, _h):
|
def image2pixbuf(path):
|
||||||
"""Convert Pillow image to GdkPixbuf"""
|
"""Convert Pillow image to GdkPixbuf"""
|
||||||
im = PImage.open(path)
|
im = PImage.open(path)
|
||||||
data = im.tobytes()
|
data = im.tobytes()
|
||||||
data = Bytes.new(data)
|
data = Bytes.new(data)
|
||||||
w, h = im.size
|
w, h = im.size
|
||||||
|
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
|
return GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
|
||||||
False, 8, w, h, w * 3)
|
False, 8, w, h, w * 3)
|
||||||
|
|
||||||
return pixbuf.scale_simple(_w, _h, 2) # 2 = BILINEAR and is best by default
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ class ImageViewMixin:
|
||||||
self.set_from_pixbuf(self.work_pixbuff)
|
self.set_from_pixbuf(self.work_pixbuff)
|
||||||
|
|
||||||
def _rotate_left(self):
|
def _rotate_left(self):
|
||||||
print("flipl")
|
|
||||||
if self.work_pixbuff and self.pixbuff:
|
if self.work_pixbuff and self.pixbuff:
|
||||||
self.work_pixbuff = self.work_pixbuff.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
|
self.work_pixbuff = self.work_pixbuff.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
|
||||||
self.pixbuff = self.pixbuff.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
|
self.pixbuff = self.pixbuff.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
|
||||||
|
|
Loading…
Reference in New Issue