Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You never hesitate to tackle the most difficult problems.


comp / comp.lang.tcl / Re: how to create a dialog that is hidden/shown rather than created/destroyed

SubjectAuthor
* how to create a dialog that is hidden/shown rather than created/destroyedMark Summerfield
+* Re: how to create a dialog that is hidden/shown rather than created/destroyedMark Summerfield
|`- Re: how to create a dialog that is hidden/shown rather than created/destroyedMark Summerfield
+* Re: how to create a dialog that is hidden/shown rather than created/destroyedMark Summerfield
|`- Re: how to create a dialog that is hidden/shown rather than created/destroyedRich
`* Re: how to create a dialog that is hidden/shown rather than created/destroyedRich
 +- Re: how to create a dialog that is hidden/shown rather than created/destroyedMark Summerfield
 `- Re: how to create a dialog that is hidden/shown rather than created/destroyedMark Summerfield

1
Subject: how to create a dialog that is hidden/shown rather than created/destroyed
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Fri, 21 Jun 2024 09:55 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: Fri, 21 Jun 2024 09:55:13 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: how to create a dialog that is hidden/shown rather than
created/destroyed
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: <RJ-dnawmWOec0-j7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
Date: Fri, 21 Jun 2024 09:55:13 +0000
Lines: 69
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-Qnew7DPL2SilPRzy9w2gMLpWgDzUoxMre9i7ZTCvxGwF1GJ4u4sAi0M5mh9jxRRfiZyFMQp0qHgyhiq!oL+0gupfMzkU8wmNKn6jL32zibfk9wBvK8c7lOmMrCRZAeHRIraSBzFUY87usXVVFRmjVcr1a00i!TqiujvTaYo0eM5wLdWIv1jRwpw==
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

Below is a tiny program.

The "About" form is created and destroyed. So you can click About then
close the About form, then repeat as often as you like.

The "Options" form is supposed to be shown and hidden. But once you click
it and then close it, the entire app is blocked. So clearly I'm doing
something wrong.

Here's the code using Tcl/Tk 9.0b2 on Linux.

#!/usr/bin/env wish9

if {[info exists env(TK_SCALING)]} { tk scaling $env(TK_SCALING) }

proc prepare_modal {form} {
wm withdraw $form
wm attributes $form -type dialog
wm transient $form .
}

proc show_modal {form {focus_widget ""}} {
wm deiconify $form
raise $form
focus $form
if {$focus_widget ne ""} {
focus $focus_widget
}
catch {grab set $form}
catch {tkwait visibility $form}
}

variable optionsForm

proc main {} {
wm title . "Dialog Tests"
wm minsize . 240 240
wm attributes . -type dialog
ttk::button .optionsButton -text Options… -underline 1 \
-command on_options
ttk::button .aboutButton -text About -underline 1 -command on_about
pack .optionsButton -side top
pack .aboutButton -side top
}

proc on_options {} {
if {![info exists ::optionsForm]} {
puts "on_options init"
set ::optionsForm [toplevel .optionsForm]
prepare_modal .optionsForm
wm protocol .optionsForm WM_DELETE_WINDOW {wm
withdraw .optionsForm}
ttk::label .optionsForm.label -text Options
pack .optionsForm.label
}
puts on_options ;# TODO use show_modal hide/show
show_modal $::optionsForm ;# TODO give focus widget
}

proc on_about {} {
toplevel .aboutForm
prepare_modal .aboutForm
wm protocol .aboutForm WM_DELETE_WINDOW {destroy .aboutForm}
ttk::label .aboutForm.label -text About
pack .aboutForm.label
show_modal .aboutForm
}

main

Subject: Re: how to create a dialog that is hidden/shown rather than created/destroyed
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Fri, 21 Jun 2024 11:49 UTC
References: 1
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-1.nntp.ord.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 21 Jun 2024 11:49:53 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: how to create a dialog that is hidden/shown rather than
created/destroyed
Newsgroups: comp.lang.tcl
References: <RJ-dnawmWOec0-j7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <9JCcna079Nd_9ej7nZ2dnZfqn_WdnZ2d@brightview.co.uk>
Date: Fri, 21 Jun 2024 11:49:54 +0000
Lines: 14
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-SSERYPVTxz9BHsX8pi/rvzSnCcZiDTYsnYgZSYhZcDoz//JZs6Y7WOe09BsYXUkth+WLkuyICuDNIgw!AhZCDyciINiUs72ZXV+zEDMXveNPMy6ESQwmgd6+fz341PbLJypTptwcJ81WhTJYbTS2CW2DdAz1!dWmGBYO32kaUavCUIy8nevDsfA==
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 figured it out.

I replaced this:

catch { tkwait visibility $form }

with

catch {
tkwait visibility $form
grab release $form
}

and now it works.

Subject: Re: how to create a dialog that is hidden/shown rather than created/destroyed
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Fri, 21 Jun 2024 11:58 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-2.nntp.ord.giganews.com!nntp.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: Fri, 21 Jun 2024 11:58:55 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: how to create a dialog that is hidden/shown rather than
created/destroyed
Newsgroups: comp.lang.tcl
References: <RJ-dnawmWOec0-j7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
<9JCcna079Nd_9ej7nZ2dnZfqn_WdnZ2d@brightview.co.uk>
MIME-Version: 1.0
User-Agent: Pan/0.154 (Izium; 517acf4)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <tIacnWqFmMSd9uj7nZ2dnZfqnPGdnZ2d@brightview.co.uk>
Date: Fri, 21 Jun 2024 11:58:56 +0000
Lines: 22
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-Y2bjKTWNxOzSYFUrlTfH8Sfj6mTTT3Z8lTXYPkxeeFxUkFrp+uQ/+6RP4emSVWJH+5f1iCOXEgDm3eL!szc56A2TLv8aOJJJTbE2FtLHgKKOZssAkKRDCfW4491rr8o93K0ihEokcxbVBuWH8/F9rToUhZpu!0jshJvNmtEeZFdtVyKsdB1SjAw==
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 Fri, 21 Jun 2024 11:49:54 +0000, Mark Summerfield wrote:

> I figured it out.
>
> I replaced this:
>
> catch { tkwait visibility $form }
>
> with
>
> catch {
> tkwait visibility $form grab release $form
> }
>
> and now it works.

Actually, it doesn't work. Firstly it stops the Options form from being
modal. Secondly, if you leave it up you can click the main form or the
About button.

What I'm trying to do is create a show/hide form (so it preserves state
between appearances).

Subject: Re: how to create a dialog that is hidden/shown rather than created/destroyed
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Fri, 21 Jun 2024 15:17 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-4.nntp.ord.giganews.com!nntp.giganews.com!local-1.nntp.ord.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: Fri, 21 Jun 2024 15:17:56 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: how to create a dialog that is hidden/shown rather than
created/destroyed
Newsgroups: comp.lang.tcl
References: <RJ-dnawmWOec0-j7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
MIME-Version: 1.0
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <aOWdnd1K6Kw5BOj7nZ2dnZfqnPGdnZ2d@brightview.co.uk>
Date: Fri, 21 Jun 2024 15:17:56 +0000
Lines: 77
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-4ZF0DT+gCh9nEl+YcG3W82kmK+eYVXDMJWDZkouzwkwW/sVgr/dNotmc/cmkBIDFG33VUlPLzNpw42/!Bz4M9O00dyM3h0U0mqxyCL6UXdn3XJXjmmoGOEZm5XoiOmMhyauf1S/i2Mzph0ORUWBWAhly2bEf!d2M0s3pb6fDA6iW/Z9UqdOqH7A==
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 Fri, 21 Jun 2024 09:55:13 +0000, Mark Summerfield wrote:

> Below is a tiny program.
>
> The "About" form is created and destroyed. So you can click About then
> close the About form, then repeat as often as you like.
>
> The "Options" form is supposed to be shown and hidden. But once you
> click it and then close it, the entire app is blocked. So clearly I'm
> doing something wrong.
>
> Here's the code using Tcl/Tk 9.0b2 on Linux.
>
> #!/usr/bin/env wish9
>
> if {[info exists env(TK_SCALING)]} { tk scaling $env(TK_SCALING) }
>
> proc prepare_modal {form} {
> wm withdraw $form wm attributes $form -type dialog wm transient
> $form .
> }
>
> proc show_modal {form {focus_widget ""}} {
> wm deiconify $form raise $form focus $form if {$focus_widget ne ""}
> {
> focus $focus_widget
> }
> catch {grab set $form}
> catch {tkwait visibility $form}
> }
>
> variable optionsForm
>
> proc main {} {
> wm title . "Dialog Tests"
> wm minsize . 240 240 wm attributes . -type dialog ttk::button
> .optionsButton -text Options… -underline 1 \
> -command on_options
> ttk::button .aboutButton -text About -underline 1 -command on_about
> pack .optionsButton -side top pack .aboutButton -side top
> }
>
> proc on_options {} {
> if {![info exists ::optionsForm]} {
> puts "on_options init"
> set ::optionsForm [toplevel .optionsForm] prepare_modal
> .optionsForm wm protocol .optionsForm WM_DELETE_WINDOW {wm
> withdraw .optionsForm}
> ttk::label .optionsForm.label -text Options pack
> .optionsForm.label
> }
> puts on_options ;# TODO use show_modal hide/show show_modal
> $::optionsForm ;# TODO give focus widget
> }
>
> proc on_about {} {
> toplevel .aboutForm prepare_modal .aboutForm wm protocol .aboutForm
> WM_DELETE_WINDOW {destroy .aboutForm} ttk::label .aboutForm.label
> -text About pack .aboutForm.label show_modal .aboutForm
> }
>
> main

I think I have solved it this time.

I added this proc:

proc hide_modal {form} {
wm withdraw $form
grab release $form
}

and changed the protocol call to:

wm protocol .optionsForm WM_DELETE_WINDOW {hide_modal .aboutForm}

It seems to work, but is this now correct?

Subject: Re: how to create a dialog that is hidden/shown rather than created/destroyed
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 21 Jun 2024 16:56 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: how to create a dialog that is hidden/shown rather than created/destroyed
Date: Fri, 21 Jun 2024 16:56:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <v54bcl$38kko$1@dont-email.me>
References: <RJ-dnawmWOec0-j7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
Injection-Date: Fri, 21 Jun 2024 18:56:54 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c1822e671ded941375ba81f7b10eb360";
logging-data="3429016"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ufmC+lysE1Nl66NjZcKCJ"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:Y18NI30Ny6Skv/6VDPkMFFrulDQ=
View all headers

Mark Summerfield <mark@qtrac.eu> wrote:
> Below is a tiny program.
>
> The "About" form is created and destroyed. So you can click About then
> close the About form, then repeat as often as you like.
>
> The "Options" form is supposed to be shown and hidden. But once you click
> it and then close it, the entire app is blocked. So clearly I'm doing
> something wrong.

Based on your code you are showing the options as a "modal" dialog.
Modal means it blocks the rest of the app. Withdrawing the window does
not change its "modalness". You need to not only withdraw the window
but also turn off the "modalness" of the window at the same time.

I.e., you need to "grab release" on the window as part of withdrawing
it.

As a suggestion, you might also consider making the options window
'non-modal' in that it can be open and the rest of the app can still
function. Modality is more often evil than anything else in a GUI.

Subject: Re: how to create a dialog that is hidden/shown rather than created/destroyed
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 21 Jun 2024 16:58 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: how to create a dialog that is hidden/shown rather than created/destroyed
Date: Fri, 21 Jun 2024 16:58:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <v54bfj$38kko$2@dont-email.me>
References: <RJ-dnawmWOec0-j7nZ2dnZfqnPWdnZ2d@brightview.co.uk> <aOWdnd1K6Kw5BOj7nZ2dnZfqnPGdnZ2d@brightview.co.uk>
Injection-Date: Fri, 21 Jun 2024 18:58:28 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c1822e671ded941375ba81f7b10eb360";
logging-data="3429016"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+aQN3rgIItKidNWkfPJ9C"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:nuTOel11Z34bxhkarFfD6Tvdy20=
View all headers

Mark Summerfield <mark@qtrac.eu> wrote:
> On Fri, 21 Jun 2024 09:55:13 +0000, Mark Summerfield wrote:
>
>> Below is a tiny program.
>>
>> The "Options" form is supposed to be shown and hidden. But once you
>> click it and then close it, the entire app is blocked. So clearly I'm
>> doing something wrong.
>>
>
> I think I have solved it this time.
>
> I added this proc:
>
> proc hide_modal {form} {
> wm withdraw $form
> grab release $form
> }
>
> and changed the protocol call to:
>
> wm protocol .optionsForm WM_DELETE_WINDOW {hide_modal .aboutForm}
>
> It seems to work, but is this now correct?

Yes, the 'grab' is what makes the options dialog modal. You also need
to release the grab to remove the modalness so the rest of the app can
receive UI events.

Subject: Re: how to create a dialog that is hidden/shown rather than created/destroyed
From: Mark Summerfield
Newsgroups: comp.lang.tcl
Date: Sat, 22 Jun 2024 09:44 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-1.nntp.ord.giganews.com!nntp.giganews.com!local-3.nntp.ord.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: Sat, 22 Jun 2024 09:44:12 +0000
From: mark@qtrac.eu (Mark Summerfield)
Subject: Re: how to create a dialog that is hidden/shown rather than
created/destroyed
Newsgroups: comp.lang.tcl
References: <RJ-dnawmWOec0-j7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
<v54bcl$38kko$1@dont-email.me>
MIME-Version: 1.0
User-Agent: Pan/0.149 (Bellevue; 4c157ba)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Message-ID: <KBydnbYaF4dxAev7nZ2dnZfqn_GdnZ2d@brightview.co.uk>
Date: Sat, 22 Jun 2024 09:44:12 +0000
Lines: 45
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-Bov/hWqoos3VTMi4Ao1JTR3Sqn0iJlHL73H/WJBYp65XHvWcKErXrx1HXqKpsFWNBx+IU/aB+UuMxEj!NvW/WV0sdL+GXmKGcJdeafjt4VDnKmC7pDIKUyAVIuethqtOSEWqBYNKbXrCMWh3sNenzIIYIXDs!6Vz/bx4g/cNE5B9UDj3gEirOcQ==
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 Fri, 21 Jun 2024 16:56:53 -0000 (UTC), Rich wrote:

> Mark Summerfield <mark@qtrac.eu> wrote:
>> Below is a tiny program.
>>
>> The "About" form is created and destroyed. So you can click About then
>> close the About form, then repeat as often as you like.
>>
>> The "Options" form is supposed to be shown and hidden. But once you
>> click it and then close it, the entire app is blocked. So clearly I'm
>> doing something wrong.
>
> Based on your code you are showing the options as a "modal" dialog.
> Modal means it blocks the rest of the app. Withdrawing the window does
> not change its "modalness". You need to not only withdraw the window
> but also turn off the "modalness" of the window at the same time.
>
> I.e., you need to "grab release" on the window as part of withdrawing
> it.
>
>
> As a suggestion, you might also consider making the options window
> 'non-modal' in that it can be open and the rest of the app can still
> function. Modality is more often evil than anything else in a GUI.

I was trying to create a family of functions to support creating dialogs
of the kinds: modal and modeless hide/show (i.e., created once and
reused), and modal create/destroy, and have now done so.

As for modality being "evil". Over the decades many aspects of UI design
have come and gone, mostly driven more by fashion than by issues of
usability or functionality. Modality is confusing and inconvenient for
some or even many users in some contexts, but it can be very convenient
and useful for others in other contexts. The same is true of MDI (multiple
document interface), a UI idea which has been out of fashion for at least
25 years but which remains useful for some applications in some contexts.
(I use it for a "pinboard" type application, and I've seen other current
uses.) There are many other fashionable inconveniences I could mention.
For example, some of my notification icons are black and white when color
would be more useful.

Personally I think a UI toolkit's role is to provide functionality and it
is for the programmer to choose what to do with that functionality. I
dislike toolkits which try to impose on the programmer (I'm thinking of
Gtk here for example).

1

rocksolid light 0.9.8
clearnet tor