chapman@lll-lcc.UUCP (Carol Chapman) (05/05/89)
Well, I am still struggling along, trying to find a way for my program to get a mere 10 bytes of input from a user. If any of you can offer advice or send me samples of code using popup windows, I'd appreciate it. My latest idea is to have a dialog widget within a popup shell. It is defined as follows: num_args = 0; XtSetArg(args[num_args], XtNallowShellResize, TRUE); num_args++; popup_shell = XtCreatePopupShell("Popup Shell", transientShellWidgetClass, toplevel, args, num_args); num_args = 0; /* reinitialize */ barcode = (char *) calloc(STR_LEN, sizeof(char)); XtSetArg(args[num_args], XtNborderWidth, 4); num_args++; XtSetArg(args[num_args], XtNlabel, "Enter a barcode: "); num_args++; XtSetArg(args[num_args], XtNvalue, barcode); num_args++; input_dialog = XtCreateManagedWidget("Input Dialog", dialogWidgetClass, popup_shell, args, num_args); /* create an OK button for the popup window */ num_args = 0; /* reinitialize */ XtSetArg(args[num_args], XtNfont, fontb_info); num_args++; ok_button = XtCreateManagedWidget("OK", commandWidgetClass, input_dialog, args, num_args); XtAddCallback(ok_button, XtNcallback, check_barcode, NULL); /* create a cancel button for the popup window */ cancel_button = XtCreateManagedWidget("Cancel", commandWidgetClass, input_dialog, args, num_args); XtAddCallback(cancel_button, XtNcallback, cancel_action, NULL); Looks simple, right? My program sets up a large vpaned window with buttons in one pane. If a user selects the Display button, a routine named display() is called, the first line of which is XtPopup(popup_shell, XtGrabExclusive); At this point, I want a popup window to appear and get a barcode. Within the popup window, if the user selects the Cancel button, I want the program to simply remove the popup window and return to the main vpaned window. Within the popup window, if the user selects the OK button, I want the program to remove the popup window and check the validity of the barcode that the user typed. If it is invalid, I want the popup window to reappear, so the process can be repeated. If the barcode is valid, I want the program to continue on its merry way in the display() routine. I'm having great difficulty getting things to work as stated above. In my latest rendition, the popup window appears but with no text in it, and my program keeps running with garbage for the barcode. When it finishes, *then* text appears in the popup window asking me for a barcode! If I give it a barcode, it calls the check_barcode routine like I want it to, but when that finishes, it never returns to the point where XtPopup was originally called. Isn't it supposed to return to that point? A few other minor questions: Is there a way to set the font for the text entered by the user in the dialog widget (XtNvalue)? Am I correct to be using XtGrabExclusive as an argument to XtPopup? If I use XtNvalue with the dialog widget, then I don't need XtGetValueDialogString, correct? If you can help, I thank you muchly! carol chapman -- ------------------------------------------------------------------------------- Livermore Lab (chapman@lll-crg.llnl.gov or chapman@lll-lcc.llnl.gov) P.O. Box 808, L-153 Tel. (415) 423-7876 Livermore, CA 94550 "Never own anything that you have to FEED or PAINT."
argv%eureka@Sun.COM (Dan Heller) (05/05/89)
In article <2461@lll-lcc.UUCP> chapman@lll-lcc.UUCP (Carol Chapman) writes: >Well, I am still struggling along, trying to find a way for my program to >get a mere 10 bytes of input from a user. If any of you can offer >advice or send me samples of code using popup windows, I'd appreciate it. This is perhaps the most commonly asked question that people send "me", so when I posted my WidgetWrap code to comp.sources.x, I made sure to include a sample program which does just what you are talking about. It is a very simple program that demonstrates the widgetwrap code (which is much easier to use and read than the XtSetArg() calls riddled throughout toolkit programs). The sample application uses a simple yes/no dialog box ... This code is also available via ftp from expo.lcs.mit.edu in the contrib directory. I have yet to have questions from someone who can't figure out this stuff, so maybe it will be equally helpful to you. dan <argv@sun.com>