overwrite private method... (of wxColumnSorterMixin class)

Jp Calderone exarkun at intarweb.us
Mon Jan 19 08:40:51 EST 2004


On Mon, Jan 19, 2004 at 05:00:03AM -0800, Zachary wrote:
> 
> "Florian Preknya" <bolo at coco.ro> wrote in message
> news:bugj2p$vqj$1 at nebula.dnttm.ro...
> > Is there a posibility to overwrite a private method (one that starts with
> > __ ) ? I read that they are just formely private, they are prefixed with
> the
> > class name to have an obtured visibility, so maybe it's a trick here...
> >
> > More details...
> > I use wxPython, more specifically the wxColumnSorterMixin class. I want to
> > overwrite the __OnColClick event handler to behave on my way: I want the
> > sorting feature will affect only some columns, not all columns and that
> > event handler is the key. The problem is that the event chain is skiped in
> > the __OnColClick method, so I cannot receive the event anymore. So, my
> idea
> > was to overwrite the __OnColClick method in the mixin subclass. Is this
> > possible? Or, are they other solutions for this ?
> >
> > Thanks,
> > Florian.
> >
> >
> What you read is true, so far as I know.  It is possible to override them,
> as Python doesn't have a notion of encapsulation, again, as far as I know.
> You can probably get away with this.
> 

  Encapsulation is not the same thing as data hiding or private
attributes/methods.  Python does not have private attributes or methods, so
this is possible.  Python *does* support the concept of encapsulation, but
that is mostly unrelated to the question at hand.

    class CustomColumnSorter(wxColumnSorterMixin):
        def _wxColumnSorterMixin__OnColClick(...):
            ...

  Assuming wxColumnSorterMixin is subclassable, this will work.  It may not
be, though.  There is also probably a better way to achieve the results
you're looking for.  Perhaps by specifying a callback in some other way,
such as binding a handler to an event.

  Jp




More information about the Python-list mailing list