dlg_db_error.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. """
  2. /***************************************************************************
  3. Name : DB Manager
  4. Description : Database manager plugin for QGIS
  5. Date : May 23, 2011
  6. copyright : (C) 2011 by Giuseppe Sucameli
  7. email : brush.tyler@gmail.com
  8. The content of this file is based on
  9. - PG_Manager by Martin Dobias (GPLv2 license)
  10. ***************************************************************************/
  11. /***************************************************************************
  12. * *
  13. * This program is free software; you can redistribute it and/or modify *
  14. * it under the terms of the GNU General Public License as published by *
  15. * the Free Software Foundation; either version 2 of the License, or *
  16. * (at your option) any later version. *
  17. * *
  18. ***************************************************************************/
  19. """
  20. from qgis.PyQt.QtWidgets import QDialog
  21. from .ui.ui_DlgDbError import Ui_DbManagerDlgDbError as Ui_Dialog
  22. from .db_plugins.plugin import DbError
  23. class DlgDbError(QDialog, Ui_Dialog):
  24. def __init__(self, e, parent=None):
  25. QDialog.__init__(self, parent)
  26. self.setupUi(self)
  27. def sanitize(txt):
  28. return "" if txt is None else "<pre>" + txt.replace('<', '&lt;') + "</pre>"
  29. if isinstance(e, DbError):
  30. self.setQueryMessage(sanitize(e.msg), sanitize(e.query))
  31. else:
  32. self.setMessage(sanitize(e.msg))
  33. def setMessage(self, msg):
  34. self.txtErrorMsg.setHtml(msg)
  35. self.stackedWidget.setCurrentIndex(0)
  36. def setQueryMessage(self, msg, query):
  37. self.txtQueryErrorMsg.setHtml(msg)
  38. self.txtQuery.setHtml(query)
  39. self.stackedWidget.setCurrentIndex(1)
  40. @staticmethod
  41. def showError(e, parent=None):
  42. dlg = DlgDbError(e, parent)
  43. dlg.exec_()