So I’ve been messing with the refactoring of, and abstracting (as I think
it was called) of the program I’ve been working on.
And had a “DOH!” momment more so than a “Aha!” momment.
For the past few hours I have been renaming things to try and
make them make more sense.
So every time an “add container” button is clicked this happens:
def ContAddEvent(self, event):
ContButton = {'ButtonNumber':''}
ContButtonLen = len(self.ContButtonsList)
i = ContButtonLen + 1
ContButton['ButtonNumber'] = wx.Button(self.ContButtonPanel, -1, 'Container %i'%i)
ContButton['ButtonNumber'].SetToolTipString('Click here to configure this container.')
self.ContButtonPanelSBS.Add(ContButton['ButtonNumber'], 1, wx.EXPAND | wx.ALL, 5)
self.Fit()
self.ContButtonsList.append(ContButton)
And everything worked great, even the sequencing, for removing buttons was just about the
opposite of the above function.
def ContRemoveEvent(self, event):
try:
ContButtonsLen = len(self.ContButtonsDict)
x = ContButtonsLen - 1
self.ContButtonPanelSBS.Remove(self.ContButtonsList[x]['ButtonNumber'])
self.Fit()
del self.ContButtonsList[x]
except:
dlg = wx.MessageDialog(self, 'There are not any buttons to remove.', 'Container Button Error', wx.OK)
dlg.ShowModal()
dlg.Destroy()
I had to through in an exception in case the user clicks “remove button” and there
are not buttons to remove. As you can see.
And elsewhere in the code was:
for buttons in self.ContButtonList:
self.Bind(wx.EVT_BUTTON, self.ContConfig, buttons['ButtonNumber'])
to reference the list of dictionaries.
Can anyone see my problem? I didn’t for about half an eternity…
that Bind needs to be in the ConAddEvent function with the for loop taken out.
My buttons weren’t doing anything… so I was scratching my head, because the
code had worked for other things before… Problem solved, but it goes to
illustrate how things propogate in Python. I’m still trying to wrap my mind around
it.
Steve