def _main_loop(self): """docstring for _main_loop""" try: # this is the mainloop while 1: assert self.cardset is not None id_, random = self.nextgame.id, self.nextgame.random self.nextgame.id, self.nextgame.random = 0, None try: if TOOLKIT == 'kivy': self.gproc.send((id_, random)) logging.info('App: sent for game to start') yield logging.info('App: game proc stopped') else: self.runGame(id_, random) except Exception: # try Klondike if current game fails if id_ == 2: raise # internal error? if DEBUG: raise traceback.print_exc() self.nextgame.id = 2 self.freeGame() continue if self.nextgame.holdgame: assert self.nextgame.id <= 0 try: self.game.gstats.holded = 1 self.game._saveGame(self.fn.holdgame) self.opt.game_holded = self.game.id except Exception: traceback.print_exc() pass self.wm_save_state() # save game geometry geom = (self.canvas.winfo_width(), self.canvas.winfo_height()) if self.opt.save_games_geometry and not self.opt.wm_maximized: self.opt.games_geometry[self.game.id] = geom self.opt.game_geometry = geom self.freeGame() # if self.nextgame.id <= 0: break # load new cardset if self.nextgame.cardset is not self.cardset: self.loadCardset(self.nextgame.cardset, id=self.nextgame.id, update=7 + 256) else: self.requestCompatibleCardsetType(self.nextgame.id) except Exception: traceback.print_exc() pass finally: # hide main window self.wm_withdraw() # destroy_help_html() destroy_find_card_dialog() destroy_solver_dialog() # update options self.opt.last_gameid = id_ # save options try: self.saveOptions() except Exception: traceback.print_exc() pass # save statistics try: self.saveStatistics() except Exception: traceback.print_exc() pass # shut down audio try: self.audio.destroy() except Exception: traceback.print_exc() pass if TOOLKIT == 'kivy': self.top.quit() while True: logging.info('App: mainloop end position') yield
def mainproc(self): # copy startup options self.startup_opt = self.opt.copy() # try to load statistics try: self.loadStatistics() except Exception: traceback.print_exc() pass # startup information if self.getGameClass(self.opt.last_gameid): self.nextgame.id = self.opt.last_gameid # load a holded or saved game id = self.gdb.getGamesIdSortedByName()[0] tmpgame = self.constructGame(id) if self.opt.game_holded > 0 and not self.nextgame.loadedgame: game = None try: game = tmpgame._loadGame(self.fn.holdgame, self) except Exception: traceback.print_exc() game = None if game: if game.id == self.opt.game_holded and game.gstats.holded: game.gstats.loaded = game.gstats.loaded - 1 game.gstats.holded = 0 self.nextgame.loadedgame = game else: # not a holded game game.destruct() destruct(game) game = None if not self.nextgame.loadedgame: if self.commandline.loadgame: try: self.nextgame.loadedgame = tmpgame._loadGame( self.commandline.loadgame, self) self.nextgame.loadedgame.gstats.holded = 0 except Exception: traceback.print_exc() self.nextgame.loadedgame = None elif self.commandline.game is not None: gameid = self.gdb.getGameByName(self.commandline.game) if gameid is None: print_err(_("can't find game: ") + self.commandline.game) sys.exit(-1) else: self.nextgame.id = gameid deal = self.commandline.deal self.nextgame.random = \ None if deal is None else constructRandom(deal) elif self.commandline.gameid is not None: self.nextgame.id, self.nextgame.random = \ self.commandline.gameid, None self.opt.game_holded = 0 tmpgame.destruct() destruct(tmpgame) tmpgame = None # # widgets # # create the menubar if self.intro.progress: self.intro.progress.update(step=1) self.menubar = PysolMenubar(self, self.top, progress=self.intro.progress) # create the statusbar(s) self.statusbar = PysolStatusbar(self.top) self.statusbar.show(self.opt.statusbar) self.statusbar.config('gamenumber', self.opt.statusbar_game_number) self.statusbar.config('stuck', self.opt.statusbar_stuck) self.helpbar = HelpStatusbar(self.top) self.helpbar.show(self.opt.helpbar) # create the canvas self.scrolled_canvas = MfxScrolledCanvas(self.top, propagate=True) self.canvas = self.scrolled_canvas.canvas padx, pady = TkSettings.canvas_padding self.scrolled_canvas.grid(row=1, column=1, sticky='nsew', padx=padx, pady=pady) self.top.grid_columnconfigure(1, weight=1) self.top.grid_rowconfigure(1, weight=1) self.setTile(self.tabletile_index, force=True) # create the toolbar dir = self.getToolbarImagesDir() self.toolbar = PysolToolbar(self.top, self.menubar, dir=dir, size=self.opt.toolbar_size, relief=self.opt.toolbar_relief, compound=self.opt.toolbar_compound) self.toolbar.show(self.opt.toolbar) if TOOLKIT == 'tk': for w, v in self.opt.toolbar_vars.items(): self.toolbar.config(w, v) # if self.intro.progress: self.intro.progress.update(step=1) # if TOOLKIT == 'kivy': self.gproc = self.gameproc() self.gproc.send(None) try: # this is the mainloop while 1: assert self.cardset is not None id_, random = self.nextgame.id, self.nextgame.random self.nextgame.id, self.nextgame.random = 0, None try: if TOOLKIT == 'kivy': self.gproc.send((id_, random)) logging.info('App: sent for game to start') yield logging.info('App: game proc stopped') else: self.runGame(id_, random) except Exception: # try Klondike if current game fails if id_ == 2: raise # internal error? if DEBUG: raise traceback.print_exc() self.nextgame.id = 2 self.freeGame() continue if self.nextgame.holdgame: assert self.nextgame.id <= 0 try: self.game.gstats.holded = 1 self.game._saveGame(self.fn.holdgame) self.opt.game_holded = self.game.id except Exception: traceback.print_exc() pass self.wm_save_state() # save game geometry geom = (self.canvas.winfo_width(), self.canvas.winfo_height()) if self.opt.save_games_geometry and not self.opt.wm_maximized: self.opt.games_geometry[self.game.id] = geom self.opt.game_geometry = geom self.freeGame() # if self.nextgame.id <= 0: break # load new cardset if self.nextgame.cardset is not self.cardset: self.loadCardset(self.nextgame.cardset, id=self.nextgame.id, update=7 + 256) else: self.requestCompatibleCardsetType(self.nextgame.id) except Exception: traceback.print_exc() pass finally: # hide main window self.wm_withdraw() # destroy_help_html() destroy_find_card_dialog() destroy_solver_dialog() # update options self.opt.last_gameid = id_ # save options try: self.saveOptions() except Exception: traceback.print_exc() pass # save statistics try: self.saveStatistics() except Exception: traceback.print_exc() pass # shut down audio try: self.audio.destroy() except Exception: traceback.print_exc() pass if TOOLKIT == 'kivy': self.top.quit() while True: logging.info('App: mainloop end position') yield