overwrite private method... (of wxColumnSorterMixin class)

F

Florian Preknya

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.
 
Z

Zachary

Florian Preknya said:
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.
 
J

Jp Calderone

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,947
Members
47,498
Latest member
yelene6679

Latest Threads

Top