def new_board(self, sgf_model=None, collection_model=None, from_file='', mode='Play', gridsize=19, handicap=0, goto=True): toast('Loading sgf', False) load_from_file = False t1 = time() # Get a collection and collectionsgf to contain and represent the board filen = from_file if sgf_model is not None: sgf = sgf_model if sgf.filename: filen = sgf.filename load_from_file = True elif collection_model is not None: sgf = Sgf() sgf.save() collectionsgf = CollectionSgf(collection=collection_model, sgf=sgf) collectionsgf.save() load_from_file = False if from_file != '': load_from_file = True filen = from_file sgf.filename = filen else: collection = get_default_collection() print 'default collection is', collection sgf = Sgf() sgf.save() print 'made sgf' collectionsgf = CollectionSgf(collection=collection, sgf=sgf) collectionsgf.save() print 'made collectionsgf' load_from_file = False if from_file != '': load_from_file = True filen = from_file sgf.filename = filen t2 = time() print 't2 - t1 is...', t2-t1 if filen == '': sgf.auto_filename() load_from_file = False t3 = time() # Work out what screen name is free to put it in i = 1 while True: if not self.has_screen('Board %d' % i): name = 'Board %d' % i break i += 1 s = Screen(name=name) self.add_widget(s) if goto: self.current = name t4 = time() if self.view_mode[:6] == 'tablet': pbv = TabletBoardView(sgf_model=sgf) else: pbv = PhoneBoardView(sgf_model=sgf) pbv.board.sgf_model = sgf # if platform() == 'android': # #set_board_height(pbv.boardcontainer) # pbv.boardcontainer.set_board_height() if sgf.gridsize: gridsize = sgf.gridsize pbv.board.gridsize = gridsize t5 = time() print ' LOAD FROM FILE!?' if load_from_file: print 'YES' print 'Trying to load from', filen try: pbv.board.load_sgf_from_file('',[filen]) except: print 'Exception occurred, making popup' popup = Popup(content=Label(text= ('Unable to open SGF. Please check' 'the file exists and is a valid SGF.'), title='Error opening file'), size_hint=(0.85, 0.4), title='Error') print 'popup made' popup.open() #self.close_board(name) return False pbv.board.reset_gridsize(gridsize) pbv.board.add_handicap_stones(handicap) pbv.board.time_start() s.add_widget(pbv) pbv.screenname = name pbv.managedby = self pbv.spinner.text = mode pbv.board.touchoffset = self.touchoffset pbv.board.coordinates = self.coordinates pbv.board.board_path = boardname_to_filepath(self.boardtype) pbv.board.display_markers = self.display_markers pbv.board.cache = App.get_running_app().cache pbv.board.get_game_info() self.boards.append(name) if self.view_mode[:6] == 'tablet': pbv.board.comment_pre_text = 'This [b]tablet mode[/b] is currently experimental. It should work fine, but is still being tested and will be subject to change (more efficient layout etc.) and speed optimisation before being finalised.\n-----\n' t6 = time() print 'timings are' print t6-t1, t6-t5, t5-t4, t4-t3, t3-t2, t2-t1 self.refresh_open_games() self.collectionindex_to_refresh = True if collection_model is not None: if collection_model.name not in self.collections_to_refresh: self.collections_to_refresh.append(collection_model.name) pbv.board.save_sgf() return pbv
def new_board(self,with_collectionsgf=None,in_collection=None,from_file='',mode='Play',gridsize=19,handicap=0,goto=True): load_from_file = False App.get_running_app().build_collections_list() print '%% NEW BOARD' print with_collectionsgf, in_collection, from_file print type(from_file) t1 = time() # Get a collection and collectionsgf to contain and represent the board filen = from_file if with_collectionsgf is not None: collectionsgf = with_collectionsgf filen = collectionsgf.filen collection = collectionsgf.collection newboard = False load_from_file = True elif in_collection is not None: collection = in_collection collectionsgf = collection.add_game(can_change_name=True) load_from_file = False if from_file != '': load_from_file = True filen = from_file collectionsgf.filen = filen collectionsgf.can_change_name = False else: collection = App.get_running_app().get_default_collection() collectionsgf = collection.add_game() print 'Made new collectionsgf for the game',collectionsgf load_from_file = False if from_file != '': load_from_file = True filen = from_file collectionsgf.filen = filen collectionsgf.can_change_name = False t2 = time() print 't2 - t1 is...',t2-t1 if filen == '' and with_collectionsgf is None: collectionsgf.filen = collectionsgf.get_default_filen() + '.sgf' filen = collectionsgf.filen load_from_file = False t3 = time() # Work out what screen name is free to put it in i = 1 while True: if not self.has_screen('Board %d' % i): name = 'Board %d' % i break i += 1 s = Screen(name=name) self.add_widget(s) if goto: self.current = name t4 = time() if self.view_mode == 'tablet': pbv = TabletBoardView(collectionsgf=collectionsgf) else: pbv = PhoneBoardView(collectionsgf=collectionsgf) pbv.board.collectionsgf = collectionsgf # if platform() == 'android': # #set_board_height(pbv.boardcontainer) # pbv.boardcontainer.set_board_height() gi = collectionsgf.gameinfo if 'gridsize' in gi: gridsize = gi['gridsize'] pbv.board.gridsize = gridsize t5 = time() if load_from_file: print 'Trying to load from',filen try: pbv.board.load_sgf_from_file('',[filen]) except: print 'Exception occurred, making popup' popup = Popup(content=Label(text='Unable to open SGF. Please check the file exists and is a valid SGF.',title='Error opening file'),size_hint=(0.85,0.4),title='Error') print 'popup made' popup.open() #self.close_board(name) return False else: pbv.board.reset_gridsize(gridsize) pbv.board.add_handicap_stones(handicap) pbv.board.time_start() s.add_widget(pbv) pbv.screenname = name pbv.managedby = self pbv.spinner.text = mode pbv.board.touchoffset = self.touchoffset pbv.board.coordinates = self.coordinates pbv.board.board_path = boardname_to_filepath(self.boardtype) pbv.board.display_markers = self.display_markers pbv.board.cache = App.get_running_app().cache pbv.board.get_game_info() pbv.board.save_sgf() self.boards.append(name) if self.view_mode == 'tablet': pbv.board.comment_pre_text = 'This [b]tablet mode[/b] is currently experimental. It should work fine, but is still being tested and will be subject to change (more efficient layout etc.) and speed optimisation before being finalised.\n-----\n' t6 = time() print 'timings are' print t6-t1, t6-t5, t5-t4, t4-t3, t3-t2, t2-t1 return pbv