Skip to content

Commit

Permalink
restore old scrollable frame to level editor
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjosack committed Apr 2, 2021
1 parent df4e7e4 commit 4fde14e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/modlunky2/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.10
0.13.11
6 changes: 3 additions & 3 deletions src/modlunky2/ui/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
114 changes: 78 additions & 36 deletions src/modlunky2/ui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<<ThemeChange>>", 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("<Configure>", 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)

class ScrollableMixin(ttk.Frame):
def on_theme_change(self, _event):
background = self.style.lookup("TFrame", "background")
self.canvas.configure(background=background)
Expand Down Expand Up @@ -227,6 +192,83 @@ def _unbind_from_mousewheel(self, _event):
self.canvas.unbind_all("<Button-5>")



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("<<ThemeChange>>", 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("<Configure>", 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)




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("<<ThemeChange>>", 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("<Configure>", 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)


class PopupWindow(ttk.Frame):
def __init__(self, title, modlunky_config, *args, **kwargs):
self.shutting_down = False
Expand Down

0 comments on commit 4fde14e

Please sign in to comment.