[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-10-28 Thread primexx
Change by primexx : -- nosy: +primexx ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Guido van Rossum
Change by Guido van Rossum : -- nosy: -gvanrossum ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Guido van Rossum
Guido van Rossum added the comment: I don't recall anything about that, sorry. -- ___ Python tracker ___ ___ Python-bugs-list

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread E. Paine
E. Paine added the comment: > I don't think this worked if the Tcl interpreter had been garbage collected Turns out I was wrong, it appears it *does* work. The only thing we need to change is ensuring the GIL is held when calling finalise (because, as Guido's comment says, this process can

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Tal Einat
Tal Einat added the comment: After thinking about this a bit more, it seems to me that using an atexit handler is definitely worth pursuing, but not for 3.10.0. I'm in favor of merging the existing PR as an immediate fix for IDLE, and following up with a general solution for tkinter using

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Tal Einat
Tal Einat added the comment: > Tcl_Finalize can be called more than once, says the tcl doc. I take that to mean that when calling Tcl_Finalize more than once, the second and following calls will do nothing rather than crash the process, corrupt memory etc. The Tcl docs are quite clear that

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Terry J. Reedy
Terry J. Reedy added the comment: Tcl_Finalize can be called more than once, says the tcl doc. It also says it, or T_FThread should be called when unloading. If the tcl implementation on some system does not match the doc, then there is a bug that should be reported. If the registration is

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread E. Paine
E. Paine added the comment: > Simply uncommenting that works perfectly on Ubuntu 20.04 and Windows 10. I can't remember the details, but I don't think this worked if the Tcl interpreter had been garbage collected before the Python interpreter shutdown. Therefore, Tcl_Finalize (or similar)

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It was commented out in commit 43ff8683fe68424b9c179ee4970bb865e11036d6 Author: Guido van Rossum Date: Tue Jul 14 18:02:13 1998 + Temporarily get rid of the registration of Tcl_Finalize() as a low-level Python exit handler. This can attempt

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Tal Einat
Tal Einat added the comment: Wow, I'm very surprised! Simply uncommenting that works perfectly on Ubuntu 20.04 and Windows 10. I'll make a new PR... -- ___ Python tracker

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: That comment may be outdated. The atexit callbacks are called very early at the interpreter shutdown stage. The interpreter is still entirely intact at this point. -- ___ Python tracker

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Tal Einat
Tal Einat added the comment: > What if register Tcl_Finalize as an atexit callback? Precisely that was tried a long time ago (2002?) and decided against, as can be seen by the comment left behind at the end of _tkinter.c: #if 0 /* This was not a good idea; through bindings,

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: What if register Tcl_Finalize as an atexit callback? -- ___ Python tracker ___ ___

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: > Pablo, would you allow the _tkinter change in .0b2? I checked the change and I think is scoped enough and doesn't change the public API (and it solves a bug). Is fine with me, but please make sure of the following: * At least a core dev reviews

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Tal Einat
Change by Tal Einat : -- versions: +Python 3.11 -Python 3.8 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Tal Einat
Tal Einat added the comment: > Can we backport? The change to _tkinter, not directly exposed in tkinter, > could be considered an enhancement, but is necessary to fix what I consider a > real bug in tkinter, and hence in IDLE. I'm +1 for backporting the latest PR. It only adds the clearly

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Terry J. Reedy
Terry J. Reedy added the comment: As Tal notes on the PR, the _tkinter patch is the minimum needed to fix the problem for IDLE, not the undetermined patch to tkinter that should be done to properly expose the fix to all tkinter users. If the tcl function were exposed with a presumably

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Terry J. Reedy
Terry J. Reedy added the comment: Can we backport? The change to _tkinter, not directly exposed in tkinter, could be considered an enhancement, but is necessary to fix what I consider a real bug in tkinter, and hence in IDLE. Pablo, would you allow the _tkinter change in .0b2? If we

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Terry J. Reedy
Terry J. Reedy added the comment: Tal: cancel comment above. I was confused because FinalizeThread is exposed as just finalize. On Windows, PR fixes issue whether Shell or editor is closed last. -- ___ Python tracker

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Terry J. Reedy
Terry J. Reedy added the comment: Serhiy: what do you know of tcl finalization? Tal: why does your patch only expose the option that you said crashes ubuntu. Spacekiwigames: if you have a cpython fork and local repository, you could try the patch on your linux mint. -- nosy:

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Tal Einat
Change by Tal Einat : -- pull_requests: +24796 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/26163 ___ Python tracker ___

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Tal Einat
Tal Einat added the comment: See PR GH-26163. -- stage: patch review -> needs patch ___ Python tracker ___ ___ Python-bugs-list

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2021-05-16 Thread Tal Einat
Tal Einat added the comment: Okay, so it appears that a generic solution for tkinter is non-trivial, as it is not clear when to call Tcl_Finalize() or Tcl_FinalizeThread(). However, giving tkinter apps the ability to call those when appropriate is possible. Exposing a thin wrapper around

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-12-07 Thread Tal Einat
Change by Tal Einat : -- Removed message: https://bugs.python.org/msg382632 ___ Python tracker ___ ___ Python-bugs-list mailing

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-12-07 Thread E. Paine
E. Paine added the comment: Removed Alex from nosy because the link was an advertisement for an essay writer. -- nosy: -alexwriter2003 ___ Python tracker ___

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-12-07 Thread Alex Writer
Alex Writer added the comment: Testing with a minimal tkinter app (see code below) gives similar behavior, so this appears to be an issue with tkinter https://goo.gl/2DqXGj and/or tcl/tk. import tkinter text = tkinter.Text() -- nosy: +alexwriter2003

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-11-02 Thread Tal Einat
Tal Einat added the comment: Perhaps we could get a Tcl/Tk dev to help with this? -- ___ Python tracker ___ ___ Python-bugs-list

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-09-04 Thread Terry J. Reedy
Terry J. Reedy added the comment: I closed duplicate issue #41709, Linux Mint 19.3, python 3.6.8 -- versions: -Python 3.7 ___ Python tracker ___

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-22 Thread E. Paine
E. Paine added the comment: Unfortunately, after lots of testing/experimenting, I cannot find a way to make the correct call/s at the correct time. The methods that call the exit handlers directly or through InvokeExitHandlers are Tcl_Exit, Tcl_Finalize & FinalizeThread (Tcl_FinalizeThread)

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-20 Thread Tal Einat
Tal Einat added the comment: Attaching the changes I made while testing as a patch file. -- Added file: https://bugs.python.org/file49173/tkinter-clipboard-on-exit.patch ___ Python tracker

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-20 Thread E. Paine
E. Paine added the comment: After some initial testing, I have found that while calling Tcl_Finalize on window closure keeps the clipboard contents (as expected), it also finishes the Python interpreter. The solution was to instead use the Tcl_FinalizeThread method, "which you can call if

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-20 Thread Tal Einat
Tal Einat added the comment: Regarding multiple Tk instances, IMO we should try the straightforward solution first: Tcl/Tk has its own mechanisms for handling per-interpreter state, so we may not actually need to handle any of this ourselves. Regarding the title of this issue, it is indeed

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-20 Thread E. Paine
E. Paine added the comment: Multiple Tk instances are already recommended against, but what would be the implications of preventing multiple roots? A simple check could be added to the Tk class init which ensures _default_root is None (if it is not None, an error is raised). In this case,

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread Terry J. Reedy
Change by Terry J. Reedy : -- versions: +Python 3.10 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread Terry J. Reedy
Terry J. Reedy added the comment: The #if 0 was added by Guido in 43ff8683fe68424b9c179ee4970bb865e11036d6 in 1998, before the tcl/tk clip fix for Windows. * Temporarily get rid of the registration of Tcl_Finalize() as a low-level Python exit handler. This can attempt to call Python code at

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread Terry J. Reedy
Terry J. Reedy added the comment: After reporting my experiments above, msg369334, I made further failing efforts to simulate pasting into another process, as in 3 and 4. It might be that a concrete key event is needed. So I strongly suspect that the solution for IDLE is indeed a tkinter

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread Tal Einat
Tal Einat added the comment: epaine, if you'd like to create a new PR based on these findings, I'd be happy to review it! -- ___ Python tracker ___

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread Tal Einat
Tal Einat added the comment: Indeed, adding a simple _tkinter.destroy() method which invokes Tcl_Finalize, and calling it in the Tk.destroy() method, makes copied text remain available after closing IDLE! I did the above to test my hypothesis, but I'm not sure it would be a proper fix.

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread Tal Einat
Tal Einat added the comment: During finalization, TkFinalizeThread would call DeleteWindowsExitProc (registered via TkCreateThreadExitHandler). This in turn is set as a thread-exit handler via Tcl_CreateThreadExitHandler upon the first call to TkCreateThreadExitHandler. Now we're out of Tk

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread Tal Einat
Tal Einat added the comment: Indeed, you've got that pretty much correct. The call chain is: Tk.__init__ _tkinter_create_impl (called as _tkinter.create() from Python) Tkapp_New Tkapp_New does a lot of things. In particular, it calls Tcl_CreateInterp and later Tcl_AppInit. Tcl_AppInit

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread E. Paine
E. Paine added the comment: I'm (sadly) not particularly familiar with C, though I have tried to trace the calls of TkClipCleanup. As @taleinat mentioned, it is called by the TkCloseDisplay, though, in turn, I believe this method is called by the DeleteWindowsExitProc method. The name

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread Tal Einat
Tal Einat added the comment: Note that Tcl/Tk once had exactly the same issue on Windows, and they added specific code to "render" to the clipboard upon exit if the current app is the "clipboard owner". https://core.tcl-lang.org/tk/tktview/732662 This was fixed here:

[issue40452] Tkinter/IDLE: preserve clipboard on closure

2020-05-19 Thread Terry J. Reedy
Terry J. Reedy added the comment: I ran your tkinter code on Windows, without IDLE, and the clipboard was clear thereafter. I added 'test.mainloop()' and observed the following. 1. Close immediately, clipboard is clear, as before. 2. Paste 'Testing again' into 'text' with ^V and close, and