PySide: getting value from another class

25 views
Skip to first unread message

Soham Parmar

unread,
May 2, 2020, 6:51:04 AM5/2/20
to Python Programming for Autodesk Maya
Hi,
I have mainWindow in that one addButton that will create newWidget and add it to mainWindow(addButton can be pressed multiple times and every time it will create newWidget and add it to mainWindow). For that i have kept separate object for newWidget so every time button get clicked it will call that object. and for that i have one default dictionary for this newWidget that will get added the main dictionary.

My problem is, if there is multiple widget, i am not able to figure out which widget got deleted. if that gets deleted i want to remove it from my dictionary too.
so how can i get which Widget got deleted, because in mainWindow there are multiple newWidgets.

what i was thinking that if i can get name of the groupBox (from below code), in my mainWindow class i will be able to remove it from dictionary,

I could have done the closing connection part in my mainWindow class but by doing that if multiple newWidgets in my new window and if close very fist newWidget it always closing very last newWidget created.

i dont know how .emit work if i can get value from this class to my mainWindow class

My this is the code of newWidget:-
class controlShapes(controlShapesUI.Ui_controlShapes, QtWidgets.QWidget):
def __init__(self, parentWin):
super(controlShapes, self).__init__(parentWin)
self.setupUi(self)

self.LE_shapesToExport.setText("*ctrl")

self.LE_csFilePath.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.LE_csFilePath.customContextMenuRequested.connect(self.CM_LE_csFilePath)

self.LE_shapesToExport.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.LE_shapesToExport.customContextMenuRequested.connect(self.CM_LE_shapesToExport)

self.menu = QtWidgets.QMenu()
self.A_delete = self.menu.addAction("Delete")
self.A_moveUp = self.menu.addAction("Move Up")
self.A_moveDown = self.menu.addAction("Move Down")
self.B_options.setMenu(self.menu)
self.B_options.setStyleSheet('QPushButton::menu-indicator { image: none; width: 0px; }')

def closeControlShapesUI(self):
groupBoxName = self.B_options.parent().title()
# print groupBoxName
# self.A_delete.emit(QtCore.SIGNAL("GB_Name"), groupBoxName)
self.close()
return groupBoxName

def CM_LE_shapesToExport(self):
menu = self.LE_shapesToExport.createStandardContextMenu()

self.A_selectCS = menu.addAction("Select Controllers", self.selectControllers)
separator = menu.addSeparator()
menu.insertActions(menu.actions()[0], [self.A_selectCS, separator])
menu.exec_(QtGui.QCursor.pos())

def CM_LE_csFilePath(self):
menu = self.LE_csFilePath.createStandardContextMenu()

A_exportCS = menu.addAction("Export Control Shapes")
A_releaseCS = menu.addAction("Release Control Shapes")
separator = menu.addSeparator()
menu.insertActions(menu.actions()[0], [A_exportCS, A_releaseCS, separator])
menu.exec_(QtGui.QCursor.pos())

def selectControllers(self):
print "selected"

Thanks in advance,
Soham.

Justin Israel

unread,
May 2, 2020, 7:43:16 AM5/2/20
to python_in...@googlegroups.com
Your code snippet doesn't seem to do anything to support your question, as I don't see anything about a shared dictionary or logic for MainWindow. It seems to me that your child widgets that are created from clicking the new button could really just be any generic widget so the specific code for newWidget is less important here than the main window code.

If you want to track the deletion of widgets from the main window, Qt gives you a few signals and events to watch:

Your main window can also be notified when a child window is closed or deleted. There is also the approach of watching for QChildEvent.removed() events from the main windows.

Lots of ways to skin a cat. 

Justin 


--
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/8588b63d-d991-4e1c-845d-dabc19cf878c%40googlegroups.com.

Soham Parmar

unread,
May 2, 2020, 10:34:25 AM5/2/20
to Python Programming for Autodesk Maya
Sorry For less information, I didn't send because there was too much happening. and i wanted to describe in short as much as possible.

Below is the code i am adding and this time i have shorten it as much as need to understand.
I have attached the photo of ui maybe that will help to understand whats happening.

This is the code.

Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Soham Parmar

unread,
May 3, 2020, 11:11:49 AM5/3/20
to Python Programming for Autodesk Maya
Hey Justin,
Thanks for the help, destroyed and lambda helped me to solve the problem.


On Saturday, May 2, 2020 at 5:13:16 PM UTC+5:30, Justin Israel wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages