From b79849cd60e6c7f485d1bf31afbf2ce26316f085 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 8 Jan 2026 17:39:29 +0100 Subject: [PATCH 1/4] enable right click movement --- RangeSlider/RangeSlider.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/RangeSlider/RangeSlider.py b/RangeSlider/RangeSlider.py index f4671c1..dd4ab21 100644 --- a/RangeSlider/RangeSlider.py +++ b/RangeSlider/RangeSlider.py @@ -129,8 +129,13 @@ def __init__(self, master, variables, Width = 400, Height = 80, min_val = 0, max self.canv = Canvas(self, height = self.canv_H, width = self.canv_W, bg=bgColor, bd=0 , highlightthickness=0, relief='ridge') self.canv.pack() - self.canv.bind("", self._mouseMotion) + # now able to grab right handle with right click if two handles are on the same position + # other possibilities without right-click: move handle in direction of click on track; if bars have equal position on mousedown, select based on first movement + self.canv.bind("", self._mouseMotion_b1) + self.canv.bind("", self._mouseMotion_b3) + self.canv.bind("", self._mouseMotion_b1) # still leave the selection on motion without click / after mouse was released self.canv.bind("", self._moveBar) + self.canv.bind("", self._moveBar) self.track = self.__addTrack(self.slider_x, self.slider_y, self.canv_W-self.slider_x, self.slider_y, self.bars[0]["Pos"], self.bars[1]["Pos"]) tempIdx=0 @@ -174,7 +179,7 @@ def forcePos(self, pos): for idx in range(len(self.bars)): self.__moveBar(idx, pos[idx]) - def _mouseMotion(self, event): + def _mouseMotion_b1(self, event): x = event.x; y = event.y selection = self.__checkSelection(x,y) if selection[0]: @@ -184,6 +189,17 @@ def _mouseMotion(self, event): self.canv.config(cursor = "") self.selected_idx = None + def _mouseMotion_b3(self, event): + x = event.x; y = event.y + selection = self.__checkSelection(x,y, right_handle_first=True) + if selection[0]: + self.canv.config(cursor = "hand2") + self.selected_idx = selection[1] + else: + self.canv.config(cursor = "") + self.selected_idx = None + + def _moveBar(self, event): x = event.x; y = event.y if self.selected_idx == None: @@ -292,15 +308,18 @@ def __moveBar(self, idx, pos): otherPos=positions[1] if self.cross_each_other == False: if pos<=otherPos: + # if pos=otherPos: + # if pos>otherPos: # test pw not allowing same values can sometimes be useful pos=pos else: pos=current_pos @@ -337,16 +356,22 @@ def __getValue(self, idx): pos = self.__calcPos(x) return pos*(self.max_val - self.min_val)+self.min_val - def __checkSelection(self, x, y): + def __checkSelection(self, x, y, right_handle_first=False): """ To check if the position is inside the bounding rectangle of a Bar Return [True, bar_index] or [False, None] """ - for idx in range(len(self.bars)): + if right_handle_first: + bars_ids = reversed(range(len(self.bars))) + else: + bars_ids = range(len(self.bars)) + + for idx in bars_ids: id = self.bars[idx]["Ids"][0] bbox = self.canv.bbox(id) if bbox[0] < x and bbox[2] > x and bbox[1] < y and bbox[3] > y: return [True, idx] + # Note: position may possibly be inside more than one bar/handle only the left-most (or right-most with reversed) can be moved return [False, None] From abf62b82bf8b1efe9480b5ff99a856316f078d45 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 8 Jan 2026 17:41:38 +0100 Subject: [PATCH 2/4] comment --- RangeSlider/RangeSlider.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RangeSlider/RangeSlider.py b/RangeSlider/RangeSlider.py index dd4ab21..ebb9c18 100644 --- a/RangeSlider/RangeSlider.py +++ b/RangeSlider/RangeSlider.py @@ -130,7 +130,10 @@ def __init__(self, master, variables, Width = 400, Height = 80, min_val = 0, max self.canv = Canvas(self, height = self.canv_H, width = self.canv_W, bg=bgColor, bd=0 , highlightthickness=0, relief='ridge') self.canv.pack() # now able to grab right handle with right click if two handles are on the same position - # other possibilities without right-click: move handle in direction of click on track; if bars have equal position on mousedown, select based on first movement + # other possibilities without right-click: + # - move handle in direction of click on track; + # - if bars have equal position on mousedown, select based on first movement + # - if bars are both at 0, select second/right handle self.canv.bind("", self._mouseMotion_b1) self.canv.bind("", self._mouseMotion_b3) self.canv.bind("", self._mouseMotion_b1) # still leave the selection on motion without click / after mouse was released From dd26c900a412346fb86c00af29af2ea9201875eb Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 8 Jan 2026 17:54:29 +0100 Subject: [PATCH 3/4] hide right-click behing option enable_right_click_movement --- RangeSlider/RangeSlider.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/RangeSlider/RangeSlider.py b/RangeSlider/RangeSlider.py index ebb9c18..836cfe1 100644 --- a/RangeSlider/RangeSlider.py +++ b/RangeSlider/RangeSlider.py @@ -23,7 +23,7 @@ def __init__(self, master, variables, Width = 400, Height = 80, min_val = 0, max auto=True, line_width=3, bar_radius=10, bar_color_inner='#5c8a8a', line_s_color="#0a50ff", bar_color_outer='#c2d6d6', line_color = '#476b6b', bgColor= '#ffffff', step_marker_color = "#ffffff", font_color = '#000000', show_value = True, digit_precision='.1f', valueSide='TOP', font_family='Times', font_size=16, suffix="", - step_size = 0,step_marker=False, cross_each_other = False): + step_size = 0,step_marker=False, cross_each_other = False, enable_right_click_movement=False): RangeSliderH.LINE_COLOR=line_color RangeSliderH.LINE_WIDTH=line_width RangeSliderH.BAR_COLOR_INNER=bar_color_inner @@ -129,16 +129,18 @@ def __init__(self, master, variables, Width = 400, Height = 80, min_val = 0, max self.canv = Canvas(self, height = self.canv_H, width = self.canv_W, bg=bgColor, bd=0 , highlightthickness=0, relief='ridge') self.canv.pack() - # now able to grab right handle with right click if two handles are on the same position - # other possibilities without right-click: - # - move handle in direction of click on track; - # - if bars have equal position on mousedown, select based on first movement - # - if bars are both at 0, select second/right handle - self.canv.bind("", self._mouseMotion_b1) - self.canv.bind("", self._mouseMotion_b3) + self.canv.bind("", self._mouseMotion_b1) # still leave the selection on motion without click / after mouse was released self.canv.bind("", self._moveBar) - self.canv.bind("", self._moveBar) + if enable_right_click_movement: + # now able to grab right handle with right click if two handles are on the same position + # other possibilities without right-click: + # - move handle in direction of click on track; + # - if bars have equal position on mousedown, select based on first movement + # - if bars are both at 0, select second/right handle + # self.canv.bind("", self._mouseMotion_b1) # not necessary + self.canv.bind("", self._mouseMotion_b3) + self.canv.bind("", self._moveBar) self.track = self.__addTrack(self.slider_x, self.slider_y, self.canv_W-self.slider_x, self.slider_y, self.bars[0]["Pos"], self.bars[1]["Pos"]) tempIdx=0 From 325b732d1bbdd3edcc71b66adc0e6d3c77172a6b Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 8 Jan 2026 17:59:26 +0100 Subject: [PATCH 4/4] remove some comments --- RangeSlider/RangeSlider.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/RangeSlider/RangeSlider.py b/RangeSlider/RangeSlider.py index 836cfe1..8560491 100644 --- a/RangeSlider/RangeSlider.py +++ b/RangeSlider/RangeSlider.py @@ -313,18 +313,15 @@ def __moveBar(self, idx, pos): otherPos=positions[1] if self.cross_each_other == False: if pos<=otherPos: - # if pos=otherPos: - # if pos>otherPos: # test pw not allowing same values can sometimes be useful pos=pos else: pos=current_pos