# -*- coding: utf-8 -*- """ *************************************************************************** utils.py --------------------- Date : September 2015 Copyright : (C) 2015 by Victor Olaya Email : volayaf at gmail dot com *************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * *************************************************************************** """ __author__ = 'Victor Olaya' __date__ = 'September 2015' __copyright__ = '(C) 2015, Victor Olaya' # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' from qgis.utils import iface from PyQt4 import QtGui from processing.core.Processing import Processing from processing.gui.MessageDialog import MessageDialog from processing.gui.AlgorithmDialog import AlgorithmDialog algorithmsToolbar = None def addAlgorithmEntry(algname, menuName, submenuName, actionText=None, icon=None, addButton=False): alg = Processing.getAlgorithm(algname) if alg is None: return if menuName: menu = getMenu(menuName, iface.mainWindow().menuBar()) submenu = getMenu(submenuName, menu) action = QtGui.QAction(icon or alg.getIcon(), actionText or alg.name, iface.mainWindow()) action.triggered.connect(lambda: _executeAlgorithm(alg)) submenu.addAction(action) if addButton: global algorithmsToolbar if algorithmsToolbar is None: algorithmsToolbar = iface.addToolBar("ProcessingAlgorithms") algorithmsToolbar.addAction(action) def _executeAlgorithm(alg): message = alg.checkBeforeOpeningParametersDialog() if message: dlg = MessageDialog() dlg.setTitle(tr('Missing dependency')) dlg.setMessage( tr('