From 79cd10ddfde1152171a885b88814ea52b4d17565 Mon Sep 17 00:00:00 2001 From: demberto Date: Tue, 18 Apr 2023 18:50:20 +0530 Subject: [PATCH] rev. 2 --- customtkinter/windows/ctk_input_dialog.py | 1 - customtkinter/windows/ctk_tk.py | 2 +- customtkinter/windows/ctk_toplevel.py | 10 +++++----- customtkinter/windows/widgets/ctk_checkbox.py | 7 ++++++- customtkinter/windows/widgets/ctk_combobox.py | 8 ++++---- customtkinter/windows/widgets/ctk_entry.py | 4 ++-- customtkinter/windows/widgets/ctk_frame.py | 7 ++++--- .../windows/widgets/ctk_optionmenu.py | 7 ++++++- .../windows/widgets/ctk_radiobutton.py | 7 ++++++- .../windows/widgets/ctk_scrollbar.py | 2 +- customtkinter/windows/widgets/ctk_slider.py | 4 ++-- customtkinter/windows/widgets/ctk_switch.py | 7 ++++++- customtkinter/windows/widgets/ctk_textbox.py | 20 +++++++++---------- 13 files changed, 53 insertions(+), 33 deletions(-) diff --git a/customtkinter/windows/ctk_input_dialog.py b/customtkinter/windows/ctk_input_dialog.py index 49ea327..b1d3358 100644 --- a/customtkinter/windows/ctk_input_dialog.py +++ b/customtkinter/windows/ctk_input_dialog.py @@ -51,7 +51,6 @@ class CTkInputDialog(CTkToplevel): self.grab_set() # make other windows not clickable def _create_widgets(self): - self.grid_columnconfigure((0, 1), weight=1) self.rowconfigure(0, weight=1) diff --git a/customtkinter/windows/ctk_tk.py b/customtkinter/windows/ctk_tk.py index bc21cec..a31809b 100644 --- a/customtkinter/windows/ctk_tk.py +++ b/customtkinter/windows/ctk_tk.py @@ -197,7 +197,7 @@ class CTk(tkinter.Tk, CTkAppearanceModeBaseClass, CTkScalingBaseClass): super().geometry(self._apply_geometry_scaling(geometry_string)) # update width and height attributes - width, height, x, y = self._parse_geometry_string(geometry_string) + width, height, *_ = self._parse_geometry_string(geometry_string) if width is not None and height is not None: self._current_width = max(self._min_width, min(width, self._max_width)) # bound value between min and max self._current_height = max(self._min_height, min(height, self._max_height)) diff --git a/customtkinter/windows/ctk_toplevel.py b/customtkinter/windows/ctk_toplevel.py index 180ede9..50d6b0b 100644 --- a/customtkinter/windows/ctk_toplevel.py +++ b/customtkinter/windows/ctk_toplevel.py @@ -56,11 +56,11 @@ class CTkToplevel(tkinter.Toplevel, CTkAppearanceModeBaseClass, CTkScalingBaseCl self._current_width = 200 # initial window size, always without scaling self._current_height = 200 - self._min_width: int = 0 - self._min_height: int = 0 - self._max_width: int = 1_000_000 - self._max_height: int = 1_000_000 - self._last_resizable_args: tuple[list, dict] | None = None # (args, kwargs) + self._min_width: int | None = 0 + self._min_height: int | None = 0 + self._max_width: int | None = 1_000_000 + self._max_height: int | None = 1_000_000 + self._last_resizable_args: tuple[list[int], dict[str, float]] | None = None # (args, kwargs) self._fg_color = ThemeManager.theme["CTkToplevel"]["fg_color"] if fg_color is None else self._check_color_type(fg_color) diff --git a/customtkinter/windows/widgets/ctk_checkbox.py b/customtkinter/windows/widgets/ctk_checkbox.py index 515d5f3..bbdd0a2 100644 --- a/customtkinter/windows/widgets/ctk_checkbox.py +++ b/customtkinter/windows/widgets/ctk_checkbox.py @@ -4,6 +4,11 @@ import sys import tkinter from typing import Any, Callable +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + from .core_rendering import CTkCanvas, DrawEngine from .core_widget_classes import CTkBaseClass from .font import CTkFont @@ -36,7 +41,7 @@ class CTkCheckBox(CTkBaseClass): text: str = "CTkCheckBox", font: tuple[Any, ...] | CTkFont | None = None, textvariable: tkinter.Variable | None = None, - state: str = tkinter.NORMAL, + state: Literal["normal", "disabled", "readonly"] = "normal", hover: bool = True, command: Callable[[], None] | None = None, onvalue: int | str = 1, diff --git a/customtkinter/windows/widgets/ctk_combobox.py b/customtkinter/windows/widgets/ctk_combobox.py index 1b25a2a..a471b97 100644 --- a/customtkinter/windows/widgets/ctk_combobox.py +++ b/customtkinter/windows/widgets/ctk_combobox.py @@ -43,11 +43,11 @@ class CTkComboBox(CTkBaseClass): font: tuple[Any, ...] | CTkFont | None = None, dropdown_font: tuple[Any, ...] | CTkFont | None = None, values: list[str] | None = None, - state: str = tkinter.NORMAL, + state: Literal["normal", "disabled", "readonly"] = "normal", hover: bool = True, variable: tkinter.Variable | None = None, command: Callable[[str], None] | None = None, - justify: str = "left", + justify: Literal["left", "center", "right"] = "left", **kwargs: Any): # transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass @@ -401,13 +401,13 @@ class CTkComboBox(CTkBaseClass): if self._state is not tkinter.DISABLED and len(self._values) > 0: self._open_dropdown_menu() - def bind(self, sequence=None, command=None, add: Literal["+", True] = True): + def bind(self, sequence: str | None = None, command=None, add: Literal["+"] | bool = True): """ called on the tkinter.Entry """ if not (add == "+" or add is True): raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") self._entry.bind(sequence, command, add=True) - def unbind(self, sequence=None, funcid=None): + def unbind(self, sequence=None, funcid: str | None = None): """ called on the tkinter.Entry """ if funcid is not None: raise ValueError("'funcid' argument can only be None, because there is a bug in" + diff --git a/customtkinter/windows/widgets/ctk_entry.py b/customtkinter/windows/widgets/ctk_entry.py index 2066bed..09253fb 100644 --- a/customtkinter/windows/widgets/ctk_entry.py +++ b/customtkinter/windows/widgets/ctk_entry.py @@ -45,7 +45,7 @@ class CTkEntry(CTkBaseClass): textvariable: tkinter.Variable | None = None, placeholder_text: str | None = None, font: tuple[Any, ...] | CTkFont | None = None, - state: str = tkinter.NORMAL, + state: Literal["normal", "disabled", "readonly"] = "normal", **kwargs: Any): # transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass @@ -288,7 +288,7 @@ class CTkEntry(CTkBaseClass): else: return super().cget(attribute_name) # cget of CTkBaseClass - def bind(self, sequence=None, command=None, add: Literal["+", True] = True): + def bind(self, sequence=None, command=None, add: Literal["+"] | bool = True): """ called on the tkinter.Entry """ if not (add == "+" or add is True): raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") diff --git a/customtkinter/windows/widgets/ctk_frame.py b/customtkinter/windows/widgets/ctk_frame.py index 9202090..e4dd32d 100644 --- a/customtkinter/windows/widgets/ctk_frame.py +++ b/customtkinter/windows/widgets/ctk_frame.py @@ -1,7 +1,8 @@ from __future__ import annotations import sys -from typing import Any +import tkinter +from typing import Any, Callable if sys.version_info >= (3, 8): from typing import Literal @@ -189,13 +190,13 @@ class CTkFrame(CTkBaseClass): else: return super().cget(attribute_name) - def bind(self, sequence=None, command=None, add: Literal["+", True] = True): + def bind(self, sequence: str | None = None, command: Callable[[tkinter.Event[Any]], None] | None = None, add: Literal["+"] | bool = True): """ called on the tkinter.Canvas """ if not (add == "+" or add is True): raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") self._canvas.bind(sequence, command, add=True) - def unbind(self, sequence=None, funcid=None): + def unbind(self, sequence=None, funcid: str | None = None): """ called on the tkinter.Canvas """ if funcid is not None: raise ValueError("'funcid' argument can only be None, because there is a bug in" + diff --git a/customtkinter/windows/widgets/ctk_optionmenu.py b/customtkinter/windows/widgets/ctk_optionmenu.py index 2cb6ebc..96ef05d 100644 --- a/customtkinter/windows/widgets/ctk_optionmenu.py +++ b/customtkinter/windows/widgets/ctk_optionmenu.py @@ -5,6 +5,11 @@ import sys import tkinter from typing import Any, Callable +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + from .core_rendering import CTkCanvas, DrawEngine from .core_widget_classes import CTkBaseClass, DropdownMenu from .font import CTkFont @@ -37,7 +42,7 @@ class CTkOptionMenu(CTkBaseClass): dropdown_font: tuple[Any, ...] | CTkFont | None = None, values: list | None = None, variable: tkinter.Variable | None = None, - state: str = tkinter.NORMAL, + state: Literal["normal", "disabled", "readonly"] = "normal", hover: bool = True, command: Callable[[str], None] | None = None, dynamic_resizing: bool = True, diff --git a/customtkinter/windows/widgets/ctk_radiobutton.py b/customtkinter/windows/widgets/ctk_radiobutton.py index 0e10172..d6e516e 100644 --- a/customtkinter/windows/widgets/ctk_radiobutton.py +++ b/customtkinter/windows/widgets/ctk_radiobutton.py @@ -4,6 +4,11 @@ import sys import tkinter from typing import Any, Callable +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + from .core_rendering import CTkCanvas, DrawEngine from .core_widget_classes import CTkBaseClass from .font import CTkFont @@ -38,7 +43,7 @@ class CTkRadioButton(CTkBaseClass): textvariable: tkinter.Variable | None = None, variable: tkinter.Variable | None = None, value: int | str = 0, - state: str = tkinter.NORMAL, + state: Literal["normal", "disabled", "readonly"] = "normal", hover: bool = True, command: Callable[..., None] | None = None, **kwargs: Any): diff --git a/customtkinter/windows/widgets/ctk_scrollbar.py b/customtkinter/windows/widgets/ctk_scrollbar.py index 0a93b14..9180474 100644 --- a/customtkinter/windows/widgets/ctk_scrollbar.py +++ b/customtkinter/windows/widgets/ctk_scrollbar.py @@ -264,7 +264,7 @@ class CTkScrollbar(CTkBaseClass): def get(self): return self._start_value, self._end_value - def bind(self, sequence=None, command: Callable[..., None] | None = None, add: Literal["+", True] = True): + def bind(self, sequence=None, command: Callable[..., None] | None = None, add: Literal["+"] | bool = True): """ called on the tkinter.Canvas """ if not (add == "+" or add is True): raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks") diff --git a/customtkinter/windows/widgets/ctk_slider.py b/customtkinter/windows/widgets/ctk_slider.py index 20c5459..d036613 100644 --- a/customtkinter/windows/widgets/ctk_slider.py +++ b/customtkinter/windows/widgets/ctk_slider.py @@ -337,7 +337,7 @@ class CTkSlider(CTkBaseClass): fill=self._apply_appearance_mode(self._button_color), outline=self._apply_appearance_mode(self._button_color)) - def _round_to_step_size(self, value) -> float: + def _round_to_step_size(self, value: float) -> float: if self._number_of_steps is not None: step_size = (self._to - self._from_) / self._number_of_steps value = self._to - (round((self._to - value) / step_size) * step_size) @@ -348,7 +348,7 @@ class CTkSlider(CTkBaseClass): def get(self) -> float: return self._output_value - def set(self, output_value, from_variable_callback: bool = False): + def set(self, output_value: float, from_variable_callback: bool = False): if self._from_ < self._to: if output_value > self._to: output_value = self._to diff --git a/customtkinter/windows/widgets/ctk_switch.py b/customtkinter/windows/widgets/ctk_switch.py index 49f7398..68b87bf 100644 --- a/customtkinter/windows/widgets/ctk_switch.py +++ b/customtkinter/windows/widgets/ctk_switch.py @@ -4,6 +4,11 @@ import sys import tkinter from typing import Any, Callable +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + from .core_rendering import CTkCanvas, DrawEngine from .core_widget_classes import CTkBaseClass from .font import CTkFont @@ -43,7 +48,7 @@ class CTkSwitch(CTkBaseClass): variable: tkinter.Variable | None = None, hover: bool = True, command: Callable[..., None] | None = None, - state: str = tkinter.NORMAL, + state: Literal["normal", "disabled", "readonly"] = "normal", **kwargs: Any): # transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass diff --git a/customtkinter/windows/widgets/ctk_textbox.py b/customtkinter/windows/widgets/ctk_textbox.py index 36035bd..b15d871 100644 --- a/customtkinter/windows/widgets/ctk_textbox.py +++ b/customtkinter/windows/widgets/ctk_textbox.py @@ -129,7 +129,7 @@ class CTkTextbox(CTkBaseClass): self.after(50, self._check_if_scrollbars_needed, None, True) self._draw() - def _create_grid_for_text_and_scrollbars(self, re_grid_textbox=False, re_grid_x_scrollbar=False, re_grid_y_scrollbar=False): + def _create_grid_for_text_and_scrollbars(self, re_grid_textbox: bool = False, re_grid_x_scrollbar: bool = False, re_grid_y_scrollbar: bool = False): # configure 2x2 grid self.grid_rowconfigure(0, weight=1) @@ -158,7 +158,7 @@ class CTkTextbox(CTkBaseClass): else: self._y_scrollbar.grid_forget() - def _check_if_scrollbars_needed(self, event=None, continue_loop: bool = False): + def _check_if_scrollbars_needed(self, event: tkinter.Event[Any] | None = None, continue_loop: bool = False): """ Method hides or places the scrollbars if they are needed on key release event of tkinter.text widget """ if self._scrollbars_activated: @@ -355,7 +355,7 @@ class CTkTextbox(CTkBaseClass): def focus_force(self): return self._textbox.focus_force() - def insert(self, index: int, text, tags=None): + def insert(self, index: int, text: str, tags=None): return self._textbox.insert(index, text, tags) def get(self, index1, index2=None): @@ -435,16 +435,16 @@ class CTkTextbox(CTkBaseClass): def see(self, index): return self._textbox.see(index) - def tag_add(self, tagName, index1, index2=None): + def tag_add(self, tagName: str, index1, index2=None): return self._textbox.tag_add(tagName, index1, index2) - def tag_bind(self, tagName, sequence, func, add=None): + def tag_bind(self, tagName: str, sequence: str, func, add: bool | Literal["", "+"] | None = None): return self._textbox.tag_bind(tagName, sequence, func, add) - def tag_cget(self, tagName, option): + def tag_cget(self, tagName: str, option: str): return self._textbox.tag_cget(tagName, option) - def tag_config(self, tagName, **kwargs: Any): + def tag_config(self, tagName: str, **kwargs: Any): if "font" in kwargs: raise AttributeError("'font' option forbidden, because would be incompatible with scaling") return self._textbox.tag_config(tagName, **kwargs) @@ -476,10 +476,10 @@ class CTkTextbox(CTkBaseClass): def tag_unbind(self, tagName: str, sequence, funcid=None): return self._textbox.tag_unbind(tagName, sequence, funcid) - def window_cget(self, index: int, option): + def window_cget(self, index: int, option: str): raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)") - def window_configure(self, index: int, option): + def window_configure(self, index: int, option: str): raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)") def window_create(self, index: int, **kwargs: Any): @@ -500,7 +500,7 @@ class CTkTextbox(CTkBaseClass): def yview(self, *args): return self._textbox.yview(*args) - def yview_moveto(self, fraction): + def yview_moveto(self, fraction: float): return self._textbox.yview_moveto(fraction) def yview_scroll(self, n, what):