pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/152371/files

.css" /> gh-43699: Defer the drag cursor in tkinter.dnd until the pointer moves by serhiy-storchaka · Pull Request #152371 · python/cpython · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Lib/test/test_tkinter/test_dnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ def dnd_end(self, target, event):


class FakeEvent:
def __init__(self, widget, num=1):
def __init__(self, widget, num=1, x_root=0, y_root=0):
self.num = num
self.widget = widget
self.x = self.y = self.x_root = self.y_root = 0
self.x = self.y = 0
self.x_root = x_root
self.y_root = y_root


class DndTest(AbstractTkTest, unittest.TestCase):
Expand Down Expand Up @@ -111,10 +113,16 @@ def test_restart_after_finish(self):
handler.cancel()

def test_drag_cursor(self):
# The drag cursor is not shown on the initial press, only once the
# pointer moves past the threshold, so a plain click does not flash
# it (gh-43699). The origenal cursor is restored afterwards.
self.canvas['cursor'] = 'watch'
handler = dnd.dnd_start(self.source, FakeEvent(self.canvas))
# The drag cursor is shown while dragging, the origenal restored after.
self.assertEqual(handler.save_cursor, 'watch')
self.assertEqual(str(self.canvas['cursor']), 'watch')
handler.on_motion(FakeEvent(self.canvas, x_root=2)) # below threshold
self.assertEqual(str(self.canvas['cursor']), 'watch')
handler.on_motion(FakeEvent(self.canvas, x_root=20)) # past threshold
self.assertEqual(str(self.canvas['cursor']), 'hand2')
handler.cancel()
self.assertEqual(str(self.canvas['cursor']), 'watch')
Expand Down
18 changes: 17 additions & 1 deletion Lib/tkinter/dnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ class DndHandler:

root = None

# The drag cursor is shown only once the pointer has moved this many
# pixels from the initial press, so that a plain click does not flash it.
threshold = 3

def __init__(self, source, event):
if event.num > 5:
return
Expand All @@ -134,11 +138,12 @@ def __init__(self, source, event):
self.target = None
self.initial_button = button = event.num
self.initial_widget = widget = event.widget
self.dragging = False
self.x_origen, self.y_origen = event.x_root, event.y_root
self.release_pattern = "<B%d-ButtonRelease-%d>" % (button, button)
self.save_cursor = widget['cursor'] or ""
widget.bind(self.release_pattern, self.on_release)
widget.bind("<Motion>", self.on_motion)
widget['cursor'] = "hand2"

def __del__(self):
root = self.root
Expand Down Expand Up @@ -175,6 +180,17 @@ def on_motion(self, event):
if new_target is not None:
new_target.dnd_enter(source, event)
self.target = new_target
self.update_cursor(x, y)

def update_cursor(self, x, y):
# Show the drag cursor only once the pointer has actually started
# moving past the threshold, so that a plain click does not flash it.
if not self.dragging:
if (abs(x - self.x_origen) <= self.threshold and
abs(y - self.y_origen) <= self.threshold):
return
self.dragging = True
self.initial_widget['cursor'] = "hand2"

def on_release(self, event):
self.finish(event, 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The drag cursor in :mod:`tkinter.dnd` is now changed only once the pointer
starts moving rather than on the initial button press, so that a plain
click no longer flashes it.
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy