Attachment "desktop.tcl" to
ticket [2901053f]
added by
traum
2009-11-20 17:20:06.
# This example causes the following problem:
# If I start it under Windows and switch to the desktop via the appropriate button
# in the Windows Toolbar, the TK-Window disappears as expected.
# If I start another application then, I can't restore the TK-Window afterwards.
# A click on the icon in the Windows Toolbar doesn't help. The only way to restore
# the dialog is to push it to the foreground with the Windows Task Manager.
# But this can mean that it is shown everytime another application is started.
# The problems only occurs if the dialog is application-modal. The grab command
# seems to cause the problem.The example has been taken
# from the Iwidgets Shell Widget class and has beem changed so that it runs without
# Itk, Itcl and Iwidgets. The implementation is very similar to the TCL script
# implementation of the tk_messageBox dialog for Unix.
package require Tk
variable _wait
variable grabstack {}
variable _oldfocus ""
# Activate application-modal dialog
proc activate { shell parent modality } {
variable _wait
variable grabstack
variable _oldfocus
if { [winfo ismapped $shell] } {
raise $shell
return
}
if { ($parent != {}) && [winfo exists $parent] } {
wm transient $shell $parent
}
set _wait 0
wm deiconify $shell
tkwait visibility $shell
set _oldfocus [focus]
if { $modality == "application" } {
if { $grabstack != {} } {
grab release [lindex $grabstack end]
}
set err 1
while { $err == 1 } {
set err [catch [list grab $shell]]
if { $err == 1 } {
after 1000
}
}
lappend grabstack [list grab $shell]
focus $shell
tkwait variable ::_wait
}
}
# Deactivate application-modal dialog
proc deactivate { shell modality } {
variable _wait
variable grabstack
variable _oldfocus
if { ![winfo ismapped $shell] } {
return
}
if { $modality == "application" } {
focus $_oldfocus
grab release $shell
if { $grabstack != {} } {
if { [set grabstack [lreplace $grabstack end end]] != {} } {
eval [lindex $grabstack end]
}
}
}
wm withdraw $shell
set _wait 1
}
# Create application-modal dialog
proc dlgcb { parent } {
set modality "application"
set shell $parent.dlg
toplevel $shell -class Dialog
frame $shell.fr
label $shell.fr.lb -text "Hello"
button $shell.fr.bt_cl -text "Close" -command "::deactivate $shell $modality"
grid $shell.fr
grid $shell.fr.lb -padx 10 -pady 10
grid $shell.fr.bt_cl -padx 10 -pady 10
wm title $shell "Modal"
wm protocol $shell WM_DELETE_WINDOW "::deactivate $shell $modality"
activate $shell $parent $modality
destroy $shell
}
# Withdraw .-Widget
wm withdraw .
# Create main dialog
set shell .top
toplevel $shell
frame $shell.fr
button $shell.fr.bt_dlg -text "Dialog" -command "::dlgcb $shell"
button $shell.fr.bt_cl -text "Close" -command "destroy $shell"
grid $shell.fr
grid $shell.fr.bt_dlg -padx 10 -pady 10
grid $shell.fr.bt_cl -padx 10 -pady 10
wm title $shell "Main"
wm protocol $shell WM_DELETE_WINDOW "destroy $shell"
tkwait window $shell
destroy $shell
destroy .