Re: [Activetcl] Question about focus and grab ...
by Tillmann A. Basien | ToolBox Solution GmbH other posts by this author
Apr 27 2008 1:31AM messages near this date
view in the new Beta List Site
Re: [Activetcl] Question about focus and grab ...
|
[Activetcl] Tablelist Interactive Cell Editing
Hy also have problems using focus,raise and grab and would be happy to
get a hint from an TK Guru.
label .l -text "The message ...."
button .b -text "OK" -command {exit}
pack .l .b
stayInForeground .
My Tcl Code (see below) does not work in any situations.
So I tried to write a small C-Procedure using XGrabServer to grab and
lock the screen reliable. But also no success.
The final TCL/TK code should look like
LockDisplay
label .l -text "The message ...."
button .b -text "OK" -command {UnlockDisplay;exit}
pack .l .b
Is there anyone, who can give me hint?
regards
TAB
My Tcl-Code:
proc stayInForeground {window } {
try {
raise $window
focus -force $window
# Grab fails if the window is not viewable
if ![catch {grab -global $window} errorMsg] {
raise $window
focus -force $window
} else {
puts "Grab failed: errorMsg=$errorMsg, window=$window"
}
set ::afterIdForWindow [after 1000 "stayInForeground $window" ]
update
} catch -msg errorMessage {
puts "stayInForeground failed: errorMessage=$errorMessage"
}
}
My C-Code:
static int LockDisplay_Cmd(
ClientData clientData, /* Not used. */
Tcl_Interp *interp, /* Current interpreter */
int objc, /* Number of arguments */
Tcl_Obj *const objv[] /* Argument strings */
)
{
char *displayName;
Display *display;
if (objc == 2) {
displayName = Tcl_GetString(objv[1]);
if (display = XOpenDisplay(displayName)) {
XGrabServer(display);
return TCL_OK;
} else {
Tcl_AddErrorInfo(interp, "Could not connect to display");
Tcl_SetResult(interp, "Could not connect to display", NULL);
return TCL_ERROR;
}
}
Flavio Salgueiro schrieb:
>
> -> 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
>
> This email was Anti Virus checked.
> ------------------------------------------------------------------------
>
> _______________________________________________
> ActiveTcl mailing list
> ActiveTcl@[...].com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
--
*ToolBox Solution GmbH*
CEO/CTO Tillmann A. Basien
Balinger StraÃ?e 37A
D-70567 Stuttgart
Fon: +49 (0) 711 71 68 631
Hy : +49 (0) 173 87 38 987
Fax: +49 (0) 711 45 70 899
*** Sun Microsystems OEM Partner ***
mailto:tab@[...].de / http://www.tbsol.de <http://www.tbsol.de> HRB: 23711
This message and any files or documents attached are strictly
confidential or otherwise legally protected. It is intended only for the
individual or entity named. If you are not the named addressee or have
received this email in error, please inform the sender immediately,
delete it from your system and do not copy or disclose it or use it for
any purpose. Please also note that transmission cannot be guaranteed to
be secure or error-free.
_______________________________________________
ActiveTcl mailing list
ActiveTcl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Michael A. Brooke
Flavio Salgueiro
Tillmann A. Basien | ToolBox Solution GmbH
|