Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions RangeSlider/RangeSlider.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def __init__(self, master, variables, Width = 400, Height = 80, min_val = 0, max
self.canv_W = self.W
self.suffix=suffix
self.variables=variables
if variables:
variables[0].trace_add("write", self._trace_vars_write0)
variables[1].trace_add("write", self._trace_vars_write1)
self.step_marker = step_marker
if self.step_marker:
assert step_size > 0, "[step_size] must be provided if [step_marker] set to True."
Expand Down Expand Up @@ -348,6 +351,14 @@ def __checkSelection(self, x, y):
if bbox[0] < x and bbox[2] > x and bbox[1] < y and bbox[3] > y:
return [True, idx]
return [False, None]

def _trace_vars_write0(self, *args):
firstVal = self.variables[0].get()
self.__moveBar(0, (firstVal - self.min_val)/(self.max_val - self.min_val))

def _trace_vars_write1(self, *args):
secondVal = self.variables[1].get()
self.__moveBar(1, (secondVal - self.min_val)/(self.max_val - self.min_val))


class RangeSliderV(Frame):
Expand Down Expand Up @@ -445,6 +456,9 @@ def __init__(self, master, variables, Width = 80, Height = 400, min_val = 0, max
self.canv_W = self.W
self.suffix=suffix
self.variables=variables
if variables:
variables[0].trace_add("write", self._trace_vars_write0)
variables[1].trace_add("write", self._trace_vars_write1)
self.step_size= step_size / (self.max_val-self.min_val)
if not show_value:
self.slider_x = self.canv_W/2 # y pos of the slider
Expand Down Expand Up @@ -685,3 +699,11 @@ def __checkSelection(self, x, y):
if bbox[0] < x and bbox[2] > x and bbox[1] < y and bbox[3] > y:
return [True, idx]
return [False, None]

def _trace_vars_write0(self, *args):
firstVal = self.variables[0].get()
self.__moveBar(0, (firstVal - self.min_val)/(self.max_val - self.min_val))

def _trace_vars_write1(self, *args):
secondVal = self.variables[1].get()
self.__moveBar(1, (secondVal - self.min_val)/(self.max_val - self.min_val))