def do(discoverer): game = GameModel(TimeModel(60,0)) #game.connect('game_started', cb_gamestarted2) game.connect('game_ended', lambda *a: mainloop.quit()) p0 = discoverer.initPlayerEngine(discoverer.getEngines()['rybka'], WHITE, 7, variants[NORMALCHESS], 60) p1 = discoverer.initPlayerEngine(discoverer.getEngines()['gnuchess'], BLACK, 7, variants[NORMALCHESS], 60) game.setPlayers([p0,p1]) game.start()
def createPlayerUIGlobals(discoverer): global playerItems global analyzerItems global allEngineItems playerItems = [] analyzerItems = [] allEngineItems = [] for variantClass in variants.values(): playerItems += [[(ipeople, _("Human Being"))]] for engine in discoverer.getEngines(): name = engine["name"] c = discoverer.getCountry(engine) path = addDataPrefix("flags/%s.png" % c) if c and os.path.isfile(path): flag_icon = get_pixbuf(path) else: path = addDataPrefix("flags/unknown.png") flag_icon = get_pixbuf(path) allEngineItems.append((flag_icon, name)) for variant in discoverer.getEngineVariants(engine): playerItems[variant] += [(flag_icon, name)] if discoverer.is_analyzer(engine): analyzerItems.append((flag_icon, name))
def update_options(self, *args): if self.cur_engine is not None: # Initial reset self.options_store.clear() # Detection of the name of the engine to reload engines = discoverer.getEngines() names = [engine["name"] for engine in engines] if self.cur_engine not in names: self.cur_engine = engines[0]["name"] engine = discoverer.getEngineByName(self.cur_engine) if engine: options = engine.get("options") if options: options.sort(key=lambda obj: obj['name'].lower() if 'name' in obj else '') for option in options: key = option["name"] val = option if option["type"] != "button": val["default"] = option.get("default") val["value"] = option.get("value", val["default"]) modified = val["value"] != val["default"] else: modified = False self.options_store.append(["*" if modified else "", key, val])
def name_edited(renderer, path, new_name): if self.cur_engine is not None: old_name = self.cur_engine if new_name and new_name != old_name: names = [engine["name"] for engine in discoverer.getEngines()] if new_name not in names: engine = discoverer.getEngineByName(self.cur_engine) engine["name"] = new_name discoverer.save() self.cur_engine = new_name update_store() # Notify playerCombos in NewGameTasker discoverer.emit("all_engines_discovered")
def createRematch (gamemodel): if gamemodel.timemodel: secs = gamemodel.timemodel.intervals[0][WHITE] gain = gamemodel.timemodel.gain newgamemodel = GameModel(TimeModel(secs, gain), gamemodel.variant) else: secs = 0 gain = 0 newgamemodel = GameModel(variant=gamemodel.variant) wp = gamemodel.players[WHITE] bp = gamemodel.players[BLACK] if wp.__type__ == LOCAL: player1tup = (wp.__type__, wp.__class__, (BLACK, ""), repr(wp)) if bp.__type__ == LOCAL: player0tup = (bp.__type__, bp.__class__, (WHITE, ""), repr(bp)) else: binname = bp.engine.path.split("/")[-1] if binname == "python": binname = bp.engine.args[1].split("/")[-1] xmlengine = discoverer.getEngines()[binname] player0tup = (ARTIFICIAL, discoverer.initPlayerEngine, (xmlengine, WHITE, bp.strength, gamemodel.variant, secs, gain), repr(bp)) else: player0tup = (bp.__type__, bp.__class__, (WHITE, ""), repr(bp)) binname = wp.engine.path.split("/")[-1] if binname == "python": binname = wp.engine.args[1].split("/")[-1] xmlengine = discoverer.getEngines()[binname] player1tup = (ARTIFICIAL, discoverer.initPlayerEngine, (xmlengine, BLACK, wp.strength, gamemodel.variant, secs, gain), repr(wp)) ionest.generalStart(newgamemodel, player0tup, player1tup)
def createPlayerUIGlobals (discoverer): global playerItems global smallPlayerItems for variantClass in variants.values(): playerItems += [ [(ipeople, _("Human Being"))] ] smallPlayerItems += [ [(speople, _("Human Being"))] ] for engine in discoverer.getEngines().values(): name = discoverer.getName(engine) c = discoverer.getCountry(engine) path = addDataPrefix("flags/%s.png" % c) if c and os.path.isfile(path): flag_icon = gtk.gdk.pixbuf_new_from_file(path) else: flag_icon = inotebook for variant in discoverer.getEngineVariants(engine): playerItems[variant] += [(flag_icon, name)] smallPlayerItems[variant] += [(snotebook, name)]
def update_options(*args): if self.cur_engine is not None: engines = discoverer.getEngines() names = [engine["name"] for engine in engines] # After deleting an engine we will select first if self.cur_engine not in names: self.cur_engine = engines[0]["name"] engine = discoverer.getEngineByName(self.cur_engine) options = engine.get("options") if options: self.options_store.clear() for option in options: key = option["name"] val = option if option["type"] != "button": val["default"] = option.get("default") val["value"] = option.get("value", val["default"]) self.options_store.append([key, val])
def add(button): self.add = True response = engine_chooser_dialog.run() if response == gtk.RESPONSE_OK: new_engine = engine_chooser_dialog.get_filename() if new_engine: try: uci = is_uci(new_engine) if not uci: if not is_cecp(new_engine): # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) print "Maybe not a chess engine" return path, binname = os.path.split(new_engine) for e in discoverer.getEngines(): if e["name"] == binname: binname = e["name"] + "(1)" break self.widgets["engine_name_entry"].set_text(binname) self.widgets["engine_command_entry"].set_text(new_engine) self.widgets["engine_protocol_combo"].set_active(0 if uci else 1) self.widgets["engine_args_entry"].set_text("") name = self.widgets["engine_name_entry"].get_text().strip() active = self.widgets["engine_protocol_combo"].get_active() protocol = "uci" if active==0 else "xboard" discoverer.addEngine(name, new_engine, protocol) self.cur_engine = name glock_connect_after(discoverer, "engine_discovered", update_store) self.add = False discoverer.start() except: print "There is something wrong with this executable" else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()
def start(discoverer): global engines, results, minutes engines = discoverer.getEngines() n = len(engines) for i in range(n): results.append([None]*n) print() print("Your installed engines are:") for i, engine in enumerate(engines): name = discoverer.getName(engine) print("[%s] %s" % (name[:3], name)) print("The total amount of fights will be %d" % (n*(n-1))) print() minutes = int(raw_input("Please enter the clock minutes for each game [n]: ")) print("The games will last up to %d minutes." % (2*n*(n-1)*minutes)) print("You will be informed of the progress as the games finish.") print() runGame()
def __init__ (self, widgets): # Put engines in trees and combos engines = discoverer.getEngines() allstore = gtk.ListStore(gtk.gdk.Pixbuf, str) for engine in engines.values(): c = discoverer.getCountry(engine) if c: flag = addDataPrefix("flags/%s.png" % c) if not c or not os.path.isfile(flag): flag = addDataPrefix("flags/unknown.png") flag_icon = gtk.gdk.pixbuf_new_from_file(flag) allstore.append((flag_icon, discoverer.getName(engine))) tv = widgets["engines_treeview"] tv.set_model(allstore) tv.append_column(gtk.TreeViewColumn( _("Flag"), gtk.CellRendererPixbuf(), pixbuf=0)) tv.append_column(gtk.TreeViewColumn( _("Name"), gtk.CellRendererText(), text=1)) analyzers = list(discoverer.getAnalyzers()) ana_data = [] invana_data = [] for engine in analyzers: name = discoverer.getName(engine) c = discoverer.getCountry(engine) if c: flag = addDataPrefix("flags/%s.png" % c) if not c or not os.path.isfile(flag): flag = addDataPrefix("flags/unknown.png") flag_icon = gtk.gdk.pixbuf_new_from_file(flag) ana_data.append((flag_icon, name)) invana_data.append((flag_icon, name)) uistuff.createCombo(widgets["ana_combobox"], ana_data) uistuff.createCombo(widgets["inv_ana_combobox"], invana_data) # Save, load and make analyze combos active conf.set("ana_combobox", conf.get("ana_combobox", 0)) conf.set("inv_ana_combobox", conf.get("inv_ana_combobox", 0)) def on_analyzer_check_toggled (check): widgets["analyzers_vbox"].set_sensitive(check.get_active()) widgets["hint_mode"].set_active(check.get_active()) from pychess.Main import gameDic if gameDic: widgets["hint_mode"].set_sensitive(check.get_active()) widgets["analyzer_check"].connect("toggled", on_analyzer_check_toggled) uistuff.keep(widgets["analyzer_check"], "analyzer_check") def on_invanalyzer_check_toggled (check): widgets["inv_analyzers_vbox"].set_sensitive(check.get_active()) widgets["spy_mode"].set_active(check.get_active()) from pychess.Main import gameDic if gameDic: widgets["spy_mode"].set_sensitive(check.get_active()) widgets["inv_analyzer_check"].connect("toggled", on_invanalyzer_check_toggled) uistuff.keep(widgets["inv_analyzer_check"], "inv_analyzer_check") # Put options in trees in add/edit dialog #======================================================================= # tv = widgets["optionview"] # tv.append_column(gtk.TreeViewColumn( # "Option", gtk.CellRendererText(), text=0)) # tv.append_column(gtk.TreeViewColumn( # "Value", gtk.CellRendererText(), text=1)) # # def edit (button): # # iter = widgets["engines_treeview"].get_selection().get_selected()[1] # if iter: row = allstore.get_path(iter)[0] # else: return # # engine = discoverer.getEngineN(row) # optionstags = engine.getElementsByTagName("options") # if not optionstags: # widgets["engine_options_expander"].hide() # else: # widgets["engine_options_expander"].show() # widgets["engine_options_expander"].set_expanded(False) # # optionsstore = gtk.ListStore(str, str) # tv = widgets["optionview"] # tv.set_model(optionsstore) # # for option in optionstags[0].childNodes: # if option.nodeType != option.ELEMENT_NODE: continue # optionsstore.append( [option.getAttribute("name"), # option.getAttribute("default")] ) # # widgets["engine_path_chooser"].set_title(_("Locate Engine")) # widgets["engine_path_chooser"].set_uri("file:///usr/bin/gnuchess") # # dialog = widgets["addconfig_engine"] # answer = dialog.run() # dialog.hide() # widgets["edit_engine_button"].connect("clicked", edit) #======================================================================= #widgets["remove_engine_button"].connect("clicked", remove) #widgets["add_engine_button"].connect("clicked", add) # Give widgets to kepper for combo in ("ana_combobox", "inv_ana_combobox"): def get_value (combobox): engine = list(discoverer.getAnalyzers())[combobox.get_active()] if engine.find('md5') != None: return engine.find('md5').text.strip() def set_value (combobox, value): engine = discoverer.getEngineByMd5(value) if not engine: combobox.set_active(0) else: try: index = list(discoverer.getAnalyzers()).index(engine) except ValueError: index = 0 combobox.set_active(index) uistuff.keep (widgets[combo], combo, get_value, set_value) # Init info box uistuff.makeYellow(widgets["analyzer_pref_infobox"]) widgets["analyzer_pref_infobox"].hide() def updatePrefInfobox (widget, *args): widgets["analyzer_pref_infobox"].show() widgets["ana_combobox"].connect("changed", updatePrefInfobox) widgets["analyzer_check"].connect("toggled", updatePrefInfobox) widgets["inv_ana_combobox"].connect("changed", updatePrefInfobox) widgets["inv_analyzer_check"].connect("toggled", updatePrefInfobox) widgets["preferences"].connect("hide", lambda *a: widgets["analyzer_pref_infobox"].hide())
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() if new_engine.lower().endswith(".exe") and sys.platform != "win32": vm_name = "wine" vmpath = searchPath(vm_name, access=os.R_OK|os.X_OK) if vmpath is None: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("wine not installed")) d.run() d.hide() new_engine = "" else: vmpath += " " else: vm_name = None vmpath = "" if new_engine: try: # Some engines support CECP and UCI, but variant engines are CECP, # so we better to start with CECP this case variant_engines = ("fmax", "sjaakii", "sjeng") if any((True for e in variant_engines if e in new_engine.lower())): checkers = [is_cecp, is_uci] else: checkers = [is_uci, is_cecp] uci = False for checker in checkers: ok = checker(vmpath + new_engine) if ok: uci = checker is is_uci break else: continue if not ok: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() engine_chooser_dialog.hide() return path, binname = os.path.split(new_engine) for e in discoverer.getEngines(): if e["name"] == binname: binname = e["name"] + "(1)" break self.widgets["engine_command_entry"].set_text(new_engine) self.widgets["engine_protocol_combo"].set_active(0 if uci else 1) self.widgets["engine_args_entry"].set_text("") active = self.widgets["engine_protocol_combo"].get_active() protocol = "uci" if uci else "xboard" discoverer.addEngine(binname, new_engine, protocol, vm_name) self.cur_engine = binname self.add = False discoverer.discover() except: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() if new_engine.lower().endswith(".exe"): vm_name = "wine" vmpath = searchPath(vm_name, access=os.R_OK|os.X_OK) if vmpath is None: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("wine not installed")) d.run() d.hide() new_engine = "" else: vmpath += " " else: vm_name = None vmpath = "" if new_engine: try: uci = is_uci(vmpath + new_engine) if not uci: if not is_cecp(vmpath + new_engine): # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() engine_chooser_dialog.hide() return path, binname = os.path.split(new_engine) for e in discoverer.getEngines(): if e["name"] == binname: binname = e["name"] + "(1)" break self.widgets["engine_command_entry"].set_text(new_engine) self.widgets["engine_protocol_combo"].set_active(0 if uci else 1) self.widgets["engine_args_entry"].set_text("") active = self.widgets["engine_protocol_combo"].get_active() protocol = "uci" if active==0 else "xboard" discoverer.addEngine(binname, new_engine, protocol, vm_name) self.cur_engine = binname glock_connect_after(discoverer, "engine_discovered", update_store) self.add = False discoverer.discover() except: d = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) d.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) d.format_secondary_text(_("There is something wrong with this executable")) d.run() d.hide() else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() vm_name = None vm_args = None vmpath = "" if new_engine.lower().endswith(".exe") and sys.platform != "win32": vm_name = "wine" vmpath = shutil.which(vm_name, mode=os.R_OK | os.X_OK) if vmpath is None: msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(_("wine not installed")) msg_dia.run() msg_dia.hide() new_engine = "" for vm in VM_LIST: ext = os.path.splitext(new_engine)[1] if ext == vm.ext: vm_name = vm.name vm_args = vm.args vmpath = shutil.which(vm_name, mode=os.R_OK | os.X_OK) if vmpath is None: msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(vm_name + _(" is not installed")) msg_dia.run() msg_dia.hide() new_engine = "" break if new_engine: vm_ext_list = [vm.ext for vm in VM_LIST] if ext not in vm_ext_list and not os.access(new_engine, os.X_OK): msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>%s is not marked executable in the filesystem</b></big>" % new_engine)) msg_dia.format_secondary_text(_("Try chmod a+x %s" % new_engine)) msg_dia.run() msg_dia.hide() self.add = False engine_chooser_dialog.hide() return try: engine_command = [] if vmpath: engine_command.append(vmpath) if vm_args is not None: engine_command.append(vm_args) engine_command.append(new_engine) # Some engines support CECP and UCI, but main variant engines are CECP, # so we better to start with CECP this case variant_engines = ("fmax", "sjaakii", "sjeng") if any((True for eng in variant_engines if eng in new_engine.lower())): checkers = [is_cecp, is_uci] else: checkers = [is_uci, is_cecp] uci = False for checker in checkers: check_ok = checker(engine_command) if check_ok: uci = checker is is_uci break else: continue if not check_ok: # restore the original engine = discoverer.getEngineByName( self.cur_engine) engine_chooser_dialog.set_filename(engine[ "command"]) msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup( _("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(_( "There is something wrong with this executable")) msg_dia.run() msg_dia.hide() engine_chooser_dialog.hide() self.add = False engine_chooser_dialog.hide() return binname = os.path.split(new_engine)[1] for eng in discoverer.getEngines(): if eng["name"] == binname: binname = eng["name"] + "(1)" break self.widgets["engine_command_entry"].set_text(new_engine) self.widgets["engine_protocol_combo"].set_active(0 if uci else 1) self.widgets["engine_args_entry"].set_text("") # active = self.widgets["engine_protocol_combo"].get_active() protocol = "uci" if uci else "xboard" if vm_args is not None: vm_args = vm_args.split(",") # print(binname, new_engine, protocol, vm_name, vm_args) discoverer.addEngine(binname, new_engine, protocol, vm_name, vm_args, "unknown") self.cur_engine = binname self.add = False discoverer.discover() except Exception: msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(_( "There is something wrong with this executable")) msg_dia.run() msg_dia.hide() self.add = False engine_chooser_dialog.hide() return else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() binname = os.path.split(new_engine)[1] ext = os.path.splitext(new_engine)[1] # Verify if the engine already exists under the same name if new_engine != "": for eng in discoverer.getEngines(): if eng["command"] == new_engine: msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(_("The engine is already installed under the same name")) msg_dia.run() msg_dia.hide() new_engine = "" break # Detect the host application if new_engine != "": vm_name = None vm_args = None vmpath = "" # Scripting for vm in VM_LIST: if ext == vm.ext: vm_name = vm.name vm_args = vm.args break # Wine for Windows application under Linux if vm_name is None and new_engine.lower().endswith(".exe") and sys.platform != "win32": vm_name = "wine" # Check that the interpreter is available if vm_name is not None: vmpath = shutil.which(vm_name, mode=os.R_OK | os.X_OK) if vmpath is None: msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(vm_name + _(" is not installed")) msg_dia.run() msg_dia.hide() new_engine = "" # Next checks if new_engine: vm_ext_list = [vm.ext for vm in VM_LIST] if ext not in vm_ext_list and not os.access(new_engine, os.X_OK): msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>%s is not marked executable in the filesystem</b></big>" % new_engine)) msg_dia.format_secondary_text(_("Try chmod a+x %s" % new_engine)) msg_dia.run() msg_dia.hide() self.add = False engine_chooser_dialog.hide() return try: engine_command = [] if vmpath: engine_command.append(vmpath) if vm_args is not None: engine_command.append(vm_args) engine_command.append(new_engine) # Search the engines based on the most expectable protocol refeng = discoverer.getReferencedEngine(binname) if refeng is not None and refeng["protocol"] == "xboard": checkers = [is_cecp, is_uci] else: checkers = [is_uci, is_cecp] uci = False for checker in checkers: check_ok = checker(engine_command) if check_ok: uci = checker is is_uci break else: continue if not check_ok: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup( _("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(_("There is something wrong with this executable")) msg_dia.run() msg_dia.hide() engine_chooser_dialog.hide() self.add = False engine_chooser_dialog.hide() return self.widgets["engine_command_entry"].set_text(new_engine) self.widgets["engine_protocol_combo"].set_active(0 if uci else 1) self.widgets["engine_args_entry"].set_text("") # active = self.widgets["engine_protocol_combo"].get_active() protocol = "uci" if uci else "xboard" if vm_args is not None: vm_args = vm_args.split(",") # print(binname, new_engine, protocol, vm_name, vm_args) discoverer.addEngine(binname, new_engine, protocol, vm_name, vm_args) self.cur_engine = binname self.add = False discoverer.discover() except Exception: msg_dia = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(_("There is something wrong with this executable")) msg_dia.run() msg_dia.hide() self.add = False engine_chooser_dialog.hide() return else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() vm_name = None vm_args = None vmpath = "" if new_engine.lower().endswith(".exe") and sys.platform != "win32": vm_name = "wine" vmpath = searchPath(vm_name, access=os.R_OK | os.X_OK) if vmpath is None: msg_dia = Gtk.MessageDialog(type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(_("wine not installed")) msg_dia.run() msg_dia.hide() new_engine = "" else: vmpath += " " for vm in VM_LIST: ext = os.path.splitext(new_engine)[1] if ext == vm.ext: vm_name = vm.name vm_args = vm.args vmpath = searchPath(vm_name, access=os.R_OK | os.X_OK) if vmpath is None: msg_dia = Gtk.MessageDialog(type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(vm_name + _(" is not installed")) msg_dia.run() msg_dia.hide() new_engine = "" break if new_engine: vm_ext_list = [vm.ext for vm in VM_LIST] if ext not in vm_ext_list and not os.access(new_engine, os.X_OK): msg_dia = Gtk.MessageDialog(type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>%s is not marked executable in the filesystem</b></big>" % new_engine)) msg_dia.format_secondary_text(_("Try chmod a+x %s" % new_engine)) msg_dia.run() msg_dia.hide() self.add = False engine_chooser_dialog.hide() return try: engine_command = [] if vmpath is not None: engine_command.append(vmpath) if vm_args is not None: engine_command.append(vm_args) engine_command.append(new_engine) # Some engines support CECP and UCI, but main variant engines are CECP, # so we better to start with CECP this case variant_engines = ("fmax", "sjaakii", "sjeng") if any((True for eng in variant_engines if eng in new_engine.lower())): checkers = [is_cecp, is_uci] else: checkers = [is_uci, is_cecp] uci = False for checker in checkers: check_ok = checker(engine_command) if check_ok: uci = checker is is_uci break else: continue if not check_ok: # restore the original engine = discoverer.getEngineByName( self.cur_engine) engine_chooser_dialog.set_filename(engine[ "command"]) msg_dia = Gtk.MessageDialog( type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup( _("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(_( "There is something wrong with this executable")) msg_dia.run() msg_dia.hide() engine_chooser_dialog.hide() self.add = False engine_chooser_dialog.hide() return binname = os.path.split(new_engine)[1] for eng in discoverer.getEngines(): if eng["name"] == binname: binname = eng["name"] + "(1)" break self.widgets["engine_command_entry"].set_text(new_engine) self.widgets["engine_protocol_combo"].set_active(0 if uci else 1) self.widgets["engine_args_entry"].set_text("") # active = self.widgets["engine_protocol_combo"].get_active() protocol = "uci" if uci else "xboard" if vm_args is not None: vm_args = vm_args.split(",") # print(binname, new_engine, protocol, vm_name, vm_args) discoverer.addEngine(binname, new_engine, protocol, vm_name, vm_args) self.cur_engine = binname self.add = False discoverer.discover() except: msg_dia = Gtk.MessageDialog(type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK) msg_dia.set_markup(_("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text(_( "There is something wrong with this executable")) msg_dia.run() msg_dia.hide() self.add = False engine_chooser_dialog.hide() return else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()
def add(button): self.add = True response = engine_chooser_dialog.run() if response == Gtk.ResponseType.OK: new_engine = engine_chooser_dialog.get_filename() binname = os.path.split(new_engine)[1] ext = os.path.splitext(new_engine)[1] # Verify if the engine already exists under the same name if new_engine != "": for eng in discoverer.getEngines(): if eng["command"] == new_engine: msg_dia = Gtk.MessageDialog( mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, ) msg_dia.set_markup( _("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text( _("The engine is already installed under the same name" )) msg_dia.run() msg_dia.hide() new_engine = "" break # Detect the host application if new_engine != "": vm_name = None vm_args = None vmpath = "" # Scripting for vm in VM_LIST: if ext == vm.ext: vm_name = vm.name vm_args = vm.args break # Wine for Windows application under Linux if (vm_name is None and new_engine.lower().endswith(".exe") and sys.platform != "win32"): vm_name = "wine" # Check that the interpreter is available if vm_name is not None: vmpath = shutil.which(vm_name, mode=os.R_OK | os.X_OK) if vmpath is None: msg_dia = Gtk.MessageDialog( mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, ) msg_dia.set_markup( _("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text( vm_name + _(" is not installed")) msg_dia.run() msg_dia.hide() new_engine = "" # Next checks if new_engine: vm_ext_list = [vm.ext for vm in VM_LIST] if ext not in vm_ext_list and not os.access( new_engine, os.X_OK): msg_dia = Gtk.MessageDialog( mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, ) msg_dia.set_markup( _("<big><b>%s is not marked executable in the filesystem</b></big>" % new_engine)) msg_dia.format_secondary_text( _("Try chmod a+x %s" % new_engine)) msg_dia.run() msg_dia.hide() self.add = False engine_chooser_dialog.hide() return try: engine_command = [] if vmpath: engine_command.append(vmpath) if vm_args is not None: engine_command += vm_args engine_command.append(new_engine) # Search the engines based on the most expectable protocol refeng = discoverer.getReferencedEngine(binname) if refeng is not None and refeng[ "protocol"] == "xboard": checkers = [is_cecp, is_uci] else: checkers = [is_uci, is_cecp] uci = False for checker in checkers: check_ok = checker(engine_command) if check_ok: uci = checker is is_uci break else: continue if not check_ok: # restore the original engine = discoverer.getEngineByName( self.cur_engine) engine_chooser_dialog.set_filename( engine["command"]) msg_dia = Gtk.MessageDialog( mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, ) msg_dia.set_markup( _("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text( _("There is something wrong with this executable" )) msg_dia.run() msg_dia.hide() engine_chooser_dialog.hide() self.add = False engine_chooser_dialog.hide() return self.widgets["engine_command_entry"].set_text( new_engine) self.widgets["engine_protocol_combo"].set_active( 0 if uci else 1) self.widgets["engine_args_entry"].set_text("") # active = self.widgets["engine_protocol_combo"].get_active() protocol = "uci" if uci else "xboard" # print(binname, new_engine, protocol, vm_name, vm_args) discoverer.addEngine(binname, new_engine, protocol, vm_name, vm_args) self.cur_engine = binname self.add = False discoverer.discover() except Exception: msg_dia = Gtk.MessageDialog( mainwindow(), type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, ) msg_dia.set_markup( _("<big><b>Unable to add %s</b></big>" % new_engine)) msg_dia.format_secondary_text( _("There is something wrong with this executable")) msg_dia.run() msg_dia.hide() self.add = False engine_chooser_dialog.hide() return else: # restore the original engine = discoverer.getEngineByName(self.cur_engine) engine_chooser_dialog.set_filename(engine["command"]) engine_chooser_dialog.hide()