Ejemplo n.º 1
0
 def open_database(self):
     dialog = QFileDialog()
     if(self.model.gamestate.last_open_dir != None):
         dialog.setDirectory(self.model.gamestate.last_open_dir)
     filename = dialog.getOpenFileName(self.mainAppWindow.chessboard_view, self.mainAppWindow.trUtf8('Open PGN'), \
                                       None, 'PGN (*.pgn)', QFileDialog.DontUseNativeDialog)
     if filename:
         db = Database(filename)
         db.init_from_pgn(self.mainAppWindow,self.mainAppWindow.trUtf8("Scanning PGN File..."))
         self.model.database = db
         self.model.user_settings.active_database = db.filename
         selectedGame = 0
         if(db.no_of_games() > 1):
             dlg = DialogBrowsePgn(db)
             if dlg.exec_() == QDialog.Accepted:
                 items = dlg.table.selectedItems()
                 selectedGame = int(items[0].text())-1
             else:
                 selectedGame = None
         if(not selectedGame == None and db.no_of_games() > 0):
             loaded_game = db.load_game(selectedGame)
             self.model.gamestate.current = loaded_game
             self.mainAppWindow.chessboard_view.update()
             self.mainAppWindow.chessboard_view.emit(SIGNAL("statechanged()"))
             self.mainAppWindow.save.setEnabled(False)
             self.mainAppWindow.setLabels()
             self.mainAppWindow.moves_edit_view.setFocus()
             self.model.gamestate.last_open_dir = QFileInfo(filename).dir().absolutePath()
             self.model.gamestate.init_game_tree(self.mainAppWindow)
     self.mainAppWindow.moves_edit_view.setFocus()
Ejemplo n.º 2
0
    def browse_games(self):
        mainWindow = self.mainAppWindow
        self.model.database.reload_if_necessary(mainWindow)
        selectedGame = 0
        mainWindow.gamestateController.on_enter_moves_mode()

        dlg = DialogBrowsePgn(self.model.database)
        if dlg.exec_() == QDialog.Accepted:
            items = dlg.table.selectedItems()
            if(len(items) > 0):
                selectedGame = int(items[0].text())-1
                loaded_game = self.model.database.load_game(selectedGame)
                if(not loaded_game == None):
                    # if the user wants to load a game, but the current open
                    # game has still unsaved changes or hasn't been saved at all,
                    # ask user what to do
                    cancel = False
                    if(self.model.database.index_current_game == None or self.model.gamestate.unsaved_changes):
                        changes_dialog = DialogSaveChanges()
                        ret = changes_dialog.exec_()
                        if(ret == QMessageBox.Save):
                            if(self.model.database.index_current_game == None):
                                self.gs_ctr.editGameData()
                                self.model.database.append_game(self.model.gamestate.current)
                            else:
                                self.model.database.update_game(self.model.database.index_current_game,\
                                                        self.model.gamestate.current)
                            self.mainAppWindow.save.setEnabled(False)
                        if(ret == QMessageBox.Cancel):
                            cancel = True
                    if(not cancel):
                        self.model.gamestate.current = loaded_game
                        self.mainAppWindow.chessboard_view.update()
                        self.mainAppWindow.chessboard_view.emit(SIGNAL("statechanged()"))
                        self.model.gamestate.unsaved_changes = False
                        self.mainAppWindow.save.setEnabled(False)
                        self.mainAppWindow.setLabels()
                        self.mainAppWindow.moves_edit_view.setFocus()
                        self.model.gamestate.init_game_tree(self.mainAppWindow)

        self.mainAppWindow.moves_edit_view.setFocus()