1# -*- coding: utf-8 -*-
2
3"""
4***************************************************************************
5    MessageDialog.py
6    ---------------------
7    Date                 : October 2014
8    Copyright            : (C) 2014 by Alexander Bruy
9    Email                : alexander dot bruy at gmail dot com
10***************************************************************************
11*                                                                         *
12*   This program is free software; you can redistribute it and/or modify  *
13*   it under the terms of the GNU General Public License as published by  *
14*   the Free Software Foundation; either version 2 of the License, or     *
15*   (at your option) any later version.                                   *
16*                                                                         *
17***************************************************************************
18"""
19
20__author__ = 'Alexander Bruy'
21__date__ = 'October 2014'
22__copyright__ = '(C) 2014, Alexander Bruy'
23
24import os
25import warnings
26
27from qgis.PyQt import uic
28from qgis.PyQt.QtGui import QDesktopServices
29from qgis.PyQt.QtWidgets import QDockWidget
30
31from qgis.utils import iface
32
33pluginPath = os.path.split(os.path.dirname(__file__))[0]
34with warnings.catch_warnings():
35    warnings.filterwarnings("ignore", category=DeprecationWarning)
36    WIDGET, BASE = uic.loadUiType(
37        os.path.join(pluginPath, 'ui', 'DlgMessage.ui'))
38
39
40class MessageDialog(BASE, WIDGET):
41
42    def __init__(self):
43        super(MessageDialog, self).__init__(None)
44        self.setupUi(self)
45
46        self.txtMessage.anchorClicked.connect(self.openLink)
47
48    def setTitle(self, title):
49        self.setWindowTitle(title)
50
51    def setMessage(self, message):
52        self.txtMessage.setHtml(message)
53
54    def openLink(self, url):
55        if url.toString() == "log":
56            self.close()
57            logDock = iface.mainWindow().findChild(QDockWidget, 'MessageLog')
58            logDock.show()
59        else:
60            QDesktopServices.openUrl(url)
61