mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
rev. 1
This commit is contained in:
@ -1,16 +1,24 @@
|
||||
import tkinter
|
||||
from distutils.version import StrictVersion as Version
|
||||
import sys
|
||||
from __future__ import annotations
|
||||
|
||||
import ctypes
|
||||
import os
|
||||
import platform
|
||||
import ctypes
|
||||
from typing import Union, Tuple, Optional
|
||||
import sys
|
||||
import tkinter
|
||||
from distutils.version import StrictVersion as Version
|
||||
from typing import Any
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
from typing import Literal
|
||||
else:
|
||||
from typing_extensions import Literal
|
||||
|
||||
from customtkinter.windows.widgets.utility.utility_functions import (
|
||||
check_kwargs_empty, pop_from_dict_by_set)
|
||||
|
||||
from .widgets.theme import ThemeManager
|
||||
from .widgets.scaling import CTkScalingBaseClass
|
||||
from .widgets.appearance_mode import CTkAppearanceModeBaseClass
|
||||
|
||||
from customtkinter.windows.widgets.utility.utility_functions import pop_from_dict_by_set, check_kwargs_empty
|
||||
from .widgets.scaling import CTkScalingBaseClass
|
||||
from .widgets.theme import ThemeManager
|
||||
|
||||
|
||||
class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseClass):
|
||||
@ -19,16 +27,16 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
For detailed information check out the documentation.
|
||||
"""
|
||||
|
||||
_valid_tk_toplevel_arguments: set = {"bd", "borderwidth", "class", "container", "cursor", "height",
|
||||
"highlightbackground", "highlightthickness", "menu", "relief",
|
||||
"screen", "takefocus", "use", "visual", "width"}
|
||||
_valid_tk_toplevel_arguments: set[str] = {"bd", "borderwidth", "class", "container", "cursor", "height",
|
||||
"highlightbackground", "highlightthickness", "menu", "relief",
|
||||
"screen", "takefocus", "use", "visual", "width"}
|
||||
|
||||
_deactivate_macos_window_header_manipulation: bool = False
|
||||
_deactivate_windows_window_header_manipulation: bool = False
|
||||
|
||||
def __init__(self, *args,
|
||||
fg_color: Optional[Union[str, Tuple[str, str]]] = None,
|
||||
**kwargs):
|
||||
def __init__(self, *args: Any,
|
||||
fg_color: str | tuple[str, str] | None = None,
|
||||
**kwargs: Any):
|
||||
|
||||
self._enable_macos_dark_title_bar()
|
||||
|
||||
@ -52,7 +60,7 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
self._min_height: int = 0
|
||||
self._max_width: int = 1_000_000
|
||||
self._max_height: int = 1_000_000
|
||||
self._last_resizable_args: Union[Tuple[list, dict], None] = None # (args, kwargs)
|
||||
self._last_resizable_args: tuple[list, dict] | None = None # (args, kwargs)
|
||||
|
||||
self._fg_color = ThemeManager.theme["CTkToplevel"]["fg_color"] if fg_color is None else self._check_color_type(fg_color)
|
||||
|
||||
@ -92,12 +100,12 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
CTkAppearanceModeBaseClass.destroy(self)
|
||||
CTkScalingBaseClass.destroy(self)
|
||||
|
||||
def _focus_in_event(self, event):
|
||||
def _focus_in_event(self, event: tkinter.Event[Any] | None = None):
|
||||
# sometimes window looses jumps back on macOS if window is selected from Mission Control, so has to be lifted again
|
||||
if sys.platform == "darwin":
|
||||
self.lift()
|
||||
|
||||
def _update_dimensions_event(self, event=None):
|
||||
def _update_dimensions_event(self, event: tkinter.Event[Any] | None = None):
|
||||
if not self._block_update_dimensions_event:
|
||||
detected_width = self.winfo_width() # detect current window size
|
||||
detected_height = self.winfo_height()
|
||||
@ -106,7 +114,7 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
self._current_width = self._reverse_window_scaling(detected_width) # adjust current size according to new size given by event
|
||||
self._current_height = self._reverse_window_scaling(detected_height) # _current_width and _current_height are independent of the scale
|
||||
|
||||
def _set_scaling(self, new_widget_scaling, new_window_scaling):
|
||||
def _set_scaling(self, new_widget_scaling: float, new_window_scaling: float):
|
||||
super()._set_scaling(new_widget_scaling, new_window_scaling)
|
||||
|
||||
# Force new dimensions on window by using min, max, and geometry. Without min, max it won't work.
|
||||
@ -130,7 +138,7 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
if self._max_width is not None or self._max_height is not None:
|
||||
super().maxsize(self._apply_window_scaling(self._max_width), self._apply_window_scaling(self._max_height))
|
||||
|
||||
def geometry(self, geometry_string: str = None):
|
||||
def geometry(self, geometry_string: str | None = None):
|
||||
if geometry_string is not None:
|
||||
super().geometry(self._apply_geometry_scaling(geometry_string))
|
||||
|
||||
@ -152,7 +160,7 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
self._iconify_called_after_windows_set_titlebar_color = True
|
||||
super().iconify()
|
||||
|
||||
def resizable(self, width: bool = None, height: bool = None):
|
||||
def resizable(self, width: bool | None = None, height: bool | None = None):
|
||||
current_resizable_values = super().resizable(width, height)
|
||||
self._last_resizable_args = ([], {"width": width, "height": height})
|
||||
|
||||
@ -161,7 +169,7 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
|
||||
return current_resizable_values
|
||||
|
||||
def minsize(self, width=None, height=None):
|
||||
def minsize(self, width: int | None = None, height: int | None = None):
|
||||
self._min_width = width
|
||||
self._min_height = height
|
||||
if self._current_width < width:
|
||||
@ -170,7 +178,7 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
self._current_height = height
|
||||
super().minsize(self._apply_window_scaling(self._min_width), self._apply_window_scaling(self._min_height))
|
||||
|
||||
def maxsize(self, width=None, height=None):
|
||||
def maxsize(self, width: int | None = None, height: int | None = None):
|
||||
self._max_width = width
|
||||
self._max_height = height
|
||||
if self._current_width > width:
|
||||
@ -179,7 +187,7 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
self._current_height = height
|
||||
super().maxsize(self._apply_window_scaling(self._max_width), self._apply_window_scaling(self._max_height))
|
||||
|
||||
def configure(self, **kwargs):
|
||||
def configure(self, **kwargs: Any):
|
||||
if "fg_color" in kwargs:
|
||||
self._fg_color = self._check_color_type(kwargs.pop("fg_color"))
|
||||
super().configure(bg=self._apply_appearance_mode(self._fg_color))
|
||||
@ -193,15 +201,15 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
super().configure(**pop_from_dict_by_set(kwargs, self._valid_tk_toplevel_arguments))
|
||||
check_kwargs_empty(kwargs)
|
||||
|
||||
def cget(self, attribute_name: str) -> any:
|
||||
def cget(self, attribute_name: str) -> Any:
|
||||
if attribute_name == "fg_color":
|
||||
return self._fg_color
|
||||
else:
|
||||
return super().cget(attribute_name)
|
||||
|
||||
def wm_iconbitmap(self, bitmap=None, default=None):
|
||||
def wm_iconbitmap(self, bitmap: Any = None, default: Any = None):
|
||||
self._iconbitmap_method_called = True
|
||||
super().wm_iconbitmap(bitmap, default)
|
||||
super().wm_iconbitmap(bitmap, default) # type: ignore
|
||||
|
||||
def _windows_set_titlebar_icon(self):
|
||||
try:
|
||||
@ -298,7 +306,7 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl
|
||||
self._withdraw_called_after_windows_set_titlebar_color = False
|
||||
self._iconify_called_after_windows_set_titlebar_color = False
|
||||
|
||||
def _set_appearance_mode(self, mode_string):
|
||||
def _set_appearance_mode(self, mode_string: Literal["light", "dark"]):
|
||||
super()._set_appearance_mode(mode_string)
|
||||
|
||||
if sys.platform.startswith("win"):
|
||||
|
Reference in New Issue
Block a user