def callback(selection): model, iter = selection.get_selected() if iter: radiobutton.set_label("%s" % model.get(iter, 0) + _(" chess")) path = model.get_path(iter) variant = pathToVariant[path.to_string()] conf.set(confid, variant)
def onFinger(self, fm, finger): if not finger.getName() == self.connection.getUsername(): return self.finger = finger numfingers = conf.get("numberOfFingers") + 1 conf.set("numberOfFingers", numfingers) if conf.get("numberOfTimesLoggedInAsRegisteredUser") is 1 and numfingers is 1: standard = self.__getRating(TYPE_STANDARD) blitz = self.__getRating(TYPE_BLITZ) lightning = self.__getRating(TYPE_LIGHTNING) if standard is not None: self.seekEditorWidgetDefaults["ratingCenterSlider"][ 0] = standard // RATING_SLIDER_STEP elif blitz is not None: self.seekEditorWidgetDefaults["ratingCenterSlider"][ 0] = blitz // RATING_SLIDER_STEP if blitz is not None: self.seekEditorWidgetDefaults["ratingCenterSlider"][ 1] = blitz // RATING_SLIDER_STEP if lightning is not None: self.seekEditorWidgetDefaults["ratingCenterSlider"][ 2] = lightning // RATING_SLIDER_STEP elif blitz is not None: self.seekEditorWidgetDefaults["ratingCenterSlider"][ 2] = blitz // RATING_SLIDER_STEP for i in range(1, 4): self.__loadSeekEditor(i) self.__updateSeekEditor(i) self.__saveSeekEditor(i) self.__writeSavedSeeks(i) self.__updateYourRatingHBox()
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 __init__ (self, widgets): # Init 'auto save" checkbutton def checkCallBack (*args): checkbox = widgets["autoSave"] widgets["autosave_grid"].set_property("sensitive", checkbox.get_active()) conf.notify_add("autoSave", checkCallBack) widgets["autoSave"].set_active(False) uistuff.keep(widgets["autoSave"], "autoSave") checkCallBack() default_path = os.path.expanduser("~") autoSavePath = conf.get("autoSavePath", default_path) conf.set("autoSavePath", autoSavePath) auto_save_chooser_dialog = Gtk.FileChooserDialog(_("Select auto save path"), None, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) auto_save_chooser_button = Gtk.FileChooserButton.new_with_dialog(auto_save_chooser_dialog) auto_save_chooser_button.set_current_folder(autoSavePath) widgets["savePathChooserDock"].add(auto_save_chooser_button) auto_save_chooser_button.show() def select_auto_save(button): new_directory = auto_save_chooser_dialog.get_filename() if new_directory != autoSavePath: conf.set("autoSavePath", new_directory) auto_save_chooser_button.connect("current-folder-changed", select_auto_save) conf.set("autoSaveFormat", conf.get("autoSaveFormat", "pychess")) uistuff.keep(widgets["autoSaveFormat"], "autoSaveFormat") uistuff.keep(widgets["saveEmt"], "saveEmt") uistuff.keep(widgets["saveEval"], "saveEval") uistuff.keep(widgets["saveOwnGames"], "saveOwnGames")
def analyse_moves(): should_black = conf.get("shouldBlack", True) should_white = conf.get("shouldWhite", True) 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)) threshold = int(conf.get("variation_threshold_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) if threat_PV: inv_analyzer.setBoard(board) time.sleep(move_time + 0.1) ply = board.ply color = (ply - 1) % 2 if ply - 1 in gamemodel.scores and ply in gamemodel.scores and ( (color == BLACK and should_black) or (color == WHITE and should_white)): oldmoves, oldscore, olddepth = gamemodel.scores[ply - 1] oldscore = oldscore * -1 if color == BLACK else oldscore score_str = prettyPrintScore(oldscore, olddepth) moves, score, depth = gamemodel.scores[ply] score = score * -1 if color == WHITE else score diff = score - oldscore if (diff > threshold and color == BLACK) or (diff < -1 * threshold 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: # 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)) widgets["analyze_game"].hide() widgets["analyze_ok_button"].set_sensitive(True) conf.set("analyzer_check", old_check_value) if threat_PV: conf.set("inv_analyzer_check", old_inv_check_value) message.dismiss()
def run (no_debug, no_idle_add_debug, no_thread_debug, log_viewer, chess_file, ics_host, ics_port): # Start logging if log_viewer: log.logger.addHandler(GLogHandler(logemitter)) log.logger.setLevel(logging.WARNING if no_debug is True else logging.DEBUG) oldlogs = [l for l in os.listdir(getUserDataPrefix()) if l.endswith(".log")] conf.set("max_log_files", conf.get("max_log_files", 10)) if len(oldlogs) >= conf.get("max_log_files", 10): oldlogs.sort() try: os.remove(addUserDataPrefix(oldlogs[0])) except OSError as e: pass signal.signal(signal.SIGINT, Gtk.main_quit) def cleanup (): SubProcess.finishAllSubprocesses() atexit.register(cleanup) pychess = PyChess(log_viewer, chess_file) idle_add.debug = not no_idle_add_debug sys.stdout = LogPipe(sys.stdout, "stdout") sys.stderr = LogPipe(sys.stderr, "stdout") log.info("PyChess %s %s rev. %s %s started" % (VERSION_NAME, VERSION, pychess.hg_rev, pychess.hg_date)) log.info("Command line args: '%s'" % chess_file) if not no_thread_debug: start_thread_dump() if ics_host: ICLogon.host = ics_host if ics_port: ICLogon.port = ics_port Gtk.main()
def analyse_moves(): move_time = int(conf.get("max_analysis_spin", 3)) thresold = int(conf.get("variation_thresold_spin", 50)) for board in gamemodel.boards: if stop_event.is_set(): break glock.acquire() try: gmwidg.board.view.setShownBoard(board) finally: glock.release() analyzer.setBoard(board) time.sleep(move_time + 0.1) ply = board.ply if ply - 1 in gamemodel.scores: color = (ply - 1) % 2 oldmoves, oldscore, olddepth = gamemodel.scores[ply - 1] 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): gamemodel.add_variation(gamemodel.boards[ply - 1], oldmoves) widgets["analyze_game"].hide() widgets["analyze_ok_button"].set_sensitive(True) conf.set("analyzer_check", old_check_value)
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)
def __init__(self, widgets): conf.set("firstName", conf.get("firstName", conf.username)) conf.set("secondName", conf.get("secondName", _("Guest"))) # Give to uistuff.keeper for key in ( "firstName", "secondName", "showEmt", "showEval", "hideTabs", "faceToFace", "showCords", "showCaptured", "figuresInNotation", "fullAnimation", "moveAnimation", "noAnimation", ): uistuff.keep(widgets[key], key) # Options on by default for key in ("autoRotate", "fullAnimation", "showBlunder"): uistuff.keep(widgets[key], key, first_value=True)
def __init__(self): self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL, title=_("Ask for permissions")) self.window.set_transient_for(mainwindow()) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) gtk_version = (Gtk.get_major_version(), Gtk.get_minor_version()) if gtk_version >= (3, 12): vbox.props.margin_start = 9 vbox.props.margin_end = 9 else: vbox.props.margin_left = 9 vbox.props.margin_right = 9 vbox.props.margin_bottom = 9 self.window.add(vbox) uistuff.keepWindowSize("externalsdialog", self.window, (320, 240), uistuff.POSITION_CENTER) label = Gtk.Label(_("Some of PyChess features needs your permission to download external programs")) vbox.pack_start(label, True, True, 0) box = Gtk.Box() check_button = Gtk.CheckButton(_("database querying needs scoutfish")) check_button.set_active(conf.get("download_scoutfish", False)) check_button.connect("toggled", lambda w: conf.set("download_scoutfish", w.get_active())) box.add(check_button) link = "https://github.com/pychess/scoutfish" link_button = Gtk.LinkButton(link, link) box.add(link_button) vbox.pack_start(box, False, False, 0) box = Gtk.Box() check_button = Gtk.CheckButton(_("database opening tree needs chess_db")) check_button.set_active(conf.get("download_chess_db", False)) check_button.connect("toggled", lambda w: conf.set("download_chess_db", w.get_active())) box.add(check_button) link = "https://github.com/pychess/chess_db" link_button = Gtk.LinkButton(link, link) box.add(link_button) vbox.pack_start(box, False, False, 0) box = Gtk.Box() check_button = Gtk.CheckButton(_("ICC lag compensation needs timestamp")) check_button.set_active(conf.get("download_timestamp", False)) check_button.connect("toggled", lambda w: conf.set("download_timestamp", w.get_active())) box.add(check_button) link = "https://www.chessclub.com/user/resources/icc/timestamp" link_button = Gtk.LinkButton(link, link) box.add(link_button) vbox.pack_start(box, False, False, 0) check_button = Gtk.CheckButton(_("Don't show this dialog on startup.")) check_button.set_active(conf.get("dont_show_externals_at_startup", False)) check_button.connect("toggled", lambda w: conf.set("dont_show_externals_at_startup", w.get_active())) vbox.pack_start(check_button, True, True, 0) buttonbox = Gtk.ButtonBox() close_button = Gtk.Button.new_from_stock(Gtk.STOCK_OK) close_button.connect("clicked", self.on_close_clicked) self.window.connect("delete_event", lambda w, a: self.window.destroy()) buttonbox.add(close_button) vbox.pack_start(buttonbox, False, False, 0)
def on_learn_changed(combo): tree_iter = combo.get_active_iter() if tree_iter is None: return else: model = combo.get_model() newlearn = model.get_path(tree_iter)[0] conf.set("learncombo%s" % self.category, newlearn)
def row_activated(self, widget, path, col): if path is None: return else: pieces = ENDGAMES[path[0]][0].lower() conf.set("categorycombo", ENDGAME) from pychess.widgets.TaskerManager import learn_tasker learn_tasker.learn_combo.set_active(path[0]) start_endgame_from(pieces)
def selectAutoSave(_): """ :Description: Sets the auto save path for stored games if it has changed since last time :signal: Activated on receiving the 'current-folder-changed' signal """ new_directory = auto_save_chooser_dialog.get_filename() if new_directory != self.auto_save_path: conf.set("autoSavePath", new_directory)
def row_activated(self, widget, path, col): if path is None: return else: filename = PUZZLES[path[0]][0] conf.set("categorycombo", PUZZLE) from pychess.widgets.TaskerManager import learn_tasker learn_tasker.learn_combo.set_active(path[0]) start_puzzle_from(filename)
def select_new_image(button): new_image = image_chooser_dialog.get_filename() if new_image: conf.set("welcome_image", new_image) from pychess.widgets.TaskerManager import tasker newTheme(tasker, background=new_image) tasker.queue_draw() else: # restore the original image_chooser_dialog.set_filename(path)
def __init__ (self, widgets): conf.set("firstName", conf.get("firstName", conf.username)) conf.set("secondName", conf.get("secondName", _("Guest"))) # Give to uistuff.keeper for key in ("firstName", "secondName", "hideTabs", "autoRotate", "faceToFace", "showCords", "figuresInNotation", "autoCallFlag", "fullAnimation", "moveAnimation", "noAnimation"): uistuff.keep(widgets[key], key)
def setFromConf (): try: v = conf.getStrict(key) except TypeError: log.warning("uistuff.keep.setFromConf: Key '%s' from conf had the wrong type '%s', ignored" % \ (key, type(conf.getStrict(key)))) if first_value != None: conf.set(key, first_value) else: conf.set(key, get_value()) else: set_value(v)
def on_logOnAsGuest_toggled(self, widget): names = self.get_user_names() self.widgets["nameEntry"].set_text(names[1] if widget.get_active() else names[0]) if self.ics == "ICC": self.widgets["nameLabel"].set_sensitive(not widget.get_active()) self.widgets["nameEntry"].set_sensitive(not widget.get_active()) else: self.widgets["nameLabel"].set_sensitive(True) self.widgets["nameEntry"].set_sensitive(True) self.widgets["passwordLabel"].set_sensitive(not widget.get_active()) self.widgets["passEntry"].set_sensitive(not widget.get_active()) conf.set("asGuestCheck", widget.get_active(), section=self.ics)
def keep(widget, key, get_value_=None, set_value_=None, first_value=None): if widget is None: raise AttributeError("key '%s' isn't in widgets" % key) for class_, methods_ in METHODS: # Use try-except just to make spinx happy... try: if isinstance(widget, class_): getter, setter, signal = methods_ break except TypeError: getter, setter, signal = methods_ break else: raise AttributeError("I don't have any knowledge of type: '%s'" % widget) if get_value_: def get_value(): return get_value_(widget) else: get_value = getattr(widget, getter) if set_value_: def set_value(v): return set_value_(widget, v) else: set_value = getattr(widget, setter) def setFromConf(): try: v = conf.get(key) except TypeError: log.warning("uistuff.keep.setFromConf: Key '%s' from conf had the wrong type '%s', ignored" % (key, type(conf.get(key)))) if first_value is not None: conf.set(key, first_value) else: conf.set(key, get_value()) else: set_value(v) def callback(*args): if not conf.hasKey(key) or conf.get(key) != get_value(): conf.set(key, get_value()) widget.connect(signal, callback) conf.notify_add(key, lambda *args: setFromConf()) if conf.hasKey(key): setFromConf() elif first_value is not None: conf.set(key, first_value)
def requestMultiPV(self, n): multipvMax = self.maxAnalysisLines() n = min(n, multipvMax) if n != self.multipvSetting: conf.set("multipv", n) self.multipvSetting = n print("stop", file=self.engine) print("setoption name MultiPV value", n, file=self.engine) self._searchNow() return n
def run(no_debug, idle_add_debug, thread_debug, log_viewer, purge_recent, chess_file, ics_host, ics_port): # Start logging if log_viewer: log.logger.addHandler(GLogHandler(logemitter)) log.logger.setLevel(logging.WARNING if no_debug is True else logging.DEBUG) oldlogs = [l for l in os.listdir(getUserDataPrefix()) if l.endswith(".log")] conf.set("max_log_files", conf.get("max_log_files", 10)) oldlogs.sort() l = len(oldlogs) while l > conf.get("max_log_files", 10): try: os.remove(addUserDataPrefix(oldlogs[0])) del oldlogs[0] except OSError: pass l -= 1 if purge_recent: items = recentManager.get_items() for item in items: uri = item.get_uri() if item.get_application_info("pychess"): recentManager.remove_item(uri) signal.signal(signal.SIGINT, Gtk.main_quit) signal.signal(signal.SIGTERM, Gtk.main_quit) def cleanup(): ICLogon.stop() SubProcess.finishAllSubprocesses() atexit.register(cleanup) pychess = PyChess(log_viewer, chess_file) idle_add.debug = idle_add_debug sys.stdout = LogPipe(sys.stdout, "stdout") sys.stderr = LogPipe(sys.stderr, "stdout") log.info("PyChess %s %s git %s" % (VERSION_NAME, VERSION, pychess.git_rev)) log.info("Command line args: '%s'" % chess_file) log.info("Platform: %s" % platform.platform()) log.info("Python version: %s.%s.%s" % sys.version_info[0:3]) log.info("Pyglib version: %s.%s.%s" % GLib.pyglib_version) if thread_debug: start_thread_dump() if ics_host: ICLogon.host = ics_host if ics_port: ICLogon.port = ics_port Gtk.main()
def requestMultiPV (self, n): multipvMax = self.maxAnalysisLines() n = min(n, multipvMax) if n != self.multipvSetting: conf.set("multipv", n) with self.moveLock: self.multipvSetting = n print >> self.engine, "stop" print >> self.engine, "setoption name MultiPV value", n self._searchNow() return n
def __saveSeekEditor(self, seeknumber): for widget in self.seekEditorWidgets: if widget in self.seekEditorWidgetGettersSetters: uistuff.saveDialogWidget( self.widgets[widget], widget, seeknumber, get_value_=self.seekEditorWidgetGettersSetters[widget][0]) else: uistuff.saveDialogWidget(self.widgets[widget], widget, seeknumber) conf.set("lastdifference-%d" % seeknumber, self.lastdifference)
def __set_panel_active(self, panel, active): name = panel.__name__ from pychess.widgets.gamewidget import notebooks, docks from pychess.widgets.pydock import EAST if active: conf.set(name, True) leaf = notebooks["board"].get_parent().get_parent() leaf.dock(docks[name][1], EAST, docks[name][0], name) else: conf.set(name, False) notebooks[name].get_parent().get_parent().undock(notebooks[name])
def __init__(self, widgets): # Init 'auto save" checkbutton def checkCallBack(_): """ :Description: Sets the various option based on user interaction with the checkboxes in the gui """ checkbox = widgets["autoSave"] widgets["autosave_grid"].set_property("sensitive", checkbox.get_active()) conf.notify_add("autoSave", checkCallBack) widgets["autoSave"].set_active(False) uistuff.keep(widgets["autoSave"], "autoSave") checkCallBack(_) default_path = os.path.expanduser("~") self.auto_save_path = conf.get("autoSavePath", default_path) conf.set("autoSavePath", self.auto_save_path) auto_save_chooser_dialog = Gtk.FileChooserDialog( _("Select auto save path"), None, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) auto_save_chooser_button = Gtk.FileChooserButton.new_with_dialog( auto_save_chooser_dialog) auto_save_chooser_button.set_current_folder(self.auto_save_path) widgets["savePathChooserDock"].add(auto_save_chooser_button) auto_save_chooser_button.show() def selectAutoSave(_): """ :Description: Sets the auto save path for stored games if it has changed since last time :signal: Activated on receiving the 'current-folder-changed' signal """ new_directory = auto_save_chooser_dialog.get_filename() if new_directory != self.auto_save_path: conf.set("autoSavePath", new_directory) auto_save_chooser_button.connect("current-folder-changed", selectAutoSave) conf.set("autoSaveFormat", conf.get("autoSaveFormat", "pychess")) uistuff.keep(widgets["autoSaveFormat"], "autoSaveFormat") uistuff.keep(widgets["saveEmt"], "saveEmt") uistuff.keep(widgets["saveEval"], "saveEval") uistuff.keep(widgets["saveOwnGames"], "saveOwnGames")
def callback (combobox, index): if combobox.get_active() == SOUND_SELECT: if opendialog.run() == gtk.RESPONSE_ACCEPT: uri = opendialog.get_uri() model = combobox.get_model() conf.set("sounduri%d"%index, uri) label = os.path.split(uri)[1] if len(model) == 3: model.append([audioIco, label]) else: model.set(model.get_iter((3,)), 1, label) combobox.set_active(3) else: combobox.set_active(conf.get("soundcombo%d"%index,SOUND_MUTE)) opendialog.hide()
def playAction (cls, action): if not conf.get("useSounds", True): return if type(action) == str: no = cls.actionToKeyNo[action] else: no = action typ = conf.get("soundcombo%d" % no, SOUND_MUTE) if typ == SOUND_BEEP: sys.stdout.write("\a") sys.stdout.flush() elif typ == SOUND_URI: uri = conf.get("sounduri%d" % no, "") if not os.path.isfile(uri[7:]): conf.set("soundcombo%d" % no, SOUND_MUTE) return cls.getPlayer().play(uri)
def playAction(cls, action): if not cls.useSounds: return if isinstance(action, str): key_no = cls.actionToKeyNo[action] else: key_no = action typ = cls.soundcombo[key_no] if typ == SOUND_BEEP: sys.stdout.write("\a") sys.stdout.flush() elif typ == SOUND_URI: uri = cls.sounduri[key_no] if not os.path.isfile(url2pathname(uri[5:])): conf.set("soundcombo%d" % key_no, SOUND_MUTE) return cls.getPlayer().play(uri)
def __init__ (self, widgets): conf.set("pieceTheme", conf.get("pieceTheme", "pychess")) self.themes = self.discover_themes() store = gtk.ListStore(gtk.gdk.Pixbuf, str) for theme in self.themes: pngfile = "%s/%s.png" % (addDataPrefix("pieces"), theme) if isfile(pngfile): pixbuf = gtk.gdk.pixbuf_new_from_file(pngfile) store.append((pixbuf, theme)) else: print "WARNING: No piece theme preview icons find. Run create_theme_preview.sh !" break iconView = widgets["pieceTheme"] iconView.set_model(store) iconView.set_pixbuf_column(0) iconView.set_text_column(1) def _get_active(iconview): model = iconview.get_model() selected = iconview.get_selected_items() if len(selected) == 0: return conf.get("pieceTheme", "pychess") i = selected[0][0] theme = model[i][1] Pieces.set_piece_theme(theme) return theme def _set_active(iconview, value): try: index = self.themes.index(value) except ValueError: index = 0 iconview.select_path((index,)) uistuff.keep (widgets["pieceTheme"], "pieceTheme", _get_active, _set_active)
def run_analyze(button, *args): old_check_value = conf.get("analyzer_check", True) conf.set("analyzer_check", True) widgets["analyze_ok_button"].set_sensitive(False) gmwidg = gamewidget.cur_gmwidg() gamemodel = gameDic[gmwidg] analyzer = gamemodel.spectators[HINT] def analyse_moves(): move_time = int(conf.get("max_analysis_spin", 3)) thresold = int(conf.get("variation_thresold_spin", 50)) for board in gamemodel.boards: if stop_event.is_set(): break glock.acquire() try: gmwidg.board.view.setShownBoard(board) finally: glock.release() analyzer.setBoard(board) time.sleep(move_time + 0.1) ply = board.ply if ply - 1 in gamemodel.scores: color = (ply - 1) % 2 oldmoves, oldscore, olddepth = gamemodel.scores[ply - 1] 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): gamemodel.add_variation(gamemodel.boards[ply - 1], oldmoves) widgets["analyze_game"].hide() widgets["analyze_ok_button"].set_sensitive(True) conf.set("analyzer_check", old_check_value) t = threading.Thread(target=analyse_moves, name=fident(analyse_moves)) t.daemon = True t.start() return True
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()
def onResetColourClicked(_): """ :Description: Resets the chess board squares to factory default """ conf.set("lightcolour", conf.get("lightcolour")) conf.set("darkcolour", conf.get("darkcolour"))
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: inv_analyzer.setBoard(board) yield from asyncio.sleep(move_time + 0.1) ply = board.ply - gamemodel.lowply color = (ply - 1) % 2 if ply - 1 in gamemodel.scores and ply in gamemodel.scores and ( (color == BLACK and should_black) or (color == WHITE and should_white)): oldmoves, oldscore, olddepth = gamemodel.scores[ply - 1] oldscore = oldscore * -1 if color == BLACK else oldscore score_str = prettyPrintScore(oldscore, olddepth) moves, score, depth = gamemodel.scores[ply] score = score * -1 if color == WHITE else score diff = score - oldscore if ((diff > threshold and color == BLACK) or (diff < -1 * threshold and color == WHITE) ) and (gamemodel.moves[ply - 1] != parseAny( gamemodel.boards[ply - 1], oldmoves[0])): 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="Threatening", score=score_str0, emit=False) 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, emit=False) 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)) self.widgets["analyze_game"].hide() self.widgets["analyze_ok_button"].set_sensitive(True) conf.set("analyzer_check", old_check_value) if threat_PV: conf.set("inv_analyzer_check", old_inv_check_value) message.dismiss() gamemodel.emit("analysis_finished") create_task(analyse_moves()) hide_window(None) return True
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: inv_analyzer.setBoard(board) yield from asyncio.sleep(move_time + 0.1) ply = board.ply - gamemodel.lowply color = (ply - 1) % 2 if ply - 1 in gamemodel.scores and ply in gamemodel.scores and ( (color == BLACK and should_black) or (color == WHITE and should_white)): oldmoves, oldscore, olddepth = gamemodel.scores[ply - 1] oldscore = oldscore * -1 if color == BLACK else oldscore score_str = prettyPrintScore(oldscore, olddepth) moves, score, depth = gamemodel.scores[ply] score = score * -1 if color == WHITE else score diff = score - oldscore if ((diff > threshold and color == BLACK) or (diff < -1 * threshold and color == WHITE) ) and (gamemodel.moves[ply - 1] != parseAny( gamemodel.boards[ply - 1], oldmoves[0])): 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="Threatening", score=score_str0, emit=False) 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, emit=False) 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)) self.widgets["analyze_game"].hide() self.widgets["analyze_ok_button"].set_sensitive(True) conf.set("analyzer_check", old_check_value) if threat_PV: conf.set("inv_analyzer_check", old_inv_check_value) message.dismiss() gamemodel.emit("analysis_finished")
def select_egtb(button): new_directory = egtb_chooser_dialog.get_filename() if new_directory != egtb_path: conf.set("egtb_path", new_directory)
def newTheme(widget, background=None): global surface, provider, loldcolor, doldcolor style_ctxt = widget.get_style_context() # get colors from theme # bg color found, bgcol = style_ctxt.lookup_color("bg_color") if not found: found, bgcol = style_ctxt.lookup_color("theme_bg_color") if not found: # fallback value bgcol = Gdk.RGBA(red=0.929412, green=0.929412, blue=0.929412, alpha=1.0) # bg selected color found, bgsel = style_ctxt.lookup_color("theme_selected_bg_color") if not found: # fallback value bgsel = Gdk.RGBA(red=0.290, green=0.565, blue=0.851, alpha=1.0) # fg color found, fgcol = style_ctxt.lookup_color("fg_color") if not found: found, fgcol = style_ctxt.lookup_color("theme_fg_color") if not found: fgcol = Gdk.RGBA(red=0.180392, green=0.203922, blue=0.211765, alpha=1.000000) # base color found, basecol = style_ctxt.lookup_color("base_color") if not found: found, basecol = style_ctxt.lookup_color("theme_base_color") if not found: basecol = Gdk.RGBA(red=0.929412, green=0.929412, blue=0.929412, alpha=1.0) # text color found, textcol = style_ctxt.lookup_color("text_color") if not found: found, textcol = style_ctxt.lookup_color("theme_text_color") if not found: textcol = Gdk.RGBA(red=0.180392, green=0.203922, blue=0.211765, alpha=1.0) def get_col(col, mult): red = col.red * mult green = col.green * mult blue = col.blue * mult if red > 1.0: red = 1.0 if green > 1.0: green = 1.0 if blue > 1.0: blue = 1.0 if red == 1 and green == 1 and blue == 1: return Gdk.RGBA(0.99, 0.99, 0.99, 1.0) else: return Gdk.RGBA(red, green, blue, 1.0) # derive other colors bgacol = get_col(bgcol, 0.9) # bg_active dcol = get_col(bgcol, 0.7) # dark darksel = get_col(bgsel, 0.71) # dark selected dpcol = get_col(bgcol, 0.71) # dark prelight dacol = get_col(dcol, 0.9) # dark_active lcol = get_col(bgcol, 1.3) # light color lightsel = get_col(bgsel, 1.3) # light selected fgsel = Gdk.RGBA(0.99, 0.99, 0.99, 1.0) # fg selected fgpcol = get_col(fgcol, 1.054) # fg prelight fgacol = Gdk.RGBA(0.0, 0.0, 0.0, 1.0) # fg active textaacol = Gdk.RGBA(min((basecol.red + textcol.red) / 2., 1.0), min((basecol.green + textcol.green) / 2., 1.0), min((basecol.blue + textcol.blue) / 2., 1.0)) # text_aa data = "@define-color p_bg_color " + hexcol(bgcol) + ";" \ "@define-color p_bg_prelight " + hexcol(bgcol) + ";" \ "@define-color p_bg_active " + hexcol(bgacol) + ";" \ "@define-color p_bg_selected " + hexcol(bgsel) + ";" \ "@define-color p_bg_insensitive " + hexcol(bgcol) + ";" \ "@define-color p_base_color " + hexcol(basecol) + ";" \ "@define-color p_dark_color " + hexcol(dcol) + ";" \ "@define-color p_dark_prelight " + hexcol(dpcol) + ";" \ "@define-color p_dark_active " + hexcol(dacol) + ";" \ "@define-color p_dark_selected " + hexcol(darksel) + ";" \ "@define-color p_text_aa " + hexcol(textaacol) + ";" \ "@define-color p_light_color " + hexcol(lcol) + ";" \ "@define-color p_light_selected " + hexcol(lightsel) + ";" \ "@define-color p_fg_color " + hexcol(fgcol) + ";" \ "@define-color p_fg_prelight " + hexcol(fgpcol) + ";" \ "@define-color p_fg_selected " + hexcol(fgsel) + ";" \ "@define-color p_fg_active " + hexcol(fgacol) + ";" if provider is not None: style_ctxt.remove_provider_for_screen(Gdk.Screen.get_default(), provider) provider = Gtk.CssProvider.new() provider.load_from_data(data.encode()) style_ctxt.add_provider_for_screen(Gdk.Screen.get_default(), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) lnewcolor = bgcol dnewcolor = dcol # check if changed if loldcolor and background is None: if lnewcolor.red == loldcolor.red and \ lnewcolor.green == loldcolor.green and \ lnewcolor.blue == loldcolor.blue and \ dnewcolor.red == doldcolor.red and \ dnewcolor.green == doldcolor.green and \ dnewcolor.blue == doldcolor.blue: return loldcolor = lnewcolor doldcolor = dnewcolor # global colors have been set up # now set colors on startup panel lnewcolor = style_ctxt.lookup_color("p_bg_color")[1] dnewcolor = style_ctxt.lookup_color("p_dark_color")[1] colors = [ int(lnewcolor.red * 255), int(lnewcolor.green * 255), int(lnewcolor.blue * 255), int(dnewcolor.red * 255), int(dnewcolor.green * 255), int(dnewcolor.blue * 255) ] if background is None: background = conf.get("welcome_image", addDataPrefix("glade/clear.png")) if not path.isfile(background): background = addDataPrefix("glade/clear.png") conf.set("welcome_image", background) if not background.endswith("clear.png"): pixbuf = GdkPixbuf.Pixbuf.new_from_file(background) # for frmat in GdkPixbuf.Pixbuf.get_formats(): # print(frmat.get_extensions()) surface = Gdk.cairo_surface_create_from_pixbuf(pixbuf, 0, None) return # Check if a cache has been saved temppng = addUserCachePrefix("temp.png") if path.isfile(temppng): fyle = open(temppng, "rb") # Check if the cache was made while using the same theme if list(fyle.read(6)) == colors: surface = cairo.ImageSurface.create_from_png(fyle) return # Get mostly transparant shadowy image imgsurface = cairo.ImageSurface.create_from_png(background) avgalpha = 108 / 255. surface = cairo.ImageSurface(cairo.FORMAT_RGB24, imgsurface.get_width(), imgsurface.get_height()) ctx = cairo.Context(surface) if lnewcolor.blue * 65535 - dnewcolor.blue * 65535 > 0: midtone = dnewcolor.red * 65535 / ( 3 * (lnewcolor.blue * 65535 - dnewcolor.blue * 65535) * (1 - avgalpha)) ctx.set_source_rgb(lnewcolor.red / 2 + dnewcolor.red * midtone / 2, lnewcolor.green / 2 + dnewcolor.green * midtone / 2, lnewcolor.blue / 2 + dnewcolor.blue * midtone / 2) ctx.paint() ctx.set_source_surface(imgsurface, 0, 0) ctx.paint_with_alpha(.8) # Save a cache for later use. Save 'newcolor' in the frist three pixels # to check for theme changes between two instances fyle = open(temppng, "wb") fyle.write(bytes(colors)) surface.write_to_png(fyle)
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) if HINT not in gamemodel.spectators: gamemodel.start_analyzer(HINT) 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) if SPY not in gamemodel.spectators: gamemodel.start_analyzer(SPY) 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) 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)) threshold = int(conf.get("variation_threshold_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) if threat_PV: 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] oldscore = oldscore * -1 if color == BLACK else oldscore score_str = prettyPrintScore(oldscore, olddepth) moves, score, depth = gamemodel.scores[ply] score = score * -1 if color == WHITE else score diff = score-oldscore if (diff > threshold and color==BLACK) or (diff < -1*threshold 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: # 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)) widgets["analyze_game"].hide() widgets["analyze_ok_button"].set_sensitive(True) conf.set("analyzer_check", old_check_value) if threat_PV: conf.set("inv_analyzer_check", old_inv_check_value) message.dismiss() t = threading.Thread(target=analyse_moves, name=fident(analyse_moves)) t.daemon = True t.start() hide_window(None) return True
def onColourSetLight(_): """ :Description: Sets the light squares of the chess board to the value selected in the colour picker """ conf.set('lightcolour', widgets['light_cbtn'].get_color().to_string())
self.widgets["inv_ana_combobox"], "inv_ana_combobox", anal_combo_get_value, lambda combobox, value: anal_combo_set_value( combobox, value, "spy_mode", SPY)) uistuff.keep(self.widgets["max_analysis_spin"], "max_analysis_spin") uistuff.keep(self.widgets["infinite_analysis"], "infinite_analysis") # Sound initing # Setup default sounds EXT = "wav" if sys.platform == "win32" else "ogg" for i in range(COUNT_OF_SOUNDS): if not conf.hasKey("soundcombo%d" % i): conf.set("soundcombo%d" % i, SOUND_URI) if not conf.hasKey("sounduri0"): conf.set("sounduri0", "file:" + pathname2url(addDataPrefix("sounds/move1.%s" % EXT))) if not conf.hasKey("sounduri1"): conf.set("sounduri1", "file:" + pathname2url(addDataPrefix("sounds/check1.%s" % EXT))) if not conf.hasKey("sounduri2"): conf.set("sounduri2", "file:" + pathname2url(addDataPrefix("sounds/capture1.%s" % EXT))) if not conf.hasKey("sounduri3"): conf.set("sounduri3", "file:" + pathname2url(addDataPrefix("sounds/start1.%s" % EXT))) if not conf.hasKey("sounduri4"): conf.set("sounduri4",
def __init__(self, widgets): # Init open dialog opendialog = Gtk.FileChooserDialog( _("Open Sound File"), mainwindow(), Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT)) for dir in self.SOUND_DIRS: if os.path.isdir(dir): opendialog.set_current_folder(dir) break soundfilter = Gtk.FileFilter() soundfilter.set_name(_("Sound files")) soundfilter.add_mime_type("audio/%s" % EXT) soundfilter.add_pattern("*.%s" % EXT) opendialog.add_filter(soundfilter) # Get combo icons icons = ((_("No sound"), "audio-volume-muted", "audio-volume-muted"), (_("Beep"), "stock_bell", "audio-x-generic"), (_("Select sound file..."), "gtk-open", "document-open")) items = [] for level, stock, altstock in icons: image = load_icon(16, stock, altstock) items += [(image, level)] audioIco = load_icon(16, "audio-x-generic") # Set-up combos def callback(combobox, index): if combobox.get_active() == SOUND_SELECT: if opendialog.run() == Gtk.ResponseType.ACCEPT: uri = opendialog.get_uri() model = combobox.get_model() conf.set("sounduri%d" % index, uri) self.sounduri[index] = uri label = unquote(os.path.split(uri)[1]) if len(model) == 3: model.append([audioIco, label]) else: model.set(model.get_iter((3, )), 1, label) combobox.set_active(3) else: combobox.set_active(conf.get("soundcombo%d" % index)) opendialog.hide() for i in range(COUNT_OF_SOUNDS): combo = widgets["sound%dcombo" % i] uistuff.createCombo(combo, items, name="soundcombo%d" % i) combo.connect("changed", callback, i) label = widgets["soundlabel%d" % i] label.props.mnemonic_widget = combo uri = conf.get("sounduri%d" % i) if os.path.isfile(url2pathname(uri[5:])): model = combo.get_model() model.append([audioIco, unquote(os.path.split(uri)[1])]) for i in range(COUNT_OF_SOUNDS): if conf.get("soundcombo%d" % i) == SOUND_URI and \ not os.path.isfile(url2pathname(conf.get("sounduri%d" % i)[5:])): conf.set("soundcombo%d" % i, SOUND_MUTE) uistuff.keep(widgets["sound%dcombo" % i], "soundcombo%d" % i) # Init play button def playCallback(button, index): SoundTab.playAction(index) for i in range(COUNT_OF_SOUNDS): button = widgets["sound%dbutton" % i] button.connect("clicked", playCallback, i) # Init 'use sound" checkbutton def checkCallBack(*args): checkbox = widgets["useSounds"] widgets["sounds_frame"].set_property("sensitive", checkbox.get_active()) self.useSounds = conf.get("useSounds") conf.notify_add("useSounds", checkCallBack) widgets["useSounds"].set_active(True) uistuff.keep(widgets["useSounds"], "useSounds") checkCallBack() if not self.getPlayer().ready: widgets["useSounds"].set_sensitive(False) widgets["useSounds"].set_active(False)
def __init__(self, widgets): self.widgets = widgets # Opening book path = conf.get("opening_file_entry") 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) book.path = 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) uistuff.keep(self.widgets["book_depth_max"], "book_depth_max") uistuff.keep(self.widgets["book_check_exact_match"], "book_exact_match") # Endgame egtb_path = conf.get("egtb_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 conf.set("ana_combobox", conf.get("ana_combobox")) conf.set("inv_ana_combobox", conf.get("inv_ana_combobox")) 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: create_task(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: create_task(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", 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", SPY)) uistuff.keep(self.widgets["max_analysis_spin"], "max_analysis_spin") uistuff.keep(self.widgets["infinite_analysis"], "infinite_analysis")
md.hide() os.remove(dockLocation) for title, panel in docks.values(): title.unparent() panel.unparent() if not os.path.isfile(dockLocation): leaf = dock.dock(docks["board"][1], CENTER, gtk.Label(docks["board"][0]), "board") docks["board"][1].show_all() leaf.setDockable(False) # NE leaf = leaf.dock(docks["historyPanel"][1], EAST, docks["historyPanel"][0], "historyPanel") conf.set("historyPanel", True) leaf = leaf.dock(docks["scorePanel"][1], CENTER, docks["scorePanel"][0], "scorePanel") conf.set("scorePanel", True) # SE leaf = leaf.dock(docks["bookPanel"][1], SOUTH, docks["bookPanel"][0], "bookPanel") conf.set("bookPanel", True) leaf = leaf.dock(docks["commentPanel"][1], CENTER, docks["commentPanel"][0], "commentPanel") conf.set("commentPanel", True) leaf = leaf.dock(docks["chatPanel"][1], CENTER, docks["chatPanel"][0], "chatPanel") conf.set("chatPanel", True)
def __init__(self, widgets): # Init open dialog opendialog = Gtk.FileChooserDialog( _("Open Sound File"), None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT)) for dir in self.SOUND_DIRS: if os.path.isdir(dir): opendialog.set_current_folder(dir) break soundfilter = Gtk.FileFilter() soundfilter.set_name(_("Sound files")) #soundfilter.add_custom(soundfilter.get_needed(), # lambda data: data[3] and data[3].startswith("audio/")) soundfilter.add_mime_type("audio/*") opendialog.add_filter(soundfilter) opendialog.set_filter(soundfilter) # Get combo icons icons = ((_("No sound"), "audio-volume-muted", "audio-volume-muted"), (_("Beep"), "stock_bell", "audio-x-generic"), (_("Select sound file..."), "gtk-open", "document-open")) items = [] for level, stock, altstock in icons: image = load_icon(16, stock, altstock) items += [(image, level)] audioIco = load_icon(16, "audio-x-generic") # Set-up combos def callback(combobox, index): if combobox.get_active() == SOUND_SELECT: if opendialog.run() == Gtk.ResponseType.ACCEPT: uri = opendialog.get_uri() model = combobox.get_model() conf.set("sounduri%d" % index, uri) label = os.path.split(uri)[1] if len(model) == 3: model.append([audioIco, label]) else: model.set(model.get_iter((3, )), 1, label) combobox.set_active(3) else: combobox.set_active( conf.get("soundcombo%d" % index, SOUND_MUTE)) opendialog.hide() for i in range(self.COUNT_OF_SOUNDS): combo = widgets["soundcombo%d" % i] uistuff.createCombo(combo, items) combo.set_active(0) combo.connect("changed", callback, i) label = widgets["soundlabel%d" % i] label.props.mnemonic_widget = combo uri = conf.get("sounduri%d" % i, "") if os.path.isfile(uri[7:]): model = combo.get_model() model.append([audioIco, os.path.split(uri)[1]]) combo.set_active(3) for i in range(self.COUNT_OF_SOUNDS): if conf.get("soundcombo%d"%i, SOUND_MUTE) == SOUND_URI and \ not os.path.isfile(conf.get("sounduri%d"%i,"")[7:]): conf.set("soundcombo%d" % i, SOUND_MUTE) uistuff.keep(widgets["soundcombo%d" % i], "soundcombo%d" % i) #widgets["soundcombo%d"%i].set_active(conf.get("soundcombo%d"%i, SOUND_MUTE)) # Init play button def playCallback(button, index): SoundTab.playAction(index) for i in range(self.COUNT_OF_SOUNDS): button = widgets["soundbutton%d" % i] button.connect("clicked", playCallback, i) # Init 'use sound" checkbutton def checkCallBack(*args): checkbox = widgets["useSounds"] widgets["frame23"].set_property("sensitive", checkbox.get_active()) conf.notify_add("useSounds", checkCallBack) widgets["useSounds"].set_active(True) uistuff.keep(widgets["useSounds"], "useSounds") checkCallBack() def soundError(player, gstmessage): widgets["useSounds"].set_sensitive(False) widgets["useSounds"].set_active(False) self.getPlayer().connect("error", soundError) uistuff.keep(widgets["alarm_spin"], "alarm_spin", first_value=15)
def __init__(self): self.widgets = uistuff.GladeWidgets("tipoftheday.glade") self.widgets["window1"].set_transient_for(mainwindow()) uistuff.keepWindowSize("tipoftheday", self.widgets["window1"], (320, 240), uistuff.POSITION_CENTER) self.widgets["checkbutton1"].set_active( conf.get("show_tip_at_startup")) self.widgets["checkbutton1"].connect( "toggled", lambda w: conf.set("show_tip_at_startup", w.get_active())) self.widgets["close_button"].connect( "clicked", lambda w: self.widgets["window1"].emit("delete-event", None)) self.widgets["window1"].connect( "delete_event", lambda w, a: self.widgets["window1"].destroy()) self.widgets["back_button"].connect( "clicked", lambda w: self.set_currentIndex(self.tips_curindex - 1)) self.widgets["forward_button"].connect( "clicked", lambda w: self.set_currentIndex(self.tips_curindex + 1)) self.tips_fixed = 2 self.tips = [ # PyChess facts -- The first tips_fixed messages are always displayed first _("PyChess is an open-source chess application that can be enhanced by any chess enthusiasts: bug reports, source code, documentation, translations, feature requests, user assistance... Let's get in touch at <b>http://www.pychess.org</b>" ), _("PyChess supports a wide range of chess engines, variants, Internet servers and lessons. It is a perfect desktop application to increase your chess skills very conveniently." ), _("The releases of PyChess hold the name of historical world chess champions. Do you know the name of the current world chess champion?" ), _("Do you know that you can help to translate PyChess into your language, <b>Help</b> > <b>Translate PyChess</b>." ), _("A game is made of an opening, a middle-game and an end-game. PyChess is able to train you thanks to its opening book, its supported chess engines and its training module." ), # Chess facts _("Do you know that it is possible to finish a chess game in just 2 turns?" ), _("Do you know that a knight is better placed in the center of the board?" ), _("Do you know that moving the queen at the very beginning of a game does not offer any particular advantage?" ), _("Do you know that having two-colored bishops working together is very powerful?" ), _("Do you know that the rooks are generally engaged late in game?" ), _("Do you know that the king can move across two cells under certain conditions? This is called " "castling" "."), _("Do you know that the number of possible chess games exceeds the number of atoms in the Universe?" ), # General UI _("You can start a new game by <b>Game</b> > <b>New Game</b>, then choose the <b>Players</b>, <b>Time Control</b> and <b>Chess Variants</b>." ), _("You can choose from 20 different difficulties to play against the computer. It will mainly affect the available time to think." ), _("The level 20 gives a full autonomy to the chess engine in managing its own time during the game." ), _("To save a game <b>Game</b> > <b>Save Game As</b>, give the filename and choose where you want to be saved. At the bottom choose extension type of the file, and <b>Save</b>." ), _("Calling the flag is the termination of the current game when the time of your opponent is over. If the clock is with you, click on the menu item <b>Actions</b> > <b>Call Flag</b> to claim the victory." ), _("Press <b>Ctrl+Z</b> to ask your opponent to rollback the last played move. Against a computer or for an unrated game, undoing is generally automatically accepted." ), _("To play on <b>Fullscreen mode</b>, just press the key <b>F11</b>. Press it again to exit this mode." ), _("Many sounds are emitted by PyChess while you are playing if you activate them in the preferences: <b>Settings</b> > <b>Preferences</b> > <b>Sound tab</b> > <b>Use sounds in PyChess</b>." ), _("Do you know that a game is generally finished after 20 to 40 moves per player? The estimated duration of a game is displayed when you configure a new game." ), _("The standard file format to manage chess games is <b>PGN</b>. It stands for " "Portable Game Notation" ". Do not get confused with PNG which is a usual file format to store drawings and pictures." ), _("You can share a position by using the exchange format <b>FEN</b>, which stands for " "Forsyth-Edwards Notation" ". This format is also adapted for the chess variants."), # Analysis _("You must define a chess engine in the preferences in order to use the local chess analysis. By default, PyChess recommends you to use the free engine named Stockfish which is renown to be the strongest engine in the world." ), _("<b>Hint mode</b> analyzes your game to show you the best current move. Enable it with the shortcut <b>Ctrl+H</b> from the menu <b>View</b>." ), _("<b>Spy mode</b> analyzes the threats, so the best move that your opponent would play as if it was his turn. Enable it with the shortcut <b>Ctrl+Y</b> from the menu <b>View</b>." ), _("<b>Ponder</b> is an option available in some chess engines that allows thinking when it is not the turn of the engine. It will then consume more resources on your computer." ), _("<b>MultiPV</b> is an option of some chess engines that shows other possible good moves. They are displayed in the panel <b>Hints</b>. The value can be adapted from that panel with a double-click on the displayed figure." ), _("You cannot use the local chess analysis mode while you are playing an unterminated game over Internet. Else you would be a cheater." ), _("An evaluation of +2.3 is an advantage for White of more than 2 pawns, even if White and Black have the same number of pawns. The position of all the pieces and their mobility are some of the factors that contribute to the score." ), _("PyChess includes a chess engine that offers an evaluation for any chess position. Winning against PyChess engine is a coherent way to succeed in chess and improve your skills." ), _("The rating is your strength: 1500 is a good average player, 2000 is a national champion and 2800 is the best human chess champion. From the properties of the game in the menu <b>Game</b>, the difference of points gives you your chance to win and the projected evolution of your rating. If your rating is provisional, append a question mark '?' to your level, like " "1399?" "."), _("Several rating systems exist to evaluate your skills in chess. The most common one is ELO (from its creator Arpad Elo) established on 1970. Schematically, the concept is to engage +/- 20 points for a game and that you will win or lose proportionally to the difference of ELO points you have with your opponent." ), _("Each chess engine has its own evaluation function. It is normal to get different scores for a same position." ), # Opening book and EGDB _("The opening book gives you the moves that are considered to be good from a theoretical perspective. You are free to play any other legal move." ), _("The <b>Gaviota tables</b> are precalculated positions that tell the final outcome of the current game in terms of win, loss or draw." ), _("Do you know that your computer is too small to store a 7-piece endgame database? That's why the Gaviota tablebase is limited to 5 pieces." ), _("A tablebase can be connected either to PyChess, or to a compatible chess engine." ), _("The <b>DTZ</b> is the " "distance to zero" ", so the remaining possible moves to end into a tie as soon as possible." ), # Variant chess _("The chess variants consist in changing the start position, the rules of the game, the types of the pieces... The gameplay is totally modified, so you must use dedicated chess engines to play against the computer." ), _("In Chess960, the lines of the main pieces are shuffled in a precise order. Therefore, you cannot use the booking book and you should change your tactical habits." ), _("When playing crazyhouse chess, the captured pieces change of ownership and can reappear on the board at a later turn." ), _("Suicide chess, giveaway chess or antichess are all the same variant: you must give your pieces to your opponent by forcing the captures like at draughts. The outcome of the game can change completely if you make an incorrect move." ), _("Playing horde in PyChess consists in destroying a flow of 36 white pawns with a normal set of black pieces." ), _("You might be interested in playing " "King of the hill" " if you target to place your king in the middle of the board, instead of protecting it in a corner of the board as usual." ), _("A lot of fun is offered by atomic chess that destroys all the surrounding main pieces at each capture move." ), _("The experienced chess players can use blind pieces by starting a new variant game." ), # Internet chess _("You should sign up online to play on an Internet chess server, so that you can find your games later and see the evolution of your rating. In the preferences, PyChess still have the possibility to save your played games locally." ), _("The time compensation is a feature that doesn't waste your clock time because of the latency of your Internet connection. The module can be downloaded from the menu <b>Edit</b> > <b>Externals</b>." ), _("You can play against chess engines on an Internet chess server. Use the filter to include or exclude them from the available players." ), _("The communication with an Internet chess server is not standardized. Therefore you can only connect to the supported chess servers in PyChess, like freechess.org or chessclub.com" ), # Externals _("PyChess uses the external module Scoutfish to evaluate the chess databases. For example, it is possible to extract the games where some pieces are in precise count or positions." ), _("Parser/ChessDB is an external module used by PyChess to show the expected outcome for a given position." ), _("SQLite is an internal module used to describe the loaded PGN files, so that PyChess can retrieve the games very fast during a search." ), _("PyChess generates 3 information files when a PGN file is opened : .sqlite (description), .scout (positions), .bin (book and outcomes). These files can be removed manually if necessary." ), # Lessons _("PyChess uses offline lessons to learn chess. You will be then never disappointed if you have no Internet connection." ), _("To start Learning, click on the <b>Book icon</b> available on the welcome screen. Or choose the category next to that button to start the activity directly." ), _("The <b>lectures</b> are commented games to learn step-by-step the strategy and principles of some chess techniques. Just watch and read." ), _("Whatever the number of pawns, an <b>end-game</b> starts when the board is made of certain main pieces : 1 rook vs 1 bishop, 1 queen versus 2 rooks, etc... Knowing the moves will help you to not miss the checkmate!" ), _("A <b>puzzle</b> is a set of simple positions classified by theme for which you should guess the best moves. It helps you to understand the patterns to drive an accurate attack or defense." ), _("A <b>lesson</b> is a complex study that explains the tactics for a given position. It is common to view circles and arrows over the board to focus on the behavior of the pieces, the threats, etc..." ) ] self.tips_seed = conf.get("tips_seed") if self.tips_seed == 0: # Forbidden value self.tips_seed = 123456789 + randrange(876543210) conf.set("tips_seed", self.tips_seed) self.tips_curindex = conf.get("tips_index") self.shuffleTips()
def select_font(button): conf.set("movetextFont", button.get_font_name())
def __init__(self, widgets): # Board Colours style_ctxt = widgets["window1"].get_style_context() LIGHT = hexcol(style_ctxt.lookup_color("p_light_color")[1]) DARK = hexcol(style_ctxt.lookup_color("p_dark_color")[1]) def onColourSetLight(_): """ :Description: Sets the light squares of the chess board to the value selected in the colour picker """ conf.set('lightcolour', widgets['light_cbtn'].get_color().to_string()) widgets["light_cbtn"].connect_after("color-set", onColourSetLight) def onColourSetDark(_): """ :Description: Sets the dark squares of the chess board to the value selected in the colour picker """ conf.set('darkcolour', widgets['dark_cbtn'].get_color().to_string()) widgets["dark_cbtn"].connect_after("color-set", onColourSetDark) def onResetColourClicked(_): """ :Description: Resets the chess board squares to factory default """ conf.set("lightcolour", LIGHT) conf.set("darkcolour", DARK) widgets["reset_btn"].connect("clicked", onResetColourClicked) # Get the current board colours if set, if not set, set them to default conf.set("lightcolour", conf.get("lightcolour", LIGHT)) conf.set("darkcolour", conf.get("darkcolour", DARK)) # Next 2 lines take a #hex str converts them to a color then to a RGBA representation self.lightcolour = Gdk.RGBA() self.lightcolour.parse(conf.get("lightcolour", LIGHT)) self.darkcolour = Gdk.RGBA() self.darkcolour.parse(conf.get("darkcolour", DARK)) # Set the color swatches in preference to stored values widgets['light_cbtn'].set_rgba(self.lightcolour) widgets['dark_cbtn'].set_rgba(self.darkcolour) # Chess Sets self.themes = self.discoverThemes() store = Gtk.ListStore(GdkPixbuf.Pixbuf, str) for theme in self.themes: pngfile = "%s/%s.png" % (addDataPrefix("pieces"), theme) if isfile(pngfile): pixbuf = get_pixbuf(pngfile) store.append((pixbuf, theme)) else: print( "WARNING: No piece theme preview icons found. Please run \ create_theme_preview.sh !") break self.icon_view = widgets["pieceTheme"] self.icon_view.set_model(store) self.icon_view.set_pixbuf_column(0) self.icon_view.set_text_column(1) def keepSize(crt, _): """ :Description: Hack to fix spacing problem in iconview http://stackoverflow.com/questions/14090094/what-causes-the-different-\ display-behaviour-for-a-gtkiconview-between-different """ crt.handler_block(crt_notify) crt.set_property('width', 40) crt.handler_unblock(crt_notify) crt = self.icon_view.get_cells()[0] crt_notify = crt.connect('notify', keepSize) def _getActive(iconview): model = iconview.get_model() selected = iconview.get_selected_items() if len(selected) == 0: return conf.get("pieceTheme", "Chessicons") indices = selected[0].get_indices() if indices: idx = indices[0] theme = model[idx][1] Pieces.set_piece_theme(theme) return theme def _setActive(iconview, value): try: index = self.themes.index(value) except ValueError: index = 0 iconview.select_path(Gtk.TreePath(index, )) uistuff.keep(widgets["pieceTheme"], "pieceTheme", _getActive, _setActive, "Chessicons")
def open_lounge(self, connection, helperconn, host): if self.first_run: self.init_layout() self.connection = connection self.helperconn = helperconn self.host = host self.finger_sent = False self.messages = [] self.players = [] self.game_cids = {} self.widgets = uistuff.GladeWidgets("fics_lounge.glade") self.widgets["fics_lounge"].hide() fics_home = self.widgets["fics_home"] self.widgets["fics_lounge_content_hbox"].remove(fics_home) self.archive_list = self.widgets["archiveListContent"] self.widgets["fics_panels_notebook"].remove(self.archive_list) self.games_list = self.widgets["gamesListContent"] self.widgets["fics_panels_notebook"].remove(self.games_list) self.news_list = self.widgets["news"] self.widgets["fics_home"].remove(self.news_list) self.players_list = self.widgets["playersListContent"] self.widgets["fics_panels_notebook"].remove(self.players_list) self.seek_graph = self.widgets["seekGraphContent"] self.widgets["fics_panels_notebook"].remove(self.seek_graph) self.seek_list = self.widgets["seekListContent"] self.widgets["fics_panels_notebook"].remove(self.seek_list) self.seek_challenge = SeekChallengeSection(self) def on_autoLogout(alm): self.emit("autoLogout") self.close() self.connection.alm.connect("logOut", on_autoLogout) self.connection.connect("disconnected", lambda connection: self.close()) self.connection.connect("error", self.on_connection_error) if self.connection.isRegistred(): numtimes = conf.get("numberOfTimesLoggedInAsRegisteredUser") + 1 conf.set("numberOfTimesLoggedInAsRegisteredUser", numtimes) self.connection.em.connect( "onCommandNotFound", lambda em, cmd: log.error( "Fics answered '%s': Command not found" % cmd)) self.connection.bm.connect("playGameCreated", self.onPlayGameCreated) self.connection.bm.connect("obsGameCreated", self.onObserveGameCreated) self.connection.bm.connect("exGameCreated", self.onObserveGameCreated) self.connection.fm.connect("fingeringFinished", self.onFinger) # the rest of these relay server messages to the lounge infobar self.connection.bm.connect("tooManySeeks", self.tooManySeeks) self.connection.bm.connect("nonoWhileExamine", self.nonoWhileExamine) self.connection.bm.connect("matchDeclined", self.matchDeclined) self.connection.bm.connect("player_on_censor", self.player_on_censor) self.connection.bm.connect("player_on_noplay", self.player_on_noplay) self.connection.bm.connect("req_not_fit_formula", self.req_not_fit_formula) self.connection.glm.connect("seek-updated", self.on_seek_updated) self.connection.glm.connect("our-seeks-removed", self.our_seeks_removed) self.connection.cm.connect("arrivalNotification", self.onArrivalNotification) self.connection.cm.connect("departedNotification", self.onDepartedNotification) def get_top_games(): if perspective_manager.current_perspective == self: self.connection.client.run_command("games *19") return True if self.connection.ICC: self.event_id = GLib.timeout_add_seconds(5, get_top_games) for user in self.connection.notify_users: user = self.connection.players.get(user) self.user_from_notify_list_is_present(user) self.userinfo = UserInfoSection(self.widgets, self.connection, self.host, self) if not self.first_run: self.notebooks["ficshome"].remove_page(-1) self.notebooks["ficshome"].append_page(fics_home) self.panels = [ panel.Sidepanel().load(self.widgets, self.connection, self) for panel in self.sidePanels ] for panel, instance in zip(self.sidePanels, self.panels): if not self.first_run: self.notebooks[panel.__name__].remove_page(-1) self.notebooks[panel.__name__].append_page(instance) instance.show() tool_buttons = [ self.logoff_button, ] self.quick_seek_buttons = [] if self.connection.ICC: self.quick_seek_buttons = [ self.minute_1_button, self.minute_3_button, self.minute_5_button, self.minute_15_button, self.minute_25_button, self.chess960_button ] tool_buttons += self.quick_seek_buttons perspective_manager.set_perspective_toolbuttons("fics", tool_buttons) if self.first_run: self.first_run = False # After all panel is set up we can push initial messages out self.connection.com.onConsoleMessage("", self.connection.ini_messages)
def __init__(self, lounge): self.lounge = lounge self.widgets = lounge.widgets self.connection = lounge.connection self.widgets["editSeekDialog"].set_transient_for(mainwindow()) self.widgets["challengeDialog"].set_transient_for(mainwindow()) self.finger = None conf.set("numberOfFingers", 0) self.connection.fm.connect("fingeringFinished", self.onFinger) self.connection.fm.finger(self.connection.getUsername()) self.widgets["untimedCheck"].connect("toggled", self.onUntimedCheckToggled) self.widgets["minutesSpin"].connect("value-changed", self.onTimeSpinChanged) self.widgets["gainSpin"].connect("value-changed", self.onTimeSpinChanged) self.onTimeSpinChanged(self.widgets["minutesSpin"]) self.widgets["nocolorRadio"].connect("toggled", self.onColorRadioChanged) self.widgets["whitecolorRadio"].connect("toggled", self.onColorRadioChanged) self.widgets["blackcolorRadio"].connect("toggled", self.onColorRadioChanged) self.onColorRadioChanged(self.widgets["nocolorRadio"]) self.widgets["noVariantRadio"].connect("toggled", self.onVariantRadioChanged) self.widgets["variantRadio"].connect("toggled", self.onVariantRadioChanged) variantcombo = self.widgets["variantCombo"] variantcombo.set_name("variantcombo") variantComboGetter, variantComboSetter = self.__initVariantCombo( variantcombo) self.seekEditorWidgetGettersSetters["variantCombo"] = ( variantComboGetter, variantComboSetter) self.widgets["variantCombo"].connect("changed", self.onVariantComboChanged) self.widgets["editSeekDialog"].connect("delete_event", lambda *a: True) # self.widgets["challengeDialog"].connect("delete_event", lambda *a: True) self.widgets["strengthCheck"].connect("toggled", self.onStrengthCheckToggled) self.onStrengthCheckToggled(self.widgets["strengthCheck"]) self.widgets["ratingCenterSlider"].connect( "value-changed", self.onRatingCenterSliderChanged) self.onRatingCenterSliderChanged(self.widgets["ratingCenterSlider"]) self.widgets["toleranceSlider"].connect("value-changed", self.onToleranceSliderChanged) self.onToleranceSliderChanged(self.widgets["toleranceSlider"]) self.widgets["toleranceButton"].connect("clicked", self.onToleranceButtonClicked) self.widgets["toleranceButton"].connect("activate-link", lambda link_button: True) def intGetter(widget): return int(widget.get_value()) self.seekEditorWidgetGettersSetters["minutesSpin"] = (intGetter, None) self.seekEditorWidgetGettersSetters["gainSpin"] = (intGetter, None) self.seekEditorWidgetGettersSetters["ratingCenterSlider"] = \ (intGetter, None) self.seekEditorWidgetGettersSetters["toleranceSlider"] = \ (intGetter, None) def toleranceHBoxGetter(widget): return self.widgets["toleranceHBox"].get_property("visible") def toleranceHBoxSetter(widget, visible): assert isinstance(visible, bool) if visible: self.widgets["toleranceHBox"].show() else: self.widgets["toleranceHBox"].hide() self.seekEditorWidgetGettersSetters["toleranceHBox"] = ( toleranceHBoxGetter, toleranceHBoxSetter) self.chainbox = ChainVBox() self.widgets["chainAlignment"].add(self.chainbox) def chainboxGetter(widget): return self.chainbox.active def chainboxSetter(widget, is_active): self.chainbox.active = is_active self.seekEditorWidgetGettersSetters["chainAlignment"] = ( chainboxGetter, chainboxSetter) self.challengee = None self.in_challenge_mode = False self.seeknumber = 1 self.widgets["seekButton"].connect("clicked", self.onSeekButtonClicked) self.widgets["seekAllButton"].connect("clicked", self.onSeekAllButtonClicked) self.widgets["challengeButton"].connect("clicked", self.onChallengeButtonClicked) self.widgets["challengeDialog"].connect("delete-event", self.onChallengeDialogResponse) self.widgets["challengeDialog"].connect("response", self.onChallengeDialogResponse) self.widgets["editSeekDialog"].connect("response", self.onEditSeekDialogResponse) for widget in ("seek1Radio", "seek2Radio", "seek3Radio", "challenge1Radio", "challenge2Radio", "challenge3Radio"): uistuff.keep(self.widgets[widget], widget) self.lastdifference = 0 self.loading_seek_editor = False self.savedSeekRadioTexts = [GAME_TYPES["blitz"].display_text] * 3 for i in range(1, 4): self.__loadSeekEditor(i) self.__writeSavedSeeks(i) self.widgets["seek%sRadioConfigButton" % i].connect( "clicked", self.onSeekRadioConfigButtonClicked, i) self.widgets["challenge%sRadioConfigButton" % i].connect( "clicked", self.onChallengeRadioConfigButtonClicked, i) if not self.connection.isRegistred(): self.chainbox.active = False self.widgets["chainAlignment"].set_sensitive(False) self.widgets["chainAlignment"].set_tooltip_text( _("The chain button is disabled because you are logged in as a guest. Guests \ can't establish ratings, and the chain button's state has no effect when \ there is no rating to which to tie \"Opponent Strength\" to"))
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(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): widgets["opening_hbox"].set_sensitive(check.get_active()) 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): widgets["endgame_hbox"].set_sensitive(check.get_active()) 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) uistuff.createCombo(widgets["inv_ana_combobox"], data) @idle_add 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 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()) from pychess.Main import gameDic if gameDic: if check.get_active(): for gmwidg in gameDic.keys(): gmwidg.gamemodel.restart_analyzer(HINT) if not widgets["hint_mode"].get_active(): gmwidg.gamemodel.pause_analyzer(HINT) else: for gmwidg in gameDic.keys(): gmwidg.gamemodel.remove_analyzer(HINT) widgets["analyzers_vbox"].set_sensitive( widgets["analyzer_check"].get_active()) widgets["analyzer_check"].connect_after("toggled", on_analyzer_check_toggled) def on_invanalyzer_check_toggled(check): widgets["inv_analyzers_vbox"].set_sensitive(check.get_active()) from pychess.Main import gameDic if gameDic: if check.get_active(): for gmwidg in gameDic.keys(): gmwidg.gamemodel.restart_analyzer(SPY) if not widgets["spy_mode"].get_active(): gmwidg.gamemodel.pause_analyzer(SPY) else: for gmwidg in gameDic.keys(): gmwidg.gamemodel.remove_analyzer(SPY) widgets["inv_analyzers_vbox"].set_sensitive( widgets["inv_analyzer_check"].get_active()) widgets["inv_analyzer_check"].connect_after( "toggled", on_invanalyzer_check_toggled) # Give widgets to keeper 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)) uistuff.keep( 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(widgets["max_analysis_spin"], "max_analysis_spin", first_value=3)
def callback(*args): if not conf.hasKey(key) or conf.get(key) != get_value(): conf.set(key, get_value())
def run(self): while True: try: line = get_input() except EOFError: line = "quit" lines = line.split() try: if not lines: continue log.debug(line, extra={"task": "xboard"}) # CECP commands # See http://home.hccnet.nl/h.g.muller/engine-intf.html if lines[0] == "xboard": pass elif lines[0] == "protover": stringPairs = [ "=".join( [k, '"%s"' % v if isinstance(v, str) else str(v)]) for k, v in self.features.items() ] self.print("feature %s" % " ".join(stringPairs)) self.print("feature done=1") elif lines[0] in ("accepted", "rejected"): # We only really care about one case: if tuple(lines) == ("rejected", "debug"): self.debug = False elif lines[0] == "new": self.__stopSearching() self.board = LBoard(NORMALCHESS) self.board.applyFen(FEN_START) self.outOfBook = False self.forced = False self.playingAs = BLACK self.clock[:] = self.basetime, self.basetime self.searchtime = 0 self.sd = MAXPLY if self.analyzing: self.__analyze() elif lines[0] == "variant": if len(lines) > 1: if lines[1] == "fischerandom": self.board.variant = FISCHERRANDOMCHESS elif lines[1] == "crazyhouse": self.board.variant = CRAZYHOUSECHESS self.board.iniHouse() elif lines[1] == "wildcastle": self.board.variant = WILDCASTLESHUFFLECHESS elif lines[1] == "losers": self.board.variant = LOSERSCHESS elif lines[1] == "suicide": self.board.variant = SUICIDECHESS elif lines[1] == "giveaway": self.board.variant = GIVEAWAYCHESS elif lines[1] == "atomic": self.board.variant = ATOMICCHESS self.board.iniAtomic() elif lines[1] == "3check": self.board.variant = THREECHECKCHESS elif lines[1] == "racingkings": self.board.variant = RACINGKINGSCHESS elif lines[1] == "kingofthehill": self.board.variant = KINGOFTHEHILLCHESS elif lines[1] == "horde": self.board = LBoard(HORDECHESS) self.board.applyFen(HORDESTART) elif lines[1] == "placement": self.board = LBoard(PLACEMENTCHESS) self.board.applyFen(PLACEMENTSTART) elif lines[1] == "asean": self.board = LBoard(ASEANCHESS) self.board.applyFen(ASEANSTART) elif lines[1] == "makruk": self.board = LBoard(MAKRUKCHESS) self.board.applyFen(MAKRUKSTART) elif lines[1] == "cambodian": self.board = LBoard(CAMBODIANCHESS) self.board.applyFen(KAMBODIANSTART) elif lines[1] == "sittuyin": self.board = LBoard(SITTUYINCHESS) self.board.applyFen(SITTUYINSTART) elif lines[0] == "quit": self.forced = True self.__stopSearching() sys.exit(0) elif lines[0] == "random": leval.random = True elif lines[0] == "force": if not self.forced and not self.analyzing: self.forced = True self.__stopSearching() elif lines[0] == "go": self.playingAs = self.board.color self.forced = False self.__go() elif lines[0] == "playother": self.playingAs = 1 - self.board.color self.forced = False # TODO: start pondering, if possible elif lines[0] in ("black", "white"): newColor = lines[0] == "black" and BLACK or WHITE self.__stopSearching() self.playingAs = 1 - newColor if self.board.color != newColor: self.board.setColor(newColor) self.board.setEnpassant(None) if self.analyzing: self.__analyze() elif lines[0] == "level": self.movestogo = int(lines[1]) inc = int(lines[3]) minutes = lines[2].split(":") # Per protocol spec, strip off any non-numeric suffixes. for i in range(len(minutes)): minutes[i] = re.match(r"\d*", minutes[i]).group() self.basetime = int(minutes[0]) * 60 if len(minutes) > 1 and minutes[1]: self.basetime += int(minutes[1]) self.clock[:] = self.basetime, self.basetime self.increment = inc self.searchtime = 0 elif lines[0] == "st": self.searchtime = float(lines[1]) elif lines[0] == "sd": self.sd = int(lines[1]) # Unimplemented: nps elif lines[0] == "time": self.clock[self.playingAs] = float(lines[1]) / 100.0 elif lines[0] == "otim": self.clock[1 - self.playingAs] = float(lines[1]) / 100.0 elif lines[0] == "usermove": self.__stopSearching() try: move = parseAny(self.board, lines[1]) except ParsingError: self.print("Error (unknown command): %s" % lines[1]) self.print(self.board.prepr(ascii=ASCII)) continue if not validateMove(self.board, move): self.print("Illegal move: %s" % lines[1]) self.print(self.board.prepr(ascii=ASCII)) continue self.board.applyMove(move) self.playingAs = self.board.color if not self.forced and not self.analyzing: self.__go() if self.analyzing: self.__analyze() elif lines[0] == "?": if not self.forced and not self.analyzing: self.__stopSearching() elif lines[0] == "ping": self.print("pong %s" % lines[1]) elif lines[0] == "draw": if self.__willingToDraw(): self.print("offer draw") elif lines[0] == "result": # We don't really care what the result is at the moment. pass elif lines[0] == "setboard": self.__stopSearching() try: self.board = LBoard(self.board.variant) fen = " ".join(lines[1:]) self.board.applyFen( fen.replace("[", "/").replace("]", "")) except SyntaxError as err: self.print("tellusererror Illegal position: %s" % str(err)) # "edit" is unimplemented. See docs. Exiting edit mode returns to analyze mode. elif lines[0] == "hint": pass # TODO: Respond "Hint: MOVE" if we have an expected reply elif lines[0] == "bk": entries = getOpenings(self.board) if entries: totalWeight = sum(entry[1] for entry in entries) for entry in entries: self.print("\t%s\t%02.2f%%" % ( toSAN(self.board, entry[0]), entry[1] * 100.0 / totalWeight, )) elif lines[0] == "undo": self.__stopSearching() self.board.popMove() if self.analyzing: self.__analyze() elif lines[0] == "remove": self.__stopSearching() self.board.popMove() self.board.popMove() if self.analyzing: self.__analyze() elif lines[0] in ("hard", "easy"): self.ponder = lines[0] == "hard" elif lines[0] in ("post", "nopost"): self.post = lines[0] == "post" elif lines[0] == "analyze": self.analyzing = True self.__analyze() elif lines[0] in ("name", "rating", "ics", "computer"): pass # We don't care. # Unimplemented: pause, resume elif lines[0] == "memory": # FIXME: this is supposed to control the *total* memory use. if lsearch.searching: self.print("Error (already searching):", line) else: limit = int(lines[1]) if limit < 1: self.print("Error (limit too low):", line) else: pass # TODO implement # lsearch.setHashSize(limit) elif lines[0] == "cores": pass # We aren't SMP-capable. elif lines[0] == "egtpath": if len(lines) >= 3 and lines[1] == "gaviota": if lines[2]: conf.set("egtb_path", lines[2]) else: conf.set("egtb_path", conf.get("egtb_path")) from pychess.Utils.lutils.lsearch import enableEGTB enableEGTB() elif lines[0] == "option" and len(lines) > 1: name, eq, value = lines[1].partition("=") if value: value = int( value ) # CECP spec says option values are *always* numeric if name == "skipPruneChance": if 0 <= value <= 100: self.skipPruneChance = value / 100.0 else: self.print( "Error (argument must be an integer 0..100): %s" % line) # CECP analyze mode commands # See http://www.gnu.org/software/xboard/engine-intf.html#11 elif lines[0] == "exit": if self.analyzing: self.__stopSearching() self.analyzing = False # Periodic updates (".") are not implemented. # Custom commands elif lines[0] == "moves": self.print(self.board.prepr(ascii=ASCII)) self.print([ toSAN(self.board, move) for move in genAllMoves(self.board) ]) elif lines[0] == "captures": self.print(self.board.prepr(ascii=ASCII)) self.print([ toSAN(self.board, move) for move in genCaptures(self.board) ]) elif lines[0] == "evasions": self.print(self.board.prepr(ascii=ASCII)) self.print([ toSAN(self.board, move) for move in genCheckEvasions(self.board) ]) elif lines[0] == "benchmark": if len(lines) > 1: benchmark(int(lines[1])) else: benchmark() elif lines[0] == "profile": if len(lines) > 1: import cProfile cProfile.runctx("benchmark()", locals(), globals(), lines[1]) else: self.print("Usage: profile outputfilename") elif lines[0] == "perft": root = "0" if len(lines) < 3 else lines[2] depth = "1" if len(lines) == 1 else lines[1] if root.isdigit() and depth.isdigit(): perft(self.board, int(depth), int(root)) else: self.print("Error (arguments must be integer") elif lines[0] == "stop_unittest": break elif len(lines) == 1: # A GUI without usermove support might try to send a move. try: move = parseAny(self.board, line) except ParsingError: self.print("Error (unknown command): %s" % line) continue if not validateMove(self.board, move): self.print("Illegal move: %s" % lines[0]) self.print(self.board.prepr(ascii=ASCII)) continue self.__stopSearching() self.board.applyMove(move) self.playingAs = self.board.color if not self.forced and not self.analyzing: self.__go() if self.analyzing: self.__analyze() else: self.print("Error (unknown command): %s" % line) except IndexError: self.print("Error (missing argument): %s" % line)
def onColourSetDark(_): """ :Description: Sets the dark squares of the chess board to the value selected in the colour picker """ conf.set('darkcolour', widgets['dark_cbtn'].get_color().to_string())
def __init__(self, widgets): self.widgets = widgets # Font chooser font = conf.get("movetextFont") font_button = Gtk.FontButton.new_with_font(font) demo_text = "♔a1 ♕f8 ♖h8 ♗g7 ♘g2 Ka1 Qf8 Rh8 Bg7 Ng2" font_button.set_preview_text(demo_text) self.widgets["fontChooserDock"].add(font_button) font_button.show() def select_font(button): conf.set("movetextFont", button.get_font_name()) font_button.connect("font-set", select_font) # Background image path = conf.get("welcome_image") conf.set("welcome_image", path) image_chooser_dialog = Gtk.FileChooserDialog( _("Select background image file"), mainwindow(), Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) image_chooser_button = Gtk.FileChooserButton.new_with_dialog( image_chooser_dialog) filter = Gtk.FileFilter() filter.set_name(_("Images")) filter.add_pattern("*.bmp") filter.add_pattern("*.jpg") filter.add_pattern("*.png") filter.add_pattern("*.svg") image_chooser_dialog.add_filter(filter) image_chooser_button.set_filename(path) self.widgets["imageChooserDock"].add(image_chooser_button) image_chooser_button.show() def select_new_image(button): new_image = image_chooser_dialog.get_filename() if new_image: conf.set("welcome_image", new_image) from pychess.widgets.TaskerManager import tasker newTheme(tasker, background=new_image) tasker.queue_draw() else: # restore the original image_chooser_dialog.set_filename(path) image_chooser_button.connect("file-set", select_new_image) # Board style uistuff.createCombo(widgets["board_style"], name="board_style") data = [(item[0], item[1]) for item in board_items] uistuff.createCombo(widgets["board_style"], data) uistuff.keep(widgets["board_style"], "board_style") # conf.set("board_style", conf.get("board_style")) # Board frame uistuff.createCombo(widgets["board_frame"], name="board_frame") data = [(item[0], item[1]) for item in [(None, "no frame")] + board_items[1:]] uistuff.createCombo(widgets["board_frame"], data) uistuff.keep(widgets["board_frame"], "board_frame") # conf.set("board_frame", conf.get("board_frame")) # Board Colours def onColourSetLight(_): """ :Description: Sets the light squares of the chess board to the value selected in the colour picker """ conf.set('lightcolour', widgets['light_cbtn'].get_color().to_string()) widgets["light_cbtn"].connect_after("color-set", onColourSetLight) def onColourSetDark(_): """ :Description: Sets the dark squares of the chess board to the value selected in the colour picker """ conf.set('darkcolour', widgets['dark_cbtn'].get_color().to_string()) widgets["dark_cbtn"].connect_after("color-set", onColourSetDark) def onResetColourClicked(_): """ :Description: Resets the chess board squares to factory default """ conf.set("lightcolour", conf.DEFAULTS["General"]["lightcolour"]) conf.set("darkcolour", conf.DEFAULTS["General"]["darkcolour"]) widgets["reset_btn"].connect("clicked", onResetColourClicked) # Get the current board colours if set, if not set, set them to default conf.set("lightcolour", conf.get("lightcolour")) conf.set("darkcolour", conf.get("darkcolour")) # Next 2 lines take a #hex str converts them to a color then to a RGBA representation self.lightcolour = Gdk.RGBA() self.lightcolour.parse(conf.get("lightcolour")) self.darkcolour = Gdk.RGBA() self.darkcolour.parse(conf.get("darkcolour")) # Set the color swatches in preference to stored values widgets['light_cbtn'].set_rgba(self.lightcolour) widgets['dark_cbtn'].set_rgba(self.darkcolour) # Chess Sets self.themes = self.discoverThemes() store = Gtk.ListStore(GdkPixbuf.Pixbuf, str) for theme in self.themes: pngfile = "%s/%s.png" % (addDataPrefix("pieces"), theme) if isfile(pngfile): pixbuf = get_pixbuf(pngfile) store.append((pixbuf, theme)) else: print( "WARNING: No piece theme preview icons found. Please run \ create_theme_preview.sh !") break self.icon_view = widgets["pieceTheme"] self.icon_view.set_model(store) self.icon_view.set_pixbuf_column(0) self.icon_view.set_text_column(1) def keepSize(crt, _): """ :Description: Hack to fix spacing problem in iconview http://stackoverflow.com/questions/14090094/what-causes-the-different-\ display-behaviour-for-a-gtkiconview-between-different """ crt.handler_block(crt_notify) crt.set_property('width', 40) crt.handler_unblock(crt_notify) crt = self.icon_view.get_cells()[0] crt_notify = crt.connect('notify', keepSize) def _getActive(iconview): model = iconview.get_model() selected = iconview.get_selected_items() if len(selected) == 0: return conf.get("pieceTheme") indices = selected[0].get_indices() if indices: idx = indices[0] theme = model[idx][1] Pieces.set_piece_theme(theme) return theme def _setActive(iconview, value): try: index = self.themes.index(value) except ValueError: index = 0 iconview.select_path(Gtk.TreePath(index, )) uistuff.keep(widgets["pieceTheme"], "pieceTheme", _getActive, _setActive)
def __init__(self): self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL, title=_("Ask for permissions")) self.window.set_transient_for(mainwindow()) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) gtk_version = (Gtk.get_major_version(), Gtk.get_minor_version()) if gtk_version >= (3, 12): vbox.props.margin_start = 9 vbox.props.margin_end = 9 else: vbox.props.margin_left = 9 vbox.props.margin_right = 9 vbox.props.margin_bottom = 9 self.window.add(vbox) uistuff.keepWindowSize("externalsdialog", self.window, (320, 240), uistuff.POSITION_CENTER) label = Gtk.Label( _("Some of PyChess features needs your permission to download external programs" )) vbox.pack_start(label, True, True, 0) box = Gtk.Box() check_button = Gtk.CheckButton(_("database querying needs scoutfish")) check_button.set_active(conf.get("download_scoutfish")) check_button.connect( "toggled", lambda w: conf.set("download_scoutfish", w.get_active())) box.add(check_button) link = "https://github.com/pychess/scoutfish" link_button = Gtk.LinkButton(link, link) box.add(link_button) vbox.pack_start(box, False, False, 0) box = Gtk.Box() check_button = Gtk.CheckButton( _("database opening tree needs chess_db")) check_button.set_active(conf.get("download_chess_db")) check_button.connect( "toggled", lambda w: conf.set("download_chess_db", w.get_active())) box.add(check_button) link = "https://github.com/pychess/chess_db" link_button = Gtk.LinkButton(link, link) box.add(link_button) vbox.pack_start(box, False, False, 0) box = Gtk.Box() check_button = Gtk.CheckButton( _("ICC lag compensation needs timestamp")) check_button.set_active(conf.get("download_timestamp")) check_button.connect( "toggled", lambda w: conf.set("download_timestamp", w.get_active())) box.add(check_button) link = "http://download.chessclub.com/timestamp/" link_button = Gtk.LinkButton(link, link) box.add(link_button) vbox.pack_start(box, False, False, 0) check_button = Gtk.CheckButton(_("Don't show this dialog on startup.")) check_button.set_active(conf.get("dont_show_externals_at_startup")) check_button.connect( "toggled", lambda w: conf.set("dont_show_externals_at_startup", w.get_active())) vbox.pack_start(check_button, True, True, 0) buttonbox = Gtk.ButtonBox() close_button = Gtk.Button.new_from_stock(Gtk.STOCK_OK) close_button.connect("clicked", self.on_close_clicked) self.window.connect("delete_event", lambda w, a: self.window.destroy()) buttonbox.add(close_button) vbox.pack_start(buttonbox, False, False, 0)
combobox, value, "spy_mode", "inv_analyzer_check", SPY)) uistuff.keep(widgets["max_analysis_spin"], "max_analysis_spin", first_value=3) ################################################################################ # Sound initing # ################################################################################ # Setup default sounds for i in range(11): if not conf.hasKey("soundcombo%d" % i): conf.set("soundcombo%d" % i, SOUND_URI) if not conf.hasKey("sounduri0"): conf.set("sounduri0", "file://" + addDataPrefix("sounds/move1.ogg")) if not conf.hasKey("sounduri1"): conf.set("sounduri1", "file://" + addDataPrefix("sounds/check1.ogg")) if not conf.hasKey("sounduri2"): conf.set("sounduri2", "file://" + addDataPrefix("sounds/capture1.ogg")) if not conf.hasKey("sounduri3"): conf.set("sounduri3", "file://" + addDataPrefix("sounds/start1.ogg")) if not conf.hasKey("sounduri4"): conf.set("sounduri4", "file://" + addDataPrefix("sounds/win1.ogg")) if not conf.hasKey("sounduri5"): conf.set("sounduri5", "file://" + addDataPrefix("sounds/lose1.ogg")) if not conf.hasKey("sounduri6"): conf.set("sounduri6", "file://" + addDataPrefix("sounds/draw1.ogg")) if not conf.hasKey("sounduri7"):
def onResetColourClicked(_): """ :Description: Resets the chess board squares to factory default """ conf.set("lightcolour", conf.DEFAULTS["General"]["lightcolour"]) conf.set("darkcolour", conf.DEFAULTS["General"]["darkcolour"])
def __init__(self, widgets): # autosave pychess database default_path = os.path.join(addDataPrefix("pychess.pdb")) path = conf.get("autosave_db_file", default_path) conf.set("autosave_db_file", path) pdb_chooser_dialog = Gtk.FileChooserDialog( _("Select pychess database"), None, Gtk.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) pdb_chooser_button = Gtk.FileChooserButton.new_with_dialog( pdb_chooser_dialog) filter = Gtk.FileFilter() filter.set_name(_("PyChess database")) filter.add_pattern("*.pdb") pdb_chooser_dialog.add_filter(filter) pdb_chooser_button.set_filename(path) widgets["saveDbPathChooserDock"].add(pdb_chooser_button) pdb_chooser_button.show() def select_new_pdb(button): new_pdb = pdb_chooser_dialog.get_filename() if new_pdb: conf.set("autosave_db_file", new_pdb) else: # restore the original pdb_chooser_dialog.set_filename(path) pdb_chooser_button.connect("file-set", select_new_pdb) def on_autosavedb_check_toggled(check): checkbox = widgets["autoSaveDb"] widgets["autosavedb_box"].set_property("sensitive", checkbox.get_active()) conf.notify_add("autoSaveDb", on_autosavedb_check_toggled) widgets["autoSaveDb"].set_active(True) uistuff.keep(widgets["autoSaveDb"], "autoSaveDb") on_autosavedb_check_toggled(_) # Init 'auto save" checkbutton def checkCallBack(_): """ :Description: Sets the various option based on user interaction with the checkboxes in the gui """ checkbox = widgets["autoSave"] widgets["autosave_grid"].set_property("sensitive", checkbox.get_active()) conf.notify_add("autoSave", checkCallBack) widgets["autoSave"].set_active(False) uistuff.keep(widgets["autoSave"], "autoSave") checkCallBack(_) default_path = os.path.expanduser("~") self.auto_save_path = conf.get("autoSavePath", default_path) conf.set("autoSavePath", self.auto_save_path) auto_save_chooser_dialog = Gtk.FileChooserDialog( _("Select auto save path"), None, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) auto_save_chooser_button = Gtk.FileChooserButton.new_with_dialog( auto_save_chooser_dialog) auto_save_chooser_button.set_current_folder(self.auto_save_path) widgets["savePathChooserDock"].add(auto_save_chooser_button) auto_save_chooser_button.show() def selectAutoSave(_): """ :Description: Sets the auto save path for stored games if it has changed since last time :signal: Activated on receiving the 'current-folder-changed' signal """ new_directory = auto_save_chooser_dialog.get_filename() if new_directory != self.auto_save_path: conf.set("autoSavePath", new_directory) auto_save_chooser_button.connect("current-folder-changed", selectAutoSave) conf.set("autoSaveFormat", conf.get("autoSaveFormat", "pychess")) uistuff.keep(widgets["autoSaveFormat"], "autoSaveFormat") uistuff.keep(widgets["saveEmt"], "saveEmt") uistuff.keep(widgets["saveEval"], "saveEval") uistuff.keep(widgets["saveOwnGames"], "saveOwnGames")