Add data to Table widget with Python Maya

I am looking forward to create a table widget to list a set of files…
basically creating a render queue…

I created the ui using Qt designer…
I added an Item based table widget and saved the file as a ui

I loaded the file in maya python using cmds.loadUI
Now I wish to add data to the table using an xml file…

My question is how do i add data rows to the widget…
I dont want to use PyQt as I need it on a lot of PC’s and cant install it everywhere…

I was earlier using a textscroll widget from Qt designer and adding data using cmds.textScrollList()
but this was only displaying a single column stuff…
I want to have multiple columns…

Below is the ui snapshot…

I can not help you with the maya command, maybe you can use spreadSheetEditor, I have not used it myself so frankly I got no idea.

But if you are using maya 2014 or 2015 it have pyside 1.1.1 already, no need to install PyQt.

If PyQt and pyside are out of the question, you may be better off building multiple textScrollLists side by side (one for each column) and connecting their selections.
I’d recommend building your own library of custom UI elements if its something you might have to do regularly (and again are unable to use PyQt or pyside).

Looks like the scriptTable command should work.


import maya.cmds as cmds

# Allows the cell to be editable
def cellChangedCB(pRow, pClm, pValue):
   return 1

win = cmds.window()
frm = cmds.formLayout(nd=100)
spr = cmds.scriptTable(c=3, r=0, cw=[[1, 100], [2, 500], [3, 100]], l=[[1, "Column 1"], [2, "Column 2"], [3, "Column 3"]], ccc=cellChangedCB)
cmds.formLayout(frm, e=True, af=[[spr, 'right', 0], [spr, 'left', 0], [spr, 'top', 0], [spr, 'bottom', 0]])

for i in xrange(10):
   cmds.scriptTable(spr, e=True, ir=1)

for i in xrange(10):
   cmds.scriptTable(spr, e=True, ci=[1+i, 1], cv='Column 1 Data %d' % i)
   cmds.scriptTable(spr, e=True, ci=[1+i, 2], cv='Column 2 Data %d' % i)
   cmds.scriptTable(spr, e=True, ci=[1+i, 3], cv='Column 3 Data %d' % i)

cmds.showWindow(win)

You can also make a GridLayout and then put other controls into it. For that matter, a column of gridLayouts will also work

@stev i guess there’s no flag called “ci”…
I tried running ur code and it gave me the error

# Error: TypeError: file <maya console> line 16: Invalid flag 'ci' # 

anyways i ended up using multiple textscrollLists for the data…
but seems like maya takes too long to load data in textscrollList…
I have around 6 rows of data and 4 columns…and it takes like 10-15 secs to load data into it…and freezes maya fr that time…

looks like i have to learn pyqt nd pyside…

is cellIndex (ci) 2013 onwards? So assuming you have 2012 or earlier.
How much data are you adding to each textscrolllist? If its relatively small, are you sure its the textscrolllist thats the issue? Try timing the functions to find the offending code. If your attempting to add large amounts of data then you want to look into alternatives - ie storing the data in a file and loading on request, storing it in memory, in scene, etc. More information would allow us to provide better suggestions.

I accomplished something similar to this in PySide using QStandardItem. I’m not quite sure what the mel or python calls would be for adding items to your tableWidget. I should also mention that I used a treeView because I needed to list items in a hierarchy.

Here is a page I found on using QStandardItem though, the section is all the way at the bottom

http://help.autodesk.com/view/MAYAUL/2015/ENU/?guid=__files_GUID_3F96AF53_A47E_4351_A86A_396E7BFD6665_htm

I had created a class that inherits from QStandardItem to store my data and added instances of those to my tree view.

What type of data are you trying to load?