In the following, the variable foo is associated with the text entry
.e. If foo is unset, then [unset] silently (no error) returns but
foo still exists. When the text entry is destroyed, then foo can be
truly unset.
I would think that the unset should work a bit like file system file
deletes. If the file is open, the delete becomes a pending delete
until all connections are closed.
Or at minimum, shouldn't the attempt to unset throw an error (since -nocomplain is not used).
et4 <[email protected]> wrote:
Why would you think this? A programming language is not a filesystem,
and not all file systems follow the Unix filesystem model of allowing
deletes of open files.
So throwing no errors seems fully within the documentation of how unset works.
The only 'quirk' is that foo does not go away because the entry is also connected to it via the textvariable option (and this is probably why
it does not actually go away).
On 10/14/2022 7:14 PM, Rich wrote:
et4 <[email protected]> wrote:
Why would you think this? A programming language is not a
filesystem, and not all file systems follow the Unix filesystem
model of allowing deletes of open files.
Hmmm, maybe the principle of least astonishment. I expected that if
some request is not done, there'd be some way to know that.
So throwing no errors seems fully within the documentation of how
unset works.
I agree, it does what it says...
The only 'quirk' is that foo does not go away because the entry is
also connected to it via the textvariable option (and this is
probably why it does not actually go away).
And also agree, it doesn't do what it says here, it doesn't unset the variable. If it's possible that it's not going to, then it should
say so, as long as we're debating whether the manual is fully
describing what the command does.
I stumbled onto this because I have have an in-line wait, that uses
after and vwait so as to not lock up things and will even work in a
callback (albeit only once) while the main code is also doing a
vwait. To accomplish that, it generates temporary global variables
that it unsets when it's done with them.
If there's a better way, I'd be happy to know about that.
et4 <[email protected]> wrote:
On 10/14/2022 7:14 PM, Rich wrote:
I stumbled onto this because I have have an in-line wait, that uses
after and vwait so as to not lock up things and will even work in a
callback (albeit only once) while the main code is also doing a
vwait. To accomplish that, it generates temporary global variables
that it unsets when it's done with them.
Sounds like a fairly standard "don't block the event loop"
1) don't link your event loop semaphore variable to a Tk widget using
-textvariable
2) investigate using coroutines
Looking at tkEntry.c in the Tk 8.6.12 source, it appears that entry uses a variable trace
Looking at tkEntry.c in the Tk 8.6.12 source, it appears that entry uses a variable trace to manage the -textvariable. The variable trace calls a C subroutine EntryTextVarProc (in the same file) to trace writes and unsets on the variable. Thesubroutine EntryTextVarProc contains code with the following comment:
/*
* If the variable is unset, then immediately recreate it unless the whole
* interpreter is going away.
*/
I'm thinking this is a good hint at what is going on.
Dave B
Hmmm, after some further thought, I wonder if it might not be better if this code merely disassociated the variable from the entry widget and let the unset stand. Maybe there's something else going on here that made that a difficult choice.
Good catch Dave!
On Sunday, October 16, 2022 at 4:46:39 AM UTC+2, et4 wrote:
Hmmm, after some further thought, I wonder if it might not be better if this code merely disassociated the variable from the entry widget and let the unset stand. Maybe there's something else going on here that made that a difficult choice.
Good catch Dave!
If I understand correctly, we are looking at Tk's variable trace that is blocking the unset for vwait.
You could check whether another trace still fires. If so, trigger another variable that vwait would then use.
On 10/16/2022 7:28 AM, heinrichmartin wrote:unsetting it. But then my 4-line wait proc would start getting ugly.
On Sunday, October 16, 2022 at 4:46:39 AM UTC+2, et4 wrote:
Hmmm, after some further thought, I wonder if it might not be better if this code merely disassociated the variable from the entry widget and let the unset stand. Maybe there's something else going on here that made that a difficult choice.
Good catch Dave!
If I understand correctly, we are looking at Tk's variable trace that is blocking the unset for vwait.
You could check whether another trace still fires. If so, trigger another variable that vwait would then use.
The problem is in my wait code where I generate a new global for each time I do a vwait with an [after] to set the waited on variable. I could probably do an immediate test using [info exist] to see if the variable has been re-incarnated, and just keep
I'm using the Tk entry as part of a debugging toolset to dynamically display global or namespace static variables. I got the idea fromprogram speed.
Global variable watch & control by RS at
https://wiki.tcl-lang.org/page/What+debugging+tools+are+available+to+a+Tcl+programmer
The beauty of RS's technique is in the ease and efficiency of using the Tk -textvariable option.
Tk is very efficient at this and in my tool's "cruise mode" (variable speed auto-stepping) one can watch variables changing slowly/rapidly while simultaneously see an arrow pointing to the current line of code in a text widget. Spin-boxes control the
One can watch a variable's tk entry going 1-1000 in just a few seconds, or slow it down as much as desired. This is now combined with my Tasks project up on github. BTW, it works somewhat with methods and class data.
I think I might send in a ticket on the Tk entry, as it's now pretty clear that unset is not at fault, but rather the entry code which is re-creating the variable that the programmer has specifically unset.
Trace does this differently - when one unsets a variable that has a trace on it, the trace is automatically removed and the unset stands.
I think the entry widget should work likewise.
Thanks again Dave for clearing up this mystery.
I'm using the Tk entry as part of a debugging toolset to dynamically
display global or namespace static variables.
On 16/10/2022 20:42, et4 wrote:
I'm using the Tk entry as part of a debugging toolset to dynamically display global or namespace static variables.
Try using a ttk::entry instead.
Schelte.
If you follow the above rules, there won't be conflicts between -textvariable variables and wait variables. And the code need not be complicated or ugly.
namespace eval Gensym {
variable counters [array set {}]
proc Gensym {class} {
variable counters
incr counters($class)
return [format {%s%05d} $class $counters($class)
}
}
To generate a new variable to wait on:
Gensym::Gensym wait
To generate a new variable to bind to an entry:
Gensym::Gensym entry
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 24:56:38 |
| Calls: | 12,106 |
| Calls today: | 6 |
| Files: | 15,006 |
| Messages: | 6,518,177 |