def menufunction(self, action): txt = (action.text()) if txt == 'New Team': Ui_MainWindow.count = 0 self.Avialable.clear() self.Taken.clear() self.team_name.clear() if txt == 'Save Team ': name = self.team_name.text() team = [] total = 0 temp = 0 for index in range(self.Taken.count()): team.append(self.Taken.item(index).text()) for i in range(len(team)): temp = self.getvalue(team[i]) total = total + temp temp = ' '.join(team) curplayer.execute( "INSERT INTO teams (name, players, value) VALUES (?,?,?);", (name, temp, total)) player.commit() if txt == 'Open Team': open_team = '' self.window = QtWidgets.QWidget() self.ui = Ui_Open() self.ui.setup(self.window) self.window.show() if txt == 'Evaluate Team': self.window = QtWidgets.QWidget() self.temp = Ui_Form() self.temp.setup_evaluate(self.window) self.window.show()
def menuaction(self, action): txt = action.text() if txt == "NEW Team": self.bat = 0 self.bow = 0 self.ar = 0 self.wk = 0 self.total = 1000 self.used = 0 self.listWidget_availablePlayer.clear() self.listWidget_selectedPlayer.clear() text, ok=QtWidgets.QInputDialog.getText(MainWindow, "Team", "Enter name of team:") if ok: self.lineEdit_TeamName.setText(str(text)) self.populate() if txt == "SAVE Team": counts = self.listWidget_selectedPlayer.count() if counts == 11: team = '' for count in range(counts): team += self.listWidget_selectedPlayer.item(count).text() if count < counts: team += ',' self.saveteam(self.lineEdit_TeamName.text(), team, self.used) else: self.showmsgbox("Number of should be equal to 11") if txt == "OPEN Team": self.bat = 0 self.bow = 0 self.ar = 0 self.wk = 0 self.listWidget_selectedPlayer.clear() self.listWidget_availablePlayer.clear() self.openteam() if txt == "EVALUATE Team": from evaluate import Ui_Form self.window = QtWidgets.QWidget() self.ui = Ui_Form() self.ui.setupUi(self.window) self.window.show()
def __init__(self, parent=None): QtWidgets.QMainWindow.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) # Beware that all widgets are now available through the self.ui attribute # Getting the push button is written: #self.ui.pushButton.connect(about) self.ui.listWidget.itemDoubleClicked.connect(self.removelist1) self.ui.listWidget_2.itemDoubleClicked.connect(self.removelist2) self.ui.radioButton.toggled.connect(self.checkstate) self.ui.radioButton_4.toggled.connect(self.checkstate) self.ui.radioButton_3.toggled.connect(self.checkstate) self.ui.radioButton_2.toggled.connect(self.checkstate) self.ui.menuManage_Teams.triggered[QtWidgets.QAction].connect(self.menufunction) self.ui.radioButton.setDisabled(True) self.ui.radioButton_3.setDisabled(True) self.ui.radioButton_4.setDisabled(True) self.ui.radioButton_2.setDisabled(True) self.numbers()
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(903, 478) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.label_yourSelection = QtWidgets.QLabel(self.centralwidget) self.label_yourSelection.setObjectName("label_yourSelection") self.verticalLayout.addWidget(self.label_yourSelection) self.horizontalLayout_3 = QtWidgets.QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.label_BAT = QtWidgets.QLabel(self.centralwidget) self.label_BAT.setObjectName("label_BAT") self.horizontalLayout_3.addWidget(self.label_BAT) self.lineEdit_BAT = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_BAT.setObjectName("lineEdit_BAT") self.horizontalLayout_3.addWidget(self.lineEdit_BAT) ############## MAKING LINE EDIT READ ONLY FIELD ####################### self.lineEdit_BAT.setReadOnly(True) ####################################################################### self.label_BOW = QtWidgets.QLabel(self.centralwidget) self.label_BOW.setObjectName("label_BOW") self.horizontalLayout_3.addWidget(self.label_BOW) self.lineEdit_BOW = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_BOW.setObjectName("lineEdit_BOW") self.horizontalLayout_3.addWidget(self.lineEdit_BOW) ############## MAKING LINE EDIT READ ONLY FIELD ####################### self.lineEdit_BOW.setReadOnly(True) ####################################################################### self.label_AR = QtWidgets.QLabel(self.centralwidget) self.label_AR.setObjectName("label_AR") self.horizontalLayout_3.addWidget(self.label_AR) self.lineEdit_AR = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_AR.setEnabled(True) font = QtGui.QFont() font.setBold(False) font.setWeight(50) self.lineEdit_AR.setFont(font) self.lineEdit_AR.setObjectName("lineEdit_AR") self.horizontalLayout_3.addWidget(self.lineEdit_AR) ############## MAKING LINE EDIT READ ONLY FIELD ####################### self.lineEdit_AR.setReadOnly(True) ####################################################################### self.label_WR = QtWidgets.QLabel(self.centralwidget) self.label_WR.setObjectName("label_WR") self.horizontalLayout_3.addWidget(self.label_WR) self.lineEdit_WK = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_WK.setObjectName("lineEdit_WK") self.horizontalLayout_3.addWidget(self.lineEdit_WK) ############## MAKING LINE EDIT READ ONLY FIELD ####################### self.lineEdit_WK.setReadOnly(True) ####################################################################### self.verticalLayout.addLayout(self.horizontalLayout_3) self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 2) self.verticalLayout_2 = QtWidgets.QVBoxLayout() self.verticalLayout_2.setObjectName("verticalLayout_2") self.horizontalLayout_5 = QtWidgets.QHBoxLayout() self.horizontalLayout_5.setObjectName("horizontalLayout_5") self.label_ptAvailable = QtWidgets.QLabel(self.centralwidget) self.label_ptAvailable.setObjectName("label_ptAvailable") self.horizontalLayout_5.addWidget(self.label_ptAvailable) self.lineEdit_ptAvailable = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_ptAvailable.setObjectName("lineEdit_ptAvailable") self.horizontalLayout_5.addWidget(self.lineEdit_ptAvailable) ############## MAKING LINE EDIT READ ONLY FIELD ####################### self.lineEdit_ptAvailable.setReadOnly(True) ####################################################################### self.verticalLayout_2.addLayout(self.horizontalLayout_5) self.horizontalLayout_4 = QtWidgets.QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.radioButton_BAT = QtWidgets.QRadioButton(self.centralwidget) self.radioButton_BAT.setObjectName("radioButton_BAT") self.horizontalLayout_4.addWidget(self.radioButton_BAT) self.radioButton_BOW = QtWidgets.QRadioButton(self.centralwidget) self.radioButton_BOW.setObjectName("radioButton_BOW") self.horizontalLayout_4.addWidget(self.radioButton_BOW) self.radioButton_AR = QtWidgets.QRadioButton(self.centralwidget) self.radioButton_AR.setObjectName("radioButton_AR") self.horizontalLayout_4.addWidget(self.radioButton_AR) self.radioButton_WK = QtWidgets.QRadioButton(self.centralwidget) self.radioButton_WK.setObjectName("radioButton_WK") self.horizontalLayout_4.addWidget(self.radioButton_WK) self.verticalLayout_2.addLayout(self.horizontalLayout_4) self.listWidget_availablePlayer = QtWidgets.QListWidget(self.centralwidget) self.listWidget_availablePlayer.setObjectName("listWidget_availablePlayer") self.verticalLayout_2.addWidget(self.listWidget_availablePlayer) self.gridLayout.addLayout(self.verticalLayout_2, 1, 0, 1, 1) self.verticalLayout_3 = QtWidgets.QVBoxLayout() self.verticalLayout_3.setObjectName("verticalLayout_3") self.horizontalLayout_6 = QtWidgets.QHBoxLayout() self.horizontalLayout_6.setObjectName("horizontalLayout_6") self.label_ptUsed = QtWidgets.QLabel(self.centralwidget) self.label_ptUsed.setObjectName("label_ptUsed") self.horizontalLayout_6.addWidget(self.label_ptUsed) self.lineEdit_ptUsed = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_ptUsed.setObjectName("lineEdit_ptUsed") self.horizontalLayout_6.addWidget(self.lineEdit_ptUsed) ############## MAKING LINE EDIT READ ONLY FIELD ####################### self.lineEdit_ptUsed.setReadOnly(True) ####################################################################### self.verticalLayout_3.addLayout(self.horizontalLayout_6) self.horizontalLayout_7 = QtWidgets.QHBoxLayout() self.horizontalLayout_7.setObjectName("horizontalLayout_7") self.label_TeamName = QtWidgets.QLabel(self.centralwidget) self.label_TeamName.setObjectName("label_TeamName") self.horizontalLayout_7.addWidget(self.label_TeamName) self.lineEdit_TeamName = QtWidgets.QLineEdit(self.centralwidget) self.lineEdit_TeamName.setObjectName("lineEdit_TeamName") self.horizontalLayout_7.addWidget(self.lineEdit_TeamName) ############## MAKING LINE EDIT READ ONLY FIELD ####################### self.lineEdit_TeamName.setReadOnly(True) ####################################################################### self.verticalLayout_3.addLayout(self.horizontalLayout_7) self.listWidget_selectedPlayer = QtWidgets.QListWidget(self.centralwidget) self.listWidget_selectedPlayer.setObjectName("listWidget_selectedPlayer") self.verticalLayout_3.addWidget(self.listWidget_selectedPlayer) self.gridLayout.addLayout(self.verticalLayout_3, 1, 1, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 903, 22)) self.menubar.setObjectName("menubar") self.menuManage_Team = QtWidgets.QMenu(self.menubar) self.menuManage_Team.setObjectName("menuManage_Team") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.actionNew_Team = QtWidgets.QAction(MainWindow) self.actionNew_Team.setObjectName("actionNew_Team") self.actionOPEN_Team = QtWidgets.QAction(MainWindow) self.actionOPEN_Team.setObjectName("actionOPEN_Team") self.actionSAVE_Team = QtWidgets.QAction(MainWindow) self.actionSAVE_Team.setObjectName("actionSAVE_Team") self.actionEVALUATE_Team = QtWidgets.QAction(MainWindow) self.actionEVALUATE_Team.setObjectName("actionEVALUATE_Team") self.actionExit = QtWidgets.QAction(MainWindow) self.actionExit.setObjectName("actionExit") self.menuManage_Team.addAction(self.actionNew_Team) self.menuManage_Team.addAction(self.actionOPEN_Team) self.menuManage_Team.addAction(self.actionSAVE_Team) self.menuManage_Team.addAction(self.actionEVALUATE_Team) self.menuManage_Team.addAction(self.actionExit) self.menubar.addAction(self.menuManage_Team.menuAction()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) ############################ Variables ################################ self.bat = 0 self.bow = 0 self.ar = 0 self.wk = 0 self.total = 1000 self.used = 0 self.role = '' ##################### Binding the method to call ####################### self.menuManage_Team.triggered[QtWidgets.QAction].connect(self.menuaction) self.radioButton_BAT.toggled.connect(lambda:self.check(True)) self.radioButton_BOW.toggled.connect(lambda:self.check(True)) self.radioButton_AR.toggled.connect(lambda:self.check(True)) self.radioButton_WK.toggled.connect(lambda:self.check(True)) self.listWidget_availablePlayer.itemDoubleClicked.connect(self.addtoSelectedPlayer) self.listWidget_selectedPlayer.itemDoubleClicked.connect(self.addtoAvailablePlayer) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.label_yourSelection.setText(_translate("MainWindow", "Your Selections")) self.label_BAT.setText(_translate("MainWindow", "Batsmen(BAT)")) self.label_BOW.setText(_translate("MainWindow", "Bowlers(BOW)")) self.label_AR.setText(_translate("MainWindow", "All Rounders(AR)")) self.label_WR.setText(_translate("MainWindow", "Wicket-Keeper(WK)")) self.label_ptAvailable.setText(_translate("MainWindow", "Point Available")) self.radioButton_BAT.setText(_translate("MainWindow", "BAT")) self.radioButton_BOW.setText(_translate("MainWindow", "BOW")) self.radioButton_AR.setText(_translate("MainWindow", "AR")) self.radioButton_WK.setText(_translate("MainWindow", "WK")) self.label_ptUsed.setText(_translate("MainWindow", "Point used")) self.label_TeamName.setText(_translate("MainWindow", "Team Name")) self.menuManage_Team.setTitle(_translate("MainWindow", "Manage Team")) self.actionNew_Team.setText(_translate("MainWindow", "NEW Team")) self.actionOPEN_Team.setText(_translate("MainWindow", "OPEN Team")) self.actionSAVE_Team.setText(_translate("MainWindow", "SAVE Team")) self.actionEVALUATE_Team.setText(_translate("MainWindow", "EVALUATE Team")) self.actionExit.setText(_translate("MainWindow", "Exit")) ########################################################################### ################### USER DEFINED METHOD STARTING ########################## ########################################################################### ####################### 1. Menu section Method ############################ def menuaction(self, action): txt = action.text() if txt == "NEW Team": self.bat = 0 self.bow = 0 self.ar = 0 self.wk = 0 self.total = 1000 self.used = 0 self.listWidget_availablePlayer.clear() self.listWidget_selectedPlayer.clear() text, ok=QtWidgets.QInputDialog.getText(MainWindow, "Team", "Enter name of team:") if ok: self.lineEdit_TeamName.setText(str(text)) self.populate() if txt == "SAVE Team": counts = self.listWidget_selectedPlayer.count() if counts == 11: team = '' for count in range(counts): team += self.listWidget_selectedPlayer.item(count).text() if count < counts: team += ',' self.saveteam(self.lineEdit_TeamName.text(), team, self.used) else: self.showmsgbox("Number of should be equal to 11") if txt == "OPEN Team": self.bat = 0 self.bow = 0 self.ar = 0 self.wk = 0 self.listWidget_selectedPlayer.clear() self.listWidget_availablePlayer.clear() self.openteam() if txt == "EVALUATE Team": from evaluate import Ui_Form self.window = QtWidgets.QWidget() self.ui = Ui_Form() self.ui.setupUi(self.window) self.window.show() #################### End of Menu Section method ########################### ##################################### 2. Radio Button check method ############################################### def check(self, flag): #Flag is used, as method is called only for checking the role that time method fill will not be called if self.radioButton_BAT.isChecked(): self.role = 'BAT' if self.radioButton_BOW.isChecked(): self.role = 'BOW' if self.radioButton_AR.isChecked(): self.role = 'AR' if self.radioButton_WK.isChecked(): self.role = 'WK' if flag == True: self.fill(self.role) #call the Method to fill the list based on the role ##################################### End of Radio Button Check Method ########################################## ################################## 3. Fill the list based on the role of the players ############################ def fill(self, role): # If no team name is mentioned then prompt the user to enter team Name # or open Saved team if self.lineEdit_TeamName.text() == "": self.showmsgbox("Enter name of team") return self.listWidget_availablePlayer.clear() #Clear the list #Populate the list based on the radio button selected sql = "SELECT Player FROM Stats WHERE CTG = '"+role+"';" players = curscricket.execute(sql) for player in players: self.listWidget_availablePlayer.addItem(player[0]) ###################################### End of Fill Method ################################################### ######################################## 4. Add to Selected player Method #################################### def addtoSelectedPlayer(self, item): #check role of the each player based on the radio button selected self.check(False) flag = self.chkCriteria(self.role, item) if True: self.listWidget_availablePlayer.takeItem(self.listWidget_availablePlayer.row(item)) self.listWidget_selectedPlayer.addItem(item.text()) self.populate() ######################################### End ADD to selected player METHOD ################################## ################################## 5. Add to Available player Method ########################################## def addtoAvailablePlayer(self, item): #To find the name of the player clicked self.listWidget_selectedPlayer.takeItem(self.listWidget_selectedPlayer.row(item)) sql = "SELECT Player, Value, Ctg FROM Stats WHERE Player = '"+item.text()+"';" details = curscricket.execute(sql) detail = details.fetchone() self.total += int(detail[1]) self.used -= int(detail[1]) role = str(detail[2]) if role == "BAT": self.bat -= 1 if self.radioButton_BAT.isChecked(): self.listWidget_availablePlayer.addItem(item.text()) if role == "BOW": self.bow -= 1 if self.radioButton_BOW.isChecked(): self.listWidget_availablePlayer.addItem(item.text()) if role == "AR": self.ar -= 1 if self.radioButton_AR.isChecked(): self.listWidget_availablePlayer.addItem(item.text()) if role == "WK": self.wk -= 1 if self.radioButton_WK.isChecked(): self.listWidget_availablePlayer.addItem(item.text()) self.populate() ###################################### End ADD to Available player METHOD ##################################### ########################################### 6. Populate METHOD ################################################# def populate(self): self.lineEdit_BAT.setText(str(self.bat)) self.lineEdit_BOW.setText(str(self.bow)) self.lineEdit_AR.setText(str(self.ar)) self.lineEdit_WK.setText(str(self.wk)) self.lineEdit_ptAvailable.setText(str(self.total)) self.lineEdit_ptUsed.setText(str(self.used)) ############################################## end populate method ################################################ ######################################### 7. Check Criteria of slection of players ################################ def chkCriteria(self, role, player): errormsg = "" if role == 'BAT' and self.bat >= 5: errormsg = "BATSMEN can't be more than 5" if role == 'BOW' and self.bow >= 5: errormsg = "BOWLERS can't be more than 5" if role == "AR" and self.ar >= 3: errormsg = "Allrounders can't be more than 3" if role == "WK" and self.wk > 1: errormsg = "Wicketkeeper can't be more the 1" if errormsg != "": self.showmsgbox(errormsg) return False if (self.total <= 0) or (self.used >= 1000): errormsg = "You Have Exhausted your Points" self.showmsgbox(errormsg) return False if role == "BAT": self.bat += 1 if role == "BOW": self.bow += 1 if role == "AR": self.ar += 1 if role == "WK": self.wk += 1 sql = "SELECT Value FROM Stats WHERE Player = '"+player.text()+"';" values = curscricket.execute(sql) value = values.fetchone() self.total -= int(value[0]) self.used += int(value[0]) return True ########################################## End of Criteria of selection of players ################################ ################################################ 8. SAVE TEAM METHOD ############################################### def saveteam(self, teamname, teammember, ptvalue): sql = "INSERT INTO Teams (Name, Players, Value) VALUES('"+teamname+"', '"+teammember+"', '"+str(ptvalue)+"');" try: curscricket.execute(sql) cricket.commit() self.showmsgbox("Team Saved Succesfully") except: cricket.rollback() self.showmsgbox("Unable to save the Team") ############################################### END SAVE TEAM METHOD ############################################### ############################################## 9. OPEN TEAM METHOD ################################################# def openteam(self): sql = "SELECT Name from Teams;" values = curscricket.execute(sql) teams = list() for value in values: teams.append(value[0]) team, ok=QtWidgets.QInputDialog.getItem(MainWindow,"Fantasy Cricket","Choose A Team",teams,0,False) if ok and team: self.lineEdit_TeamName.setText(team) sql1 = "SELECT Players, Value FROM Teams WHERE Name = '"+team+"';" values = curscricket.execute(sql1) value = curscricket.fetchone() Players = value[0].split(',') self.listWidget_selectedPlayer.addItems(Players) self.used = value[1] self.total = 1000 - value[1] counts = self.listWidget_selectedPlayer.count() for count in range(counts - 1): player = self.listWidget_selectedPlayer.item(count).text() sql3 = "SELECT Ctg FROM Stats WHERE Player = '"+player+"';" curscricket.execute(sql3) roles = curscricket.fetchone() role = roles[0] if role == 'BAT': self.bat += 1 if role == 'BOW': self.bow += 1 if role == 'AR': self.ar += 1 if role == 'WK': self.wk += 1 self.populate() ############################################### END OPEN TEAM METHOD ############################################### ############################## MESSAGE BOX ################################ def showmsgbox(self,msg): Dialog=QtWidgets.QMessageBox() Dialog.setText(msg) Dialog.setWindowTitle("Fantasy Cricket") ret=Dialog.exec()
class Ui_MainWindow(object): count = 0 def __init__(self, a=''): open_team = a def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(538, 549) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.centralwidget) self.verticalLayout_2.setObjectName("verticalLayout_2") self.horizontalLayout_15 = QtWidgets.QHBoxLayout() self.horizontalLayout_15.setObjectName("horizontalLayout_15") self.bat = QtWidgets.QRadioButton(self.centralwidget) self.bat.setObjectName("bat") self.horizontalLayout_15.addWidget(self.bat) self.bwl = QtWidgets.QRadioButton(self.centralwidget) self.bwl.setObjectName("bwl") self.horizontalLayout_15.addWidget(self.bwl) self.wk = QtWidgets.QRadioButton(self.centralwidget) self.wk.setObjectName("wk") self.horizontalLayout_15.addWidget(self.wk) self.ar = QtWidgets.QRadioButton(self.centralwidget) self.ar.setObjectName("ar") self.horizontalLayout_15.addWidget(self.ar) spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.bat.toggled.connect(self.checkstate) self.bwl.toggled.connect(self.checkstate) self.wk.toggled.connect(self.checkstate) self.ar.toggled.connect(self.checkstate) self.horizontalLayout_15.addItem(spacerItem) self.label_18 = QtWidgets.QLabel(self.centralwidget) self.label_18.setObjectName("label_18") self.horizontalLayout_15.addWidget(self.label_18) self.team_name = QtWidgets.QLineEdit(self.centralwidget) self.team_name.setObjectName("team_name") self.horizontalLayout_15.addWidget(self.team_name) self.verticalLayout_2.addLayout(self.horizontalLayout_15) self.horizontalLayout_16 = QtWidgets.QHBoxLayout() self.horizontalLayout_16.setObjectName("horizontalLayout_16") self.Avialable = QtWidgets.QListWidget(self.centralwidget) self.Avialable.setObjectName("Avialable") self.Avialable.itemDoubleClicked.connect(self.addplayer) self.horizontalLayout_16.addWidget(self.Avialable) spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) self.horizontalLayout_16.addItem(spacerItem1) self.Taken = QtWidgets.QListWidget(self.centralwidget) self.Taken.setObjectName("Taken") self.horizontalLayout_16.addWidget(self.Taken) self.Taken.itemDoubleClicked.connect(self.rmplayer) self.verticalLayout_2.addLayout(self.horizontalLayout_16) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 538, 26)) self.menubar.setObjectName("menubar") self.menuManage_Team = QtWidgets.QMenu(self.menubar) self.menuManage_Team.setObjectName("menuManage_Team") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.actionNew_Team = QtWidgets.QAction(MainWindow) self.actionNew_Team.setObjectName("actionNew_Team") self.actionOpen_Team = QtWidgets.QAction(MainWindow) self.actionOpen_Team.setObjectName("actionOpen_Team") self.actionSave_Team = QtWidgets.QAction(MainWindow) self.actionSave_Team.setObjectName("actionSave_Team") self.actionEvaluate_Team = QtWidgets.QAction(MainWindow) self.actionEvaluate_Team.setObjectName("actionEvaluate_Team") self.menuManage_Team.addAction(self.actionNew_Team) self.menuManage_Team.addAction(self.actionOpen_Team) self.menuManage_Team.addAction(self.actionSave_Team) self.menuManage_Team.addSeparator() self.menuManage_Team.addAction(self.actionEvaluate_Team) self.menubar.addAction(self.menuManage_Team.menuAction()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.menuManage_Team.triggered[QtWidgets.QAction].connect( self.menufunction) def menufunction(self, action): txt = (action.text()) if txt == 'New Team': Ui_MainWindow.count = 0 self.Avialable.clear() self.Taken.clear() self.team_name.clear() if txt == 'Save Team ': name = self.team_name.text() team = [] total = 0 temp = 0 for index in range(self.Taken.count()): team.append(self.Taken.item(index).text()) for i in range(len(team)): temp = self.getvalue(team[i]) total = total + temp temp = ' '.join(team) curplayer.execute( "INSERT INTO teams (name, players, value) VALUES (?,?,?);", (name, temp, total)) player.commit() if txt == 'Open Team': open_team = '' self.window = QtWidgets.QWidget() self.ui = Ui_Open() self.ui.setup(self.window) self.window.show() if txt == 'Evaluate Team': self.window = QtWidgets.QWidget() self.temp = Ui_Form() self.temp.setup_evaluate(self.window) self.window.show() def checkstate(self): state1 = 'OFF' state2 = 'OFF' state3 = 'OFF' state4 = 'OFF' if self.bat.isChecked() == True: state1 = 'ON' curplayer.execute( "select player from stats where category ='Bat';") record = curplayer.fetchall() elif self.bwl.isChecked() == True: state2 = 'ON' curplayer.execute( "select player from stats where category ='Bwl';") record = curplayer.fetchall() elif self.wk.isChecked() == True: state3 = 'ON' curplayer.execute("select player from stats where category ='Wk';") record = curplayer.fetchall() elif self.ar.isChecked() == True: state4 = 'ON' curplayer.execute("select player from stats where category ='Ar';") record = curplayer.fetchall() self.Avialable.clear() for i in record: record1 = ''.join(i) self.Avialable.addItem(record1) def addplayer(self, item): if Ui_MainWindow.count < 11: self.Avialable.takeItem(self.Avialable.row(item)) self.Taken.addItem(item.text()) Ui_MainWindow.count = Ui_MainWindow.count + 1 def rmplayer(self, item): self.Taken.takeItem(self.Taken.row(item)) self.Avialable.addItem(item.text()) Ui_MainWindow.count = Ui_MainWindow.count - 1 def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.bat.setText(_translate("MainWindow", "BAT")) self.bwl.setText(_translate("MainWindow", "BWL")) self.wk.setText(_translate("MainWindow", "WK")) self.ar.setText(_translate("MainWindow", "AR")) self.label_18.setText(_translate("MainWindow", "Team Name")) self.menuManage_Team.setTitle(_translate("MainWindow", "Manage Team")) self.actionNew_Team.setText(_translate("MainWindow", "New Team")) self.actionOpen_Team.setText(_translate("MainWindow", "Open Team")) self.actionSave_Team.setText(_translate("MainWindow", "Save Team ")) self.actionEvaluate_Team.setText( _translate("MainWindow", "Evaluate Team")) def getvalue(self, temp): total_value = 0 sql = "select * from match where player ='" + temp + "';" result = curplayer.execute(sql) column_name = [] return_name = [] for row in result.description: column_name.append(row[0]) result = result.fetchall() temp_dict = {} for res in range(len(result)): for col in range(len(column_name)): temp_dict.update({column_name[col]: result[res][col]}) total_value = Calculate_value.players(temp_dict) return total_value
def Window(self): self.window=QtWidgets.QWidget() self.ui=Ui_Form() self.ui.setupUi(self.window) myMainWindow.hide() self.window.show()
class MyMainWindow(QtWidgets.QMainWindow): def __init__(self, parent=None): QtWidgets.QMainWindow.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) # Beware that all widgets are now available through the self.ui attribute # Getting the push button is written: #self.ui.pushButton.connect(about) self.ui.listWidget.itemDoubleClicked.connect(self.removelist1) self.ui.listWidget_2.itemDoubleClicked.connect(self.removelist2) self.ui.radioButton.toggled.connect(self.checkstate) self.ui.radioButton_4.toggled.connect(self.checkstate) self.ui.radioButton_3.toggled.connect(self.checkstate) self.ui.radioButton_2.toggled.connect(self.checkstate) self.ui.menuManage_Teams.triggered[QtWidgets.QAction].connect(self.menufunction) self.ui.radioButton.setDisabled(True) self.ui.radioButton_3.setDisabled(True) self.ui.radioButton_4.setDisabled(True) self.ui.radioButton_2.setDisabled(True) self.numbers() def numbers(self): global BAT,BOW,WK,AR,batters,bowlers,wicketers,rounders,bat1,bow1,al1,wk1 curschool.execute('''select count(player) from stats where ctg="WK";''') WK=list(curschool.fetchone()) curschool.execute('''select count(player) from stats where ctg="BAT";''') BAT=list(curschool.fetchone()) curschool.execute('''select count(player) from stats where ctg="AR";''') AR=list(curschool.fetchone()) curschool.execute('''select count(player) from stats where ctg="BWL";''') BOW=list(curschool.fetchone()) curschool.execute('''select player from stats where ctg="BAT";''') batters=curschool.fetchall() curschool.execute('''select player from stats where ctg="BWL";''') bowlers=curschool.fetchall() curschool.execute('''select player from stats where ctg="AR";''') rounders=curschool.fetchall() curschool.execute('''select player from stats where ctg="WK";''') wicketers=curschool.fetchall() curschool.execute('''select player from stats where ctg="BAT";''') bat1=curschool.fetchall() curschool.execute('''select player from stats where ctg="BWL";''') bow1=curschool.fetchall() curschool.execute('''select player from stats where ctg="AR";''') al1=curschool.fetchall() curschool.execute('''select player from stats where ctg="WK";''') wk1=curschool.fetchall() def Window(self): self.window=QtWidgets.QWidget() self.ui=Ui_Form() self.ui.setupUi(self.window) myMainWindow.hide() self.window.show() def menufunction(self, action): txt= (action.text()) if(txt=='NEW Team'): team_name=QtWidgets.QInputDialog.getText(self,"NEW TEAM","Enter the name of new team") if team_name[0] is '' : QtWidgets.QMessageBox.critical(self,"Error","Team Name cannot be empty") else: self.ui.lineEdit_7.setText(team_name[0]) self.ui.radioButton.setDisabled(False) self.ui.radioButton_3.setDisabled(False) self.ui.radioButton_4.setDisabled(False) self.ui.radioButton_2.setDisabled(False) if(txt=='SAVE Team'): team1=[] curschool.execute('''insert into teams (name,players,value) values(?,?,?);''',(self.ui.lineEdit_7.text(),self.ui.listWidget_2.count(),self.ui.lineEdit_6.text())) MySchool.commit() if(txt=='EVALUATE Team'): self.Window() def checkstate(self): global batters state1='OFF' state2='OFF' state3='OFF' state4='OFF' if self.ui.radioButton.isChecked()==True: state1='ON' self.ui.listWidget.clear() curschool.execute('''select player from stats where ctg="BAT";''') for row in batters: self.ui.listWidget.addItem(row[0]) else: state1='OFF' if self.ui.radioButton_4.isChecked()==True: state2='ON' self.ui.listWidget.clear() curschool.execute('''select player from stats where ctg="AR";''') for row in rounders: self.ui.listWidget.addItem(row[0]) else: state2='OFF' if self.ui.radioButton_3.isChecked()==True: state3='ON' self.ui.listWidget.clear() curschool.execute('''select player from stats where ctg="BWL";''') for row in bowlers: self.ui.listWidget.addItem(row[0]) else: state3='OFF' if self.ui.radioButton_2.isChecked()==True: state4='ON' self.ui.listWidget.clear() curschool.execute('''select player from stats where ctg="WK";''') for row in wicketers: self.ui.listWidget.addItem(row[0]) else: state4='OFF' def x(self,ctg): global BAT,BOW,WK,AR if ctg=="BAT": BAT[0]=BAT[0]-1 self.ui.lineEdit.setText(str(BAT[0]-self.ui.listWidget.count())) elif ctg=="BOW": BOW[0]=BOW[0]-1 self.ui.lineEdit_2.setText(str(BOW[0])) elif ctg=="WK": WK[0]=WK[0]-1 self.ui.lineEdit_4.setText(str(WK[0])) elif ctg=="AR": AR[0]=AR[0]-1 self.ui.lineEdit_3.setText(str(AR[0])) def values(self,item,ctg): global total_value curschool.execute('''select value from stats where player="'''+item.text()+'''";''') value1=curschool.fetchone() total_value=total_value-value1[0] if total_value < 0 : QtWidgets.QMessageBox.critical(self,"Error","Cannot select this player") total_value=total_value+value1[0] self.ui.listWidget.addItem(item.text()) y=0 else: self.ui.listWidget_2.addItem(item.text()) self.x(ctg) y=1 self.ui.lineEdit_6.setText(str(1000-total_value)) self.ui.lineEdit_5.setText(str(total_value)) return y def removelist1(self, item): if self.ui.radioButton_2.isChecked()== True: if self.ui.lineEdit_4.text()=='1': QtWidgets.QMessageBox.critical(self,"error","cannot select more than one wicket keeper") else: self.ui.listWidget.takeItem(self.ui.listWidget.row(item)) y=self.values(item,self.ui.radioButton_2.text()) if y==1: wicketers.remove((item.text(),)) if self.ui.radioButton.isChecked()==True: if self.ui.lineEdit.text()=='5': QtWidgets.QMessageBox.critical(self,"error","cannot select more than five batsmen") else: self.ui.listWidget.takeItem(self.ui.listWidget.row(item)) y=self.values(item,self.ui.radioButton.text()) if y==1: batters.remove((item.text(),)) if self.ui.radioButton_3.isChecked()==True: if self.ui.lineEdit_2.text()=='3': QtWidgets.QMessageBox.critical(self,"error","cannot select more than three bowlers") else: self.ui.listWidget.takeItem(self.ui.listWidget.row(item)) y=self.values(item,self.ui.radioButton_3.text()) if y==1: bowlers.remove((item.text(),)) if self.ui.radioButton_4.isChecked()==True: if self.ui.lineEdit_3.text()=='2': QtWidgets.QMessageBox.critical(self,"error","cannot select more than two Allrounders") else: self.ui.listWidget.takeItem(self.ui.listWidget.row(item)) y=self.values(item,self.ui.radioButton_4.text()) if y==1: rounders.remove((item.text(),)) def removelist2(self, item): global total_value,bat1,bow1,al1,wk1,batters,bowlers,wicketers,rounders,BAT,BOW,AR,WK self.ui.listWidget_2.takeItem(self.ui.listWidget_2.row(item)) if((item.text(),) in bat1): batters.append((item.text(),)) BAT[0]=BAT[0]+1 self.ui.lineEdit.setText(str(BAT[0])) if((item.text(),) in bow1): bowlers.append((item.text(),)) BOW[0]=BOW[0]+1 self.ui.lineEdit_2.setText(str(BOW[0])) if((item.text(),) in al1): rounders.append((item.text(),)) AR[0]=AR[0]+1 self.ui.lineEdit_3.setText(str(AR[0])) if((item.text(),) in wk1): wicketers.append((item.text(),)) WK[0]=WK[0]+1 self.ui.lineEdit_4.setText(str(WK[0])) curschool.execute('''select value from stats where player="'''+item.text()+'''";''') value2=curschool.fetchone() total_value=total_value+value2[0] self.ui.lineEdit_6.setText(str(1000-total_value)) self.ui.lineEdit_5.setText(str(total_value))