| | 389 | Also creation and removal of connected lines is recorded and can be undone: |
|---|
| | 390 | |
|---|
| | 391 | >>> def real_connect(handle, item): |
|---|
| | 392 | ... def real_disconnect(): |
|---|
| | 393 | ... handle.connected_to = None |
|---|
| | 394 | ... handle.disconnect = lambda: 0 |
|---|
| | 395 | ... handle.connected_to = item |
|---|
| | 396 | ... handle.disconnect = real_disconnect |
|---|
| | 397 | >>> canvas = Canvas() |
|---|
| | 398 | >>> b0 = Item() |
|---|
| | 399 | >>> canvas.add(b0) |
|---|
| | 400 | >>> b1 = Item() |
|---|
| | 401 | >>> canvas.add(b1) |
|---|
| | 402 | >>> l = Line() |
|---|
| | 403 | >>> canvas.add(l) |
|---|
| | 404 | >>> real_connect(l.handles()[0], b0) |
|---|
| | 405 | >>> real_connect(l.handles()[1], b1) |
|---|
| | 406 | >>> l.handles()[0].connected_to # doctest: +ELLIPSIS |
|---|
| | 407 | <gaphas.item.Item object at 0x...> |
|---|
| | 408 | >>> l.handles()[1].connected_to # doctest: +ELLIPSIS |
|---|
| | 409 | <gaphas.item.Item object at 0x...> |
|---|
| | 410 | >>> l.handles()[0].disconnect # doctest: +ELLIPSIS |
|---|
| | 411 | <function real_disconnect at 0x...> |
|---|
| | 412 | >>> l.handles()[1].disconnect # doctest: +ELLIPSIS |
|---|
| | 413 | <function real_disconnect at 0x...> |
|---|
| | 414 | |
|---|
| | 415 | Clear already collected undo data: |
|---|
| | 416 | |
|---|
| | 417 | >>> del undo_list[:] |
|---|
| | 418 | |
|---|
| | 419 | Now remove the line from the canvas: |
|---|
| | 420 | |
|---|
| | 421 | >>> canvas.remove(l) |
|---|
| | 422 | |
|---|
| | 423 | The handles are disconnected: |
|---|
| | 424 | |
|---|
| | 425 | >>> l.canvas |
|---|
| | 426 | >>> l.handles()[0].connected_to |
|---|
| | 427 | >>> l.handles()[1].connected_to |
|---|
| | 428 | >>> l.handles()[0].disconnect # doctest: +ELLIPSIS |
|---|
| | 429 | <function <lambda> at 0x...> |
|---|
| | 430 | >>> l.handles()[1].disconnect # doctest: +ELLIPSIS |
|---|
| | 431 | <function <lambda> at 0x...> |
|---|
| | 432 | |
|---|
| | 433 | Undoing the remove() action should put everything back in place again: |
|---|
| | 434 | |
|---|
| | 435 | >>> undo() |
|---|
| | 436 | |
|---|
| | 437 | >>> l.canvas # doctest: +ELLIPSIS |
|---|
| | 438 | <gaphas.canvas.Canvas object at 0x...> |
|---|
| | 439 | >>> l.handles()[0].connected_to # doctest: +ELLIPSIS |
|---|
| | 440 | <gaphas.item.Item object at 0x...> |
|---|
| | 441 | >>> l.handles()[1].connected_to # doctest: +ELLIPSIS |
|---|
| | 442 | <gaphas.item.Item object at 0x...> |
|---|
| | 443 | >>> l.handles()[0].disconnect # doctest: +ELLIPSIS |
|---|
| | 444 | <function real_disconnect at 0x...> |
|---|
| | 445 | >>> l.handles()[1].disconnect # doctest: +ELLIPSIS |
|---|
| | 446 | <function real_disconnect at 0x...> |
|---|
| | 447 | |
|---|