[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Multiple inheritance with item views
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2010-02-22 21:39:24
Message-ID: 20100222213924.GA3878 () trinity ! apaku ! dnsalias ! org
[Download RAW message or body]

On 22.02.10 21:09:28, Jugdish wrote:
> The reason I have BaseView inheriting from QAbstractItemView is because
> inside it I make calls like:
> 
> self.setItemDelegate(...)
> self.setDragEnabled(...)
> self.setEditTriggers(...)
> 
> and so on. These are all things that are common to both
> MyTreeView/MyTableView, and obviously wouldn't work if BaseView had no base
> class.

Sure they would, thats so nice about python being a dynamically typed
language - as long as self has that function during runtime it'll work.
And during runtime it does have that function because of subclassing
MyTableView from QTableView+BaseView (unless PyQt4 has a restriction).
Take this example:

class Bar:
    def my(self):
        self.goup()

class Foo:
    def goup(self):
        print "Hi", self

class FooBar( Foo, Bar ):
    def makeit(self):
        print "me:", self
        self.my()

f = FooBar()
f.makeit()

It'll just work.

> Any ideas of a better way to achieve this without duplicating code between
> the 2 views?

Avoiding code-duplication should only be done with subclassing if the
subclasses "make sense", i.e. if they'd also exist without wanting to
avoid the code-duplication. In other cases the duplicated code should
rather be put into some shared functions or the like.

Andreas

-- 
Your object is to save the world, while still leading a pleasant life.
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic