CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

Minor improvements and recommendations (merak related)

Open rtommy opened this issue 1 year ago • 0 comments

To be able to use Merak package building toolkit some minor code change would be required.

Could you please let us know if these changes proposed here below could be done/accepted? (I left the original code line there commented out)

  1. root __init__.py Is there any specific reason to import os and sys here?
    __version__ = "5.2.2"
    
    #import os
    #import sys
    
  2. Add PACKAGE_ROOT to windows/widgets/utility/__init.py__
    from pathlib import Path
    PACKAGE_ROOT = Path(__file__).resolve().parents[3] # define package root for assets
    
  3. Modify windows/ctk_tk.py The utility import has different logic than other imports and add PACKAGE_ROOT:
    #from customtkinter.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty
    from .widgets.utility import pop_from_dict_by_set, check_kwargs_empty, PACKAGE_ROOT
    
    Use PACKAGE_ROOT:
    #customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    #self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico"))
    self.iconbitmap(str(PACKAGE_ROOT.joinpath("assets", "icons", "CustomTkinter_icon_Windows.ico")))
    
  4. Modify windows/ctk_toplevel.py The utility import has different logic than other imports and add PACKAGE_ROOT:
    #from customtkinter.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty
    from .widgets.utility import pop_from_dict_by_set, check_kwargs_empty, PACKAGE_ROOT
    
    Use PACKAGE_ROOT:
    #customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    #self.after(200, lambda: self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico")))
    self.after(200, lambda: self.iconbitmap(str(PACKAGE_ROOT.joinpath("assets", "icons", "CustomTkinter_icon_Windows.ico"))))
    
    and
    #customtkinter_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    #self.iconbitmap(os.path.join(customtkinter_directory, "assets", "icons", "CustomTkinter_icon_Windows.ico"))
    self.iconbitmap(str(PACKAGE_ROOT.joinpath("assets", "icons", "CustomTkinter_icon_Windows.ico")))
    
  5. Modify windows/widgets/fonts/__init.py__ Add PACKAGE_ROOT:
    from ..utility import PACKAGE_ROOT
    
    Use PACKAGE_ROOT:
    # load Roboto fonts (used on Windows/Linux)
    #customtkinter_directory = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
    #FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "Roboto", "Roboto-Regular.ttf"))
    #FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "Roboto", "Roboto-Medium.ttf"))
    FontManager.load_font(str(PACKAGE_ROOT.joinpath("assets", "fonts", "Roboto", "Roboto-Regular.ttf")))
    FontManager.load_font(str(PACKAGE_ROOT.joinpath("assets", "fonts", "Roboto", "Roboto-Medium.ttf")))
    
    # load font necessary for rendering the widgets (used on Windows/Linux)
    #if FontManager.load_font(os.path.join(customtkinter_directory, "assets", "fonts", "CustomTkinter_shapes_font.otf")) is False:
    if FontManager.load_font(str(PACKAGE_ROOT.joinpath("assets", "fonts", "CustomTkinter_shapes_font.otf"))) is False:
    
  6. Modify windows/widgets/themes/theme_manager.py Add PACKAGE_ROOT:
    from ..utility import PACKAGE_ROOT
    
    Use PACKAGE_ROOT:
    #customtkinter_path = pathlib.Path(script_directory).parent.parent.parent
    #with open(os.path.join(customtkinter_path, "assets", "themes", f"{theme_name_or_path}.json"), "r") as f:
    with open(str(PACKAGE_ROOT.joinpath("assets", "themes", f"{theme_name_or_path}.json")), "r") as f:
    

I can create a Pull request for these above, if that helps. I was able to test these on Windows but can't test on Linux or MacOS.

Thank you for your consideration!

rtommy avatar Oct 27 '24 05:10 rtommy