本文整理汇总了Python中pychess.Players.engineNest.discoverer.connect_after函数的典型用法代码示例。如果您正苦于以下问题:Python connect_after函数的具体用法?Python connect_after怎么用?Python connect_after使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect_after函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleArgs
def handleArgs(self, chess_file):
if chess_file:
def do(discoverer):
GLib.idle_add(newGameDialog.LoadFileExtension.run, chess_file)
discoverer.connect_after("all_engines_discovered", do)
示例2: __init__
def __init__(self):
#GObject.GObject.__init__(self,0,0,0,0)
GObject.GObject.__init__(self)
self.widgets = widgets = uistuff.GladeWidgets("taskers.glade")
tasker = widgets["newGameTasker"]
tasker.unparent()
self.add(tasker)
combo = ToggleComboBox()
combo.addItem(_("White"), get_pixbuf("glade/white.png"))
combo.addItem(_("Black"), get_pixbuf("glade/black.png"))
combo.addItem(_("Random"), get_pixbuf("glade/random.png"))
combo.setMarkup("<b>", "</b>")
widgets["colorDock"].add(combo)
uistuff.keep(combo, "newgametasker_colorcombo")
widgets['yourColorLabel'].set_mnemonic_widget(combo)
# We need to wait until after engines have been discovered, to init the
# playerCombos. We use connect_after to make sure, that newGameDialog
# has also had time to init the constants we share with them.
self.playerCombo = ToggleComboBox()
widgets["opponentDock"].add(self.playerCombo)
discoverer.connect_after("all_engines_discovered",
self.__initPlayerCombo, widgets)
widgets['opponentLabel'].set_mnemonic_widget(self.playerCombo)
def on_skill_changed(scale):
pix = newGameDialog.skillToIconLarge[int(scale.get_value())]
widgets["skillImage"].set_from_pixbuf(pix)
widgets["skillSlider"].connect("value-changed", on_skill_changed)
on_skill_changed(widgets["skillSlider"])
widgets["startButton"].connect("clicked", self.startClicked)
self.widgets["opendialog1"].connect("clicked", self.openDialogClicked)
示例3: handleArgs
def handleArgs(self, chess_file):
if chess_file:
def do(discoverer):
perspective = perspective_manager.get_perspective("database")
perspective.open_chessfile(chess_file)
self.dd_task.cancel()
discoverer.connect_after("all_engines_discovered", do)
示例4: __init__
def __init__(self):
GObject.GObject.__init__(self)
self.widgets = widgets = uistuff.GladeWidgets("taskers.glade")
tasker = widgets["newGameTasker"]
tasker.unparent()
self.add(tasker)
startButton = self.widgets["startButton"]
startButton.set_name("startButton")
combo = Gtk.ComboBox()
uistuff.createCombo(combo, [
(get_pixbuf("glade/white.png"), _("White")),
(get_pixbuf("glade/black.png"), _("Black")),
(get_pixbuf("glade/random.png"), _("Random"))])
widgets["colorDock"].add(combo)
if combo.get_active() < 0:
combo.set_active(0)
uistuff.keep(combo, "newgametasker_colorcombo")
widgets['yourColorLabel'].set_mnemonic_widget(combo)
# We need to wait until after engines have been discovered, to init the
# playerCombos. We use connect_after to make sure, that newGameDialog
# has also had time to init the constants we share with them.
self.playerCombo = Gtk.ComboBox()
widgets["opponentDock"].add(self.playerCombo)
discoverer.connect_after("all_engines_discovered",
self.__initPlayerCombo, widgets)
widgets['opponentLabel'].set_mnemonic_widget(self.playerCombo)
def on_skill_changed(scale):
# Just to make sphinx happy...
try:
pix = newGameDialog.skillToIconLarge[int(scale.get_value())]
widgets["skillImage"].set_from_pixbuf(pix)
except TypeError:
pass
widgets["skillSlider"].connect("value-changed", on_skill_changed)
on_skill_changed(widgets["skillSlider"])
widgets["startButton"].connect("clicked", self.startClicked)
self.widgets["opendialog1"].connect("clicked", self.openDialogClicked)
示例5: do_activate
def do_activate(self):
# create_task(self.print_tasks())
self.add_window(self.window)
self.window.show_all()
gamewidget.getWidgets()["player_rating1"].hide()
gamewidget.getWidgets()["leave_fullscreen1"].hide()
# Externals download dialog
if not conf.get("dont_show_externals_at_startup"):
externals_dialog = ExternalsDialog()
externals_dialog.show()
# Tip of the day dialog
if conf.get("show_tip_at_startup"):
tip_of_the_day = TipOfTheDay()
tip_of_the_day.show()
preferencesDialog.run(gamewidget.getWidgets())
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)
# Try to set conf analyzer engine on very first start of pychess
if conf.get("ana_combobox") == 0:
discoverer.connect_after("all_engines_discovered", on_all_engine_discovered)
dd = DiscovererDialog(discoverer)
self.dd_task = create_task(dd.start())
style_ctxt = gamewidget.getWidgets()["main_window"].get_style_context()
LIGHT = hexcol(style_ctxt.lookup_color("p_light_color")[1])
DARK = hexcol(style_ctxt.lookup_color("p_dark_color")[1])
conf.set("lightcolour", LIGHT)
conf.set("darkcolour", DARK)
示例6: protocol_changed
def protocol_changed(widget):
if self.cur_engine is not None and not self.add and not self.selection:
active = self.widgets["engine_protocol_combo"].get_active()
new_protocol = "uci" if active==0 else "xboard"
engine = discoverer.getEngineByName(self.cur_engine)
old_protocol = engine["protocol"]
if new_protocol != old_protocol:
engine_command = engine_chooser_dialog.get_filename()
# is the new protocol supported by the engine?
if new_protocol == "uci":
ok = is_uci(engine_command)
else:
ok = is_cecp(engine_command)
if ok:
# discover engine options for new protocol
engine["protocol"] = new_protocol
engine["recheck"] = True
discoverer.connect_after("engine_discovered", update_options)
discoverer.discover()
else:
# restore the original protocol
widgets["engine_protocol_combo"].set_active(0 if old_protocol=="uci" else 1)
示例7: _init
def _init(cls):
cls.white = get_pixbuf("glade/white.png")
cls.black = get_pixbuf("glade/black.png")
cls.widgets = uistuff.GladeWidgets("newInOut.glade")
cls.widgets["newgamedialog"].set_transient_for(mainwindow())
def on_exchange_players(widget, button_event):
white = cls.widgets["whitePlayerCombobox"].get_active()
black = cls.widgets["blackPlayerCombobox"].get_active()
whiteLevel = cls.widgets["skillSlider1"].get_value()
blackLevel = cls.widgets["skillSlider2"].get_value()
cls.widgets["whitePlayerCombobox"].set_active(black)
cls.widgets["blackPlayerCombobox"].set_active(white)
cls.widgets["skillSlider1"].set_value(blackLevel)
cls.widgets["skillSlider2"].set_value(whiteLevel)
cls.widgets["whitePlayerButton"].set_image(Gtk.Image.new_from_pixbuf(cls.white))
cls.widgets["whitePlayerButton"].connect("button-press-event", on_exchange_players)
cls.widgets["blackPlayerButton"].set_image(Gtk.Image.new_from_pixbuf(cls.black))
cls.widgets["blackPlayerButton"].connect("button-press-event", on_exchange_players)
uistuff.createCombo(cls.widgets["whitePlayerCombobox"], name="whitePlayerCombobox")
uistuff.createCombo(cls.widgets["blackPlayerCombobox"], name="blackPlayerCombobox")
cls.widgets["playersIcon"].set_from_pixbuf(big_people)
cls.widgets["timeIcon"].set_from_pixbuf(big_time)
def on_playerCombobox_changed(widget, skill_hbox, skill_level):
position = widget.get_active()
skill_hbox.props.visible = position > 0
if position > 0:
tree_iter = widget.get_active_iter()
if tree_iter is not None:
engine_name = widget.get_model()[tree_iter][1]
engine = discoverer.getEngineByName(engine_name)
if engine:
pref_level = engine.get("level")
if pref_level:
skill_level.set_value(pref_level)
cls.widgets["whitePlayerCombobox"].connect("changed", on_playerCombobox_changed, cls.widgets["skillHbox1"], cls.widgets["skillSlider1"])
cls.widgets["blackPlayerCombobox"].connect("changed", on_playerCombobox_changed, cls.widgets["skillHbox2"], cls.widgets["skillSlider2"])
cls.widgets["whitePlayerCombobox"].set_active(0)
cls.widgets["blackPlayerCombobox"].set_active(1)
def on_skill_changed(scale, image):
image.set_from_pixbuf(skillToIcon[int(scale.get_value())])
cls.widgets["skillSlider1"].connect("value-changed", on_skill_changed, cls.widgets["skillIcon1"])
cls.widgets["skillSlider2"].connect("value-changed", on_skill_changed, cls.widgets["skillIcon2"])
cls.widgets["skillSlider1"].set_value(3)
cls.widgets["skillSlider2"].set_value(3)
cls.__initTimeRadio("ngblitz", cls.widgets["blitzRadio"], cls.widgets["configImageBlitz"], 5, 0, 0)
cls.__initTimeRadio("ngrapid", cls.widgets["rapidRadio"], cls.widgets["configImageRapid"], 15, 5, 0)
cls.__initTimeRadio("ngnormal", cls.widgets["normalRadio"], cls.widgets["configImageNormal"], 45, 15, 0)
cls.__initTimeRadio("ngclassical", cls.widgets["classicalRadio"], cls.widgets["configImageClassical"], 3, 0, 40)
cls.__initVariantRadio("ngvariant1", cls.widgets["playVariant1Radio"], cls.widgets["configImageVariant1"])
cls.__initVariantRadio("ngvariant2", cls.widgets["playVariant2Radio"], cls.widgets["configImageVariant2"])
def updateCombos(*args):
if cls.widgets["playNormalRadio"].get_active():
variant = NORMALCHESS
elif cls.widgets["playVariant1Radio"].get_active():
variant = conf.get("ngvariant1")
else:
variant = conf.get("ngvariant2")
variant1 = conf.get("ngvariant1")
cls.widgets["playVariant1Radio"].set_tooltip_text(variants[variant1].__desc__)
variant2 = conf.get("ngvariant2")
cls.widgets["playVariant2Radio"].set_tooltip_text(variants[variant2].__desc__)
data = [(item[0], item[1]) for item in playerItems[variant]]
uistuff.updateCombo(cls.widgets["blackPlayerCombobox"], data)
uistuff.updateCombo(cls.widgets["whitePlayerCombobox"], data)
discoverer.connect_after("all_engines_discovered", updateCombos)
updateCombos(discoverer)
conf.notify_add("ngvariant1", updateCombos)
conf.notify_add("ngvariant2", updateCombos)
cls.widgets["playNormalRadio"].connect("toggled", updateCombos)
cls.widgets["playNormalRadio"].set_tooltip_text(variants[NORMALCHESS].__desc__)
cls.widgets["playVariant1Radio"].connect("toggled", updateCombos)
variant1 = conf.get("ngvariant1")
cls.widgets["playVariant1Radio"].set_tooltip_text(variants[variant1].__desc__)
cls.widgets["playVariant2Radio"].connect("toggled", updateCombos)
variant2 = conf.get("ngvariant2")
cls.widgets["playVariant2Radio"].set_tooltip_text(variants[variant2].__desc__)
# The "variant" has to come before players, because the engine positions
# in the user comboboxes can be different in different variants
for key in ("whitePlayerCombobox", "blackPlayerCombobox",
"skillSlider1", "skillSlider2", "notimeRadio",
"blitzRadio", "rapidRadio", "normalRadio", "classicalRadio",
"playNormalRadio", "playVariant1Radio", "playVariant2Radio"):
uistuff.keep(cls.widgets[key], key)
# We don't want the dialog to deallocate when closed. Rather we hide
#.........这里部分代码省略.........
示例8: initialize
def initialize(gameDic):
uistuff.keep(widgets["fromCurrent"], "fromCurrent", first_value=True)
uistuff.keep(widgets["threatPV"], "threatPV")
uistuff.keep(widgets["showEval"], "showEval")
uistuff.keep(widgets["showBlunder"], "showBlunder", first_value=True)
uistuff.keep(widgets["max_analysis_spin"], "max_analysis_spin", first_value=3)
uistuff.keep(widgets["variation_thresold_spin"], "variation_thresold_spin", first_value=50)
# Analyzing engines
uistuff.createCombo(widgets["ana_combobox"])
from pychess.widgets import newGameDialog
@idle_add
def update_analyzers_store(discoverer):
data = [(item[0], item[1]) for item in newGameDialog.analyzerItems]
uistuff.updateCombo(widgets["ana_combobox"], data)
discoverer.connect_after("all_engines_discovered", update_analyzers_store)
update_analyzers_store(discoverer)
uistuff.keep(widgets["ana_combobox"], "ana_combobox", anal_combo_get_value,
lambda combobox, value: anal_combo_set_value(combobox, value, "hint_mode",
"analyzer_check", HINT))
def hide_window(button, *args):
widgets["analyze_game"].hide()
return True
def abort ():
stop_event.set()
widgets["analyze_game"].hide()
def run_analyze(button, *args):
gmwidg = gamewidget.cur_gmwidg()
gamemodel = gameDic[gmwidg]
old_check_value = conf.get("analyzer_check", True)
conf.set("analyzer_check", True)
analyzer = gamemodel.spectators[HINT]
gmwidg.menuitems["hint_mode"].active = True
threat_PV = conf.get("ThreatPV", False)
if threat_PV:
old_inv_check_value = conf.get("inv_analyzer_check", True)
conf.set("inv_analyzer_check", True)
inv_analyzer = gamemodel.spectators[SPY]
gmwidg.menuitems["spy_mode"].active = True
title = _("Game analyzing in progress...")
text = _("Do you want to abort it?")
content = InfoBar.get_message_content(title, text, Gtk.STOCK_DIALOG_QUESTION)
def response_cb (infobar, response, message):
message.dismiss()
abort()
message = InfoBarMessage(Gtk.MessageType.QUESTION, content, response_cb)
message.add_button(InfoBarMessageButton(_("Abort"), Gtk.ResponseType.CANCEL))
gmwidg.showMessage(message)
def analyse_moves():
from_current = conf.get("fromCurrent", True)
start_ply = gmwidg.board.view.shown if from_current else 0
move_time = int(conf.get("max_analysis_spin", 3))
thresold = int(conf.get("variation_thresold_spin", 50))
for board in gamemodel.boards[start_ply:]:
if stop_event.is_set():
break
@idle_add
def do():
gmwidg.board.view.setShownBoard(board)
do()
analyzer.setBoard(board)
inv_analyzer.setBoard(board)
time.sleep(move_time+0.1)
ply = board.ply
if ply-1 in gamemodel.scores and ply in gamemodel.scores:
color = (ply-1) % 2
oldmoves, oldscore, olddepth = gamemodel.scores[ply-1]
score_str = prettyPrintScore(oldscore, olddepth)
oldscore = oldscore * -1 if color == BLACK else oldscore
moves, score, depth = gamemodel.scores[ply]
score = score * -1 if color == WHITE else score
diff = score-oldscore
if (diff > thresold and color==BLACK) or (diff < -1*thresold and color==WHITE):
if threat_PV:
try:
if ply-1 in gamemodel.spy_scores:
oldmoves0, oldscore0, olddepth0 = gamemodel.spy_scores[ply-1]
score_str0 = prettyPrintScore(oldscore0, olddepth0)
pv0 = listToMoves(gamemodel.boards[ply-1], ["--"] + oldmoves0, validate=True)
if len(pv0) > 2:
gamemodel.add_variation(gamemodel.boards[ply-1], pv0, comment="Treatening", score=score_str0)
except ParsingError as e:
# ParsingErrors may happen when parsing "old" lines from
# analyzing engines, which haven't yet noticed their new tasks
log.debug("__parseLine: Ignored (%s) from analyzer: ParsingError%s" % \
(' '.join(oldmoves),e))
try:
pv = listToMoves(gamemodel.boards[ply-1], oldmoves, validate=True)
gamemodel.add_variation(gamemodel.boards[ply-1], pv, comment="Better is", score=score_str)
except ParsingError as e:
#.........这里部分代码省略.........
示例9: _init
def _init (cls):
cls.widgets = uistuff.GladeWidgets ("newInOut.glade")
uistuff.createCombo(cls.widgets["whitePlayerCombobox"], name="whitePlayerCombobox")
uistuff.createCombo(cls.widgets["blackPlayerCombobox"], name="blackPlayerCombobox")
cls.widgets["playersIcon"].set_from_pixbuf(big_people)
cls.widgets["timeIcon"].set_from_pixbuf(big_time)
def on_playerCombobox_changed (widget, skillHbox):
skillHbox.props.visible = widget.get_active() > 0
cls.widgets["whitePlayerCombobox"].connect(
"changed", on_playerCombobox_changed, cls.widgets["skillHbox1"])
cls.widgets["blackPlayerCombobox"].connect(
"changed", on_playerCombobox_changed, cls.widgets["skillHbox2"])
cls.widgets["whitePlayerCombobox"].set_active(0)
cls.widgets["blackPlayerCombobox"].set_active(1)
def on_skill_changed (scale, image):
image.set_from_pixbuf(skillToIcon[int(scale.get_value())])
cls.widgets["skillSlider1"].connect("value-changed", on_skill_changed,
cls.widgets["skillIcon1"])
cls.widgets["skillSlider2"].connect("value-changed", on_skill_changed,
cls.widgets["skillIcon2"])
cls.widgets["skillSlider1"].set_value(3)
cls.widgets["skillSlider2"].set_value(3)
cls.__initTimeRadio(_("Blitz"), "ngblitz", cls.widgets["blitzRadio"],
cls.widgets["configImageBlitz"], 5, 0)
cls.__initTimeRadio(_("Rapid"), "ngrapid", cls.widgets["rapidRadio"],
cls.widgets["configImageRapid"], 15, 5)
cls.__initTimeRadio(_("Normal"), "ngnormal", cls.widgets["normalRadio"],
cls.widgets["configImageNormal"], 40, 15)
cls.__initVariantRadio("ngvariant1", cls.widgets["playVariant1Radio"],
cls.widgets["configImageVariant1"],
FISCHERRANDOMCHESS)
cls.__initVariantRadio("ngvariant2", cls.widgets["playVariant2Radio"],
cls.widgets["configImageVariant2"], LOSERSCHESS)
#@idle_add
def updateCombos(*args):
if cls.widgets["playNormalRadio"].get_active():
variant = NORMALCHESS
elif cls.widgets["playVariant1Radio"].get_active():
variant = conf.get("ngvariant1", FISCHERRANDOMCHESS)
else:
variant = conf.get("ngvariant2", LOSERSCHESS)
variant1 = conf.get("ngvariant1", FISCHERRANDOMCHESS)
cls.widgets["playVariant1Radio"].set_tooltip_text(variants[variant1].__desc__)
variant2 = conf.get("ngvariant2", LOSERSCHESS)
cls.widgets["playVariant2Radio"].set_tooltip_text(variants[variant2].__desc__)
data = [(item[0], item[1]) for item in playerItems[variant]]
uistuff.updateCombo(cls.widgets["blackPlayerCombobox"], data)
uistuff.updateCombo(cls.widgets["whitePlayerCombobox"], data)
discoverer.connect_after("all_engines_discovered", updateCombos)
updateCombos(discoverer)
conf.notify_add("ngvariant1", updateCombos)
conf.notify_add("ngvariant2", updateCombos)
cls.widgets["playNormalRadio"].connect("toggled", updateCombos)
cls.widgets["playNormalRadio"].set_tooltip_text(variants[NORMALCHESS].__desc__)
cls.widgets["playVariant1Radio"].connect("toggled", updateCombos)
variant1 = conf.get("ngvariant1", FISCHERRANDOMCHESS)
cls.widgets["playVariant1Radio"].set_tooltip_text(variants[variant1].__desc__)
cls.widgets["playVariant2Radio"].connect("toggled", updateCombos)
variant2 = conf.get("ngvariant2", LOSERSCHESS)
cls.widgets["playVariant2Radio"].set_tooltip_text(variants[variant2].__desc__)
# The "variant" has to come before players, because the engine positions
# in the user comboboxes can be different in different variants
for key in ("whitePlayerCombobox", "blackPlayerCombobox",
"skillSlider1", "skillSlider2",
"notimeRadio", "blitzRadio", "rapidRadio", "normalRadio",
"playNormalRadio", "playVariant1Radio", "playVariant2Radio"):
uistuff.keep(cls.widgets[key], key)
# We don't want the dialog to deallocate when closed. Rather we hide
# it on respond
cls.widgets["newgamedialog"].connect("delete_event", lambda *a: True)
示例10: __init__
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
#.........这里部分代码省略.........
示例11: __init__
def __init__(self, widgets):
self.widgets = widgets
self.dialog = self.widgets["manage_engines_dialog"]
self.cur_engine = None
self.default_workdir = getEngineDataPrefix()
uistuff.keepWindowSize("engineswindow", self.dialog, defaultSize=(1, 500))
# Put engines into tree store
allstore = Gtk.ListStore(Pixbuf, str)
self.tv = self.widgets["engines_treeview"]
self.tv.set_model(allstore)
self.tv.append_column(Gtk.TreeViewColumn(
"Flag", Gtk.CellRendererPixbuf(), pixbuf=0))
name_renderer = Gtk.CellRendererText()
name_renderer.set_property("editable", True)
self.tv.append_column(Gtk.TreeViewColumn("Name", name_renderer, text=1))
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")
name_renderer.connect("edited", name_edited)
# Add cell renderer to protocol combo column
protocol_combo = self.widgets["engine_protocol_combo"]
cell = Gtk.CellRendererText()
protocol_combo.pack_start(cell, True)
protocol_combo.add_attribute(cell, "text", 0)
# Add columns and cell renderers to options treeview
self.options_store = Gtk.ListStore(str, GObject.TYPE_PYOBJECT)
optv = self.widgets["options_treeview"]
optv.set_model(self.options_store)
optv.append_column(Gtk.TreeViewColumn(
"Option", Gtk.CellRendererText(), text=0))
optv.append_column(Gtk.TreeViewColumn(
"Data", KeyValueCellRenderer(self.options_store), data=1))
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 update_store(*args):
newGameDialog.createPlayerUIGlobals(discoverer)
engine_names = [row[1] for row in allstore]
new_items = []
# don't add the very first (Human) player to engine store
for item in newGameDialog.playerItems[0][1:]:
if item[1] not in engine_names:
new_items.append(item)
iter = None
for item in new_items:
iter = allstore.append(item)
if iter is not None:
ts = self.tv.get_selection()
ts.select_iter(iter)
update_options()
update_store()
def do_update_store(*args):
GLib.idle_add(update_store)
discoverer.connect_after("engine_discovered", do_update_store)
################################################################
# remove button
################################################################
def remove(button):
if self.cur_engine is not None:
self.widgets['remove_engine_button'].set_sensitive(False)
engine = discoverer.getEngineByName(self.cur_engine)
discoverer.removeEngine(self.cur_engine)
discoverer.save()
selection = self.tv.get_selection()
#.........这里部分代码省略.........
示例12: __init__
def __init__(self):
self.widgets = uistuff.GladeWidgets("analyze_game.glade")
self.widgets["analyze_game"].set_transient_for(mainwindow())
self.stop_event = asyncio.Event()
uistuff.keep(self.widgets["fromCurrent"], "fromCurrent")
uistuff.keep(self.widgets["shouldBlack"], "shouldBlack")
uistuff.keep(self.widgets["shouldWhite"], "shouldWhite")
uistuff.keep(self.widgets["threatPV"], "threatPV")
uistuff.keep(self.widgets["showEval"], "showEval")
uistuff.keep(self.widgets["showBlunder"], "showBlunder")
uistuff.keep(self.widgets["max_analysis_spin"], "max_analysis_spin")
uistuff.keep(self.widgets["variation_threshold_spin"], "variation_threshold_spin")
# Analyzing engines
uistuff.createCombo(self.widgets["ana_combobox"], name="ana_combobox")
from pychess.widgets import newGameDialog
def update_analyzers_store(discoverer):
data = [(item[0], item[1]) for item in newGameDialog.analyzerItems]
uistuff.updateCombo(self.widgets["ana_combobox"], data)
discoverer.connect_after("all_engines_discovered", update_analyzers_store)
update_analyzers_store(discoverer)
uistuff.keep(self.widgets["ana_combobox"], "ana_combobox", anal_combo_get_value,
lambda combobox, value: anal_combo_set_value(combobox, value, "hint_mode", HINT))
def hide_window(button, *args):
self.widgets["analyze_game"].destroy()
def abort():
self.stop_event.set()
self.widgets["analyze_game"].destroy()
def run_analyze(button, *args):
@asyncio.coroutine
def coro():
persp = perspective_manager.get_perspective("games")
gmwidg = persp.cur_gmwidg()
gamemodel = gmwidg.gamemodel
old_check_value = conf.get("analyzer_check")
conf.set("analyzer_check", True)
if HINT not in gamemodel.spectators:
try:
yield from asyncio.wait_for(gamemodel.start_analyzer(HINT), 5.0)
except asyncio.TimeoutError:
log.error("Got timeout error while starting hint analyzer")
return
except Exception:
log.error("Unknown error while starting hint analyzer")
return
analyzer = gamemodel.spectators[HINT]
gmwidg.menuitems["hint_mode"].active = True
threat_PV = conf.get("ThreatPV")
if threat_PV:
old_inv_check_value = conf.get("inv_analyzer_check")
conf.set("inv_analyzer_check", True)
if SPY not in gamemodel.spectators:
try:
yield from asyncio.wait_for(gamemodel.start_analyzer(SPY), 5.0)
except asyncio.TimeoutError:
log.error("Got timeout error while starting spy analyzer")
return
except Exception:
log.error("Unknown error while starting spy analyzer")
return
inv_analyzer = gamemodel.spectators[SPY]
gmwidg.menuitems["spy_mode"].active = True
title = _("Game analyzing in progress...")
text = _("Do you want to abort it?")
content = InfoBar.get_message_content(title, text, Gtk.STOCK_DIALOG_QUESTION)
def response_cb(infobar, response, message):
conf.set("analyzer_check", old_check_value)
if threat_PV:
conf.set("inv_analyzer_check", old_inv_check_value)
message.dismiss()
abort()
message = InfoBarMessage(Gtk.MessageType.QUESTION, content, response_cb)
message.add_button(InfoBarMessageButton(_("Abort"), Gtk.ResponseType.CANCEL))
gmwidg.replaceMessages(message)
@asyncio.coroutine
def analyse_moves():
should_black = conf.get("shouldBlack")
should_white = conf.get("shouldWhite")
from_current = conf.get("fromCurrent")
start_ply = gmwidg.board.view.shown if from_current else 0
move_time = int(conf.get("max_analysis_spin"))
threshold = int(conf.get("variation_threshold_spin"))
for board in gamemodel.boards[start_ply:]:
if self.stop_event.is_set():
break
gmwidg.board.view.setShownBoard(board)
analyzer.setBoard(board)
if threat_PV:
#.........这里部分代码省略.........
示例13: __init__
def __init__(self, widgets):
self.widgets = widgets
self.dialog = self.widgets["manage_engines_dialog"]
self.cur_engine = None
self.default_workdir = getEngineDataPrefix()
uistuff.keepWindowSize("engineswindow", self.dialog)
# Put engines into tree store
allstore = Gtk.ListStore(Pixbuf, str)
self.tv = self.widgets["engines_treeview"]
self.tv.set_model(allstore)
self.tv.append_column(Gtk.TreeViewColumn("Flag",
Gtk.CellRendererPixbuf(),
pixbuf=0))
name_renderer = Gtk.CellRendererText()
name_renderer.set_property("editable", False)
self.tv.append_column(Gtk.TreeViewColumn("Name",
name_renderer,
text=1))
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")
name_renderer.connect("edited", name_edited)
# Add cell renderer to protocol combo column
protocol_combo = self.widgets["engine_protocol_combo"]
protocol_combo.set_name("engine_protocol_combo")
cell = Gtk.CellRendererText()
protocol_combo.pack_start(cell, True)
protocol_combo.add_attribute(cell, "text", 0)
# Add columns and cell renderers to options treeview
self.options_store = Gtk.ListStore(str, GObject.TYPE_PYOBJECT)
optv = self.widgets["options_treeview"]
optv.set_model(self.options_store)
optv.append_column(Gtk.TreeViewColumn("Option",
Gtk.CellRendererText(),
text=0))
optv.append_column(Gtk.TreeViewColumn("Data",
KeyValueCellRenderer(
self.options_store),
data=1))
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")
self.options_store.clear()
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"])
self.options_store.append([key, val])
def update_store(*args):
newGameDialog.createPlayerUIGlobals(discoverer)
engine_names = [row[1] for row in allstore]
new_items = []
# don't add the very first (Human) player to engine store
for item in newGameDialog.allEngineItems:
if item[1] not in engine_names:
new_items.append(item)
ts_iter = None
for item in new_items:
ts_iter = allstore.append(item)
if ts_iter is not None:
text_select = self.tv.get_selection()
text_select.select_iter(ts_iter)
update_options()
update_store()
def do_update_store(*args):
GLib.idle_add(update_store)
discoverer.connect_after("engine_discovered", do_update_store)
#.........这里部分代码省略.........
示例14: add
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:
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
discoverer.connect_after("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()
示例15: __init__
def __init__(self, widgets):
self.widgets = widgets
self.dialog = self.widgets["manage_engines_dialog"]
self.cur_engine = None
self.default_workdir = getEngineDataPrefix()
uistuff.keepWindowSize("engineswindow", self.dialog)
# Put engines into tree store
self.allstore = Gtk.ListStore(Pixbuf, str)
self.tv = self.widgets["engines_treeview"]
self.tv.set_model(self.allstore)
self.tv.append_column(Gtk.TreeViewColumn("Flag", Gtk.CellRendererPixbuf(), pixbuf=0))
name_renderer = Gtk.CellRendererText()
name_renderer.set_property("editable", False)
self.tv.append_column(Gtk.TreeViewColumn("Name", name_renderer, text=1))
# Add cell renderer to protocol combo column
protocol_combo = self.widgets["engine_protocol_combo"]
protocol_combo.set_name("engine_protocol_combo")
cell = Gtk.CellRendererText()
protocol_combo.pack_start(cell, True)
protocol_combo.add_attribute(cell, "text", 0)
# Add columns and cell renderers to options treeview
self.options_store = Gtk.ListStore(str, str, GObject.TYPE_PYOBJECT)
optv = self.widgets["options_treeview"]
optv.set_model(self.options_store)
optv.append_column(Gtk.TreeViewColumn(" ", Gtk.CellRendererText(), text=0))
optv.append_column(Gtk.TreeViewColumn(_("Option"), Gtk.CellRendererText(), text=1))
optv.append_column(Gtk.TreeViewColumn(_("Value"), KeyValueCellRenderer(self.options_store), data=2))
self.update_store()
def do_update_store(self, *args):
GLib.idle_add(engine_dialog.update_store)
discoverer.connect_after("engine_discovered", do_update_store)
################################################################
# remove button
################################################################
def remove(button):
if self.cur_engine is not None:
self.widgets['remove_engine_button'].set_sensitive(False)
discoverer.removeEngine(self.cur_engine)
selection = self.tv.get_selection()
result = selection.get_selected()
if result is not None:
model, ts_iter = result
model.remove(ts_iter)
if model.iter_n_children() == 0:
clearView()
# Notify playerCombos in NewGameTasker
discoverer.emit("all_engines_discovered")
self.widgets["remove_engine_button"].connect("clicked", remove)
################################################################
# add button
################################################################
engine_chooser_dialog = Gtk.FileChooserDialog(
_("Select engine"), mainwindow(), Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN,
Gtk.ResponseType.OK))
filter = Gtk.FileFilter()
filter.set_name(_("Executable files"))
filter.add_mime_type("application/x-executable")
filter.add_mime_type("application/x-sharedlib")
filter.add_mime_type("application/x-ms-dos-executable")
filter.add_mime_type("application/x-msdownload")
filter.add_pattern("*.exe")
for vm in VM_LIST:
filter.add_pattern("*%s" % vm.ext)
engine_chooser_dialog.add_filter(filter)
self.add = False
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()
#.........这里部分代码省略.........