Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   Management of GUI window elements (https://simplymaya.com/forum/showthread.php?t=40263)

Grimt 04-03-2014 03:03 PM

Management of GUI window elements
 
Hello all,

I need a simple script that controls GUI elements (buttons, scrollfields, pictures) in main window from external procedure. Below the code.

global proc WindowGUI()
{
if (`window -exists WindowGUI`) deleteUI WindowGUI;

window -t "Window GUI Form" -widthHeight 300 300 -rtf true -sizeable false WindowGUI;
string $form = `formLayout`;
string $BackgroundImage = ` picture -width 300 -height 300 -image "Background.png"`;
string $SelectionScrollField = `scrollField -wordWrap false -w 200 -h 200 -cl -enable false -editable false`; // clear field
string $Button_ShowText = `button -label "Show text on Form" -w 160 -h 25 -command ShowTextOnForm Button_ShowText`; // Button exec procedure ShowTextOnForm
formLayout -edit
-attachForm $SelectionScrollField "top" 50
-attachForm $SelectionScrollField "left" 50 // paste panel on form

-attachForm $Button_ShowText "top" 260
-attachForm $Button_ShowText "left" 70 // paste button on form
$form;

showWindow WindowGUI;
}

global proc ShowTextOnForm()
{
//?! There will be a code for management of a field
}

WindowGUI;

1)I need to execute external procedure (ShowTextOnForm) which changes an interface element on pressing of the button, for example adds the text in the scrollField.
2)If it is possible, whether there is a need to kill and redraw a window each time at change of any element.
3)how to address directly to any element of a window (for example something like that: WindowGUI.scrollfield1.text)?

Thanks for your help

Gen 04-03-2014 07:13 PM

In cases of UI elements that will be accessed by procs outside the main proc, I explicitly name them.

So instead of...

string $Button_ShowText = `button -label "Show text on Form" -w 160 -h 25 -command ShowTextOnForm Button_ShowText`;

I would use..

button -label "Show text on Form" -w 160 -h 25 -command ShowTextOnForm Button_ShowText abc_myButton;

So now the button can be referred to by any procedure.

Also it's a good idea to give unique names to anything with a global scope. I can see WindowGUI becoming a problem if you start writing more scripts. Try prefixing it with something that describes the family of scripts it belongs to, like beanCounter_windowGUI or something.

Grimt 10-04-2014 03:01 PM

Thank you very much, everything works. Please tell me how to make the window redraws every N-seconds or event, such as the selection of the object in the scene. I believe this requires a global procedure with a timer, but to understand how it works, I can not.

Gen 12-04-2014 09:10 PM

You can write a proc that checks the selection for the object and if true, carries out the task, then call that proc using a scriptJob that leans on the "SelectionChanged" event. You can parent the scriptJob to your custom UI so it's killed when the UI is closed.


All times are GMT. The time now is 03:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018