[Tutor] Copying a list?

Zak Arntson zak at harlekin-maus.com
Wed Aug 27 16:16:48 EDT 2003


> import copy
> b = copy.copy(a)
>
<SNIP!>
> --
> Lloyd Kvam
> Venix Corp.

I want to keep the elements as references. Sorry about that, I should've
pointed out my situation:

I am creating a GUI, which consists of AppObjects with children. For
drawing the objects, I want to go through the list of children in normal
order. So that's easy:

###
class GraphicObject(AppObject):

def draw(self):
    for child in self.children:
        if isinstance(child, GraphicObject):
            child.draw()
    self._draw()
###

But for event handling, I want the object on the "top" (meaning drawn
LAST, so it's on top of all other objects), to be first to get the event.

###
import copy

class AppObject:

def handle(self, event):
    event_children = copy.copy(self.children)
    event_children.reverse()

    for child in event_children:
        child.handle(event)

    self._handle(event)
###

Does that make sense?

---
Zak Arntson
www.harlekin-maus.com - Games - Lots of 'em



More information about the Tutor mailing list