From jeanbigboute at gmail.com Tue Aug 12 05:37:38 2014 From: jeanbigboute at gmail.com (JBB) Date: Mon, 11 Aug 2014 20:37:38 -0700 Subject: [Tkinter-discuss] tkFileDialog.askopenfile() mac Message-ID: Hello, I am attempting to use tkFileDialog.askopenfile(): 1) On my Mac OSX Mavericks w/ Python 2.7.8, Anaconda 2.0.1 (x86_64) the following code (found via web searches) crashes: from Tkinter import * import tkFileDialog root = Tk() root.withdraw() file = tkFileDialog.askopenfile(parent=root) - A file dialog opens, I can select a file and click the Open button or doubleclick the filename. The window freezes, the spinning rainbow ball comes up, and a Kernel restart is needed to close the window. This happens on iPython notebook as well as within the Spyder IDE. 2) I run the same distribution on a Linux VM on the same machine. There, it works fine. The variable 'file' contains the name of whichever file I've selected. As far as I know, my Mac Python distribution is up-to-date. Pointers to documentation or fixes appreciated. JBB From klappnase at web.de Tue Aug 12 10:20:23 2014 From: klappnase at web.de (Michael Lange) Date: Tue, 12 Aug 2014 10:20:23 +0200 Subject: [Tkinter-discuss] tkFileDialog.askopenfile() mac In-Reply-To: References: Message-ID: <20140812102023.c2425c108ba0f9fabc23690d@web.de> Hi, On Mon, 11 Aug 2014 20:37:38 -0700 JBB wrote: > Hello, > > I am attempting to use tkFileDialog.askopenfile(): > > 1) On my Mac OSX Mavericks w/ Python 2.7.8, Anaconda 2.0.1 (x86_64) the > following code (found via web searches) crashes: > > from Tkinter import * > import tkFileDialog > root = Tk() > root.withdraw() > file = tkFileDialog.askopenfile(parent=root) > (...) I don't know about the Mac-specific issues, but nevertheless two things hit my eye here :) First, I would not recommend using "file" as a variable name because this way you override one of Python's built-ins (though I don't think this has anything to do with the crash, except if you accidentally try to use the built-in later in your code). Second, are you sure that you want to use askopenfile () and not askopenfilename() ? The latter just returns the filename as a string (which is what's intended in most cases) whereas the first returns a readily opened file object. Quoting the code from tkFileDialog.py: # FIXME: are the following perhaps a bit too convenient? def askopenfile(mode = "r", **options): "Ask for a filename to open, and returned the opened file" filename = Open(**options).show() if filename: return open(filename, mode) return None Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. War is never imperative. -- McCoy, "Balance of Terror", stardate 1709.2 From jeanbigboute at gmail.com Tue Aug 12 16:23:11 2014 From: jeanbigboute at gmail.com (JBB) Date: Tue, 12 Aug 2014 07:23:11 -0700 Subject: [Tkinter-discuss] tkFileDialog.askopenfile() mac In-Reply-To: <20140812102023.c2425c108ba0f9fabc23690d@web.de> References: <20140812102023.c2425c108ba0f9fabc23690d@web.de> Message-ID: On 8/12/14, 1:20 AM, Michael Lange wrote: > Hi, > > On Mon, 11 Aug 2014 20:37:38 -0700 > JBB wrote: > >> Hello, >> >> I am attempting to use tkFileDialog.askopenfile(): >> >> 1) On my Mac OSX Mavericks w/ Python 2.7.8, Anaconda 2.0.1 (x86_64) the >> following code (found via web searches) crashes: >> >> from Tkinter import * >> import tkFileDialog >> root = Tk() >> root.withdraw() >> file = tkFileDialog.askopenfile(parent=root) >> > (...) > > I don't know about the Mac-specific issues, but nevertheless two things > hit my eye here :) > First, I would not recommend using "file" as a variable name because this > way you override one of Python's built-ins (though I don't think this has > anything to do with the crash, except if you accidentally try to use the > built-in later in your code). > Second, are you sure that you want to use askopenfile () and not > askopenfilename() ? The latter just returns the filename as a string > (which is what's intended in most cases) whereas the first returns a > readily opened file object. Quoting the code from tkFileDialog.py: > > # FIXME: are the following perhaps a bit too convenient? > > def askopenfile(mode = "r", **options): > "Ask for a filename to open, and returned the opened file" > > filename = Open(**options).show() > if filename: > return open(filename, mode) > return None > > Regards > > Michael Thank you. You are right, askopenfilename is what I want. I wasn't aware that this method existed. After some more digging, I find that Python uses the macosx backend on initialization. If I change this to tk before beginning work, the problem goes away. My Linux Python uses tk by default. As a newcomer to Python, I had read that Tkinter was "the" Python GUI tool and started copying code from examples and discussion threads. But, it is clear that there are other tools for GUI programming and that backend selection may have to be matched depending on the package. JBB From Cameron at phaseit.net Wed Aug 13 00:03:19 2014 From: Cameron at phaseit.net (Cameron Laird) Date: Tue, 12 Aug 2014 22:03:19 +0000 Subject: [Tkinter-discuss] tkFileDialog.askopenfile() mac In-Reply-To: References: <20140812102023.c2425c108ba0f9fabc23690d@web.de> Message-ID: <20140812220319.GA23061@lairds.us> On Tue, Aug 12, 2014 at 07:23:11AM -0700, JBB wrote: > On 8/12/14, 1:20 AM, Michael Lange wrote: . . . > Thank you. You are right, askopenfilename is what I want. I wasn't > aware that this method existed. > > After some more digging, I find that Python uses the macosx backend on > initialization. If I change this to tk before beginning work, the > problem goes away. My Linux Python uses tk by default. > > As a newcomer to Python, I had read that Tkinter was "the" Python GUI > tool and started copying code from examples and discussion threads. > But, it is clear that there are other tools for GUI programming and that > backend selection may have to be matched depending on the package. . . . Good follow-up, JBB; it helps the rest of us to learn your findings as you describe them here. Tkinter is indeed the official Python GUI toolkit. At the same time, as you have also discovered, there is a wealth of more-or-less well-supported alternatives (I once argued in a published article that Python boasted or suffered from a wider range of useful GUI toolkits than *any* language, including even C and Java). Extension of Python is so easy that even intermediate- level Pythoneers with a good idea or two can quickly create an interesting extension; Web frameworks and ssh libraries are a couple of other domains which, at different level, have witnessed these remarkable radiations. We're all fans of Tkinter here. At the same time, if you describe more of your own situation, we might be able to help you evaluate how its competitors are likely to serve you. From jeanbigboute at gmail.com Wed Aug 13 03:30:16 2014 From: jeanbigboute at gmail.com (JBB) Date: Tue, 12 Aug 2014 18:30:16 -0700 Subject: [Tkinter-discuss] tkFileDialog.askopenfile() mac In-Reply-To: <20140812220319.GA23061@lairds.us> References: <20140812102023.c2425c108ba0f9fabc23690d@web.de> <20140812220319.GA23061@lairds.us> Message-ID: On 8/12/14, 3:03 PM, Cameron Laird wrote: > On Tue, Aug 12, 2014 at 07:23:11AM -0700, JBB wrote: >> [ Snip ] > . > Good follow-up, JBB; it helps the rest of us to learn > your findings as you describe them here. > > Tkinter is indeed the official Python GUI toolkit. At > the same time, as you have also discovered, there is a > wealth of more-or-less well-supported alternatives (I > once argued in a published article that Python boasted > or suffered from a wider range of useful GUI toolkits > than *any* language, including even C and Java). > Extension of Python is so easy that even intermediate- > level Pythoneers with a good idea or two can quickly > create an interesting extension; Web frameworks and > ssh libraries are a couple of other domains which, at > different level, have witnessed these remarkable > radiations. > > We're all fans of Tkinter here. At the same time, if > you describe more of your own situation, we might be > able to help you evaluate how its competitors are > likely to serve you. I did a little reading on some of the other toolkits and I think Tkinter will suit me just fine. Not that that other ones aren't good, it just seems like more configuration is required for the basic operations I'm likely to do in the near future: simple dialog boxes to open and save files, maybe a very simple GUI front-end to a data processing script. There are a lot of people who've been where I am with Tkinter and there's a lot of good, ready-made answers on the discussion forums I can use right off the bat. The code I initially asked about falls into that category. The minor back end glitch aside, it works well and I am able to understand its features. JBB From kw at codebykevin.com Wed Aug 13 04:19:20 2014 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 12 Aug 2014 22:19:20 -0400 Subject: [Tkinter-discuss] tkFileDialog.askopenfile() mac In-Reply-To: References: <20140812102023.c2425c108ba0f9fabc23690d@web.de> Message-ID: <53EACB28.7050409@codebykevin.com> Hi, On 8/12/14, 10:23 AM, JBB wrote: > After some more digging, I find that Python uses the macosx backend on > initialization. If I change this to tk before beginning work, the > problem goes away. My Linux Python uses tk by default. What do you mean by this? On Mac, Tkinter/Tk uses native dialogs and widgets by default. What change did you make to get it to work on the Mac? I did see the dialog hanging on the Mac. My guess is that you weren't giving the event loop enough time to spin; the dialog was popping up too fast. This code works just fine: from Tkinter import * import tkFileDialog root = Tk() def openfile(): tkFileDialog.askopenfilename(parent=root) b = Button(root, text="Open", command=openfile).pack() root.mainloop() --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From jeanbigboute at gmail.com Wed Aug 13 06:05:16 2014 From: jeanbigboute at gmail.com (JBB) Date: Tue, 12 Aug 2014 21:05:16 -0700 Subject: [Tkinter-discuss] tkFileDialog.askopenfile() mac In-Reply-To: <53EACB28.7050409@codebykevin.com> References: <20140812102023.c2425c108ba0f9fabc23690d@web.de> <53EACB28.7050409@codebykevin.com> Message-ID: Kevin, On 8/12/14, 7:19 PM, Kevin Walzer wrote: > Hi, > On 8/12/14, 10:23 AM, JBB wrote: >> After some more digging, I find that Python uses the macosx backend on >> initialization. If I change this to tk before beginning work, the >> problem goes away. My Linux Python uses tk by default. > > What do you mean by this? On Mac, Tkinter/Tk uses native dialogs and > widgets by default. What change did you make to get it to work on the Mac? Thank you for the suggestions. My notes: I normally use the iPython Notebook for my Python coding. As a newcomer to the language, the self-documenting features are helpful. The following code works in the notebook: A file dialog (native Mac) comes up, I can navigate, select a file, the dialog box closes, and the correct path and filename print. %matplotlib tk from Tkinter import * import tkFileDialog root = Tk() root.withdraw() filename = tkFileDialog.askopenfilename(parent=root) print filename If I don't have the initial magic command, the file dialog box hangs after file selection. The rainbow ball just spins until I restart the kernel at which point it closes. I normally invoke the notebook with ipython notebook %matplotlib at the first cell gives Using matplotlib backend: MacOSX I can't change the backend at this point so I have to restart the kernel and make sure to run %matplotlib tk before any imports. This is a convenient albeit slightly kludgy way of setting the backend. If I invoke the notebook with: ipython notebook --matplotlib=tk then the code above _without_ the %magic command works fine. > I did see the dialog hanging on the Mac. My guess is that you weren't > giving the event loop enough time to spin; the dialog was popping up too > fast. This code works just fine: > > from Tkinter import * > import tkFileDialog > root = Tk() > def openfile(): > tkFileDialog.askopenfilename(parent=root) > b = Button(root, text="Open", command=openfile).pack() > root.mainloop() I tried this in a fresh notebook. A small window opens, when I mouseover, an Open button appears. I click it, I get a native Mac file dialog box. I navigate, select a file, the dialog box disappears and the small window/button remain. The kernel on the notebook shows busy until I close the small window. I'm not up on the Button and .pack tools as yet. I don't know where the filename is stored. JBB From Vasilis.Vlachoudis at cern.ch Mon Aug 25 16:15:59 2014 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Mon, 25 Aug 2014 14:15:59 +0000 Subject: [Tkinter-discuss] Text() highlight Message-ID: <0BC70B5D93E054469872FFD0FE07220EC0C2B03F@CERNXCHG53.cern.ch> Hi all, I am trying to implement a small g-code editor and real time viewer in tkinter. I am using the Text() widget as an editor, but I have troubles in highlighting the text during editing. Its slow when editing big files. below is the highlighting routine The routine is scanning for all patterns and picks the next one to highlight (found dictionary). It assigns a tag and re-scans all the tags that became invalid (falling within the area of the the just assigned tag. e.g. a valid command inside a comment) Running it on the whole text file on every modification is out of the question, it makes the editing very very slow on big files. In order to minimize the calls, I do them with a delay of 50ms, using the after() command during a period of inactivity and only for the 100lines following the first one to be displayed. Still is slow and lacks interactivity. I would like your suggestions, on what is the best way to do the highlighting during the editing of the code? Thanks in advance Vasilis def highlight(self): self._highAfter = None # List contains order of match with regular expression patterns = {"C": (r"\(.*\)", "Blue") , "X": (r"[xX][+\-]?\d*\.?\d*", "DarkRed" ), "Y": (r"[yY][+\-]?\d*\.?\d*", "DarkBlue" ), "Z": (r"[zZ][+\-]?\d*\.?\d*", "DarkGreen"), "I": (r"[iI][+\-]?\d*\.?\d*", "Maroon"), "J": (r"[jJ][+\-]?\d*\.?\d*", "Maroon"), "K": (r"[kK][+\-]?\d*\.?\d*", "Maroon"), "R": (r"[rR][+\-]?\d*\.?\d*", "Maroon"), "G": (r"[gG]\d+", "Dark Orchid"), "M": (r"[mM]\d+", "DarkGrey"), "F": (r"[fF][+\-]?\d*\.?\d*", "Yellow4"), "P": (r"[pP]\d+", "DarkGrey") } for tag in patterns.keys(): self.editor.tag_delete(tag) count = IntVar() start = self.editor.index("%d.0"%(self._highStart)) end = self.editor.index("%d.0"%(self._highStart+100)) # First search for the first occurance of all patterns found = {} for tag,(pat,color) in patterns.items(): index = self.editor.search(pat, start, end, count=count, regexp=True) if index != "": found[tag] = (index, count.get()) #print "Found:", tag, index, count.get() # Main loop while True: # Find the top-most pattern to highlight nextTag = None nextIndex = end nextCount = 0 for tag,(index,c) in found.items(): if self.editor.compare(index,"<",nextIndex): nextTag = tag nextIndex = index nextCount = c #print "Minimum:", nextTag, nextIndex, nextCount if nextTag is None: break start = self.editor.index("%s+%sc"%(nextIndex,nextCount)) self.editor.tag_add(nextTag, nextIndex, start) # Update tags foundItems = found.items() for tag,(index,c) in foundItems: #print ">>",tag,index if self.editor.compare(index,"<",start): index = self.editor.search(patterns[tag][0], start, end, count=count, regexp=True) if index != "": #print "Update:", tag, index, count.get() found[tag] = (index, count.get()) else: #print "Update:", tag, "-None-" del found[tag] # Set properties to tags for tag,(pat,color) in patterns.items(): self.editor.tag_config(tag,foreground=color) # ---------------------------------------------------------------------- def highlightAfter(self): if self._highAfter is not None: self.after_cancel(self._highAfter) self._highAfter = self.after(10, self.highlight) -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Tue Aug 26 10:34:21 2014 From: klappnase at web.de (Michael Lange) Date: Tue, 26 Aug 2014 10:34:21 +0200 Subject: [Tkinter-discuss] Text() highlight In-Reply-To: <0BC70B5D93E054469872FFD0FE07220EC0C2B03F@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220EC0C2B03F@CERNXCHG53.cern.ch> Message-ID: <20140826103421.f25184a997aad67e7c6bbd93@web.de> On Mon, 25 Aug 2014 14:15:59 +0000 Vasilis Vlachoudis wrote: > Hi all, > > I am trying to implement a small g-code editor and real time viewer in > tkinter. I am using the Text() widget as an editor, but I have troubles > in highlighting the text during editing. Its slow when editing big > files. (...) I don't have much experience with the text widget's advanced capabilities, so I can just give a general hint on how to speed up repeating tasks in Tkinter. In my experience calls to Python commands are usually fast enough, the bottleneck is the calls to Tk, though I am not sure if this is because Tk is slow in itself or if it is the mechanism of the Tcl interpreter that is somehow "embedded" into Python that makes things slow. So as a rule of thumb I suggest that if you want to speed up things I would try to eliminate as many of the calls to Tkinter widgets from the repeating routine as possible. If you want to track down which of these calls are particularly time expensive sometimes it proved useful to add some calls to time.time() to measure the duration a particular command took. So my suggestion is to see, if you can store some of the information about the tags that you query in your highlight() routine again and again e.g. with the text widgets search() or compare() methods in a python list or dictionary and access the information from there. This might complicate parts of the code but will probably result in a remarkable speed-up of your routine. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Kirk to Enterprise -- beam down yeoman Rand and a six-pack. From Vasilis.Vlachoudis at cern.ch Tue Aug 26 14:49:33 2014 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Tue, 26 Aug 2014 12:49:33 +0000 Subject: [Tkinter-discuss] Text() highlight In-Reply-To: <20140826103421.f25184a997aad67e7c6bbd93@web.de> References: <0BC70B5D93E054469872FFD0FE07220EC0C2B03F@CERNXCHG53.cern.ch>, <20140826103421.f25184a997aad67e7c6bbd93@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220EC0C3A6E8@CERNXCHG53.cern.ch> Thank Michael you for your answer, I am trying to simplify the calls to Tk but I didn't manage much. BTW I saw that IDLE has a very nice and fast highlighting but I didn't understand the way. I see that somehow it overrides the insert and delete function of the Text (not of the subclass) with a register function and applies the highlighting from there. (ColorDelegator.py and Percolator.py) V. ________________________________________ From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: 26 August 2014 10:34 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Text() highlight On Mon, 25 Aug 2014 14:15:59 +0000 Vasilis Vlachoudis wrote: > Hi all, > > I am trying to implement a small g-code editor and real time viewer in > tkinter. I am using the Text() widget as an editor, but I have troubles > in highlighting the text during editing. Its slow when editing big > files. (...) I don't have much experience with the text widget's advanced capabilities, so I can just give a general hint on how to speed up repeating tasks in Tkinter. In my experience calls to Python commands are usually fast enough, the bottleneck is the calls to Tk, though I am not sure if this is because Tk is slow in itself or if it is the mechanism of the Tcl interpreter that is somehow "embedded" into Python that makes things slow. So as a rule of thumb I suggest that if you want to speed up things I would try to eliminate as many of the calls to Tkinter widgets from the repeating routine as possible. If you want to track down which of these calls are particularly time expensive sometimes it proved useful to add some calls to time.time() to measure the duration a particular command took. So my suggestion is to see, if you can store some of the information about the tags that you query in your highlight() routine again and again e.g. with the text widgets search() or compare() methods in a python list or dictionary and access the information from there. This might complicate parts of the code but will probably result in a remarkable speed-up of your routine. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Kirk to Enterprise -- beam down yeoman Rand and a six-pack. _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From alexxandro.medici at gmail.com Tue Aug 26 16:00:34 2014 From: alexxandro.medici at gmail.com (alessandro medici) Date: Tue, 26 Aug 2014 16:00:34 +0200 Subject: [Tkinter-discuss] Tkinter-discuss Digest, Vol 126, Issue 3 In-Reply-To: References: Message-ID: Just my 5 cents: 1) list comprehensions if possible (and, for bigger dict, from list to dict after) 2) defining patterns outside the repeated method 3) profiling all 4) editor is a Class? look (profiling) into it methods. 5) better of all: multithreading the tagger routine. Many on line for thats. Bye and sorry for my poor english Alex 2014-08-26 12:00 GMT+02:00 : > Send Tkinter-discuss mailing list submissions to > tkinter-discuss at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tkinter-discuss > or, via email, send a message with subject or body 'help' to > tkinter-discuss-request at python.org > > You can reach the person managing the list at > tkinter-discuss-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tkinter-discuss digest..." > > > Today's Topics: > > 1. Text() highlight (Vasilis Vlachoudis) > 2. Re: Text() highlight (Michael Lange) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Mon, 25 Aug 2014 14:15:59 +0000 > From: Vasilis Vlachoudis > To: "tkinter-discuss at python.org" > Subject: [Tkinter-discuss] Text() highlight > Message-ID: > <0BC70B5D93E054469872FFD0FE07220EC0C2B03F at CERNXCHG53.cern.ch> > Content-Type: text/plain; charset="iso-8859-1" > > Hi all, > > I am trying to implement a small g-code editor and real time viewer in > tkinter. > I am using the Text() widget as an editor, but I have troubles > in highlighting the text during editing. Its slow when editing big files. > > below is the highlighting routine > > The routine is scanning for all patterns and picks the next one to > highlight > (found dictionary). It assigns a tag and re-scans all the tags that > became invalid (falling within the area of the the just assigned tag. > e.g. a valid command inside a comment) > > Running it on the whole text file on every modification is out of the > question, > it makes the editing very very slow on big files. > > In order to minimize the calls, I do them with a delay of 50ms, using the > after() > command during a period of inactivity and only for the 100lines following > the first one to be displayed. Still is slow and lacks interactivity. > > I would like your suggestions, on what is the best way to do the > highlighting > during the editing of the code? > > Thanks in advance > Vasilis > > > def highlight(self): > self._highAfter = None > # List contains order of match with regular expression > patterns = {"C": (r"\(.*\)", "Blue") , > "X": (r"[xX][+\-]?\d*\.?\d*", "DarkRed" ), > "Y": (r"[yY][+\-]?\d*\.?\d*", "DarkBlue" ), > "Z": (r"[zZ][+\-]?\d*\.?\d*", "DarkGreen"), > > "I": (r"[iI][+\-]?\d*\.?\d*", "Maroon"), > "J": (r"[jJ][+\-]?\d*\.?\d*", "Maroon"), > "K": (r"[kK][+\-]?\d*\.?\d*", "Maroon"), > "R": (r"[rR][+\-]?\d*\.?\d*", "Maroon"), > > "G": (r"[gG]\d+", "Dark Orchid"), > "M": (r"[mM]\d+", "DarkGrey"), > "F": (r"[fF][+\-]?\d*\.?\d*", "Yellow4"), > "P": (r"[pP]\d+", "DarkGrey") } > > for tag in patterns.keys(): > self.editor.tag_delete(tag) > > count = IntVar() > start = self.editor.index("%d.0"%(self._highStart)) > end = self.editor.index("%d.0"%(self._highStart+100)) > > # First search for the first occurance of all patterns > found = {} > for tag,(pat,color) in patterns.items(): > index = self.editor.search(pat, start, end, count=count, > regexp=True) > if index != "": > found[tag] = (index, count.get()) > #print "Found:", tag, index, count.get() > > # Main loop > while True: > # Find the top-most pattern to highlight > nextTag = None > nextIndex = end > nextCount = 0 > for tag,(index,c) in found.items(): > if self.editor.compare(index,"<",nextIndex): > nextTag = tag > nextIndex = index > nextCount = c > > #print "Minimum:", nextTag, nextIndex, nextCount > if nextTag is None: break > start = self.editor.index("%s+%sc"%(nextIndex,nextCount)) > self.editor.tag_add(nextTag, nextIndex, start) > > # Update tags > foundItems = found.items() > for tag,(index,c) in foundItems: > #print ">>",tag,index > if self.editor.compare(index,"<",start): > index = self.editor.search(patterns[tag][0], > start, end, > count=count, > regexp=True) > if index != "": > #print "Update:", tag, index, count.get() > found[tag] = (index, count.get()) > else: > #print "Update:", tag, "-None-" > del found[tag] > > # Set properties to tags > for tag,(pat,color) in patterns.items(): > self.editor.tag_config(tag,foreground=color) > > # > ---------------------------------------------------------------------- > def highlightAfter(self): > if self._highAfter is not None: self.after_cancel(self._highAfter) > self._highAfter = self.after(10, self.highlight) > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/tkinter-discuss/attachments/20140825/1961befb/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Tue, 26 Aug 2014 10:34:21 +0200 > From: Michael Lange > To: tkinter-discuss at python.org > Subject: Re: [Tkinter-discuss] Text() highlight > Message-ID: <20140826103421.f25184a997aad67e7c6bbd93 at web.de> > Content-Type: text/plain; charset=US-ASCII > > On Mon, 25 Aug 2014 14:15:59 +0000 > Vasilis Vlachoudis wrote: > > > Hi all, > > > > I am trying to implement a small g-code editor and real time viewer in > > tkinter. I am using the Text() widget as an editor, but I have troubles > > in highlighting the text during editing. Its slow when editing big > > files. > (...) > > I don't have much experience with the text widget's advanced > capabilities, so I can just give a general hint on how to speed up > repeating tasks in Tkinter. > In my experience calls to Python commands are usually fast enough, the > bottleneck is the calls to Tk, though I am not sure if this is because Tk > is slow in itself or if it is the mechanism of the Tcl interpreter that > is somehow "embedded" into Python that makes things slow. > So as a rule of thumb I suggest that if you want to speed up things I > would try to eliminate as many of the calls to Tkinter widgets from the > repeating routine as possible. > If you want to track down which of these calls are particularly time > expensive sometimes it proved useful to add some calls to time.time() to > measure the duration a particular command took. > So my suggestion is to see, if you can store some of the information > about the tags that you query in your highlight() routine again and again > e.g. with the text widgets search() or compare() methods in a python list > or dictionary and access the information from there. This might > complicate parts of the code but will probably result in a remarkable > speed-up of your routine. > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > Kirk to Enterprise -- beam down yeoman Rand and a six-pack. > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > https://mail.python.org/mailman/listinfo/tkinter-discuss > > > ------------------------------ > > End of Tkinter-discuss Digest, Vol 126, Issue 3 > *********************************************** > -------------- next part -------------- An HTML attachment was scrubbed... URL: