From 4fde14eed488808d836f4d8a72cdcceb72f18896 Mon Sep 17 00:00:00 2001 From: "Gary M. Josack" Date: Thu, 1 Apr 2021 20:20:14 -0700 Subject: [PATCH] restore old scrollable frame to level editor --- src/modlunky2/VERSION | 2 +- src/modlunky2/ui/levels.py | 6 +- src/modlunky2/ui/widgets.py | 114 ++++++++++++++++++++++++------------ 3 files changed, 82 insertions(+), 40 deletions(-) diff --git a/src/modlunky2/VERSION b/src/modlunky2/VERSION index 3609c5241..5df22014c 100644 --- a/src/modlunky2/VERSION +++ b/src/modlunky2/VERSION @@ -1 +1 @@ -0.13.10 \ No newline at end of file +0.13.11 \ No newline at end of file diff --git a/src/modlunky2/ui/levels.py b/src/modlunky2/ui/levels.py index f70b7182f..1403c5510 100644 --- a/src/modlunky2/ui/levels.py +++ b/src/modlunky2/ui/levels.py @@ -27,7 +27,7 @@ from modlunky2.levels.tile_codes import VALID_TILE_CODES, TileCode, TileCodes from modlunky2.sprites import SpelunkySpriteFetcher from modlunky2.sprites.tilecode_extras import TILENAMES -from modlunky2.ui.widgets import PopupWindow, ScrollableFrameInner, Tab +from modlunky2.ui.widgets import PopupWindow, ScrollableFrameLegacy, Tab from modlunky2.utils import tb_info logger = logging.getLogger("modlunky2") @@ -558,8 +558,8 @@ def load_editor(self): # the tile palletes are loaded into here as buttons with their image # as a tile and txt as their value to grab when needed - self.tile_pallete = ScrollableFrameInner( - self.editor_tab, width=50 + self.tile_pallete = ScrollableFrameLegacy( + self.editor_tab, text="Tile Pallete", width=50 ) self.tile_pallete.grid(row=2, column=9, columnspan=4, rowspan=1, sticky="swne") self.tile_pallete.scrollable_frame["width"] = 50 diff --git a/src/modlunky2/ui/widgets.py b/src/modlunky2/ui/widgets.py index c4eb11c76..a39620f15 100644 --- a/src/modlunky2/ui/widgets.py +++ b/src/modlunky2/ui/widgets.py @@ -137,43 +137,8 @@ def __init__(self, parent, *args, **kwargs): super().__init__(self.inner.scrollable_frame) -# Adapted from https://gist.github.com/JackTheEngineer/81df334f3dcff09fd19e4169dd560c59 -class ScrollableFrameInner(ttk.Frame): - def __init__(self, parent, *args, **kw): - - super().__init__(parent, *args, **kw) - self.rowconfigure(0, weight=1) - self.columnconfigure(0, weight=1) - - # create a canvas object and a vertical scrollbar for scrolling it - self.vscrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL) - self.vscrollbar.grid(row=0, column=1, sticky="nse") - - self.style = ttk.Style() - background = self.style.lookup("TFrame", "background") - - self.canvas = tk.Canvas(self, bg=background, yscrollcommand=self.vscrollbar.set) - self.bind_all("<>", self.on_theme_change) - self.canvas.grid(row=0, column=0, sticky="nswe") - self.vscrollbar.config(command=self.canvas.yview) - - # reset the view - self.canvas.xview_moveto(0) - self.canvas.yview_moveto(0) - - # create a frame inside the canvas which will be scrolled with it - self.scrollable_frame = ttk.Frame(self.canvas) - self.scrollable_frame.columnconfigure(0, weight=1) - self.scrollable_frame.rowconfigure(0, weight=1) - self.interior_id = self.canvas.create_window( - 0, 0, window=self.scrollable_frame, anchor=tk.NW - ) - - self.scrollable_frame.bind("", self._configure_interior) - self.canvas.bind("", self._configure_canvas) - self.canvas.bind("", self._bind_to_mousewheel) - self.canvas.bind("", self._unbind_from_mousewheel) +class ScrollableMixin(ttk.Frame): def on_theme_change(self, _event): background = self.style.lookup("TFrame", "background") self.canvas.configure(background=background) @@ -227,6 +192,83 @@ def _unbind_from_mousewheel(self, _event): self.canvas.unbind_all("") + +class ScrollableFrameInner(ScrollableMixin, ttk.Frame): + def __init__(self, parent, *args, **kw): + + ttk.Frame.__init__(self, parent, *args, **kw) + self.rowconfigure(0, weight=1) + self.columnconfigure(0, weight=1) + +# Adapted from https://gist.github.com/JackTheEngineer/81df334f3dcff09fd19e4169dd560c59 + # create a canvas object and a vertical scrollbar for scrolling it + self.vscrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL) + self.vscrollbar.grid(row=0, column=1, sticky="nse") + + self.style = ttk.Style() + background = self.style.lookup("TFrame", "background") + + self.canvas = tk.Canvas(self, bg=background, yscrollcommand=self.vscrollbar.set) + self.bind_all("<>", self.on_theme_change) + self.canvas.grid(row=0, column=0, sticky="nswe") + self.vscrollbar.config(command=self.canvas.yview) + + # reset the view + self.canvas.xview_moveto(0) + self.canvas.yview_moveto(0) + + # create a frame inside the canvas which will be scrolled with it + self.scrollable_frame = ttk.Frame(self.canvas) + self.scrollable_frame.columnconfigure(0, weight=1) + self.scrollable_frame.rowconfigure(0, weight=1) + self.interior_id = self.canvas.create_window( + 0, 0, window=self.scrollable_frame, anchor=tk.NW + ) + + self.scrollable_frame.bind("", self._configure_interior) + self.canvas.bind("", self._configure_canvas) + self.canvas.bind("", self._bind_to_mousewheel) + self.canvas.bind("", self._unbind_from_mousewheel) + + + + +class ScrollableFrameLegacy(ScrollableMixin, ttk.LabelFrame): + def __init__(self, parent, *args, **kw): + + ttk.LabelFrame.__init__(self, parent, *args, **kw) + self.rowconfigure(0, weight=1) + self.columnconfigure(0, weight=1) + +# Adapted from https://gist.github.com/JackTheEngineer/81df334f3dcff09fd19e4169dd560c59 + # create a canvas object and a vertical scrollbar for scrolling it + self.vscrollbar = ttk.Scrollbar(self, orient=tk.VERTICAL) + self.vscrollbar.grid(row=0, column=1, sticky="nse") + + self.style = ttk.Style() + background = self.style.lookup("TFrame", "background") + + self.canvas = tk.Canvas(self, bg=background, yscrollcommand=self.vscrollbar.set) + self.bind_all("<>", self.on_theme_change) + self.canvas.grid(row=0, column=0, sticky="nswe") + self.vscrollbar.config(command=self.canvas.yview) + + # reset the view + self.canvas.xview_moveto(0) + self.canvas.yview_moveto(0) + + # create a frame inside the canvas which will be scrolled with it + self.scrollable_frame = ttk.Frame(self.canvas) + self.interior_id = self.canvas.create_window( + 0, 0, window=self.scrollable_frame, anchor=tk.NW + ) + + self.scrollable_frame.bind("", self._configure_interior) + self.canvas.bind("", self._configure_canvas) + self.canvas.bind("", self._bind_to_mousewheel) + self.canvas.bind("", self._unbind_from_mousewheel) + + class PopupWindow(ttk.Frame): def __init__(self, title, modlunky_config, *args, **kwargs): self.shutting_down = False