Using Mel to show output in window


#1

Having one of those “Google is full of results that answer close but off mark questions” moments. I definitely need someone to point me in the correct direction or this will take forever to figure out.

I’m trying to find a way to display within UI output from my code. In this case it’s information for the user of my script and displaying it in command line is useless. So while I’ve figured out how to use print statement I cannot figure out how to update a window display.

I’ll be simplify what I need from my actual application for clarity.

string $cheese = "cheese";
window -title "Maybe Cheese";
columnLayout -columnAttach "both" 5 -rowSpacing 10 -columnWidth 250;
button -label "add cheese" -command "";
textField -text "No cheese" -editable false;
showWindow;

Okay so what I am looking to do is have the button labeled “Add Cheese” change text field to display “Cheese”.

So far everything I’ve found involves taking in user input and reacting to it in the code. I’m looking to take the codes output and show it to the user. I don’t need to stick with textField but it’s the only thing I’ve found in my digging to display output (with editable set to false).


#2

You can update the text in the text field. You only need to know the control name when you edit the text field:

string $textF = `textField -text "No cheese" -editable false`;
.....
do something and then....
textField -edit true -text "Another Cheese" $textF;

#3

Are Text Fields my only option?


#4

Well it works in any event. Updating in case anyone finds this via search function.

Haggi’s code lead to a specific error.

-edit true

isn’t the correct syntax in Mel. I had some issues using variables to point to the widget I needed. So I used explicit names for the widget (textfield) in question.

window -title "Maybe Cheese";
columnLayout -columnAttach "both" 5 -rowSpacing 10 -columnWidth 250;
button -label "add cheese" -command "textField -e -text cheese cheeseField";
textField -text "No cheese" -editable false cheeseField;
showWindow;

The above code works as a mel script just fine.

It’s still not quite what I was hoping for but it’ll be serviceable. I was hoping there was a more direct output string only widget available. I also note that textfields lead people to trying to click on them.


#5

Hi,

Haggi’s code does not work because you do not need to put “true” after the -edit flag, it takes no argument (or maybe he meant the “-editable” flag)

Maybe you can use a text instead of a textField.You’ll need to replace your code like this :

button -label "add cheese" -command "text -e -label cheese cheeseField";
text -label "No cheese" cheeseField;

#6

Thanks Loukana. That’s actually the exact style of widget I was looking for. :banghead:

Thank you for including the correct syntax for it. I’ll glance through the flags…and yeah there’s enough font and color control to do what I wanted.

I’ll test in a second but I assume you can initialize a text with “-bgs 0 1 0” and then update it with a “-e -bgs 1 0 0” to change background color from pure green to pure red.


#7

I’m very sorry for the trouble I caused. I mostly do python coding and that’s the reason I used the “true”.


#8

According to the Mel documentation, the background color is indeed editable.
Be careful though, the flag you want is -bgc, not -bgs !


#9

I actually flagged your post as helpful! I kind of guessed you may have been using Python instead of Mel. Fact is your post lead me to the right place. No real harm done.

@ Loukana I wrote it wrong there but I got it right in my script. Oopsie. As I’m sure we all know spelling errors and syntax errors tend to be the easier ones to locate and fix.