2022-06-28 12:16:28 +03:00
|
|
|
import tkinter
|
2022-12-06 20:09:20 +03:00
|
|
|
from typing import Union, Tuple, Optional, Callable
|
2022-06-28 12:16:28 +03:00
|
|
|
|
2022-11-29 21:06:33 +03:00
|
|
|
from .core_rendering import CTkCanvas
|
2022-10-05 19:39:45 +03:00
|
|
|
from .ctk_scrollbar import CTkScrollbar
|
2022-11-29 21:06:33 +03:00
|
|
|
from .theme import ThemeManager
|
|
|
|
from .core_rendering import DrawEngine
|
|
|
|
from .core_widget_classes import CTkBaseClass
|
|
|
|
from .font import CTkFont
|
|
|
|
from .utility import pop_from_dict_by_set, check_kwargs_empty
|
2022-10-04 04:03:43 +03:00
|
|
|
|
2022-06-28 12:16:28 +03:00
|
|
|
|
|
|
|
class CTkTextbox(CTkBaseClass):
|
2022-10-02 04:23:10 +03:00
|
|
|
"""
|
2022-10-05 19:39:45 +03:00
|
|
|
Textbox with x and y scrollbars, rounded corners, and all text features of tkinter.Text widget.
|
|
|
|
Scrollbars only appear when they are needed. Text is wrapped on line end by default,
|
|
|
|
set wrap='none' to disable automatic line wrapping.
|
2022-10-02 04:23:10 +03:00
|
|
|
For detailed information check out the documentation.
|
2022-10-05 11:35:41 +03:00
|
|
|
|
|
|
|
Detailed methods and parameters of the underlaying tkinter.Text widget can be found here:
|
|
|
|
https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/text.html
|
|
|
|
(most of them are implemented here too)
|
2022-10-02 04:23:10 +03:00
|
|
|
"""
|
|
|
|
|
2022-10-05 19:39:45 +03:00
|
|
|
_scrollbar_update_time = 200 # interval in ms, to check if scrollbars are needed
|
|
|
|
|
2022-10-04 04:03:43 +03:00
|
|
|
# attributes that are passed to and managed by the tkinter textbox only:
|
|
|
|
_valid_tk_text_attributes = {"autoseparators", "cursor", "exportselection",
|
|
|
|
"insertborderwidth", "insertofftime", "insertontime", "insertwidth",
|
|
|
|
"maxundo", "padx", "pady", "selectborderwidth", "spacing1",
|
|
|
|
"spacing2", "spacing3", "state", "tabs", "takefocus", "undo", "wrap",
|
|
|
|
"xscrollcommand", "yscrollcommand"}
|
|
|
|
|
2022-10-06 16:53:52 +03:00
|
|
|
def __init__(self,
|
2022-11-11 01:27:55 +03:00
|
|
|
master: any,
|
2022-10-03 01:33:06 +03:00
|
|
|
width: int = 200,
|
|
|
|
height: int = 200,
|
2022-11-11 01:27:55 +03:00
|
|
|
corner_radius: Optional[int] = None,
|
|
|
|
border_width: Optional[int] = None,
|
2022-10-05 19:39:45 +03:00
|
|
|
border_spacing: int = 3,
|
2022-10-03 01:33:06 +03:00
|
|
|
|
2022-11-11 01:27:55 +03:00
|
|
|
bg_color: Union[str, Tuple[str, str]] = "transparent",
|
|
|
|
fg_color: Optional[Union[str, Tuple[str, str]]] = None,
|
|
|
|
border_color: Optional[Union[str, Tuple[str, str]]] = None,
|
|
|
|
text_color: Optional[Union[str, str]] = None,
|
2022-11-27 04:48:09 +03:00
|
|
|
scrollbar_button_color: Optional[Union[str, Tuple[str, str]]] = None,
|
|
|
|
scrollbar_button_hover_color: Optional[Union[str, Tuple[str, str]]] = None,
|
2022-10-03 01:33:06 +03:00
|
|
|
|
2022-11-11 01:27:55 +03:00
|
|
|
font: Optional[Union[tuple, CTkFont]] = None,
|
2022-10-05 19:39:45 +03:00
|
|
|
activate_scrollbars: bool = True,
|
2022-06-28 12:16:28 +03:00
|
|
|
**kwargs):
|
|
|
|
|
2022-11-01 02:37:30 +03:00
|
|
|
# transfer basic functionality (_bg_color, size, __appearance_mode, scaling) to CTkBaseClass
|
2022-10-06 16:53:52 +03:00
|
|
|
super().__init__(master=master, bg_color=bg_color, width=width, height=height)
|
2022-06-28 12:16:28 +03:00
|
|
|
|
|
|
|
# color
|
2022-11-27 04:48:09 +03:00
|
|
|
self._fg_color = ThemeManager.theme["CTkTextbox"]["fg_color"] if fg_color is None else self._check_color_type(fg_color, transparency=True)
|
|
|
|
self._border_color = ThemeManager.theme["CTkTextbox"]["border_color"] if border_color is None else self._check_color_type(border_color)
|
|
|
|
self._text_color = ThemeManager.theme["CTkTextbox"]["text_color"] if text_color is None else self._check_color_type(text_color)
|
|
|
|
self._scrollbar_button_color = ThemeManager.theme["CTkTextbox"]["scrollbar_button_color"] if scrollbar_button_color is None else self._check_color_type(scrollbar_button_color)
|
|
|
|
self._scrollbar_button_hover_color = ThemeManager.theme["CTkTextbox"]["scrollbar_button_hover_color"] if scrollbar_button_hover_color is None else self._check_color_type(scrollbar_button_hover_color)
|
2022-06-28 12:16:28 +03:00
|
|
|
|
|
|
|
# shape
|
2022-11-27 04:48:09 +03:00
|
|
|
self._corner_radius = ThemeManager.theme["CTkTextbox"]["corner_radius"] if corner_radius is None else corner_radius
|
|
|
|
self._border_width = ThemeManager.theme["CTkTextbox"]["border_width"] if border_width is None else border_width
|
2022-10-05 19:39:45 +03:00
|
|
|
self._border_spacing = border_spacing
|
2022-06-28 12:16:28 +03:00
|
|
|
|
2022-10-22 16:08:13 +03:00
|
|
|
# font
|
2022-11-11 01:27:55 +03:00
|
|
|
self._font = CTkFont() if font is None else self._check_font_type(font)
|
2022-10-22 16:08:13 +03:00
|
|
|
if isinstance(self._font, CTkFont):
|
|
|
|
self._font.add_size_configure_callback(self._update_font)
|
2022-06-28 12:16:28 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas = CTkCanvas(master=self,
|
|
|
|
highlightthickness=0,
|
2022-11-06 16:40:15 +03:00
|
|
|
width=self._apply_widget_scaling(self._desired_width),
|
|
|
|
height=self._apply_widget_scaling(self._desired_height))
|
2022-10-22 16:08:13 +03:00
|
|
|
self._canvas.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="nsew")
|
2022-10-29 02:20:32 +03:00
|
|
|
self._canvas.configure(bg=self._apply_appearance_mode(self._bg_color))
|
2022-10-02 04:23:10 +03:00
|
|
|
self._draw_engine = DrawEngine(self._canvas)
|
2022-06-28 12:16:28 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._textbox = tkinter.Text(self,
|
2022-10-29 02:20:32 +03:00
|
|
|
fg=self._apply_appearance_mode(self._text_color),
|
2022-10-02 04:23:10 +03:00
|
|
|
width=0,
|
|
|
|
height=0,
|
2022-10-05 19:39:45 +03:00
|
|
|
font=self._apply_font_scaling(self._font),
|
2022-10-02 04:23:10 +03:00
|
|
|
highlightthickness=0,
|
|
|
|
relief="flat",
|
2022-10-29 02:20:32 +03:00
|
|
|
insertbackground=self._apply_appearance_mode(self._text_color),
|
2022-10-04 04:03:43 +03:00
|
|
|
**pop_from_dict_by_set(kwargs, self._valid_tk_text_attributes))
|
2022-10-02 04:23:10 +03:00
|
|
|
|
2022-10-16 21:13:19 +03:00
|
|
|
check_kwargs_empty(kwargs, raise_error=True)
|
2022-10-04 04:03:43 +03:00
|
|
|
|
2022-10-05 19:39:45 +03:00
|
|
|
# scrollbars
|
|
|
|
self._scrollbars_activated = activate_scrollbars
|
|
|
|
self._hide_x_scrollbar = True
|
|
|
|
self._hide_y_scrollbar = True
|
|
|
|
|
|
|
|
self._y_scrollbar = CTkScrollbar(self,
|
|
|
|
width=8,
|
|
|
|
height=0,
|
|
|
|
border_spacing=0,
|
|
|
|
fg_color=self._fg_color,
|
2022-11-27 04:48:09 +03:00
|
|
|
button_color=self._scrollbar_button_color,
|
|
|
|
button_hover_color=self._scrollbar_button_hover_color,
|
2022-10-05 19:39:45 +03:00
|
|
|
orientation="vertical",
|
|
|
|
command=self._textbox.yview)
|
|
|
|
self._textbox.configure(yscrollcommand=self._y_scrollbar.set)
|
|
|
|
|
|
|
|
self._x_scrollbar = CTkScrollbar(self,
|
|
|
|
height=8,
|
|
|
|
width=0,
|
|
|
|
border_spacing=0,
|
|
|
|
fg_color=self._fg_color,
|
2022-11-27 04:48:09 +03:00
|
|
|
button_color=self._scrollbar_button_color,
|
|
|
|
button_hover_color=self._scrollbar_button_hover_color,
|
2022-10-05 19:39:45 +03:00
|
|
|
orientation="horizontal",
|
|
|
|
command=self._textbox.xview)
|
|
|
|
self._textbox.configure(xscrollcommand=self._x_scrollbar.set)
|
|
|
|
|
2022-10-05 20:06:40 +03:00
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_textbox=True, re_grid_x_scrollbar=True, re_grid_y_scrollbar=True)
|
2022-10-05 19:39:45 +03:00
|
|
|
|
2023-01-22 00:37:40 +03:00
|
|
|
self.after(50, self._check_if_scrollbars_needed, None, True)
|
2022-10-02 04:23:10 +03:00
|
|
|
self._draw()
|
|
|
|
|
2022-10-05 20:06:40 +03:00
|
|
|
def _create_grid_for_text_and_scrollbars(self, re_grid_textbox=False, re_grid_x_scrollbar=False, re_grid_y_scrollbar=False):
|
2022-10-05 19:39:45 +03:00
|
|
|
|
|
|
|
# configure 2x2 grid
|
|
|
|
self.grid_rowconfigure(0, weight=1)
|
|
|
|
self.grid_rowconfigure(1, weight=0, minsize=self._apply_widget_scaling(max(self._corner_radius, self._border_width + self._border_spacing)))
|
|
|
|
self.grid_columnconfigure(0, weight=1)
|
|
|
|
self.grid_columnconfigure(1, weight=0, minsize=self._apply_widget_scaling(max(self._corner_radius, self._border_width + self._border_spacing)))
|
|
|
|
|
|
|
|
if re_grid_textbox:
|
|
|
|
self._textbox.grid(row=0, column=0, rowspan=1, columnspan=1, sticky="nsew",
|
|
|
|
padx=(self._apply_widget_scaling(max(self._corner_radius, self._border_width + self._border_spacing)), 0),
|
|
|
|
pady=(self._apply_widget_scaling(max(self._corner_radius, self._border_width + self._border_spacing)), 0))
|
|
|
|
|
|
|
|
if re_grid_x_scrollbar:
|
|
|
|
if not self._hide_x_scrollbar and self._scrollbars_activated:
|
|
|
|
self._x_scrollbar.grid(row=1, column=0, rowspan=1, columnspan=1, sticky="ewn",
|
|
|
|
pady=(3, self._border_spacing + self._border_width),
|
2022-10-05 20:06:40 +03:00
|
|
|
padx=(max(self._corner_radius, self._border_width + self._border_spacing), 0)) # scrollbar grid method without scaling
|
2022-10-05 19:39:45 +03:00
|
|
|
else:
|
|
|
|
self._x_scrollbar.grid_forget()
|
|
|
|
|
|
|
|
if re_grid_y_scrollbar:
|
|
|
|
if not self._hide_y_scrollbar and self._scrollbars_activated:
|
|
|
|
self._y_scrollbar.grid(row=0, column=1, rowspan=1, columnspan=1, sticky="nsw",
|
|
|
|
padx=(3, self._border_spacing + self._border_width),
|
2022-10-05 20:06:40 +03:00
|
|
|
pady=(max(self._corner_radius, self._border_width + self._border_spacing), 0)) # scrollbar grid method without scaling
|
2022-10-05 19:39:45 +03:00
|
|
|
else:
|
|
|
|
self._y_scrollbar.grid_forget()
|
|
|
|
|
2023-01-22 00:37:40 +03:00
|
|
|
def _check_if_scrollbars_needed(self, event=None, continue_loop: bool = False):
|
2022-10-05 19:39:45 +03:00
|
|
|
""" Method hides or places the scrollbars if they are needed on key release event of tkinter.text widget """
|
|
|
|
|
|
|
|
if self._scrollbars_activated:
|
|
|
|
if self._textbox.xview() != (0.0, 1.0) and not self._x_scrollbar.winfo_ismapped(): # x scrollbar needed
|
|
|
|
self._hide_x_scrollbar = False
|
2022-10-05 20:06:40 +03:00
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_x_scrollbar=True)
|
2022-10-05 19:39:45 +03:00
|
|
|
elif self._textbox.xview() == (0.0, 1.0) and self._x_scrollbar.winfo_ismapped(): # x scrollbar not needed
|
|
|
|
self._hide_x_scrollbar = True
|
2022-10-05 20:06:40 +03:00
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_x_scrollbar=True)
|
2022-10-05 19:39:45 +03:00
|
|
|
|
|
|
|
if self._textbox.yview() != (0.0, 1.0) and not self._y_scrollbar.winfo_ismapped(): # y scrollbar needed
|
|
|
|
self._hide_y_scrollbar = False
|
2022-10-05 20:06:40 +03:00
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_y_scrollbar=True)
|
2022-10-05 19:39:45 +03:00
|
|
|
elif self._textbox.yview() == (0.0, 1.0) and self._y_scrollbar.winfo_ismapped(): # y scrollbar not needed
|
|
|
|
self._hide_y_scrollbar = True
|
2022-10-05 20:06:40 +03:00
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_y_scrollbar=True)
|
2022-10-05 19:39:45 +03:00
|
|
|
else:
|
|
|
|
self._hide_x_scrollbar = False
|
|
|
|
self._hide_x_scrollbar = False
|
2022-10-05 20:06:40 +03:00
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_y_scrollbar=True)
|
2022-10-05 19:39:45 +03:00
|
|
|
|
2022-10-05 20:06:40 +03:00
|
|
|
if self._textbox.winfo_exists() and continue_loop is True:
|
|
|
|
self.after(self._scrollbar_update_time, lambda: self._check_if_scrollbars_needed(continue_loop=True))
|
2022-10-05 19:39:45 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _set_scaling(self, *args, **kwargs):
|
|
|
|
super()._set_scaling(*args, **kwargs)
|
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
self._textbox.configure(font=self._apply_font_scaling(self._font))
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
|
|
|
|
height=self._apply_widget_scaling(self._desired_height))
|
2022-11-13 01:17:37 +03:00
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_textbox=True, re_grid_x_scrollbar=True, re_grid_y_scrollbar=True)
|
2022-10-15 02:02:54 +03:00
|
|
|
self._draw(no_color_updates=True)
|
2022-10-02 04:23:10 +03:00
|
|
|
|
|
|
|
def _set_dimensions(self, width=None, height=None):
|
|
|
|
super()._set_dimensions(width, height)
|
|
|
|
|
|
|
|
self._canvas.configure(width=self._apply_widget_scaling(self._desired_width),
|
|
|
|
height=self._apply_widget_scaling(self._desired_height))
|
|
|
|
self._draw()
|
|
|
|
|
2022-10-22 16:08:13 +03:00
|
|
|
def _update_font(self):
|
|
|
|
""" pass font to tkinter widgets with applied font scaling and update grid with workaround """
|
|
|
|
self._textbox.configure(font=self._apply_font_scaling(self._font))
|
|
|
|
|
|
|
|
# Workaround to force grid to be resized when text changes size.
|
|
|
|
# Otherwise grid will lag and only resizes if other mouse action occurs.
|
|
|
|
self._canvas.grid_forget()
|
|
|
|
self._canvas.grid(row=0, column=0, rowspan=2, columnspan=2, sticky="nsew")
|
|
|
|
|
|
|
|
def destroy(self):
|
|
|
|
if isinstance(self._font, CTkFont):
|
|
|
|
self._font.remove_size_configure_callback(self._update_font)
|
|
|
|
|
|
|
|
super().destroy()
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _draw(self, no_color_updates=False):
|
2022-11-01 02:37:30 +03:00
|
|
|
super()._draw(no_color_updates)
|
2022-10-02 04:23:10 +03:00
|
|
|
|
2022-10-05 22:11:46 +03:00
|
|
|
if not self._canvas.winfo_exists():
|
|
|
|
return
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
requires_recoloring = self._draw_engine.draw_rounded_rect_with_border(self._apply_widget_scaling(self._current_width),
|
|
|
|
self._apply_widget_scaling(self._current_height),
|
|
|
|
self._apply_widget_scaling(self._corner_radius),
|
|
|
|
self._apply_widget_scaling(self._border_width))
|
2022-06-28 12:16:28 +03:00
|
|
|
|
|
|
|
if no_color_updates is False or requires_recoloring:
|
2022-11-11 01:27:55 +03:00
|
|
|
if self._fg_color == "transparent":
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("inner_parts",
|
2022-10-29 02:20:32 +03:00
|
|
|
fill=self._apply_appearance_mode(self._bg_color),
|
|
|
|
outline=self._apply_appearance_mode(self._bg_color))
|
|
|
|
self._textbox.configure(fg=self._apply_appearance_mode(self._text_color),
|
|
|
|
bg=self._apply_appearance_mode(self._bg_color),
|
|
|
|
insertbackground=self._apply_appearance_mode(self._text_color))
|
2022-12-06 20:09:20 +03:00
|
|
|
self._x_scrollbar.configure(fg_color=self._bg_color, button_color=self._scrollbar_button_color,
|
|
|
|
button_hover_color=self._scrollbar_button_hover_color)
|
|
|
|
self._y_scrollbar.configure(fg_color=self._bg_color, button_color=self._scrollbar_button_color,
|
|
|
|
button_hover_color=self._scrollbar_button_hover_color)
|
2022-06-28 12:16:28 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("inner_parts",
|
2022-10-29 02:20:32 +03:00
|
|
|
fill=self._apply_appearance_mode(self._fg_color),
|
|
|
|
outline=self._apply_appearance_mode(self._fg_color))
|
|
|
|
self._textbox.configure(fg=self._apply_appearance_mode(self._text_color),
|
|
|
|
bg=self._apply_appearance_mode(self._fg_color),
|
|
|
|
insertbackground=self._apply_appearance_mode(self._text_color))
|
2022-11-27 04:48:09 +03:00
|
|
|
self._x_scrollbar.configure(fg_color=self._fg_color, button_color=self._scrollbar_button_color,
|
|
|
|
button_hover_color=self._scrollbar_button_hover_color)
|
|
|
|
self._y_scrollbar.configure(fg_color=self._fg_color, button_color=self._scrollbar_button_color,
|
|
|
|
button_hover_color=self._scrollbar_button_hover_color)
|
2022-06-28 12:16:28 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("border_parts",
|
2022-10-29 02:20:32 +03:00
|
|
|
fill=self._apply_appearance_mode(self._border_color),
|
|
|
|
outline=self._apply_appearance_mode(self._border_color))
|
|
|
|
self._canvas.configure(bg=self._apply_appearance_mode(self._bg_color))
|
2022-06-28 12:16:28 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.tag_lower("inner_parts")
|
|
|
|
self._canvas.tag_lower("border_parts")
|
2022-06-28 12:16:28 +03:00
|
|
|
|
2022-07-07 17:02:51 +03:00
|
|
|
def configure(self, require_redraw=False, **kwargs):
|
2022-06-28 12:16:28 +03:00
|
|
|
if "fg_color" in kwargs:
|
2022-11-11 01:27:55 +03:00
|
|
|
self._fg_color = self._check_color_type(kwargs.pop("fg_color"), transparency=True)
|
2022-06-28 12:16:28 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
# check if CTk widgets are children of the frame and change their _bg_color to new frame fg_color
|
2022-06-28 12:16:28 +03:00
|
|
|
for child in self.winfo_children():
|
2022-10-02 04:23:10 +03:00
|
|
|
if isinstance(child, CTkBaseClass) and hasattr(child, "_fg_color"):
|
|
|
|
child.configure(bg_color=self._fg_color)
|
2022-06-28 12:16:28 +03:00
|
|
|
|
|
|
|
if "border_color" in kwargs:
|
2022-11-11 01:27:55 +03:00
|
|
|
self._border_color = self._check_color_type(kwargs.pop("border_color"))
|
2022-06-28 12:16:28 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
2022-10-04 04:16:59 +03:00
|
|
|
if "text_color" in kwargs:
|
2022-11-11 01:27:55 +03:00
|
|
|
self._text_color = self._check_color_type(kwargs.pop("text_color"))
|
2022-10-04 04:16:59 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
2022-11-27 04:48:09 +03:00
|
|
|
if "scrollbar_button_color" in kwargs:
|
|
|
|
self._scrollbar_button_color = self._check_color_type(kwargs.pop("scrollbar_button_color"))
|
|
|
|
self._x_scrollbar.configure(button_color=self._scrollbar_button_color)
|
|
|
|
self._y_scrollbar.configure(button_color=self._scrollbar_button_color)
|
2022-11-11 01:27:55 +03:00
|
|
|
|
2022-11-27 04:48:09 +03:00
|
|
|
if "scrollbar_button_hover_color" in kwargs:
|
|
|
|
self._scrollbar_button_hover_color = self._check_color_type(kwargs.pop("scrollbar_button_hover_color"))
|
|
|
|
self._x_scrollbar.configure(button_hover_color=self._scrollbar_button_hover_color)
|
|
|
|
self._y_scrollbar.configure(button_hover_color=self._scrollbar_button_hover_color)
|
2022-11-11 01:27:55 +03:00
|
|
|
|
2022-06-28 12:16:28 +03:00
|
|
|
if "corner_radius" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._corner_radius = kwargs.pop("corner_radius")
|
2022-10-05 20:06:40 +03:00
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_textbox=True, re_grid_x_scrollbar=True, re_grid_y_scrollbar=True)
|
2022-06-28 12:16:28 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "border_width" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._border_width = kwargs.pop("border_width")
|
2022-10-05 20:06:40 +03:00
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_textbox=True, re_grid_x_scrollbar=True, re_grid_y_scrollbar=True)
|
2022-06-28 12:16:28 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
2022-10-10 01:48:08 +03:00
|
|
|
if "border_spacing" in kwargs:
|
|
|
|
self._border_spacing = kwargs.pop("border_spacing")
|
|
|
|
self._create_grid_for_text_and_scrollbars(re_grid_textbox=True, re_grid_x_scrollbar=True, re_grid_y_scrollbar=True)
|
|
|
|
require_redraw = True
|
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
if "font" in kwargs:
|
2022-10-22 16:08:13 +03:00
|
|
|
if isinstance(self._font, CTkFont):
|
|
|
|
self._font.remove_size_configure_callback(self._update_font)
|
|
|
|
self._font = self._check_font_type(kwargs.pop("font"))
|
|
|
|
if isinstance(self._font, CTkFont):
|
|
|
|
self._font.add_size_configure_callback(self._update_font)
|
|
|
|
|
|
|
|
self._update_font()
|
2022-08-16 15:05:15 +03:00
|
|
|
|
2022-10-04 04:03:43 +03:00
|
|
|
self._textbox.configure(**pop_from_dict_by_set(kwargs, self._valid_tk_text_attributes))
|
|
|
|
super().configure(require_redraw=require_redraw, **kwargs)
|
2022-10-02 04:59:54 +03:00
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
def cget(self, attribute_name: str) -> any:
|
|
|
|
if attribute_name == "corner_radius":
|
|
|
|
return self._corner_radius
|
|
|
|
elif attribute_name == "border_width":
|
|
|
|
return self._border_width
|
2022-10-10 01:48:08 +03:00
|
|
|
elif attribute_name == "border_spacing":
|
|
|
|
return self._border_spacing
|
2022-10-03 01:33:06 +03:00
|
|
|
|
|
|
|
elif attribute_name == "fg_color":
|
|
|
|
return self._fg_color
|
|
|
|
elif attribute_name == "border_color":
|
|
|
|
return self._border_color
|
|
|
|
elif attribute_name == "text_color":
|
|
|
|
return self._text_color
|
|
|
|
|
|
|
|
elif attribute_name == "font":
|
|
|
|
return self._font
|
2022-10-04 04:03:43 +03:00
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
else:
|
|
|
|
return super().cget(attribute_name)
|
|
|
|
|
2022-12-06 20:09:20 +03:00
|
|
|
def bind(self, sequence: str = None, command: Callable = None, add: Union[str, bool] = True):
|
|
|
|
""" called on the tkinter.Canvas """
|
2022-12-06 21:25:00 +03:00
|
|
|
if not (add == "+" or add is True):
|
2022-12-06 20:09:20 +03:00
|
|
|
raise ValueError("'add' argument can only be '+' or True to preserve internal callbacks")
|
|
|
|
self._textbox.bind(sequence, command, add=True)
|
|
|
|
|
|
|
|
def unbind(self, sequence: str = None, funcid: str = None):
|
|
|
|
""" called on the tkinter.Label and tkinter.Canvas """
|
|
|
|
if funcid is not None:
|
|
|
|
raise ValueError("'funcid' argument can only be None, because there is a bug in" +
|
|
|
|
" tkinter and its not clear whether the internal callbacks will be unbinded or not")
|
|
|
|
self._textbox.unbind(sequence, None)
|
2022-10-04 04:16:59 +03:00
|
|
|
|
2022-10-05 22:11:46 +03:00
|
|
|
def focus(self):
|
|
|
|
return self._textbox.focus()
|
|
|
|
|
|
|
|
def focus_set(self):
|
|
|
|
return self._textbox.focus_set()
|
|
|
|
|
|
|
|
def focus_force(self):
|
|
|
|
return self._textbox.focus_force()
|
|
|
|
|
2022-10-04 04:16:59 +03:00
|
|
|
def insert(self, index, text, tags=None):
|
|
|
|
return self._textbox.insert(index, text, tags)
|
|
|
|
|
|
|
|
def get(self, index1, index2=None):
|
|
|
|
return self._textbox.get(index1, index2)
|
|
|
|
|
2022-10-04 21:17:56 +03:00
|
|
|
def bbox(self, index):
|
|
|
|
return self._textbox.bbox(index)
|
|
|
|
|
|
|
|
def compare(self, index, op, index2):
|
|
|
|
return self._textbox.compare(index, op, index2)
|
|
|
|
|
2022-10-10 01:48:08 +03:00
|
|
|
def delete(self, index1, index2=None):
|
|
|
|
return self._textbox.delete(index1, index2)
|
|
|
|
|
2022-10-04 21:17:56 +03:00
|
|
|
def dlineinfo(self, index):
|
|
|
|
return self._textbox.dlineinfo(index)
|
|
|
|
|
|
|
|
def edit_modified(self, arg=None):
|
|
|
|
return self._textbox.edit_modified(arg)
|
|
|
|
|
|
|
|
def edit_redo(self):
|
2022-10-05 19:39:45 +03:00
|
|
|
self._check_if_scrollbars_needed()
|
2022-10-04 21:17:56 +03:00
|
|
|
return self._textbox.edit_redo()
|
|
|
|
|
|
|
|
def edit_reset(self):
|
|
|
|
return self._textbox.edit_reset()
|
|
|
|
|
|
|
|
def edit_separator(self):
|
|
|
|
return self._textbox.edit_separator()
|
|
|
|
|
|
|
|
def edit_undo(self):
|
2022-10-05 19:39:45 +03:00
|
|
|
self._check_if_scrollbars_needed()
|
2022-10-04 21:17:56 +03:00
|
|
|
return self._textbox.edit_undo()
|
|
|
|
|
|
|
|
def image_create(self, index, **kwargs):
|
|
|
|
raise AttributeError("embedding images is forbidden, because would be incompatible with scaling")
|
|
|
|
|
|
|
|
def image_cget(self, index, option):
|
|
|
|
raise AttributeError("embedding images is forbidden, because would be incompatible with scaling")
|
|
|
|
|
|
|
|
def image_configure(self, index):
|
|
|
|
raise AttributeError("embedding images is forbidden, because would be incompatible with scaling")
|
|
|
|
|
|
|
|
def image_names(self):
|
|
|
|
raise AttributeError("embedding images is forbidden, because would be incompatible with scaling")
|
|
|
|
|
|
|
|
def index(self, i):
|
|
|
|
return self._textbox.index(i)
|
|
|
|
|
|
|
|
def mark_gravity(self, mark, gravity=None):
|
|
|
|
return self._textbox.mark_gravity(mark, gravity)
|
|
|
|
|
|
|
|
def mark_names(self):
|
|
|
|
return self._textbox.mark_names()
|
|
|
|
|
|
|
|
def mark_next(self, index):
|
|
|
|
return self._textbox.mark_next(index)
|
|
|
|
|
|
|
|
def mark_previous(self, index):
|
|
|
|
return self._textbox.mark_previous(index)
|
|
|
|
|
|
|
|
def mark_set(self, mark, index):
|
|
|
|
return self._textbox.mark_set(mark, index)
|
|
|
|
|
|
|
|
def mark_unset(self, mark):
|
|
|
|
return self._textbox.mark_unset(mark)
|
|
|
|
|
|
|
|
def scan_dragto(self, x, y):
|
|
|
|
return self._textbox.scan_dragto(x, y)
|
|
|
|
|
|
|
|
def scan_mark(self, x, y):
|
|
|
|
return self._textbox.scan_mark(x, y)
|
|
|
|
|
|
|
|
def search(self, pattern, index, *args, **kwargs):
|
|
|
|
return self._textbox.search(pattern, index, *args, **kwargs)
|
|
|
|
|
|
|
|
def see(self, index):
|
|
|
|
return self._textbox.see(index)
|
|
|
|
|
|
|
|
def tag_add(self, tagName, index1, index2=None):
|
|
|
|
return self._textbox.tag_add(tagName, index1, index2)
|
|
|
|
|
|
|
|
def tag_bind(self, tagName, sequence, func, add=None):
|
|
|
|
return self._textbox.tag_bind(tagName, sequence, func, add)
|
|
|
|
|
|
|
|
def tag_cget(self, tagName, option):
|
|
|
|
return self._textbox.tag_cget(tagName, option)
|
|
|
|
|
|
|
|
def tag_config(self, tagName, **kwargs):
|
|
|
|
if "font" in kwargs:
|
|
|
|
raise AttributeError("'font' option forbidden, because would be incompatible with scaling")
|
|
|
|
return self._textbox.tag_config(tagName, **kwargs)
|
|
|
|
|
|
|
|
def tag_delete(self, *tagName):
|
|
|
|
return self._textbox.tag_delete(*tagName)
|
|
|
|
|
|
|
|
def tag_lower(self, tagName, belowThis=None):
|
|
|
|
return self._textbox.tag_lower(tagName, belowThis)
|
|
|
|
|
|
|
|
def tag_names(self, index=None):
|
|
|
|
return self._textbox.tag_names(index)
|
|
|
|
|
|
|
|
def tag_nextrange(self, tagName, index1, index2=None):
|
|
|
|
return self._textbox.tag_nextrange(tagName, index1, index2)
|
|
|
|
|
|
|
|
def tag_prevrange(self, tagName, index1, index2=None):
|
|
|
|
return self._textbox.tag_prevrange(tagName, index1, index2)
|
|
|
|
|
|
|
|
def tag_raise(self, tagName, aboveThis=None):
|
|
|
|
return self._textbox.tag_raise(tagName, aboveThis)
|
|
|
|
|
|
|
|
def tag_ranges(self, tagName):
|
|
|
|
return self._textbox.tag_ranges(tagName)
|
|
|
|
|
|
|
|
def tag_remove(self, tagName, index1, index2=None):
|
|
|
|
return self._textbox.tag_remove(tagName, index1, index2)
|
|
|
|
|
|
|
|
def tag_unbind(self, tagName, sequence, funcid=None):
|
|
|
|
return self._textbox.tag_unbind(tagName, sequence, funcid)
|
|
|
|
|
|
|
|
def window_cget(self, index, option):
|
|
|
|
raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)")
|
|
|
|
|
|
|
|
def window_configure(self, index, option):
|
|
|
|
raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)")
|
|
|
|
|
|
|
|
def window_create(self, index, **kwargs):
|
|
|
|
raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)")
|
|
|
|
|
|
|
|
def window_names(self):
|
|
|
|
raise AttributeError("embedding widgets is forbidden, would probably cause all kinds of problems ;)")
|
|
|
|
|
|
|
|
def xview(self, *args):
|
|
|
|
return self._textbox.xview(*args)
|
|
|
|
|
|
|
|
def xview_moveto(self, fraction):
|
|
|
|
return self._textbox.xview_moveto(fraction)
|
|
|
|
|
|
|
|
def xview_scroll(self, n, what):
|
|
|
|
return self._textbox.xview_scroll(n, what)
|
|
|
|
|
|
|
|
def yview(self, *args):
|
|
|
|
return self._textbox.yview(*args)
|
|
|
|
|
|
|
|
def yview_moveto(self, fraction):
|
|
|
|
return self._textbox.yview_moveto(fraction)
|
|
|
|
|
|
|
|
def yview_scroll(self, n, what):
|
|
|
|
return self._textbox.yview_scroll(n, what)
|