main.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. """
  2. /***************************************************************************
  3. MnCheck
  4. A QGIS plugin
  5. Contrôle des données FTTH format MN
  6. -------------------
  7. copyright : (C) 2019 by Manche Numérique
  8. email : olivier.massot@manchenumerique.fr
  9. ***************************************************************************/
  10. """
  11. from core import logging_
  12. import logging
  13. from PyQt5.QtCore import Qt
  14. from PyQt5.QtGui import QIcon
  15. from PyQt5.QtWidgets import QAction, QStyle, QApplication
  16. from core.constants import MAIN, VERSION
  17. from ui.dlg_main import DlgMain
  18. __VERSION__ = VERSION
  19. logger = logging.getLogger("mncheck")
  20. logging_.start("mncheck", logging.DEBUG)
  21. logger.info("* loading plugin")
  22. logger.info("version: %s", VERSION)
  23. class MnCheck:
  24. def __init__(self, iface):
  25. self.iface = iface
  26. self.actions = []
  27. self.menu = '&MnCheck'
  28. self.toolbar = self.iface.addToolBar('MnCheck')
  29. self.toolbar.setObjectName('MnCheck')
  30. self.main_window = None
  31. def add_action(self, icon_path, text, callback, enabled_flag=True, add_to_menu=True,
  32. add_to_toolbar=True, status_tip=None, whats_this=None, parent=None):
  33. icon = QIcon(icon_path)
  34. action = QAction(icon, text, parent)
  35. action.triggered.connect(callback)
  36. action.setEnabled(enabled_flag)
  37. if status_tip is not None:
  38. action.setStatusTip(status_tip)
  39. if whats_this is not None:
  40. action.setWhatsThis(whats_this)
  41. if add_to_toolbar:
  42. self.toolbar.addAction(action)
  43. if add_to_menu:
  44. self.iface.addPluginToMenu(self.menu, action)
  45. self.actions.append(action)
  46. return action
  47. def initGui(self):
  48. """Create the menu entries and toolbar icons inside the QGIS GUI."""
  49. logging_.QgsLogHandler.connect_to_iface(self.iface)
  50. self.add_action(MAIN / 'icon.png',
  51. text='MnCheck',
  52. callback=self.run,
  53. parent=self.iface.mainWindow())
  54. def unload(self):
  55. """Removes the plugin menu item and icon from QGIS GUI."""
  56. for action in self.actions:
  57. self.iface.removePluginMenu('&MnCheck', action)
  58. self.iface.removeToolBarIcon(action)
  59. del self.toolbar
  60. def run(self):
  61. """Run method that performs all the real work"""
  62. if self.main_window and self.main_window.isVisible():
  63. self.main_window.activateWindow()
  64. self.main_window.setGeometry(QStyle.alignedRect(Qt.LeftToRight,
  65. Qt.AlignCenter,
  66. self.main_window.size(),
  67. QApplication.desktop().availableGeometry()))
  68. return
  69. dlg = DlgMain(self.iface)
  70. self.main_window = dlg
  71. dlg.show()
  72. dlg.exec_()