View Full Version : promptDialog not prompting?

01 January 2004, 08:35 PM
Hi y'all,

Tiny little question from me today ;)

I'm running a renaming script using promptDialog, virutally identical to the example script given in the MEL reference. It looks like this:

string $result = `promptDialog
-title "Rename Object"
-message "Enter Name:"
-button "OK" -button "Cancel"
-defaultButton "OK" -cancelButton "Cancel"
-dismissString "Cancel"`;

if ($result == "OK") {
$text = `promptDialog -query -text`;
rename $text;

I've set the script to run anytime I press ctrl-R. (this is great for, say, renaming any number of joints in a heirarchy using solely the keyboard)

But I've run into this problem where sometimes the textbox will appear with the prompt cursor (so I can simply type the new name and press 'enter'), but sometimes without it (so I have to either click in the box, or alt-tab between windows).

It's a little thing, but it's an interruption in the workflow--you all know what that feels like.

So, does anyone know why this happens? It doesn't appear to be anything I can control with flags in the promptDialog command itself. Is there any way to ensure that the textbox will always come up with the prompt cursor inside it?

- M

01 January 2004, 02:25 PM
i only know that there is a difference in the bahaviour (meaning if you have to click on enter or just hit enter on the numpad), but that is a bug i reported to alias and it is a difference between MAC and PCs.
but the problem that the cursor is not inside the textfield is new to me :/



01 January 2004, 04:29 PM
Usually the `setFocus` MEL command does this. Try inserting the command

setFocus $result;

after your dialog command, but Iīm not totally sure that will fix it for you. I havenīt seen this problem on 5.01. Worse case is you have to build your own prompt window, then use setFocus on your rename textField.

01 January 2004, 06:01 PM
Hey David,

Thanks for the tip... I've tried setFocus in a few different places in the script, but it doesn't seem to help much. I think it sets the focus to the window but not the text field specifically.

I think I'll try to build my own window... which, coincidentally, is what I was trying to do when I came across 'promptDialog' and thought "My troubles are over!" ;)

Thanks again for the help... if nothing else, I learned a valuable new command.

- M

01 January 2004, 06:31 PM

I'm also working on a MAC, but the 'enter' problem doesn't seem to happen for me...

by using the flag:

-defaultButton "OK"

the window appears with the "OK" button already highlighted, so that once you press 'enter' that's the command it executes. It doesn't work that way for you?

- M

01 January 2004, 06:48 PM
> I think I'll try to build my own window...

Watch out. To my knowledge one cannot create modal windows with just ELF commands. Perhaps with a command plugin.

If I'm wrong -- somebody tell me how!!!

- Matthew Durante

Edit: Given what you're doing that might not matter, however.

01 January 2004, 07:11 PM
Hey Matthew,

I'm not a programmer... and I'm a little ashamed to admit that I understood very little of what you warned me against. ;)

What's a "modal window"?

And what's an "ELF command"?

And heck, what would a "command plugin" do?

(these are serious questions, by the way... I'm interested in learning)

As for what I'm planning to build, I've built similar windows before... although it's possible I'm using incorrect terminology--hence the confusion. (I'm still in the "newbie" stages)

Essentially, I'll be using the 'window', 'formLayout' and 'textField' commands to build a simple UI window with a text field in it. Nothing much more than that, really.

Is this different than a "modal" window?

- M

01 January 2004, 08:20 PM
Hm... now I've tried setFocus in a brand new window setup... but I seem to be having trouble. Could this have something to do with the way a Mac handles windows, and nothing to do with Maya/MEL?

Here's the new code I'm using:

if (`window -exists simpRename`) deleteUI simpRename;

-title "Rename selection"
-w 250
-h 150

string $form = `formLayout renameForm`;

string $textField1 = `textField renameField`;

formLayout -e
-attachForm renameField left 30
-attachForm renameField top 15

textField -e
-cc "string $newName = `textField -q -tx renameField`;"
-enterCommand "rename $newName; \ deleteUI simpRename;"

setFocus renameField;

showWindow simpRename;

- M

01 January 2004, 08:24 PM

A modal window is one that, when open, restricts input to itself -- i.e. you can't access the rest of the application until the window is dismissed. Using a promptDialog, you force the user to enter input before continuing on with workflow. It simplifies the process.

If you end up making your own input window, it cannot be modal -- and thus, the user can still do other things. This would be a problem for some gui's where the interaction between a data-input window and the parent window needs to be carefully controlled. Often I add data input fields to the main window and forget about seperate data-entry windows for just this reason. If not, I'd have to worry about the interaction between the windows.

From the maya glossary:
"Extension Layer Framework. ELF commands are commands added to MEL that create custom interface elements."

So, just the commands you use to create the windows and do UI stuff...

A command plugin (as I understand) is just a compiled mel command that can do whatever. Most of the mel commands are this type, unless is says "script" in the reference.

Anyway hope that helps,

- Matthew Durante

01 January 2004, 12:54 AM
Thanks for the definitions, Matthew... I think I'm beginning to grasp what you're talking about. The "modal window" definitely makes sense to me now.

In other news....

HEY Y'ALL... I figured out what the problem is!!! I don't know how to fix it, and I stumbled across it quite by accident, but GET THIS:

If the window opens in a location where the mouse's cursor falls WITHIN the bounds of the window, the setFocus works perfectly and a text cursor appears inside the textField.

If the window opens in a location where the mouse's cursor falls OUTSIDE the window's area, no cursor appears in the textField even though the window is active!

This doesn't sound normal to me... sounds like a possible bug. But maybe there's a workaround:

Is it possible to dictate where a window appears, dynamically, when it's called? That is, can I tell a window: "Open yourself centered around wherever the mouse's cursor falls on the screen?"

I believe this would finally solve my problem and I could move forward at long last.... :)

Any ideas?

- M

01 January 2004, 02:13 AM
The '-tlc x y' argument to 'window' will let you set the windows position. You'll need to delete the window's preferences before you do this (each time):

if( `windowPref -exists MyWindow` )
windowPref -remove MyWindow;

Not sure about the mouse stuff...

- Matthew Durante

CGTalk Moderation
01 January 2006, 07:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.