2021-03-04 20:27:46 +03:00
|
|
|
import tkinter
|
|
|
|
import sys
|
2022-10-02 04:23:10 +03:00
|
|
|
from typing import Union, Tuple, Callable
|
2021-03-04 20:27:46 +03:00
|
|
|
|
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-03-04 20:27:46 +03:00
|
|
|
|
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
class CTkSlider(CTkBaseClass):
|
2022-10-02 04:23:10 +03:00
|
|
|
"""
|
|
|
|
Slider with rounded corners, border, number of steps, variable support, vertical orientation.
|
|
|
|
For detailed information check out the documentation.
|
|
|
|
"""
|
2021-09-13 15:27:29 +03:00
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
def __init__(self, *args,
|
2022-10-03 01:33:06 +03:00
|
|
|
width: Union[int, str] = "default_init",
|
|
|
|
height: Union[int, str] = "default_init",
|
|
|
|
corner_radius: Union[int, str] = "default_theme",
|
|
|
|
button_corner_radius: Union[int, str] = "default_theme",
|
|
|
|
border_width: Union[int, str] = "default_theme",
|
|
|
|
button_length: Union[int, str] = "default_theme",
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
bg_color: Union[str, Tuple[str, str], None] = None,
|
|
|
|
fg_color: Union[str, Tuple[str, str]] = "default_theme",
|
2022-10-03 01:33:06 +03:00
|
|
|
border_color: Union[str, Tuple[str, str], None] = None,
|
2022-10-02 04:23:10 +03:00
|
|
|
progress_color: Union[str, Tuple[str, str], None] = "default_theme",
|
|
|
|
button_color: Union[str, Tuple[str, str]] = "default_theme",
|
|
|
|
button_hover_color: Union[str, Tuple[str, str]] = "default_theme",
|
2022-10-03 01:33:06 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
from_: int = 0,
|
|
|
|
to: int = 1,
|
2022-10-03 01:33:06 +03:00
|
|
|
state: str = "normal",
|
2022-10-02 04:23:10 +03:00
|
|
|
number_of_steps: Union[int, None] = None,
|
|
|
|
command: Callable = None,
|
|
|
|
variable: tkinter.Variable = None,
|
2022-10-03 01:33:06 +03:00
|
|
|
orientation: str = "horizontal",
|
2022-01-16 18:54:21 +03:00
|
|
|
**kwargs):
|
2021-03-04 20:27:46 +03:00
|
|
|
|
2022-05-16 17:51:19 +03:00
|
|
|
# set default dimensions according to orientation
|
2022-10-02 04:23:10 +03:00
|
|
|
if width == "default_init":
|
2022-10-03 01:33:06 +03:00
|
|
|
if orientation.lower() == "vertical":
|
2022-05-16 17:51:19 +03:00
|
|
|
width = 16
|
|
|
|
else:
|
|
|
|
width = 200
|
2022-10-02 04:23:10 +03:00
|
|
|
if height == "default_init":
|
2022-10-03 01:33:06 +03:00
|
|
|
if orientation.lower() == "vertical":
|
2022-05-16 17:51:19 +03:00
|
|
|
height = 200
|
|
|
|
else:
|
|
|
|
height = 16
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
# transfer basic functionality (_bg_color, size, _appearance_mode, scaling) to CTkBaseClass
|
2022-04-20 23:50:57 +03:00
|
|
|
super().__init__(*args, bg_color=bg_color, width=width, height=height, **kwargs)
|
2022-01-07 22:54:45 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# color
|
2022-10-02 04:23:10 +03:00
|
|
|
self._border_color = border_color
|
|
|
|
self._fg_color = ThemeManager.theme["color"]["slider"] if fg_color == "default_theme" else fg_color
|
|
|
|
self._progress_color = ThemeManager.theme["color"]["slider_progress"] if progress_color == "default_theme" else progress_color
|
|
|
|
self._button_color = ThemeManager.theme["color"]["slider_button"] if button_color == "default_theme" else button_color
|
|
|
|
self._button_hover_color = ThemeManager.theme["color"]["slider_button_hover"] if button_hover_color == "default_theme" else button_hover_color
|
2021-09-14 15:48:17 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# shape
|
2022-10-02 04:23:10 +03:00
|
|
|
self._corner_radius = ThemeManager.theme["shape"]["slider_corner_radius"] if corner_radius == "default_theme" else corner_radius
|
|
|
|
self._button_corner_radius = ThemeManager.theme["shape"]["slider_button_corner_radius"] if button_corner_radius == "default_theme" else button_corner_radius
|
|
|
|
self._border_width = ThemeManager.theme["shape"]["slider_border_width"] if border_width == "default_theme" else border_width
|
|
|
|
self._button_length = ThemeManager.theme["shape"]["slider_button_length"] if button_length == "default_theme" else button_length
|
|
|
|
self._value: float = 0.5 # initial value of slider in percent
|
2022-10-03 01:33:06 +03:00
|
|
|
self._orientation = orientation
|
2022-10-02 04:23:10 +03:00
|
|
|
self._hover_state: bool = False
|
|
|
|
self._from_ = from_
|
|
|
|
self._to = to
|
|
|
|
self._number_of_steps = number_of_steps
|
|
|
|
self._output_value = self._from_ + (self._value * (self._to - self._from_))
|
|
|
|
|
|
|
|
if self._corner_radius < self._button_corner_radius:
|
|
|
|
self._corner_radius = self._button_corner_radius
|
2022-03-08 17:03:47 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
# callback and control variables
|
2022-10-02 04:23:10 +03:00
|
|
|
self._command = command
|
|
|
|
self._variable: tkinter.Variable = variable
|
|
|
|
self._variable_callback_blocked: bool = False
|
|
|
|
self._variable_callback_name: Union[bool, None] = None
|
|
|
|
self._state = state
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-05-02 00:29:14 +03:00
|
|
|
self.grid_rowconfigure(0, weight=1)
|
|
|
|
self.grid_columnconfigure(0, weight=1)
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas = CTkCanvas(master=self,
|
|
|
|
highlightthickness=0,
|
|
|
|
width=self._apply_widget_scaling(self._desired_width),
|
|
|
|
height=self._apply_widget_scaling(self._desired_height))
|
|
|
|
self._canvas.grid(column=0, row=0, rowspan=1, columnspan=1, sticky="nswe")
|
|
|
|
self._draw_engine = DrawEngine(self._canvas)
|
2022-03-01 18:12:55 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.bind("<Enter>", self._on_enter)
|
|
|
|
self._canvas.bind("<Leave>", self._on_leave)
|
|
|
|
self._canvas.bind("<Button-1>", self._clicked)
|
|
|
|
self._canvas.bind("<B1-Motion>", self._clicked)
|
2021-03-04 20:27:46 +03:00
|
|
|
|
2022-01-23 19:06:34 +03:00
|
|
|
# Each time an item is resized due to pack position mode, the binding Configure is called on the widget
|
2022-10-04 04:03:43 +03:00
|
|
|
super().bind('<Configure>', self._update_dimensions_event)
|
2022-01-23 19:06:34 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._set_cursor()
|
|
|
|
self._draw() # initial draw
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._variable is not None:
|
|
|
|
self._variable_callback_name = self._variable.trace_add("write", self._variable_callback)
|
|
|
|
self._variable_callback_blocked = True
|
|
|
|
self.set(self._variable.get(), from_variable_callback=True)
|
|
|
|
self._variable_callback_blocked = False
|
2021-03-04 20:27:46 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _set_scaling(self, *args, **kwargs):
|
|
|
|
super()._set_scaling(*args, **kwargs)
|
2022-05-02 00:29:14 +03:00
|
|
|
|
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))
|
|
|
|
self._draw()
|
2022-05-02 00:29:14 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _set_dimensions(self, width=None, height=None):
|
|
|
|
super()._set_dimensions(width, height)
|
2022-05-24 02:00:58 +03:00
|
|
|
|
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))
|
|
|
|
self._draw()
|
2022-05-24 02:00:58 +03:00
|
|
|
|
2022-01-02 00:16:06 +03:00
|
|
|
def destroy(self):
|
2022-02-28 02:35:52 +03:00
|
|
|
# remove variable_callback from variable callbacks if variable exists
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._variable is not None:
|
|
|
|
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-10-02 04:23:10 +03:00
|
|
|
def _set_cursor(self):
|
|
|
|
if self._state == "normal" and Settings.cursor_manipulation_enabled:
|
2022-05-02 00:29:14 +03:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
self.configure(cursor="pointinghand")
|
|
|
|
elif sys.platform.startswith("win"):
|
|
|
|
self.configure(cursor="hand2")
|
2022-03-01 18:12:55 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
elif self._state == "disabled" and Settings.cursor_manipulation_enabled:
|
2022-06-15 03:07:51 +03:00
|
|
|
if sys.platform == "darwin":
|
|
|
|
self.configure(cursor="arrow")
|
|
|
|
elif sys.platform.startswith("win"):
|
|
|
|
self.configure(cursor="arrow")
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _draw(self, no_color_updates=False):
|
|
|
|
if self._orientation.lower() == "horizontal":
|
2022-05-16 17:51:19 +03:00
|
|
|
orientation = "w"
|
2022-10-02 04:23:10 +03:00
|
|
|
elif self._orientation.lower() == "vertical":
|
2022-05-16 17:51:19 +03:00
|
|
|
orientation = "s"
|
|
|
|
else:
|
|
|
|
orientation = "w"
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
requires_recoloring = self._draw_engine.draw_rounded_slider_with_border_and_button(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),
|
|
|
|
self._apply_widget_scaling(self._button_length),
|
|
|
|
self._apply_widget_scaling(self._button_corner_radius),
|
|
|
|
self._value, orientation)
|
2021-11-11 00:17:49 +03:00
|
|
|
|
2022-04-20 23:50:57 +03:00
|
|
|
if no_color_updates is False or requires_recoloring:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.configure(bg=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
2022-01-07 22:54:45 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._border_color is None:
|
|
|
|
self._canvas.itemconfig("border_parts", fill=ThemeManager.single_color(self._bg_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._bg_color, self._appearance_mode))
|
2022-01-07 22:54:45 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("border_parts", fill=ThemeManager.single_color(self._border_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._border_color, self._appearance_mode))
|
2022-01-07 22:54:45 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("inner_parts", fill=ThemeManager.single_color(self._fg_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._fg_color, self._appearance_mode))
|
2022-01-07 22:54:45 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._progress_color is None:
|
|
|
|
self._canvas.itemconfig("progress_parts", fill=ThemeManager.single_color(self._fg_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._fg_color, self._appearance_mode))
|
2022-01-07 22:54:45 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("progress_parts", fill=ThemeManager.single_color(self._progress_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._progress_color, self._appearance_mode))
|
2022-01-07 22:54:45 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._hover_state is True:
|
|
|
|
self._canvas.itemconfig("slider_parts",
|
|
|
|
fill=ThemeManager.single_color(self._button_hover_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._button_hover_color, self._appearance_mode))
|
2022-06-15 03:07:51 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._canvas.itemconfig("slider_parts",
|
|
|
|
fill=ThemeManager.single_color(self._button_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._button_color, self._appearance_mode))
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-07-07 17:02:51 +03:00
|
|
|
def configure(self, require_redraw=False, **kwargs):
|
2022-06-15 03:07:51 +03:00
|
|
|
if "state" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._state = kwargs.pop("state")
|
|
|
|
self._set_cursor()
|
2022-06-15 03:07:51 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
2021-12-22 12:48:41 +03:00
|
|
|
if "fg_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._fg_color = kwargs.pop("fg_color")
|
2021-12-22 12:48:41 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "progress_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._progress_color = kwargs.pop("progress_color")
|
2021-12-22 12:48:41 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "button_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._button_color = kwargs.pop("button_color")
|
2021-12-22 12:48:41 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "button_hover_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._button_hover_color = kwargs.pop("button_hover_color")
|
2021-12-22 12:48:41 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "border_color" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._border_color = kwargs.pop("border_color")
|
2021-12-22 12:48:41 +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")
|
2021-12-22 12:48:41 +03:00
|
|
|
require_redraw = True
|
|
|
|
|
|
|
|
if "from_" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._from_ = kwargs.pop("from_")
|
2021-12-22 12:48:41 +03:00
|
|
|
|
|
|
|
if "to" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._to = kwargs.pop("to")
|
2021-12-22 12:48:41 +03:00
|
|
|
|
|
|
|
if "number_of_steps" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._number_of_steps = kwargs.pop("number_of_steps")
|
2021-12-22 12:48:41 +03:00
|
|
|
|
|
|
|
if "command" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._command = kwargs.pop("command")
|
2021-12-22 12:48:41 +03:00
|
|
|
|
2022-01-16 18:54:21 +03:00
|
|
|
if "variable" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._variable is not None:
|
|
|
|
self._variable.trace_remove("write", self._variable_callback_name)
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
self._variable = kwargs.pop("variable")
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
if self._variable is not None and self._variable != "":
|
|
|
|
self._variable_callback_name = self._variable.trace_add("write", self._variable_callback)
|
|
|
|
self.set(self._variable.get(), from_variable_callback=True)
|
2022-01-16 18:54:21 +03:00
|
|
|
else:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._variable = None
|
2022-01-16 18:54:21 +03:00
|
|
|
|
2022-05-24 02:00:58 +03:00
|
|
|
if "width" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._set_dimensions(width=kwargs.pop("width"))
|
2022-05-24 02:00:58 +03:00
|
|
|
|
|
|
|
if "height" in kwargs:
|
2022-10-02 04:23:10 +03:00
|
|
|
self._set_dimensions(height=kwargs.pop("height"))
|
2022-05-24 02:00:58 +03:00
|
|
|
|
2022-07-07 17:02:51 +03:00
|
|
|
super().configure(require_redraw=require_redraw, **kwargs)
|
2022-10-02 04:23:10 +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 == "button_corner_radius":
|
|
|
|
return self._button_corner_radius
|
|
|
|
elif attribute_name == "border_width":
|
|
|
|
return self._border_width
|
|
|
|
elif attribute_name == "button_length":
|
|
|
|
return self._button_length
|
|
|
|
|
|
|
|
elif attribute_name == "fg_color":
|
|
|
|
return self._fg_color
|
|
|
|
elif attribute_name == "border_color":
|
|
|
|
return self._border_color
|
|
|
|
elif attribute_name == "progress_color":
|
|
|
|
return self._progress_color
|
|
|
|
elif attribute_name == "button_color":
|
|
|
|
return self._button_color
|
|
|
|
elif attribute_name == "button_hover_color":
|
|
|
|
return self._button_hover_color
|
|
|
|
|
|
|
|
elif attribute_name == "from_":
|
|
|
|
return self._from_
|
|
|
|
elif attribute_name == "to":
|
|
|
|
return self._to
|
|
|
|
elif attribute_name == "state":
|
|
|
|
return self._state
|
|
|
|
elif attribute_name == "number_of_steps":
|
|
|
|
return self._number_of_steps
|
|
|
|
elif attribute_name == "command":
|
|
|
|
return self._command
|
|
|
|
elif attribute_name == "variable":
|
|
|
|
return self._variable
|
|
|
|
elif attribute_name == "orientation":
|
|
|
|
return self._orientation
|
2022-10-04 04:03:43 +03:00
|
|
|
|
2022-10-03 01:33:06 +03:00
|
|
|
else:
|
|
|
|
return super().cget(attribute_name)
|
|
|
|
|
2022-10-02 04:23:10 +03:00
|
|
|
def _clicked(self, event=None):
|
|
|
|
if self._state == "normal":
|
|
|
|
if self._orientation.lower() == "horizontal":
|
|
|
|
self._value = (event.x / self._current_width) / self._widget_scaling
|
|
|
|
else:
|
|
|
|
self._value = 1 - (event.y / self._current_height) / self._widget_scaling
|
|
|
|
|
|
|
|
if self._value > 1:
|
|
|
|
self._value = 1
|
|
|
|
if self._value < 0:
|
|
|
|
self._value = 0
|
|
|
|
|
|
|
|
self._output_value = self._round_to_step_size(self._from_ + (self._value * (self._to - self._from_)))
|
|
|
|
self._value = (self._output_value - self._from_) / (self._to - self._from_)
|
|
|
|
|
|
|
|
self._draw(no_color_updates=False)
|
|
|
|
|
|
|
|
if self._variable is not None:
|
|
|
|
self._variable_callback_blocked = True
|
|
|
|
self._variable.set(round(self._output_value) if isinstance(self._variable, tkinter.IntVar) else self._output_value)
|
|
|
|
self._variable_callback_blocked = False
|
|
|
|
|
|
|
|
if self._command is not None:
|
|
|
|
self._command(self._output_value)
|
|
|
|
|
|
|
|
def _on_enter(self, event=0):
|
|
|
|
if self._state == "normal":
|
|
|
|
self._hover_state = True
|
|
|
|
self._canvas.itemconfig("slider_parts",
|
|
|
|
fill=ThemeManager.single_color(self._button_hover_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._button_hover_color, self._appearance_mode))
|
|
|
|
|
|
|
|
def _on_leave(self, event=0):
|
|
|
|
self._hover_state = False
|
|
|
|
self._canvas.itemconfig("slider_parts",
|
|
|
|
fill=ThemeManager.single_color(self._button_color, self._appearance_mode),
|
|
|
|
outline=ThemeManager.single_color(self._button_color, self._appearance_mode))
|
|
|
|
|
|
|
|
def _round_to_step_size(self, value) -> 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)
|
|
|
|
return value
|
|
|
|
else:
|
|
|
|
return value
|
|
|
|
|
|
|
|
def get(self) -> float:
|
|
|
|
return self._output_value
|
|
|
|
|
|
|
|
def set(self, output_value, from_variable_callback=False):
|
|
|
|
if self._from_ < self._to:
|
|
|
|
if output_value > self._to:
|
|
|
|
output_value = self._to
|
|
|
|
elif output_value < self._from_:
|
|
|
|
output_value = self._from_
|
|
|
|
else:
|
|
|
|
if output_value < self._to:
|
|
|
|
output_value = self._to
|
|
|
|
elif output_value > self._from_:
|
|
|
|
output_value = self._from_
|
|
|
|
|
|
|
|
self._output_value = self._round_to_step_size(output_value)
|
|
|
|
self._value = (self._output_value - self._from_) / (self._to - self._from_)
|
|
|
|
|
|
|
|
self._draw(no_color_updates=False)
|
|
|
|
|
|
|
|
if self._variable is not None and not from_variable_callback:
|
|
|
|
self._variable_callback_blocked = True
|
|
|
|
self._variable.set(round(self._output_value) if isinstance(self._variable, tkinter.IntVar) else self._output_value)
|
|
|
|
self._variable_callback_blocked = False
|
|
|
|
|
|
|
|
def _variable_callback(self, var_name, index, mode):
|
|
|
|
if not self._variable_callback_blocked:
|
|
|
|
self.set(self._variable.get(), from_variable_callback=True)
|
2022-10-04 03:26:29 +03:00
|
|
|
|
|
|
|
def bind(self, sequence=None, command=None, add=None):
|
|
|
|
""" called on the tkinter.Canvas """
|
|
|
|
return self._canvas.bind(sequence, command, add)
|
2022-10-04 04:03:43 +03:00
|
|
|
|
|
|
|
def unbind(self, sequence, funcid=None):
|
|
|
|
""" called on the tkinter.Canvas """
|
2022-10-04 04:16:59 +03:00
|
|
|
return self._canvas.unbind(sequence, funcid)
|