alcemirfernandes / pynguin

Automatically exported from code.google.com/p/pynguin
GNU General Public License v3.0
0 stars 0 forks source link

no way to delete/hide a single pynguin? #30

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I can't seem to find a way to delete a single pynguin.

I can delete the reference to it, which is OK in combination with moving it 
offscreen, but I'd like to be able to do stuff like p.hide(), p.remove(), or 
q.remove_everything_else()

What version of the product are you using? On what operating system?
HEAD, Ubuntu 9.10

Original issue reported on code.google.com by aresnick...@gmail.com on 6 Jul 2010 at 6:41

GoogleCodeExporter commented 9 years ago
I am adding a pynguin.remove() method. It works like this:

    def remove(self, pyn=None):
        '''take the given pynguin (or this one if none specified)
            out of the scene.

        If removing a different pynguin from this one, this one will
            adopt all of the drawn items from the other pynguin. In
            other words, items drawn by the pynguin that is being
            removed will not be cleared immediately, but can later
            be cleared by this pynguin.

        If this pynguin is removing itself, it will first clear all
            of its own drawings, otherwise there will be no way to
            clear them out later.
        '''

Give it a try to see if it does what you need.

Original comment by miss...@hotmail.com on 15 Jul 2010 at 5:21

GoogleCodeExporter commented 9 years ago
See also p.reap() for removing all other pynguins and taking charge of their 
drawings all at once.

Original comment by miss...@hotmail.com on 15 Jul 2010 at 9:13

GoogleCodeExporter commented 9 years ago
Thanks!  This is awesome.

Original comment by aresnick...@gmail.com on 16 Jul 2010 at 3:54

GoogleCodeExporter commented 9 years ago

Original comment by miss...@hotmail.com on 17 Jul 2010 at 12:41

GoogleCodeExporter commented 9 years ago
Any chance we could have an argument for .remove that lets you choose whether 
to remove a penguin's drawings?  e.g. if you want to remove a penguin but leave 
its drawings, is that easy?  Or do drawings need to be owned by a penguin?   If 
so, maybe there could be an invisible/omnipresent penguin?

Original comment by aresnick...@gmail.com on 17 Jul 2010 at 7:23

GoogleCodeExporter commented 9 years ago
Well...

You can certainly create an invisible, omnipresent pynguin to hold any drawings 
by pynguins that you want to get rid of:

>>> reaper = Pynguin()
>>> reaper.avatar('hidden')

Now make some drawings

>>> circle(100)
>>> square(150)

Use the reaper to get rid of the pynguin

>>> reaper.remove(p)

Need a new pynguin to draw with?

>>> promote(Pynguin())
>>> lt(45)
>>> fd(100)
>>> reaper.remove(p)

Remember that if you have a bunch of other pynguins drawing, and want to get 
rid of them all at once -- but keep their drawings -- use the reap() method:

>>> for i in range(20):
>>>    pyn = Pynguin()
>>>    pyn.right(10*i)
>>>    pyn.fd(100)
>>>
>>> reaper.reap()

Original comment by miss...@hotmail.com on 18 Jul 2010 at 2:05