2013-09-12 20:07:00 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
2014-07-14 14:19:09 +02:00
|
|
|
MessageBarProgress.py
|
2013-09-12 20:07:00 +02:00
|
|
|
---------------------
|
|
|
|
Date : April 2013
|
|
|
|
Copyright : (C) 2013 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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
2015-09-29 17:50:53 +02:00
|
|
|
|
2013-09-12 20:07:00 +02:00
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'April 2013'
|
|
|
|
__copyright__ = '(C) 2013, Victor Olaya'
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-09-12 20:07:00 +02:00
|
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
2013-10-01 20:52:22 +03:00
|
|
|
|
2013-09-12 20:07:00 +02:00
|
|
|
__revision__ = '$Format:%H$'
|
|
|
|
|
2016-04-22 10:38:48 +02:00
|
|
|
from qgis.PyQt.QtCore import Qt, QCoreApplication
|
|
|
|
from qgis.PyQt.QtWidgets import QProgressBar
|
2014-05-20 16:30:59 +02:00
|
|
|
from qgis.utils import iface
|
2015-09-29 17:50:53 +02:00
|
|
|
from processing.gui.MessageDialog import MessageDialog
|
2013-09-12 20:07:00 +02:00
|
|
|
|
2015-10-02 21:06:19 +02:00
|
|
|
|
2013-10-01 20:52:22 +03:00
|
|
|
class MessageBarProgress:
|
2013-09-17 12:33:57 +02:00
|
|
|
|
2015-06-08 18:27:51 +02:00
|
|
|
def __init__(self, algname=None):
|
2015-09-29 17:50:53 +02:00
|
|
|
self.msg = []
|
2013-10-01 20:52:22 +03:00
|
|
|
self.progressMessageBar = \
|
2015-06-08 18:27:51 +02:00
|
|
|
iface.messageBar().createMessage(self.tr('Executing algorithm <i>{0}</i>'.format(algname if algname else '')))
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
self.progress = QProgressBar()
|
2013-09-12 20:07:00 +02:00
|
|
|
self.progress.setMaximum(100)
|
2013-10-01 20:52:22 +03:00
|
|
|
self.progress.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
2013-09-17 12:33:57 +02:00
|
|
|
self.progressMessageBar.layout().addWidget(self.progress)
|
2014-05-20 16:30:59 +02:00
|
|
|
iface.messageBar().pushWidget(self.progressMessageBar,
|
|
|
|
iface.messageBar().INFO)
|
2013-09-12 20:07:00 +02:00
|
|
|
|
2013-10-07 18:40:37 +02:00
|
|
|
def error(self, msg):
|
2015-09-29 17:50:53 +02:00
|
|
|
self.msg.append(msg)
|
|
|
|
|
2013-09-12 20:07:00 +02:00
|
|
|
def setText(self, text):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setPercentage(self, i):
|
|
|
|
self.progress.setValue(i)
|
|
|
|
|
|
|
|
def setInfo(self, _):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setCommand(self, _):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setDebugInfo(self, _):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setConsoleInfo(self, _):
|
|
|
|
pass
|
2013-09-17 12:33:57 +02:00
|
|
|
|
2013-09-12 20:07:00 +02:00
|
|
|
def close(self):
|
2015-09-29 17:50:53 +02:00
|
|
|
if self.msg:
|
|
|
|
dlg = MessageDialog()
|
|
|
|
dlg.setTitle(QCoreApplication.translate('MessageBarProgress', 'Problem executing algorithm'))
|
|
|
|
dlg.setMessage("<br>".join(self.msg))
|
|
|
|
dlg.exec_()
|
2014-05-20 16:30:59 +02:00
|
|
|
iface.messageBar().clearWidgets()
|
2014-10-03 14:44:01 +03:00
|
|
|
|
|
|
|
def tr(self, string, context=''):
|
|
|
|
if context == '':
|
|
|
|
context = 'MessageBarProgress'
|
|
|
|
return QCoreApplication.translate(context, string)
|