Launching a wx GUI from within our python framework

B

bg_ie

Hi,

At my work we have a framework writen in python which allows us to
test our equipment. This framework is quite large and uses a Singelton
called frameworkExec which we pass around between objects in order to
share functionailty. For example, frameWorkExec stores an instance of
the BatteryManagement module which I use to set the voltage during
certain tests.

I've just writen a gui using wx which I wish to use to calibrate our
voltage supply. I launch this app at the moment within python win as
follows -

app = VoltageCalibrationApp(0)
app.MainLoop()

class VoltageCalibrationApp(wx.App):
def OnInit(self):

voltageCalibration = {}
voltageCalibration[0.0] = 1.2
voltageCalibration[9.0] = 10.1
voltageCalibration[22.0] = 22.7
voltageCalibration[24.0] = 24.8
voltageCalibration[30.0] = 31.1
voltageCalibration[35.0] = 36.9

frame = VoltageCalibrationFrame(None, -1, 'Voltage Calibration',
voltageCalibration)
frame.Show(True)
frame.Centre()
return True

I hope that by adding the code above into the framework, I will be
able to call this app as part of the framework before the execution of
certain tests, as follows -

app = VoltageCalibrationApp(0)
app.MainLoop()
test1.run()
test2.run()

As you can see in the VoltageCalibrationApp class, I am currently
hardcoding voltageCalibration. Rather than doing this, I wish to store
them in our singleton which is available at the scope at which I
create my VoltageCalibrationApp instance. But I can't figure our a way
of referencing my singleton with the OnInit function. Normally, you
would pass the reference via __init__

How can I do this?

Thanks,

Barry.
 
G

Guilherme Polo

2008/1/7 said:
Hi,

At my work we have a framework writen in python which allows us to
test our equipment. This framework is quite large and uses a Singelton
called frameworkExec which we pass around between objects in order to
share functionailty. For example, frameWorkExec stores an instance of
the BatteryManagement module which I use to set the voltage during
certain tests.

I've just writen a gui using wx which I wish to use to calibrate our
voltage supply. I launch this app at the moment within python win as
follows -

app = VoltageCalibrationApp(0)
app.MainLoop()

class VoltageCalibrationApp(wx.App):
def OnInit(self):

voltageCalibration = {}
voltageCalibration[0.0] = 1.2
voltageCalibration[9.0] = 10.1
voltageCalibration[22.0] = 22.7
voltageCalibration[24.0] = 24.8
voltageCalibration[30.0] = 31.1
voltageCalibration[35.0] = 36.9

frame = VoltageCalibrationFrame(None, -1, 'Voltage Calibration',
voltageCalibration)
frame.Show(True)
frame.Centre()
return True

I hope that by adding the code above into the framework, I will be
able to call this app as part of the framework before the execution of
certain tests, as follows -

app = VoltageCalibrationApp(0)
app.MainLoop()
test1.run()
test2.run()

As you can see in the VoltageCalibrationApp class, I am currently
hardcoding voltageCalibration. Rather than doing this, I wish to store
them in our singleton which is available at the scope at which I
create my VoltageCalibrationApp instance. But I can't figure our a way
of referencing my singleton with the OnInit function. Normally, you
would pass the reference via __init__

How can I do this?

You can define the __init__ method in your wx.App subclass, something like this:

class MyApp(wx.App):
def __init__(self, thingYouWant, redirect=True, filename=None):
self.thingyouwant = thingYouWant
wx.App.__init__(self, redirect, filename)

def OnInit(self):
... something that uses self.thingyouwant ...
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top