def validateSubmission(self): #Ensures that there are not errors with the movie entry being added if self.titleVal.text() == "" or self.titleVal.text() == None: self.errorMessage = "Please Enter a Title" QToaster.showMessage(self.parent(), self.errorMessage, corner=QtCore.Qt.BottomRightCorner) return False if len(self.titleVal.text()) >= 100: self.errorMessage = "Title is too long" #Don't really love the way this is phrased, will probably revise this later QToaster.showMessage(self.parent(), self.errorMessage, corner=QtCore.Qt.BottomRightCorner) return False if self.dateVal.date().toString() == None: self.errorMessage = "Please Enter a Date" QToaster.showMessage(self.parent(), self.errorMessage, corner=QtCore.Qt.BottomRightCorner) return False if self.ratingVal.currentText() == None: self.errorMessage = "Please Enter a Rating" QToaster.showMessage(self.parent(), self.errorMessage, corner=QtCore.Qt.BottomRightCorner) return False if self.genreVal.currentText() == None: self.errorMessage = "Please Enter a Genre" QToaster.showMessage(self.parent(), self.errorMessage, corner=QtCore.Qt.BottomRightCorner) return False if self.theaterChecked.isChecked() == True: self.locationVal = "Theater" elif self.homeChecked.isChecked() == True: self.locationVal = "Home" else: self.locationVal = None if (self.rewatchYesChecked.isChecked() == True): self.rewatchVal = 'Yes' elif (self.rewatchNoChecked.isChecked() == True): self.rewatchVal = 'No' else: self.rewatchVal = None return True #Indicates that the entry is good and can be inserted into the table
def updateSettings(self): #This will update the settings table so that the selected settings are saved sql = 'UPDATE settings SET SETTINGS_APP_THEME = %s, SETTINGS_FONT_SIZE = %s, SETTINGS_GRAPH_THEME = %s WHERE SETTINGS_ID = 1' vals = [ self.appThemeVal.currentText(), self.fontSizeVal.currentText(), self.graphThemeVal.currentText() ] cursor = dbConnection.cursor() cursor.execute(sql, vals) dbConnection.commit() cursor.close() QToaster.showMessage(self.parent(), 'Settings Updated', corner=QtCore.Qt.BottomRightCorner) self.close()
def displayEditWindow(self): #Displays the Edit Window when the EditButton is pressed if(len(self.MainLogTable.selectedItems()) > 0): entryID = self.MainLogTable.item(self.MainLogTable.currentRow(), 0).text() title = self.MainLogTable.item(self.MainLogTable.currentRow(), 1).text() date = self.MainLogTable.item(self.MainLogTable.currentRow(), 2).text() rating = self.MainLogTable.item(self.MainLogTable.currentRow(), 3).text() genre = self.MainLogTable.item(self.MainLogTable.currentRow(), 4).text() location = self.MainLogTable.item(self.MainLogTable.currentRow(), 5).text() comments = self.MainLogTable.item(self.MainLogTable.currentRow(), 6).text() rewatch = self.MainLogTable.item(self.MainLogTable.currentRow(), 7).text() editWin = EditForm_Win(self, entryID, title, date, rating, genre, location, comments, rewatch, self.MainLogTable.currentRow()) if editWin.exec_(): print("Success!") else: print("Closing Edit Window") if(self.changed == True): #Only updates if an entry has actually been edited self.refreshLastTen() self.refreshMainLog() self.updateStats() else: QToaster.showMessage(self, 'Please Select a Row', corner=QtCore.Qt.BottomRightCorner)
def deleteEntry(self): #Deletes a selected entry from the table if(len(self.MainLogTable.selectedItems()) > 0): entryID = self.MainLogTable.item(self.MainLogTable.currentRow(), 0).text() sql = "DELETE FROM log WHERE LOG_ID = %s" vals = [entryID] cursor = self.dbConnection.cursor() cursor.execute(sql, vals) self.dbConnection.commit() cursor.close() #Deleting from MainLogTable self.MainLogTable.removeRow(self.MainLogTable.currentRow()) QToaster.showMessage(self, 'Entry Deleted', corner=QtCore.Qt.BottomRightCorner) entriesCount = self.getAllTimeCount() #Probably could make this a one liner, but not sure how yet if(entriesCount[0][0] != 0): self.updateStats() self.refreshLastTen() self.refreshMainLog() else: QToaster.showMessage(self, 'Please Select a Row', corner=QtCore.Qt.BottomRightCorner)
def insertMovie(self): #Inserts a new movie to the movie list dbConnection2 = self.parent().dbConnection if self.validateSubmission() == True: sql = "INSERT INTO log (LOG_MOVIE_TITLE, LOG_MOVIE_DATE, LOG_MOVIE_RATING, LOG_MOVIE_GENRE, LOG_MOVIE_LOCATION, LOG_MOVIE_COMMENTS, LOG_MOVIE_REWATCH) VALUES (%s, %s, %s, %s, %s, %s, %s)" vals = [ self.titleVal.text(), self.dateVal.date().toString('yyyy-MM-dd'), self.ratingVal.currentText(), self.genreVal.currentText(), self.locationVal, self.commentVal.toPlainText(), self.rewatchVal ] cursor = dbConnection2.cursor() cursor.execute(sql, vals) dbConnection2.commit() cursor.close() QToaster.showMessage(self.parent(), 'Entry Added', corner=QtCore.Qt.BottomRightCorner) self.parent().changed = True self.close() else: print("Error: " + self.errorMessage)
def updateMovie(self): #Updates a movie entry dbConnection2 = self.parentWin.dbConnection if self.validateSubmission() == True: sql = "UPDATE log SET LOG_MOVIE_TITLE = %s, LOG_MOVIE_DATE = %s, LOG_MOVIE_RATING = %s, LOG_MOVIE_GENRE = %s, LOG_MOVIE_LOCATION = %s, LOG_MOVIE_COMMENTS = %s, LOG_MOVIE_REWATCH = %s WHERE LOG_ID = %s" vals = [ self.titleVal.text(), self.dateVal.date().toString('yyyy-MM-dd'), self.ratingVal.currentText(), self.genreVal.currentText(), self.locationVal, self.commentVal.toPlainText(), self.rewatchVal, self.entryIdVal ] cursor = dbConnection2.cursor() cursor.execute(sql, vals) dbConnection2.commit() cursor.close() QToaster.showMessage(self.parentWin, 'Entry Updated', corner=QtCore.Qt.BottomRightCorner) self.parentWin.changed = True self.close() else: print("Error: " + self.errorMessage)