main.py 3.3 KB

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