Image event box addition

This commit is contained in:
itdominator 2023-04-22 15:05:28 -05:00
parent 8178fe3490
commit 31bf0e00b5
3 changed files with 28 additions and 14 deletions

View File

@ -37,15 +37,28 @@ class PreviewScroll(Gtk.ScrolledWindow):
def _load_widgets(self):
viewport = Gtk.Viewport()
viewport.add(PreviewPane())
viewport.connect("size-allocate", self._scale_image)
eve_box = Gtk.EventBox()
eve_box.add(PreviewPane())
viewport.add(eve_box)
self.add(viewport)
eve_box.connect("button-release-event", self._handle_clicks)
viewport.connect("size-allocate", self._scale_image)
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)
preview_image = widget.get_children()[0].get_children()[0]
if not preview_image.pixbuf in ("", None):
pixbuf = preview_image.scale_to_container(preview_image.pixbuf)
preview_image.set_from_pixbuf(pixbuf)
def _handle_clicks(self, widget = None, eve = None):
preview_image = widget.get_children()[0]
if eve.button == 3 and not preview_image.file_name in ("", None):
event_system.emit("set_revert_data", (preview_image.file_name,))
event_system.emit("show_menu", (preview_image.file_name,))
class LeftBox(Gtk.Box):

View File

@ -15,7 +15,8 @@ class PreviewPane(Gtk.Image):
def __init__(self):
super(PreviewPane, self).__init__()
self.pixbuf = None
self.pixbuf = None
self.file_name = None
self._setup_styling()
self._setup_signals()
@ -39,17 +40,18 @@ class PreviewPane(Gtk.Image):
def _load_widgets(self):
self.unset_image_preview()
def set_image_to_view(self, image_file):
if not image_file:
def set_image_to_view(self, file_name):
if not file_name:
return
self.file_name = file_name
images_dir = settings.get_screenshots_dir()
path = os.path.join(images_dir, image_file)
path = os.path.join(images_dir, file_name)
self.pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
self.set_from_pixbuf( self.scale_to_container(self.pixbuf) )
def scale_to_container(self, pixbuf):
rect = self.get_parent().get_parent().get_allocated_size().allocation
rect = self.get_parent().get_parent().get_parent().get_allocated_size().allocation
pxw = pixbuf.get_width()
pxh = pixbuf.get_height()
h = rect.height

View File

@ -1,11 +1,10 @@
.region-window {
background-color: rgba(0, 0, 0, 0.0);
/* border: 2px solid rgba(136, 204, 39, 1); */
/* Dark Bergundy */
border: 2px solid rgba(116, 0, 0, 1);
}
.expand-button {
.transparent-button {
background-color: rgba(0, 0, 0, 0.0);
border: 2px solid rgba(56, 56, 56, 1);
border: 2px solid rgba(96, 96, 96, 1);
}