In order to prevent similar situations in the my code where I have a set of
dependent boxes I've used a couple of methods.
First method is to use a governor function. Send all of your signals to one
function which can evaluate each signal as it's called and decide to act on
or ignore subsequent signals. From here you can set status flags and call
your worker methods. When the signals are triggered again, because of your
status flags you know to ignore them.
Second method is to disconnect the widgets that you're currently working on
and them re-connect them when you're done. This way probably works better as
it decrease the amount of events flying around.
It becomes an issue not just when updating widgets, but clearing them as
well sometimes, depending on which signal you use. I have functions which I
can call that does mass connects and disconnects.
There may be better methods for handling this in Qt, but I've found these to
work.
Marc
On Tue, Feb 3, 2009 at 11:28 AM, Knapp <magick.crow at gmail.com> wrote:
> Hello, I am a bit new to all this, so I hope this question is not to
> dumb. I am writing a program that must have a form with just these
> inputs and one input effects the other. I have one spin box,
> ST(strength) that sets the base of the second, HP (hit points). So if
> you have 10 ST then you have 10 HP but you can buy more HP by rolling
> the roller for ST. This is where it gets really messed up! Changing ST
> must update ST and HP. Calling HP must update only HP. I know this
> explanation sucks but hopefully the code will help. I am using count
> to try and stop the run away look that is happening. Is there a much
> better way?!
>> BTW, ST cost one price and HP a second so changes from both rollers
> must be kept separately be be shown added.
>> Thanks all!
> Douglas E
>> import sys
> from PyQt4 import * #QtCore, QtGui
> from Char1 import *
>> class StartQT4(QtGui.QMainWindow):
> count=0
> dHP = 0
> oldHP = 10
> dST = 0
> oldST = 10
> def __init__(self, parent=None):
> QtGui.QWidget.__init__(self, parent)
> self.ui = Ui_MainWindow()
> self.ui.setupUi(self)
> QtCore.QObject.connect(self.ui.spinBox_DX,
> QtCore.SIGNAL("valueChanged(int)"), self.label_DX_Cost_Set)
> QtCore.QObject.connect(self.ui.spinBox_ST,
> QtCore.SIGNAL("valueChanged(int)"), self.label_ST_Cost_Set)
> QtCore.QObject.connect(self.ui.spinBox_HP,
> QtCore.SIGNAL("valueChanged(int)"), self.adjust_HP)
> #
> QtCore.QObject.connect(self.ui.spinBox_ST,QtCore.SIGNAL("valueChanged(int)"),
> self.lineEdit_Basic_Lift_s)
>> def label_DX_Cost_Set(self, Num):
> Num1= Num - self.dx
> self.dx = Num
> self.ui.label_DX_Cost.setNum(Num1)
>> def label_ST_Cost_Set(self, Num):
> self.dST = Num - self.oldST
> self.oldST = Num
> self.ui.label_ST_Cost.setNum((Num-10)*20)
> self.ui.lineEdit_Basic_Lift.setText(str(Num*Num/5))
> #val = self.ui.spinBox_HP.value()
> #self.ui.spinBox_HP.setValue(0)
> self.adjust_HP(-99)
>> def adjust_HP(self, Num):
> print "Num, Count", Num, self.count
> if Num==-99 :
> self.ui.spinBox_HP.setValue(self.oldHP+self.dST)
> print "99 ds, oldHP", self.dST, self.oldHP
> self.oldHP += self.dST
> elif self.count == 0 :
> self.count += 1
> self.dHP = Num - self.oldHP
> print " ds, oldHP", self.dST, self.oldHP
> self.oldHP = Num
> self.ui.label_HP_Cost.setNum(Num+self.oldHP)
> self.ui.spinBox_HP.setValue(self.oldHP+self.dHP)
> else :
> self.count = 0
> print "end"
>> if __name__ == "__main__":
> app = QtGui.QApplication(sys.argv)
> myapp = StartQT4()
> myapp.show()
> sys.exit(app.exec_())
> --
> Douglas E Knapp
>> Amazon Gift Cards; let them choose!!
>>http://www.amazon.com/gp/product/B001078FFE?ie=UTF8&tag=seattlebujinkand&linkCode=as2&camp=1789&creative=9325&creativeASIN=B001078FFE> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com>http://www.riverbankcomputing.com/mailman/listinfo/pyqt>-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090204/7f0c2c38/attachment.html