how to retrive Objects created dynamically

Showing 1-5 of 5 messages
how to retrive Objects created dynamically PBLNRAO Kiran 9/3/12 12:54 AM
Hi,

I have a QFrame (Frame_ptr), and at run time i am creating a frames in loop with child objects in that frame.

like
[code]
for i in range (1,5):
    self.frame = QtGui.QFrame(self.Frame_ptr)             # creating frame as child in "Frame_prt" as discussed above

    self.frame.setGeometry(QtCore.QRect(9, self.Record_Location, 575, 25))

    self.frame.setMinimumSize(QtCore.QSize(575, 25))

    self.frame.setMaximumSize(QtCore.QSize(575, 10))

    self.frame.setFrameShape(QtGui.QFrame.NoFrame)

    self.frame.setFrameShadow(QtGui.QFrame.Raised)

    self.frame.setObjectName("Frame_" + i)

    self.frame.show()


#Adding Button

   self.pushButton = QtGui.QPushButton(i,self.frame)                      #creating as child in above created frame

   self.pushButton.setGeometry(QtCore.QRect(0, 0, 65, 25))

   self.pushButton.setAutoFillBackground(False)

   self.pushButton.setCheckable(True)

   self.pushButton.setObjectName("Btn_" +  i)

 
[/code]

now in maya if i use the below command it gives me error
[code]
for child1 in MainUi.Frame_1.children():

    print child1.objectName()


# Error: AttributeError: 'Interface' object has no attribute 'Frame_012' #

[/code]

if i create the same in designer and use the same command i can retrieve the details.
how to overcome this issue.
Re: [Maya-Python] how to retrive Objects created dynamically Justin Israel 9/3/12 8:29 AM
You are replacing the same self.frame each time you loop

for i in range (1,5):
    self.frame = QtGui.QFrame(self.Frame_ptr)  

This will work in terms of creating them and parenting each button to the frame you just made. 

As a different point, I don't see where you have the attribute name:
MainUi.Frame_1.children
Are you trying to refer directly to the objectName you set dynamically as an attribute? Frame_1 would not automatically resolve to an object name unless you explicitly did:
MainUi.Frame_1 = anObject
Re: [Maya-Python] how to retrive Objects created dynamically PBLNRAO Kiran 9/3/12 11:11 PM
Yes justin,

i want to refer to the objectName and other properties like text() that i set dynamically.

How can i do it explicitly...?
Re: [Maya-Python] how to retrive Objects created dynamically Justin Israel 9/4/12 7:45 AM
If you plan on creating and destroying dynamic objects then you might want to store them in a dict. 

self.dynamics = {}
# create them in a dict
for i in xrange(10):
    obj = QtGui.QWidget(self)
    self.dynamics["widget%02d" % i] = obj

# loop over them later
for name, widget in self.dynamics.iteritems():
    print name, widget
Re: [Maya-Python] how to retrive Objects created dynamically PBLNRAO Kiran 9/5/12 1:47 AM
Justin thx for the help....