ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activetcl
activetcl
Re: [Activetcl] Question about focus and grab ...
by Flavio Salgueiro other posts by this author
Apr 25 2008 11:28AM messages near this date
view in the new Beta List Site
[Activetcl] Question about focus and grab ... | Re: [Activetcl] Question about focus and grab ...
->  I think it is caused by my attempt to return the focus to each dialog
box I call so that the user cannot place the dialog into the background.

 

 

I use "grab" and "tkwait" in my dialogs to "lock" the dialog and force
the user to take some action on the dialog before being able to access
the main app. 

This is basically what I use for dialogs.

 

toplevel .dialogwin

 

# Make the toplevel transient of the main app 

wm transient .dialogwin .

 

# Hide the dialog window until the guts are added

wm withdraw .dialogwin

 

# Add the guts of the dialog

--

 

#  Raise the dialog

wm deiconify .dialogwin 

 

# Focus on the toplevel

    focus .dialogwin

 

    # Grab the dialog until released by the desired entry

    catch {grab .dialogwin}

 

    # When the user completes or cancels the dialog then the variable is
updated

    tkwait variable dialog(wait)

 

    # Release the dialog

    catch {grab release .dialogwin}

 

# Return focus to the app

 

I also use a similar method to block all input to my app while some
process is waiting. I call this proc before I do a process that takes a
bit. I call it again after the process is done to unlock.

 

# Lock the app as the following process can break if the user tries to
do several other things during 

busyApp hold

 

someOtherLongProcess

 

# Unlock the app as the process is done

busyApp release

 

proc busyApp {state} {

    switch $state {

        hold {

            if {![winfo exists .busy]} {

                # Create a hidden transient window

                toplevel .busy

                wm transient .busy

                wm withdraw .busy

            }

            . config -cursor watch

            focus -force .busy

            grab .busy

            # Create a timeout so busy does not lock out forever

            set ::busyAfter [after 60000 [list  ::busyApp release]]

            return

        }

        default {

            catch {after cancel $::busyAfter}

            catch {grab release .busy}

            . config -cursor arrow

        }

    }

}

 

________________________________

From: activetcl-bounces@[...].com
[mailto:activetcl-bounces@[...].com] On Behalf Of Michael
A. Brooke
Sent: Friday, April 25, 2008 10:27 AM
To: activetcl@[...].com
Subject: [Activetcl] Question about focus and grab ...

 

I have been getting a strange error message from my Tcl Tk application

    grab failed: another application has grab

I am not sure why I would get this error, however I think it is caused
by my attempt to return the focus to each dialog box I call so that the
user cannot place the dialog into the background.

Is it possible that by doing a focus that the grab command is called.

If not can anyone help me understand why this would come up once in a
while.


Michael
Thread:
Michael A. Brooke
Flavio Salgueiro
Tillmann A. Basien | ToolBox Solution GmbH

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved