File indexing completed on 2024-11-24 03:56:27
0001 /* 0002 * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <memory> 0010 #include "app/scripting/script_engine.hpp" 0011 0012 0013 namespace app::scripting::python { 0014 0015 class PythonContext : public ScriptExecutionContext 0016 { 0017 public: 0018 PythonContext(const ScriptEngine* engine); 0019 ~PythonContext(); 0020 0021 void expose(const QString& name, const QVariant& obj) override; 0022 0023 QString eval_to_string(const QString& code) override; 0024 0025 QStringList eval_completions(const QString& line) override; 0026 0027 bool run_from_module ( 0028 const QDir& path, 0029 const QString& module, 0030 const QString& function, 0031 const QVariantList& args 0032 ) override; 0033 0034 0035 const ScriptEngine* engine() const override; 0036 0037 void app_module(const QString& name) override; 0038 0039 private: 0040 class Private; 0041 0042 std::unique_ptr<Private> d; 0043 }; 0044 0045 class PythonEngine : public ScriptEngine 0046 { 0047 public: 0048 static void add_module_search_paths(const QStringList& paths); 0049 0050 QString slug() const override { return "python"; } 0051 QString label() const override { return "Python"; } 0052 0053 ScriptContext create_context() const override; 0054 0055 private: 0056 static Autoregister<PythonEngine> autoreg; 0057 }; 0058 0059 } // namespace app::scripting::python