Velocity Reviews > Passing Variables

# Passing Variables

GihanFernando
Junior Member
Join Date: Dec 2009
Posts: 2

 12-10-2009
Hello I have developed code that makes fairly basic calculations and then prints them out accordingly on a frame.

But I want to know how to export these calculated variables for use in another frame.

import wx
import FloatSpin as FS

class DesignConditions(wx.Frame):

def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Design Conditions',size=(1000,700))
panel = wx.Panel(self)

wx.StaticText(panel,-1,'Atmospheric Temperature (K): ', (25,150))
wx.StaticText(panel,-1,'Atmospheric Pressure (kPa): ', (25,200))
wx.StaticText(panel,-1,'Mach Number: ', (25,250))
wx.StaticText(panel,-1,'Ratio of Specific Heat Capacities (k) of AIR: ', (25,300))
wx.StaticText(panel,-1,'Ratio of Specific Heat Capacities (k) of EXHAUST: ', (25,350))
wx.StaticText(panel,-1,'Gas co-efficient Constant (R - KJ/kg.K) of AIR: ', (25,400))
wx.StaticText(panel,-1,'Gas co-efficient Constant (R - KJ/kg.K) of EXHAUST: ', (25,450))

self.temp = FS.FloatSpin(panel,-1,min_val=200,max_val=300,increment=0.01,value=0.0 1,pos=(200,150))
self.temp.SetFormat("%f")
self.temp.SetDigits(3)

self.pres = FS.FloatSpin(panel,-1,min_val=10,max_val=110,increment=0.01,value=0.01 ,pos=(200,200))
self.pres.SetFormat("%f")
self.pres.SetDigits(3)

self.mach = FS.FloatSpin(panel,-1,min_val=0,max_val=10,increment=0.01,value=0.01,p os=(200,250))
self.mach.SetFormat("%f")
self.mach.SetDigits(3)

self.K = FS.FloatSpin(panel,-1,min_val=1,max_val=3,increment=0.01,value=1.4,pos =(275,300))
self.K.SetFormat("%f")
self.K.SetDigits(3)

self.Kt = FS.FloatSpin(panel,-1,min_val=1,max_val=3,increment=0.01,value=1.3,pos =(275,350))
self.Kt.SetFormat("%f")
self.Kt.SetDigits(3)

self.R = FS.FloatSpin(panel,-1,min_val=0,max_val=1,increment=0.01,value=0.287,p os=(275,400))
self.R.SetFormat("%f")
self.R.SetDigits(3)

self.Rt = FS.FloatSpin(panel,-1,min_val=0,max_val=1,increment=0.01,value=0.287,p os=(285,450))
self.Rt.SetFormat("%f")
self.Rt.SetDigits(3)

wx.StaticText(panel,-1,'Stagnation Temperature: ', (350,150))
wx.StaticText(panel,-1,'Stagnation Pressure: ', (350,200))
wx.StaticText(panel,-1,'Speed of Sound: ', (350,250))
wx.StaticText(panel,-1,'Specific Heat Capacity of AIR @ Constant Pressure: ', (450,300))
wx.StaticText(panel,-1,'Specific Heat Capacity of EXHAUST @ Constant Pressure: ', (450,350))

self.t2 = wx.StaticText(panel,-1,'',(500,150))
self.p2 = wx.StaticText(panel,-1,'',(500,200))
self.speed = wx.StaticText(panel,-1,'',(500,250))
self.cp = wx.StaticText(panel,-1,'',(710,300))
self.cpe = wx.StaticText(panel,-1,'',(750,350))

compute_btn = wx.Button(panel,1,'Calculate',(450,450))
compute_btn.SetFocus()
clear_btn = wx.Button(panel,2,'Quit',(650,450))

wx.EVT_BUTTON(panel,1,self.OnCompute)
wx.EVT_BUTTON(panel,2,self.OnClose)
wx.EVT_CLOSE(panel,self.OnClose)

def OnCompute(self,event):

t = float(self.temp.GetValue())
p = float(self.pres.GetValue())
M = float(self.mach.GetValue())
k = float(self.K.GetValue())
kt = float(self.Kt.GetValue())
R = float(self.R.GetValue())
Rt = float(self.Rt.GetValue())

t2 = t*(1+((k-1)/2)*(M**2))
p2 = p*((1+((k-1)/2)**(M**2))**((k-1)/k))
v = (1000*k*R*t)**(0.5)
cp = (k*R)/(k - 1)
cpe = (kt*Rt)/(kt - 1)

self.t2.SetLabel(str(t2) + ' K')
self.p2.SetLabel(str(p2) + ' kPa')
self.speed.SetLabel(str(v) + ' m/s')
self.cp.SetLabel(str(cp) + ' KJ/kg.K')
self.cpe.SetLabel(str(cpe) + ' KJ/kg.K')

return t2,p2,v,k,kt,cp,cpe

def OnClose(self,event):
self.Destroy()

if __name__=='__main__':

app = wx.PySimpleApp()
frame = DesignConditions(parent=None, id=1)
frame.Show()
app.MainLoop()

Basically all i want to do is export t2,p2,v,k,kt,cp,cpe for use in another file...

Its a very basic question because I am an absolute newb at wxPython and Python programming.