This one is a bit hard to explain. To see it: download the attached file, Senso.zip, and extract it somewhere, then run senso_editor.py. Now click on the Ships tab, create a new ship, and then copy it with the Copy button. Then change one of the ships, and check the other one; both the ships have changed.
I have isolated the problem to be the copying method. For ships, it is on line 462:
self.ships.append(self.ships[self.selectedship])
self.ships is a list of dictionaries containing all necessary information for each ship (position, size, speed, etc). That line is supposed to copy one of these dictionaries and append it to the end of self.ships. Instead, what it seems to be doing is appending a reference to the ship I’m trying to make a copy of. I was surprised that changing it to:
Sent: Friday, September 03, 2010 10:55 AM To:wxpython-users@googlegroups.com Subject: [wxPython-users] Copying from a list instead of referencing an
index
This one is a bit hard to explain. To see it: download the
attached file, Senso.zip, and extract it somewhere, then run senso_editor.py.
Now click on the Ships tab, create a new ship, and then copy it with the Copy
button. Then change one of the ships, and check the other one; both the ships
have changed.
I have isolated the problem to be the copying method. For ships, it is on line
462:
self.ships.append(self.ships[self.selectedship])
self.ships is a list of dictionaries containing all necessary information for
each ship (position, size, speed, etc). That line is supposed to copy one of
these dictionaries and append it to the end of self.ships. Instead, what it
seems to be doing is appending a reference to the ship I’m trying to make a
copy of. I was surprised that changing it to:
This one is a bit hard to explain. To see it: download the
attached file, Senso.zip, and extract it somewhere, then run senso_editor.py.
Now click on the Ships tab, create a new ship, and then copy it with the Copy
button. Then change one of the ships, and check the other one; both the ships
have changed.
I have isolated the problem to be the copying method. For ships, it is on line
462:
self.ships.append(self.ships[self.selectedship])
self.ships is a list of dictionaries containing all necessary information for
each ship (position, size, speed, etc). That line is supposed to copy one of
these dictionaries and append it to the end of self.ships. Instead, what it
seems to be doing is appending a reference to the ship I’m trying to make a
copy of. I was surprised that changing it to: