Thanks Michael, looking at the text.tcl I saw that I need to bind() also the "B1-Enter" and "B1-Leave" since they are responsible for the AutoRepeat window scroll once you exit the window. In order not to lose the auto-scroll I've duplicated the functionality copying from text.tcl and removing the selection auto repeat like this
... self.bind('<B1-Leave>', self.autoRepeat) self.bind('<B1-Enter>', self.cancelRepeat) ... def cancelRepeat(self, event=None): if self._autoId: self.after_cancel(self._autoId) self._autoId = None return "break" def autoRepeat(self, event=None): self._autoId = None if not self.winfo_exists(): return "break" if event is None: x, y = self._autoPos else: # Unfortunatelly the scroll is fixed from the first time it exits x, y = self._autoPos = event.x, event.y # Something like this would be more dynamic, but it doesn't work # x = self.winfo_pointerx() - self.winfo_rootx() # y = self.winfo_pointery() - self.winfo_rooty() if y > self.winfo_height(): self.yview(tk.SCROLL, 1+y-self.winfo_height(), "pixels") elif y < 0: self.yview(tk.SCROLL, -1+y, "pixels") elif x > self.winfo_width(): self.xview(tk.SCROLL, 2, tk.UNITS) elif x < 0: self.xview(tk.SCROLL, -2, tk.UNITS) else: return "break" self._autoId = self.after(50, self.autoRepeat) return "break" Vasilis ________________________________________ From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern...@python.org] on behalf of Michael Lange [klappn...@web.de] Sent: Sunday, November 04, 2018 22:56 To: tkinter-discuss@python.org Subject: Re: [Tkinter-discuss] Text drag&drop Hi, On Sun, 4 Nov 2018 19:37:29 +0000 Vasilis Vlachoudis <vasilis.vlachou...@cern.ch> wrote: (...) > #1. However I cannot get rid of the #1. I've tried to subclass the > #DndHandler() > especially the on_motion() method to delete the text anchor (dirty > hack) after looking at the text.tcl as well deleting the selection and > calling the CancelRepeat to avoid the auto-scrolling, but nothing > worked ok. Is there a way to tell the Text() to stop the selection? I think you could add something like this to DnDHandler.__init__() : def _return_break(widget, event): return 'break' self._id = widget.bind('<B1-Motion>') widget.bind('<B1-Motion>', _return_break) which should remove the motion-selection binding and then restore it after the dnd operation has finished by adding self.initial_widget.bind('<B1-Motion>', self._id) to the end of DnDHandler.finish() (untested however). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. "The combination of a number of things to make existence worthwhile." "Yes, the philosophy of 'none,' meaning 'all.'" -- Spock and Lincoln, "The Savage Curtain", stardate 5906.4 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss