Problem #1:
spinbox:
Command-Line Name: -textvariable
Specifies the name of a global variable. The value of the variable is
a text string to be displayed inside the widget; if the variable value changes then the widget will automatically update itself to reflect the
new value. The way in which the string is displayed in the widget
depends on the particular widget and may be determined by other
options, such as -anchor or -justify.
I dislike that. When the dialog is launched, it has a spinbox that is supposed to display an initial value. While I was working in the global scope, it worked fine. Then I put everything into a namespace and now
that variable doesn't work anymore, even if I refer to it by its
complete path, i.e. including namespace.
So I am forced to make that variable global to make the widget look correctly. This is supposed to be a package. What if my global variable clashes with another global variable in someone else's code?
What do you think of this? Any solutions?
Optional: video showing the problem:
https://0x0.st/HhyO.mp4
Problem #2:
I have this binding inside a namespace. Its command became too long
so I decided to make a proc out of it.
proc p.home
bind $namebox <Home> p.home
It doesn't work. The compiler can't find the proc.
So I use its complete path:
bind $namebox <Home> typychooser::p.home
Now it can find the proc, but can't find the variable.
So I make the proc run everything in the variable's namespace with
eval. But the compiler still can't see the variable.
1. Why?
2. How do I get out of this straitjacket?
1. Why?
Bindings execute at the global level, outside of any namespace, so you
can't point a binding at a proc that is in a namespace without a bit of >extra work.
2. How do I get out of this straitjacket?
Read the documentation for "namespace code" in the namespace manpage.
It provides the "bit of extra work" you are missing.
Why is SpinboxFontSize found in the [info vars] list but not pf,
guifontsize and many others? They all exist within the scope of the
same namespace.
Very confusing.
On Mon, 11 Mar 2024 20:53:51 -0000 (UTC), Rich wrote:
1. Why?
Bindings execute at the global level, outside of any namespace, so you >>can't point a binding at a proc that is in a namespace without a bit of >>extra work.
2. How do I get out of this straitjacket?
Read the documentation for "namespace code" in the namespace manpage.
It provides the "bit of extra work" you are missing.
I don't get it.
set [namespace current]::runhome [namespace code {
puts [list [$namebox itemconfigure 0]]
$namebox selection clear 0 end
$namebox selection set 0
$namebox selection anchor 0
$namebox see 0
}]
puts [set [namespace current]::runhome]
bind $namebox <Home> {eval $::typychooser::runhome}
So I run the code and the puts line (outside the proc) outputs this:
::namespace inscope ::typychooser {
puts [list [$namebox itemconfigure 0]]
$namebox selection clear 0 end
$namebox selection set 0
$namebox selection anchor 0
$namebox see 0
}
But when I press Home...
can't read "namebox": no such variable
while executing
"$namebox itemconfigure 0"
(in namespace inscope "::typychooser" script line 2)
invoked from within
"::namespace inscope ::typychooser {
puts [list [$namebox itemconfigure 0]]
$namebox selection clear 0 end
$namebox selection set 0
$namebo..."
("eval" body line 1)
invoked from within
"eval $::typychooser::runhome"
(command bound to event)
I could fix this now merely replacing $namebox with the hard coded
path of the widget. But I still want to understand this problem.
On Mon, 11 Mar 2024 19:49:09 -0300, Luc wrote:
What I also don't understand:
Regarding problem #1, I followed your guidance:
set [namespace current]::SpinboxFontSize $guifontsize
ttk::spinbox $pf.sizespinbox
$pf.sizespinbox configure -textvariable [namespace current]::SpinboxFontSize
And now the number is shown as expected. OK. Solved.
But wait a minute. Look at those variables...
Back to problem #2:
set [namespace current]::runhome [namespace code {
puts "current [namespace current]"
puts [info vars]
puts [list [$namebox itemconfigure 0]]
$namebox selection clear 0 end
$namebox selection set 0
$namebox selection anchor 0
$namebox see 0
}]
output:
current ::typychooser
SpinboxFontSize runhome version tcl_rcFileName tcl_version argv0 argv tcl_interactive tk_library tk_version auto_path errorCode
tk_strictMotif errorInfo auto_index env tcl_pkgPath tcl_patchLevel
argc tk_patchLevel tcl_library tcl_platform
Why is SpinboxFontSize found in the [info vars] list but not pf,
guifontsize and many others? They all exist within the scope of the
same namespace.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 916 |
Nodes: | 10 (1 / 9) |
Uptime: | 50:14:31 |
Calls: | 12,172 |
Calls today: | 2 |
Files: | 186,522 |
Messages: | 2,234,725 |