SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


SM Forums / Maya Questions / Programming / Management of GUI window elements

Programming MEL Scripts, Expressions & Programming Related Topics

Join the conversation. Reply to post
 
Thread Tools
04-03-2014, 03:03 PM   #1
Grimt
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
  Reply with quote
04-03-2014, 07:13 PM   #2
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,514
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 ||::
  Reply with quote
10-04-2014, 03:01 PM   #3
Grimt
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.
  Reply with quote
12-04-2014, 09:10 PM   #4
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,514
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 ||::
  Reply with quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to modify/wrap existing Maya window? memory_leak Programming 3 31-12-2014 01:10 AM
changing the "Quick help" window size in the maya 2012 script editor. Jouri Programming 3 27-11-2011 06:15 AM
asign sliderFunction to costum window Falott Programming 2 31-07-2008 12:07 AM
Output Window Doesn't Open When Maya Starts InsightfulMind Maya Technical Issues 0 28-04-2006 06:34 PM
Size Of A Window skywola Programming 2 25-03-2006 05:37 PM