Exemple #1
0
 def reload_if_necessary(self, mainWindow):
     print("MY FILENAME WHEN CALLED:"+self.filename)
     print(os.path.isfile(self.filename))
     if not os.path.isfile(self.filename):
         self.filename = ad.user_data_dir(appname, appauthor) + "/mygames.pgn"
         self.index_current_game = None
     # if still path doesn't exist, we have to create
     # new default pgn from scratch
     print("my filename is now:"+self.filename)
     if(not os.path.isfile(self.filename)):
         self.create_new_pgn()
     else:
         crc = crc32_from_file(self.filename)
         print("crc caluclated: "+str(crc))
         print(self.checksum)
         if not crc == self.checksum:
             try:
                 self.init_from_pgn(mainWindow, mainWindow.trUtf8("Re-loading PGN File..."))
             except BaseException as e:
                 print(e)
                 print("EXECPTION SO CHANING FILENAME")
                 self.filename = ad.user_data_dir(appname, appauthor) + "/mygames.pgn"
                 self.index_current_game = None
                 self.create_new_pgn()
         else:
             print("CHECKSUM EQUAL SO DOING NOTHING")
Exemple #2
0
 def reload_if_necessary(self, mainWindow):
     if not os.path.isfile(self.filename):
         self.filename = ad.user_data_dir(appname,
                                          appauthor) + "/mygames.pgn"
         self.index_current_game = None
     # if still path doesn't exist, we have to create
     # new default pgn from scratch
     if (not os.path.isfile(self.filename)):
         self.create_new_pgn()
     else:
         crc = crc32_from_file(self.filename)
         if not crc == self.checksum:
             try:
                 self.init_from_pgn(
                     mainWindow,
                     mainWindow.trUtf8("Re-loading PGN File..."))
             except BaseException as e:
                 #print(e)
                 self.filename = ad.user_data_dir(
                     appname, appauthor) + "/mygames.pgn"
                 self.index_current_game = None
                 self.create_new_pgn()
         else:
             pass
Exemple #3
0
    def create_on_startup(cls, parentWidget):

        # default gamestate is just entering moves
        gamestate = gs.GameState()
        gamestate.mode = gs.MODE_ENTER_MOVES

        # default active engine is the internal one (Stockfish)
        user_settings = us.UserSettings()
        user_settings.engines.append(us.InternalEngine())
        user_settings.active_engine = user_settings.engines[0]

        database = None

        # if existing, recover game state, user settings, and
        # database that user used before exiting app last time
        # (by unpickling)
        # TODO: replace by proper JSON serialization
        fn = ad.user_data_dir(appname, appauthor)
        save_dir = fn
        try:
            with open(fn+"/current.pgn") as pgn:
                game = chess.pgn.read_game(pgn)
                gamestate.current = game
                gamestate.init_game_tree(mainAppWindow=parentWidget)
            pgn.close()
        except BaseException as e:
            print(e)
            pass
        user_settings.load_from_file(fn+"/settings.ini")
        print("on startup: "+str(user_settings.active_database))
        if(not user_settings.active_database == None):
            database = Database(user_settings.active_database)
        else:
            default_db_path = fn + "/mygames.pgn"
            database = Database(default_db_path)

        return Model(gamestate,database,user_settings, save_dir)
Exemple #4
0
    def create_on_startup(cls, parentWidget):

        # default gamestate is just entering moves
        gamestate = gs.GameState()
        gamestate.mode = gs.MODE_ENTER_MOVES

        # default active engine is the internal one (Stockfish)
        user_settings = us.UserSettings()
        user_settings.engines.append(us.InternalEngine())
        user_settings.active_engine = user_settings.engines[0]

        database = None

        # if existing, recover game state, user settings, and
        # database that user used before exiting app last time
        # (by unpickling)
        # TODO: replace by proper JSON serialization
        fn = ad.user_data_dir(appname, appauthor)
        save_dir = fn
        try:
            with open(fn+os.sep+"current.pgn") as pgn:
                game = chess.pgn.read_game(pgn)
                gamestate.current = game
                gamestate.init_game_tree(mainAppWindow=parentWidget)
            pgn.close()
        except BaseException as e:
            print(e)
            pass
        user_settings.load_from_file(fn+os.sep+"settings.ini")
        if(not user_settings.active_database == None):
            database = Database(user_settings.active_database)
        else:
            default_db_path = fn + os.sep + "mygames.pgn"
            database = Database(default_db_path)

        return Model(gamestate,database,user_settings, save_dir)