# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import (QDialog, QTableView,QPlainTextEdit,QVBoxLayout,QHBoxLayout,QSpacerItem,QSizePolicy,QPushButton)
from PyQt5.QtCore import (Qt,QSize )
from PyQt5.QtGui import (QIcon,QPixmap)
from PyQt5 import QtCore
from .outils import XMLWriter, XMLReader
class scr_Souscription_Vie_Longevite(QDialog):
    
    def __init__(self,styleaffiche):
        QDialog.__init__(self)
        self.setWindowModality(  Qt.NonModal)
        self.setWindowFlags(  Qt.Dialog|  Qt.WindowMinimizeButtonHint|  Qt.WindowMaximizeButtonHint |  Qt.WindowCloseButtonHint)
        
        icon =   QIcon()
        icon.addPixmap(  QPixmap(":/Images/Images/scrbuild.png"),   QIcon.Normal,   QIcon.Off)
        self.setWindowIcon(icon)         
        self.verticalLayout =   QVBoxLayout()
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout =   QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.pushButton =   QPushButton()
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout.addWidget(self.pushButton)
        spacerItem =   QSpacerItem(40, 20,   QSizePolicy.Expanding,   QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.pushButton_2 =   QPushButton()
        self.pushButton_2.setObjectName("pushButton_2")
        self.horizontalLayout.addWidget(self.pushButton_2)
        spacerItem =   QSpacerItem(40, 20,   QSizePolicy.Expanding,   QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)        
        ########
        self.plainTextEdit =   QPlainTextEdit(self)
        sizePolicy =   QSizePolicy(  QSizePolicy.Expanding,   QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.plainTextEdit.sizePolicy().hasHeightForWidth())
        self.plainTextEdit.setSizePolicy(sizePolicy)
        self.plainTextEdit.setMaximumSize(  QSize(400, 25))
        self.plainTextEdit.setMinimumSize(  QSize(400, 25))
        self.plainTextEdit.setObjectName("plainTextEdit")
        self.plainTextEdit.setDocumentTitle(QtCore.QCoreApplication.translate ("SCR","SCR Longevité [ Souscription Vie ]"))
        self.plainTextEdit.setToolTip(QtCore.QCoreApplication.translate ("SCR","SCR Longevité [ Souscription Vie ]"))
        self.plainTextEdit.setStyleSheet(styleaffiche)
        #self.plainTextEdit.setTextInteractionFlags(QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse)
        #self.plainTextEdit.setFixedWidth(len(self.plainTextEdit.toPlainText()))
        self.horizontalLayout.addWidget(self.plainTextEdit)        
        
        spacerItem =   QSpacerItem(40, 20,   QSizePolicy.Expanding,   QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)          
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.tableView =   QTableView()
        self.tableView.setObjectName("tableView")
        self.verticalLayout.addWidget(self.tableView)
        self.setLayout(self.verticalLayout)
        self.setWindowTitle(QtCore.QCoreApplication.translate ("SCR","Longevité [ Souscription Vie ]"))
        self.valueData()
    def valueData(self):
        self.nomElement()
        value = XMLReader().read_element(self.nomElement())
        self.plainTextEdit.setPlainText(value)
    def updateValueSCR(self, value):
        self.plainTextEdit.setPlainText(value)
        XMLWriter().modify_data(self, item=self.nomElement(), value=value)
    def nomElement(self):
        return "SVLongevite"           
    def closeEvent(self, event):
        self.accept() je veux toute les composantes pour le calcul du scr souscription vie longevité et dans un style élegant et professionnel