[Tutor] HELP: wxPython, adding items to combo box?
Aaron Elbaz
flamesrock at gmail.com
Tue Jul 5 08:56:43 CEST 2005
The simplest way I can explain this:
I have a settings wxPython settings dialog, which contains a 'servers' combo
box. I also have a shelf object that 'remembers' values entered into the
ComboBox. The current value is stored as shelf['SERVER'] and the old values
are kept in a list at shelf['OLD_SERVERS'].
The idea is to keep a history of all servers entered into the combo box. So
when you click apply changes:
def save_settings(self):
d = shelve.open(self.SETTINGS_FILE)
if d.has_key('SERVER') and d.has_key('OLD_SERVER') and \
d['SERVER'] != self.server_combo_box.GetValue():
d['OLD_SERVER'].append(d['SERVER'])
d['SERVER'] = self.server_combo_box.GetValue()
else:
d['OLD_SERVER'] = [self.server_combo_box.GetValue()]
d['SERVER'] = self.server_combo_box.GetValue()
d.close()
def on_apply_changes(self, event):
self.save_settings()
When I load the settings dialog, it should execute:
def __set_properties(self):
# begin wxGlade: SettingsDialog.__set_properties
self.SetTitle("SimNet Settings")
self.server_combo_box.SetSelection(0)
# end wxGlade
if os.path.exists(self.SETTINGS_FILE):
d = shelve.open(self.SETTINGS_FILE)
self.server_combo_box.SetString(1,d['SERVER'])
self.server_combo_box.SetString(2,d['SERVER'])
if d.has_key('OLD_SERVER'):
counter = 2
for x in d['OLD_SERVER']:
if x != d['SERVER']:
self.server_combo_box.SetString(counter,x)
counter = counter + 1
d.close()
Causing the 'history' of old servers to load at position 'counter'. Only,
this isn't working! Am I doing something wrong
or have I discovered some sort of bug in wxPython (2.6.0)?
-thanks
--
A man convinced against his will
is still of the same opinion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050705/8fdfc889/attachment.htm
More information about the Tutor
mailing list