Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Maya® / Python / Python and QT windows
  RSS 2.0 ATOM  

Python and QT windows
Rate this thread
 
61729
 
Permlink of this thread  
avatar
  • Total Posts: 11
  • Joined: 22 August 2006 10:40 PM

I have been playing with some basic code for sometime now and I am unable to access the textFields after I have created my window. I want to update the lblSandbox with the path selected via the btnSandbox.

I have tried:
1) using the name “lblSandbox”
2) using the full dag path “MainWindow|OPPShotUI|lblSandbox” (maybe wrong)

In addition,I am a little concerned with hard coding the window. Would rather it be dynamic.

my.ui, is a qt file that should have the necessary widgets to try the code below.

lblSandbox --> QT Label Widget
btnSandbox --> QT Push Button

I have added the dynamic property for btnSandbox:
“+command” with “set_sandbox()”

The code runs just fine, and gives a traceback:
# Error: Object ‘lblSandbox’ not found.
# Traceback (most recent call last):
# File “<maya console>”, line 1, in <module>
# File “shotui.py”, line 45, in set_sandbox
# lbl_sandbox = cmds.textField("lblSandbox", e=True, tx=sandbox_path)
# RuntimeError: Object ‘lblSandbox’ not found. #

I believe I am missing a step to access the label.

#!/usr/env python
import os
import sys
import maya
.cmds as cmds


MYUI 
"my.ui"

class OPPShotUI:
    
def __init__(self):
        
self.win cmds.loadUIuiFile=MYUI )
        print 
self.win
        cmds
.showWindow(self.win)

def set_sandbox():
    
# show browse window
    
sandbox_path cmds.fileDialog2(fileMode=3okc="select")
    print 
sandbox_path
    
if sandbox_path:
        
sandbox_path sandbox_path[0]
        lbl_sandbox 
cmds.textField("lblSandbox"e=Truetx=sandbox_path)
        print 
lbl_sandbox
        
#cmds.textField("lblSandbox" , edit=True, text=str(sandbox_path[0]))

#
#def run_ui():
#    dialog = cmds.loadUI(uiFile=MYUI)
#    print dir(dialog)
#    #print dialog.cboSeqShot
#    cmds.showWindow(dialog)


## --- execute main ui if all is good ---
if os.path.exists(MYUI):
    
win OPPShotUI()

    
else:
    print 
"ERROR: UI File was not found. This file is required to continue"
    
print ">> %s" MYUI


Replies: 1
/img/forum/dark/default_avatar.png

Unfortunately, maya is not ready for full QT development as I would have liked. I found some great resources for installing PyQt4:

http://www.justinfx.com/2011/01/07/installing-pyqt-for-maya-2011-osx/
http://nathanhorne.com/?paged=2
http://nathanhorne.com/?p=204

Once installed, you can use the normal PyQt classes / sub-classing.

I never was able to fix this particular issue. As I have decided (painfully) to use only python / maya ui to prevent having to install PyQt4 on over 50 machines. The painful part comes in when you try to dynamically update ui elements. I will be posting some questions about that on another post. (Not that anyone reads these posts)

Author: tcomputerchip

Replied: 11 November 2011 01:40 PM  
avatar
  • ldunham1
  • Posted: 11 November 2011 10:30 PM

the problem is your trying to access a label widget with a textField command.

instead try using

cmds.text('lblSandbox',q-True,l=True)


Lee Dunham | Character TD
ldunham.blogspot.com

Replies: 0