Skip to content

Commit

Permalink
fix drag on Windows OS
Browse files Browse the repository at this point in the history
  • Loading branch information
vantu5z committed Sep 26, 2019
1 parent 357447e commit f55f693
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions GraphView/graphview.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,8 @@ def populate(self, active_person):
# set the busy cursor, so the user knows that we are working
self.uistate.set_busy_cursor(True)

self._in_drag = False
self._in_drag = False # True - when drag can be started
self._do_drag = False # True - when drag is started
self.clear()
self.active_person_handle = active_person

Expand Down Expand Up @@ -1357,7 +1358,10 @@ def motion_notify_event(self, item, target, event):
self.vadjustment.set_value(new_y)
return True

if self._in_drag and (event.type == Gdk.EventType.MOTION_NOTIFY):
if not (event.type == Gdk.EventType.MOTION_NOTIFY):
return False

if self._in_drag and (not self._do_drag):
# start drag when cursor moved more then 5
# to separate it from simple click
if ((abs(self._last_x - event.x_root) > 5)
Expand All @@ -1371,11 +1375,8 @@ def motion_notify_event(self, item, target, event):

# translate to drag_widget coords
scale_coef = self.canvas.get_scale()
bounds = self.canvas.get_root_item().get_bounds()
height_canvas = bounds.y2 - bounds.y1
x = self._last_x * scale_coef - self.hadjustment.get_value()
y = ((height_canvas + self._last_y) * scale_coef -
self.vadjustment.get_value())
y = self._last_y * scale_coef - self.vadjustment.get_value()

# setup targets
tglist = Gtk.TargetList.new([])
Expand All @@ -1394,14 +1395,12 @@ def motion_notify_event(self, item, target, event):
# allow drag to a text document, info on drag_get will be 1
tglist.add_text_targets(1)

drag_widget = self.get_widget()
# change event window
event.window = drag_widget.get_window()
# start drag
drag_widget = self.get_widget()
drag_widget.drag_begin_with_coordinates(
tglist,
Gdk.DragAction.COPY,
Gdk.KEY_Pointer_Button1,
1, # left mouse button = 1
event,
x, y)
return True
Expand Down Expand Up @@ -1500,6 +1499,7 @@ def cb_drag_begin(self, widget, context):
"""
Called on start drag.
"""
self._do_drag = True
tgs = [x.name() for x in context.list_targets()]
# set icon depending on person or family drag
if DdTargets.PERSON_LINK.drag_type in tgs:
Expand All @@ -1512,6 +1512,7 @@ def cb_drag_end(self, widget, context):
Called when drag is end.
"""
self._in_drag = False
self._do_drag = False

def cb_drag_data_get(self, widget, context, sel_data, info, time):
"""
Expand Down

0 comments on commit f55f693

Please sign in to comment.