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::runningp lot(n,plottitle ,xname,x,y1name ,y1,y2name,y2)
{
if n==1 :
plotkey1=self.r unningqwtPlot.i nsertCurve(y1na me,self.running qwtPlot.xBottom ,self.runningqw tPlot.yLeft)
plotkey2=self.r unningqwtPlot.i nsertCurve(y2na me,self.running qwtPlot.xBottom ,self.runningqw tPlot.yRight)
self.runningqwt Plot.setTitle(p lottitle)
self.runningqwt Plot.setXGrid(T rue)
self.runningqwt Plot.setAxisAut oScale(self.run ningqwtPlot.yLe ft)
self.runningqwt Plot.setAxisAut oScale(self.run ningqwtPlot.yRi ght)
self.runningqwt Plot.setAxisAut oScale(self.run ningqwtPlot.xBo ttom)
self.runningqwt Plot.setAxisTit le(self.running qwtPlot.yLeft,y 1name)
self.runningqwt Plot.setAxisTit le(self.running qwtPlot.yRight, y2name)
self.runningqwt Plot.setAxisTit le(self.running qwtPlot.xBottom ,xname)
self.runningqwt Plot.setCurveDa ta(plotkey1,x,y 1,n)
self.runningqwt Plot.setCurveDa ta(plotkey2,x,y 2,n)
self.runningqwt Plot.replot()
else :
self.runningqwt Plot.setCurveDa ta(plotkey1,x,y 1,n)
self.runningqwt Plot.setCurveDa ta(plotkey2,x,y 2,n)
self.runningqwt Plot.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 "globaldebu g" 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 ?
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::runningp lot(n,plottitle ,xname,x,y1name ,y1,y2name,y2)
{
if n==1 :
plotkey1=self.r unningqwtPlot.i nsertCurve(y1na me,self.running qwtPlot.xBottom ,self.runningqw tPlot.yLeft)
plotkey2=self.r unningqwtPlot.i nsertCurve(y2na me,self.running qwtPlot.xBottom ,self.runningqw tPlot.yRight)
self.runningqwt Plot.setTitle(p lottitle)
self.runningqwt Plot.setXGrid(T rue)
self.runningqwt Plot.setAxisAut oScale(self.run ningqwtPlot.yLe ft)
self.runningqwt Plot.setAxisAut oScale(self.run ningqwtPlot.yRi ght)
self.runningqwt Plot.setAxisAut oScale(self.run ningqwtPlot.xBo ttom)
self.runningqwt Plot.setAxisTit le(self.running qwtPlot.yLeft,y 1name)
self.runningqwt Plot.setAxisTit le(self.running qwtPlot.yRight, y2name)
self.runningqwt Plot.setAxisTit le(self.running qwtPlot.xBottom ,xname)
self.runningqwt Plot.setCurveDa ta(plotkey1,x,y 1,n)
self.runningqwt Plot.setCurveDa ta(plotkey2,x,y 2,n)
self.runningqwt Plot.replot()
else :
self.runningqwt Plot.setCurveDa ta(plotkey1,x,y 1,n)
self.runningqwt Plot.setCurveDa ta(plotkey2,x,y 2,n)
self.runningqwt Plot.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 "globaldebu g" 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 ?
Comment