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