# -*- coding: utf-8 -*-
# Python 3

from pathlib import Path

from qgis.core import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *

from . import doDlgBox1, doAbout


class MainPlugin(object):

    def __init__(self, iface):
        self.name = "Recherche Commune"
        self.iface = iface

    def initGui(self):
        menuIcon = resolve("RechercheCommuneIco.jpg")
        self.commande1 = QAction(QIcon(menuIcon), "Recherche Commune", self.iface.mainWindow())

        menuIcon1 = resolve("about.png")
        self.about = QAction(QIcon(menuIcon1), "A propos ...", self.iface.mainWindow())

        self.commande1.triggered.connect(self.LoadDlgBoxQt1)
        self.about.triggered.connect(self.doInfo)

        self.iface.addToolBarIcon(self.commande1)
        self.iface.addPluginToMenu("Recherche Commune", self.commande1)

    def unload(self):
        self.iface.removePluginMenu("Recherche Commune", self.commande1)
        self.iface.removeToolBarIcon(self.commande1)

    def LoadDlgBoxQt1(self):
        d = doDlgBox1.Dialog()
        d.exec()

    def doInfo(self):
        d = doAbout.Dialog()
        d.exec()


def resolve(name, basepath=None):
    basepath = Path(basepath) if basepath else Path(__file__).resolve().parent
    return str(basepath / name)