| 253 | self.array.wait(50) |
| 254 | |
| 255 | def swapwith(self, other): |
| 256 | nsteps = steps(self.index, other.index) |
| 257 | if not nsteps: return |
| 258 | if self.array.speed == "fastest": |
| 259 | nsteps = 0 |
| 260 | myoldpts = self.position() |
| 261 | otheroldpts = other.position() |
| 262 | self.index, other.index = other.index, self.index |
| 263 | mynewpts = self.position() |
| 264 | othernewpts = other.position() |
| 265 | myfill = self.canvas.itemcget(self.item_id, 'fill') |
| 266 | otherfill = self.canvas.itemcget(other.item_id, 'fill') |
| 267 | self.canvas.itemconfig(self.item_id, fill='green') |
| 268 | self.canvas.itemconfig(other.item_id, fill='yellow') |
| 269 | self.array.master.update() |
| 270 | if self.array.speed == "single-step": |
| 271 | self.canvas.coords(self.item_id, mynewpts) |
| 272 | self.canvas.coords(other.item_id, othernewpts) |
| 273 | self.array.master.update() |
| 274 | self.canvas.itemconfig(self.item_id, fill=myfill) |
| 275 | self.canvas.itemconfig(other.item_id, fill=otherfill) |
| 276 | self.array.wait(0) |
| 277 | return |
| 278 | mytrajectory = interpolate(myoldpts, mynewpts, nsteps) |
| 279 | othertrajectory = interpolate(otheroldpts, othernewpts, nsteps) |
| 280 | if self.value > other.value: |
| 281 | self.canvas.tag_raise(self.item_id) |
| 282 | self.canvas.tag_raise(other.item_id) |
| 283 | else: |
| 284 | self.canvas.tag_raise(other.item_id) |
| 285 | self.canvas.tag_raise(self.item_id) |
| 286 | try: |
| 287 | for i in range(len(mytrajectory)): |
| 288 | mypts = mytrajectory[i] |
| 289 | otherpts = othertrajectory[i] |
| 290 | self.canvas.coords(self.item_id, mypts) |
| 291 | self.canvas.coords(other.item_id, otherpts) |
| 292 | self.array.wait(50) |
| 293 | finally: |
| 294 | mypts = mytrajectory[-1] |
| 295 | otherpts = othertrajectory[-1] |
| 296 | self.canvas.coords(self.item_id, mypts) |
| 297 | self.canvas.coords(other.item_id, otherpts) |
| 298 | self.canvas.itemconfig(self.item_id, fill=myfill) |
| 299 | self.canvas.itemconfig(other.item_id, fill=otherfill) |
| 300 | |
| 301 | def compareto(self, other): |
| 302 | myfill = self.canvas.itemcget(self.item_id, 'fill') |