PDA

View Full Version : Help building UI using UI file


KHing
01-16-2013, 07:52 AM
Hi, I am new to scripting and I am trying to build a tool to facilitate the production of a small project coming up.

The tool is as simple as setting up the folders with a specific folder structure to a standard path where all the artists can work together, and yet with proper referencing, etc.

The problem is that some of our artist work on pc, and some on mac. I have set up drive mapping and symbolic links on the machines, so they share the same path on either pc or mac.
etc, "T:/" on win and "/Users/Shared/" on mac

When I build the ui with qt creator, I am able to give a default value to my textField, where the artist can specify the path to save their files, whether to "T:/" or "Users/Shared/". Now the problem is whether I can set the default value of the textField based on the os the artists are working on?

For example, when artist on mac fires up the script the textField will show "/Users/Shared" and when the artist on win will see "T:/"?

I know this can be done with with an if statement querying the os version if I build the UI with mel. However is this possible if i am using a .ui file for my tool?

Thanks a bunch in advance. :thumbsup:

djx
01-16-2013, 12:48 PM
Since I'm probably not the best one to explain the exact steps, let me just start the ball rolling by assuring you that it is certainly possible to do what you want.

Once I've created myUI.ui (with qt designer) I would convert it to myUI.py with pyuic4.bat. (since I prefer not to use the .ui in my scripts) Then I import myUI.py into my script, and then I create a class for my window. This class inherits the top level widget from myUI.py (for example, something like myUI.Ui_myMainWindow). Near the beginning of that class you need to call self.setupUi(self) to give you access to all your widgets. You can then set defaults or change labels or colors or whatever you want. For example... you can use your if condition followed by...
self.outputPath_lineEdit.setText('T:/')

I know I'm probably oversimplifying it. Someone might want to elaborate (or correct me).

David

KHing
01-16-2013, 02:49 PM
Hi thanks for the reply. Unfortunately I don't think I know python enough to build this tool just yet.. I am looking for solutions using mel for now.

gmask
01-16-2013, 03:28 PM
string $checkOs = `about -os`;

KHing
01-16-2013, 07:59 PM
Hi, I have found out that I can assign dynamic properties to my textField in qt creator. By defining a $var to the -text flag, the ui will pull the value of $var when i define it in my mel script.

Now, I have another problem... I want to assign a $var to a path throughout my whole script, but the current one I have always return a empty value. Why is it so?

Example:

string $os = `about -os`;
if ($os == "mac"){
string $myPath = "/Users/";
}else{
string $myPath = "T:/";
}

print ("\n"+$myPath+"\n");


Can anyone tell me what is wrong here? Thanks

djx
01-16-2013, 09:23 PM
I think you just need to declare the string outside the if...

string $os = `about -os`;
string $myPath;
if ($os == "mac"){
$myPath = "/Users/";
}else{
$myPath = "T:/";
}

print ("\n"+$myPath+"\n");

David

gmask
01-16-2013, 09:23 PM
Hi, I have found out that I can assign dynamic properties to my textField in qt creator. By defining a $var to the -text flag, the ui will pull the value of $var when i define it in my mel script.

Now, I have another problem... I want to assign a $var to a path throughout my whole script, but the current one I have always return a empty value. Why is it so?

Example:

string $os = `about -os`;
if ($os == "mac"){
string $myPath = "/Users/";
}else{
string $myPath = "T:/";
}

print ("\n"+$myPath+"\n");


Can anyone tell me what is wrong here? Thanks

When you redeclare a variable inside the scope of {} then it the script is only aware of it's assignment inside that scope.. you need to declare it before the enclosed curly braces {}..

such as this..


string $myPath;
string $os = `about -os`;
if ($os == "mac"){
$myPath = "/Users/";
}else{
$myPath = "T:/";
}

print ("\n"+$myPath+"\n");

KHing
01-17-2013, 04:17 AM
Thanks for your help so far. Part of my script now:

global proc my_tool()
{
//Enable drive mapping;
dirmap -en true;
//Path variables;
string $macPath = "/Users/Shared/my_production/";
string $winPath = "T:/";
global string $myPath;
// get the os type;
string $os = `about -os`;
if($os == "mac"){
dirmap -m $macPath $winPath;
global string $myPath = "/Users/Shared/my_production/";
}else{
dirmap -m $winPath $macPath;
global string $myPath = "T:/";
}

//*******Menu for tiny production*******//
if (`window -exists tinyWindow`){
deleteUI myWindow;
}
string $d = ($myPath+"cg/pipeline/scripts");
string $myWindow =`loadUI -uiFile ($d+"/my_tool/my_ui.ui")`;
showWindow $myWindow;
}

$myPath is always returning the value of "T:/" regardless of the condition i set. Is it due to the fact that $myPath follows the value that is last declared?

How should it be in this case?

Panupat
01-17-2013, 05:41 AM
So you tried it on mac and it's still returning "T:/" ? I guess the best way is to run the "about -os" on mac and see what it returns.

Anyway. I'd have a function return me the string instead of setting up a gobal variable. I'd also get rid of the $d and put them all in 1 line.

global proc string getPathPrefix() {
string $temp = `about -os`;
if ($temp == "mac") {
return "/Users/Shared/my_production/";
}
else {
return "T:/";
}
}

string $myWindow = ( getPathPrefix() + "cg/pipeline/scripts/my_tool/my_ui.ui" );

KHing
01-17-2013, 06:59 AM
So you tried it on mac and it's still returning "T:/" ? I guess the best way is to run the "about -os" on mac and see what it returns.

Anyway. I'd have a function return me the string instead of setting up a gobal variable. I'd also get rid of the $d and put them all in 1 line.

global proc string getPathPrefix() {
string $temp = `about -os`;
if ($temp == "mac") {
return "/Users/Shared/my_production/";
}
else {
return "T:/";
}
}

string $myWindow = ( getPathPrefix() + "cg/pipeline/scripts/my_tool/my_ui.ui" );

Thanks! This solved my problem.

I guess I will run into more problems... but until then, thanks all the folks who helped me out here! Cheers!

CGTalk Moderation
01-17-2013, 06:59 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.