Maya Crashed: Adding widgets under ScrollArea PySide Python

35 views
Skip to first unread message

Soham Parmar

unread,
May 29, 2020, 3:31:18 PM5/29/20
to Python Programming for Autodesk Maya
Hi,
I am trying to create scrollArea under my tabWidget.
I have already written code for creating widgets under my tab widgets but now i wanted scrollArea. running code with scrollArea i can not se any Widgets in my scrollArea and maya is geting crached if i move the window or change the tab.

Below Code is working perfectly fine WITHOUT scrollArea In my tabWidget:
def buildTabLodUpdate(self):
# all tabs in widget
tabs = [self.buildTabWidget.tabText(index) for index in range(self.buildTabWidget.count())]
allLod = [lod for lod in self.uiData["spModularRig"]["rig"]]

# if lod exist deleting default tab
if len(allLod) > 0:
# deleting default tab if exists
if "spModularRig" in tabs:
self.buildTabWidget.removeTab(0)

# creating tab for all lod and updating widgets.
for lod in allLod:
if lod.keys()[0] not in tabs:
W_lod = QtWidgets.QWidget()
VerL_lod = QtWidgets.QVBoxLayout(W_lod)

self.buildTabWidget.addTab(W_lod, lod.keys()[0])
self.buildTabWidget.setCurrentIndex(self.buildTabWidget.count()-1)

# updating rig data widgets inside tab
self.buildTabSWUpdate()

def buildTabSWUpdate(self):
self.buildTabSWRemoveAll()

Widget = self.buildTabWidget.currentWidget()
layout = Widget.findChild(QtWidgets.QVBoxLayout)

for num, rigData in enumerate(self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName]):
GB_name = self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName][num][rigData.keys()[0]]["name"]
if rigData.keys()[0] == "rigInfo":
# gathering data from dictionary.
assetName = self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName][num][rigData.keys()[0]]["assetName"]
assetType = self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName][num][rigData.keys()[0]]["assetType"]
assetOtherType = self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName][num][rigData.keys()[0]]["OtherType"]

# creating widget with above values.
rigInfoW = self.rigInfoUIFunc(Widget, layout, GB_name, assetName, assetType, assetOtherType)

# connecting.
rigInfoW.LE_assetName.editingFinished.connect(lambda data=[num, rigInfoW.LE_assetName]: self.RI_assetNameUpdate(data))
rigInfoW.LE_assetOtherType.editingFinished.connect(lambda data=[num, rigInfoW.LE_assetOtherType]: self.RI_assetOtherTypeUpdate(data))
rigInfoW.ComB_assetType.currentIndexChanged.connect(self.RI_assetTypeUpdate)
rigInfoW.B_applyRigInfo.clicked.connect(self.applyRigInfo)



below is the code where i am adding scrollArea:
def buildTabLodUpdate(self):
# all tabs in widget
tabs = [self.buildTabWidget.tabText(index) for index in range(self.buildTabWidget.count())]
allLod = [lod for lod in self.uiData["spModularRig"]["rig"]]

# if lod exist deleting default tab
if len(allLod) > 0:
# deleting default tab if exists
if "spModularRig" in tabs:
self.buildTabWidget.removeTab(0)

# creating tab for all lod and updating widgets.
for lod in allLod:
if lod.keys()[0] not in tabs:
W_lod = QtWidgets.QWidget()
VerL_lod = QtWidgets.QVBoxLayout(W_lod)

SA_buildTab = QtWidgets.QScrollArea(W_lod)
SA_buildTab.setObjectName("SA_buildTab")

SA_W_rigData = QtWidgets.QWidget()
SA_W_rigData.setObjectName("SA_W_rigData")
VerL_SA_W_rigData = QtWidgets.QVBoxLayout(SA_W_rigData)
VerL_SA_W_rigData.setObjectName("VerL_SA_W_rigData")

SA_buildTab.setWidget(SA_W_rigData)
VerL_lod.addWidget(SA_buildTab)

self.buildTabWidget.addTab(W_lod, lod.keys()[0])
self.buildTabWidget.setCurrentIndex(self.buildTabWidget.count()-1)

# updating rig data widgets inside tab
self.buildTabSWUpdate()

def buildTabSWUpdate(self):
self.buildTabSWRemoveAll()

Widget = [Widget for Widget in self.buildTabWidget.currentWidget().findChildren(QtWidgets.QWidget) if Widget.objectName() == "SA_W_rigData"][0]
layout = Widget.findChild(QtWidgets.QVBoxLayout)

for num, rigData in enumerate(self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName]):
GB_name = self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName][num][rigData.keys()[0]]["name"]
if rigData.keys()[0] == "rigInfo":
# gathering data from dictionary.
assetName = self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName][num][rigData.keys()[0]]["assetName"]
assetType = self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName][num][rigData.keys()[0]]["assetType"]
assetOtherType = self.uiData["spModularRig"]["rig"][self.lodIndex][self.selectedLodName][num][rigData.keys()[0]]["OtherType"]

# creating widget with above values.
rigInfoW = self.rigInfoUIFunc(Widget, layout, GB_name, assetName, assetType, assetOtherType)

# connecting.
rigInfoW.LE_assetName.editingFinished.connect(lambda data=[num, rigInfoW.LE_assetName]: self.RI_assetNameUpdate(data))
rigInfoW.LE_assetOtherType.editingFinished.connect(lambda data=[num, rigInfoW.LE_assetOtherType]: self.RI_assetOtherTypeUpdate(data))
rigInfoW.ComB_assetType.currentIndexChanged.connect(self.RI_assetTypeUpdate)
rigInfoW.B_applyRigInfo.clicked.connect(self.applyRigInfo)


What am i doing wrong here?

Justin Israel

unread,
May 29, 2020, 5:50:51 PM5/29/20
to python_in...@googlegroups.com
It is really hard to know for sure what is causing the crash just from looking at this code. Is it a complete crash of Maya or just a python exception? 
Your code is using an approach that is much harder to reason about, where you are using lots and lots of introspection to find a child of this or that widget with this or that type or object name. If these were properly composed as more custom classes then you could ask the widget for the thing you need. An example of a possible problem is where you are looping on the tab to find the current widget and then get the child and layout and check the name. Now that you have added a scroll widget in the middle, it would appear you aren't looking deep enough in the widget hierarchy anymore. 
Other issues could be not setting object names on layouts. Or the fact that you use dict.keys()[0] everywhere when a dict makes no guarantee of being ordered. So this could be a bug now, or later, and/or break when you run this in py3. 
There are also lots of redundant nested dictionary lookups in the same function body would could lead to a mistake. 

My suggestion is to try and reduce your problem to the absolute smallest amount of code. This will help isolate the difference between success and crashing. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/bcadbece-a05b-4ee2-abd4-636fcd95dd8c%40googlegroups.com.

Soham Parmar

unread,
May 31, 2020, 12:32:48 AM5/31/20
to python_in...@googlegroups.com
hey i solved i was deleting the widget which was not there may be that was the problem.  and second thing is i was not using setWidgetResizable(True) so stuff inside scroll area was not visible in ui.

yes you’re right dictionaries will never in order so i am using list as a value so the list will be always in order.

may be now you have figured out that i am working on rig tool so there can be multiple hand leg modules and many more module with multiple LODs. So my idea is to save all the data into dictionary and save that dictionary as string attribute to null transform node in maya. so whenever i open ui if dictionary found the ui will be updated accordingly.

if you don't mind, I would like to hear the suggestion to make more efficient.


Justin Israel

unread,
May 31, 2020, 12:39:00 AM5/31/20
to python_in...@googlegroups.com
On Sun, May 31, 2020 at 4:32 PM Soham Parmar <soha...@gmail.com> wrote:
hey i solved i was deleting the widget which was not there may be that was the problem.  and second thing is i was not using setWidgetResizable(True) so stuff inside scroll area was not visible in ui.

yes you’re right dictionaries will never in order so i am using list as a value so the list will be always in order.

Hopefully that means you have made a recent change and are no longer doing  dict.keys()[0] ?
 

may be now you have figured out that i am working on rig tool so there can be multiple hand leg modules and many more module with multiple LODs. So my idea is to save all the data into dictionary and save that dictionary as string attribute to null transform node in maya. so whenever i open ui if dictionary found the ui will be updated accordingly.

if you don't mind, I would like to hear the suggestion to make more efficient.

Using nested dictionaries is fine. Using lists are fine. I was mainly referring to this kind of thing:

# All in the body of one function
foo = x['a']['b']['c']
bar1 = x['a']['b']['c']['d'][0]
bar2 = x['a']['b']['c']['d'][1]
bar2 = x['a']['b']['c']['d'][2]
  
This could be error prone and is very repetitive. You already have looked up a reference to foo, which means you can do:
foo = x['a']['b']['c']
bar1 = foo['d'][0]
bar2 = foo['d'][1]
bar2 = foo['d'][2]

Or even better:
foo = x['a']['b']['c']
foo_d = foo['d'] 
bar1 = foo_d[0]
bar2 = foo_d[1]
bar2 = foo_d[2]

 
Reply all
Reply to author
Forward
0 new messages