Skip to content

Commit

Permalink
Fix image issues in toplevel previews. refs alejandroautalan/pygubu-d…
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroautalan committed Feb 26, 2024
1 parent 1cb50f9 commit 38a2675
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/pygubu/plugins/customtkinter/designer/designerplugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pygubu.api.v1 import IPluginBase, IDesignerPlugin
from pygubu.utils.widget import crop_widget
from pygubu.stockimage import StockRegistry, StockImageCache, StockImage
from .preview import (
CTkToplevelPreviewBO,
CTkPreviewBO,
Expand Down Expand Up @@ -30,6 +31,12 @@ def get_toplevel_preview_for(
top = None
toplevel_uids = ("customtkinter.CTkToplevel", "customtkinter.CTk")
if builder_uid in toplevel_uids:
# for a new tk root, create a diferent image cache:
def on_root_created(root):
image_cache = StockImageCache(root, StockImage.registry)
builder.image_cache = image_cache

builder.on_first_object = on_root_created
top = builder.get_object(widget_id)
return top

Expand Down
7 changes: 7 additions & 0 deletions src/pygubu/plugins/pygubu/designer/designerplugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pygubu.api.v1 import IDesignerPlugin
from pygubu.utils.widget import crop_widget
from pygubu.stockimage import StockRegistry, StockImageCache, StockImage
from .toplevelframe import ToplevelFramePreviewBO


Expand All @@ -20,6 +21,12 @@ def get_toplevel_preview_for(
if builder_uid == "tk.Toplevel":
top = builder.get_object(widget_id, top_master)
elif builder_uid == "tk.Tk":
# for a new tk root, create a diferent image cache:
def on_root_created(root):
image_cache = StockImageCache(root, StockImage.registry)
builder.image_cache = image_cache

builder.on_first_object = on_root_created
top = builder.get_object(widget_id)
elif builder_uid == "pygubu.builder.widgets.dialog":
dialog = builder.get_object(widget_id, top_master)
Expand Down

0 comments on commit 38a2675

Please sign in to comment.