def on_all_engine_discovered(discoverer): engine = discoverer.getEngineByName(discoverer.getEngineLearn()) if engine is None: engine = discoverer.getEngineN(-1) default_engine = engine.get("md5") conf.set("ana_combobox", default_engine) conf.set("inv_ana_combobox", default_engine)
def startClicked(self, button): color = self.widgets["colorDock"].get_child().active if color == 2: color = random.choice([WHITE, BLACK]) opponent = self.widgets["opponentDock"].get_child().active difficulty = int(self.widgets["skillSlider"].get_value()) gamemodel = GameModel(TimeModel(5 * 60, 0)) name = conf.get("firstName", _("You")) player0tup = (LOCAL, Human, (color, name), name) if opponent == 0: name = conf.get("secondName", _("Guest")) player1tup = (LOCAL, Human, (1 - color, name), name) else: engine = discoverer.getEngineN(opponent - 1) name = discoverer.getName(engine) player1tup = (ARTIFICIAL, discoverer.initPlayerEngine, (engine, 1 - color, difficulty, variants[NORMALCHESS], 5 * 60, 0), name) if color == WHITE: ionest.generalStart(gamemodel, player0tup, player1tup) else: ionest.generalStart(gamemodel, player1tup, player0tup)
def startClicked(self, button): color = self.widgets["colorDock"].get_child().active if color == 2: color = random.choice([WHITE, BLACK]) opponent = self.widgets["opponentDock"].get_child().active difficulty = int(self.widgets["skillSlider"].get_value()) gamemodel = GameModel(TimeModel(5 * 60, 0)) name = conf.get("firstName", _("You")) player0tup = (LOCAL, Human, (color, name), name) if opponent == 0: name = conf.get("secondName", _("Guest")) player1tup = (LOCAL, Human, (1 - color, name), name) else: engine = discoverer.getEngineN(opponent - 1) name = discoverer.getName(engine) player1tup = (ARTIFICIAL, discoverer.initPlayerEngine, (engine, 1 - color, difficulty, variants[NORMALCHESS], 5 * 60, 0), name) if color == WHITE: game_handler.generalStart(gamemodel, player0tup, player1tup) else: game_handler.generalStart(gamemodel, player1tup, player0tup)
def onResponse(dialog, res): cls.widgets["newgamedialog"].hide() cls.widgets["newgamedialog"].disconnect(handlerId) if res != gtk.RESPONSE_OK: return # Find variant if cls.widgets["playNormalRadio"].get_active(): variant_index = NORMALCHESS elif cls.widgets["playVariant1Radio"].get_active(): variant_index = conf.get("ngvariant1", FISCHERRANDOMCHESS) else: variant_index = conf.get("ngvariant2", LOSERSCHESS) variant = variants[variant_index] # Find time if cls.widgets["notimeRadio"].get_active(): secs = 0 incr = 0 elif cls.widgets["blitzRadio"].get_active(): secs = cls.widgets["ngblitz min"].get_value_as_int()*60 incr = cls.widgets["ngblitz gain"].get_value_as_int() elif cls.widgets["rapidRadio"].get_active(): secs = cls.widgets["ngrapid min"].get_value_as_int()*60 incr = cls.widgets["ngrapid gain"].get_value_as_int() elif cls.widgets["normalRadio"].get_active(): secs = cls.widgets["ngnormal min"].get_value_as_int()*60 incr = cls.widgets["ngnormal gain"].get_value_as_int() # Find players player0 = cls.widgets["whitePlayerCombobox"].get_active() player0 = playerItems[0].index(playerItems[variant_index][player0]) diffi0 = int(cls.widgets["skillSlider1"].get_value()) player1 = cls.widgets["blackPlayerCombobox"].get_active() player1 = playerItems[0].index(playerItems[variant_index][player1]) diffi1 = int(cls.widgets["skillSlider2"].get_value()) # Prepare players for ionest playertups = [] for i, playerno, diffi, color in ((0, player0, diffi0, WHITE), (1, player1, diffi1, BLACK)): if playerno > 0: engine = discoverer.getEngineN (playerno-1) name = discoverer.getName(engine) playertups.append((ARTIFICIAL, discoverer.initPlayerEngine, (engine, color, diffi, variant, secs, incr), name)) else: playertups.append((LOCAL, Human, (color, ""), _("Human"))) if secs > 0: timemodel = TimeModel (secs, incr) else: timemodel = None gamemodel = GameModel (timemodel, variant) callback(gamemodel, playertups[0], playertups[1])
def onResponse(dialog, response): if response == COPY: clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.set_text(cls.get_fen(), -1) #print("put clipboard:", clipboard.wait_for_text()) return elif response == CLEAR: cls.board_control.emit("action", "SETUP", True) cls.ini_widgets(True) #print("clear") return elif response == PASTE: clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) text = clipboard.wait_for_text() #print("got clipboard:", text) if len(text.split()) < 2: return try: lboard = cls.setupmodel.variant(setup=text).board cls.ini_widgets(lboard.asFen()) cls.board_control.emit("action", "SETUP", text) except SyntaxError as e: d = Gtk.MessageDialog (type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK, message_format=e.args[0]) if len(e.args) > 1: d.format_secondary_text (e.args[1]) d.connect("response", lambda d,a: d.hide()) d.show() return elif response != Gtk.ResponseType.OK: cls.widgets["newgamedialog"].hide() cls.widgets["newgamedialog"].disconnect(handlerId) return if hasattr(cls, "board_control"): cls.board_control.emit("action", "CLOSE", None) # Find variant if cls.widgets["playNormalRadio"].get_active(): variant_index = NORMALCHESS elif cls.widgets["playVariant1Radio"].get_active(): variant_index = conf.get("ngvariant1", FISCHERRANDOMCHESS) else: variant_index = conf.get("ngvariant2", LOSERSCHESS) variant = variants[variant_index] # Find time if cls.widgets["notimeRadio"].get_active(): secs = 0 incr = 0 elif cls.widgets["blitzRadio"].get_active(): secs = cls.ngblitz_min.get_value_as_int()*60 incr = cls.ngblitz_gain.get_value_as_int() elif cls.widgets["rapidRadio"].get_active(): secs = cls.ngrapid_min.get_value_as_int()*60 incr = cls.ngrapid_gain.get_value_as_int() elif cls.widgets["normalRadio"].get_active(): secs = cls.ngnormal_min.get_value_as_int()*60 incr = cls.ngnormal_gain.get_value_as_int() # Find players player0 = cls.widgets["whitePlayerCombobox"].get_active() player0 = playerItems[0].index(playerItems[variant_index][player0]) diffi0 = int(cls.widgets["skillSlider1"].get_value()) player1 = cls.widgets["blackPlayerCombobox"].get_active() player1 = playerItems[0].index(playerItems[variant_index][player1]) diffi1 = int(cls.widgets["skillSlider2"].get_value()) # Prepare players for ionest playertups = [] for i, playerno, diffi, color in ((0, player0, diffi0, WHITE), (1, player1, diffi1, BLACK)): if playerno > 0: engine = discoverer.getEngineN (playerno-1) name = discoverer.getName(engine) playertups.append((ARTIFICIAL, discoverer.initPlayerEngine, [engine, color, diffi, variant, secs, incr], name)) else: if not playertups or playertups[0][0] != LOCAL: name = conf.get("firstName", _("You")) else: name = conf.get("secondName", _("Guest")) playertups.append((LOCAL, Human, (color, name), name)) # Set forcePonderOff initPlayerEngine param True in engine-engine games if playertups[0][0] == ARTIFICIAL and playertups[1][0] == ARTIFICIAL: playertups[0][2].append(True) playertups[1][2].append(True) timemodel = TimeModel (secs, incr) gamemodel = GameModel (timemodel, variant) if not validate(gamemodel): return else: cls.widgets["newgamedialog"].hide() cls.widgets["newgamedialog"].disconnect(handlerId) callback(gamemodel, playertups[0], playertups[1])
def __init__(self, widgets): self.widgets = widgets # Options on by default for key in ("opening_check", "endgame_check", "online_egtb_check", "analyzer_check", "inv_analyzer_check"): uistuff.keep(widgets[key], key, first_value=True) # Opening book default_path = os.path.join(addDataPrefix("pychess_book.bin")) path = conf.get("opening_file_entry", default_path) conf.set("opening_file_entry", path) book_chooser_dialog = Gtk.FileChooserDialog( _("Select book file"), mainwindow(), Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) book_chooser_button = Gtk.FileChooserButton.new_with_dialog( book_chooser_dialog) filter = Gtk.FileFilter() filter.set_name(_("Opening books")) filter.add_pattern("*.bin") book_chooser_dialog.add_filter(filter) book_chooser_button.set_filename(path) self.widgets["bookChooserDock"].add(book_chooser_button) book_chooser_button.show() def select_new_book(button): new_book = book_chooser_dialog.get_filename() if new_book: conf.set("opening_file_entry", new_book) else: # restore the original book_chooser_dialog.set_filename(path) book_chooser_button.connect("file-set", select_new_book) def on_opening_check_toggled(check): self.widgets["opening_hbox"].set_sensitive(check.get_active()) self.widgets["opening_check"].connect_after("toggled", on_opening_check_toggled) # Endgame default_path = os.path.join(getDataPrefix()) egtb_path = conf.get("egtb_path", default_path) conf.set("egtb_path", egtb_path) egtb_chooser_dialog = Gtk.FileChooserDialog( _("Select Gaviota TB path"), mainwindow(), Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) egtb_chooser_button = Gtk.FileChooserButton.new_with_dialog( egtb_chooser_dialog) egtb_chooser_button.set_current_folder(egtb_path) self.widgets["egtbChooserDock"].add(egtb_chooser_button) egtb_chooser_button.show() def select_egtb(button): new_directory = egtb_chooser_dialog.get_filename() if new_directory != egtb_path: conf.set("egtb_path", new_directory) egtb_chooser_button.connect("current-folder-changed", select_egtb) def on_endgame_check_toggled(check): self.widgets["endgame_hbox"].set_sensitive(check.get_active()) self.widgets["endgame_check"].connect_after("toggled", on_endgame_check_toggled) # Analyzing engines from pychess.widgets import newGameDialog data = [(item[0], item[1]) for item in newGameDialog.analyzerItems] uistuff.createCombo(widgets["ana_combobox"], data, name="ana_combobox") uistuff.createCombo(widgets["inv_ana_combobox"], data, name="inv_ana_combobox") def update_analyzers_store(discoverer): data = [(item[0], item[1]) for item in newGameDialog.analyzerItems] uistuff.updateCombo(widgets["ana_combobox"], data) uistuff.updateCombo(widgets["inv_ana_combobox"], data) discoverer.connect_after("all_engines_discovered", update_analyzers_store) update_analyzers_store(discoverer) # Save, load and make analyze combos active # Let Stockfish to be default analyzer in Windows installer default = discoverer.getEngineN(-1).get("md5") conf.set("ana_combobox", conf.get("ana_combobox", default)) conf.set("inv_ana_combobox", conf.get("inv_ana_combobox", default)) def on_analyzer_check_toggled(check): self.widgets["analyzers_vbox"].set_sensitive(check.get_active()) from pychess.widgets.gamewidget import widgets perspective = perspective_manager.get_perspective("games") if len(perspective.gamewidgets) != 0: if check.get_active(): for gmwidg in perspective.gamewidgets: asyncio. async ( gmwidg.gamemodel.restart_analyzer(HINT)) if not widgets["hint_mode"].get_active(): gmwidg.gamemodel.pause_analyzer(HINT) else: for gmwidg in perspective.gamewidgets: gmwidg.gamemodel.remove_analyzer(HINT) self.widgets["analyzers_vbox"].set_sensitive( widgets["analyzer_check"].get_active()) self.widgets["analyzer_check"].connect_after( "toggled", on_analyzer_check_toggled) def on_invanalyzer_check_toggled(check): self.widgets["inv_analyzers_vbox"].set_sensitive( check.get_active()) perspective = perspective_manager.get_perspective("games") if len(perspective.gamewidgets) != 0: if check.get_active(): for gmwidg in perspective.gamewidgets: asyncio. async (gmwidg.gamemodel.restart_analyzer(SPY)) if not widgets["spy_mode"].get_active(): gmwidg.gamemodel.pause_analyzer(SPY) else: for gmwidg in perspective.gamewidgets: gmwidg.gamemodel.remove_analyzer(SPY) self.widgets["inv_analyzers_vbox"].set_sensitive( widgets["inv_analyzer_check"].get_active()) self.widgets["inv_analyzer_check"].connect_after( "toggled", on_invanalyzer_check_toggled) # Give widgets to keeper uistuff.keep( self.widgets["ana_combobox"], "ana_combobox", anal_combo_get_value, lambda combobox, value: anal_combo_set_value( combobox, value, "hint_mode", "analyzer_check", HINT)) uistuff.keep( self.widgets["inv_ana_combobox"], "inv_ana_combobox", anal_combo_get_value, lambda combobox, value: anal_combo_set_value( combobox, value, "spy_mode", "inv_analyzer_check", SPY)) uistuff.keep(self.widgets["max_analysis_spin"], "max_analysis_spin", first_value=3)
def onResponse(dialog, response): if response == COPY: clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clipboard.set_text(cls.get_fen(), -1) #print("put clipboard:", clipboard.wait_for_text()) return elif response == CLEAR: cls.board_control.emit("action", "SETUP", True) cls.ini_widgets(True) #print("clear") return elif response == PASTE: clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) text = clipboard.wait_for_text() #print("got clipboard:", text) if len(text.split()) < 2: return try: lboard = cls.setupmodel.variant(setup=text).board cls.ini_widgets(lboard.asFen()) cls.board_control.emit("action", "SETUP", text) except SyntaxError as e: d = Gtk.MessageDialog(type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK, message_format=e.args[0]) if len(e.args) > 1: d.format_secondary_text(e.args[1]) d.connect("response", lambda d, a: d.hide()) d.show() return elif response != Gtk.ResponseType.OK: cls.widgets["newgamedialog"].hide() cls.widgets["newgamedialog"].disconnect(handlerId) return if hasattr(cls, "board_control"): cls.board_control.emit("action", "CLOSE", None) # Find variant if cls.widgets["playNormalRadio"].get_active(): variant_index = NORMALCHESS elif cls.widgets["playVariant1Radio"].get_active(): variant_index = conf.get("ngvariant1", FISCHERRANDOMCHESS) else: variant_index = conf.get("ngvariant2", LOSERSCHESS) variant = variants[variant_index] # Find time if cls.widgets["notimeRadio"].get_active(): secs = 0 incr = 0 elif cls.widgets["blitzRadio"].get_active(): secs = cls.ngblitz_min.get_value_as_int() * 60 incr = cls.ngblitz_gain.get_value_as_int() elif cls.widgets["rapidRadio"].get_active(): secs = cls.ngrapid_min.get_value_as_int() * 60 incr = cls.ngrapid_gain.get_value_as_int() elif cls.widgets["normalRadio"].get_active(): secs = cls.ngnormal_min.get_value_as_int() * 60 incr = cls.ngnormal_gain.get_value_as_int() # Find players player0 = cls.widgets["whitePlayerCombobox"].get_active() player0 = playerItems[0].index(playerItems[variant_index][player0]) diffi0 = int(cls.widgets["skillSlider1"].get_value()) player1 = cls.widgets["blackPlayerCombobox"].get_active() player1 = playerItems[0].index(playerItems[variant_index][player1]) diffi1 = int(cls.widgets["skillSlider2"].get_value()) # Prepare players for ionest playertups = [] for i, playerno, diffi, color in ((0, player0, diffi0, WHITE), (1, player1, diffi1, BLACK)): if playerno > 0: engine = discoverer.getEngineN(playerno - 1) name = discoverer.getName(engine) playertups.append( (ARTIFICIAL, discoverer.initPlayerEngine, [engine, color, diffi, variant, secs, incr], name)) else: if not playertups or playertups[0][0] != LOCAL: name = conf.get("firstName", _("You")) else: name = conf.get("secondName", _("Guest")) playertups.append((LOCAL, Human, (color, name), name)) # Set forcePonderOff initPlayerEngine param True in engine-engine games if playertups[0][0] == ARTIFICIAL and playertups[1][ 0] == ARTIFICIAL: playertups[0][2].append(True) playertups[1][2].append(True) timemodel = TimeModel(secs, incr) gamemodel = GameModel(timemodel, variant) if not validate(gamemodel): return else: cls.widgets["newgamedialog"].hide() cls.widgets["newgamedialog"].disconnect(handlerId) callback(gamemodel, playertups[0], playertups[1])
def __init__(self, widgets): self.widgets = widgets # Options on by default for key in ("opening_check", "endgame_check", "online_egtb_check", "analyzer_check", "inv_analyzer_check"): uistuff.keep(widgets[key], key, first_value=True) # Opening book default_path = os.path.join(addDataPrefix("pychess_book.bin")) path = conf.get("opening_file_entry", default_path) conf.set("opening_file_entry", path) book_chooser_dialog = Gtk.FileChooserDialog( _("Select book file"), None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) book_chooser_button = Gtk.FileChooserButton.new_with_dialog( book_chooser_dialog) filter = Gtk.FileFilter() filter.set_name(_("Opening books")) filter.add_pattern("*.bin") book_chooser_dialog.add_filter(filter) book_chooser_button.set_filename(path) self.widgets["bookChooserDock"].add(book_chooser_button) book_chooser_button.show() def select_new_book(button): new_book = book_chooser_dialog.get_filename() if new_book: conf.set("opening_file_entry", new_book) else: # restore the original book_chooser_dialog.set_filename(path) book_chooser_button.connect("file-set", select_new_book) def on_opening_check_toggled(check): self.widgets["opening_hbox"].set_sensitive(check.get_active()) self.widgets["opening_check"].connect_after("toggled", on_opening_check_toggled) # Endgame default_path = os.path.join(getDataPrefix()) egtb_path = conf.get("egtb_path", default_path) conf.set("egtb_path", egtb_path) egtb_chooser_dialog = Gtk.FileChooserDialog( _("Select Gaviota TB path"), None, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) egtb_chooser_button = Gtk.FileChooserButton.new_with_dialog( egtb_chooser_dialog) egtb_chooser_button.set_current_folder(egtb_path) self.widgets["egtbChooserDock"].add(egtb_chooser_button) egtb_chooser_button.show() def select_egtb(button): new_directory = egtb_chooser_dialog.get_filename() if new_directory != egtb_path: conf.set("egtb_path", new_directory) egtb_chooser_button.connect("current-folder-changed", select_egtb) def on_endgame_check_toggled(check): self.widgets["endgame_hbox"].set_sensitive(check.get_active()) self.widgets["endgame_check"].connect_after("toggled", on_endgame_check_toggled) # Analyzing engines from pychess.widgets import newGameDialog data = [(item[0], item[1]) for item in newGameDialog.analyzerItems] uistuff.createCombo(widgets["ana_combobox"], data, name="ana_combobox") uistuff.createCombo(widgets["inv_ana_combobox"], data, name="inv_ana_combobox") def update_analyzers_store(discoverer): data = [(item[0], item[1]) for item in newGameDialog.analyzerItems] uistuff.updateCombo(widgets["ana_combobox"], data) uistuff.updateCombo(widgets["inv_ana_combobox"], data) discoverer.connect_after("all_engines_discovered", update_analyzers_store) update_analyzers_store(discoverer) # Save, load and make analyze combos active # Let Stockfish to be default analyzer in Windows installer default = discoverer.getEngineN(-1).get("md5") conf.set("ana_combobox", conf.get("ana_combobox", default)) conf.set("inv_ana_combobox", conf.get("inv_ana_combobox", default)) def on_analyzer_check_toggled(check): self.widgets["analyzers_vbox"].set_sensitive(check.get_active()) from pychess.widgets.gamewidget import widgets perspective = perspective_manager.get_perspective("games") if len(perspective.gamewidgets) != 0: if check.get_active(): for gmwidg in perspective.gamewidgets: asyncio.async(gmwidg.gamemodel.restart_analyzer(HINT)) if not widgets["hint_mode"].get_active(): gmwidg.gamemodel.pause_analyzer(HINT) else: for gmwidg in perspective.gamewidgets: gmwidg.gamemodel.remove_analyzer(HINT) self.widgets["analyzers_vbox"].set_sensitive(widgets[ "analyzer_check"].get_active()) self.widgets["analyzer_check"].connect_after("toggled", on_analyzer_check_toggled) def on_invanalyzer_check_toggled(check): self.widgets["inv_analyzers_vbox"].set_sensitive(check.get_active()) perspective = perspective_manager.get_perspective("games") if len(perspective.gamewidgets) != 0: if check.get_active(): for gmwidg in perspective.gamewidgets: asyncio.async(gmwidg.gamemodel.restart_analyzer(SPY)) if not widgets["spy_mode"].get_active(): gmwidg.gamemodel.pause_analyzer(SPY) else: for gmwidg in perspective.gamewidgets: gmwidg.gamemodel.remove_analyzer(SPY) self.widgets["inv_analyzers_vbox"].set_sensitive(widgets[ "inv_analyzer_check"].get_active()) self.widgets["inv_analyzer_check"].connect_after( "toggled", on_invanalyzer_check_toggled) # Give widgets to keeper uistuff.keep( self.widgets["ana_combobox"], "ana_combobox", anal_combo_get_value, lambda combobox, value: anal_combo_set_value(combobox, value, "hint_mode", "analyzer_check", HINT)) uistuff.keep( self.widgets["inv_ana_combobox"], "inv_ana_combobox", anal_combo_get_value, lambda combobox, value: anal_combo_set_value(combobox, value, "spy_mode", "inv_analyzer_check", SPY)) uistuff.keep(self.widgets["max_analysis_spin"], "max_analysis_spin", first_value=3)
def onResponse(dialog, res): if res != Gtk.ResponseType.OK: cls.widgets["newgamedialog"].hide() cls.widgets["newgamedialog"].disconnect(handlerId) return # Find variant if cls.widgets["playNormalRadio"].get_active(): variant_index = NORMALCHESS elif cls.widgets["playVariant1Radio"].get_active(): variant_index = conf.get("ngvariant1", FISCHERRANDOMCHESS) else: variant_index = conf.get("ngvariant2", LOSERSCHESS) variant = variants[variant_index] # Find time if cls.widgets["notimeRadio"].get_active(): secs = 0 incr = 0 elif cls.widgets["blitzRadio"].get_active(): secs = cls.ngblitz_min.get_value_as_int()*60 incr = cls.ngblitz_gain.get_value_as_int() elif cls.widgets["rapidRadio"].get_active(): secs = cls.ngrapid_min.get_value_as_int()*60 incr = cls.ngrapid_gain.get_value_as_int() elif cls.widgets["normalRadio"].get_active(): secs = cls.ngnormal_min.get_value_as_int()*60 incr = cls.ngnormal_gain.get_value_as_int() # Find players player0 = cls.widgets["whitePlayerCombobox"].get_active() player0 = playerItems[0].index(playerItems[variant_index][player0]) diffi0 = int(cls.widgets["skillSlider1"].get_value()) player1 = cls.widgets["blackPlayerCombobox"].get_active() player1 = playerItems[0].index(playerItems[variant_index][player1]) diffi1 = int(cls.widgets["skillSlider2"].get_value()) # Prepare players for ionest playertups = [] for i, playerno, diffi, color in ((0, player0, diffi0, WHITE), (1, player1, diffi1, BLACK)): if playerno > 0: engine = discoverer.getEngineN (playerno-1) name = discoverer.getName(engine) playertups.append((ARTIFICIAL, discoverer.initPlayerEngine, [engine, color, diffi, variant, secs, incr], name)) else: if not playertups or playertups[0][0] != LOCAL: name = conf.get("firstName", _("You")) else: name = conf.get("secondName", _("Guest")) playertups.append((LOCAL, Human, (color, name), name)) # Set forcePonderOff initPlayerEngine param True in engine-engine games if playertups[0][0] == ARTIFICIAL and playertups[1][0] == ARTIFICIAL: playertups[0][2].append(True) playertups[1][2].append(True) if secs > 0: timemodel = TimeModel (secs, incr) else: timemodel = TimeModel() gamemodel = GameModel (timemodel, variant) if not validate(gamemodel): return else: cls.widgets["newgamedialog"].hide() cls.widgets["newgamedialog"].disconnect(handlerId) callback(gamemodel, playertups[0], playertups[1])
def onResponse(dialog, res): if res != Gtk.ResponseType.OK: cls.widgets["newgamedialog"].hide() cls.widgets["newgamedialog"].disconnect(handlerId) return # Find variant if cls.widgets["playNormalRadio"].get_active(): variant_index = NORMALCHESS elif cls.widgets["playVariant1Radio"].get_active(): variant_index = conf.get("ngvariant1", FISCHERRANDOMCHESS) else: variant_index = conf.get("ngvariant2", LOSERSCHESS) variant = variants[variant_index] # Find time if cls.widgets["notimeRadio"].get_active(): secs = 0 incr = 0 elif cls.widgets["blitzRadio"].get_active(): secs = cls.ngblitz_min.get_value_as_int() * 60 incr = cls.ngblitz_gain.get_value_as_int() elif cls.widgets["rapidRadio"].get_active(): secs = cls.ngrapid_min.get_value_as_int() * 60 incr = cls.ngrapid_gain.get_value_as_int() elif cls.widgets["normalRadio"].get_active(): secs = cls.ngnormal_min.get_value_as_int() * 60 incr = cls.ngnormal_gain.get_value_as_int() # Find players player0 = cls.widgets["whitePlayerCombobox"].get_active() player0 = playerItems[0].index(playerItems[variant_index][player0]) diffi0 = int(cls.widgets["skillSlider1"].get_value()) player1 = cls.widgets["blackPlayerCombobox"].get_active() player1 = playerItems[0].index(playerItems[variant_index][player1]) diffi1 = int(cls.widgets["skillSlider2"].get_value()) # Prepare players for ionest playertups = [] for i, playerno, diffi, color in ((0, player0, diffi0, WHITE), (1, player1, diffi1, BLACK)): if playerno > 0: engine = discoverer.getEngineN(playerno - 1) name = discoverer.getName(engine) playertups.append( (ARTIFICIAL, discoverer.initPlayerEngine, [engine, color, diffi, variant, secs, incr], name)) else: if not playertups or playertups[0][0] != LOCAL: name = conf.get("firstName", _("You")) else: name = conf.get("secondName", _("Guest")) playertups.append((LOCAL, Human, (color, name), name)) # Set forcePonderOff initPlayerEngine param True in engine-engine games if playertups[0][0] == ARTIFICIAL and playertups[1][ 0] == ARTIFICIAL: playertups[0][2].append(True) playertups[1][2].append(True) if secs > 0: timemodel = TimeModel(secs, incr) else: timemodel = TimeModel() gamemodel = GameModel(timemodel, variant) if not validate(gamemodel): return else: cls.widgets["newgamedialog"].hide() cls.widgets["newgamedialog"].disconnect(handlerId) callback(gamemodel, playertups[0], playertups[1])