aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/README.md17
-rw-r--r--examples/macroexpander/main.py61
-rw-r--r--examples/numpysetup/main.py60
-rw-r--r--examples/numpysetup/setup.py62
-rw-r--r--examples/package.py64
-rw-r--r--examples/projects/main.py63
-rw-r--r--examples/projects/view.py50
-rw-r--r--examples/requirerequests/main.py58
-rw-r--r--examples/requirerequests/requirements.txt5
-rw-r--r--examples/smallmenu/actions.py54
-rw-r--r--examples/smallmenu/main.py56
-rw-r--r--examples/transform/actions.py61
-rw-r--r--examples/transform/main.py55
-rw-r--r--examples/transform/ui.py72
14 files changed, 738 insertions, 0 deletions
diff --git a/examples/README.md b/examples/README.md
new file mode 100644
index 0000000..f94ef22
--- /dev/null
+++ b/examples/README.md
@@ -0,0 +1,17 @@
+# Python Extension Examples
+
+This directory contains examples of what Python extensions might look like. Each extension is in its
+own directory, where you can inspect its source code.
+
+
+## How to install
+If you want to install some of these extensions to play around with them, you can use the
+`package.py` utility. Run `$ python package.py` in your terminal, to generate extension packages
+(.zip files) of all the extensions in this directory. The generated extension packages can then be
+installed into your QtCreator using the extension manager that comes with the plugin. (Find the
+extension manager in the help menu of your QtCreator.)
+
+To clean this directory from generated packages, simply run `$ python package.py clean` in your
+terminal. Note that for your own Python extensions, it is sufficient to distribute .zip
+files, which you can easily generate manually. **Remember to include a top-level directory** when
+making your own extension packages.
diff --git a/examples/macroexpander/main.py b/examples/macroexpander/main.py
new file mode 100644
index 0000000..bd64028
--- /dev/null
+++ b/examples/macroexpander/main.py
@@ -0,0 +1,61 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# This example demonstrates how to use the macro expander
+# API to register a macro that can evaluate Python expressions
+
+from PySide2.QtWidgets import QInputDialog, QMessageBox
+from PythonExtension import QtCreator
+
+# Register our macro (it can be used as %{Python:exp})
+QtCreator.Utils.MacroExpander().registerPrefix(b"Python", "Evaluate Python expressions.", lambda x: eval(x))
+
+# Add a small menu item, that let's us test the macro
+def act():
+ text = QInputDialog.getMultiLineText(QtCreator.Core.ICore.dialogParent(),
+ "Input Text", "Input your text, including some macros",
+ "3 + 3 = %{Python:3+3}"
+ )
+ text = QtCreator.Utils.MacroExpander().expand(text[0])
+ QMessageBox.information(QtCreator.Core.ICore.dialogParent(), "Result", text)
+
+# Add this to the "Tools" menu
+menu = QtCreator.Core.ActionManager.actionContainer("QtCreator.Menu.Tools")
+menu.menu().addAction("Test MacroExpander...", act)
diff --git a/examples/numpysetup/main.py b/examples/numpysetup/main.py
new file mode 100644
index 0000000..cf67157
--- /dev/null
+++ b/examples/numpysetup/main.py
@@ -0,0 +1,60 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# This example illustrates the use of external
+# Python modules
+
+import numpy as np
+from PythonExtension import QtCreator
+from PySide2.QtWidgets import QMessageBox
+
+def dotProduct():
+ a = np.array([1,2,3], float)
+ b = np.array([4,5,6], float)
+ return np.dot(a, b)
+
+def show():
+ box = QMessageBox()
+ box.setText("[1,2,3] * [4,5,6] = {}".format(dotProduct()))
+ box.exec_()
+
+# Add this to the "Window" menu
+menu = QtCreator.Core.ActionManager.actionContainer("QtCreator.Menu.Window")
+menu.menu().addAction("Show dot product", show)
diff --git a/examples/numpysetup/setup.py b/examples/numpysetup/setup.py
new file mode 100644
index 0000000..901bbe4
--- /dev/null
+++ b/examples/numpysetup/setup.py
@@ -0,0 +1,62 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# Setup script that installs required modules.
+# If you simply want to make sure a Python
+# module is installed, you can use this script
+# directly.
+# The modules are installed locally for QtCreator
+# and are not accessible from the system Python.
+
+import importlib, subprocess, sys
+from PythonExtension import PluginInstance as instance
+
+def setup(modules=None):
+ def install(module):
+ cmd = "{0} -m pip install -I -t {1} {2}".format(sys.executable, instance.pythonPackagePath(), module)
+ subprocess.call(cmd.split())
+ for module in modules:
+ try:
+ importlib.import_module(module)
+ except ImportError:
+ install(module)
+
+if __name__ == "__main__":
+ setup(["numpy"])
diff --git a/examples/package.py b/examples/package.py
new file mode 100644
index 0000000..08f6077
--- /dev/null
+++ b/examples/package.py
@@ -0,0 +1,64 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# This script is just here for convenience. If you are writing
+# your own extension, manually creating a zip archive is sufficient.
+
+# Usage: $ python package.py
+# (pass argument 'clean' to remove generated package.zip files)
+
+import os, sys, shutil
+
+def package():
+ for entry in os.scandir("./"):
+ if entry.is_dir():
+ shutil.make_archive(entry.path.split("/")[-1], "zip", "./", entry.path)
+
+def clean():
+ for entry in os.scandir("./"):
+ if entry.is_file() and entry.name.split(".")[-1] == "zip":
+ os.remove(entry.path)
+
+
+if __name__ == "__main__":
+ if "clean" in sys.argv:
+ clean()
+ else:
+ package()
diff --git a/examples/projects/main.py b/examples/projects/main.py
new file mode 100644
index 0000000..daac366
--- /dev/null
+++ b/examples/projects/main.py
@@ -0,0 +1,63 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# This example demonstrates how to work with the current
+# project. It also includes a dependency on a plugin
+# that can be disabled.
+
+import sys, view
+
+# When importing optional bindings, we can warn the user in case things go south
+try:
+ from PythonExtension.QtCreator import ProjectExplorer
+except ImportError:
+ view.error("The extension \"projects\" could not be loaded, since it depends on a disabled plugin.")
+ raise Exception("Dependencies missing")
+
+# Now we can assume, that ProjectExplorer was imported
+def showProjectPath():
+ current_project = ProjectExplorer.ProjectTree.instance().currentProject()
+ if current_project:
+ view.show(current_project.projectDirectory().toString())
+ else:
+ view.error("Please open a project")
+
+helpMenu = QtCreator.Core.ActionManager.actionContainer("QtCreator.Menu.Window")
+helpMenu.menu().addAction("Show Project Directory", showProjectPath)
diff --git a/examples/projects/view.py b/examples/projects/view.py
new file mode 100644
index 0000000..9052d1f
--- /dev/null
+++ b/examples/projects/view.py
@@ -0,0 +1,50 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# This contains all the display logic
+
+from PySide2 import QtWidgets
+from PythonExtension import QtCreator
+
+def error(text, title="Error"):
+ QtWidgets.QMessageBox.critical(QtCreator.Core.ICore.instance().dialogParent(), title, text)
+
+def show(text, title="Result"):
+ QtWidgets.QMessageBox.information(QtCreator.Core.ICore.instance().dialogParent(), title, text)
diff --git a/examples/requirerequests/main.py b/examples/requirerequests/main.py
new file mode 100644
index 0000000..9ca4ee9
--- /dev/null
+++ b/examples/requirerequests/main.py
@@ -0,0 +1,58 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# This is intended to illustrate the
+# use of requirements.txt files in
+# extensions.
+
+import requests
+from PythonExtension import QtCreator
+from PySide2 import QtWidgets
+
+def load(url):
+ r = requests.get(url)
+ box = QtWidgets.QMessageBox(QtCreator.Core.ICore.dialogParent())
+ box.setWindowTitle("Request results")
+ box.setText("The request status is {}".format(r.status_code))
+ box.setDetailedText(r.text)
+ box.exec_()
+
+helpMenu = QtCreator.Core.ActionManager.actionContainer("QtCreator.Menu.Window")
+helpMenu.menu().addAction("Load from the web...", lambda: load("https://www.qt.io/"))
diff --git a/examples/requirerequests/requirements.txt b/examples/requirerequests/requirements.txt
new file mode 100644
index 0000000..eaae000
--- /dev/null
+++ b/examples/requirerequests/requirements.txt
@@ -0,0 +1,5 @@
+# This illustrates that requirement.txt files
+# can be used instead of a setup.py, for simply
+# installing missing packages
+
+requests
diff --git a/examples/smallmenu/actions.py b/examples/smallmenu/actions.py
new file mode 100644
index 0000000..6a9815b
--- /dev/null
+++ b/examples/smallmenu/actions.py
@@ -0,0 +1,54 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# Menu actions
+
+from PySide2.QtWidgets import QMessageBox
+
+def hello():
+ msg("Hello there")
+
+def goodbye():
+ msg("Goodbye for now")
+
+def msg(text):
+ box = QMessageBox()
+ box.setText(text)
+ box.exec_()
diff --git a/examples/smallmenu/main.py b/examples/smallmenu/main.py
new file mode 100644
index 0000000..b2753c1
--- /dev/null
+++ b/examples/smallmenu/main.py
@@ -0,0 +1,56 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# This example illustrates the use of action
+# containers to create new menus
+
+from PythonExtension import QtCreator
+from actions import hello, goodbye
+
+# By convention, the menuId starts with "Python"
+menuId = "Python.SmallMenu.Menu"
+
+menu = QtCreator.Core.ActionManager.createMenu(menuId)
+menu.menu().setTitle("Small menu")
+menu.menu().addAction("Say hello", hello)
+menu.menu().addAction("Say goodbye", goodbye)
+
+# Add our new menu to the "Tools" menu in QtCreator
+QtCreator.Core.ActionManager.actionContainer("QtCreator.Menu.Tools").addMenu(menu)
diff --git a/examples/transform/actions.py b/examples/transform/actions.py
new file mode 100644
index 0000000..a74bb0b
--- /dev/null
+++ b/examples/transform/actions.py
@@ -0,0 +1,61 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+from PythonExtension import QtCreator
+import ui
+
+# Apply a function to each file
+def run(code):
+ try:
+ files = QtCreator.Core.DocumentManager.getOpenFileNames("")
+ if len(files) == 0:
+ ui.error("No files were selected.")
+ return
+ for filename in files:
+ s = open(filename, "r")
+ filebody = s.read()
+ s.close()
+ filebody = eval(code)
+ s = open(filename, "w")
+ s.write(filebody)
+ s.close()
+ ui.success()
+ except Exception as e:
+ ui.error(str(e))
diff --git a/examples/transform/main.py b/examples/transform/main.py
new file mode 100644
index 0000000..b0d47f1
--- /dev/null
+++ b/examples/transform/main.py
@@ -0,0 +1,55 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+# This example extension allows you to run a
+# user supplied function that executes on
+# a set of files specified by the user
+
+from PythonExtension import QtCreator
+import actions, ui
+
+def transform():
+ code = ui.getCode()
+ if code[1]:
+ actions.run(code[0])
+
+# Add our new action to the "Tools" menu
+menu = QtCreator.Core.ActionManager.actionContainer("QtCreator.Menu.Tools")
+menu.menu().addAction("Transform files...", transform)
diff --git a/examples/transform/ui.py b/examples/transform/ui.py
new file mode 100644
index 0000000..441fa69
--- /dev/null
+++ b/examples/transform/ui.py
@@ -0,0 +1,72 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: http://www.qt.io/licensing/
+##
+## This file is part of the Python Extensions Plugin for QtCreator.
+##
+## $QT_BEGIN_LICENSE:BSD$
+## You may use this file under the terms of the BSD license as follows:
+##
+## "Redistribution and use in source and binary forms, with or without
+## modification, are permitted provided that the following conditions are
+## met:
+## * Redistributions of source code must retain the above copyright
+## notice, this list of conditions and the following disclaimer.
+## * 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.
+## * Neither the name of The Qt Company Ltd nor the names of its
+## contributors may be used to endorse or promote products derived
+## from this software without specific prior written permission.
+##
+##
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+## "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 COPYRIGHT
+## OWNER OR CONTRIBUTORS 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."
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+from PythonExtension import QtCreator
+from PySide2 import QtWidgets
+
+template = """# Parameters:
+# filename (string)
+# filebody (string)
+# Writing:
+# Your expression is evaluated, the
+# result is written to the file.
+
+filebody
+"""
+
+def getCode():
+ return QtWidgets.QInputDialog.getMultiLineText(
+ QtCreator.Core.ICore.dialogParent(),
+ "Input transformation expression",
+ "Transform expression:",
+ template
+ )
+
+def success():
+ box = QtWidgets.QMessageBox()
+ box.setText("Success!")
+ box.exec_()
+
+def error(log = ""):
+ box = QtWidgets.QMessageBox()
+ box.setText("There was a problem running your script.")
+ if log != "":
+ box.setDetailedText(log)
+ box.exec_()