From Vasilis.Vlachoudis at cern.ch Tue Dec 11 08:45:10 2018 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Tue, 11 Dec 2018 13:45:10 +0000 Subject: [Tkinter-discuss] Text editing and tags... Message-ID: <0BC70B5D93E054469872FFD0FE07220E026A59A639@CERNXCHG53.cern.ch> Hi all, Considering the following code, it creates a Text() and adds the word "Red" with tag "red" and "Normal" without afterwords without any tag. If you click the cursor in between the two letters d|N from (Red"d" and "N"ormal) and you start typing, the newly inserted text will be black without out any tag associated. Is there a way to change this behavior like the word processing editor where the end of a tag is inclusive that if you start typing at the end of the tag it will assume that is inside the tag-range and not outside? import tkinter as tk root=tk.Tk() txt = tk.Text(root) txt.pack(fill=tk.BOTH, expand=tk.YES) txt.insert(tk.END,"Red","red") txt.insert(tk.END,"Normal") txt.tag_configure("red", foreground="Red") root.mainloop() Many thanks in advance Vasilis From klappnase at web.de Tue Dec 11 14:54:48 2018 From: klappnase at web.de (Michael Lange) Date: Tue, 11 Dec 2018 20:54:48 +0100 Subject: [Tkinter-discuss] Text editing and tags... In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E026A59A639@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E026A59A639@CERNXCHG53.cern.ch> Message-ID: <20181211205448.6bebe7907ae1f47310958f2f@web.de> Hi Vasilis, On Tue, 11 Dec 2018 13:45:10 +0000 Vasilis Vlachoudis wrote: > Hi all, > > Considering the following code, it creates a Text() and adds the word > "Red" with tag "red" and "Normal" without afterwords without any tag. > If you click the cursor in between the two letters d|N from (Red"d" and > "N"ormal) and you start typing, the newly inserted text will be black > without out any tag associated. Is there a way to change this behavior > like the word processing editor where the end of a tag is inclusive > that if you start typing at the end of the tag it will assume that is > inside the tag-range and not outside? so far as I can see there is no built-in way to achieve this. Maybe you can try to override the default Tk event handlers of the Text widget. For starters I set up a very basic example of a modified KeyPress event handler: ################################## import tkinter as tk root=tk.Tk() txt = tk.Text(root) txt.pack(fill='both', expand=1) txt.tag_configure("red", foreground="Red") txt.insert('end',"Red", 'red') txt.insert('end',"Normal") def on_key_press(event): ins = txt.index('insert') if event.char and not ('\n' in event.char or '\r' in event.char or '\b' in event.char): txt.tk.call('tk::TextInsert', txt._w, event.char)# borrowed from text.tcl l, i = str(ins).split('.') if int(i) > 0 and 'red' in txt.tag_names('%s.%d' %(l, int(i)-1)): txt.tag_add('red', ins) return('break') txt.bind('', on_key_press) root.mainloop() ################################## I guess this is not perfect though, and you will probably also want handlers for copy-and-paste'ing text. Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. It is a human characteristic to love little animals, especially if they're attractive in some way. -- McCoy, "The Trouble with Tribbles", stardate 4525.6 From Vasilis.Vlachoudis at cern.ch Wed Dec 12 05:32:24 2018 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Wed, 12 Dec 2018 10:32:24 +0000 Subject: [Tkinter-discuss] Text editing and tags... In-Reply-To: <20181211205448.6bebe7907ae1f47310958f2f@web.de> References: <0BC70B5D93E054469872FFD0FE07220E026A59A639@CERNXCHG53.cern.ch>, <20181211205448.6bebe7907ae1f47310958f2f@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220E026A59AE94@CERNXCHG53.cern.ch> Thanks Michael, I am doing something similar, by inserting the tag_names of the character before like txt.insert(tk.INSERT, event.char, txt.tag_names(tk.INSERT + "-1c")) but I don't find it elegant. I saw that for marks there is a gravity field but it doesn't exist for tags What it is the advantage of using the txt.tk.call('tk::TextInsert', txt._w, event.char)# borrowed from text.tcl instead of txt.insert()? Thanks Vasilis ________________________________________ From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: Tuesday, December 11, 2018 20:54 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Text editing and tags... Hi Vasilis, On Tue, 11 Dec 2018 13:45:10 +0000 Vasilis Vlachoudis wrote: > Hi all, > > Considering the following code, it creates a Text() and adds the word > "Red" with tag "red" and "Normal" without afterwords without any tag. > If you click the cursor in between the two letters d|N from (Red"d" and > "N"ormal) and you start typing, the newly inserted text will be black > without out any tag associated. Is there a way to change this behavior > like the word processing editor where the end of a tag is inclusive > that if you start typing at the end of the tag it will assume that is > inside the tag-range and not outside? so far as I can see there is no built-in way to achieve this. Maybe you can try to override the default Tk event handlers of the Text widget. For starters I set up a very basic example of a modified KeyPress event handler: ################################## import tkinter as tk root=tk.Tk() txt = tk.Text(root) txt.pack(fill='both', expand=1) txt.tag_configure("red", foreground="Red") txt.insert('end',"Red", 'red') txt.insert('end',"Normal") def on_key_press(event): ins = txt.index('insert') if event.char and not ('\n' in event.char or '\r' in event.char or '\b' in event.char): txt.tk.call('tk::TextInsert', txt._w, event.char)# borrowed from text.tcl l, i = str(ins).split('.') if int(i) > 0 and 'red' in txt.tag_names('%s.%d' %(l, int(i)-1)): txt.tag_add('red', ins) return('break') txt.bind('', on_key_press) root.mainloop() ################################## I guess this is not perfect though, and you will probably also want handlers for copy-and-paste'ing text. Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. It is a human characteristic to love little animals, especially if they're attractive in some way. -- McCoy, "The Trouble with Tribbles", stardate 4525.6 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From klappnase at web.de Wed Dec 12 06:20:44 2018 From: klappnase at web.de (Michael Lange) Date: Wed, 12 Dec 2018 12:20:44 +0100 Subject: [Tkinter-discuss] Text editing and tags... In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E026A59AE94@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E026A59A639@CERNXCHG53.cern.ch> <20181211205448.6bebe7907ae1f47310958f2f@web.de> <0BC70B5D93E054469872FFD0FE07220E026A59AE94@CERNXCHG53.cern.ch> Message-ID: <20181212122044.9b36e1e1dc55e8f5d026f1ae@web.de> Hi, On Wed, 12 Dec 2018 10:32:24 +0000 Vasilis Vlachoudis wrote: (...) > What it is the advantage of using the > txt.tk.call('tk::TextInsert', txt._w, event.char)# borrowed from > text.tcl instead of txt.insert()? > actually I do not know if there is any difference, I just supposed there might be. The apparently more low-level tk::TextInsert is exactly what the Text widget does on KeyPress events, so when I set up that example I just copied it. Of course that snippet was just a "quick shot", for all I know insert() may or may not do exactly the same :-) Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. A father doesn't destroy his children. -- Lt. Carolyn Palamas, "Who Mourns for Adonais?", stardate 3468.1. From Vasilis.Vlachoudis at cern.ch Mon Dec 17 02:52:52 2018 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Mon, 17 Dec 2018 07:52:52 +0000 Subject: [Tkinter-discuss] Event debugging Message-ID: <0BC70B5D93E054469872FFD0FE07220E026A59D725@CERNXCHG53.cern.ch> Hi all in my application there is one listbox which has a bind("",...) strangely enough under some OS the Double-1 is not working. For example in Fedora with KDE it works ok but not on Ubuntu with XFCE. Is there a way to debug the events? I believe that some other widget is intercepting the Button-1 and somehow it blocks the Double-1 Thanks in advance Vasiils From klappnase at web.de Mon Dec 17 13:13:11 2018 From: klappnase at web.de (Michael Lange) Date: Mon, 17 Dec 2018 19:13:11 +0100 Subject: [Tkinter-discuss] Event debugging In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E026A59D725@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E026A59D725@CERNXCHG53.cern.ch> Message-ID: <20181217191311.8abe52ccfdef0c54839135ad@web.de> Hi, On Mon, 17 Dec 2018 07:52:52 +0000 Vasilis Vlachoudis wrote: > Hi all > > in my application there is one listbox which has a bind > ("",...) strangely enough under some OS the Double-1 is not > working. For example in Fedora with KDE it works ok but not on Ubuntu > with XFCE. > > Is there a way to debug the events? I believe that some other > widget is intercepting the Button-1 and somehow it blocks the > Double-1 did you try to add a print(event.widget) to the callback? Can you post a simple code example that exhibits the problem? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. It is necessary to have purpose. -- Alice #1, "I, Mudd", stardate 4513.3 From Vasilis.Vlachoudis at cern.ch Thu Dec 20 09:47:39 2018 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Thu, 20 Dec 2018 14:47:39 +0000 Subject: [Tkinter-discuss] Event debugging In-Reply-To: <20181217191311.8abe52ccfdef0c54839135ad@web.de> References: <0BC70B5D93E054469872FFD0FE07220E026A59D725@CERNXCHG53.cern.ch>, <20181217191311.8abe52ccfdef0c54839135ad@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220E026A5A1154@CERNXCHG53.cern.ch> Simple print doesn't work, since I don't get the call. Unfortunately when I try to simplify and isolate the widget it I cannot reproduce it. It only appears in the whole application. I've tried to bind also the Button-1, Release-1 and Button-2, Release-2, Double-2, 3 I get all the Button/Release calls, but I don't get any Double-X call at all. Its a bit strange behavior, I have a big nesting of frames and PanedWindows... .!flair.!flairtabribbonframe.!treesplitter.!frame.!frame2.!panedwindow.!frame.!filestab.!panedwindow.!frame.!colormultilistbox.!panedwindow.!frame.!exlistbox If I remove the grand parent PanedWindow and Frame (just above the colormultistbox) then it works ok. However it is not the PanedWindow since I replace it with a Frame then it doesn't work. It seems it works if I remove two nestings. Could it be some result of big nesting of widgets. Still same version of the code on Fedora it works. Vasilis ________________________________________ From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: Monday, December 17, 2018 19:13 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Event debugging Hi, On Mon, 17 Dec 2018 07:52:52 +0000 Vasilis Vlachoudis wrote: > Hi all > > in my application there is one listbox which has a bind > ("",...) strangely enough under some OS the Double-1 is not > working. For example in Fedora with KDE it works ok but not on Ubuntu > with XFCE. > > Is there a way to debug the events? I believe that some other > widget is intercepting the Button-1 and somehow it blocks the > Double-1 did you try to add a print(event.widget) to the callback? Can you post a simple code example that exhibits the problem? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. It is necessary to have purpose. -- Alice #1, "I, Mudd", stardate 4513.3 _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From klappnase at web.de Thu Dec 20 17:46:59 2018 From: klappnase at web.de (Michael Lange) Date: Thu, 20 Dec 2018 23:46:59 +0100 Subject: [Tkinter-discuss] Event debugging In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E026A5A1154@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E026A59D725@CERNXCHG53.cern.ch> <20181217191311.8abe52ccfdef0c54839135ad@web.de> <0BC70B5D93E054469872FFD0FE07220E026A5A1154@CERNXCHG53.cern.ch> Message-ID: <20181220234659.ca06099f90d3239cc40fd1b3@web.de> Hi, On Thu, 20 Dec 2018 14:47:39 +0000 Vasilis Vlachoudis wrote: > Simple print doesn't work, since I don't get the call. Ok, then it does not seem to be another widget that intercepts the event. > Unfortunately when I try to simplify and isolate the widget it I cannot > reproduce it. It only appears in the whole application. > > I've tried to bind also the Button-1, Release-1 and Button-2, > Release-2, Double-2, 3 I get all the Button/Release calls, but I don't > get any Double-X call at all. > > Its a bit strange behavior, I have a big nesting of frames and > PanedWindows... .!flair.!flairtabribbonframe.!treesplitter.!frame.! > frame2.!panedwindow.!frame.!filestab.!panedwindow.!frame.! > colormultilistbox.!panedwindow.!frame.!exlistbox > > If I remove the grand parent PanedWindow and Frame (just above the > colormultistbox) then it works ok. However it is not the PanedWindow > since I replace it with a Frame then it doesn't work. It seems it works > if I remove two nestings. > > Could it be some result of big nesting of widgets. Did you try to write a minimal example app with the same stack of nested widgets? > > Still same version of the code on Fedora it works. Maybe a WM / DE issue? Did you try some other DE's with Ubuntu besides XFCE? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Conquest is easy. Control is not. -- Kirk, "Mirror, Mirror", stardate unknown From Vasilis.Vlachoudis at cern.ch Fri Dec 21 09:40:48 2018 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Fri, 21 Dec 2018 14:40:48 +0000 Subject: [Tkinter-discuss] Event debugging In-Reply-To: <20181220234659.ca06099f90d3239cc40fd1b3@web.de> References: <0BC70B5D93E054469872FFD0FE07220E026A59D725@CERNXCHG53.cern.ch> <20181217191311.8abe52ccfdef0c54839135ad@web.de> <0BC70B5D93E054469872FFD0FE07220E026A5A1154@CERNXCHG53.cern.ch>, <20181220234659.ca06099f90d3239cc40fd1b3@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220E026A5A59EE@CERNXCHG53.cern.ch> I've created a virtual machine with the same ubuntu version and gnome With gnome the double click on the specific listbox works ok. I will try to install also xfce on the VM and test Vasilis ________________________________________ From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: Thursday, December 20, 2018 23:46 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Event debugging Hi, On Thu, 20 Dec 2018 14:47:39 +0000 Vasilis Vlachoudis wrote: > Simple print doesn't work, since I don't get the call. Ok, then it does not seem to be another widget that intercepts the event. > Unfortunately when I try to simplify and isolate the widget it I cannot > reproduce it. It only appears in the whole application. > > I've tried to bind also the Button-1, Release-1 and Button-2, > Release-2, Double-2, 3 I get all the Button/Release calls, but I don't > get any Double-X call at all. > > Its a bit strange behavior, I have a big nesting of frames and > PanedWindows... .!flair.!flairtabribbonframe.!treesplitter.!frame.! > frame2.!panedwindow.!frame.!filestab.!panedwindow.!frame.! > colormultilistbox.!panedwindow.!frame.!exlistbox > > If I remove the grand parent PanedWindow and Frame (just above the > colormultistbox) then it works ok. However it is not the PanedWindow > since I replace it with a Frame then it doesn't work. It seems it works > if I remove two nestings. > > Could it be some result of big nesting of widgets. Did you try to write a minimal example app with the same stack of nested widgets? > > Still same version of the code on Fedora it works. Maybe a WM / DE issue? Did you try some other DE's with Ubuntu besides XFCE? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Conquest is easy. Control is not. -- Kirk, "Mirror, Mirror", stardate unknown _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss