Added drag scroll of image
This commit is contained in:
parent
1f0760492b
commit
f0784916ed
|
@ -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
|
|
@ -10,7 +10,7 @@ from gi.repository import Gdk
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from ..widgets.image_view import ImageView
|
from .image_view_evebox import ImageViewEveBox
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,12 +41,14 @@ class ImageViewScroll(Gtk.ScrolledWindow):
|
||||||
self.connect("size-allocate", self._size_request_change)
|
self.connect("size-allocate", self._size_request_change)
|
||||||
self.connect('scroll-event', self.on_scroll)
|
self.connect('scroll-event', self.on_scroll)
|
||||||
|
|
||||||
def _load_widgets(self):
|
|
||||||
self.add(ImageView())
|
|
||||||
|
|
||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
event_system.subscribe("do_filter_open", self._do_filter_open)
|
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):
|
def _set_up_dnd(self):
|
||||||
flags = Gtk.DestDefaults.ALL
|
flags = Gtk.DestDefaults.ALL
|
||||||
URI_TARGET_TYPE = 80
|
URI_TARGET_TYPE = 80
|
||||||
|
@ -68,8 +70,7 @@ class ImageViewScroll(Gtk.ScrolledWindow):
|
||||||
|
|
||||||
|
|
||||||
def _do_filter_open(self, uris: [] = []):
|
def _do_filter_open(self, uris: [] = []):
|
||||||
if len(uris) == 0:
|
if len(uris) == 0: return
|
||||||
return
|
|
||||||
|
|
||||||
has_loaded_image, path, img_list = self.filter_for_images(uris)
|
has_loaded_image, path, img_list = self.filter_for_images(uris)
|
||||||
self._handle_open(has_loaded_image, path, img_list)
|
self._handle_open(has_loaded_image, path, img_list)
|
||||||
|
@ -98,8 +99,7 @@ class ImageViewScroll(Gtk.ScrolledWindow):
|
||||||
return has_loaded_image, path, img_list
|
return has_loaded_image, path, img_list
|
||||||
|
|
||||||
def _handle_open(self, has_loaded_image, path, img_list):
|
def _handle_open(self, has_loaded_image, path, img_list):
|
||||||
if len(img_list) == 0:
|
if len(img_list) == 0: return
|
||||||
return
|
|
||||||
|
|
||||||
if not has_loaded_image:
|
if not has_loaded_image:
|
||||||
img = img_list[0]
|
img = img_list[0]
|
||||||
|
|
Loading…
Reference in New Issue