def lee(self): dic = Util.restore_pickle(self.file) if dic: for x in dir(self): if x.startswith("x_"): if x in dic: setattr(self, x, dic[x]) xperf = dic.get("PERFOMANCE") if xperf: self.perfomance.restore(xperf) palette = dic.get("PALETTE") if palette: self.palette = palette for x in os.listdir("../.."): if x.endswith(".pon"): os.remove("../%s" % x) self.x_translator = x[:2] self.releeTRA() TrListas.ponPiecesLNG(self.x_pgn_english or self.translator() == "en") self.tutor = self.buscaTutor(self.x_tutor_clave) if self.tutor.key != self.x_tutor_clave: self.x_tutor_clave = self.tutor.key
def informacion(self): menu = QTVarios.LCMenu(self.main_window) f = Controles.TipoLetra(puntos=10, peso=75) menu.ponFuente(f) siOpening = False for key, valor in self.game.li_tags: trad = TrListas.pgnLabel(key) if trad != key: key = trad menu.opcion(key, "%s : %s" % (key, valor), Iconos.PuntoAzul()) if key.upper() == "OPENING": siOpening = True if not siOpening: opening = self.game.opening if opening: menu.separador() nom = opening.trNombre ape = _("Opening") label = nom if ape.upper() in nom.upper() else ("%s : %s" % (ape, nom)) menu.opcion("opening", label, Iconos.PuntoNaranja()) menu.separador() menu.opcion("pgn", _("Edit PGN labels"), Iconos.PGN()) resp = menu.lanza() if resp: self.editEtiquetasPGN()
def read_svg(self, base): with open(base % "svg") as f: x = f.read() dic = TrListas.transsiberian() for k, v in dic.items(): x = x.replace(">%s<" % k, ">%s<" % v) return x
def creaListaSonidos(self): self.liSonidos = [["MC", _("After rival move"), None]] # self.liSonidos.append( [ None, "", None ] ) self.liSonidos.append([None, "- " + _("Results") + " -", None]) d = collections.OrderedDict() d["GANAMOS"] = _("You win") d["GANARIVAL"] = _("Opponent wins") d["TABLAS"] = _("Stalemate") d["TABLASREPETICION"] = _("Draw due to three times repetition") d["TABLAS50"] = _("Draw according to the 50 move rule") d["TABLASFALTAMATERIAL"] = _("Draw, not enough material") d["GANAMOSTIEMPO"] = _("You win on time") d["GANARIVALTIEMPO"] = _("Opponent has won on time") for c, tr in d.items(): self.liSonidos.append([c, tr, None]) # self.liSonidos.append( [ None, "", None ] ) self.liSonidos.append([None, "- " + _("Rival moves") + " -", None]) for c in "abcdefgh12345678": self.liSonidos.append([c, c, None]) for c in "KQRBNP": t = TrListas.letterPiece(c) self.liSonidos.append([c, t, None]) for c in ("O-O", "O-O-O", "=", "x", "#", "+"): self.liSonidos.append([c, c, None]) self.liSonidos.append([None, "", None]) self.liSonidos.append(["ZEITNOT", _("Zeitnot"), None])
def pgn_translated(self): dConv = TrListas.dConv() li = [] for c in self.pgnBase: if c in dConv: c = dConv[c] li.append(c) return "".join(li)
def tr_pgn(self): p = "" pzs = "KQRBNPkqrbnp" pgn = self.pgn for n, c in enumerate(pgn): if c in pzs and not pgn[n + 1].isdigit(): c = TrListas.letterPiece(c) p += c return p
def __init__(self, carpeta): dicTraining = TrListas.dicTraining() def trTraining(txt): return dicTraining.get(txt, txt) self.tr = trTraining self.name = trTraining(os.path.basename(carpeta)) self.read(carpeta)
def read_standard(dic): list_std = TrListas.list_std() for name, eco, a1h8, pgn, siBasic in list_std: bloque = OpeningStd(name) bloque.eco = eco bloque.a1h8 = a1h8 bloque.pgn = pgn bloque.siBasic = siBasic dic[bloque.a1h8] = bloque
def mousePressEvent(self, event): siRight = event.button() == QtCore.Qt.RightButton p = event.pos() a1h8 = self.punto2a1h8(p) m = int(event.modifiers()) is_ctrl = (m & QtCore.Qt.ControlModifier) > 0 is_shift = (m & QtCore.Qt.ShiftModifier) > 0 is_alt = (m & QtCore.Qt.AltModifier) > 0 li_tareas = self.guion.tareasPosicion(p) if siRight and is_shift and is_alt: pz_borrar = self.board.dameNomPiezaEn(a1h8) menu = Controles.Menu(self.board) dicPieces = TrListas.dicNomPiezas() icoPiece = self.board.piezas.icono if pz_borrar or len(li_tareas): mrem = menu.submenu(_("Remove"), Iconos.Delete()) if pz_borrar: label = dicPieces[pz_borrar.upper()] mrem.opcion(("rem_pz", None), label, icoPiece(pz_borrar)) mrem.separador() for pos_guion, tarea in li_tareas: label = "%s - %s - %s" % (tarea.txt_tipo(), tarea.name(), tarea.info()) mrem.opcion(("rem_gr", pos_guion), label, Iconos.Delete()) mrem.separador() menu.separador() for pz in "KQRBNPkqrbnp": if pz != pz_borrar: if pz == "k": menu.separador() menu.opcion(("create", pz), dicPieces[pz.upper()], icoPiece(pz)) resp = menu.lanza() if resp is not None: orden, arg = resp if orden == "rem_gr": self.w.g_guion.goto(arg, 0) self.w.borrar_lista() elif orden == "rem_pz": self.w.creaTarea("B", pz_borrar, a1h8, -1) elif orden == "create": self.w.creaTarea("C", arg, a1h8, -1) return True if self.director: return self.mousePressEvent_Drop(event) self.w.boardPress(event, a1h8, siRight, is_shift, is_alt, is_ctrl) return True
def pgn_translated(self, from_sq, to_sq, promotion=""): d_conv = TrListas.dConv() li = [] cpgn = self.pgn(from_sq, to_sq, promotion) if not cpgn: return "" for c in cpgn: if c in d_conv: c = d_conv[c] li.append(c) return "".join(li)
def __init__(self, procesador): titulo = _("Play against a game") QTVarios.WDialogo.__init__(self, procesador.main_window, titulo, Iconos.Law(), "playgame") self.procesador = procesador self.configuration = procesador.configuration self.recno = None self.db = DBPlayGame(self.configuration.file_play_game()) # Historico o_columns = Columnas.ListaColumnas() def creaCol(key, label, centered=True): o_columns.nueva(key, label, 80, centered=centered) # # Claves segun orden estandar self.li_keys = liBasic = ("EVENT", "SITE", "DATE", "ROUND", "WHITE", "BLACK", "RESULT", "ECO", "FEN", "WHITEELO", "BLACKELO") for key in liBasic: label = TrListas.pgnLabel(key) creaCol(key, label, key != "EVENT") self.grid = Grid.Grid(self, o_columns, siSelecFilas=True, siSeleccionMultiple=True) self.grid.setMinimumWidth(self.grid.anchoColumnas() + 20) # Tool bar li_acciones = ( (_("Close"), Iconos.MainMenu(), self.terminar), None, (_("Play"), Iconos.Empezar(), self.play), (_("New"), Iconos.Nuevo(), self.new), None, (_("Remove"), Iconos.Borrar(), self.remove), None, ) self.tb = QTVarios.LCTB(self, li_acciones) # Colocamos lyTB = Colocacion.H().control(self.tb).margen(0) ly = Colocacion.V().otro(lyTB).control(self.grid).margen(3) self.setLayout(ly) self.register_grid(self.grid) self.restore_video(siTam=False) self.grid.gotop()
def tacticas(self, tipo, name, carpeta, ini): dic_training = TrListas.dicTraining() um = self.procesador.unMomento() tacticas = Tactics.Tactics(tipo, name, carpeta, ini) liMenus = tacticas.listaMenus() if len(liMenus) == 0: um.final() return nico = QTVarios.rondoPuntos() if len(liMenus) > 1: menu = QTVarios.LCMenu(self.parent) menu.opcion(None, _SP(name), Iconos.Tacticas()) menu.separador() dmenu = {} for valor, lista in liMenus: actmenu = menu if len(lista) > 1: t = "" for x in range(len(lista) - 1): t += "|%s" % lista[x] if not (t in dmenu): v_trad = dic_training.get(lista[x], lista[x]) dmenu[t] = actmenu.submenu(v_trad, nico.otro()) actmenu.separador() actmenu = dmenu[t] actmenu.opcion(valor, dic_training.get(lista[-1], lista[-1]), nico.otro()) actmenu.separador() um.final() resp = menu.lanza() else: resp = liMenus[0][0] if not resp: um.final() return tactica = tacticas.eligeTactica(resp, self.configuration.carpeta_results) um.final() if tactica: self.entrenaTactica(tactica)
def create_menu_tactics(self, menu, xopcion): menu.separador() menu_tactics = menu.submenu(_("Tactics"), Iconos.Training_Tactics()) # Posiciones de entrenamiento -------------------------------------------------------------------------- self.menuFNS(menu_tactics, _("Training positions"), xopcion) menu_tactics.separador() # Tacticas --------------------------------------------------------------------------------------------- menu_t = menu_tactics.submenu(_("Learn tactics by repetition"), Iconos.Tacticas()) nico = Util.Rondo(Iconos.Amarillo(), Iconos.Naranja(), Iconos.Verde(), Iconos.Azul(), Iconos.Magenta()) dicTraining = TrListas.dicTraining() def trTraining(txt): return dicTraining.get(txt, txt) def menu_tacticas(submenu, tipo, carpeta_base, lista): if os.path.isdir(carpeta_base): for entry in os.scandir(carpeta_base): if entry.is_dir(): carpeta = entry.path ini = os.path.join(carpeta, "Config.ini") if os.path.isfile(ini): name = entry.name xopcion( submenu, "tactica|%s|%s|%s|%s" % (tipo, name, carpeta, ini), trTraining(name), nico.otro()) menu_t.separador() lista.append((carpeta, name)) else: submenu1 = submenu.submenu(entry.name, nico.otro()) menu_tacticas(submenu1, tipo, carpeta, lista) return lista menu_tacticas(menu_t, TACTICS_BASIC, Code.path_resource("Tactics"), []) lista = [] carpetaTacticasP = self.configuration.folder_tactics() if os.path.isdir(carpetaTacticasP): submenu1 = menu_t.submenu(_("Personal tactics"), nico.otro()) lista = menu_tacticas(submenu1, TACTICS_PERSONAL, carpetaTacticasP, lista) if lista: ico = Iconos.Delete() menub = menu_t.submenu(_("Remove"), ico) for carpeta, name in lista: xopcion(menub, "remtactica|%s|%s" % (carpeta, name), trTraining(name), ico) menu_tactics.separador() xopcion(menu_tactics, "bmt", _("Find best move"), Iconos.BMT()) menu_tactics.separador() xopcion(menu_tactics, "dailytest", _("Your daily test"), Iconos.DailyTest()) menu_tactics.separador() xopcion(menu_tactics, "potencia", _("Determine your calculating power"), Iconos.Potencia()) menu_tactics.separador() # TOL menu_tactics.separador() menu2 = menu_tactics.submenu(_("Turn on the lights"), Iconos.TOL()) menu.separador() menu3 = menu2.submenu(_("Memory mode"), Iconos.TOL()) xopcion(menu3, "tol_uned_easy", "%s (%s)" % (_("UNED chess school"), _("Initial")), Iconos.Uned()) menu3.separador() xopcion(menu3, "tol_uned", "%s (%s)" % (_("UNED chess school"), _("Complete")), Iconos.Uned()) menu3.separador() xopcion(menu3, "tol_uwe_easy", "%s (%s)" % (_("Uwe Auerswald"), _("Initial")), Iconos.Uwe()) menu3.separador() xopcion(menu3, "tol_uwe", "%s (%s)" % (_("Uwe Auerswald"), _("Complete")), Iconos.Uwe()) menu2.separador() menu3 = menu2.submenu(_("Calculation mode"), Iconos.Calculo()) xopcion(menu3, "tol_uned_easy_calc", "%s (%s)" % (_("UNED chess school"), _("Initial")), Iconos.Uned()) menu3.separador() xopcion(menu3, "tol_uned_calc", "%s (%s)" % (_("UNED chess school"), _("Complete")), Iconos.Uned()) menu3.separador() xopcion(menu3, "tol_uwe_easy_calc", "%s (%s)" % (_("Uwe Auerswald"), _("Initial")), Iconos.Uwe()) menu3.separador() xopcion(menu3, "tol_uwe_calc", "%s (%s)" % (_("Uwe Auerswald"), _("Complete")), Iconos.Uwe()) menu2.separador() xopcion(menu2, "tol_oneline", _("Turn on lights in one line"), Iconos.TOLline())
def start(self, pos_training, num_trainings, title_training, li_trainings, is_tutor_enabled=None, is_automatic_jump=False): if hasattr(self, "reiniciando"): if self.reiniciando: return self.reiniciando = True if is_tutor_enabled is None: is_tutor_enabled = (Code.dgtDispatch is None) and self.configuration.x_default_tutor_active self.pos_training = pos_training self.save_pos(pos_training) self.num_trainings = num_trainings self.title_training = title_training self.li_trainings = li_trainings self.is_automatic_jump = is_automatic_jump self.li_histo = [self.pos_training] self.hints = 99999 self.line_fns = FNSLine.FNSLine(self.li_trainings[self.pos_training - 1]) self.game_obj = self.line_fns.game_obj self.pos_obj = 0 self.is_rival_thinking = False cp = self.line_fns.position is_white = cp.is_white if self.line_fns.with_game_original(): self.game = self.line_fns.game_original else: self.game.set_position(cp) if self.game_obj: self.game.set_first_comment(self.game_obj.first_comment, True) self.game.pending_opening = False self.game_type = GT_POSITIONS self.human_is_playing = False self.state = ST_PLAYING self.plays_instead_of_me_option = True self.human_side = is_white self.is_engine_side_white = not is_white self.rm_rival = None self.is_tutor_enabled = is_tutor_enabled self.main_window.set_activate_tutor(self.is_tutor_enabled) self.ayudas_iniciales = 0 li_options = [TB_CLOSE, TB_HELP, TB_CHANGE, TB_REINIT, TB_TAKEBACK] li_options.append(TB_PGN_LABELS) li_options.extend((TB_CONFIG, TB_UTILITIES)) if self.num_trainings > 1: li_options.extend((TB_PREVIOUS, TB_NEXT)) self.li_options_toolbar = li_options self.main_window.pon_toolbar(li_options) self.main_window.activaJuego(True, False, siAyudas=False) self.main_window.remove_hints(False, False) self.set_dispatcher(self.player_has_moved) self.set_position(self.game.last_position) self.show_side_indicator(True) self.put_pieces_bottom(is_white) titulo = "<b>%s</b>" % TrListas.dicTraining().get(self.title_training, self.title_training) if self.line_fns.label: titulo += "<br>%s" % self.line_fns.label self.set_label1(titulo) self.set_label2("%d / %d" % (pos_training, num_trainings)) self.pgnRefresh(True) QTUtil.refresh_gui() if self.xrival is None: self.xrival = self.procesador.creaManagerMotor( self.configuration.tutor, self.configuration.x_tutor_mstime, self.configuration.x_tutor_depth ) player = self.configuration.nom_player() other = _("the engine") w, b = (player, other) if self.human_side else (other, player) self.game.set_tag("White", w) self.game.set_tag("Black", b) self.is_analyzed_by_tutor = False self.continueTt = not self.configuration.x_engine_notbackground self.check_boards_setposition() if self.line_fns.with_game_original(): self.repiteUltimaJugada() self.reiniciando = False self.is_rival_thinking = False self.is_analyzing = False self.play_next_move()
def __init__(self, owner, nom_pieces_ori): titulo = _("Blindfold") + " - " + _("Configuration") icono = Iconos.Ojo() extparam = "wblindfold" QTVarios.WDialogo.__init__(self, owner, titulo, icono, extparam) self.config = BlindfoldConfig(nom_pieces_ori) self.nom_pieces_ori = nom_pieces_ori lbWhite = Controles.LB(self, _("White")).ponTipoLetra(peso=75, puntos=10) lbBlack = Controles.LB(self, _("Black")).ponTipoLetra(peso=75, puntos=10) self.dicWidgets = collections.OrderedDict() self.dicImgs = {} li_options = ((_("Hide"), HIDE), (_("Green"), GREY), (_("Checker"), CHECKER), (_("Show"), SHOW)) dicNomPiezas = TrListas.dicNomPiezas() def haz(pz): tpW = self.config.dicPiezas[pz.upper()] tpB = self.config.dicPiezas[pz] lbPZw = Controles.LB(self) cbPZw = Controles.CB(self, li_options, tpW).capture_changes(self.reset) lbPZ = Controles.LB(self, dicNomPiezas[pz.upper()]).ponTipoLetra( peso=75, puntos=10) lbPZb = Controles.LB(self) cbPZb = Controles.CB(self, li_options, tpB).capture_changes(self.reset) self.dicWidgets[pz] = [ lbPZw, cbPZw, lbPZ, lbPZb, cbPZb, None, None ] for pz in "kqrbnp": haz(pz) btAllW = Controles.PB(self, _("All White"), self.allWhite, plano=False) self.cbAll = Controles.CB(self, li_options, HIDE) btAllB = Controles.PB(self, _("All Black"), self.allBlack, plano=False) btSwap = Controles.PB(self, _("Swap"), self.swap, plano=False) li_acciones = ( (_("Save"), Iconos.Grabar(), "grabar"), None, (_("Cancel"), Iconos.Cancelar(), "cancelar"), None, (_("Configurations"), Iconos.Opciones(), "configurations"), None, ) tb = Controles.TB(self, li_acciones) ly = Colocacion.G() ly.controlc(lbWhite, 0, 1).controlc(lbBlack, 0, 3) row = 1 for pz in "kqrbnp": lbPZw, cbPZw, lbPZ, lbPZb, cbPZb, tipoW, tipoB = self.dicWidgets[ pz] ly.control(cbPZw, row, 0) ly.controlc(lbPZw, row, 1) ly.controlc(lbPZ, row, 2) ly.controlc(lbPZb, row, 3) ly.control(cbPZb, row, 4) row += 1 ly.filaVacia(row, 20) row += 1 ly.controld(btAllW, row, 0, 1, 2) ly.control(self.cbAll, row, 2) ly.control(btAllB, row, 3, 1, 2) ly.controlc(btSwap, row + 1, 0, 1, 5) ly.margen(20) layout = Colocacion.V().control(tb).otro(ly) self.setLayout(layout) self.reset()
def name(self): return TrListas.categoria(self.key)
def __init__(self, procesador, mapa): self.workmap = WorkMap.WorkMap(mapa) dic = TrListas.maps() titulo = dic[mapa] icono = getattr(Iconos, mapa)() QTVarios.WDialogo.__init__(self, procesador.main_window, titulo, icono, mapa) self.procesador = procesador self.playCurrent = None o_columns = Columnas.ListaColumnas() o_columns.nueva("TYPE", "", 24, edicion=Delegados.PmIconosBMT(), centered=True) o_columns.nueva("SELECT", _("Select one to play"), 150) self.grid = Grid.Grid(self, o_columns, siSelecFilas=True, xid="W") self.register_grid(self.grid) li_acciones = ((_("Close"), Iconos.MainMenu(), self.terminar), None, (_("Play"), Iconos.Empezar(), self.play), None) tb_work = QTVarios.LCTB(self, li_acciones, icon_size=24) self.lbInfo = Controles.LB(self) self.wsvg = wsvg = QtSvg.QSvgWidget() p = wsvg.palette() p.setColor(wsvg.backgroundRole(), QtGui.QColor("#F5F5F5")) wsvg.setPalette(p) ly = Colocacion.V().control(tb_work).control(self.lbInfo).control( self.grid) w = QtWidgets.QWidget() w.setLayout(ly) splitter = QtWidgets.QSplitter(self) splitter.addWidget(w) splitter.addWidget(wsvg) self.register_splitter(splitter, "splitter") o_columns = Columnas.ListaColumnas() o_columns.nueva("ACTIVE", _("Active"), 80, centered=True) o_columns.nueva("TYPE", _("Type"), 110, centered=True) o_columns.nueva("DCREATION", _("Creation date"), 110, centered=True) o_columns.nueva("DONE", _("Done"), 110, centered=True) o_columns.nueva("DEND", _("Ending date"), 110, centered=True) o_columns.nueva("RESULT", _("Result"), 110, centered=True) self.gridData = Grid.Grid(self, o_columns, siSelecFilas=True, xid="H") self.register_grid(self.gridData) li_acciones = ( (_("Close"), Iconos.MainMenu(), self.terminar), None, (_("Select"), Iconos.Seleccionar(), self.data_select), None, (_("New"), Iconos.NuevoMas(), self.data_new), None, (_("Remove"), Iconos.Borrar(), self.data_remove), None, ) tb = QTVarios.LCTB(self, li_acciones, icon_size=24) ly = Colocacion.V().control(tb).control(self.gridData) w = QtWidgets.QWidget() w.setLayout(ly) self.tab = Controles.Tab() self.tab.set_position("W") self.tab.nuevaTab(splitter, _("Map")) self.tab.nuevaTab(w, _("Data")) ly = Colocacion.H().control(self.tab).margen(0) self.setLayout(ly) self.restore_video(siTam=True, anchoDefecto=960, altoDefecto=600) self.workmap.setWidget(wsvg) self.workmap.resetWidget() self.grid.gotop() self.gridData.gotop() self.informacion()