<commit_before>from pygubu.api.v1 import register_widget, register_custom_property
from pygubu.i18n import _
from pygubu.plugins.tk.tkstdwidgets import TKToplevel as TKToplevelBO
from customtkinter import (
    CTk,
    CTkToplevel,
    set_appearance_mode,
    set_default_color_theme,
)

from ..customtkinter import _designer_tab_label, _plugin_uid
from .ctkbase import CTkBaseMixin


class CTkBO(TKToplevelBO):
    class_ = CTk
    properties = TKToplevelBO.properties + (
        "appearance_mode",
        "color_theme",
        "fg_color",
    )
    ro_properties = TKToplevelBO.ro_properties + ("background", "fg_color")

    def realize(self, parent):
        # Call realize from BuilderObject not Toplevel.
        return super(TKToplevelBO, self).realize(parent)

    def _set_property(self, target_widget, pname, value):
        if pname == "appearance_mode":
            set_appearance_mode(value)
        elif pname == "color_theme":
            set_default_color_theme(value)
        else:
            return super()._set_property(target_widget, pname, value)

    def _code_set_property(self, targetid, pname, value, code_bag):
        if pname == "appearance_mode":
            code_bag[pname] = (f'set_appearance_mode("{value}")',)
        elif pname == "color_theme":
            code_bag[pname] = (f'set_default_color_theme("{value}")',)
        else:
            super()._code_set_property(targetid, pname, value, code_bag)

    def code_imports(self):
        imports = ["CTk"]
        if "appearance_mode" in self.wmeta.properties:
            imports.append("set_appearance_mode")
        if "color_theme" in self.wmeta.properties:
            imports.append("set_default_color_theme")
        return [("customtkinter", name) for name in imports]


_builder_uid = f"{_plugin_uid}.CTk"
register_widget(
    _builder_uid,
    CTkBO,
    "CTk",
    ("ttk", _designer_tab_label),
    group=-1,
)


class CTkToplevelBO(TKToplevelBO):
    class_ = CTkToplevel
    properties = TKToplevelBO.properties + ("fg_color",)
    ro_properties = TKToplevelBO.ro_properties + ("background", "fg_color")

    def realize(self, parent):
        # Call realize from BuilderObject not Toplevel.
        return super(TKToplevelBO, self).realize(parent)

    def code_imports(self):
        return [("customtkinter", self.class_.__name__)]


_builder_uid = f"{_plugin_uid}.CTkToplevel"
register_widget(
    _builder_uid,
    CTkToplevelBO,
    "CTkToplevel",
    ("ttk", _designer_tab_label),
    group=-1,
)<commit_msg>Fix minsize, maxsize editors for customtkinter Ctk and Toplevel.<commit_after>from pygubu.api.v1 import register_widget, register_custom_property
from pygubu.i18n import _
from pygubu.plugins.tk.tkstdwidgets import TKToplevel as TKToplevelBO
from customtkinter import (
    CTk,
    CTkToplevel,
    set_appearance_mode,
    set_default_color_theme,
)

from ..customtkinter import _designer_tab_label, _plugin_uid
from .ctkbase import CTkBaseMixin


class CTkBO(TKToplevelBO):
    class_ = CTk
    properties = TKToplevelBO.properties + (
        "appearance_mode",
        "color_theme",
        "fg_color",
    )
    ro_properties = TKToplevelBO.ro_properties + ("background", "fg_color")

    def realize(self, parent):
        # Call realize from BuilderObject not Toplevel.
        return super(TKToplevelBO, self).realize(parent)

    def _set_property(self, target_widget, pname, value):
        if pname == "appearance_mode":
            set_appearance_mode(value)
        elif pname == "color_theme":
            set_default_color_theme(value)
        else:
            return super()._set_property(target_widget, pname, value)

    def _code_set_property(self, targetid, pname, value, code_bag):
        if pname == "appearance_mode":
            code_bag[pname] = (f'set_appearance_mode("{value}")',)
        elif pname == "color_theme":
            code_bag[pname] = (f'set_default_color_theme("{value}")',)
        else:
            super()._code_set_property(targetid, pname, value, code_bag)

    def code_imports(self):
        imports = ["CTk"]
        if "appearance_mode" in self.wmeta.properties:
            imports.append("set_appearance_mode")
        if "color_theme" in self.wmeta.properties:
            imports.append("set_default_color_theme")
        return [("customtkinter", name) for name in imports]


_builder_uid = f"{_plugin_uid}.CTk"
register_widget(
    _builder_uid,
    CTkBO,
    "CTk",
    ("ttk", _designer_tab_label),
    group=-1,
)

_maxsize_help = _("Set the maximum window size.")
_minsize_help = _("Set the minimum window size.")

register_custom_property(
    _builder_uid,
    "minsize",
    "whentry",
    help=_minsize_help,
)
register_custom_property(
    _builder_uid,
    "maxsize",
    "whentry",
    help=_maxsize_help,
)


class CTkToplevelBO(TKToplevelBO):
    class_ = CTkToplevel
    properties = TKToplevelBO.properties + ("fg_color",)
    ro_properties = TKToplevelBO.ro_properties + ("background", "fg_color")

    def realize(self, parent):
        # Call realize from BuilderObject not Toplevel.
        return super(TKToplevelBO, self).realize(parent)

    def code_imports(self):
        return [("customtkinter", self.class_.__name__)]


_builder_uid = f"{_plugin_uid}.CTkToplevel"
register_widget(
    _builder_uid,
    CTkToplevelBO,
    "CTkToplevel",
    ("ttk", _designer_tab_label),
    group=-1,
)

register_custom_property(
    _builder_uid,
    "minsize",
    "whentry",
    help=_minsize_help,
)
register_custom_property(
    _builder_uid,
    "maxsize",
    "whentry",
    help=_maxsize_help,
)
{'fraction_non_alphanumeric': 0.10578984989278056, 'fraction_numerical': 0.0017869907076483202, 'mean_word_length': 3.369242779078845, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3303126', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1893, 'n_words': 362}