Hello everyone, I was playing around with this /examples/widgets/sliders.py and thought about how to use it in my case. I'd like to controll a parameter which - if changed - starts a calculation which last about some seconds. So dragging=False would be exactly what I'm looking for! But on the other hand I'd like to see the slider moving and the value shown altering!
A look at the code in widgets.py made me think about how to change the code to achieve this. Here's my suggestion (my widgets.py is also attached): docstring: update_func_only_on_release_event : The function specified by on_changed is normally updated on motion_notify_event if dragging is True. However if you don't want it to get updated (because it would take too long or whatever) but nevertheless want to see the slider moving then set dragging=True and update_func_only_on_release_event=True. (Therefore: dragging=False and update_func_only_on_release_event=False makes no sense and dragging=False makes update_func_only_on_release_event=True.) def __init__(self, ax, label, valmin, valmax, valinit=0.5, valfmt='%1.2f', closedmin=True, closedmax=True, slidermin=None, slidermax=None, dragging=True, update_func_only_on_release_event=False): ... snip ... if dragging: self.update_func_only_on_release_event = \ update_func_only_on_release_event else: self.update_func_only_on_release_event = False ... snip ... ax.figure.canvas.mpl_connect('button_press_event', self._update) if dragging: ax.figure.canvas.mpl_connect('motion_notify_event', self._update) # VVV new # if self.update_func_only_on_release_event: ax.figure.canvas.mpl_connect('button_release_event', self._update) # ^^^ new # ... snip ... def set_val(self, val, name): self.poly.xy[-1] = val, 0 self.poly.xy[-2] = val, 1 self.valtext.set_text(self.valfmt%val) if self.drawon: self.ax.figure.canvas.draw() self.val = val if not self.eventson: return # VVV new # if not self.update_func_only_on_release_event or \ (name == 'button_release_event' and self.update_func_only_on_release_event): # ^^^ new # for cid, func in self.observers.items(): func(val) To see what happens I altered the example/widgets/slider.py to the one also attached. So far so good. But I'm not really convinced by this change (are you?). I'm not sure if a list instead of dragging and update_func_only_on_release_event would be better. Sliders could be initialized with two lists: update_slider_on = ['button_press_event', 'motion_notify_event'] update_func_on = ['button_release_event'] The drawback here: A lot of all possible combinations are useless! Please let me know what you're thinking about this. Have a nice weekend Martin
widgets.py
Description: application/python
sliders.py
Description: application/python
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users