Skip to content

Commit

Permalink
Avoid wobbling of AutomaticScrollbar, thonny#2258
Browse files Browse the repository at this point in the history
  • Loading branch information
aivarannamaa committed Apr 30, 2022
1 parent 30d57ef commit 9baf5f6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Version history
* Fix error when trying to open a file from file browser with ENTER, #1785
* Fix support for remote Python 3 over SSH (regression introduced in one of the 4.0.0 betas), #2249
* Support CircuitPython with micro:bit, #2251
* Avoid wobbling of AutomaticScrollbar, helpful report by @TooLazy0x00, #2258

4.0.0b2 (2022-04-09)
====================
Expand Down
28 changes: 26 additions & 2 deletions thonny/ui_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,16 +970,40 @@ class AutoScrollbar(SafeScrollbar):
# works if you use the grid geometry manager.

def __init__(self, master=None, **kw):
self.hide_count = 0
self.gridded = False
super().__init__(master=master, **kw)

def set(self, first, last):
if float(first) <= 0.0 and float(last) >= 1.0:
self.grid_remove()
# Need to accept 1 automatic hide, otherwise even narrow files
# get horizontal scrollbar
if self.gridded and self.hide_count < 2:
self.grid_remove()
elif float(first) > 0.001 or float(last) < 0.999:
# with >0 and <1 it occasionally made scrollbar wobble back and forth
self.grid()
if not self.gridded:
self.grid()
ttk.Scrollbar.set(self, first, last)

def grid(self, *args, **kwargs):
super().grid(*args, **kwargs)
self.gridded = True

def grid_configure(self, *args, **kwargs):
super().grid_configure(*args, **kwargs)
self.gridded = True

def grid_remove(self):
super().grid_remove()
self.gridded = False
self.hide_count += 1

def grid_forget(self):
super().grid_forget()
self.gridded = False
self.hide_count += 1

def pack(self, **kw):
raise tk.TclError("cannot use pack with this widget")

Expand Down

0 comments on commit 9baf5f6

Please sign in to comment.