Michael Muratet | 15 Sep 16:22 2014
Picon

Can't find tkInter components to build tktreectrl

Greetings

I am trying to build the extension tktreectrl-2.4.1 so I can call it from python. It took me awhile to sort out
versions, but I think the version I want is under /anaconda

./configure --with-tk=/anaconda/pkgs/tk-8.5.13-1/lib --with-tcl=/anaconda/pkgs/tk-8.5.13-1/lib

it finds tkConfig.sh and tclConfig.sh

Michaels-MacBook-Pro:tktreectrl-2.4.1 mmuratet$ ./configure
--with-tk=/anaconda/pkgs/tk-8.5.13-1/lib --with-tcl=/anaconda/pkgs/tk-8.5.13-1/lib
checking for correct TEA configuration... ok (TEA 3.9)
configure: configuring treectrl 2.4
checking for Tcl configuration... found /anaconda/pkgs/tk-8.5.13-1/lib/tclConfig.sh
checking for existence of /anaconda/pkgs/tk-8.5.13-1/lib/tclConfig.sh... loading
checking for Tk configuration... found /anaconda/pkgs/tk-8.5.13-1/lib/tkConfig.sh
checking for existence of /anaconda/pkgs/tk-8.5.13-1/lib/tkConfig.sh... loading
configure: --prefix defaulting to TCL_PREFIX /opt/anaconda1anaconda2anaconda3
configure: --exec-prefix defaulting to TCL_EXEC_PREFIX /opt/anaconda1anaconda2anaconda3
checking for a BSD-compatible install... /usr/bin/install -c
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
(Continue reading)

jevan | 12 Sep 05:32 2014
Picon

Cursor Index From Tkinter.Text in <KeyRelease> Gives Insconsistent Column, Test Case




I want to get the cursor position (line and column) of the insertion point of a Tkinter.Text, but you may assume the answer is easy until you run this simple test run.  Acutally I hope someone finds it easy.

PROBLEM: My text editor project requires a custom undo/redo for Tkinter.Text. I put in the same string for both Test One and Test Two below, but undo does not act consistently due to a inconsistent column variable in KeyRelease event handler given by Tkinter. The problem seems to be that I type too fast for second test which produces a bad column value. Can you help me find the problem?

TWO TEST PROCESS TO REPRODUCE THE ERROR:

TEST ONE

        Type this string slowly: 'one two three'
        Press F1 to see each word undo.

    Result: Works fine. (For me atleast. Ephasis: type slowly.)

TEST TWO

        Type the same string as fast as you can: 'one two three'
        Press F1 to see each word undo.

    Result: Gets the wrong column and does not undo properly. (Restart script and repeat this step if you don't see the error at first, it sometimes works fine with fast typing. I usually get it with 3 to 4 tries at the most.)

QUESTION: Is this a bug in Tkinter, or am I not understanding something specific within Tkinter that would produce consistent columns for my undo/redo records?



from Tkinter import *

class TextView(Text):

    def __init__(self, root):
        Text.__init__(self, root)

        self.history = History(self)
        self.bind("<KeyRelease>", self.keyRelease)

        # used to capture a char at a time in keyRelease.  If space char is pressed it , self.word)

if __name__ == "__main__":
    root = Tk()
    root.geometry("400x200+0+0")

    textView = TextView(root)
    textView.pack()
    root.bind("<F1>", textView.undo)
    root.bind("<F2>", textView.redo)

    root.mainloop()



---
Alle Postfächer an einem Ort. Jetzt wechseln und E-Mail-Adresse mitnehmen! Rundum glücklich mit freenetMail
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
alessandro medici | 26 Aug 16:00 2014
Picon

Re: Tkinter-discuss Digest, Vol 126, Issue 3

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 <tkinter-discuss-request <at> python.org>:
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 <Vasilis.Vlachoudis <at> cern.ch>
To: "tkinter-discuss <at> python.org" <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 <klappnase <at> web.de>
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 <Vasilis.Vlachoudis <at> cern.ch> 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
***********************************************

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
Chris Roy-Smith | 1 Sep 04:46 2014
Picon

Problem using StringVar()

Just trying to learn to use Tkinter.

python 2.7.3  OS Ubuntu 12.4

This code
-----------------------
#!/usr/bin/python
import Tkinter
top = Tkinter.Tk()

v = top.StringVar()
Label(master, textvariable=v).pack()

v.set("hello")

top.mainloop()
---------------------------
returns this error message

Traceback (most recent call last):
   File "./hello.py", line 5, in <module>
     v = top.StringVar()
   File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in __getattr__
     return getattr(self.tk, attr)
AttributeError: StringVar

Please what am I doing wrong?
Vasilis Vlachoudis | 25 Aug 16:15 2014
Picon
Picon

Text() highlight

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)

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
JBB | 12 Aug 05:37 2014
Picon

tkFileDialog.askopenfile() mac

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
Bob Greschke | 19 Jul 00:54 2014

Combining events?

I have a huge program...several huge programs...and I keep writing duplicate sets of calls for <Return>
and <KP_enter>.  I'm tired of it, even though they are already all written.  Is there any way to combine those
(those two, specifically) into one bind like

x.bind(("<Return>", "<KP_Enter"), command = .....?

I know you can't do that, but something like that on a global scale (both figuratively, and
programmatically).  Some little line of code at the beginning of the program that redirects the
<KP_Enter> to the <Return> event when some field or whatever is specifically looking for either return
key to be pressed?.

Thanks!
Alan Gauld | 23 Jun 00:18 2014

divergent behaviour

I've observed a strange difference in the behaviour of
one of my event handlers, I'm wondering if anyone knows
the explanation.

I have a form with a list box and a set of buttons.
When you highlight a list item you can press the
Edit button and it calls evEdit() which opens an
edit dialog in the centre of the parent window.

However I also bound the double click event to evEdit and
if you double click the same item it opebns the dialog
in the centre of the screen.

Does anyone know why double-click and button versions
of the same method result in different locations? I'm
assuming that somehow the dialog (TopLevel widget) sees
the screen as its parent in one version but the
original window as parent in the other - maybe...?

PS.
If necessary I'll try to produce a short example to
illustrate, but the existing code is over 500 lines
so a tad too long to post.

--

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
Thiago Padilha | 10 Jun 23:59 2014
Picon

Text widget "lags" when doing fast updates with increased window heights

I'm currently implementing a sample UI for neovim(http://neovim.org/),
and decided to use Tkinter/python due to the popularity/simplicity of
the platforms. The problem I'm having is that tkinter seems to "stack"
UI updates when the window height crosses a certain threshold.

Here is a video that shows the problem: http://youtu.be/sgE2C9lLqQQ

The right window is a terminal emulator running neovim, and the left
window is the Tkinter UI program connected to neovim. The idea is that
the tkinter UI should mirror neovim terminal screen, including
dimensions. Notice that in this video I don't take focus away from the
terminal window, so the only events Tk has to process come from the
connection to neovim(virtual <<nvim>> events which describe screen
updates)

The first part of the video shows that everything works nicely when
the window height is small, but starts to lag updates when I increase
the height.

I think what I'm trying to implement is close to a terminal
emulator(must handle large bursts of text updates efficiently) but I'm
very inexperienced in GUI programming. Is Tkinter a wise choice for
this task? If yes, then what am I doing wrong?(

The code for the Tkinter program is here: http://pastebin.com/0c8cjsmR
and my OS is ubuntu 12.04(running as a VM under windows 7)

Thanks in advance

Thiago.
Saimadhav Heblikar | 8 Jun 15:55 2014
Picon

About making Text.tag_*range methods more consistent

Some code,

>>> from tkinter import Text
>>> text = Text()
>>> text.pack()
>>> text.insert('insert', 'ab cd ef')
>>> text.tag_add('red', '1.0','1.2')
>>> text.tag_add('red', '1.6', '1.8')
>>> text.tag_prevrange('red', 'end')
('1.6', '1.8')
>>> text.tag_ranges('red')
(<textindex object: '1.0'>, <textindex object: '1.2'>, <textindex object: '1.6'>, <textindex object: '1.8'>)
>>> text.tag_nextrange('red', '1.0')
('1.0', '1.2')

I propose that Text.tag_ranges(tag) return a list of tuples (start index, end index), instead of a list like [start index1, endindex1, startindex2, endindex2....etc]

To be more even more consistent, tag_ranges tuples should contain indexes similar to the ones returned by tag_prevrange/tag_nextrange i.e. strings instead of textindex objects.

So, the above output would have been
>>> text.tag_ranges('red')
(('1.0', '1.2'), ('1.6', '1.8'))

If there is a reason for current behavior, can you link me to it?
-- 
Regards
Saimadhav Heblikar
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss <at> python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
Alan Gauld | 13 May 20:51 2014

How to enable/disable a menu?

I have an app with a tabbed notebook. I want to
only enable one of the main menus when the appropriate
tab is selected. When the tab is deselected I want
to disable the menu again.

I can't see any obvious properties in the Menu
object. I can mess around with flags in the event
handlers and change the menu font colours etc but
that's pretty horrible. Is there anything better?

Using Python 3.3; on Linux and Windows 8 if it makes
any difference.

TIA
--

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

Gmane