diff --git a/src/core/containers/image_view_evebox.py b/src/core/containers/image_view_evebox.py new file mode 100644 index 0000000..a17cff5 --- /dev/null +++ b/src/core/containers/image_view_evebox.py @@ -0,0 +1,90 @@ +# 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 +from ..widgets.image_view import ImageView + + + +class ImageViewEveBox(Gtk.EventBox): + def __init__(self, vadjustment, hadjustment): + super(ImageViewEveBox, self).__init__() + + self.vadjustment = vadjustment + self.hadjustment = hadjustment + self._is_dragging = False + self._drag_start_x = 0 + self._drag_start_y = 0 + self._current_x = 0 + self._current_y = 0 + + self._setup_styling() + self._setup_signals() + self._subscribe_to_events() + self._load_widgets() + + self.show_all() + + + def _setup_styling(self): + ... + + def _setup_signals(self): + self.connect("button-press-event", self._press_event) + self.connect("motion-notify-event", self._move_motion_event) + self.connect("button-release-event", self._release_event) + + def _subscribe_to_events(self): + ... + + def _load_widgets(self): + self.add(ImageView()) + + def _press_event(self, widget = None, eve = None): + window = settings.get_main_window() + cursor = Gdk.Cursor(Gdk.CursorType.CROSSHAIR) + window.get_window().set_cursor(cursor) + + self._is_dragging = True + self._drag_start_x = eve.x_root + self._drag_start_y = eve.y_root + + def _move_motion_event(self, widget = None, eve = None): + if self._is_dragging: + vval = self.vadjustment.get_value() + hval = self.hadjustment.get_value() + hstep_val = self.hadjustment.get_step_increment() + vstep_val = self.vadjustment.get_step_increment() + + if eve.x_root > self._drag_start_x: + self.hadjustment.set_value(hval + hstep_val) + elif eve.x_root < self._drag_start_x: + self.hadjustment.set_value(hval - hstep_val) + else: + self.hadjustment.set_value(hval) + + if eve.y_root > self._drag_start_y: + self.vadjustment.set_value(vval + vstep_val) + elif eve.y_root < self._drag_start_y: + self.vadjustment.set_value(vval - vstep_val) + else: + self.vadjustment.set_value(vval) + + self._drag_start_x = eve.x_root + self._drag_start_y = eve.y_root + + + def _release_event(self, widget = None, eve = None): + window = settings.get_main_window() + watch_cursor = Gdk.Cursor(Gdk.CursorType.ARROW) + window.get_window().set_cursor(watch_cursor) + + self._is_dragging = False + self._drag_start_x = 0 + self._drag_start_y = 0 diff --git a/src/core/containers/image_view_scroll.py b/src/core/containers/image_view_scroll.py index 6a1899e..d5f6e41 100644 --- a/src/core/containers/image_view_scroll.py +++ b/src/core/containers/image_view_scroll.py @@ -10,7 +10,7 @@ from gi.repository import Gdk from gi.repository import GLib # Application imports -from ..widgets.image_view import ImageView +from .image_view_evebox import ImageViewEveBox @@ -41,19 +41,21 @@ class ImageViewScroll(Gtk.ScrolledWindow): self.connect("size-allocate", self._size_request_change) self.connect('scroll-event', self.on_scroll) - def _load_widgets(self): - self.add(ImageView()) - def _subscribe_to_events(self): event_system.subscribe("do_filter_open", self._do_filter_open) + def _load_widgets(self): + vadjustment = self.get_vadjustment() + hadjustment = self.get_hadjustment() + self.add(ImageViewEveBox(vadjustment, hadjustment)) + def _set_up_dnd(self): flags = Gtk.DestDefaults.ALL URI_TARGET_TYPE = 80 - uri_target = Gtk.TargetEntry.new('text/uri-list', Gtk.TargetFlags(0), URI_TARGET_TYPE) - targets = [ uri_target ] - action = Gdk.DragAction.COPY + uri_target = Gtk.TargetEntry.new('text/uri-list', Gtk.TargetFlags(0), URI_TARGET_TYPE) + targets = [ uri_target ] + action = Gdk.DragAction.COPY self.drag_dest_set(flags, targets, action) self.connect("drag-data-received", self._on_drag_data_received) @@ -68,8 +70,7 @@ class ImageViewScroll(Gtk.ScrolledWindow): def _do_filter_open(self, uris: [] = []): - if len(uris) == 0: - return + if len(uris) == 0: return has_loaded_image, path, img_list = self.filter_for_images(uris) self._handle_open(has_loaded_image, path, img_list) @@ -98,8 +99,7 @@ class ImageViewScroll(Gtk.ScrolledWindow): return has_loaded_image, path, img_list def _handle_open(self, has_loaded_image, path, img_list): - if len(img_list) == 0: - return + if len(img_list) == 0: return if not has_loaded_image: img = img_list[0]