Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDLE: source line in editor doesn't highlight when debugging #58354

Closed
RichRauenzahn mannequin opened this issue Feb 28, 2012 · 32 comments
Closed

IDLE: source line in editor doesn't highlight when debugging #58354

RichRauenzahn mannequin opened this issue Feb 28, 2012 · 32 comments
Assignees
Labels
topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@RichRauenzahn
Copy link
Mannequin

RichRauenzahn mannequin commented Feb 28, 2012

BPO 14146
Nosy @loewis, @terryjreedy, @serwy, @rovitotv
Files
  • win_highlighting.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serwy'
    closed_at = <Date 2013-05-29.04:24:23.023>
    created_at = <Date 2012-02-28.04:01:48.091>
    labels = ['expert-IDLE', 'type-bug']
    title = "IDLE: source line in editor doesn't highlight when debugging"
    updated_at = <Date 2015-09-28.03:30:17.769>
    user = 'https://bugs.python.org/RichRauenzahn'

    bugs.python.org fields:

    activity = <Date 2015-09-28.03:30:17.769>
    actor = 'terry.reedy'
    assignee = 'roger.serwy'
    closed = True
    closed_date = <Date 2013-05-29.04:24:23.023>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2012-02-28.04:01:48.091>
    creator = 'Rich.Rauenzahn'
    dependencies = []
    files = ['29786']
    hgrepos = []
    issue_num = 14146
    keywords = ['patch']
    message_count = 32.0
    messages = ['154533', '154566', '154571', '154591', '183793', '183833', '183851', '183853', '185516', '185535', '185536', '185539', '185578', '185582', '185608', '185631', '185632', '186061', '186608', '186610', '188655', '188751', '189092', '189096', '189192', '189194', '189718', '189719', '190271', '225376', '225380', '251748']
    nosy_count = 7.0
    nosy_names = ['loewis', 'terry.reedy', 'roger.serwy', 'Todd.Rovito', 'python-dev', 'Rich.Rauenzahn', 'dzabel']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue14146'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @RichRauenzahn
    Copy link
    Mannequin Author

    RichRauenzahn mannequin commented Feb 28, 2012

    Using 64bit python for windows downloaded from python.org on 64bit windows 7.

    Python Version 3.2.2
    Tk version 8.5
    IDLE version 3.2.2

    When stepping through code the corresponding line in the editor does not highlight with the code steps. The windows does update the contents, so it appears to be tracking, but just fails to highlight the line.

    Double clicking on the line in the debugger will go ahead and highlight it. My settings are all default, and I've double checked the color schemes in the "highlighting" dialog.

    @RichRauenzahn RichRauenzahn mannequin added topic-IDLE type-bug An unexpected behavior, bug, or error labels Feb 28, 2012
    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Feb 28, 2012

    Is the "Source" check box in the Debug Control window checked?

    @RichRauenzahn
    Copy link
    Mannequin Author

    RichRauenzahn mannequin commented Feb 28, 2012

    Yes, the source box was checkmarked.

    Not the first one to encounter this as well:

    http://python.6.n6.nabble.com/IDLE-not-highlighting-current-line-while-debugging-on-Win-td2113345.html

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Feb 29, 2012

    I am not seeing this problem under Ubuntu, but I do see this problem on Vista. It looks like the "sel" tags get hidden when a window loses focus under Windows.

    @terryjreedy
    Copy link
    Member

    I closed bpo-17382 as a duplicate of this. The OP, Dirk, only had problem on Windows xp, not on Ubuntu 3.2 and 3.3. I see the same problem on 3.3 win 7.

    Roger, do you think this is a windows, tkinter, or idle problem?

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Mar 9, 2013

    I think it's a problem on Tk on Windows. The painting of the selection
    highlight goes away when a window loses focus.

    @dzabel
    Copy link
    Mannequin

    dzabel mannequin commented Mar 9, 2013

    If this is a Tk problem on windows, are there any chances to get it fixed? The Tk version installed with python 3.3 seems to be 8.5.11, while there are newer Tk versions available on www.activestate.com (8.5.13 and 8.6.0). But I don't know how to connect a stand-alone version of Tcl/Tk with Python, and I don't want to mess up my Python installation.

    @terryjreedy
    Copy link
    Member

    Martin, is there any way to test if tcl/tk 8.5.13 and/or 8.6.0 fix this windows-only tk issue?

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented Mar 29, 2013

    I was going to try Python 3.4 and TK 8.6 on Windows and see what happens.

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented Mar 30, 2013

    I tried both TCL/TK 8.5.13 and TCL/TK 8.6 with the latest Python 3.4 on Windows 7 the editor window never showed a line as I stepped through the debugger. I am going to try in Mac/Linux to make sure I am not crazy that a line in the editor window does indicate where the debugger is. Then I intend to look in the bug tracker on TCL/TK and possibly post a question for help. On Windows the initial line does look funny on a line with a quoted string such as print("hello world") the yellow does not cover the quoted string.

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented Mar 30, 2013

    Before I forget here are the general steps I followed to get TCL/TK 8.5.13 and 8.6 to work. For TCL/TK 8.6 I had to change the actual Visual Studio 2010 project.

    Generally you have to follow the steps in readme.txt located in PCBuild of the source tree. readme.txt references a file Tools\buildbot\external.bat which has the step by step instructions on how to build TCL/TK. Skip the part about going to svn.python.org/external because neither 8.6 or 8.5.13 have been added yet. So I downloaded the code from the sourceforge.net TCL/TK site. This post explains a step that must be performed which is not documented in any of the references above:
    http://mail.python.org/mailman/private/core-mentorship/2013-March/001593.html

    Finally for TCL/TK 8.6 I had to change the visual studio project to use the right .lib file for TCL/TK. Start Visual Studio 2010 right click _tkinter project then select properties. Under the Linker/Input option set Additional Dependencies to c:\prog\cpython\tcltk\lib\tcl86tg.lib and c:\prog\cpython\tcltk\lib\tk86tg.lib

    erase the old values. Now rebuild and everything should just work (c) don't forget to manually copy the DLL files to the PCBuild directory.

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented Mar 30, 2013

    I have confirmed that Linux and Mac work great but Windows fails to highlight the current line in the editor window. Next I will try and find/file a bug with the TCL/TK folks.....

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented Mar 30, 2013

    Here is a backtrace from PDB:

    -> self.sync_source_line()
    /Volumes/SecurePython3/cpython/py34/Lib/idlelib/Debugger.py(211)sync_source_line()
    -> self.flist.gotofileline(filename, lineno)
    /Volumes/SecurePython3/cpython/py34/Lib/idlelib/FileList.py(46)gotofileline()
    -> edit.gotoline(lineno)

    /Volumes/SecurePython3/cpython/py34/Lib/idlelib/EditorWindow.py(694)gotoline()
    -> self.center()

    The offending code seems to be in EditorWindow.py:gotoline()

        def gotoline(self, lineno):
            if lineno is not None and lineno > 0:
                self.text.mark_set("insert", "%d.0" % lineno)
                self.text.tag_remove("sel", "1.0", "end")
                self.text.tag_add("sel", "insert", "insert +1l")
                self.center()

    Next I am going to write a small program to try and reproduce the bug so I can file with the TCL/TK folks.

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented Mar 30, 2013

    I created a small test program trying to reproduce the problem on Windows 7, Python 3.4, and TK 8.6. Unfortunately it works fine and each line is highlighted as a user presses ctrl-B. I got the select code straight from IDLE. Any other ideas Roger? This might be an IDLE bug after all.

    from tkinter import *
    
    class SelectTest:
        def __init__(self):
            self.mainwin = Tk()
            # Create a text widget
            # idle creates the text widget like this
            #self.text = text = MultiCallCreator(Text)(text_frame, **text_options)
            self.textbox = Text(self.mainwin, width=80, height=10)
            self.textbox.pack()
    
            # Add some text
            self.textbox.insert(INSERT, "line 1: Select some text\n")
            self.textbox.insert(INSERT, "line 2: Select some text\n")
            self.textbox.insert(INSERT, "line 3: Select some text\n")
            self.textbox.insert(INSERT, "line 4: Select some text\n")
    
            # Add the binding
            self.textbox.bind("<Control-Key-b>", self.select_just_like_idle)
            # just in case caps lock is on
            self.textbox.bind("<Control-Key-B>", self.select_just_like_idle)
            self.lineno = 1
    	
        def select_just_like_idle(self, event):
            print("Select just like idle was called")
            if self.lineno is not None and self.lineno > 0:
                self.textbox.mark_set("insert", "%d.0" % self.lineno)
                self.textbox.tag_remove("sel", "1.0", "end")
                self.textbox.tag_add("sel", "insert", "insert +1l")
                self.lineno = self.lineno + 1
    
    
    if __name__ == "__main__":
        # Start the program
        selectIDLETest = SelectTest()
        selectIDLETest.mainwin.mainloop()

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Mar 31, 2013

    It's definitely a "bug" with Tk. Whenever the Text widget loses focus, the selection highlighting goes away. The following example code brings up a focused text box with selected text. Clicking the button switches focus to the button itself and then back to the text widget. During that focus change, the selection highlight goes away.

    from tkinter import *
    main = Tk()
    text = Text(main, width=40, height=10, wrap="char")
    text.pack()
    text.insert(INSERT, "".join(map(str, range(100))))
    text.tag_add(SEL, "1.0", "end")
    text.focus_set()
    def jump():
        text.after(500, btn.focus_set)
        text.after(1000, text.focus_set)
    btn = Button(main, text="Click me", command=jump)
    btn.pack()
    main.mainloop()

    One possible solution would be to use the "<FocusOut>" and "<FocusIn>" events to substitute the "sel" tag with a custom tag so that the highlight remains when losing focus, and then replace it with the "sel" tag when gaining focus.

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented Mar 31, 2013

    Roger,
    You are a genius!!!!! The example program duplicates the bug exactly. It works on Mac (I assume Linux but I will test on Linux) and it does not work on correctly on Windows. On Windows as soon as the text widget looses focus then the hi-light disappears. I will use this code and file a bug report for TCL/TK and post on the tkinter mailing list. Thank you I was stuck.

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented Mar 31, 2013

    Bug report has been filed with Tk here:
    https://sourceforge.net/tracker/?func=detail&aid=3609608&group_id=12997&atid=112997

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented Apr 5, 2013

    I posted this message on tinter discuss email list:
    http://mail.python.org/pipermail/tkinter-discuss/2013-March/003415.html

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Apr 12, 2013

    Todd, thank you for being proactive with the Tcl/Tk community. Hopefully they will offer a fix in their next version.

    In the meanwhile, here's a patch that works around the problem on Windows. The purpose of getting the highlight configuration at each FocusOut event is in case the current theme changes.

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented Apr 12, 2013

    I forgot to mention that the idea for replacing the "sel" tags is based on an idea from Sarah's patch from bpo-17511.

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented May 7, 2013

    I'm pinging this issue to see if anyone has had any problems with the Windows-specific workaround for highlighting the selection tags. bpo-17511 depends on this fix.

    @serwy serwy mannequin self-assigned this May 7, 2013
    @terryjreedy
    Copy link
    Member

    64 bit Win 7 with 32 bit debug build.
    Patch imported cleanly with all 3 branches. I cannot currently test 2.7. On 3.3 and 3.4, debugger worked fine relative to this issue: editor window highlight tracked line displayed in debugger as far as I checked.
    Normal selection and Shell Go to file/line highlight seem to work normally. Normal color marking seems not affected. I cannot think of any more manual tests. So if someone else checks 2.7 and it is also ok, I think you should apply this, so if there is any problem, it can show up in other usage. We can deal with a patched tk if and when it happens.

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented May 13, 2013

    I'm waiting until after the next wave of maitenance releases before I apply this patch. If anyone feels strongly that it should be applied now, let me know.

    I applied the patch to the latest 2.7.4 64-bit release version of Python and it worked.

    @rovitotv
    Copy link
    Mannequin

    rovitotv mannequin commented May 13, 2013

    Roger,
    If you and Terry tested I would apply now so it makes it into 2.7.5. Why not? Right now the debugger in Windows doesn't highlight and I am sure that has to drive people crazy. But if you feel it needs more testing maybe you should let it bake some more?

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented May 14, 2013

    It won't make it in 2.7.5. Benjamin tagged the 2.7.5 release a couple of days ago.

    I'll apply this later tonight.

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented May 14, 2013

    On second thought, I'll wait until after the releases so that Misc/NEWS gets populated properly.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 21, 2013

    New changeset 5ae830ff6d64 by Roger Serwy in branch '2.7':
    bpo-14146: Highlight source line while debugging on Windows.
    http://hg.python.org/cpython/rev/5ae830ff6d64

    New changeset 3735b4e0fc7c by Roger Serwy in branch '3.3':
    bpo-14146: Highlight source line while debugging on Windows.
    http://hg.python.org/cpython/rev/3735b4e0fc7c

    New changeset b56ae3f878cb by Roger Serwy in branch 'default':
    bpo-14146: merge with 3.3.
    http://hg.python.org/cpython/rev/b56ae3f878cb

    @serwy
    Copy link
    Mannequin

    serwy mannequin commented May 21, 2013

    I committed the Tk workaround for the Windows platform. I'm leaving this issue as pending with a resolution of later in case Tk developers address the bug report mentioned in msg185632.

    If anyone else wishes to close it, feel free.

    @terryjreedy
    Copy link
    Member

    This appears fixed for not, even if not the way we would like. Thanks.
    If a future tk changes, a new patch will be version-dependent and that will be a new issue.

    @terryjreedy
    Copy link
    Member

    Regardless of what I said in the previous message, highlighting of found text is NOT working in any current release -- 2.7.8, 3.3.5 (final release) and 3.4.1. Mark Lawrence opened bpo-22179. I propose there to use the 'found' highlight, as used in the replace dialog. for the find dialog also.

    @terryjreedy
    Copy link
    Member

    Sorry, wrong issue (should have been bpo-17511). Debugger source line highlighting works fine.

    @terryjreedy
    Copy link
    Member

    The workaround function added in this issue is replaced in bpo-24972 with the Text widget inactiveselectbackground option. In the course of testing, I discovered that while the function still works, debugger source highlighting no longer does, at least not on my machine. I opened new issue bpo-25254. On the other hand, find seems to be working better.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-IDLE type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant