From Vasilis.Vlachoudis at cern.ch Fri Oct 26 11:12:37 2018 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Fri, 26 Oct 2018 15:12:37 +0000 Subject: [Tkinter-discuss] Text: immutable strings Message-ID: <0BC70B5D93E054469872FFD0FE07220E026A559CB6@CERNXCHG53.cern.ch> Hi all, I have a Text() widget and I want to display some values tab formatted. The values should be prefixed with a text-label which is immutable by the user something like label: value label: value the user should be able to edit the values but not the labels. I know that I can insert the label as a window create_window(Label()) but for very big files it becomes extremely slow If I tag the labels, can I forbid the Text widget to disallow the text editing over this specific tag? Thanks in advance Vasilis From msa01 at bitflipper.ca Fri Oct 26 11:38:43 2018 From: msa01 at bitflipper.ca (Cam Farnell) Date: Fri, 26 Oct 2018 12:38:43 -0300 Subject: [Tkinter-discuss] Text: immutable strings In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E026A559CB6@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E026A559CB6@CERNXCHG53.cern.ch> Message-ID: <6c5b5fa3-f52e-29a6-b7e7-d644bd93a801@bitflipper.ca> Hi Vasilis, I've done this successfully. Bind an event handler to the KeyPress event of the text. Check the tags and if they are inside immutable text and the key is something that would change the text the return 'break' which will stop the processing of the key. Cheers Cam Farnell On 2018-10-26 12:12 p.m., Vasilis Vlachoudis wrote: > Hi all, > > I have a Text() widget and I want to display some values tab formatted. > The values should be prefixed with a text-label which is immutable by the user > something like > > label: value label: value > > the user should be able to edit the values but not the labels. > I know that I can insert the label as a window create_window(Label()) > but for very big files it becomes extremely slow > > If I tag the labels, can I forbid the Text widget to disallow the text editing > over this specific tag? > > Thanks in advance > Vasilis > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > From Vasilis.Vlachoudis at cern.ch Sun Oct 28 05:21:15 2018 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Sun, 28 Oct 2018 09:21:15 +0000 Subject: [Tkinter-discuss] Text: immutable strings In-Reply-To: <6c5b5fa3-f52e-29a6-b7e7-d644bd93a801@bitflipper.ca> References: <0BC70B5D93E054469872FFD0FE07220E026A559CB6@CERNXCHG53.cern.ch>, <6c5b5fa3-f52e-29a6-b7e7-d644bd93a801@bitflipper.ca> Message-ID: <0BC70B5D93E054469872FFD0FE07220E026A55CAA8@CERNXCHG53.cern.ch> Many thanks, it worked like a charm. Vasilis ________________________________________ From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern.ch at python.org] on behalf of Cam Farnell [msa01 at bitflipper.ca] Sent: Friday, October 26, 2018 17:38 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Text: immutable strings Hi Vasilis, I've done this successfully. Bind an event handler to the KeyPress event of the text. Check the tags and if they are inside immutable text and the key is something that would change the text the return 'break' which will stop the processing of the key. Cheers Cam Farnell On 2018-10-26 12:12 p.m., Vasilis Vlachoudis wrote: > Hi all, > > I have a Text() widget and I want to display some values tab formatted. > The values should be prefixed with a text-label which is immutable by the user > something like > > label: value label: value > > the user should be able to edit the values but not the labels. > I know that I can insert the label as a window create_window(Label()) > but for very big files it becomes extremely slow > > If I tag the labels, can I forbid the Text widget to disallow the text editing > over this specific tag? > > Thanks in advance > Vasilis > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From Vasilis.Vlachoudis at cern.ch Wed Oct 31 10:27:04 2018 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Wed, 31 Oct 2018 14:27:04 +0000 Subject: [Tkinter-discuss] Text drag&drop Message-ID: <0BC70B5D93E054469872FFD0FE07220E026A56B4D4@CERNXCHG53.cern.ch> Hi all, moving from Canvas() to Text() I wanted to re-implement the same drag&drop functionality I have. I created a small test program show my problem(s). I am creating two, Toplevel windows with MyText() inside. The MyText extends the Text and adds a drag&drop. For demonstration I've binded on the Control-Button-1 the starting of the drag action it creates a "floating" Label() with the selected text, which is placed at the mouse position. Now the problems: 1. The selection on the "drag" window keeps changing as I move the mouse. The selection is changing as if there was a grab_set() even if the cursor is on the second window. 2. If I drag the mouse on the second window, despite the Label is created() it doesn't show it. How can I correct those problems? Many thanks in advance Vasilis import tkinter as tk import tkinter.dnd as Dnd class MyText(tk.Text): def __init__(self, master, *kw, **kwargs): super().__init__(master, *kw, **kwargs) self.bind("", self.button1) self.dnd_text = None # ---------------------------------------------------------------------- def button1(self, event): Dnd.dnd_start(text1, event) self.dnd_text = text1.get(tk.SEL_FIRST, tk.SEL_LAST) # ---------------------------------------------------------------------- def dnd_accept(self, source, event): return self # ---------------------------------------------------------------------- def dnd_enter(self, source, event): self.focus_set() self.dnd_item = tk.Label(self, text=source.dnd_text, border=2, relief=tk.RAISED) self.dnd_motion(source, event) # ---------------------------------------------------------------------- def dnd_leave(self, source, event): self.dnd_item.place_forget() self.dnd_item = None # ---------------------------------------------------------------------- def dnd_motion(self, source, event): self.dnd_item.place(x=event.x, y=event.y) # ---------------------------------------------------------------------- def dnd_end(self, target, event): if self.dnd_item: self.dnd_item.place_forget() self.dnd_item = None self.dnd_text = None # ---------------------------------------------------------------------- # Object has been dropped here # ---------------------------------------------------------------------- def dnd_commit(self, source, event): if self.dnd_item: self.dnd_item.place_forget() self.dnd_item = None if source.dnd_text is None: return self.insert(tk.CURRENT, source.dnd_text) self.dnd_text = None root=tk.Tk() root.title("Top1") text1 = MyText(root) text1.pack(fill=tk.BOTH, expand=tk.YES) for i in range(1000): text1.insert(tk.END, "%d The quick brown fox jumps over the lazy dog's tail\n"%(i)) top2 = tk.Toplevel(root) top2.title("Top2") text2 = MyText(top2) text2.pack(fill=tk.BOTH, expand=tk.YES) root.mainloop()