Help building UI using UI file

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 01 January 2013   #1
Help building UI using UI file

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.
 
Old 01 January 2013   #2
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
__________________
http://www.djx.com.au
 
Old 01 January 2013   #3
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.
 
Old 01 January 2013   #4
string $checkOs = `about -os`;
__________________
blah blah blah
 
Old 01 January 2013   #5
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
 
Old 01 January 2013   #6
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
__________________
http://www.djx.com.au
 
Old 01 January 2013   #7
Originally Posted by KHing: 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");
__________________
blah blah blah
 
Old 01 January 2013   #8
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?

Last edited by Keithcheuk : 01 January 2013 at 04:35 AM.
 
Old 01 January 2013   #9
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" );
 
Old 01 January 2013   #10
Originally Posted by Panupat: 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!
 
Old 01 January 2013   #11
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:15 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.