Image scale events on container resize
This commit is contained in:
parent
76978db127
commit
8178fe3490
|
@ -12,6 +12,42 @@ from ..widgets.preview_image import PreviewPane
|
|||
from ..widgets.menu_popover import MenuPopover
|
||||
|
||||
|
||||
|
||||
class PreviewScroll(Gtk.ScrolledWindow):
|
||||
def __init__(self):
|
||||
super(PreviewScroll, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_vexpand(True)
|
||||
self.set_hexpand(True)
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
viewport = Gtk.Viewport()
|
||||
viewport.add(PreviewPane())
|
||||
viewport.connect("size-allocate", self._scale_image)
|
||||
self.add(viewport)
|
||||
|
||||
def _scale_image(self, widget = None, allocation = None):
|
||||
child = widget.get_children()[0]
|
||||
if not child.pixbuf in ("", None):
|
||||
pixbuf = child.scale_to_container(child.pixbuf)
|
||||
child.set_from_pixbuf(pixbuf)
|
||||
|
||||
|
||||
class LeftBox(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(LeftBox, self).__init__()
|
||||
|
@ -37,4 +73,4 @@ class LeftBox(Gtk.Box):
|
|||
|
||||
self.add(RadioButtons())
|
||||
self.add(delay_amount)
|
||||
self.add(PreviewPane())
|
||||
self.add(PreviewScroll())
|
||||
|
|
|
@ -11,11 +11,11 @@ from gi.repository import Gio
|
|||
|
||||
|
||||
|
||||
class PreviewPane(Gtk.AspectFrame):
|
||||
class PreviewPane(Gtk.Image):
|
||||
def __init__(self):
|
||||
super(PreviewPane, self).__init__()
|
||||
|
||||
self._preview_image = None
|
||||
self.pixbuf = None
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
|
@ -26,7 +26,8 @@ class PreviewPane(Gtk.AspectFrame):
|
|||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_size_request(312, 312)
|
||||
self.set_vexpand(True)
|
||||
self.set_hexpand(True)
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
@ -36,9 +37,7 @@ class PreviewPane(Gtk.AspectFrame):
|
|||
event_system.subscribe("unset_image_preview", self.unset_image_preview)
|
||||
|
||||
def _load_widgets(self):
|
||||
self._preview_image = Gtk.Image()
|
||||
self.unset_image_preview()
|
||||
self.add(self._preview_image)
|
||||
|
||||
def set_image_to_view(self, image_file):
|
||||
if not image_file:
|
||||
|
@ -46,11 +45,19 @@ class PreviewPane(Gtk.AspectFrame):
|
|||
|
||||
images_dir = settings.get_screenshots_dir()
|
||||
path = os.path.join(images_dir, image_file)
|
||||
self.pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
|
||||
self.set_from_pixbuf( self.scale_to_container(self.pixbuf) )
|
||||
|
||||
pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
|
||||
scaledPixBuf = pixbuf.scale_simple(480, 320, 2) # 2 = BILINEAR and is best by default
|
||||
self._preview_image.set_from_pixbuf(scaledPixBuf)
|
||||
def scale_to_container(self, pixbuf):
|
||||
rect = self.get_parent().get_parent().get_allocated_size().allocation
|
||||
pxw = pixbuf.get_width()
|
||||
pxh = pixbuf.get_height()
|
||||
h = rect.height
|
||||
w = (pxw * h) / pxh
|
||||
|
||||
return pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
|
||||
|
||||
def unset_image_preview(self):
|
||||
self.pixbuf = None
|
||||
pixbuf = Gtk.Image.new_from_icon_name("gtk-missing-image", 4).get_pixbuf()
|
||||
self._preview_image.set_from_pixbuf(pixbuf)
|
||||
self.set_from_pixbuf(pixbuf)
|
||||
|
|
|
@ -48,9 +48,9 @@ class BodyGrid(Gtk.Grid):
|
|||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
drag_button = Gtk.Button("")
|
||||
close_button = Gtk.Button("x")
|
||||
grab_button = Gtk.Button("Grab")
|
||||
drag_button = Gtk.Button("...")
|
||||
close_button = Gtk.Button("")
|
||||
grab_button = Gtk.Button("")
|
||||
bottom_right = Gtk.Button("")
|
||||
box2 = Gtk.Box()
|
||||
box3 = Gtk.Box()
|
||||
|
@ -58,9 +58,13 @@ class BodyGrid(Gtk.Grid):
|
|||
box5 = Gtk.Box()
|
||||
|
||||
ctx = drag_button.get_style_context()
|
||||
ctx.add_class("expand-button")
|
||||
ctx.add_class("transparent-button")
|
||||
ctx2 = bottom_right.get_style_context()
|
||||
ctx2.add_class("expand-button")
|
||||
ctx2.add_class("transparent-button")
|
||||
ctx3 = close_button.get_style_context()
|
||||
ctx3.add_class("transparent-button")
|
||||
ctx4 = grab_button.get_style_context()
|
||||
ctx4.add_class("transparent-button")
|
||||
|
||||
col, row = 1, 1
|
||||
self.attach(drag_button, col, row, 11, 1)
|
||||
|
@ -81,6 +85,13 @@ class BodyGrid(Gtk.Grid):
|
|||
|
||||
close_button.set_vexpand(False)
|
||||
close_button.set_hexpand(False)
|
||||
close_button.set_image( Gtk.Image.new_from_icon_name("gtk-close", 4) )
|
||||
close_button.set_always_show_image(True)
|
||||
grab_button.set_image( Gtk.Image.new_from_icon_name("gtk-media-record", 4) )
|
||||
grab_button.set_always_show_image(True)
|
||||
bottom_right.set_image( Gtk.Image.new_from_icon_name("gtk-zoom-fit", 4) )
|
||||
bottom_right.set_always_show_image(True)
|
||||
|
||||
box2.set_vexpand(True)
|
||||
box2.set_hexpand(True)
|
||||
box3.set_vexpand(True)
|
||||
|
|
Loading…
Reference in New Issue