Introduction to Maya - Rendering in Arnold
This course will look at the fundamentals of rendering in Arnold. We'll go through the different light types available, cameras, shaders, Arnold's render settings and finally how to split an image into render passes (AOV's), before we then reassemble it i
# 1 04-03-2014 , 03:03 PM
Registered User
Join Date: Mar 2014
Posts: 2

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

# 2 04-03-2014 , 07:13 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
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.


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
# 3 10-04-2014 , 03:01 PM
Registered User
Join Date: Mar 2014
Posts: 2
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.

# 4 12-04-2014 , 09:10 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
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.


- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads