Deutsch   English   Français   Italiano  
<RJ-dnawmWOec0-j7nZ2dnZfqnPWdnZ2d@brightview.co.uk>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!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 Summerfield <mark@qtrac.eu>
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
Bytes: 2902

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