diff --git a/krita/plugins/extensions/pykrita/CMakeLists.txt b/krita/plugins/extensions/pykrita/CMakeLists.txt index 45b6329e59..a5e74d4c73 100644 --- a/krita/plugins/extensions/pykrita/CMakeLists.txt +++ b/krita/plugins/extensions/pykrita/CMakeLists.txt @@ -1,27 +1,29 @@ + +set(Python_ADDITIONAL_VERSIONS 3.0 3.1 3.2 3.3 3.4 3.5 3.6) macro_optional_find_package(PythonLibrary) macro_log_feature(PYTHON_LIBRARY "PythonLibrary" "Python Library" FALSE "" "Required by the Krita PyQt plugin") macro_bool_to_01(PYTHONLIBS_FOUND HAVE_PYTHONLIBS) macro_optional_find_package(SIP 4.7.1) macro_log_feature(SIP_FOUND "SIP" "Support for SIP Python bindings" FALSE "" "Required by the Krita PyQt plugin") macro_bool_to_01(SIP_FOUND HAVE_SIP) macro_optional_find_package(PyQt4 4.3.1) macro_log_feature(PYQT4_FOUND "PyQt4" "Python bindings for Qt4" FALSE "" "Required by the Krita PyQt plugin") macro_bool_to_01(PYQT4_FOUND HAVE_PYQT4) if (HAVE_PYQT4 AND HAVE_SIP AND HAVE_PYTHONLIBS) -if (NOT EXISTS ${PYQT4_SIP_DIR}/QtCore/QtCoremod.sip) - message(WARNING "krita-pykrita plugin needs the PyQt4 development sip file QtCoremod.sip") - return() -endif() +# if (NOT EXISTS ${PYQT4_SIP_DIR}/QtCore/QtCoremod.sip) +# message(WARNING "krita-pykrita plugin needs the PyQt4 development sip file QtCoremod.sip") +# return() +# endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${SIP_INCLUDE_DIR} ${PYTHON_INCLUDE_PATH}) add_subdirectory(libkis) add_subdirectory(sip) add_subdirectory(src) endif (HAVE_PYQT4 AND HAVE_SIP AND HAVE_PYTHONLIBS) diff --git a/krita/plugins/extensions/pykrita/libkis/document.cpp b/krita/plugins/extensions/pykrita/libkis/document.cpp index dd573f3c1c..130bbc9545 100644 --- a/krita/plugins/extensions/pykrita/libkis/document.cpp +++ b/krita/plugins/extensions/pykrita/libkis/document.cpp @@ -1,32 +1,32 @@ /* * 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 "document.h" #include "image.h" -#include +#include -Document::Document(QObject *document, QObject *parent) +Document::Document(KisDocument *document, QObject *parent) : QObject(parent) - , m_document(qobject_cast(document)) + , m_document(document) { } Image *Document::image() { return new Image(m_document->image().data(), this); } diff --git a/krita/plugins/extensions/pykrita/libkis/document.h b/krita/plugins/extensions/pykrita/libkis/document.h index da1bf2b391..dbf343c875 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 +#include -class KisDoc2; +class KisDocument; class Image; class LIBKIS_EXPORT Document : public QObject { Q_OBJECT public: - explicit Document(QObject *document, QObject *parent = 0); + explicit Document(KisDocument *document, QObject *parent = 0); Image *image(); signals: public slots: private: - KisDoc2 *m_document; + QPointer m_document; }; #endif // LIBKIS_DOCUMENT_H diff --git a/krita/plugins/extensions/pykrita/libkis/krita.cpp b/krita/plugins/extensions/pykrita/libkis/krita.cpp index c7a6905914..064346d2ba 100644 --- a/krita/plugins/extensions/pykrita/libkis/krita.cpp +++ b/krita/plugins/extensions/pykrita/libkis/krita.cpp @@ -1,97 +1,77 @@ /* * 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 +#include +#include #include #include #include Krita::Krita(QObject *parent) : QObject(parent) { } QList Krita::mainWindows() { QList ret; - foreach(KoPart *part, koApp->partList()) { - if (part) { - foreach(KoMainWindow *mainWin, part->mainWindows()) { - ret << new MainWindow(mainWin, this); - } - } + foreach(QPointer mainWin, KisPart::instance()->mainWindows()) { + ret << new MainWindow(mainWin, this); } return ret; } QList Krita::views() { QList ret; - foreach(MainWindow *mainWin, mainWindows()) { - ret << mainWin->views(); + foreach(QPointer view, KisPart::instance()->views()) { + ret << new View(view, this); } return ret; } QList Krita::documents() { QList ret; - foreach(KoPart *part, koApp->partList()) { - if (part) { - KisDoc2 *doc = qobject_cast(part->document()); - if (doc) { - ret << new Document(doc, this); - } - } + 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(KoPart *part, koApp->partList()) { - if (part) { - foreach(KoMainWindow *mainWin, part->mainWindows()) { - if (mainWin && mainWin->rootView()) { - KisView2 *view = qobject_cast(view); - if (view) { - view->scriptManager()->addAction(action); - } - } - } - } + foreach(KisMainWindow *mainWin, KisPart::instance()->mainWindows()) { + mainWin->viewManager()->scriptManager()->addAction(action); } return action; } diff --git a/krita/plugins/extensions/pykrita/libkis/mainwindow.cpp b/krita/plugins/extensions/pykrita/libkis/mainwindow.cpp index 8166679d56..69ca89cdc2 100644 --- a/krita/plugins/extensions/pykrita/libkis/mainwindow.cpp +++ b/krita/plugins/extensions/pykrita/libkis/mainwindow.cpp @@ -1,39 +1,29 @@ /* * 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 "mainwindow.h" -#include -#include +#include +#include #include "view.h" -MainWindow::MainWindow(QObject *mainWin, QObject *parent) +MainWindow::MainWindow(KisMainWindow *mainWin, QObject *parent) : QObject(parent) - , m_mainWindow(qobject_cast(mainWin)) + , m_mainWindow(mainWin) { } - -QList MainWindow::views() -{ - QList ret; - KisView2 *view = qobject_cast(m_mainWindow->rootView()); - if (view) { - ret << new View(view, this); - } - return ret; -} diff --git a/krita/plugins/extensions/pykrita/libkis/mainwindow.h b/krita/plugins/extensions/pykrita/libkis/mainwindow.h index 6e06a53dc8..ba4e58d49d 100644 --- a/krita/plugins/extensions/pykrita/libkis/mainwindow.h +++ b/krita/plugins/extensions/pykrita/libkis/mainwindow.h @@ -1,44 +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_MAINWINDOW_H #define LIBKIS_MAINWINDOW_H #include #include -class KoMainWindow; +class KisMainWindow; #include class LIBKIS_EXPORT MainWindow : public QObject { Q_OBJECT public: - explicit MainWindow(QObject *mainWin, QObject *parent = 0); + explicit MainWindow(KisMainWindow *mainWin, QObject *parent = 0); - QList views(); signals: public slots: private: - KoMainWindow *m_mainWindow; + KisMainWindow *m_mainWindow; }; #endif // MAINWINDOW_H diff --git a/krita/plugins/extensions/pykrita/libkis/view.cpp b/krita/plugins/extensions/pykrita/libkis/view.cpp index 09ca6999af..22c34cc680 100644 --- a/krita/plugins/extensions/pykrita/libkis/view.cpp +++ b/krita/plugins/extensions/pykrita/libkis/view.cpp @@ -1,26 +1,26 @@ /* * 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 "view.h" -#include +#include -View::View(QObject *view, QObject *parent) +View::View(KisView *view, QObject *parent) : QObject(parent) - , m_view(qobject_cast(view)) + , m_view(view) { } diff --git a/krita/plugins/extensions/pykrita/libkis/view.h b/krita/plugins/extensions/pykrita/libkis/view.h index f2ecdefd07..2d7aaa10b2 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 KisView2; +class KisView; class LIBKIS_EXPORT View : public QObject { Q_OBJECT public: - explicit View(QObject *view, QObject *parent = 0); + explicit View(KisView *view, QObject *parent = 0); signals: public slots: private: - KisView2 *m_view; + KisView *m_view; }; #endif // LIBKIS_VIEW_H diff --git a/krita/plugins/extensions/pykrita/sip/krita/document.sip b/krita/plugins/extensions/pykrita/sip/krita/document.sip index 8a3acc74bf..52b47674d0 100644 --- a/krita/plugins/extensions/pykrita/sip/krita/document.sip +++ b/krita/plugins/extensions/pykrita/sip/krita/document.sip @@ -1,14 +1,13 @@ %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip -class Document : public QObject +class Document : public QObject /NoDefaultCtors/ { %TypeHeaderCode #include "document.h" %End public: - explicit Document(QObject *document, QObject *parent /TransferThis/ = 0); Image *image(); }; diff --git a/krita/plugins/extensions/pykrita/sip/krita/image.sip b/krita/plugins/extensions/pykrita/sip/krita/image.sip index 8789487d8b..a68bcb589f 100644 --- a/krita/plugins/extensions/pykrita/sip/krita/image.sip +++ b/krita/plugins/extensions/pykrita/sip/krita/image.sip @@ -1,13 +1,12 @@ %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip -class Image : public QObject +class Image : public QObject /NoDefaultCtors/ { %TypeHeaderCode #include "image.h" %End public: - explicit Image(QObject *image, QObject *parent /TransferThis/ = 0); }; diff --git a/krita/plugins/extensions/pykrita/sip/krita/mainwindow.sip b/krita/plugins/extensions/pykrita/sip/krita/mainwindow.sip index de0757005c..f729696bad 100644 --- a/krita/plugins/extensions/pykrita/sip/krita/mainwindow.sip +++ b/krita/plugins/extensions/pykrita/sip/krita/mainwindow.sip @@ -1,14 +1,12 @@ %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip -class MainWindow : public QObject +class MainWindow : public QObject /NoDefaultCtors/ { %TypeHeaderCode #include "mainwindow.h" %End public: - MainWindow(QObject *mainWin, QObject *parent /TransferThis/ = 0); - QList views(); }; diff --git a/krita/plugins/extensions/pykrita/sip/krita/view.sip b/krita/plugins/extensions/pykrita/sip/krita/view.sip index b8ddd5754e..961fd4b6fb 100644 --- a/krita/plugins/extensions/pykrita/sip/krita/view.sip +++ b/krita/plugins/extensions/pykrita/sip/krita/view.sip @@ -1,13 +1,13 @@ %Import QtCore/QtCoremod.sip %Import QtGui/QtGuimod.sip -class View : public QObject +class View : public QObject /NoDefaultCtors/ { %TypeHeaderCode #include "view.h" %End public: - explicit View(QObject *view, QObject *parent /TransferThis/ = 0); +// explicit View(QObject *view, QObject *parent /TransferThis/ = 0); }; diff --git a/krita/plugins/extensions/pykrita/src/CMakeLists.txt b/krita/plugins/extensions/pykrita/src/CMakeLists.txt index a1c7b57c18..935bf9c808 100644 --- a/krita/plugins/extensions/pykrita/src/CMakeLists.txt +++ b/krita/plugins/extensions/pykrita/src/CMakeLists.txt @@ -1,42 +1,42 @@ # 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) +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 ) 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/engine.h b/krita/plugins/extensions/pykrita/src/engine.h index 4de0e51e8c..8d981cc1e6 100644 --- a/krita/plugins/extensions/pykrita/src/engine.h +++ b/krita/plugins/extensions/pykrita/src/engine.h @@ -1,197 +1,197 @@ // This file is part of PyKrita, Krita' Python scripting plugin. // // Copyright (C) 2006 Paul Giannaros // Copyright (C) 2012, 2013 Shaheed Haque // Copyright (C) 2013 Alex Turbov // // This library 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.1 of the License, or (at your option) version 3, or any // later version accepted by the membership of KDE e.V. (or its // successor approved by the membership of KDE e.V.), which shall // act as a proxy defined in Section 6 of version 3 of the license. // // This library 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 // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library. If not, see . // #ifndef __PYKRITA_ENGINE_H__ # define __PYKRITA_ENGINE_H__ +# include + # include "version_checker.h" # include # include -# include - # include # include # include namespace PyKrita { class Python; // fwd decl /** * The Engine class hosts the Python interpreter, loading * it into memory within Krita, and then with finding and * loading all of the PyKrita plugins. * * \attention Qt/KDE do not use exceptions (unfortunately), * so this class must be initialized in two steps: * - create an instance (via constructor) * - try to initialize the rest (via \c Engine::tryInitializeGetFailureReason()) * If latter returns a non empty (failure reason) string, the only member * can be called is conversion to boolean! (which is implemented as safe-bool idiom [1]) * Calling others leads to UB! * * \sa [1] http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Safe_bool */ class Engine : public QAbstractItemModel { Q_OBJECT typedef void (Engine::*bool_type)() const; void unspecified_true_bool_type() const {} public: /// \todo Turn into a class w/ accessors class PluginState { public: /// \name Immutable accessors //@{ QString pythonModuleName() const; const QString& errorReason() const; bool isEnabled() const; bool isBroken() const; bool isUnstable() const; //@} private: friend class Engine; PluginState(); /// Transfort Python module name into a file path part QString moduleFilePathPart() const; KService::Ptr m_service; QString m_pythonModule; QString m_errorReason; bool m_enabled; bool m_broken; bool m_unstable; bool m_isDir; }; /// Default constructor: initialize Python interpreter Engine(); /// Cleanup everything on unload ~Engine(); //BEGIN QAbstractItemModel interface virtual int columnCount(const QModelIndex&) const /*override*/; virtual int rowCount(const QModelIndex&) const /*override*/; virtual QModelIndex index(int, int, const QModelIndex&) const /*override*/; virtual QModelIndex parent(const QModelIndex&) const /*override*/; virtual QVariant headerData(int, Qt::Orientation, int) const /*override*/; virtual QVariant data(const QModelIndex&, int) const /*override*/; virtual Qt::ItemFlags flags(const QModelIndex&) const /*override*/; virtual bool setData(const QModelIndex&, const QVariant&, int) /*override*/; //END QAbstractItemModel interface void readSessionPluginsConfiguration(KConfigBase*); void writeSessionPluginsConfiguration(KConfigBase*); void setEnabledPlugins(const QStringList&); ///< Set enabled plugins to the model void tryLoadEnabledPlugins(); ///< Try to load enabled plugins QStringList enabledPlugins() const; ///< Form a list of enabled plugins const QList& plugins() const; ///< Provide immutable access to found plugins QString tryInitializeGetFailureReason(); ///< Try to initialize Python interpreter operator bool_type() const; ///< Check if instance is usable void setBroken(); ///< Make it broken by some external reason public Q_SLOTS: void readGlobalPluginsConfiguration(); ///< Load plugins' configuration. void saveGlobalPluginsConfiguration(); ///< Write out plugins' configuration. void unloadAllModules(); protected: void scanPlugins(); ///< Search for available plugins void loadModule(int); ///< Load module by index in \c m_plugins void unloadModule(int); ///< Unload module by index in \c m_plugins private: // Simulate strong typed enums from C++11 struct Column { enum type { NAME , COMMENT , LAST__ }; }; static bool isServiceUsable(const KService::Ptr&); ///< Make sure that service is usable static bool setModuleProperties(PluginState&); static void verifyDependenciesSetStatus(PluginState&); static QPair parseDependency(const QString&); static version tryObtainVersionFromTuple(PyObject*); static version tryObtainVersionFromString(PyObject*); PyObject* m_configuration; ///< Application-wide configuration data PyObject* m_sessionConfiguration; ///< Session-wide configuration data QList m_plugins; ///< List of available plugins bool m_engineIsUsable; ///< Is engine loaded Ok? }; inline QString Engine::PluginState::pythonModuleName() const { return m_service->library(); } inline QString PyKrita::Engine::PluginState::moduleFilePathPart() const { /// \todo Use \c QString::split() and \c KUrl to form a valid path return m_service->library().replace(".", "/"); } inline const QString& Engine::PluginState::errorReason() const { return m_errorReason; } inline bool Engine::PluginState::isEnabled() const { return m_enabled; } inline bool Engine::PluginState::isBroken() const { return m_broken; } inline bool Engine::PluginState::isUnstable() const { return m_unstable; } inline const QList& Engine::plugins() const { return m_plugins; } inline Engine::operator bool_type() const { return m_engineIsUsable ? &Engine::unspecified_true_bool_type : 0; } inline void Engine::setBroken() { m_engineIsUsable = false; } } // namespace PyKrita #endif // __PYKRITA_ENGINE_H__ // krita: indent-width 4; diff --git a/krita/plugins/extensions/pykrita/src/plugin.cpp b/krita/plugins/extensions/pykrita/src/plugin.cpp index 9aba275010..d5fa2ccded 100644 --- a/krita/plugins/extensions/pykrita/src/plugin.cpp +++ b/krita/plugins/extensions/pykrita/src/plugin.cpp @@ -1,76 +1,75 @@ /* * 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 K_PLUGIN_FACTORY(KritaPyQtPluginFactory, registerPlugin();) K_EXPORT_PLUGIN(KritaPyQtPluginFactory("krita")) KritaPyQtPlugin::KritaPyQtPlugin(QObject *parent, const QVariantList &) - : KisViewPlugin(parent, "kritaplugins/kritapykritaplugin.rc") + : 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(); } } KritaPyQtPlugin::~KritaPyQtPlugin() { } diff --git a/krita/plugins/extensions/pykrita/src/plugin.h b/krita/plugins/extensions/pykrita/src/plugin.h index 8613769f88..080867346f 100644 --- a/krita/plugins/extensions/pykrita/src/plugin.h +++ b/krita/plugins/extensions/pykrita/src/plugin.h @@ -1,40 +1,40 @@ /* * 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; 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. */ #ifndef _PYQT_PLUGIN_H_ #define _PYQT_PLUGIN_H_ -#include - #include +#include + #include #include "engine.h" class KritaPyQtPlugin : public KisViewPlugin { Q_OBJECT public: KritaPyQtPlugin(QObject *parent, const QVariantList &); virtual ~KritaPyQtPlugin(); private: PyKrita::Engine m_engine; QString m_engineFailureReason; bool m_autoReload; }; #endif diff --git a/krita/plugins/extensions/pykrita/src/plugins/CMakeLists.txt b/krita/plugins/extensions/pykrita/src/plugins/CMakeLists.txt index 0b4de3fcfe..84c738d254 100644 --- a/krita/plugins/extensions/pykrita/src/plugins/CMakeLists.txt +++ b/krita/plugins/extensions/pykrita/src/plugins/CMakeLists.txt @@ -1,89 +1,89 @@ # Copyright (C) 2012, 2013 Shaheed Haque # Copyright (C) 2013 Alex Turbov # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. include(CMakeParseArguments) # # Simple helper function to install plugin and related files # having only a name of the plugin... # (just to reduce syntactic noise when a lot of plugins get installed) # function(install_pykrita_plugin name) set(_options) set(_one_value_args) set(_multi_value_args PATTERNS FILE) cmake_parse_arguments(install_pykrita_plugin "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN}) if(NOT name) message(FATAL_ERROR "Plugin filename is not given") endif() if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.py) install(FILES kritapykrita_${name}.desktop DESTINATION ${SERVICES_INSTALL_DIR}/calligra) foreach(_f ${name}.py ${name}.ui ${name}_ui.rc ${install_pykrita_plugin_FILE}) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_f}) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${_f} DESTINATION ${DATA_INSTALL_DIR}/krita/pykrita) endif() endforeach() elseif(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${name}) install(FILES ${name}/kritapykrita_${name}.desktop DESTINATION ${SERVICES_INSTALL_DIR}/calligra) install( DIRECTORY ${name} DESTINATION ${DATA_INSTALL_DIR}/krita/pykrita FILES_MATCHING PATTERN "*.py" PATTERN "*.ui" PATTERN "*_ui.rc" PATTERN "__pycache__*" EXCLUDE ) # TODO Is there any way to form a long PATTERN options string # and use it in a single install() call? # NOTE Install specified patterns one-by-one... foreach(_pattern ${install_pykrita_plugin_PATTERNS}) install( DIRECTORY ${name} DESTINATION ${DATA_INSTALL_DIR}/krita/pykrita FILES_MATCHING PATTERN "${_pattern}" PATTERN "__pycache__*" EXCLUDE ) endforeach() else() message(FATAL_ERROR "Do not know what to do with ${name}") endif() endfunction() install_pykrita_plugin(hello) -if(PYTHON_VERSION_MAJOR VERSION_EQUAL 3) - install_pykrita_plugin(cmake_utils) - install_pykrita_plugin(js_utils PATTERNS "*.json") - install_pykrita_plugin(expand PATTERNS "*.expand" "templates/*.tpl") -endif() +# if(PYTHON_VERSION_MAJOR VERSION_EQUAL 3) +# install_pykrita_plugin(cmake_utils) +# install_pykrita_plugin(js_utils PATTERNS "*.json") +# install_pykrita_plugin(expand PATTERNS "*.expand" "templates/*.tpl") +# endif() install( DIRECTORY libkritapykrita DESTINATION ${DATA_INSTALL_DIR}/krita/pykrita FILES_MATCHING PATTERN "*.py" PATTERN "__pycache__*" EXCLUDE ) diff --git a/krita/plugins/extensions/pykrita/src/pyqtpluginsettings.cpp b/krita/plugins/extensions/pykrita/src/pyqtpluginsettings.cpp index 589b2a4fce..69c49da38c 100644 --- a/krita/plugins/extensions/pykrita/src/pyqtpluginsettings.cpp +++ b/krita/plugins/extensions/pykrita/src/pyqtpluginsettings.cpp @@ -1,90 +1,90 @@ /* * 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; 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 "pyqtpluginsettings.h" #include "ui_manager.h" #include #include #include #include #include #include #include "kis_config.h" PyQtPluginSettings::PyQtPluginSettings(PyKrita::Engine *engine, QWidget *parent) : KisPreferenceSet(parent), m_manager(new Ui::ManagerPage) { m_manager->setupUi(this); QSortFilterProxyModel* const proxy_model = new QSortFilterProxyModel(this); proxy_model->setSourceModel(engine); m_manager->pluginsList->setModel(proxy_model); m_manager->pluginsList->resizeColumnToContents(0); m_manager->pluginsList->sortByColumn(0, Qt::AscendingOrder); const bool is_enabled = bool(engine); const bool is_visible = !is_enabled; m_manager->errorLabel->setVisible(is_visible); m_manager->pluginsList->setEnabled(is_enabled); } PyQtPluginSettings::~PyQtPluginSettings() { delete m_manager; } QString PyQtPluginSettings::id() { return QString("pykritapluginmanager"); } QString PyQtPluginSettings::name() { return header(); } QString PyQtPluginSettings::header() { return QString(i18n("Python Plugin Manager")); } KIcon PyQtPluginSettings::icon() { return koIcon("applications-development"); } void PyQtPluginSettings::savePreferences() const { - emit settingsChanged(); + Q_EMIT(settingsChanged()); } void PyQtPluginSettings::loadPreferences() { } void PyQtPluginSettings::loadDefaultPreferences() { }