From 3d445a01ddbe440f29db0d211880a71882bc4310 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sun, 3 Jun 2018 09:14:09 -0400 Subject: [PATCH 1/4] bpo-33664: IDLE: Scroll editor text by lines and not pixels --- Lib/idlelib/editor.py | 30 +++++++++++++++++-- .../2018-06-03-09-13-28.bpo-33664.PZzQyL.rst | 2 ++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index 892b64ba696df22..5488d51abfe642f 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -30,6 +30,7 @@ # The default tab setting for a Text widget, in average-width characters. TK_TABWIDTH_DEFAULT = 8 _py_version = ' (%s)' % platform.python_version() +darwin = sys.platform == 'darwin' def _sphinx_version(): "Format sys.version_info to produce the Sphinx version string used to install the chm docs" @@ -49,7 +50,7 @@ class EditorWindow(object): from idlelib.undo import UndoDelegator from idlelib.iomenu import IOBinding, encoding from idlelib import mainmenu - from tkinter import Toplevel + from tkinter import Toplevel, EventType from idlelib.statusbar import MultiStatusBar from idlelib.autocomplete import AutoComplete from idlelib.autoexpand import AutoExpand @@ -147,6 +148,9 @@ def __init__(self, flist=None, filename=None, key=None, root=None): else: # Elsewhere, use right-click for popup menus. text.bind("<3>",self.right_menu_event) + text.bind('', self.mousescroll) + text.bind('', self.mousescroll) + text.bind('', self.mousescroll) text.bind("<>", self.cut) text.bind("<>", self.copy) text.bind("<>", self.paste) @@ -178,7 +182,6 @@ def __init__(self, flist=None, filename=None, key=None, root=None): text.bind("<>",self.change_indentwidth_event) text.bind("", self.move_at_edge_if_selection(0)) text.bind("", self.move_at_edge_if_selection(1)) - text.bind("<>", self.del_word_left) text.bind("<>", self.del_word_right) text.bind("<>", self.home_callback) @@ -193,7 +196,7 @@ def __init__(self, flist=None, filename=None, key=None, root=None): text.bind("<>", self.open_turtle_demo) self.set_status_bar() - vbar['command'] = text.yview + vbar['command'] = self.handle_yview vbar.pack(side=RIGHT, fill=Y) text['yscrollcommand'] = vbar.set text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow') @@ -441,6 +444,27 @@ def postwindowsmenu(self): menu.delete(self.wmenu_end+1, end) windows.add_windows_to_menu(menu) + def handle_yview(self, event, *args): + "Handle scrollbar." + if event == 'moveto': + fraction = float(args[0]) + lines = (round(self.getlineno('end') * fraction) - + self.getlineno('@0,0')) + event = 'scroll' + args = (lines, 'units') + self.text.yview(event, *args) + return 'break' + + def mousescroll(self, event): + "Handle scroll wheel." + up = {EventType.MouseWheel: event.delta >= 0 == darwin, + EventType.Button: event.num == 4} + lines = 5 + if up[event.type]: + lines = -lines + self.text.yview_scroll(lines, 'units') + return 'break' + rmenu = None def right_menu_event(self, event): diff --git a/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst b/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst new file mode 100644 index 000000000000000..b01f75abfd735f4 --- /dev/null +++ b/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst @@ -0,0 +1,2 @@ +IDLE: Scroll editor by lines instead of pixels for mousewheel and button +events. From 050d3e5917ffe66f0d7e0819f60123b711754ca4 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sun, 3 Jun 2018 10:02:04 -0400 Subject: [PATCH 2/4] Restore accidentally deleted line --- Lib/idlelib/editor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index 5488d51abfe642f..7c3f215e9f96a8c 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -182,6 +182,7 @@ def __init__(self, flist=None, filename=None, key=None, root=None): text.bind("<>",self.change_indentwidth_event) text.bind("", self.move_at_edge_if_selection(0)) text.bind("", self.move_at_edge_if_selection(1)) + text.bind("<>", self.del_word_left) text.bind("<>", self.del_word_right) text.bind("<>", self.home_callback) From 68608e7455b636fcc6c4751f5d4e26509dcef4ce Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 3 Jun 2018 12:41:47 -0400 Subject: [PATCH 3/4] Update 2018-06-03-09-13-28.bpo-33664.PZzQyL.rst --- .../next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst b/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst index b01f75abfd735f4..193a57ea3f763bd 100644 --- a/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst +++ b/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst @@ -1,2 +1,5 @@ -IDLE: Scroll editor by lines instead of pixels for mousewheel and button -events. +bpo-33664: Scroll IDLE editor text by lines. +Previously, the mouse wheel and scrollbar slider moved text by a fixed +number of pixels, resulting in partial lines at the top of the editor +box. The change also applies to the shell and grep output windows, +but not to read-only text views. From 0a565c50aa3a17924751dc83af164d4a2e6fcc52 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 3 Jun 2018 12:52:43 -0400 Subject: [PATCH 4/4] Update 2018-06-03-09-13-28.bpo-33664.PZzQyL.rst --- Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst b/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst index 193a57ea3f763bd..48f602f641c96c3 100644 --- a/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst +++ b/Misc/NEWS.d/next/IDLE/2018-06-03-09-13-28.bpo-33664.PZzQyL.rst @@ -1,4 +1,4 @@ -bpo-33664: Scroll IDLE editor text by lines. +Scroll IDLE editor text by lines. Previously, the mouse wheel and scrollbar slider moved text by a fixed number of pixels, resulting in partial lines at the top of the editor box. The change also applies to the shell and grep output windows,