I'm new to IronPython and trying to create a simple application with windows forms that converts a fixed fielded file to a delimited file.
I've created a form with three buttons.
The first is to select the file to be converted. The second is to select a file with a the layout of the first file. The third is a 'submit' button to send the file names of the two files above to the python function that will convert the file.
The first two buttons work fine. My problem is passing the file names to the 'button_submitPressed' function. I tried to make FILENAME and LAYOUT global variables (I've tried it inside and outside of the 'HelloWorldForm' class but neither are working).
What do I have to do to pass variables that I collect in button events to another function?
When I run this, when I click on the submit button (after clicking the first two and selecting the filename and layout) I get the error:
IronPython.Runtime.UnboundNameException: global name 'FILENAME' is not defined
Thanks.
class HelloWorldForm(Form):
FILENAME = ''
LAYOUT = ''
def __init__(self):
self.Text = 'ff2delim'
self.label = Label()
self.label.Text = "Convert fixed legnth file to delimited"
self.label.Location = Point(50, 50)
self.label.Height = 30
self.label.Width = 200
self.count = 0
button = Button()
button.Text = "File name"
button.Location = Point(50, 100)
button.Click += self.buttonPressed
button2 = Button()
button2.Text = "Layout"
button2.Location = Point(50, 130)
button2.Click += self.button2Pressed
button_submit = Button()
button_submit.Text = "Convert"
button_submit.Location = Point(50, 190)
button_submit.Click += self.button_submitPressed
self.Controls.Add(self.label)
self.Controls.Add(button)
self.Controls.Add(button2)
self.Controls.Add(button_submit)
def buttonPressed(self, sender, args):
dialogf = OpenFileDialog()
if dialogf.ShowDialog() == DialogResult.OK:
FILENAME = dialogf.FileName
print "FILENAME: " + FILENAME
self.label_filename = Label()
self.label_filename.Text = FILENAME
self.label_filename.Location = Point(140, 105)
self.label_filename.Height = 30
self.label_filename.Width = 200
self.Controls.Add(self.label_filename)
else:
print "No file selected"
def button2Pressed(self, sender, args):
dialogl = OpenFileDialog()
if dialogl.ShowDialog() == DialogResult.OK:
LAYOUT = dialogl.FileName
print "LAYOUT: " + LAYOUT
self.label_layout = Label()
self.label_layout.Text = LAYOUT
self.label_layout.Location = Point(140, 135)
self.label_layout.Height = 30
self.label_layout.Width = 200
self.Controls.Add(self.label_layout)
else:
print "No file selected"
def button_submitPressed(self, sender, args):
convert(FILENAME,LAYOUT)