2021-08-25 18:02:16 +03:00
|
|
|
import tkinter
|
|
|
|
import sys
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
from .ctk_canvas import CTkCanvas
|
2022-05-17 22:44:59 +03:00
|
|
|
from ..theme_manager import ThemeManager
|
|
|
|
from ..settings import Settings
|
|
|
|
from ..draw_engine import DrawEngine
|
2022-04-20 23:50:57 +03:00
|
|
|
from .widget_base_class import CTkBaseClass
|
2021-08-25 18:02:16 +03:00
|
|
|
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
class CTkCheckBox(CTkBaseClass):
|
2021-08-25 18:02:16 +03:00
|
|
|
""" tkinter custom checkbox with border, rounded corners and hover effect """
|
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
def __init__(self, *args,
|
2021-08-25 18:02:16 +03:00
|
|
|
bg_color=None,
|
2022-02-23 00:38:40 +03:00
|
|
|
fg_color="default_theme",
|
|
|
|
hover_color="default_theme",
|
|
|
|
border_color="default_theme",
|
2022-02-28 02:35:52 +03:00
|
|
|
border_width="default_theme",
|
2022-03-09 16:49:44 +03:00
|
|
|
checkmark_color="default_theme",
|
2022-02-28 02:35:52 +03:00
|
|
|
width=24,
|
|
|
|
height=24,
|
|
|
|
corner_radius="default_theme",
|
2022-02-23 03:47:34 +03:00
|
|
|
text_font="default_theme",
|
2022-02-23 00:38:40 +03:00
|
|
|
text_color="default_theme",
|
2021-08-25 18:02:16 +03:00
|
|
|
text="CTkCheckBox",
|
2022-03-10 04:12:30 +03:00
|
|
|
text_color_disabled="default_theme",
|
2021-08-25 18:02:16 +03:00
|
|
|
hover=True,
|
2021-09-13 15:27:29 +03:00
|
|
|
command=None,
|
2021-08-25 18:02:16 +03:00
|
|
|
state=tkinter.NORMAL,
|
2022-01-16 18:54:21 +03:00
|
|
|
onvalue=1,
|
|
|
|
offvalue=0,
|
|
|
|
variable=None,
|
|
|
|
textvariable=None,
|
|
|
|
**kwargs):
|
2022-04-20 23:50:57 +03:00
|
|
|
|
|
|
|
# transfer basic functionality (bg_color, size, appearance_mode, scaling) to CTkBaseClass
|
|
|
|
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs)
|
|
|
|
|
|
|
|
# color
|
2022-05-17 22:44:59 +03:00
|
|
|
self.fg_color = ThemeManager.theme["color"]["button"] if fg_color == "default_theme" else fg_color
|
|
|
|
self.hover_color = ThemeManager.theme["color"]["button_hover"] if hover_color == "default_theme" else hover_color
|
|
|
|
self.border_color = ThemeManager.theme["color"]["checkbox_border"] if border_color == "default_theme" else border_color
|
|
|
|
self.checkmark_color = ThemeManager.theme["color"]["checkmark"] if checkmark_color == "default_theme" else checkmark_color
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# shape
|
2022-05-17 22:44:59 +03:00
|
|
|
self.corner_radius = ThemeManager.theme["shape"]["checkbox_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
|
|
|
self.border_width = ThemeManager.theme["shape"]["checkbox_border_width"] if border_width == "default_theme" else border_width
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# text
|
2021-08-25 18:02:16 +03:00
|
|
|
self.text = text
|
2022-04-20 23:50:57 +03:00
|
|
|
self.text_label = None
|
2022-05-17 22:44:59 +03:00
|
|
|
self.text_color = ThemeManager.theme["color"]["text"] if text_color == "default_theme" else text_color
|
|
|
|
self.text_color_disabled = ThemeManager.theme["color"]["text_disabled"] if text_color_disabled == "default_theme" else text_color_disabled
|
|
|
|
self.text_font = (ThemeManager.theme["text"]["font"], ThemeManager.theme["text"]["size"]) if text_font == "default_theme" else text_font
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# callback and hover functionality
|
2021-09-13 15:27:29 +03:00
|
|
|
self.function = command
|
2021-08-25 18:02:16 +03:00
|
|
|
self.state = state
|
|
|
|
self.hover = hover
|
|
|
|
self.check_state = False
|
2022-01-16 18:54:21 +03:00
|
|
|
self.onvalue = onvalue
|
|
|
|
self.offvalue = offvalue
|
|
|
|
self.variable: tkinter.Variable = variable
|
|
|
|
self.variable_callback_blocked = False
|
|
|
|
self.textvariable = textvariable
|
2022-02-23 01:50:03 +03:00
|
|
|
self.variable_callback_name = None
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# configure grid system (1x3)
|
2022-03-05 15:05:39 +03:00
|
|
|
self.grid_columnconfigure(0, weight=0)
|
2022-05-02 00:29:14 +03:00
|
|
|
self.grid_columnconfigure(1, weight=0, minsize=self.apply_widget_scaling(6))
|
2022-03-05 15:05:39 +03:00
|
|
|
self.grid_columnconfigure(2, weight=1)
|
2022-04-21 19:34:58 +03:00
|
|
|
self.grid_rowconfigure(0, weight=1)
|
2022-03-05 15:05:39 +03:00
|
|
|
|
2022-04-21 21:30:46 +03:00
|
|
|
self.bg_canvas = CTkCanvas(master=self,
|
|
|
|
highlightthickness=0,
|
2022-05-02 00:29:14 +03:00
|
|
|
width=self.apply_widget_scaling(self.desired_width),
|
|
|
|
height=self.apply_widget_scaling(self.desired_height))
|
2022-04-21 21:30:46 +03:00
|
|
|
self.bg_canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=3, rowspan=1, sticky="nswe")
|
|
|
|
|
2022-02-23 01:50:03 +03:00
|
|
|
self.canvas = CTkCanvas(master=self,
|
|
|
|
highlightthickness=0,
|
2022-05-02 00:29:14 +03:00
|
|
|
width=self.apply_widget_scaling(self.desired_width),
|
|
|
|
height=self.apply_widget_scaling(self.desired_height))
|
2022-04-21 19:34:58 +03:00
|
|
|
self.canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=1, rowspan=1)
|
2022-05-22 01:02:45 +03:00
|
|
|
self.draw_engine = DrawEngine(self.canvas)
|
2022-02-24 02:19:40 +03:00
|
|
|
|
2021-08-25 18:02:16 +03:00
|
|
|
if self.hover is True:
|
|
|
|
self.canvas.bind("<Enter>", self.on_enter)
|
|
|
|
self.canvas.bind("<Leave>", self.on_leave)
|
|
|
|
|
|
|
|
self.canvas.bind("<Button-1>", self.toggle)
|
|
|
|
self.canvas.bind("<Button-1>", self.toggle)
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# set select state according to variable
|
2022-01-16 18:54:21 +03:00
|
|
|
if self.variable is not None:
|
2022-02-23 01:50:03 +03:00
|
|
|
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
2022-01-16 18:54:21 +03:00
|
|
|
if self.variable.get() == self.onvalue:
|
|
|
|
self.select(from_variable_callback=True)
|
|
|
|
elif self.variable.get() == self.offvalue:
|
|
|
|
self.deselect(from_variable_callback=True)
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
self.set_cursor()
|
|
|
|
self.draw() # initial draw
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-05-02 00:29:14 +03:00
|
|
|
def set_scaling(self, *args, **kwargs):
|
|
|
|
super().set_scaling(*args, **kwargs)
|
|
|
|
|
|
|
|
self.grid_columnconfigure(1, weight=0, minsize=self.apply_widget_scaling(6))
|
|
|
|
self.text_label.configure(font=self.apply_font_scaling(self.text_font))
|
|
|
|
|
|
|
|
self.bg_canvas.configure(width=self.apply_widget_scaling(self.desired_width), height=self.apply_widget_scaling(self.desired_height))
|
|
|
|
self.canvas.configure(width=self.apply_widget_scaling(self.desired_width), height=self.apply_widget_scaling(self.desired_height))
|
|
|
|
self.draw()
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
def destroy(self):
|
2022-01-16 18:54:21 +03:00
|
|
|
if self.variable is not None:
|
2022-02-23 01:50:03 +03:00
|
|
|
self.variable.trace_remove("write", self.variable_callback_name)
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-01-02 00:16:06 +03:00
|
|
|
super().destroy()
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
def draw(self, no_color_updates=False):
|
2022-05-02 00:29:14 +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))
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-03-09 16:49:44 +03:00
|
|
|
if self.check_state is True:
|
2022-05-02 00:29:14 +03:00
|
|
|
self.draw_engine.draw_checkmark(self.apply_widget_scaling(self.current_width),
|
|
|
|
self.apply_widget_scaling(self.current_height),
|
|
|
|
self.apply_widget_scaling(self.current_height * 0.58))
|
2022-03-09 16:49:44 +03:00
|
|
|
else:
|
|
|
|
self.canvas.delete("checkmark")
|
|
|
|
|
2022-05-17 22:44:59 +03:00
|
|
|
self.bg_canvas.configure(bg=ThemeManager.single_color(self.bg_color, self.appearance_mode))
|
|
|
|
self.canvas.configure(bg=ThemeManager.single_color(self.bg_color, self.appearance_mode))
|
2022-02-23 01:50:03 +03:00
|
|
|
|
2022-03-09 16:49:44 +03:00
|
|
|
if self.check_state is True:
|
2022-02-23 01:50:03 +03:00
|
|
|
self.canvas.itemconfig("inner_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
outline=ThemeManager.single_color(self.fg_color, self.appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self.fg_color, self.appearance_mode))
|
2022-03-09 16:49:44 +03:00
|
|
|
self.canvas.itemconfig("border_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
outline=ThemeManager.single_color(self.fg_color, self.appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self.fg_color, self.appearance_mode))
|
2022-02-23 01:50:03 +03:00
|
|
|
|
2022-03-09 16:49:44 +03:00
|
|
|
if "create_line" in self.canvas.gettags("checkmark"):
|
2022-05-17 22:44:59 +03:00
|
|
|
self.canvas.itemconfig("checkmark", fill=ThemeManager.single_color(self.checkmark_color, self.appearance_mode))
|
2022-03-09 16:49:44 +03:00
|
|
|
else:
|
2022-05-17 22:44:59 +03:00
|
|
|
self.canvas.itemconfig("checkmark", fill=ThemeManager.single_color(self.checkmark_color, self.appearance_mode))
|
2022-03-09 16:49:44 +03:00
|
|
|
else:
|
|
|
|
self.canvas.itemconfig("inner_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
outline=ThemeManager.single_color(self.bg_color, self.appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self.bg_color, self.appearance_mode))
|
2022-03-09 16:49:44 +03:00
|
|
|
self.canvas.itemconfig("border_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
outline=ThemeManager.single_color(self.border_color, self.appearance_mode),
|
|
|
|
fill=ThemeManager.single_color(self.border_color, self.appearance_mode))
|
2022-02-23 01:50:03 +03:00
|
|
|
|
|
|
|
if self.text_label is None:
|
|
|
|
self.text_label = tkinter.Label(master=self,
|
2022-03-05 15:05:39 +03:00
|
|
|
bd=0,
|
2022-02-23 01:50:03 +03:00
|
|
|
text=self.text,
|
|
|
|
justify=tkinter.LEFT,
|
2022-04-21 19:34:58 +03:00
|
|
|
font=self.apply_font_scaling(self.text_font))
|
2022-03-05 15:05:39 +03:00
|
|
|
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
2022-02-23 01:50:03 +03:00
|
|
|
self.text_label["anchor"] = "w"
|
|
|
|
|
2022-03-10 04:12:30 +03:00
|
|
|
if self.state == tkinter.DISABLED:
|
2022-05-17 22:44:59 +03:00
|
|
|
self.text_label.configure(fg=(ThemeManager.single_color(self.text_color_disabled, self.appearance_mode)))
|
2022-03-10 04:12:30 +03:00
|
|
|
else:
|
2022-05-17 22:44:59 +03:00
|
|
|
self.text_label.configure(fg=ThemeManager.single_color(self.text_color, self.appearance_mode))
|
|
|
|
self.text_label.configure(bg=ThemeManager.single_color(self.bg_color, self.appearance_mode))
|
2021-11-11 00:17:49 +03:00
|
|
|
|
2022-02-23 01:50:03 +03:00
|
|
|
self.set_text(self.text)
|
|
|
|
|
2021-08-25 18:02:16 +03:00
|
|
|
def configure(self, *args, **kwargs):
|
2021-11-07 00:06:27 +03:00
|
|
|
require_redraw = False # some attribute changes require a call of self.draw()
|
|
|
|
|
2021-08-25 18:02:16 +03:00
|
|
|
if "text" in kwargs:
|
|
|
|
self.set_text(kwargs["text"])
|
|
|
|
del kwargs["text"]
|
|
|
|
|
|
|
|
if "state" in kwargs:
|
2022-03-10 04:12:30 +03:00
|
|
|
self.state = kwargs["state"]
|
|
|
|
self.set_cursor()
|
|
|
|
require_redraw = True
|
2021-08-25 18:02:16 +03:00
|
|
|
del kwargs["state"]
|
|
|
|
|
2021-11-07 00:06:27 +03:00
|
|
|
if "fg_color" in kwargs:
|
|
|
|
self.fg_color = kwargs["fg_color"]
|
|
|
|
require_redraw = True
|
|
|
|
del kwargs["fg_color"]
|
|
|
|
|
|
|
|
if "bg_color" in kwargs:
|
|
|
|
if kwargs["bg_color"] is None:
|
|
|
|
self.bg_color = self.detect_color_of_master()
|
|
|
|
else:
|
|
|
|
self.bg_color = kwargs["bg_color"]
|
|
|
|
require_redraw = True
|
|
|
|
del kwargs["bg_color"]
|
|
|
|
|
|
|
|
if "hover_color" in kwargs:
|
|
|
|
self.hover_color = kwargs["hover_color"]
|
|
|
|
require_redraw = True
|
|
|
|
del kwargs["hover_color"]
|
|
|
|
|
|
|
|
if "text_color" in kwargs:
|
|
|
|
self.text_color = kwargs["text_color"]
|
|
|
|
require_redraw = True
|
|
|
|
del kwargs["text_color"]
|
|
|
|
|
|
|
|
if "border_color" in kwargs:
|
|
|
|
self.border_color = kwargs["border_color"]
|
|
|
|
require_redraw = True
|
|
|
|
del kwargs["border_color"]
|
|
|
|
|
2022-01-08 15:13:10 +03:00
|
|
|
if "command" in kwargs:
|
|
|
|
self.function = kwargs["command"]
|
|
|
|
del kwargs["command"]
|
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
if "variable" in kwargs:
|
|
|
|
if self.variable is not None:
|
2022-02-23 01:50:03 +03:00
|
|
|
self.variable.trace_remove("write", self.variable_callback_name)
|
2022-01-16 18:54:21 +03:00
|
|
|
|
|
|
|
self.variable = kwargs["variable"]
|
|
|
|
|
|
|
|
if self.variable is not None and self.variable != "":
|
2022-02-23 01:50:03 +03:00
|
|
|
self.variable_callback_name = self.variable.trace_add("write", self.variable_callback)
|
2022-01-16 18:54:21 +03:00
|
|
|
if self.variable.get() == self.onvalue:
|
|
|
|
self.select(from_variable_callback=True)
|
|
|
|
elif self.variable.get() == self.offvalue:
|
|
|
|
self.deselect(from_variable_callback=True)
|
|
|
|
else:
|
|
|
|
self.variable = None
|
|
|
|
|
|
|
|
del kwargs["variable"]
|
|
|
|
|
2021-08-25 18:02:16 +03:00
|
|
|
super().configure(*args, **kwargs)
|
|
|
|
|
2021-11-07 00:06:27 +03:00
|
|
|
if require_redraw:
|
|
|
|
self.draw()
|
|
|
|
|
2022-03-10 04:12:30 +03:00
|
|
|
def set_cursor(self):
|
2022-05-17 22:44:59 +03:00
|
|
|
if Settings.cursor_manipulation_enabled:
|
2022-05-02 00:29:14 +03:00
|
|
|
if self.state == tkinter.DISABLED:
|
2022-05-17 22:44:59 +03:00
|
|
|
if sys.platform == "darwin" and Settings.cursor_manipulation_enabled:
|
2022-05-02 00:29:14 +03:00
|
|
|
self.canvas.configure(cursor="arrow")
|
2022-05-17 22:44:59 +03:00
|
|
|
elif sys.platform.startswith("win") and Settings.cursor_manipulation_enabled:
|
2022-05-02 00:29:14 +03:00
|
|
|
self.canvas.configure(cursor="arrow")
|
|
|
|
|
|
|
|
elif self.state == tkinter.NORMAL:
|
2022-05-17 22:44:59 +03:00
|
|
|
if sys.platform == "darwin" and Settings.cursor_manipulation_enabled:
|
2022-05-02 00:29:14 +03:00
|
|
|
self.canvas.configure(cursor="pointinghand")
|
2022-05-17 22:44:59 +03:00
|
|
|
elif sys.platform.startswith("win") and Settings.cursor_manipulation_enabled:
|
2022-05-02 00:29:14 +03:00
|
|
|
self.canvas.configure(cursor="hand2")
|
2021-08-25 18:02:16 +03:00
|
|
|
|
|
|
|
def set_text(self, text):
|
|
|
|
self.text = text
|
|
|
|
if self.text_label is not None:
|
2022-03-05 15:05:39 +03:00
|
|
|
self.text_label.configure(text=self.text)
|
2021-08-25 18:02:16 +03:00
|
|
|
else:
|
2022-03-05 15:05:39 +03:00
|
|
|
sys.stderr.write("ERROR (CTkButton): Cant change text because checkbox has no text.")
|
2021-08-25 18:02:16 +03:00
|
|
|
|
|
|
|
def on_enter(self, event=0):
|
2022-03-10 04:12:30 +03:00
|
|
|
if self.hover is True and self.state == tkinter.NORMAL:
|
|
|
|
if self.check_state is True:
|
|
|
|
self.canvas.itemconfig("inner_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
fill=ThemeManager.single_color(self.hover_color, self.appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.hover_color, self.appearance_mode))
|
2022-03-10 04:12:30 +03:00
|
|
|
self.canvas.itemconfig("border_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
fill=ThemeManager.single_color(self.hover_color, self.appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.hover_color, self.appearance_mode))
|
2022-03-10 04:12:30 +03:00
|
|
|
else:
|
|
|
|
self.canvas.itemconfig("inner_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
fill=ThemeManager.single_color(self.hover_color, self.appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.hover_color, self.appearance_mode))
|
2021-08-25 18:02:16 +03:00
|
|
|
|
|
|
|
def on_leave(self, event=0):
|
|
|
|
if self.hover is True:
|
2022-02-23 01:50:03 +03:00
|
|
|
if self.check_state is True:
|
|
|
|
self.canvas.itemconfig("inner_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
fill=ThemeManager.single_color(self.fg_color, self.appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.fg_color, self.appearance_mode))
|
2022-03-10 04:12:30 +03:00
|
|
|
self.canvas.itemconfig("border_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
fill=ThemeManager.single_color(self.fg_color, self.appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.fg_color, self.appearance_mode))
|
2021-08-25 18:02:16 +03:00
|
|
|
else:
|
2022-02-23 01:50:03 +03:00
|
|
|
self.canvas.itemconfig("inner_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
fill=ThemeManager.single_color(self.bg_color, self.appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.bg_color, self.appearance_mode))
|
2022-03-10 04:12:30 +03:00
|
|
|
self.canvas.itemconfig("border_parts",
|
2022-05-17 22:44:59 +03:00
|
|
|
fill=ThemeManager.single_color(self.border_color, self.appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self.border_color, self.appearance_mode))
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
def variable_callback(self, var_name, index, mode):
|
|
|
|
if not self.variable_callback_blocked:
|
|
|
|
if self.variable.get() == self.onvalue:
|
|
|
|
self.select(from_variable_callback=True)
|
|
|
|
elif self.variable.get() == self.offvalue:
|
|
|
|
self.deselect(from_variable_callback=True)
|
|
|
|
|
2021-08-25 18:02:16 +03:00
|
|
|
def toggle(self, event=0):
|
|
|
|
if self.state == tkinter.NORMAL:
|
|
|
|
if self.check_state is True:
|
|
|
|
self.check_state = False
|
2022-03-09 16:49:44 +03:00
|
|
|
self.draw()
|
2021-08-25 18:02:16 +03:00
|
|
|
else:
|
|
|
|
self.check_state = True
|
2022-03-09 16:49:44 +03:00
|
|
|
self.draw()
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2021-09-13 15:27:29 +03:00
|
|
|
if self.function is not None:
|
|
|
|
self.function()
|
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
if self.variable is not None:
|
|
|
|
self.variable_callback_blocked = True
|
|
|
|
self.variable.set(self.onvalue if self.check_state is True else self.offvalue)
|
|
|
|
self.variable_callback_blocked = False
|
|
|
|
|
|
|
|
def select(self, from_variable_callback=False):
|
2021-08-25 18:02:16 +03:00
|
|
|
self.check_state = True
|
2022-03-09 23:32:27 +03:00
|
|
|
self.draw()
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
if self.variable is not None and not from_variable_callback:
|
|
|
|
self.variable_callback_blocked = True
|
|
|
|
self.variable.set(self.onvalue)
|
|
|
|
self.variable_callback_blocked = False
|
|
|
|
|
2022-05-13 00:56:00 +03:00
|
|
|
if self.function is not None:
|
2022-05-16 17:51:19 +03:00
|
|
|
try:
|
|
|
|
self.function()
|
|
|
|
except:
|
|
|
|
pass
|
2022-05-13 00:56:00 +03:00
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
def deselect(self, from_variable_callback=False):
|
2021-08-25 18:02:16 +03:00
|
|
|
self.check_state = False
|
2022-03-09 23:32:27 +03:00
|
|
|
self.draw()
|
2021-08-25 18:02:16 +03:00
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
if self.variable is not None and not from_variable_callback:
|
|
|
|
self.variable_callback_blocked = True
|
|
|
|
self.variable.set(self.offvalue)
|
|
|
|
self.variable_callback_blocked = False
|
|
|
|
|
2022-05-13 00:56:00 +03:00
|
|
|
if self.function is not None:
|
2022-05-16 17:51:19 +03:00
|
|
|
try:
|
|
|
|
self.function()
|
|
|
|
except:
|
|
|
|
pass
|
2022-05-13 00:56:00 +03:00
|
|
|
|
2021-08-25 18:02:16 +03:00
|
|
|
def get(self):
|
2022-01-16 18:54:21 +03:00
|
|
|
return self.onvalue if self.check_state is True else self.offvalue
|