PyQGIS script management plugin that offers an intuitive interface for organizing, monitoring, and executing custom Python scripts within the QGIS environment.
Script Manager transforms the way you work with PyQGIS scripts by providing:
- Visual Script Browser with detailed information and descriptions
- Quick Access Menu for rapid script execution
- Automatic File Monitoring that detects changes and reloads scripts
- Enhanced Security and Error Handling for safe script execution
- Multi-language Support (English, Portuguese)
- Complete Qt5/Qt6 Compatibility for future-proof operation
- Interactive dialog with detailed script information
- Preview descriptions and file locations
- Execute scripts directly from the browser
- Refresh and folder management tools
- Console Output Capture: Displays
print()
statements and error messages from executed scripts - Detailed Error Reporting: Provides clear error messages and traceback for debugging
- Traditional menu structure for fast execution
- Hover tooltips showing script descriptions
- Organized by script categories
- Status bar integration
- Real-time detection of new scripts
- Automatic reloading when files change
- No manual refresh required
- Efficient file system watching
- Script Validation: Performs pre-execution checks to identify potentially risky operations (e.g.,
subprocess.call
,subprocess.run
,subprocess.Popen
,os.system
,eval(
,exec(
,__import__
) - Isolated Execution Environment: Scripts run in a controlled namespace with pre-defined QGIS and PyQt imports to prevent unintended side effects and ensure access to necessary modules
- Crash Prevention: Robust error handling mechanisms prevent script errors from crashing QGIS, providing a stable environment
- Multi-language interface support
- Automatic language detection from QGIS settings
- Currently supports: English (en) and Portuguese Brazil (pt_BR)
- Easy to extend for additional languages by modifying the
Translator
class
- Works seamlessly with both Qt5 and Qt6
- Automatic Qt version detection
- Compatible import handling for various Qt modules (e.g.,
QMessageBox
,QInputDialog
,QFileDialog
,QProgressBar
,QComboBox
,QCheckBox
) - Handles differences in Qt API calls:
Qt.UserRole
vsQt.ItemDataRole.UserRole
dialog.exec_()
vsdialog.exec()
Qt.RichText
vsQt.TextFormat.RichText
QFont.Bold
vsQFont.Weight.Bold
Qt.Horizontal
vsQt.Orientation.Horizontal
- Future-proof architecture
- Open QGIS
- Go to Plugins → Manage and Install Plugins
- Search for "Script Manager"
- Click Install Plugin
- Download the plugin zip file
- Extract to your QGIS plugins directory:
- Windows:
%APPDATA%\QGIS\QGIS3\profiles\default\python\plugins\
- macOS:
~/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins\
- Linux:
~/.local/share/QGIS/QGIS3/profiles/default/python/plugins\
- Windows:
- Restart QGIS
- Enable the plugin in Plugins → Manage and Install Plugins → Installed
After installation, the plugin automatically creates a scripts
folder within the plugin directory and adds an example script to help you get started.
- Access the Script Manager menu in QGIS
- Click "Open Scripts Folder" to open the scripts directory
- Copy your
.py
files into this folder - Scripts are automatically detected and loaded
For best results, format your scripts with proper metadata:
# -*- coding: utf-8 -*-
"""
My Custom Tool
Description: This script performs custom GIS operations
"""
# Qt compatibility imports (recommended)
try:
from PyQt6.QtWidgets import QMessageBox
QT_VERSION = 6
except ImportError:
from PyQt5.QtWidgets import QMessageBox
QT_VERSION = 5
from qgis.core import QgsProject
from qgis.utils import iface
def main():
"""Main script function"""
layers = QgsProject.instance().mapLayers()
message = f"Project has {len(layers)} layers (Qt{QT_VERSION})"
QMessageBox.information(None, "Layer Count", message)
if __name__ == "__main__":
main()
The plugin supports descriptions in multiple languages:
"""
Ferramenta Personalizada
Descrição: Este script realiza operações GIS personalizadas
"""
- Go to Script Manager → Script Browser
- Browse through available scripts in the left panel
- View detailed information in the right panel
- Click Execute Script to run the selected script
- Monitor Output: Check the console output and warnings sections for script execution results
- Navigate to Script Manager → Quick Access
- Hover over script names to see descriptions
- Click any script name to execute immediately
- Reload Scripts: Manually refresh the script list
- Open Scripts Folder: Quick access to the scripts directory
- About: View plugin information and usage instructions
The plugin stores scripts in: [plugin_directory]/scripts/
You can access this location through:
- Script Manager → Open Scripts Folder
- The About dialog shows the exact path
- Scripts are monitored for changes automatically
- New files are detected when added to the folder
- Modified scripts are reloaded immediately
- No configuration required
- QGIS: 3.0 or higher
- Python: 3.6+
- Qt: Version 5.x or 6.x (auto-detected)
- Operating System: Windows, macOS, Linux
The plugin executes scripts within a controlled environment using the SafeScriptExecutor
class, which:
- Captures
stdout
andstderr
to prevent direct console interference - Performs security checks for potentially dangerous imports
- Provides a safe namespace with pre-loaded QGIS and PyQt modules including:
- QGIS Core:
QgsProject
,QgsVectorLayer
,QgsRasterLayer
,QgsFeature
,QgsGeometry
,QgsCoordinateReferenceSystem
,QgsCoordinateTransform
,QgsMessageLog
,QgsUnitTypes
,QgsWkbTypes
,QgsMapLayerProxyModel
,QgsProcessingContext
- QGIS GUI:
QgsMapCanvas
,QgsMapTool
- PyQt Widgets:
QMessageBox
,QInputDialog
,QFileDialog
,QProgressBar
,QComboBox
,QCheckBox
- PyQt Core:
Qt
,QTimer
,QThread
,pyqtSignal
- PyQt GUI:
QIcon
,QPixmap
,QColor
- Standard Libraries:
json
,math
,datetime
,re
- QGIS Core:
The plugin includes a comprehensive QtCompat
class to handle differences between Qt5 and Qt6 APIs, ensuring broad compatibility. This includes adapting methods for:
- User roles (
Qt.UserRole
vsQt.ItemDataRole.UserRole
) - Dialog execution (
dialog.exec_()
vsdialog.exec()
) - Text formats (
Qt.RichText
vsQt.TextFormat.RichText
) - Font weights (
QFont.Bold
vsQFont.Weight.Bold
) - Orientations (
Qt.Horizontal
vsQt.Orientation.Horizontal
)
- Uses
QFileSystemWatcher
for efficient monitoring of the scripts directory - Debounced reloading prevents excessive updates when multiple changes occur rapidly
- Monitors both directory changes and individual file modifications to ensure scripts are always up-to-date
- English (en)
- Portuguese Brazil (pt_BR)
The plugin automatically detects your QGIS interface language from settings and adjusts accordingly. The detection system maps language codes as follows:
pt
→pt_BR
- Other languages fall back to English
To contribute translations:
- Extend the
translations
dictionary in theTranslator
class withinscript_manager.py
- Add your language code and translated strings
- Update the
language_map
in thedetect_qgis_language
method if needed - Submit a pull request
Scripts not appearing in menu:
- Check that files have
.py
extension - Ensure files are in the correct scripts folder
- Try Reload Scripts from the menu
Qt version errors:
- The plugin auto-detects Qt version
- Check QGIS log for Qt compatibility messages
- Most scripts should work with both Qt5 and Qt6
Script execution errors:
- Check the QGIS message log for detailed error information
- Ensure your script has proper imports
- Verify file permissions and encoding (UTF-8 recommended)
- Review Console Output: The Script Browser's output panel will show
print()
statements and error messages from your script, which can help in debugging - Validation Warnings: Pay attention to any warnings about potentially risky operations detected during script validation
Enable debug logging by checking the QGIS message log:
- View → Panels → Log Messages
- Look for "Script Manager" entries
- Set log level to "Info" for detailed output
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with appropriate tests
- Update documentation as needed
- Submit a pull request
git clone https://github.com/TiagoJoseMS/script-manager.git
cd script-manager
# Link to QGIS plugins directory for testing
This plugin is licensed under the GNU General Public License v2.0. See the LICENSE file for details.
Tiago José M. Silva
- Email: [email protected]
- GitHub: @TiagoJoseMS
- QGIS Development Team for the excellent GIS platform
- PyQt/Qt developers for the robust GUI framework
- The QGIS community for feedback and support
- ✅ Script browser with detailed information
- ✅ Quick access menu system
- ✅ Automatic file system monitoring
- ✅ Multi-language support (EN, PT-BR)
- ✅ Complete Qt5/Qt6 compatibility
- ✅ Professional user interface
- ✅ Comprehensive error handling
- ✅ Automatic script reloading
- ✅ Integrated help system
- ✅ Safe script execution environment
- ✅ Console output capture