[PyQt] Newbie with a circular problem calling problem

Knapp magick.crow at gmail.com
Tue Feb 3 17:28:10 GMT 2009


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


More information about the PyQt mailing list