diff --git a/krita/plugins/extensions/pykrita/libkis/krita.cpp b/krita/plugins/extensions/pykrita/libkis/krita.cpp index 064346d2bab..86b9444b996 100644 --- a/krita/plugins/extensions/pykrita/libkis/krita.cpp +++ b/krita/plugins/extensions/pykrita/libkis/krita.cpp @@ -1,77 +1,88 @@ /* * Copyright (c) 2014 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "krita.h" #include #include #include #include #include #include +Krita* Krita::s_instance = 0; + Krita::Krita(QObject *parent) : QObject(parent) { } QList Krita::mainWindows() { QList ret; foreach(QPointer mainWin, KisPart::instance()->mainWindows()) { ret << new MainWindow(mainWin, this); } return ret; } QList Krita::views() { QList ret; foreach(QPointer view, KisPart::instance()->views()) { ret << new View(view, this); } return ret; } QList Krita::documents() { QList ret; foreach(QPointer doc, KisPart::instance()->documents()) { ret << new Document(doc, this); } return ret; } QList Krita::images() { QList ret; foreach(Document *doc, documents()) { ret << doc->image(); } return ret; } QAction *Krita::createAction(const QString &text) { KisAction *action = new KisAction(text, this); foreach(KisMainWindow *mainWin, KisPart::instance()->mainWindows()) { mainWin->viewManager()->scriptManager()->addAction(action); } return action; } + +Krita* Krita::instance() +{ + if (!s_instance) + { + s_instance = new Krita; + } + return s_instance; +} diff --git a/krita/plugins/extensions/pykrita/libkis/krita.h b/krita/plugins/extensions/pykrita/libkis/krita.h index 189551ba475..d15b5aeceac 100644 --- a/krita/plugins/extensions/pykrita/libkis/krita.h +++ b/krita/plugins/extensions/pykrita/libkis/krita.h @@ -1,53 +1,54 @@ /* * Copyright (c) 2014 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef LIBKIS_KRITA_H #define LIBKIS_KRITA_H #include #include #include #include "application.h" #include "mainwindow.h" #include "view.h" #include "document.h" #include "image.h" #include class LIBKIS_EXPORT Krita : public QObject { Q_OBJECT public: explicit Krita(QObject *parent = 0); QList mainWindows(); QList views(); QList documents(); QList images(); QAction *createAction(const QString &text); - + static Krita* instance(); signals: public slots: private: + static Krita* s_instance; }; #endif // LIBKIS_KRITA_H diff --git a/krita/plugins/extensions/pykrita/sip/krita/krita.sip b/krita/plugins/extensions/pykrita/sip/krita/krita.sip index 26d3f69f0e9..32906294278 100644 --- a/krita/plugins/extensions/pykrita/sip/krita/krita.sip +++ b/krita/plugins/extensions/pykrita/sip/krita/krita.sip @@ -1,20 +1,20 @@ %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip class Krita : public QObject { %TypeHeaderCode #include "krita.h" %End -public: Krita(QObject *parent /TransferThis/ = 0); - +public: + static Krita* instance(); QList mainWindows(); QList views(); QList documents(); QList images(); QAction *createAction(const QString &text); }; diff --git a/krita/plugins/extensions/pykrita/src/plugins/hello/hello.py b/krita/plugins/extensions/pykrita/src/plugins/hello/hello.py index aeb92bf0be2..b3f9e630582 100644 --- a/krita/plugins/extensions/pykrita/src/plugins/hello/hello.py +++ b/krita/plugins/extensions/pykrita/src/plugins/hello/hello.py @@ -1,11 +1,10 @@ from PyQt4.QtGui import * from PyKrita4.krita import * import krita def hello(): QMessageBox.information(QWidget(), "Test", "Hello World") -kr = Krita() -ac = kr.createAction("Hello") +ac = Krita.instance().createAction("Hello") ac.triggered.connect(hello)