im working on my first wxpython app. Its a GUI for a comandline utility and needs the connection to a samba share. Now i want to add a server selection to the menu as radio buttons. Im using ConfigParser for a settings ini file which also holds the configuration for the default server as well as the server it should connect.
Now i want to deselect all radio buttons if no default server is selected and the program didnt connect at startup.
Here is my Code for adding the RADIO_ITEMS to the menu: (I know this could probably be done much better but im still learning and im glad it works, any recommendatiosn are welcome)
# Create a List to be used as variables
for i in range(1,7):
list.append('radiobutton{}'.format(str(i)))
# Append the RadioButtons
for i in range(1,7):
num = str(i)
# Load Sections of ini (every server has its own section, up to 6 are allowed)
config_sec = Config.sections()
if filter(lambda x: 'Server{}'.format(num) in x, config_sec):
name = LoadConfig("Server{}".format(num))['connection name']
list[i] = wx.MenuItem(self.wpkg_server, 400+i, name, 'Connect to Server: {} ?'.format(name), kind=wx.ITEM_RADIO)
self.wpkg_server.AppendItem(list[i])
# Get Default server setting from ini
default_server = LoadConfig("Options")['default server']
# Try if default_server is a valid number that can be converted to int
try:
int(default_server)
except ValueError:
# This is the part not working, if there is no default server set i want to uncheck
# deselect all added items but with no luck.
# the first item is always selected if no default server was set
list[i].Check(False)
else:
if i == int(default_server):
# Selecting the correct radio button if it is the default server works fine
list[i].Check(True)
self.statusbar.SetStatusText('Connected to Server: {}!'.format(name))
don't use list as your variable name, also I would expect you to get an IndexError with this code ....