dynamic inheritance


Hello all,
I'm playing with wxPython, and came to the following problem (which is more python related than wx related)
I have the following class scheme:
class Base():
def basemethod1(self,args):
pass
def basemethod2(self,args):
pass
class BaseGL(glcanvas.GLCanvas,Base):
## render the content of Base on an glcanvas
def __init__(self,parent):
Base.__init__(self,parent)
glcanvas.GLCanvas.__init__(self,parent,-1)
def Draw(self):
pass
class BaseDC(wx.Panel,Base):
## render the content of base on a standard dc
def __init__(self,parent):
Base.__init__(self,parent)
wx.Panel.__init__(self, parent)
def Draw(self):
pass
How can I implement a subclass that would inherit either from BaseDC or BaseGL, depending on user supplied parameter, so that I can Write
class DerivedClass(BaseDC or BaseGL):
def someothermethod1(self):
def someothermethod2(self):
if __name__ == "__main__":
myobject=DerivedClass(parent,usegl=true)
myobject.basemethod1
myobject.someothermethod1()
myobject.Draw()
Thanks in advance!

I'd say that you took the problem the reverse way: create 2 classes
and use either depending on user supplied parm.

JY

···

On Fri, 3 Apr 2015 07:05:41 -0700 (PDT) Yves Le Feuvre <lefeuvreyves33@gmail.com> wrote:

How can I implement a subclass that would inherit either from BaseDC
or BaseGL, depending on user supplied parameter, so that I can Write

class DerivedClass(BaseDC or BaseGL):
  def someothermethod1(self):
  def someothermethod2(self):

Yves Le Feuvre wrote:

Hello all,

I'm playing with wxPython, and came to the following problem (which is
more python related than wx related)
...
How can I implement a subclass that would inherit either from BaseDC or
BaseGL, depending on user supplied parameter, so that I can Write: ...

Inheritance is not the right answer to every question. Maybe you should
have the canvas class tree be separate, then have your final Derived
class contain an instance of it. I think your goal is to make it so
DerivedClass neither knows nor cares what kind of canvas lives below
it. If DerivedClass is a kind of canvas, then you may need two
DerivedClasses. But if DerivedClass is something that USES a canvas,
then you shouldn't inherit.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

+1 This has always been a unanswered subject I often contemplate how to solve…
Yes and No… maybe… No… Yes… Huh…Why not…What If…Ok. Now try option. eval or exec… Hmmmm…
Looking forward or backward in code and mind, yet not knowing what the user wants as an end result, but still providing all options in a simple way…
…so I will leave you with this quote without 1000*Infinity code trial iterations…
"Nothing is impossible, except that the state of your mind makes it so" - Prof John R.R. Searl"

…maybe we are not quite there(The IDEA) yet…

···

On Friday, April 3, 2015 at 12:21:23 PM UTC-5, Tim Roberts wrote:

Yves Le Feuvre wrote:

Hello all,

I’m playing with wxPython, and came to the following problem (which is
more python related than wx related)

How can I implement a subclass that would inherit either from BaseDC or
BaseGL, depending on user supplied parameter, so that I can Write: …

Inheritance is not the right answer to every question. Maybe you should

have the canvas class tree be separate, then have your final Derived

class contain an instance of it. I think your goal is to make it so

DerivedClass neither knows nor cares what kind of canvas lives below

it. If DerivedClass is a kind of canvas, then you may need two

DerivedClasses. But if DerivedClass is something that USES a canvas,

then you shouldn’t inherit.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Starter Kit Code:

import wx # GUI library
import ast # parse source code (dynamically bla bla in app so to speak)
import re # helpful only if you know what error you are looking for.
import imp # import stuff dynamically. Hopefully here, there, wherever is the IDEA import it. else fall back to other methods…

reload() # You’l’l need it for debugging and of course reloading dynamically… Python Builtin.

+ Whatever I have forgot here.

… Please improve…