Using globals with classes

Madhusudan Singh spammers-go-here at spam.invalid
Fri Aug 12 01:06:24 EDT 2005


Hi

I am relatively new to Python.

I am using Qt Designer to create a UI for a measurement application that I
use.

Everything seems to be clear but the use of globals (defined in the module
that is generated using pyuic, that contains the form class).

I am using qwtplot to display a running plot :

void Form3::runningplot(n,plottitle,xname,x,y1name,y1,y2name,y2)
{
if n==1 :

plotkey1=self.runningqwtPlot.insertCurve(y1name,self.runningqwtPlot.xBottom,self.runningqwtPlot.yLeft)

plotkey2=self.runningqwtPlot.insertCurve(y2name,self.runningqwtPlot.xBottom,self.runningqwtPlot.yRight)
        self.runningqwtPlot.setTitle(plottitle)
        self.runningqwtPlot.setXGrid(True)
        self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.yLeft)
        self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.yRight)
        self.runningqwtPlot.setAxisAutoScale(self.runningqwtPlot.xBottom)
        self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.yLeft,y1name)
        self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.yRight,y2name)
        self.runningqwtPlot.setAxisTitle(self.runningqwtPlot.xBottom,xname)
        self.runningqwtPlot.setCurveData(plotkey1,x,y1,n)
        self.runningqwtPlot.setCurveData(plotkey2,x,y2,n)
        self.runningqwtPlot.replot()
else :
 self.runningqwtPlot.setCurveData(plotkey1,x,y1,n)
 self.runningqwtPlot.setCurveData(plotkey2,x,y2,n)
 self.runningqwtPlot.replot()
}

        where the above routine is called repeatedly to display real time data.
Now, plotkey1 and plotkey2 need to remain unchanged between successive
invocations of setCurveData() and replot() above. I have defined these as
globals (in the Form settings comment field with Python: as usual).
However, when I run it, I get an error indicating that plotkey1 and
plotkey2 are unknown outside.

I also have a global variable named "globaldebug" that when set to True,
shows some diagnostic information as different slots are called. That too
fails with the same error :

NameError: global name 'globaldebug' is not defined

Is there a way to make a Python function "remember" the values of certain
variables ? Or use fortran 95 like use module, only : varname, type of
within a def ?



More information about the Python-list mailing list