John Li wrote:
Hi all-
I have 2 Qs about OO style to use in wxPython
programs:1) I want a widget to be inherited from one class
under Windows, but from another under Linux.
At first, I wrote 2 different classes, but then thought
it would be better to write one class that uses "if wx.Platform == '__WXGTK__':" logic to decide
which class to inherit from. I used the following to begin with:class Test_Text(wxGenStaticText, wx.StaticText):
to inherit from both classes; it works under both
platforms. However, I'm wondering if that's a
dangerous programming style, since methods/values
of the two parent classes might conflict with
each other. Is there a better way to do this?
You will have problems with multiple inheritance of wx classes. A better way to do what you want is somethign like this:
if wx.Platform == '__WXGTK__':
PARENTCLASS = wxGenStaticText
else:
PARENTCLASS = wx.StaticText
class MyStaticText(PARENTCLASS):
...
2) In the demo programs, for example, there are
'MyPanel', 'MyFrame' and 'MyApp' classes that are
intended to be used only when the containing file
is run independently, not when it is imported into
another program. My question, then, is whether
it is better OO programming style to place these
classes within the 'if __name__ == __main__:' structure. Again, I have done this and it works, but I am wondering if there are any drawbacks
to using this style?
No.
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!