diff --git a/krita/plugins/extensions/pykrita/libkis/CMakeLists.txt b/krita/plugins/extensions/pykrita/libkis/CMakeLists.txt index 18aa1370bb..33a9649979 100644 --- a/krita/plugins/extensions/pykrita/libkis/CMakeLists.txt +++ b/krita/plugins/extensions/pykrita/libkis/CMakeLists.txt @@ -1,30 +1,32 @@ include_directories(${KOMAIN_INCLUDES} ${KRITA_INCLUDES}) set(kritalibkis_LIB_SRCS application.cpp document.cpp image.cpp mainwindow.cpp krita.cpp node.cpp view.cpp + viewextension.cpp + viewmanager.cpp ) kde4_add_library(kritalibkis SHARED ${kritalibkis_LIB_SRCS} ) if (WIN32) target_link_libraries(kritalibkis kritaui kritaimage ${WIN32_PLATFORM_NET_LIBS}) else (WIN32) target_link_libraries(kritalibkis kritaui kritaimage) endif (WIN32) target_link_libraries(kritalibkis LINK_INTERFACE_LIBRARIES kritaimage kritaui) set_target_properties(kritalibkis PROPERTIES VERSION ${GENERIC_CALLIGRA_LIB_VERSION} SOVERSION ${GENERIC_CALLIGRA_LIB_SOVERSION} ) install(TARGETS kritalibkis ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/krita/plugins/extensions/pykrita/libkis/application.h b/krita/plugins/extensions/pykrita/libkis/application.h index 4033386010..f503e465fe 100644 --- a/krita/plugins/extensions/pykrita/libkis/application.h +++ b/krita/plugins/extensions/pykrita/libkis/application.h @@ -1,35 +1,35 @@ /* * 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_APPLICATION_H #define LIBKIS_APPLICATION_H #include #include class LIBKIS_EXPORT Application : public QObject { Q_OBJECT public: explicit Application(QObject *parent = 0); -signals: +Q_SIGNALS: -public slots: +public Q_SLOTS: }; #endif // LIBKIS_APPLICATION_H diff --git a/krita/plugins/extensions/pykrita/libkis/document.h b/krita/plugins/extensions/pykrita/libkis/document.h index dbf343c875..c506a58a2d 100644 --- a/krita/plugins/extensions/pykrita/libkis/document.h +++ b/krita/plugins/extensions/pykrita/libkis/document.h @@ -1,43 +1,43 @@ /* * 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_DOCUMENT_H #define LIBKIS_DOCUMENT_H #include #include class KisDocument; class Image; class LIBKIS_EXPORT Document : public QObject { Q_OBJECT public: explicit Document(KisDocument *document, QObject *parent = 0); Image *image(); -signals: +Q_SIGNALS: -public slots: +public Q_SLOTS: private: QPointer m_document; }; #endif // LIBKIS_DOCUMENT_H diff --git a/krita/plugins/extensions/pykrita/libkis/image.h b/krita/plugins/extensions/pykrita/libkis/image.h index 405cc163f2..88bbe6e4c5 100644 --- a/krita/plugins/extensions/pykrita/libkis/image.h +++ b/krita/plugins/extensions/pykrita/libkis/image.h @@ -1,38 +1,38 @@ /* * 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_IMAGE_H #define LIBKIS_IMAGE_H #include #include #include class LIBKIS_EXPORT Image : public QObject { Q_OBJECT public: explicit Image(QObject *image, QObject *parent = 0); -signals: +Q_SIGNALS: -public slots: +public Q_SLOTS: private: KisImageWSP m_image; }; #endif // LIBKIS_IMAGE_H diff --git a/krita/plugins/extensions/pykrita/libkis/krita.cpp b/krita/plugins/extensions/pykrita/libkis/krita.cpp index 86b9444b99..ab2bc17632 100644 --- a/krita/plugins/extensions/pykrita/libkis/krita.cpp +++ b/krita/plugins/extensions/pykrita/libkis/krita.cpp @@ -1,88 +1,99 @@ /* * 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 "viewextension.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; } +void Krita::addViewExtension(ViewExtension* _viewExtension) +{ + m_viewExtensions.append(_viewExtension); +} + +QList< ViewExtension* > Krita::viewExtensions() +{ + return m_viewExtensions; +} + 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 d15b5aecea..75d58386a9 100644 --- a/krita/plugins/extensions/pykrita/libkis/krita.h +++ b/krita/plugins/extensions/pykrita/libkis/krita.h @@ -1,54 +1,61 @@ /* * 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 ViewExtension; + 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); + + void addViewExtension(ViewExtension* _viewExtension); + QList viewExtensions(); + static Krita* instance(); -signals: +Q_SIGNALS: -public slots: +public Q_SLOTS: private: static Krita* s_instance; + QList m_viewExtensions; }; #endif // LIBKIS_KRITA_H diff --git a/krita/plugins/extensions/pykrita/libkis/mainwindow.h b/krita/plugins/extensions/pykrita/libkis/mainwindow.h index ba4e58d49d..de3f605e4c 100644 --- a/krita/plugins/extensions/pykrita/libkis/mainwindow.h +++ b/krita/plugins/extensions/pykrita/libkis/mainwindow.h @@ -1,43 +1,41 @@ /* * 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_MAINWINDOW_H #define LIBKIS_MAINWINDOW_H #include #include class KisMainWindow; -#include - class LIBKIS_EXPORT MainWindow : public QObject { Q_OBJECT public: explicit MainWindow(KisMainWindow *mainWin, QObject *parent = 0); -signals: +Q_SIGNALS: -public slots: +public Q_SLOTS: private: KisMainWindow *m_mainWindow; }; #endif // MAINWINDOW_H diff --git a/krita/plugins/extensions/pykrita/libkis/node.h b/krita/plugins/extensions/pykrita/libkis/node.h index 2df7714f35..3ff5b40be0 100644 --- a/krita/plugins/extensions/pykrita/libkis/node.h +++ b/krita/plugins/extensions/pykrita/libkis/node.h @@ -1,37 +1,37 @@ /* * 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_NODE_H #define LIBKIS_NODE_H #include #include class LIBKIS_EXPORT Node : public QObject { Q_OBJECT public: explicit Node(QObject *parent = 0); -signals: +Q_SIGNALS: -public slots: +public Q_SLOTS: }; #endif // LIBKIS_NODE_H diff --git a/krita/plugins/extensions/pykrita/libkis/view.h b/krita/plugins/extensions/pykrita/libkis/view.h index 2d7aaa10b2..635b015b9c 100644 --- a/krita/plugins/extensions/pykrita/libkis/view.h +++ b/krita/plugins/extensions/pykrita/libkis/view.h @@ -1,43 +1,43 @@ /* * 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_VIEW_H #define LIBKIS_VIEW_H #include #include class KisView; class LIBKIS_EXPORT View : public QObject { Q_OBJECT public: explicit View(KisView *view, QObject *parent = 0); -signals: +Q_SIGNALS: -public slots: +public Q_SLOTS: private: KisView *m_view; }; #endif // LIBKIS_VIEW_H diff --git a/krita/plugins/extensions/pykrita/libkis/node.h b/krita/plugins/extensions/pykrita/libkis/viewextension.cpp similarity index 71% copy from krita/plugins/extensions/pykrita/libkis/node.h copy to krita/plugins/extensions/pykrita/libkis/viewextension.cpp index 2df7714f35..67f2d45460 100644 --- a/krita/plugins/extensions/pykrita/libkis/node.h +++ b/krita/plugins/extensions/pykrita/libkis/viewextension.cpp @@ -1,37 +1,31 @@ /* - * Copyright (c) 2014 Boudewijn Rempt + * Copyright (c) 2015 Cyrille Berger * * 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_NODE_H -#define LIBKIS_NODE_H -#include +#include "viewextension.h" -#include +#include -class LIBKIS_EXPORT Node : public QObject +ViewExtension::ViewExtension(QObject* parent): QObject(parent) { - Q_OBJECT -public: - explicit Node(QObject *parent = 0); -signals: +} -public slots: - -}; - -#endif // LIBKIS_NODE_H +ViewExtension::~ViewExtension() +{ + qDebug() << "~"; +} diff --git a/krita/plugins/extensions/pykrita/libkis/view.h b/krita/plugins/extensions/pykrita/libkis/viewextension.h similarity index 71% copy from krita/plugins/extensions/pykrita/libkis/view.h copy to krita/plugins/extensions/pykrita/libkis/viewextension.h index 2d7aaa10b2..9da585c65c 100644 --- a/krita/plugins/extensions/pykrita/libkis/view.h +++ b/krita/plugins/extensions/pykrita/libkis/viewextension.h @@ -1,43 +1,37 @@ /* - * Copyright (c) 2014 Boudewijn Rempt + * Copyright (c) 2015 Cyrille Berger * * 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_VIEW_H -#define LIBKIS_VIEW_H -#include +#ifndef LIBKIS_VIEWEXTENSION_H +#define LIBKIS_VIEWEXTENSION_H #include -class KisView; +#include + +class ViewManager; -class LIBKIS_EXPORT View : public QObject +class LIBKIS_EXPORT ViewExtension : public QObject { Q_OBJECT public: - explicit View(KisView *view, QObject *parent = 0); - -signals: - -public slots: - -private: - - KisView *m_view; - + explicit ViewExtension(QObject *parent = 0); + virtual ~ViewExtension(); + virtual void setup(ViewManager* _view) = 0; }; -#endif // LIBKIS_VIEW_H +#endif diff --git a/krita/plugins/extensions/pykrita/libkis/mainwindow.h b/krita/plugins/extensions/pykrita/libkis/viewmanager.cpp similarity index 60% copy from krita/plugins/extensions/pykrita/libkis/mainwindow.h copy to krita/plugins/extensions/pykrita/libkis/viewmanager.cpp index ba4e58d49d..75d5a8c9b3 100644 --- a/krita/plugins/extensions/pykrita/libkis/mainwindow.h +++ b/krita/plugins/extensions/pykrita/libkis/viewmanager.cpp @@ -1,43 +1,35 @@ /* - * Copyright (c) 2014 Boudewijn Rempt + * Copyright (c) 2015 Cyrille Berger * * 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_MAINWINDOW_H -#define LIBKIS_MAINWINDOW_H +#include "viewmanager.h" -#include -#include -class KisMainWindow; +#include +#include +#include -#include - -class LIBKIS_EXPORT MainWindow : public QObject +ViewManager::ViewManager(KisViewManager *viewManager, QObject *parent) + : QObject(parent) + , m_viewManager(viewManager) { - Q_OBJECT -public: - explicit MainWindow(KisMainWindow *mainWin, QObject *parent = 0); - -signals: - -public slots: - +} -private: - - KisMainWindow *m_mainWindow; -}; - -#endif // MAINWINDOW_H +QAction *ViewManager::createAction(const QString& text) +{ + KisAction *action = new KisAction(text, m_viewManager); + m_viewManager->scriptManager()->addAction(action); + return action; +} diff --git a/krita/plugins/extensions/pykrita/libkis/view.h b/krita/plugins/extensions/pykrita/libkis/viewmanager.h similarity index 68% copy from krita/plugins/extensions/pykrita/libkis/view.h copy to krita/plugins/extensions/pykrita/libkis/viewmanager.h index 2d7aaa10b2..9ec53b7941 100644 --- a/krita/plugins/extensions/pykrita/libkis/view.h +++ b/krita/plugins/extensions/pykrita/libkis/viewmanager.h @@ -1,43 +1,45 @@ /* - * Copyright (c) 2014 Boudewijn Rempt + * Copyright (c) 2015 Cyrille Berger * * 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_VIEW_H -#define LIBKIS_VIEW_H +#ifndef LIBKIS_VIEWMANAGER_H +#define LIBKIS_VIEWMANAGER_H #include #include -class KisView; +class KisViewManager; +class QAction; -class LIBKIS_EXPORT View : public QObject +class LIBKIS_EXPORT ViewManager : public QObject { Q_OBJECT public: - explicit View(KisView *view, QObject *parent = 0); + explicit ViewManager(KisViewManager *viewManager, QObject *parent = 0); + QAction *createAction(const QString &text); -signals: +Q_SIGNALS: -public slots: +public Q_SLOTS: private: - KisView *m_view; + KisViewManager *m_viewManager; }; #endif // LIBKIS_VIEW_H diff --git a/krita/plugins/extensions/pykrita/sip/krita/krita.sip b/krita/plugins/extensions/pykrita/sip/krita/krita.sip index 3290629427..11e33dd5d3 100644 --- a/krita/plugins/extensions/pykrita/sip/krita/krita.sip +++ b/krita/plugins/extensions/pykrita/sip/krita/krita.sip @@ -1,20 +1,22 @@ %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip class Krita : public QObject { %TypeHeaderCode #include "krita.h" %End Krita(QObject *parent /TransferThis/ = 0); public: static Krita* instance(); QList mainWindows(); QList views(); QList documents(); QList images(); QAction *createAction(const QString &text); + + void addViewExtension(ViewExtension* _viewExtension /TransferThis/); }; diff --git a/krita/plugins/extensions/pykrita/sip/krita/kritamod.sip b/krita/plugins/extensions/pykrita/sip/krita/kritamod.sip index af67f6f2e8..50d35e5d83 100644 --- a/krita/plugins/extensions/pykrita/sip/krita/kritamod.sip +++ b/krita/plugins/extensions/pykrita/sip/krita/kritamod.sip @@ -1,20 +1,22 @@ %Module PyKrita4.krita %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip %ModuleHeaderCode #pragma GCC visibility push(default) %End %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip %Import QtXml/QtXmlmod.sip %Include application.sip %Include document.sip %Include image.sip %Include mainwindow.sip %Include krita.sip %Include node.sip %Include view.sip +%Include viewextension.sip +%Include viewmanager.sip diff --git a/krita/plugins/extensions/pykrita/sip/krita/viewextension.sip b/krita/plugins/extensions/pykrita/sip/krita/viewextension.sip new file mode 100644 index 0000000000..416a6046d6 --- /dev/null +++ b/krita/plugins/extensions/pykrita/sip/krita/viewextension.sip @@ -0,0 +1,16 @@ +%Import QtCore/QtCoremod.sip +%Import QtGui/QtGuimod.sip + + +class ViewExtension : public QObject +{ + +%TypeHeaderCode +#include "viewextension.h" +#include +%End + +public: + explicit ViewExtension(QObject *parent /TransferThis/ = 0); + virtual void setup(ViewManager* _viewManager) = 0; +}; diff --git a/krita/plugins/extensions/pykrita/sip/krita/viewmanager.sip b/krita/plugins/extensions/pykrita/sip/krita/viewmanager.sip new file mode 100644 index 0000000000..186def7f86 --- /dev/null +++ b/krita/plugins/extensions/pykrita/sip/krita/viewmanager.sip @@ -0,0 +1,13 @@ +%Import QtCore/QtCoremod.sip +%Import QtGui/QtGuimod.sip + +class ViewManager : public QObject /NoDefaultCtors/ +{ +%TypeHeaderCode +#include "viewmanager.h" +%End + +public: + QAction *createAction(const QString &text); + +}; diff --git a/krita/plugins/extensions/pykrita/src/CMakeLists.txt b/krita/plugins/extensions/pykrita/src/CMakeLists.txt index 935bf9c808..bf5b0779b8 100644 --- a/krita/plugins/extensions/pykrita/src/CMakeLists.txt +++ b/krita/plugins/extensions/pykrita/src/CMakeLists.txt @@ -1,42 +1,43 @@ # NOTE Disable trivial Qt keywords due conflicts w/ some Python.h header # (at least version 3.3 of it has a member PyType_Spec::slots) add_definitions(-DQT_NO_KEYWORDS) configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) set(SOURCES plugin.cpp pyqtpluginsettings.cpp utilities.cpp engine.cpp ) kde4_add_ui_files(SOURCES info.ui manager.ui ) kde4_add_plugin(kritapykrita ${SOURCES}) target_link_libraries( kritapykrita ${PYTHON_LIBRARY} kritaui kritalibbrush + kritalibkis ) install(TARGETS kritapykrita DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES kritapyqt.desktop DESTINATION ${SERVICES_INSTALL_DIR}/calligra) install(FILES kritapyqtplugin.rc DESTINATION ${DATA_INSTALL_DIR}/kritaplugins) install(FILES kritapyqtplugin.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) # Install "built-in" plugins install( DIRECTORY krita DESTINATION ${DATA_INSTALL_DIR}/krita/plugins/pykrita FILES_MATCHING PATTERN "*.py" ) add_subdirectory(plugins) add_subdirectory(test) diff --git a/krita/plugins/extensions/pykrita/src/plugin.cpp b/krita/plugins/extensions/pykrita/src/plugin.cpp index d5fa2ccded..2e65fd9bf7 100644 --- a/krita/plugins/extensions/pykrita/src/plugin.cpp +++ b/krita/plugins/extensions/pykrita/src/plugin.cpp @@ -1,75 +1,81 @@ /* * Copyright (c) 2014 Boudewijn Rempt (boud@valdyas.org) * * 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; version 2 of the License. * * 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 "plugin.h" #include "engine.h" #include "utilities.h" #include #include #include #include #include +#include +#include +#include + K_PLUGIN_FACTORY(KritaPyQtPluginFactory, registerPlugin();) K_EXPORT_PLUGIN(KritaPyQtPluginFactory("krita")) KritaPyQtPlugin::KritaPyQtPlugin(QObject *parent, const QVariantList &) : KisViewPlugin(parent) , m_engineFailureReason(m_engine.tryInitializeGetFailureReason()) , m_autoReload(false) { KisPreferenceSetRegistry *preferenceSetRegistry = KisPreferenceSetRegistry::instance(); PyQtPluginSettingsFactory* settingsFactory = new PyQtPluginSettingsFactory(&m_engine); //load and save preferences //if something in kritarc is missing, then the default from this load function will be used and saved back to kconfig. //this way, cfg.readEntry() in any part won't be able to set its own default KisPreferenceSet* settings = settingsFactory->createPreferenceSet(); Q_ASSERT(settings); settings->loadPreferences(); settings->savePreferences(); delete settings; preferenceSetRegistry->add("PyQtPluginSettingsFactory", settingsFactory); // Try to import the `pykrita` module PyKrita::Python py = PyKrita::Python(); PyObject* pykritaPackage = py.moduleImport("pykrita"); pykritaPackage = py.moduleImport("krita"); if (pykritaPackage) { dbgScript << "Loaded pykrita, now load plugins"; m_engine.tryLoadEnabledPlugins(); py.functionCall("_pykritaLoaded", PyKrita::Python::PYKRITA_ENGINE); } else { dbgScript << "Cannot load pykrita module"; m_engine.setBroken(); } - - - + ViewManager* viewManager = new ViewManager(m_view); + Q_FOREACH (ViewExtension* ext, Krita::instance()->viewExtensions()) + { + ext->setup(viewManager); + } } KritaPyQtPlugin::~KritaPyQtPlugin() { } diff --git a/krita/plugins/extensions/pykrita/src/plugins/hello/hello.py b/krita/plugins/extensions/pykrita/src/plugins/hello/hello.py index b3f9e63058..42527b9cbe 100644 --- a/krita/plugins/extensions/pykrita/src/plugins/hello/hello.py +++ b/krita/plugins/extensions/pykrita/src/plugins/hello/hello.py @@ -1,10 +1,14 @@ from PyQt4.QtGui import * from PyKrita4.krita import * -import krita - def hello(): QMessageBox.information(QWidget(), "Test", "Hello World") -ac = Krita.instance().createAction("Hello") -ac.triggered.connect(hello) +class HelloViewExtension(ViewExtension): + def __init__(self, parent): + super().__init__(parent) + def setup(self, viewManager): + action = viewManager.createAction("Hello") + action.triggered.connect(hello) + +Krita.instance().addViewExtension(HelloViewExtension(Krita.instance()))