Python and QT windows

Python and QT windows

Anonymous
Not applicable
388 Views
2 Replies
Message 1 of 3

Python and QT windows

Anonymous
Not applicable
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.loadUI( uiFile=MYUI )
print self.win
cmds.showWindow(self.win)

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

#
#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
0 Likes
389 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
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)
0 Likes
Message 3 of 3

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

instead try using

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