Skip to content

caprieldeluca/puentes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

puentes

QGIS plugin to run external Python files.


With puentes you can:

  • Write and save pyqgis code where you want, and run into QGIS with one click.

  • Modify the code, save changes and run it again.

  • Print messages to Log Messages Panel.


Usage:

In the Plugins menu, a new Puentes node is created. It has two entries:

  • Configure: select a Python file to run.
  • Run: run the file into QGIS.

Also, a Puentes Toolbar is added with a button to Run the file.

A keyboard shorcut doesn't come pre-assigned, but feel free to configure one for the Run action.

Each time the Run action is executed again, the changes saved in the file to be run will be reflected.

When run a file, a message is displayed in the Puentes tab, inside Log Messages panel.

Print objects to that tab using plog function.


The plog() function:

puentes registers a plog() function to print objects to the Puentes tab of Log Messages panel.

The plog name is sent as a global name to the Python file to be run, so plog() can be called there instead of print().

Once puentes is installed, plog name is also accesible from any other pyqgis code importing the plugin module of puentes package, so you can also do the following anywhere:

from puentes.plugin import plog

plog("Hello world!")

mochila:

If you want to import a personal toolbox of pyqgis modules as a package, in which you can edit files, write new code and run it through puentes plugin, see the mochila project.


notes:

  • The QGIS Log Messages panel does not allow to print angle brackets ('<' and '>') or content between them, so the plog function replaces them with an -arbitrary- choice of characters ('~::' and ':: ~').
  • The plog function is not intended to collapse with the built-in print function, and it is not recommended to bind their names in the file to be run, so print continues to have its normal -for code run in QGIS but outside QGIS Python Console- behavior (i.e., if QGIS is launched from a shell console or terminal emulator, print will send messages there).
  • The path of the file to run is saved in a QGIS setting for the active user profile, in the /plugins/puentes/file_path node. This setting will not be shown in the new (as per QGIS 3.32) settings tree widget.
  • Changes in version 1.1:
    • In the event of an exception, the stack trace is logged from the FrameSummary object with index 1, that is, from runpy.run_path (old behavior: log only last object).
    • The path of file to be run is saved in settings each time a new file is configured to run (old behavior: the setting was saved only on run success).