main.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. """
  3. /***************************************************************************
  4. MnCheck
  5. A QGIS plugin
  6. Contrôle des données FTTH format MN
  7. Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
  8. -------------------
  9. begin : 2018-12-07
  10. git sha : $Format:%H$
  11. copyright : (C) 2018 by Manche Numérique 2019
  12. email : olivier.massot@manchenumerique.fr
  13. ***************************************************************************/
  14. /***************************************************************************
  15. * *
  16. * This program is free software; you can redistribute it and/or modify *
  17. * it under the terms of the GNU General Public License as published by *
  18. * the Free Software Foundation; either version 2 of the License, or *
  19. * (at your option) any later version. *
  20. * *
  21. ***************************************************************************/
  22. """
  23. import logging
  24. from PyQt5.QtGui import QIcon
  25. from PyQt5.QtWidgets import QAction
  26. from core import logconf
  27. from core.constants import MAIN
  28. from ui.dlg_main import DlgMain
  29. __VERSION__ = "0.1.0"
  30. logger = logging.getLogger("mncheck")
  31. logconf.start("mncheck", logging.DEBUG)
  32. class MnCheck:
  33. def __init__(self, iface):
  34. self.iface = iface
  35. self.actions = []
  36. self.menu = '&MnCheck'
  37. self.toolbar = self.iface.addToolBar('MnCheck')
  38. self.toolbar.setObjectName('MnCheck')
  39. def add_action(self, icon_path, text, callback, enabled_flag=True, add_to_menu=True,
  40. add_to_toolbar=True, status_tip=None, whats_this=None, parent=None):
  41. icon = QIcon(icon_path)
  42. action = QAction(icon, text, parent)
  43. action.triggered.connect(callback)
  44. action.setEnabled(enabled_flag)
  45. if status_tip is not None:
  46. action.setStatusTip(status_tip)
  47. if whats_this is not None:
  48. action.setWhatsThis(whats_this)
  49. if add_to_toolbar:
  50. self.toolbar.addAction(action)
  51. if add_to_menu:
  52. self.iface.addPluginToMenu(self.menu, action)
  53. self.actions.append(action)
  54. return action
  55. def initGui(self):
  56. """Create the menu entries and toolbar icons inside the QGIS GUI."""
  57. self.add_action(MAIN / 'icon.png',
  58. text='MnCheck',
  59. callback=self.run,
  60. parent=self.iface.mainWindow())
  61. def unload(self):
  62. """Removes the plugin menu item and icon from QGIS GUI."""
  63. for action in self.actions:
  64. self.iface.removePluginMenu('&MnCheck', action)
  65. self.iface.removeToolBarIcon(action)
  66. del self.toolbar
  67. def run(self):
  68. """Run method that performs all the real work"""
  69. dlg = DlgMain(self.iface)
  70. dlg.show()
  71. dlg.exec_()