[PyQt] Newbie with a circular problem calling problem
mnations.lists at gmail.com
Wed Feb 4 14:24:00 GMT 2009
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
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):
> dHP = 0
> oldHP = 10
> dST = 0
> oldST = 10
> def __init__(self, parent=None):
> QtGui.QWidget.__init__(self, parent)
> self.ui = Ui_MainWindow()
> QtCore.SIGNAL("valueChanged(int)"), self.label_DX_Cost_Set)
> QtCore.SIGNAL("valueChanged(int)"), self.label_ST_Cost_Set)
> QtCore.SIGNAL("valueChanged(int)"), self.adjust_HP)
> def label_DX_Cost_Set(self, Num):
> Num1= Num - self.dx
> self.dx = Num
> def label_ST_Cost_Set(self, Num):
> self.dST = Num - self.oldST
> self.oldST = Num
> #val = self.ui.spinBox_HP.value()
> def adjust_HP(self, Num):
> print "Num, Count", Num, self.count
> if Num==-99 :
> 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
> else :
> self.count = 0
> print "end"
> if __name__ == "__main__":
> app = QtGui.QApplication(sys.argv)
> myapp = StartQT4()
> Douglas E Knapp
> Amazon Gift Cards; let them choose!!
> PyQt mailing list PyQt at riverbankcomputing.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the PyQt