Message 1 of 3
Python and QT windows
Not applicable
11-06-2011
04:44 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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