[PyQt] List of instances of a class
Chris O'Halloran
cmoman at gmail.com
Mon Oct 27 22:05:45 GMT 2014
Hello all,
I'm writing an in house tool to calculate some aspects of behavior of a
faulted power system. I using PyQt, Numpy and Matplotlib.
I've created a class that extends QtGui.QWidget
This widget has a number of QtGui objects such as QDial, QSpinbox, QLabel
and links them with some signals and slots.
Later on in my code I instantiate a number of these classes and lay them
out on a MainWindow widget.
self.Rf = InputDial('Fault Resistance', 'Ohms', 0, 400)
self.R_NER = InputDial('NER', 'Neutral Earthing Resistor in ohms', 0, 50)
self.CapFaultCct = InputDial('Cap Fault CCT', 'circuit capacitance in
microfarads', 0, 500)
self.CapAdjacent = InputDial('Cap adjacent', 'Sum of adjacent circuits
capacitance in microfarads', 0, 500)
self.relayInFront = InputDial('3I0 current Relay In Front', 'Current seen
by relay in front of fault', 0, 10000, True)
self.relayBehind= InputDial('3I0 current Relay Behind', 'Current seen by
relay in front of fault', 0, 10000, True)
I've found myself repeating a bit of code so I wondered if could gather
these objects into a list.
I find I can using
self.dialist = self.findChildren(InputDial)
[<__main__.InputDial object at 0x0000000003BF6EE8>, <__main__.InputDial
object at 0x0000000005ABB1F8>, etc
This return a list of objects and I can access them
self.dialist[0] etc
At this stage though, I'd like to be able to return the 'handle' (I'm new
to a lot of this') of when I originally instantiated the class eg self.Rf.
self.diallist[0].objectname() only return what you assign it and not the
handle. I've been searching through Object.metaclass() but am not
convinced I'm looking in the right place. self.dialist[0].__getAttr__()
seems to want a parameter but I'm not sure what to give it.
If you want to see all the code so far you can find it on github.com
https://github.com/cmoman/sequence_locus
Any clues?
Would this question be better suited for stackoverflow?
Cheers,
Chris O'Halloran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20141028/21cbb369/attachment.html>
More information about the PyQt
mailing list