diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/examples.pro | 4 | ||||
-rw-r--r-- | examples/examples_common.py | 8 | ||||
-rw-r--r-- | examples/macroexpander.py (renamed from examples/macroexpander/__init__.py) | 13 | ||||
-rw-r--r-- | examples/projects/__init__.py | 8 | ||||
-rw-r--r-- | examples/projects/view.py | 6 | ||||
-rw-r--r-- | examples/requirerequests/__init__.py | 6 | ||||
-rw-r--r-- | examples/smallmenu/__init__.py | 10 | ||||
-rw-r--r-- | examples/transform/__init__.py | 8 | ||||
-rw-r--r-- | examples/transform/actions.py | 7 | ||||
-rw-r--r-- | examples/transform/ui.py | 4 |
10 files changed, 38 insertions, 36 deletions
diff --git a/examples/examples.pro b/examples/examples.pro index 57b1764..34b5843 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -7,7 +7,6 @@ include(../plugins/pythonextensions/qtcreator.pri) include($$IDE_SOURCE_TREE/qtcreator.pri) inst_examples.files = \ - macroexpander \ projects \ requirerequests \ smallmenu \ @@ -18,7 +17,8 @@ inst_examples.CONFIG += no_default_install directory INSTALLS += inst_examples inst_examplefiles.files = \ - examples_common.py + examples_common.py \ + macroexpander.py inst_examplefiles.path = $$IDE_PLUGIN_PATH/python inst_examplefiles.CONFIG += no_default_install diff --git a/examples/examples_common.py b/examples/examples_common.py index db7f669..0bb93d4 100644 --- a/examples/examples_common.py +++ b/examples/examples_common.py @@ -38,15 +38,15 @@ ## ############################################################################# -from PythonExtension import QtCreator +from QtCreator import Core def ensureExamplesMenu(): menuId = 'PythonExtensions.Examples' - menu = QtCreator.Core.ActionManager.actionContainer(menuId) + menu = Core.ActionManager.actionContainer(menuId) if not menu: - menu = QtCreator.Core.ActionManager.createMenu(menuId) + menu = Core.ActionManager.createMenu(menuId) menu.menu().setTitle("Python Extensions Examples") - toolsMenu = QtCreator.Core.ActionManager.actionContainer("QtCreator.Menu.Tools") + toolsMenu = Core.ActionManager.actionContainer("QtCreator.Menu.Tools") toolsMenu.addMenu(menu) return menu diff --git a/examples/macroexpander/__init__.py b/examples/macroexpander.py index 20e10a3..17c30cc 100644 --- a/examples/macroexpander/__init__.py +++ b/examples/macroexpander.py @@ -45,22 +45,23 @@ import examples_common from PySide2.QtCore import QObject, SIGNAL from PySide2.QtWidgets import QInputDialog, QMessageBox, QAction -from PythonExtension import QtCreator +from QtCreator import Core +from QtCreator import Utils # Register our macro (it can be used as %{Python:exp}) -QtCreator.Utils.MacroExpander().registerPrefix(b"Python", "Evaluate Python expressions.", lambda x: eval(x)) +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(), + text = QInputDialog.getMultiLineText(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) + text = Utils.MacroExpander().expand(text[0]) + QMessageBox.information(Core.ICore.dialogParent(), "Result", text) # Add this to the "Tools" menu action = QAction("Test Macro Expander...") -command = QtCreator.Core.ActionManager.registerAction(action, 'PythonExtensions.Examples.MacroExpander') +command = Core.ActionManager.registerAction(action, 'PythonExtensions.Examples.MacroExpander') QObject.connect(action, SIGNAL('triggered()'), act) examples_common.addExampleItem(command) diff --git a/examples/projects/__init__.py b/examples/projects/__init__.py index c7919fc..a618e5b 100644 --- a/examples/projects/__init__.py +++ b/examples/projects/__init__.py @@ -42,16 +42,16 @@ # project. It also includes a dependency on a plugin # that can be disabled. +from . import view import examples_common -import view -from PythonExtension import QtCreator +from QtCreator import Core from PySide2.QtCore import QObject, SIGNAL from PySide2.QtWidgets import QAction # When importing optional bindings, we can warn the user in case things go south try: - from PythonExtension.QtCreator import ProjectExplorer + from 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") @@ -65,7 +65,7 @@ def showProjectPath(): view.error("Please open a project") action = QAction("Show Project Directory") -command = QtCreator.Core.ActionManager.registerAction(action, 'PythonExtensions.Examples.ShowProjectDirectory') +command = Core.ActionManager.registerAction(action, 'PythonExtensions.Examples.ShowProjectDirectory') QObject.connect(action, SIGNAL('triggered()'), showProjectPath) examples_common.addExampleItem(command) diff --git a/examples/projects/view.py b/examples/projects/view.py index 31dbbe6..df1eeb0 100644 --- a/examples/projects/view.py +++ b/examples/projects/view.py @@ -41,10 +41,10 @@ # This contains all the display logic from PySide2 import QtWidgets -from PythonExtension import QtCreator +from QtCreator import Core def error(text, title="Error"): - QtWidgets.QMessageBox.critical(QtCreator.Core.ICore.instance().dialogParent(), title, text) + QtWidgets.QMessageBox.critical(Core.ICore.instance().dialogParent(), title, text) def show(text, title="Result"): - QtWidgets.QMessageBox.information(QtCreator.Core.ICore.instance().dialogParent(), title, text) + QtWidgets.QMessageBox.information(Core.ICore.instance().dialogParent(), title, text) diff --git a/examples/requirerequests/__init__.py b/examples/requirerequests/__init__.py index acbf9e6..3fb14c7 100644 --- a/examples/requirerequests/__init__.py +++ b/examples/requirerequests/__init__.py @@ -44,7 +44,7 @@ import examples_common -from PythonExtension import QtCreator +from QtCreator import Core from PySide2.QtCore import QObject, SIGNAL from PySide2.QtWidgets import QAction, QMessageBox @@ -52,14 +52,14 @@ import requests def load(url): r = requests.get(url) - box = QMessageBox(QtCreator.Core.ICore.dialogParent()) + box = QMessageBox(Core.ICore.dialogParent()) box.setWindowTitle("Request results") box.setText("The request status is {}".format(r.status_code)) box.setDetailedText(r.text) box.exec_() action = QAction("Load from the web...") -command = QtCreator.Core.ActionManager.registerAction(action, 'PythonExtensions.Examples.LoadFromWeb') +command = Core.ActionManager.registerAction(action, 'PythonExtensions.Examples.LoadFromWeb') QObject.connect(action, SIGNAL('triggered()'), lambda: load("https://www.qt.io/")) examples_common.addExampleItem(command) diff --git a/examples/smallmenu/__init__.py b/examples/smallmenu/__init__.py index 5dcfef9..f26b637 100644 --- a/examples/smallmenu/__init__.py +++ b/examples/smallmenu/__init__.py @@ -41,27 +41,27 @@ # This example illustrates the use of action # containers to create new menus -from actions import hello, goodbye +from .actions import hello, goodbye import examples_common -from PythonExtension import QtCreator +from QtCreator import Core from PySide2.QtCore import QObject, SIGNAL from PySide2.QtWidgets import QAction # Create submenu and add it to examples menu menuId = "PythonExtensions.Examples.SmallMenu" -menu = QtCreator.Core.ActionManager.createMenu(menuId) +menu = Core.ActionManager.createMenu(menuId) menu.menu().setTitle("Small Menu") examplesMenu = examples_common.ensureExamplesMenu() examplesMenu.addMenu(menu) # Add actions to our new menu helloAction = QAction("Say Hello") -command = QtCreator.Core.ActionManager.registerAction(helloAction, 'PythonExtensions.Examples.SayHello') +command = Core.ActionManager.registerAction(helloAction, 'PythonExtensions.Examples.SayHello') QObject.connect(helloAction, SIGNAL('triggered()'), hello) menu.addAction(command) goodbyeAction = QAction("Say Goodbye") -command = QtCreator.Core.ActionManager.registerAction(goodbyeAction, 'PythonExtensions.Examples.SayGoodbye') +command = Core.ActionManager.registerAction(goodbyeAction, 'PythonExtensions.Examples.SayGoodbye') QObject.connect(goodbyeAction, SIGNAL('triggered()'), goodbye) menu.addAction(command) diff --git a/examples/transform/__init__.py b/examples/transform/__init__.py index c58f4e6..f2647dc 100644 --- a/examples/transform/__init__.py +++ b/examples/transform/__init__.py @@ -42,11 +42,11 @@ # user supplied function that executes on # a set of files specified by the user -import actions +from . import actions +from . import ui import examples_common -import ui -from PythonExtension import QtCreator +from QtCreator import Core from PySide2.QtCore import QObject, SIGNAL from PySide2.QtWidgets import QAction @@ -56,7 +56,7 @@ def transform(): actions.run(code[0]) action = QAction("Transform files...") -command = QtCreator.Core.ActionManager.registerAction(action, 'PythonExtensions.Examples.TransformFiles') +command = Core.ActionManager.registerAction(action, 'PythonExtensions.Examples.TransformFiles') QObject.connect(action, SIGNAL('triggered()'), transform) examples_common.addExampleItem(command) diff --git a/examples/transform/actions.py b/examples/transform/actions.py index de54d94..e459ab2 100644 --- a/examples/transform/actions.py +++ b/examples/transform/actions.py @@ -38,13 +38,14 @@ ## ############################################################################# -from PythonExtension import QtCreator -import ui +from . import ui + +from QtCreator import Core # Apply a function to each file def run(code): try: - files = QtCreator.Core.DocumentManager.getOpenFileNames("") + files = Core.DocumentManager.getOpenFileNames("") if len(files) == 0: ui.error("No files were selected.") return diff --git a/examples/transform/ui.py b/examples/transform/ui.py index 21892ef..cc5b7f1 100644 --- a/examples/transform/ui.py +++ b/examples/transform/ui.py @@ -38,7 +38,7 @@ ## ############################################################################# -from PythonExtension import QtCreator +from QtCreator import Core from PySide2 import QtWidgets template = """# Parameters: @@ -53,7 +53,7 @@ filebody def getCode(): return QtWidgets.QInputDialog.getMultiLineText( - QtCreator.Core.ICore.dialogParent(), + Core.ICore.dialogParent(), "Input transformation expression", "Transform expression:", template |