main.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. import logging
  12. from PyQt5.QtGui import QIcon
  13. from PyQt5.QtWidgets import QAction
  14. from core import logging_
  15. from core.constants import MAIN,VERSION
  16. from ui.dlg_main import DlgMain
  17. __VERSION__ = VERSION
  18. logger = logging.getLogger("mncheck")
  19. logging_.start("mncheck", logging.DEBUG)
  20. logger.info("* loading plugin")
  21. logger.info(f"version: {VERSION}")
  22. class MnCheck:
  23. def __init__(self, iface):
  24. self.iface = iface
  25. self.actions = []
  26. self.menu = '&MnCheck'
  27. self.toolbar = self.iface.addToolBar('MnCheck')
  28. self.toolbar.setObjectName('MnCheck')
  29. def add_action(self, icon_path, text, callback, enabled_flag=True, add_to_menu=True,
  30. add_to_toolbar=True, status_tip=None, whats_this=None, parent=None):
  31. icon = QIcon(icon_path)
  32. action = QAction(icon, text, parent)
  33. action.triggered.connect(callback)
  34. action.setEnabled(enabled_flag)
  35. if status_tip is not None:
  36. action.setStatusTip(status_tip)
  37. if whats_this is not None:
  38. action.setWhatsThis(whats_this)
  39. if add_to_toolbar:
  40. self.toolbar.addAction(action)
  41. if add_to_menu:
  42. self.iface.addPluginToMenu(self.menu, action)
  43. self.actions.append(action)
  44. return action
  45. def initGui(self):
  46. """Create the menu entries and toolbar icons inside the QGIS GUI."""
  47. logging_.QgsLogHandler.connect_to_iface(self.iface)
  48. self.add_action(MAIN / 'icon.png',
  49. text='MnCheck',
  50. callback=self.run,
  51. parent=self.iface.mainWindow())
  52. def unload(self):
  53. """Removes the plugin menu item and icon from QGIS GUI."""
  54. for action in self.actions:
  55. self.iface.removePluginMenu('&MnCheck', action)
  56. self.iface.removeToolBarIcon(action)
  57. del self.toolbar
  58. def run(self):
  59. """Run method that performs all the real work"""
  60. dlg = DlgMain(self.iface)
  61. dlg.show()
  62. dlg.exec_()