""" /*************************************************************************** MnCheck A QGIS plugin Contrôle des données FTTH format MN ------------------- copyright : (C) 2019 by Manche Numérique email : olivier.massot@manchenumerique.fr ***************************************************************************/ """ from core import logging_ import logging from PyQt5.QtCore import Qt from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QAction, QStyle, QApplication from core.constants import MAIN, VERSION from ui.dlg_main import DlgMain __VERSION__ = VERSION logger = logging.getLogger("mncheck") logging_.start("mncheck", logging.DEBUG) logger.info("* loading plugin") logger.info("version: %s", VERSION) class MnCheck: def __init__(self, iface): self.iface = iface self.actions = [] self.menu = '&MnCheck' self.toolbar = self.iface.addToolBar('MnCheck') self.toolbar.setObjectName('MnCheck') self.main_window = None def add_action(self, icon_path, text, callback, enabled_flag=True, add_to_menu=True, add_to_toolbar=True, status_tip=None, whats_this=None, parent=None): icon = QIcon(icon_path) action = QAction(icon, text, parent) action.triggered.connect(callback) action.setEnabled(enabled_flag) if status_tip is not None: action.setStatusTip(status_tip) if whats_this is not None: action.setWhatsThis(whats_this) if add_to_toolbar: self.toolbar.addAction(action) if add_to_menu: self.iface.addPluginToMenu(self.menu, action) self.actions.append(action) return action def initGui(self): """Create the menu entries and toolbar icons inside the QGIS GUI.""" logging_.QgsLogHandler.connect_to_iface(self.iface) self.add_action(MAIN / 'icon.png', text='MnCheck', callback=self.run, parent=self.iface.mainWindow()) def unload(self): """Removes the plugin menu item and icon from QGIS GUI.""" for action in self.actions: self.iface.removePluginMenu('&MnCheck', action) self.iface.removeToolBarIcon(action) del self.toolbar def run(self): """Run method that performs all the real work""" if self.main_window and self.main_window.isVisible(): self.main_window.activateWindow() self.main_window.setGeometry(QStyle.alignedRect(Qt.LeftToRight, Qt.AlignCenter, self.main_window.size(), QApplication.desktop().availableGeometry())) return dlg = DlgMain(self.iface) self.main_window = dlg dlg.show() dlg.exec_()