From 5477514f58b8de6a53a7e83c376fb7d2b072fd24 Mon Sep 17 00:00:00 2001 From: Jesse Hines Date: Fri, 16 Apr 2021 11:03:06 -0400 Subject: [PATCH] Sorta fixed scrolling bug. Now the puzzle frame doesn't really expand to fit which is annoying. --- shell_adventure/gui.py | 10 ++++++---- shell_adventure/scrolled_frame.py | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/shell_adventure/gui.py b/shell_adventure/gui.py index c5257dc..bc05774 100644 --- a/shell_adventure/gui.py +++ b/shell_adventure/gui.py @@ -35,16 +35,18 @@ def __init__(self, tutorial: tutorial.Tutorial): self.title("Shell Adventure") self.minsize(300, 100) # To keep you from being able to shrink everything off the screen. self.columnconfigure(0, weight = 1, minsize = 80) - self.rowconfigure(0, weight = 1, minsize = 80) + self.rowconfigure(0, weight = 0) + self.rowconfigure(1, weight = 1, minsize = 80) + self.rowconfigure(2, weight = 0) status_bar = self.make_status_bar(self) - status_bar.pack(side = tk.TOP, fill = tk.X, expand = False) + status_bar.grid(row = 0, column = 0, sticky = "WE") self.file_tree = self.make_file_tree(self) - self.file_tree.pack(side = tk.TOP, fill = tk.BOTH, expand = True) + self.file_tree.grid(row = 1, column = 0, sticky = "NSWE") self.puzzle_frame = self.make_puzzle_frame(self) - self.puzzle_frame.pack(side = tk.BOTTOM, fill = tk.BOTH, expand = True) + self.puzzle_frame.grid(row = 2, column = 0, sticky = "NSWE") self.update_puzzle_frame() def update_loop(): # TODO make this trigger after every command instead of on a loop diff --git a/shell_adventure/scrolled_frame.py b/shell_adventure/scrolled_frame.py index 31a0bf3..ed1ae8c 100644 --- a/shell_adventure/scrolled_frame.py +++ b/shell_adventure/scrolled_frame.py @@ -35,7 +35,7 @@ def __init__(self, parent, *args, **kw): self.interior_id = self.canvas.create_window(0, 0, window=self.interior, anchor=tk.NW) - self.interior.bind('', self._configure_interior) + self.interior.bind('', lambda e: self._configure_interior()) self.canvas.bind('', self._configure_canvas) self.canvas.bind('', self._bind_to_mousewheel) self.canvas.bind('', self._unbind_from_mousewheel) @@ -44,7 +44,7 @@ def __init__(self, parent, *args, **kw): # track changes to the canvas and frame width and sync them, # also updating the scrollbar - def _configure_interior(self, event): + def _configure_interior(self): # update the scrollbars to match the size of the inner frame size = (self.interior.winfo_reqwidth(), self.interior.winfo_reqheight()) self.canvas.config(scrollregion="0 0 %s %s" % size) @@ -54,12 +54,22 @@ def _configure_interior(self, event): # # update the canvas's width to fit the inner frame # self.canvas.config(width=self.interior.winfo_reqwidth()) + # This seems to make the canvas shrink to fit if the content is smaller than requested hight. + # But you still have to back the VerticalScroll with expand = False. I'm not sure how to fix it + # so that it will expand. + if self.interior.winfo_reqheight() < self.canvas.winfo_height(): + self.canvas.config(height = self.interior.winfo_reqheight()) + elif self.canvas.winfo_height() != self.winfo_height(): + self.canvas.config(height = self.winfo_height()) + + def _configure_canvas(self, event): - if self.interior.winfo_reqwidth() != self.winfo_width(): + if self.interior.winfo_reqwidth() != event.width: # update the inner frame's width to fill the canvas # Jesse: Changing this to from `self.winfo_width` to `event.width` seems to fix a minor # spacing issue where the scrollbar was covering part of the buttons. self.canvas.itemconfigure(self.interior_id, width=event.width) + self._configure_interior() # This can now handle either windows or linux platforms def _on_mousewheel(self, event, scroll=None):