Skip to content

Commit

Permalink
Sorta fixed scrolling bug.
Browse files Browse the repository at this point in the history
Now the puzzle frame doesn't really expand to fit which is annoying.
  • Loading branch information
jesse-r-s-hines committed Apr 16, 2021
1 parent f82f1fd commit 5477514
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 6 additions & 4 deletions shell_adventure/gui.py
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions shell_adventure/scrolled_frame.py
Expand Up @@ -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('<Configure>', self._configure_interior)
self.interior.bind('<Configure>', lambda e: self._configure_interior())
self.canvas.bind('<Configure>', self._configure_canvas)
self.canvas.bind('<Enter>', self._bind_to_mousewheel)
self.canvas.bind('<Leave>', self._unbind_from_mousewheel)
Expand All @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit 5477514

Please sign in to comment.