Esempio n. 1
0
    def refreshView(self):

        self.clear()

        self.playerObjects = []

        # Get player names
        players = dbu.Database().getPlayerNames()

        for name in players:
            # Fill the list with player names

            player = dbu.Database().getPlayerByName(name[0])  # get all players

            playerObj = ply.Player(player[0][1])  # create player objects
            # set players stats
            playerObj.setGender(player[0][2])
            playerObj.setGames(player[0][3])
            playerObj.setWins(player[0][4])
            playerObj.setRounds(player[0][5])
            playerObj.setAvatar()
            playerObj.setId()

            # create list item
            self.items = PlayerItem(playerObj, self)

            self.playerObjects.append(playerObj)
Esempio n. 2
0
    def setWatched(self):

        selectedMovie = self.getSelectedMovie()

        if selectedMovie:

            if selectedMovie.watched == 0:
                selectedMovie.watched = 1
                DB_utils.update_movie_status(selectedMovie.id,
                                             selectedMovie.watched)
            else:
                selectedMovie.watched = 0
                DB_utils.update_movie_status(selectedMovie.id,
                                             selectedMovie.watched)

            self.refresh()
Esempio n. 3
0
    def quitMsg(self):

        msgBox = QMessageBox()
        msgBox.setText("Are you sure to quit? All unsaved data will be lost!")
        msgBox.setStandardButtons(QMessageBox.Save | QMessageBox.Discard
                                  | QMessageBox.Cancel)
        msgBox.setDefaultButton(QMessageBox.Save)
        ret = msgBox.exec_()

        if ret == QMessageBox.Save:
            # Save was clicked - save game dialog
            pass

        elif ret == QMessageBox.Discard:
            # Don't save was clicked - exitting into main menu
            self.mainWindow.backToMainMenu()
            self.mainWindow.btnQuit.hide()
            self.mainWindow.playerList.btnRemovePlayer.hide()
            self.mainWindow.playerList.btnEditPlayer.hide()
            self.mainWindow.playerList.btnAddPlayer.hide()

            if self.mainWindow.gameWidget.isVisible():

                for i in self.mainWindow.playerList.browser.playerObjects:

                    print(i.name)
                    print(i.currentLevel)
                    print(i.currentBonus)
                    print(
                        int(i.rounds) +
                        int(self.mainWindow.gameWidget.game.rounds))
                    print("--")

                    rounds = int(i.rounds) + int(
                        self.mainWindow.gameWidget.game.rounds - 1)

                    print("rounds: " + str(rounds))

                    dbu.Database().update(id=i.id,
                                          name=i.name,
                                          gamesplayed=int(i.games),
                                          wins=int(i.wins),
                                          roundsplayed=int(rounds))

                self.mainWindow.gameWidget.hide()

            self.mainWindow.setMaximumSize(600, 800)
            self.mainWindow.setMinimumSize(600, 800)
            self.mainWindow.resize(600, 800)

        elif ret == QMessageBox.Cancel:
            # cancel was clicked
            self.mainWindow.gameWidget.setVisible(True)
            return
        else:
            pass
Esempio n. 4
0
    def keyPressEvent(self, event):

        selectedMovie = self.getSelectedMovie()

        if event.key() == Qt.Key_Delete:
            if not selectedMovie: return

            poster = selectedMovie.path[:-4] + ".jpg"

            msg = QMessageBox(self)
            msg.setIcon(QMessageBox.Warning)
            msg.setText(
                "Are you sure you want to delete %s? \nThe file will be deleted as well."
                % selectedMovie.name)
            msg.setWindowTitle("Deleting movie")
            msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)

            if msg.exec_() == QMessageBox.Ok:
                print "Deleting: " + str(selectedMovie.name)

                try:
                    DB_utils.delete_movie(selectedMovie.id)
                    print "Movie deleted from MongoDB..."
                except:
                    print "Error deleting movie from MongoDB " + str(
                        selectedMovie.id)
                try:
                    fileUtils.delete_movie_file(selectedMovie.path)
                    print "Movie file deleted..."
                except:
                    print "Error deleting movie file: " + str(
                        selectedMovie.path)
                try:
                    fileUtils.delete_movie_file(poster)
                    print "Deleting poster: " + str(poster)
                except:
                    print "Error deleting movie poster: " + str(poster)

                self.takeItem(self.row(self.currentItem()))
                selectedMovie.delete()
Esempio n. 5
0
def downloadWorker(queue, dataDownloader):
    while not queue.empty():
        movieObj = queue.get()

        movieData = getMovieDataFromTMDB(movieObj.name)

        posterPath = downloadPoster(movieObj.path, movieData["poster_path"])

        movieData["poster"] = posterPath
        movieData["path"] = movieObj.path
        movieData["watched"] = 0
        movieData["_id"] = DB_utils.insert_movie(movieData)

        movieObj.setData(movieData)

        dataDownloader.downloadFinished.emit()
Esempio n. 6
0
    def setCurrentFolder(self):

        self.movieObjects = []
        self.currentFolder = self.currentItem().path

        files = fileUtils.get_movies(self.currentFolder)

        for filePath in files:
            movieObj = movie.Movie(filePath)

            # Check in DataBase
            movieData = DB_utils.get_movies_by_path(movieObj.path)

            if movieData:
                movieObj.setData(movieData)
            else:
                self.dataDownloader.addMovie(movieObj)

            self.movieObjects.append(movieObj)

        self.dataDownloader.startDownload()
Esempio n. 7
0
    def removePlayer(self):

        dbu.Database().removePlayer(self.browser.getCurrentPlayer().name,
                                    self.browser.getCurrentPlayer().games,
                                    self.browser.getCurrentPlayer().wins)
        self.browser.refreshView()
Esempio n. 8
0
    def savePlayer(self):

        name = self.txtPlayerName.toPlainText()

        # check name
        if name:
            if len(name) < 1:
                raise TypeError
        else:
            msg1 = QMessageBox()
            msg1.setText("Player name is not given.")
            msg1.exec_()
            return

        # Check radiobuttons value
        if self.rbtnMale.isChecked():
            gender = "male"
        elif self.rbtnFemale.isChecked():
            gender = "female"
        else:
            msg1 = QMessageBox()
            msg1.setText("Select gender.")
            msg1.exec_()

        gamesPlayed = self.txtPlayerGames.toPlainText()

        # Check games played
        if gamesPlayed:

            try:
                gamesPlayed = int(gamesPlayed)

                if gamesPlayed < 0:
                    raise TypeError
                else:
                    gamesPlayed = str(gamesPlayed)
            except:
                msg2 = QMessageBox()
                msg2.setText(
                    "Invalid number in Games played.\n\nValid: 0-9999")
                msg2.exec_()
                return
        else:
            msg2 = QMessageBox()
            msg2.setText("Number of played games is not given.")
            msg2.exec_()
            return

        wins = self.txtPlayerWins.toPlainText()

        # Check number of wins
        if wins:
            try:
                wins = int(wins)
                if wins < 0:
                    raise TypeError
                else:
                    wins = str(wins)
            except:
                msg3 = QMessageBox()
                msg3.setText("Invalid number in Wins field.\n\nValid: 0-9999")
                msg3.exec_()
                return
        else:
            msg3 = QMessageBox()
            msg3.setText("Number of won games is not given.")
            msg3.exec_()
            return

        id = dbu.Database().getPlayerId(self.name, self.games, self.wins)[0][0]

        dbu.Database().updateAll(id, self.txtPlayerName.toPlainText(),
                                 str(gender),
                                 int(self.txtPlayerGames.toPlainText()),
                                 int(self.txtPlayerWins.toPlainText()),
                                 int(self.txtPlayedRounds.toPlainText()))

        self.hide()
        self.playerList.btnAddPlayer.show()
        self.playerList.btnEditPlayer.show()
        self.playerList.browser.show()
        self.playerList.btnRemovePlayer.show()
        self.playerList.mainWindow.btnBack.show()
        self.playerList.mainWindow.btnStartGame.show()

        self.playerList.setMaximumSize(600, 800)

        self.playerList.browser.refreshView()