Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You'll be called to a post requiring ability in handling groups of people.


comp / comp.lang.tcl / Re: I am failing to get a hide/show dialog to show more than once

SubjectAuthor
* I am failing to get a hide/show dialog to show more than onceMark Summerfield
`* Re: I am failing to get a hide/show dialog to show more than onceRalf Fassel
 +- Re: I am failing to get a hide/show dialog to show more than onceMark Summerfield
 `* Re: I am failing to get a hide/show dialog to show more than onceMark Summerfield
  `- Re: I am failing to get a hide/show dialog to show more than onceRalf Fassel

1
Subject: I am failing to get a hide/show dialog to show more than once
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Wed, 26 Jun 2024 09:59 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-4.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 26 Jun 2024 09:59:48 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: I am failing to get a hide/show dialog to show more than once
Newsgroups: comp.lang.tcl
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <eYecndBfv-AJe-b7nZ2dnZfqnPUAAAAA@brightview.co.uk>
Date: Wed, 26 Jun 2024 09:59:48 +0000
Lines: 102
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-3GrOfwm5wzaqIP4yDGUvm8HnJwIqp0yILnkD+R+P+wLtUZtiMxT452z6bBPldOEtOrmJa8gJx1dbtp5!X5Sr0pyU95Ef9s+u2ZWl1VuAg+aDVC/6FZkMMcVtz7ofkWamZq2tguMqocZyEfteAYdF7fz1Io9T!NYTuCGQbkjomydZK3IcU/ob+eA==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

I've made a cut-down example shown below.
If I click the Options button the Options dialog shows as it should.
And if I click the Options dialog's Close button it is hidden.
But if I click the Options button a second time I get the error:

bad window path name ".optionsForm"

Clearly I've made a mistake, but I don't know Tcl/Tk well enough to see
what I've done wrong.

#!/usr/bin/env wish9

package require tepam

tk scaling 1.67
tk appname HideShow

proc main {} {
wm withdraw .
wm title . [tk appname]
wm attributes . -type dialog
wm minsize . 200 200
make_widgets
wm deiconify .
raise .
}

namespace eval test {
variable optionsButton
variable optionsForm
}

proc make_widgets {} {
set test::optionsButton [ttk::button .optionsButton -text Options… \
-underline 0 -command test::on_options]
pack .optionsButton
bind . <Alt-o> {$test::::optionsButton invoke}
bind . <Escape> {destroy .}
}

# Hide/show dialog
proc test::on_options {} {
if {![info exists ::test::optionsForm]} {
puts "on_options init"
set ::test::optionsForm [toplevel .optionsForm]
wm title .optionsForm "Options — [tk appname]"
ttk::label .optionsForm.label -text "Options go here"
grid .optionsForm.label -row 0 -column 0
ttk::button .optionsForm.closeButton -text Close \
-command {destroy $::test::optionsForm}
grid .optionsForm.closeButton -row 1 -column 0
dialog prepare .optionsForm
wm protocol .optionsForm WM_DELETE_WINDOW \
{dialog hide $::test::optionsForm}
bind .optionsForm <Escape> {destroy $::test::optionsForm}
}
puts on_options
dialog show .optionsForm
}

namespace eval dialog {}

tepam::procedure {dialog prepare} {
-named_arguments_first 0
-args {
{-modeless -type none}
{-parent -default .}
{window}
}
} {
wm withdraw $window
wm attributes $window -type dialog
if {!$modeless} { wm transient $window $parent }
}

tepam::procedure {dialog show} {
-named_arguments_first 0
-args {
{-modeless -type none}
{-focuswidget -default ""}
{window}
}
} {
puts "dialog show $window"
wm deiconify $window
raise $window
focus $window
if {$focuswidget ne ""} {focus $focuswidget}
if {!$modeless} {
catch {grab set $window}
catch {tkwait visibility $window}
}
}

tepam::procedure {dialog hide} {
-args { {window} }
} {
wm withdraw $window
grab release $window
}

main

Subject: Re: I am failing to get a hide/show dialog to show more than once
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Wed, 26 Jun 2024 10:23 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: I am failing to get a hide/show dialog to show more than once
Date: Wed, 26 Jun 2024 12:23:13 +0200
Lines: 27
Message-ID: <ygazfr8t33i.fsf@akutech.de>
References: <eYecndBfv-AJe-b7nZ2dnZfqnPUAAAAA@brightview.co.uk>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net +NfPS8ADiTgpy7r/DNvqgwDl080Y/10ZXpHZwdJyff1W3XCB0=
Cancel-Lock: sha1:RUDV6r9wDI2vhsBdP7qcnB+bhfk= sha1:StrS/OKjzVT4a9BdUfCBrgLj6PI= sha256:CSEdMXJr7xayFc8LSKQVvFw/WuiE8UOTa8W23/enyKg=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* Mark Summerfield <mark@qtrac.eu>
| I've made a cut-down example shown below.
| If I click the Options button the Options dialog shows as it should.
| And if I click the Options dialog's Close button it is hidden.

No, it's not, it is destroyed (as you requested by)

| ttk::button .optionsForm.closeButton -text Close \
| -command {destroy $::test::optionsForm}

Part of the problem is that you only check for the existence of the
variable, but not of the window it describes. The second time you call
test::on_options, the variable exists, but the window does not since it
was destroyed by the closeButton.

| # Hide/show dialog
| proc test::on_options {} {
| if {![info exists ::test::optionsForm]} {

I suggest to add
|| ![winfo exists $::test::optionsForm]

in test::on_options (and probably to unify all the different ways to
withdraw/destroy the window - Close button, WM_DELETE, Escape).

HTH
R'

Subject: Re: I am failing to get a hide/show dialog to show more than once
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Thu, 27 Jun 2024 06:31 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!nntp.giganews.com!local-3.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 27 Jun 2024 06:31:30 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: I am failing to get a hide/show dialog to show more than once
Newsgroups: comp.lang.tcl
References: <eYecndBfv-AJe-b7nZ2dnZfqnPUAAAAA@brightview.co.uk>
<ygazfr8t33i.fsf@akutech.de>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <utudnea1LKbfmuD7nZ2dnZfqnPUAAAAA@brightview.co.uk>
Date: Thu, 27 Jun 2024 06:31:30 +0000
Lines: 42
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-zn54C/ziAXnYaBK4Rn2Xn8jN2w6CNkLcX+vkTo7ucUhUWeGUWjPsffkqse2Kxyy0r0GfLJuAp2DKTeo!Yq50isPcCOCmdHWm2bJ7gnskdcLbYjuahJkvdxpyozgrn3q9OjPyya0CZ/SekI5xknwJZYXnLev0!AKpk+0Oxiepgs/uRM6L3T2o3YA==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

On Wed, 26 Jun 2024 12:23:13 +0200, Ralf Fassel wrote:

> * Mark Summerfield <mark@qtrac.eu>
> | I've made a cut-down example shown below.
> | If I click the Options button the Options dialog shows as it should. |
> And if I click the Options dialog's Close button it is hidden.
>
> No, it's not, it is destroyed (as you requested by)
>
> | ttk::button .optionsForm.closeButton -text Close \
> | -command {destroy $::test::optionsForm}
>
> Part of the problem is that you only check for the existence of the
> variable, but not of the window it describes. The second time you call
> test::on_options, the variable exists, but the window does not since it
> was destroyed by the closeButton.
>
> | # Hide/show dialog | proc test::on_options {} {
> | if {![info exists ::test::optionsForm]} {
>
> I suggest to add
> || ![winfo exists $::test::optionsForm]
>
> in test::on_options (and probably to unify all the different ways to
> withdraw/destroy the window - Close button, WM_DELETE, Escape).
>
> HTH R'

You are quite right, I made a silly copy/paste mistake.

I now use a lambda:

set on_close [lambda {} {dialog hide .optionsForm}]

and set this and the close button's command, the wm protocol for delete
window and for Esc.

I have not added the or-clause you suggested since my view is that if the
variable exists and the window doesn't it is a coding error and I want the
exception.

Thanks for your help.

Subject: Re: I am failing to get a hide/show dialog to show more than once
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Thu, 27 Jun 2024 06:51 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-4.nntp.ord.giganews.com!nntp.giganews.com!local-2.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 27 Jun 2024 06:51:18 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: I am failing to get a hide/show dialog to show more than once
Newsgroups: comp.lang.tcl
References: <eYecndBfv-AJe-b7nZ2dnZfqnPUAAAAA@brightview.co.uk>
<ygazfr8t33i.fsf@akutech.de>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <5Pqdnbdjd8R7luD7nZ2dnZfqnPudnZ2d@brightview.co.uk>
Date: Thu, 27 Jun 2024 06:51:18 +0000
Lines: 23
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-W0dopL02gi1v/DB+2MRoXZHffEWtm1sLlIZCPe/4WD/SztpH3pZ25Mv06iXhjzQ1mc3ogOlbyJjFU7s!xQta+fpRZScN2QWcrjAy5FR5Pi3J6E5FJL/OxzvY476sQOBE2R/tqM1J9Rkd45a4+2hkl4N8Q+04!F9bLyXLjPhseg4mdXieU7zmMsA==
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

[snip]

Based on your idea of using winfo exists I've now refined the on_options
proc to this:

proc test::on_options {} {
if {![winfo exists .optionsForm]} {
puts "on_options init"
toplevel .optionsForm
set on_close [lambda {} {dialog hide .optionsForm}]
wm title .optionsForm "Options — [tk appname]"
ttk::label .optionsForm.label -text "Options go here"
grid .optionsForm.label -row 0 -column 0
ttk::button .optionsForm.closeButton -text Close -command
$on_close
grid .optionsForm.closeButton -row 1 -column 0
wm protocol .optionsForm WM_DELETE_WINDOW $on_close
bind .optionsForm <Escape> $on_close
dialog prepare .optionsForm
}
puts on_options
dialog show .optionsForm
}

Subject: Re: I am failing to get a hide/show dialog to show more than once
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Thu, 27 Jun 2024 08:46 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: I am failing to get a hide/show dialog to show more than once
Date: Thu, 27 Jun 2024 10:46:39 +0200
Lines: 41
Message-ID: <ygav81uu61c.fsf@akutech.de>
References: <eYecndBfv-AJe-b7nZ2dnZfqnPUAAAAA@brightview.co.uk>
<ygazfr8t33i.fsf@akutech.de>
<5Pqdnbdjd8R7luD7nZ2dnZfqnPudnZ2d@brightview.co.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net TQUy1xZb4zwBZK+iGYK3LAe1jk8z6ZWn/6pDXeqXQ5oGAOS/8=
Cancel-Lock: sha1:Id5mYCsHGtm3Oz2wBNDrLkVpNso= sha1:TG0H92izc2r9/bgZn/S9/XRJ6Y4= sha256:Ylm3LQww9jXx6eTG3iTUaLdQVfBi8h8z1U6mx6GYUo4=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
View all headers

* Mark Summerfield <mark@qtrac.eu>
| proc test::on_options {} {
| if {![winfo exists .optionsForm]} {
| puts "on_options init"
| toplevel .optionsForm
| set on_close [lambda {} {dialog hide .optionsForm}]
| wm title .optionsForm "Options — [tk appname]"
--<snip-snip>--

I make a habit of putting the layout of any widget structure in
variables, so if I decide to add another frame or toplevel or whatever,
I just need to change the variables and leave the rest of the code
unchanged:

proc test::on_options {} {
set w(optionsForm) .optionsForm
set w(optionsLabel) $w(optionsForm).label
set w(optionsClose) $w(optionsForm).closeButton
if {![winfo exists $w(optionsForm)]} {
puts "on_options init"
toplevel $w(optionsForm)
set on_close [lambda {} [list dialog hide $w(optionsForm)]]
wm title $w(optionsForm) "Options — [tk appname]"

ttk::label $w(optionsLabel) -text "Options go here"
grid $w(optionsLabel) -row 0 -column 0
ttk::button $w(optionsClose) -text Close -command $on_close
grid $w(optionsClose) -row 1 -column 0
...

Say I need the options frame as child of a different widget than ".",
I could just change the proc to

proc test::on_options {top} {
set w(optionsForm) $top.optionsForm
...

and be done.

HTH
R'

1

rocksolid light 0.9.8
clearnet tor