from __future__ import print_function
from builtins import object
# -*- coding: utf-8 -*-

from PyQt5.QtCore import*
from PyQt5.QtGui import*
from qgis.core import*
from qgis.gui import*
from PyQt5.QtWidgets import *

# initialize Qt resources from file resources.py
from . import resources

from .RUSLE_cover import RUSLE_cover
from .RUSLE_runoff import RUSLE_runoff
from .RUSLE_soil import RUSLE_soil
from .RUSLE_slope import RUSLE_slope
from .RUSLE_practice import RUSLE_practice
from .RUSLE import RUSLE

class RUSLEToolbar(object):
    
    def __init__(self,  iface):
        # save reference to the QGIS interface
        self.iface = iface   
       
    def initGui(self):
        # create action that will start plugin configuration
        self.RUSLE_cover = QAction(QIcon(":/plugins/RUSLE/cover_management.png"), "Parameter C", self.iface.mainWindow())
        self.RUSLE_slope = QAction(QIcon(":/plugins/RUSLE/slope_steepness.png"), "Parameter LS", self.iface.mainWindow())
        self.RUSLE_soil = QAction(QIcon(":/plugins/RUSLE/soil.png"), "Parameter K", self.iface.mainWindow())
        self.RUSLE_practice = QAction(QIcon(":/plugins/RUSLE/support_practice.png"), "Parameter P", self.iface.mainWindow())
        self.RUSLE_runoff = QAction(QIcon(":/plugins/RUSLE/surface_runoff.png"), "Parameter R", self.iface.mainWindow())
        self.RUSLE = QAction(QIcon(":/plugins/RUSLE/RUSLE.png"), "RUSLE", self.iface.mainWindow())
       
        # connect new action to plugin function - when action is triggered
        self.RUSLE_cover.triggered.connect(self.doRUSLE_cover)
        self.RUSLE_slope.triggered.connect(self.doRUSLE_slope)
        self.RUSLE_soil.triggered.connect(self.doRUSLE_soil)
        self.RUSLE_practice.triggered.connect(self.doRUSLE_practice)
        self.RUSLE_runoff.triggered.connect(self.doRUSLE_runoff)
        self.RUSLE.triggered.connect(self.doRUSLE)
        
        # create toolbar
        self.toolbar = self.iface.addToolBar("RUSLEToolbar")
        self.toolbar.setObjectName("RUSLEToolbar")
        self.toolbar.addAction(self.RUSLE_runoff)
        self.toolbar.addAction(self.RUSLE_soil)
        self.toolbar.addAction(self.RUSLE_slope)
        self.toolbar.addAction(self.RUSLE_cover)  
        self.toolbar.addAction(self.RUSLE_practice)
        self.toolbar.addAction(self.RUSLE)
        
        
        # add toolbar button and menu item
        self.iface.addToolBarIcon(self.RUSLE_cover)
        self.iface.addToolBarIcon(self.RUSLE_slope)
        self.iface.addToolBarIcon(self.RUSLE_soil)
        self.iface.addToolBarIcon(self.RUSLE_practice)
        self.iface.addToolBarIcon(self.RUSLE_runoff)
        self.iface.addToolBarIcon(self.RUSLE)
        self.iface.addPluginToMenu("&RUSLEToolbar",  self.RUSLE_cover)
        self.iface.addPluginToMenu("&RUSLEToolbar",  self.RUSLE_slope)
        self.iface.addPluginToMenu("&RUSLEToolbar",  self.RUSLE_soil)
        self.iface.addPluginToMenu("&RUSLEToolbar",  self.RUSLE_practice)
        self.iface.addPluginToMenu("&RUSLEToolbar",  self.RUSLE_runoff)
        self.iface.addPluginToMenu("&RUSLEToolbar",  self.RUSLE)
        
        # connect to signal renderComplete which is emitted when canvas rendering is done
        self.iface.mapCanvas().renderComplete.connect(self.renderTest)
        
    def unload(self):
        # remove the plugin menu item and icon
        self.iface.removePluginMenu("&RUSLEToolbar", self.RUSLE_cover)
        self.iface.removePluginMenu("&RUSLEToolbar", self.RUSLE_slope)
        self.iface.removePluginMenu("&RUSLEToolbar", self.RUSLE_soil)
        self.iface.removePluginMenu("&RUSLEToolbar", self.RUSLE_practice)
        self.iface.removePluginMenu("&RUSLEToolbar", self.RUSLE_runoff)
        self.iface.removePluginMenu("&RUSLEToolbar", self.RUSLE)
        self.iface.removeToolBarIcon(self.RUSLE_cover)
        self.iface.removeToolBarIcon(self.RUSLE_slope)
        self.iface.removeToolBarIcon(self.RUSLE_soil)
        self.iface.removeToolBarIcon(self.RUSLE_practice)
        self.iface.removeToolBarIcon(self.RUSLE_runoff)
        self.iface.removeToolBarIcon(self.RUSLE)
        
        # remove toolbar icon
        del self.toolbar
                        
    def run(self):
        #create and show a configuration dialog or something similar
        print ("RUSLEToolbar: run called!")
        
    def renderTest(self, painter):
        #use painter for drawing to map canvas
        print ("RUSLEToolbar: renderTest called!")
        
    def doRUSLE_cover(self):
        self.dlgRUSLE_cover = RUSLE_cover(self)
        if RUSLE_cover ==0:
            return
        self.dlgRUSLE_cover.show()        
        
    def doRUSLE_runoff(self):
        self.dlgRUSLE_runoff = RUSLE_runoff(self)
        if RUSLE_runoff ==0:
            return
        self.dlgRUSLE_runoff.show()     
        
    def doRUSLE_soil(self):
        self.dlgRUSLE_soil = RUSLE_soil(self)
        if RUSLE_soil ==0:
            return
        self.dlgRUSLE_soil.show()        
        
    def doRUSLE_slope(self):
        self.dlgRUSLE_slope = RUSLE_slope(self)
        if RUSLE_slope ==0:
            return
        self.dlgRUSLE_slope.show()    
        
    def doRUSLE_practice(self):
        self.dlgRUSLE_practice = RUSLE_practice(self)
        if RUSLE_practice ==0:
            return
        self.dlgRUSLE_practice.show()  
        
        
    def doRUSLE(self):
        self.dlgRUSLE = RUSLE(self)
        if RUSLE ==0:
            return
        self.dlgRUSLE.show()      



     
        
