Launching a wx GUI from within our python framework
Guilherme Polo
ggpolo at gmail.com
Mon Jan 7 08:45:23 EST 2008
2008/1/7, bg_ie at yahoo.com <bg_ie at yahoo.com>:
> 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 ...
...
>
> Thanks,
>
> Barry.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
-- Guilherme H. Polo Goncalves
More information about the Python-list
mailing list