From 90ba6325a74fd6c77217b9581ba52f1088af73f7 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Wed, 7 Jun 2017 07:40:21 -0400 Subject: [PATCH 1/2] bpo-1207613: IDLE Editor Bottom Scroll Bar --- Lib/idlelib/editor.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index 04c786dc5234c2..e53f02ccc49338 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -122,6 +122,7 @@ def __init__(self, flist=None, filename=None, key=None, root=None): self.prompt_last_line = '' # Override in PyShell self.text_frame = text_frame = Frame(top) self.vbar = vbar = Scrollbar(text_frame, name='vbar') + self.hbar = hbar = Scrollbar(text_frame, orient="horizontal", name='hbar') width = idleConf.GetOption('main', 'EditorWindow', 'width', type='int') text_options = { 'name': 'text', @@ -212,6 +213,9 @@ def __init__(self, flist=None, filename=None, key=None, root=None): vbar['command'] = self.handle_yview vbar.grid(row=1, column=2, sticky=NSEW) text['yscrollcommand'] = vbar.set + hbar['command'] = text.xview + hbar.pack(side='bottom', fill='x') + text['xscrollcommand'] = hbar.set text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow') text.grid(row=1, column=1, sticky=NSEW) text.focus_set() From 568ac0f99a8d414b76c745c7305efecef50911be Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Wed, 26 Feb 2020 07:33:26 -0500 Subject: [PATCH 2/2] Update to AutoShowScrollbar --- Lib/idlelib/editor.py | 18 ++++++++++++------ Lib/idlelib/idle_test/test_textview.py | 4 ++-- Lib/idlelib/pyshell.py | 1 + Lib/idlelib/textview.py | 6 +++--- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index e53f02ccc49338..8563ec7f8879dc 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -26,6 +26,7 @@ from idlelib import query from idlelib import replace from idlelib import search +from idlelib.textview import AutoShowScrollbar from idlelib.tree import wheel_event from idlelib import window @@ -68,6 +69,7 @@ class EditorWindow(object): allow_code_context = True allow_line_numbers = True + allow_hbar = True def __init__(self, flist=None, filename=None, key=None, root=None): # Delay import: runscript imports pyshell imports EditorWindow. @@ -121,8 +123,6 @@ def __init__(self, flist=None, filename=None, key=None, root=None): self.prompt_last_line = '' # Override in PyShell self.text_frame = text_frame = Frame(top) - self.vbar = vbar = Scrollbar(text_frame, name='vbar') - self.hbar = hbar = Scrollbar(text_frame, orient="horizontal", name='hbar') width = idleConf.GetOption('main', 'EditorWindow', 'width', type='int') text_options = { 'name': 'text', @@ -136,6 +136,13 @@ def __init__(self, flist=None, filename=None, key=None, root=None): } self.text = text = MultiCallCreator(Text)(text_frame, **text_options) self.top.focused_widget = self.text + self.vbar = vbar = Scrollbar(text_frame, name='vbar', + takefocus=False, + command=self.handle_yview) + self.hbar = hbar = AutoShowScrollbar(text_frame, name="hbar", + orient="horizontal", + takefocus=False, + command=text.xview) self.createmenubar() self.apply_bindings() @@ -210,12 +217,11 @@ def __init__(self, flist=None, filename=None, key=None, root=None): text_frame.pack(side=LEFT, fill=BOTH, expand=1) text_frame.rowconfigure(1, weight=1) text_frame.columnconfigure(1, weight=1) - vbar['command'] = self.handle_yview vbar.grid(row=1, column=2, sticky=NSEW) text['yscrollcommand'] = vbar.set - hbar['command'] = text.xview - hbar.pack(side='bottom', fill='x') - text['xscrollcommand'] = hbar.set + if self.allow_hbar: + hbar.grid(row=2, column=1, sticky="ew") + text['xscrollcommand'] = hbar.set text['font'] = idleConf.GetFont(self.root, 'main', 'EditorWindow') text.grid(row=1, column=1, sticky=NSEW) text.focus_set() diff --git a/Lib/idlelib/idle_test/test_textview.py b/Lib/idlelib/idle_test/test_textview.py index 7189378ab3dd61..6df5f2ed45d572 100644 --- a/Lib/idlelib/idle_test/test_textview.py +++ b/Lib/idlelib/idle_test/test_textview.py @@ -69,10 +69,10 @@ def test_ok(self): view.destroy() -class AutoHideScrollbarTest(unittest.TestCase): +class AutoShowScrollbarTest(unittest.TestCase): # Method set is tested in ScrollableTextFrameTest def test_forbidden_geometry(self): - scroll = tv.AutoHideScrollbar(root) + scroll = tv.AutoShowScrollbar(root) self.assertRaises(TclError, scroll.pack) self.assertRaises(TclError, scroll.place) diff --git a/Lib/idlelib/pyshell.py b/Lib/idlelib/pyshell.py index d5b310ffd7a9be..c2928db8f92827 100755 --- a/Lib/idlelib/pyshell.py +++ b/Lib/idlelib/pyshell.py @@ -856,6 +856,7 @@ class PyShell(OutputWindow): ] allow_line_numbers = False + allow_hbar = False # New classes from idlelib.history import History diff --git a/Lib/idlelib/textview.py b/Lib/idlelib/textview.py index 808a2aefab4f71..b519d7ba39857e 100644 --- a/Lib/idlelib/textview.py +++ b/Lib/idlelib/textview.py @@ -10,7 +10,7 @@ from idlelib.colorizer import color_config -class AutoHideScrollbar(Scrollbar): +class AutoShowScrollbar(Scrollbar): """A scrollbar that is automatically hidden when not needed. Only the grid geometry manager is supported. @@ -53,7 +53,7 @@ def __init__(self, master, wrap=NONE, **kwargs): self.grid_columnconfigure(0, weight=1) # vertical scrollbar - self.yscroll = AutoHideScrollbar(self, orient=VERTICAL, + self.yscroll = AutoShowScrollbar(self, orient=VERTICAL, takefocus=False, command=text.yview) self.yscroll.grid(row=0, column=1, sticky=NS) @@ -61,7 +61,7 @@ def __init__(self, master, wrap=NONE, **kwargs): # horizontal scrollbar - only when wrap is set to NONE if wrap == NONE: - self.xscroll = AutoHideScrollbar(self, orient=HORIZONTAL, + self.xscroll = AutoShowScrollbar(self, orient=HORIZONTAL, takefocus=False, command=text.xview) self.xscroll.grid(row=1, column=0, sticky=EW)