python - PySide Multiple Inheritance: Inheriting a QWidget and a Mixin -


i'm trying create set of pyside classes inherit qwidget, qmainwindow, , qdialog. also, inherit class overrides few functions, , set layout of widget.

example:

mixin:

class mixin(object):     def __init__(self, parent, arg):         self.arg = arg         self.parent = parent          # setup ui qdesigner         ui = ui_widget()         ui.setupui(self.parent)      def setlayout(self, layout, title):         self.parent.setwindowtitle(title)         self.parent.setlayout(layout)      def dosomething(self):         # awesome.         pass 

widget:

class widget(mixin, qtgui.qwidget):     def __init__(self, parent, arg):         super(widget, self).__init__(parent=parent, arg=arg) 

this won't work, doing through composition works

widget (composition):

class widget(qtgui.qwidget):     def __init__(self, parent, arg):         super(widget, self).__init__(parent=parent)         mixin = mixin(parent=self, arg=arg)          self.setlayout = mixin.setlayout         self.dosomething = mixin.dosomething 

i try have widget inherit instead of having part of done through composition. thanks!

keep class widget(mixin, qtgui.widget):, add super call in mixin.__init__. should ensure __init__ method of both mixin , qwidget called, , mixin implementation of setlayout method found first in mro widget.

class mixin(object):     def __init__(self, parent=none, arg=none):         super(mixin, self).__init__(parent=parent)  # call qwidget.__init__         self.arg = arg         self.parent = parent          # setup ui qdesigner         ui = ui_widget()         ui.setupui(self.parent)      def setlayout(self, layout, title):         self.parent.setwindowtitle(title)         self.parent.setlayout(layout)      def dosomething(self):         # awesome.         pass   class widget(mixin, qtgui.qwidget):     def __init__(self, parent, arg):         super(widget, self).__init__(parent=parent, arg=arg)  # calls mixin.__init__ 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -