Hello.
I'm having problems with KXMLGUIClient; in particular, it seems
subclassing from it does not work when multiple inheritance is involved.
See the script below. If this gets fixed, the attached example should
work as well.
(I seem to be pushing PyKDE to its limits, and I've already found three
non-working features which I need for my application. As I've said
before, I understand that you're not very inclined to fix them for KDE 3,
but what are the odds that they'll work in KDE 4? I guess my application
can live without them until then, but I'd like to know if the future
will indeed be better. I'm afraid all I can provide is working/non-working
C++/Python examples.)
-------------------------------------------------------------------------
#! /usr/bin/env python
"""This script demonstrates that multiple inheritance with KXMLGUIClient does
not work."""
import qt
import kdeui
class MyClient1(kdeui.KXMLGUIClient):
def __init__(self):
super(MyClient1, self).__init__()
class MyClient2(kdeui.KXMLGUIClient, qt.QObject):
def __init__(self):
super(MyClient2, self).__init__()
class MyClient3(qt.QObject, kdeui.KXMLGUIClient):
def __init__(self):
super(MyClient3, self).__init__()
print hasattr(MyClient1(), 'actionCollection') # True
print hasattr(MyClient2(), 'actionCollection') # True
print hasattr(MyClient2(), 'connect') # False
print hasattr(MyClient3(), 'actionCollection') # False
print hasattr(MyClient3(), 'connect') # True
-------------------------------------------------------------------------
--
Adeodato Simó dato at net.com.org.es
Debian Developer adeodato at debian.org
We're happy, we have boyfriends! This is infinitely better than any mood
stabilizer I have ever been on.
-- Paris Geller
#! /usr/bin/env python
import sys
import qt
import kdeui
import kdecore
def main():
application = kdecore.KApplication(sys.argv, 'test app')
main_window = MainWindow(None, 'main window')
main_window.show()
application.exec_loop()
class MainWindow(kdeui.KMainWindow):
def __init__ (self, *args):
kdeui.KMainWindow.__init__(self, *args)
self.vbox = MyVBox(self)
class MyVBox(qt.QVBox, kdeui.KXMLGUIClient):
def __init__(self, parent):
qt.QVBox.__init__(self, parent)
kdeui.KXMLGUIClient.__init__(self)
self.toolbar = kdeui.KToolBar(self, 'toolbar')
# This assert succeeds...
assert 'actionCollection' in dir(self)
# ... but this does not:
print hasattr(self, 'actionCollection')
# XXX ... and this obviously dies with AttributeError
# Using super() instead of calling each constructor does not help
ac = self.actionCollection()
kdeui.KAction('Action 1', kdecore.KShortcut.null(), self.noop, ac, 'action1')
kdeui.KAction('Action 2', kdecore.KShortcut.null(), self.noop, ac, 'action2')
kdeui.KAction('Action 3', kdecore.KShortcut.null(), self.noop, ac, 'action3')
self.setXMLFile('/tmp/xml_toolbar.rc');
self.createGUI()
def createGUI(self):
builder = kdeui.KXMLGUIBuilder(self)
factory = kdeui.KXMLGUIFactory(builder, self)
factory.addClient(self)
def noop(self):
pass
if __name__ == '__main__':
main()
#include <qvbox.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kmainwindow.h>
#include <ktoolbar.h>
#include <kxmlguiclient.h>
#include <kxmlguibuilder.h>
#include <kxmlguifactory.h>
#include <kaction.h>
#include <kactioncollection.h>
class MyVBox : public QVBox, public KXMLGUIClient
{
Q_OBJECT;
public:
MyVBox(QWidget *parent);
~MyVBox();
void createGUI();
public slots:
void noop();
private:
KToolBar *toolbar;
};
MyVBox::MyVBox(QWidget *parent) : QVBox(parent), KXMLGUIClient()
{
toolbar = new KToolBar(this, "toolbar");
KActionCollection *ac = actionCollection();
new KAction("Action 1", 0, this, SLOT( noop() ), ac, "action1");
new KAction("Action 2", 0, this, SLOT( noop() ), ac, "action2");
new KAction("Action 3", 0, this, SLOT( noop() ), ac, "action3");
setXMLFile("/tmp/xml_toolbar.rc");
createGUI();
}
void
MyVBox::createGUI()
{
KXMLGUIBuilder builder(this);
KXMLGUIFactory factory(&builder, this);
factory.addClient(this);
}
void
MyVBox::noop()
{
}
MyVBox::~MyVBox()
{
delete toolbar;
}
///////////////////////////////////////
class MainWindow : public KMainWindow
{
Q_OBJECT;
public:
MainWindow();
~MainWindow();
private:
MyVBox *vbox;
};
MainWindow::MainWindow() : KMainWindow()
{
vbox = new MyVBox(this);
}
MainWindow::~MainWindow()
{
delete vbox;
}
///////////////////////////////////////
int
main (int argc, char **argv)
{
KCmdLineArgs::init(argc, argv, "test", "test", "test", "1.0");
KApplication app;
MainWindow *window = new MainWindow;
app.setTopWidget(window);
window->show();
return app.exec();
}
#include "xml_toolbar_moc.cc"
<!DOCTYPE kpartgui>
<kpartgui name="test" version="1">
<ToolBar name="toolbar" fullWidth="true">
<Text>Toolbar</Text>
<Action name="action1" />
<Action name="action2" />
<Action name="action3" />
</ToolBar>
</kpartgui>
_______________________________________________
PyQt mailing list [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt