# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'py2.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(771, 551)
        self.horizontalLayoutWidget = QtWidgets.QWidget(Form)
        self.horizontalLayoutWidget.setGeometry(QtCore.QRect(20, 60, 828, 61))
        self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
        self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label = QtWidgets.QLabel(self.horizontalLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
        self.label.setSizePolicy(sizePolicy)
        self.label.setObjectName("label")
        self.horizontalLayout.addWidget(self.label)
        self.lineEdit = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lineEdit.sizePolicy().hasHeightForWidth())
        self.lineEdit.setSizePolicy(sizePolicy)
        self.lineEdit.setObjectName("lineEdit")
        self.horizontalLayout.addWidget(self.lineEdit)
        self.label_4 = QtWidgets.QLabel(self.horizontalLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_4.sizePolicy().hasHeightForWidth())
        self.label_4.setSizePolicy(sizePolicy)
        self.label_4.setObjectName("label_4")
        self.horizontalLayout.addWidget(self.label_4)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lineEdit_2.sizePolicy().hasHeightForWidth())
        self.lineEdit_2.setSizePolicy(sizePolicy)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.horizontalLayout.addWidget(self.lineEdit_2)
        self.label_3 = QtWidgets.QLabel(self.horizontalLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_3.sizePolicy().hasHeightForWidth())
        self.label_3.setSizePolicy(sizePolicy)
        self.label_3.setObjectName("label_3")
        self.horizontalLayout.addWidget(self.label_3)
        self.lineEdit_3 = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lineEdit_3.sizePolicy().hasHeightForWidth())
        self.lineEdit_3.setSizePolicy(sizePolicy)
        self.lineEdit_3.setObjectName("lineEdit_3")
        self.horizontalLayout.addWidget(self.lineEdit_3)
        self.label_2 = QtWidgets.QLabel(self.horizontalLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
        self.label_2.setSizePolicy(sizePolicy)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout.addWidget(self.label_2)
        self.lineEdit_4 = QtWidgets.QLineEdit(self.horizontalLayoutWidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lineEdit_4.sizePolicy().hasHeightForWidth())
        self.lineEdit_4.setSizePolicy(sizePolicy)
        self.lineEdit_4.setObjectName("lineEdit_4")
        self.horizontalLayout.addWidget(self.lineEdit_4)
        self.label_5 = QtWidgets.QLabel(Form)
        self.label_5.setGeometry(QtCore.QRect(20, 40, 101, 16))
        self.label_5.setObjectName("label_5")
        self.comboBox = QtWidgets.QComboBox(Form)
        self.comboBox.setGeometry(QtCore.QRect(20, 10, 111, 22))
        self.comboBox.setEditable(True)
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.radioButton = QtWidgets.QRadioButton(Form)
        self.radioButton.setGeometry(QtCore.QRect(20, 160, 82, 17))
        self.radioButton.setObjectName("radioButton")
        self.radioButton_2 = QtWidgets.QRadioButton(Form)
        self.radioButton_2.setGeometry(QtCore.QRect(110, 160, 82, 17))
        self.radioButton_2.setObjectName("radioButton_2")
        self.radioButton_3 = QtWidgets.QRadioButton(Form)
        self.radioButton_3.setGeometry(QtCore.QRect(200, 160, 82, 17))
        self.radioButton_3.setObjectName("radioButton_3")
        self.radioButton_4 = QtWidgets.QRadioButton(Form)
        self.radioButton_4.setGeometry(QtCore.QRect(290, 160, 82, 17))
        self.radioButton_4.setObjectName("radioButton_4")
        self.label_6 = QtWidgets.QLabel(Form)
        self.label_6.setGeometry(QtCore.QRect(20, 130, 111, 16))
        self.label_6.setObjectName("label_6")
        self.label_7 = QtWidgets.QLabel(Form)
        self.label_7.setGeometry(QtCore.QRect(390, 130, 101, 16))
        self.label_7.setObjectName("label_7")
        self.label_8 = QtWidgets.QLabel(Form)
        self.label_8.setGeometry(QtCore.QRect(450, 300, 151, 20))
        self.label_8.setText("")
        self.label_8.setObjectName("label_8")
        self.lineEdit_5 = QtWidgets.QLineEdit(Form)
        self.lineEdit_5.setGeometry(QtCore.QRect(130, 130, 113, 20))
        self.lineEdit_5.setObjectName("lineEdit_5")
        self.lineEdit_6 = QtWidgets.QLineEdit(Form)
        self.lineEdit_6.setGeometry(QtCore.QRect(470, 130, 113, 20))
        self.lineEdit_6.setObjectName("lineEdit_6")
        self.textEdit = QtWidgets.QTextEdit(Form)
        self.textEdit.setGeometry(QtCore.QRect(20, 200, 311, 341))
        self.textEdit.setObjectName("textEdit")
        self.textEdit_2 = QtWidgets.QTextEdit(Form)
        #
        self.textEdit.selectionChanged.connect(self.handleSelectionChanged)
        self.list = ['teamname india']
        self.list1 = [106,95,69,60.5,45,24,55.5,30,28.5,43,41,50,31,33.5,26,44,33.5,44,21.5,24]
        self.list2=[]
        #
        self.textEdit_2.setGeometry(QtCore.QRect(440, 200, 301, 341))
        self.textEdit_2.setObjectName("textEdit_2")
        self.pushButton = QtWidgets.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(340, 330, 75, 23))
        self.pushButton.setObjectName("pushButton")

        self.pushButton.clicked.connect(self.btname)

         #######################################################

        self.radioButton.clicked.connect(lambda:self.btnstate(self.radioButton))
        self.radioButton_2.clicked.connect(lambda:self.btnstate(self.radioButton_2))
        self.radioButton_3.clicked.connect(lambda:self.btnstate(self.radioButton_3))
        self.radioButton_4.clicked.connect(lambda:self.btnstate(self.radioButton_4))

       #########################################################

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    
    def handleSelectionChanged(self):
        text = self.textEdit.textCursor().selectedText()

        self.textEdit.textCursor().removeSelectedText()
            
        self.list.append(text)

        import sqlite3
        c=sqlite3.connect('Stats_Cricket.db')
        r=c.cursor()
        query="SELECT value from stats WHERE player='"+text+"'"
        r.execute(query)
        record=r.fetchone()
        if record!=None:
            self.p=(float(record[0]))
            self.list2.append(self.p)
            self.list1.remove(self.p)
            s1=self.sumoflist(self.list1)
            s2=self.sumoflist(self.list2)
            self.lineEdit_5.setText(str(s1))
            self.lineEdit_6.setText(str(s2))

        
    def msgbtn(i):
        print ("Button pressed is:"+i.text())
        
            
        
    def sumoflist(self,l):
        total=0
        for i in l:
            total+=i
        return total
        

    
    def btname(self):
        for name in self.list:
            self.textEdit_2.append(name)

        import sqlite3
        con = sqlite3.connect('Stats_Cricket.db')
        cur = con.cursor()
        sql = "SELECT * from stats LIMIT 5"
        sql1 = "SELECT * from stats LIMIT 5 OFFSET 5"
        sql2 = "SELECT * from stats LIMIT 5 OFFSET 10"
        sql3 = "SELECT * from stats LIMIT 5 OFFSET 15"
        
        cur.execute(sql)
        rec = cur.fetchall()

        cur.execute(sql1)
        rec1 = cur.fetchall()

        cur.execute(sql2)
        rec2 = cur.fetchall()

        cur.execute(sql3)
        rec3 = cur.fetchall()

        #BAT
        self.batpts = 0
        for i in range(0,len(self.list)):
            for row in rec:
                if row[0] == self.list[i]:
                    self.batpts = self.batpts + 1
        self.lineEdit.setText(str(self.batpts))

        #BOWL
        self.bowlpts = 0
        for i in range(0,len(self.list)):
            for row in rec1:
                if row[0] == self.list[i]:
                    self.bowlpts = self.bowlpts + 1
        self.lineEdit_2.setText(str(self.bowlpts))

        #AR
        self.arpts = 0
        for i in range(0,len(self.list)):
            for row in rec2:
                if row[0] == self.list[i]:
                    self.arpts = self.arpts + 1
        self.lineEdit_3.setText(str(self.arpts))

        #WK
        self.wkpts = 0
        for i in range(0,len(self.list)):
            for row in rec3:
                if row[0] == self.list[i]:
                    self.wkpts = self.wkpts + 1
        self.lineEdit_4.setText(str(self.wkpts))
                

    def btnstate(self,b):

        #FOR BAT
        if b.text() == "BAT":
            if b.isChecked()==True:
        
                import sqlite3
                con = sqlite3.connect('Stats_Cricket.db')
                cur = con.cursor()
                sql = "SELECT * from stats LIMIT 5;"
                cur.execute(sql)
                rec=cur.fetchall()
                
                self.textEdit.setText("NAMES: \n")
                for row in rec:
                    #print(row)
                    self.textEdit.append(str(row[0]))

                con.close()

            else:
                print("NOT SELECTED")

        #FOR BOWL
        elif b.text() == "BOWL":
            if b.isChecked()==True:
        
                import sqlite3
                con = sqlite3.connect('Stats_Cricket.db')
                cur = con.cursor()
                sql = "SELECT * from stats LIMIT 5 OFFSET 5;"
                cur.execute(sql)
                rec=cur.fetchall()
                
                self.textEdit.setText("NAMES: \n")
                for row in rec:
                   # print(row)
                    self.textEdit.append(str(row[0]))

                con.close()

            else:
                print("NOT SELECTED")

            

            

        #FOR AR
        elif b.text() == "AR":
            if b.isChecked()==True:
        
                import sqlite3
                con = sqlite3.connect('Stats_Cricket.db')
                cur = con.cursor()
                sql = "SELECT * from stats LIMIT 5 OFFSET 10;"
                cur.execute(sql)
                rec=cur.fetchall()
                
                self.textEdit.setText("NAMES: \n")
                for row in rec:
                    #print(row)
                    self.textEdit.append(str(row[0]))

                con.close()

            else:
                print("NOT SELECTED")

        #FOR WK
        elif b.text()== "WK":
            if b.isChecked()==True:
        
                import sqlite3
                con = sqlite3.connect('Stats_Cricket.db')
                cur = con.cursor()
                sql = "SELECT * from stats LIMIT 5 OFFSET 15;"
                cur.execute(sql)
                rec=cur.fetchall()
                
                self.textEdit.setText("NAMES: \n")
                for row in rec:
                    #print(row)
                    self.textEdit.append(str(row[0]))

                con.close()

            else:
                print("NOT SELECTED")

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.label.setText(_translate("Form", "BATSMEN"))
        self.label_4.setText(_translate("Form", "BOWLERS"))
        self.label_3.setText(_translate("Form", "ALLROUNDERS"))
        self.label_2.setText(_translate("Form", "WICKET-KEEPERS"))
        self.label_5.setText(_translate("Form", "YOURS SELECTIONS"))
        self.comboBox.setCurrentText(_translate("Form", "NEW TEAM"))
        self.comboBox.setItemText(0, _translate("Form", "NEW TEAM"))
        self.comboBox.setItemText(1, _translate("Form", "OPEN TEAM"))
        self.comboBox.setItemText(2, _translate("Form", "SAVE TEAM"))
        self.comboBox.setItemText(3, _translate("Form", "EVALUATE TEAM"))
        self.radioButton.setText(_translate("Form", "BAT"))
        self.radioButton_2.setText(_translate("Form", "BOWL"))
        self.radioButton_3.setText(_translate("Form", "AR"))
        self.radioButton_4.setText(_translate("Form", "WK"))
        self.label_6.setText(_translate("Form", "POINTS AVAILABLE"))
        self.label_7.setText(_translate("Form", "POINTS USED"))
        self.pushButton.setText(_translate("Form", "---->"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = Ui_Form()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())
