[wxPython] newbie: events & saving values

Hi all,

i'm kinda new to GUI and OO, so if this is something silly, please excuse the question.
If I've missed some documentation somewhere, point me to it pls.

I have a form, with a whole bunch of text entry fields, that gets generated dynamically from a file.
I might have more fields, or less. It's no set number.

pretty much the what i do is:

for x in readFile
   create fld [x] on the form

now, i want to be able to change the values of these fields and save them.

i have a vague idea of how events work. i would use EVT_TEXT to check if a field has changed.
But how do i know _which_ field has changed?

related question to this, is there a way of running through ALL the fields(right term: widgets?) on the form and save that to another file? something like:

for x in fields_on_the_Form
   write field[x] to file

hope that was clear enough.

If anyone has an example of such a thing, please point me to it.

TIA

Vuk

But how do i know _which_ field has changed?

related question to this, is there a way of running through ALL the fields(right term: widgets?) on the form and save that to another file? something like:

Hello!

Every widget is when created assigned an ID. You can give it
some specific number

name_text_ctrl = wxTextCtrl(self, 12345, "Initial string")

or you can do this

name_text_ctrl = wxTextCtrl(self, -1, "Initial string")

and a text conrol is assigned some free identificator.

Later you can bind the control with some function which is invoked
when some event happens.

EVT_TEXT(self, 12345, self.on_name_text_ctrl)

...

def on_name_text_ctrl(self, evt):
  do something ....

Solution to your problem would look similar to this:

# let's suppose your initial field data are stored in a list
# called init_data

ID_FIELDS = 12000

def __init__(...):
  ...
  wxForm.__init__(...)
  ...
  fields = ; i = 0
  for data in init_data:
    fields.append(wxTextCtrl(self, ID_FIELDS + i, data))
    EVT_TEXT(self, ID_FIELDS + i, self.on_field_changed)
    i = i + 1

  self.fields = fields
  self.values = init_data
  ...

def on_field_changed(self, evt):
  id = evt.GetId() - ID_FIELDS
  self.values[id] = self.fields[id].GetValue()

and you have the current data in self.values list.

Hope this helps you.

Jirka Mikulasek