def authstatechanged(self, user): self.user = user self.passwordinput.setText("") if user: self.displayName = user.displayName self.email = user.email self.emailVerified = user.emailVerified self.photoURL = user.photoURL self.isAnonymous = user.isAnonymous self.uid = user.uid self.providerData = user.providerData print("user", self.displayName, self.email) print(self.providerData) self.nameinfodiv = Div().html("name : <span class='{}'>{}</span>".format(cpick(self.displayName, "uiinfo", "uiinfored"), getelse(self.displayName,"<NA>"))).pt(5) self.emailinfodiv = Div().html("email : <span class='{}'>{}</span>".format(cpick(self.email, "uiinfo", "uiinfored"), getelse(self.email, "<NA>"))) self.verifiedinfodiv = Div().html("status : <span class='{}'>{}</span>".format(cpick(self.userverified(), "uiinfo", "uiinfored"), self.userstatusverbal())) self.photourldiv = Div().html("photo url : <span class='{}'>{}</span>".format(cpick(self.photoURL, "uiinfo", "uiinfored"), getelse(self.photoURL,"<NA>"))) self.uidinfodiv = Div().html("uid : <span class='uiinfo'>{}</span>".format(self.uid)).pb(8) self.userinfodiv.x().a([self.nameinfodiv, self.emailinfodiv, self.verifiedinfodiv, self.photourldiv, self.uidinfodiv]) self.emailinput.setText(self.email) self.displaynameinput.setText(self.displayName) self.photourlinput.setText(self.photoURL) self.photodiv.x() if self.photoURL: self.photodiv.html("<img src='{}'></img>".format(self.photoURL)) else: print("no user") self.userinfodiv.x().a([ Div().html("Please sign up or sign in !"), Button("Sign in anonymously", self.signinanonymously()) ]) self.setprofiletab() self.userinfodiv.fs(cpick(self.user, 10, 14))
def buildprominput(self): promkinds = prompiecekindsforvariantkey(self.variantkey) promsq = self.dragmove.tosq.copy() dir = cpick(promsq.rank >= ( self.numranks / 2 ), -1, 1) ppks = prompiecekindsforvariantkey(self.variantkey) for ppk in ppks: fapromsq = self.flipawaresquare(promsq) pp = Piece(ppk, self.turn()) psqdiv = Div().pa().cp().zi(150).w(self.squaresize).h(self.squaresize).ac("boardpromotionsquare") psqdiv.pv(self.squarecoordsvect(fapromsq)) ppdiv = Div().pa().cp().zi(200).w(self.piecesize).h(self.piecesize).ac(getclassforpiece(pp, self.piecestyle)) ppdiv.pv(self.piececoordsvect(fapromsq)).ae("mousedown", self.prompiececlickedfactory(ppk)) self.container.a([psqdiv, ppdiv]) promsq = promsq.p(Square(0, dir))
def setmybots(self, obj): botprofiles = obj["mybots"] self.botresultdiv.x() __pragma__("jsiter") for id in botprofiles: botprofile = botprofiles[id] self.botresultdiv.a(Div().html("{} {}".format( botprofile["username"], cpick(botprofile["online"], "online", "offline"))).fs(25).pad(5)) self.botresultdiv.a(Div().html( "follow {} games {} last move {}".format( botprofile["nbFollowers"], botprofile["count"]["all"], botprofile["lastmoveago"])).fs(20).pad(3)) self.botresultdiv.a(Div().html("last players {}".format( botprofile["lastplayers"])).fs(20).pad(3)) __pragma__("nojsiter")
def buildsquares(self): self.container.x() self.sqdivs = {} self.sqhdivs = {} for sq in self.squarelist(): sqclass = cpick(self.islightsquare(sq), "boardsquarelight", "boardsquaredark") sqdiv = Div().ac(["boardsquare", sqclass]).w(self.squaresize).h(self.squaresize) sqhdiv = Div().pa().w(self.squaresize).h(self.squaresize) self.sqdivs[sq.hashkey()] = sqdiv self.sqhdivs[sq.hashkey()] = { "div": sqhdiv, "cumop": 0.0 } fasq = self.flipawaresquare(sq) sqdiv.pv(self.squarecoordsvect(fasq)) sqhdiv.pv(self.squarecoordsvect(fasq)) sqdiv.ae("dragover", self.piecedragoverfactory(sq)) sqdiv.ae("drop", self.piecedropfactory(sq)) sqhdiv.ae("dragover", self.piecedragoverfactory(sq)) sqhdiv.ae("drop", self.piecedropfactory(sq)) self.container.a([sqdiv, sqhdiv]) p = self.getpieceatsquare(sq) if p.ispiece(): pdiv = Div().ac("boardpiece").w(self.piecesize).h(self.piecesize).pv(self.piececoordsvect(fasq)) pdiv.ac(getclassforpiece(p, self.piecestyle)).sa("draggable", True) pdiv.ae("dragstart", self.piecedragstartfactory(sq, pdiv)) pdiv.ae("drag", self.piecedragfactory()) pdiv.ae("dragend", self.piecedragendfactory(sq, pdiv)) pdiv.ae("dragover", self.piecedragoverfactory(sq)) pdiv.ae("drop", self.piecedropfactory(sq)) pdiv.zi(10) if self.variantkey == "threeCheck": if ( p.kind == "k" ): mul = self.getthreelifesforcolor(p.color) lifesdiv = Div().pa().t(- self.squaresize / 10).l(self.squaresize / 2 + self.squaresize / 10).w(self.squaresize / 2).h(self.squaresize / 2) lifesdiv.ac("boardthreechecklifesdiv").fs(self.squaresize / 1.5).html("{}".format(mul)) lifesdiv.c(["#ff0", "#ff0"][p.color]) pdiv.a(lifesdiv) self.container.a(pdiv)
def userstatusverbal(self): if not self.user: return "[logged out]" if self.user.isAnonymous: return "anonymous" return cpick(self.emailVerified, "verified", "not verified")
def __init__(self, args): super().__init__("div") self.BARWIDTH = args.get("barwidth", 20) self.BARSEPARATION = int(self.BARWIDTH * 1.1) self.YHEIGHT = args.get("yheight", 2) self.CLUSTER = args.get("cluster", 50) self.data = args.get("data", []) first = True for d in self.data: mind = d["min"] maxd = d["max"] if first: miny = mind maxy = maxd first = False else: if mind < miny: miny = mind if maxd > maxy: maxy = maxd miny = miny - ( miny % self.CLUSTER ) maxy = maxy - ( maxy % self.CLUSTER ) + self.CLUSTER chartwidth = self.BARSEPARATION * len(self.data) self.w(chartwidth) range = maxy - miny chartheight = range * self.YHEIGHT self.h(chartheight) self.pr().bc("#ffc") for i in range(1, range / self.CLUSTER): rt = maxy - ( i * self.CLUSTER ) yt = i * self.CLUSTER * self.YHEIGHT linediv = Div().pa().t(yt).l(0).w(chartwidth).h(1).bc("#000") ratingdiv = Div().pa().t(yt + 5).ms().html(rt) self.a([ linediv, ratingdiv ]) i = 0 for d in self.data: mind = d["min"] minr = range - ( mind - miny ) mint = minr * self.YHEIGHT maxd = d["max"] maxr = range - ( maxd - miny ) maxt = maxr * self.YHEIGHT open = d["open"] openr = range - ( open - miny ) opent = openr * self.YHEIGHT close = d["close"] closer = range - ( close - miny ) closet = closer * self.YHEIGHT xcoord = i * self.BARSEPARATION bardiv = Div().pa().t(min(opent, closet)).l(xcoord + 1).w(self.BARWIDTH).h(abs(opent - closet)).bc(cpick(opent < closet, "#f00", "#0f0")) minmaxdiv = Div().pa().t(maxt).l(xcoord + int(self.BARWIDTH / 2) - 1 + 1).w(2).h(mint - maxt).bc("#007") self.a([ minmaxdiv, bardiv ]) i += 1
def setrepfromfen(self, fen): self.fen = fen self.crazyfen = None self.threefen = None self.rep = [Piece() for i in range(self.area)] fenparts = self.fen.split(" ") self.rawfen = fenparts[0] rawfenparts = self.rawfen.split("/") if self.variantkey == "crazyhouse": self.crazyfen = "" if "[" in self.rawfen: cfenparts = self.rawfen.split("[") self.rawfen = cfenparts[0] rawfenparts = self.rawfen.split("/") cfenparts = cfenparts[1].split("]") self.crazyfen = cfenparts[0] i = 0 for rawfenpart in rawfenparts: pieceletters = rawfenpart.split("") for pieceletter in pieceletters: if isvalidpieceletter(pieceletter): self.setpieceati(i, piecelettertopiece(pieceletter)) i+=1 else: mul = 0 try: mul = int(pieceletter) except: print("warning, multiplicity could not be parsed from", pieceletter) for j in range(mul): self.setpieceati(i, Piece()) i += 1 if i < self.area: print("warning, raw fen did not fill board") elif i > self.area: print("warning, raw fen exceeded board") self.turnfen = "w" if len(fenparts) > 1: self.turnfen = fenparts[1] else: print("warning, no turn fen") self.castlefen = "-" if len(fenparts) > 2: self.castlefen = fenparts[2] else: print("warning, no castle fen") self.epfen = "-" if len(fenparts) > 3: self.epfen = fenparts[3] else: print("warning, no ep fen") moveclocksi = cpick(self.variantkey == "threeCheck", 5, 4) self.halfmoveclock = 0 if len(fenparts) > moveclocksi: try: self.halfmoveclock = int(fenparts[moveclocksi]) except: print("warning, half move clock could not be parsed from", fenparts[4]) else: print("warning, no half move fen") self.fullmovenumber = 1 if len(fenparts) > ( moveclocksi + 1 ): try: self.fullmovenumber = int(fenparts[moveclocksi + 1]) except: print("warning, full move number could not be parsed from", fenparts[5]) else: print("warning, no full move fen") if self.variantkey == "threeCheck": if len(fenparts) > 4: self.threefen = fenparts[4] self.promoting = False
def build(self): self.sectioncontainer = Div().ac("boardsectioncontainer").w(self.outerwidth) self.sectioncontainer.bci(self.background) self.outercontainer = Div().ac("boardoutercontainer").w(self.outerwidth).h(self.outerheight) self.outercontainer.bci(self.background) self.container = Div().ac("boardcontainer").w(self.width).h(self.height).t(self.margin).l(self.margin) self.container.bci(self.background) self.outercontainer.a(self.container) self.buildsquares() self.turndiv = Div().pa().w(self.turndivsize).h(self.turndivsize).bc(cpick(self.iswhitesturn(), "#fff", "#000")) if self.variantkey == "racingKings": self.turndiv.t(cpick(self.flip, 0, self.outerheight - self.turndivsize)) if xor(self.isblacksturn(), self.flip): self.turndiv.l(0) else: self.turndiv.l(self.outerwidth - self.turndivsize) else: self.turndiv.l(self.outerwidth - self.turndivsize).t(cpick(xor(self.isblacksturn(), self.flip), 0, self.outerheight - self.turndivsize)) self.outercontainer.a(self.turndiv) if self.promoting: self.buildprominput() self.container.ae("mousedown", self.promotecancelclick) self.fentext = TextInput({}).w(self.width).fs(10).setText(self.fen) self.fentext.changecallback = self.fentextchanged self.fendiv = Div().ac("boardfendiv").h(self.fendivheight).a(self.fentext) if self.variantkey == "crazyhouse": self.whitestorediv = Div().ac("boardstorediv").h(self.squaresize).w(self.outerwidth) self.whitestorediv.bci(self.background) self.blackstorediv = Div().ac("boardstorediv").h(self.squaresize).w(self.outerwidth) self.blackstorediv.bci(self.background) self.whitestore = PieceStore({ "show": self.show, "parent": self, "color": WHITE, "store": self.crazyfen, "containerdiv": self.whitestorediv }) self.blackstore = PieceStore({ "show": self.show, "parent": self, "color": BLACK, "store": self.crazyfen, "containerdiv": self.blackstorediv }) if self.flip: self.sectioncontainer.a([self.whitestorediv, self.outercontainer, self.blackstorediv]) else: self.sectioncontainer.a([self.blackstorediv, self.outercontainer, self.whitestorediv]) else: self.sectioncontainer.a([self.outercontainer]) if self.showfen: self.sectioncontainer.a(self.fendiv) self.x().a(self.sectioncontainer) self.movecanvas = Canvas(self.width, self.height).pa().t(0).l(0) self.movecanvashook = Div().pa().t(0).l(0).zi(5).op(0.5) self.piececanvashook = Div().pa().t(0).l(0).zi(11).op(0.5) self.arrowdiv = Div().pa() self.container.a([self.movecanvashook, self.arrowdiv, self.piececanvashook]) self.movecanvashook.a(self.movecanvas) self.buildgenmove() return self
def moveuci(self, move): fromuci = self.squareuci(move.fromsq) touci = self.squareuci(move.tosq) promuci = cpick(move.prompiece.isempty(), "", move.prompiece.kind) return fromuci + touci + promuci
def totalheight(self): th = self.outerheight + cpick(self.showfen, self.fendivheight, 0) if self.variantkey == "crazyhouse": th += 2 * self.squaresize return th