I have a problem with saving the actual string into an output file. in the
1st run it doesn't save anything. in the 2nd run it save the strings of the
1st run.
how can i make the program to save the strings of the last runs??
Stephan H
from WxPython.wx import *
import os, sys, string
from distutils.core import Command
from distutils.errors import *
wxNewID=01
file_out=open('input.txt','w')
class MainWindow(wxFrame):
def __init__(self, parent, id):
self.dirname=".."
wxFrame.__init__(self,parent,-2,"MainFrame",wxDefaultPosition,wxSize(600,800
))
panel1 = wxPanel(self, -1)
wxTextCtrl(panel1, -1, "Make Choice of Requirements",
wxPoint(350, 10),wxSize(160,20),wxTE_READONLY |
wxST_NO_AUTORESIZE)
···
#---------------------------------------------------------------------------
-----------------------------
choicebox = wxChoice(panel1, -1, (10,50),
choices = ['Customer', 'TeamMember',
'TeamLeader'])
for choice in range(1):
choicebox.Append(str(choice))
btn = wxButton(panel1, -1, 'Get User Type', (10,85))
EVT_CHOICE(panel1, choicebox.GetId(), self.OnChoice1)
EVT_BUTTON(panel1, btn.GetId(), self.OnGet1ChoiceValue)
self.choice = choicebox
#---------------------------------------------------------------------------
-----------------------------
choicebox = wxChoice(panel1, -1, (160,50),
choices =
['<100','100','150','200','250','300','350','400',
'450','500','>500'])
for choice in range(1):
choicebox.Append(str(choice))
btn2 = wxButton(panel1, -1, 'Range Value', (160,85))
EVT_CHOICE(panel1, choicebox.GetId(), self.OnChoice2)
EVT_BUTTON(panel1, btn2.GetId(), self.OnGet2ChoiceValue)
self.choice=choicebox
#---------------------------------------------------------------------------
-----------------------------
choicebox = wxChoice(panel1, -1, (270,50),
choices = ['3','3.5','4','4.5'])
for choice in range(1):
choicebox.Append(str(choice))
btn3 = wxButton(panel1, -1, 'Runway Length Requirement',
(270,85))
EVT_CHOICE(panel1, choicebox.GetId(), self.OnChoice3)
EVT_BUTTON(panel1, btn3.GetId(), self.OnGet3ChoiceValue)
self.choice=choicebox
#---------------------------------------------------------------------------
-----------------------------
choicebox = wxChoice(panel1, -1, (450,50),
choices = ['150','200','250','300','350'])
for choice in range(1):
choicebox.Append(str(choice))
btn4 = wxButton(panel1, -1, 'Maximum Cruise Speed Requirement',
(450,85))
EVT_CHOICE(panel1, choicebox.GetId(), self.OnChoice4)
EVT_BUTTON(panel1, btn4.GetId(), self.OnGet4ChoiceValue)
self.choice=choicebox
#---------------------------------------------------------------------------
-----------------------------
def OnChoice1(self, event):
print 'User:', event.GetString()
def OnGet1ChoiceValue(self, event):
print 'Kind of User:', self.choice.GetStringSelection() #writes the
former value of range string instead of actual string
def OnChoice2(self, event):
print 'Range [km]:', event.GetString()
Range_=event.GetString()
file_out.write(Range_) #writes the former value of range string
instead of actual string
file_out.write('\n')
def OnGet2ChoiceValue(self, event):
print 'Range Required [km]:', self.choice.GetStringSelection()
def OnChoice3(self, event):
print 'Runway Length [km]:', event.GetString()
Runwaylength=event.GetString()
file_out.write(Runwaylength)
file_out.write('\n')
def OnGet3ChoiceValue(self, event):
print 'Runway Length Requirement [km]:',
self.choice.GetStringSelection() #writes the former value of range string
instead of actual string
def OnChoice4(self, event):
print 'Maximum Cruise Speed[m/s]:', event.GetString()
Maxcruisespeed=event.GetString()
file_out.write(Maxcruisespeed) #writes the former value of range
string instead of actual string
file_out.write('\n')
def OnGet4ChoiceValue(self, event):
print 'Maximum Cruise Speed Required [m/s]:',
self.choice.GetStringSelection()
#---------------------------------------------------------------------------
-----------------------------
class TestApp(wxApp):
def OnInit(self):
frame = MainWindow(NULL,-1)
frame.SetSize((800,600))
frame.Show(1)
return true
app = TestApp(0)
app.MainLoop()