コード例 #1
0
class bs3010(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["bksmst", "bksaut", "bksown"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        t = time.localtime()
        self.curdt = time.strftime("%Y-%m", t)
        self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "books.png")
        if not os.path.exists(self.image):
            getImage("books", fle=self.image)
        if not os.path.exists(self.image):
            self.image = None
        return True

    def mainProcess(self):
        lst = {
            "stype": "R",
            "tables": ("bksmst", ),
            "cols": (("bmf_mnth", "", 0, "Month"), ),
            "where": [("bmf_cono", "=", self.opts["conum"])],
            "group": "bmf_mnth",
            "order": "bmf_mnth"
        }
        r1s = (("All", "A"), ("Current", "C"), ("Removed", "R"))
        r2s = (("Title", "T"), ("Date", "D"), ("Author", "A"), ("Owner", "O"))
        fld = ((("T", 0, 0, 0), "ID2", 7, "Last Meeting", "", "", "N",
                self.doLast, lst, None, ("efld", )),
               (("T", 0, 1, 0), ("IRB", r1s), 0, "Status", "", "A", "N",
                self.doStatus, None, None, None),
               (("T", 0, 2, 0), ("IRB", r2s), 0, "Order", "", "T", "N",
                self.doOrder, None, None, None))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               tops=False,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("B", "Y"))

    def doLast(self, frt, pag, r, c, p, i, w):
        self.last = w
        self.new = False

    def doStatus(self, frt, pag, r, c, p, i, w):
        self.status = w

    def doOrder(self, frt, pag, r, c, p, i, w):
        self.order = w

    def doEnd(self):
        self.df.closeProcess()
        if self.df.repeml[1] == "Y":
            if not self.df.repeml[2]:
                owns = self.sql.getRec("bksown",
                                       cols=["bof_mail"],
                                       where=[("bof_mail", "<>", ""),
                                              ("bof_stat", "=", "C")])
                adds = None
                for own in owns:
                    if not adds:
                        adds = own[0]
                    else:
                        adds = "%s,%s" % (adds, own[0])
                self.df.repeml[2] = adds
            if not self.df.repeml[3]:
                self.df.repeml[3] = """Dear Member

Attached please find the latest list of books.

All books which came onto the list at the last meeting are highlighted and, if available, a precis will be printed at the end.

Thanks and Regards.
"""
        tab = ["bksmst", "bksaut", "bksown"]
        col = [
            "bmf_stat", "bmf_titl", "bmf_code", "baf_snam", "baf_fnam",
            "bmf_mnth", "bof_fnam", "bof_snam"
        ]
        odr = ""
        if self.status == "C":
            whr = [("bmf_stat", "=", "C")]
        elif self.status == "R":
            whr = [("bmf_stat", "=", "X")]
        else:
            whr = []
            odr = "bmf_stat"
        whr.extend([("baf_code=bmf_auth", ), ("bof_code=bmf_ownr", )])
        if self.order == "T":
            if odr:
                odr = "%s, bmf_titl" % odr
            else:
                odr = "bmf_titl"
        elif self.order == "D":
            if odr:
                odr = "%s, bmf_mnth, bmf_titl" % odr
            else:
                odr = "bmf_mnth, bmf_titl"
        elif self.order == "A":
            if odr:
                odr = "%s, baf_snam, baf_fnam, bmf_titl" % odr
            else:
                odr = "baf_snam, baf_fnam, bmf_titl"
        elif self.order == "O":
            if odr:
                odr = "%s, bmf_ownr, bmf_titl" % odr
            else:
                odr = "bmf_ownr, bmf_titl"
        recs = self.sql.getRec(tables=tab, cols=col, where=whr, order=odr)
        if not recs:
            showError(self.opts["mf"].body, "Selection Error",
                      "No Records Selected")
            self.opts["mf"].closeLoop()
            return
        self.fpdf = MyFpdf(name="bs3010", head=90, auto=True)
        self.fpdf.header = self.pageHeading
        self.stat = recs[0][0]
        self.fpdf.add_page()
        new = []
        for rec in recs:
            stat = CCD(rec[0], "UA", 1).disp
            if stat != self.stat:
                self.stat = stat
                self.fpdf.add_page()
            titl = CCD(rec[1], "NA", 30).disp
            code = CCD(rec[2], "UI", 4).disp
            auth = CCD("%s, %s" % (rec[3], rec[4]), "NA", 30).disp
            mnth = CCD(rec[5], "D2", 7).disp
            ownr = CCD("%s %s" % (rec[6], rec[7][0]), "NA", 12).disp
            if rec[5] < self.last:
                fill = 0
            else:
                new.append([auth, titl])
                fill = 1
            self.fpdf.drawText("%1s %30s %4s %30s %7s %10s" %
                               (stat, titl, code, auth, mnth, ownr),
                               h=5,
                               fill=fill)
        if new:
            sp = SplashScreen(
                self.opts["mf"].body,
                "Preparing Summary of New Books ... Please Wait")
            self.new = True
            self.fpdf.add_page()
            for book in new:
                try:
                    if self.fpdf.get_y() > 260:
                        self.fpdf.add_page()
                    desc = self.getDesc(book)
                    if desc:
                        w = self.fpdf.cwth * 9
                        desc = desc.rstrip().encode("latin-1",
                                                    "ignore").decode(
                                                        "latin-1", "ignore")
                        self.fpdf.drawText(w=w, txt="Title: ", font="B", ln=0)
                        self.fpdf.drawText(txt=book[1].rstrip(), font="I")
                        self.fpdf.drawText(w=w, txt="Author: ", font="B", ln=0)
                        self.fpdf.drawText(txt=book[0].rstrip(), font="I")
                        self.fpdf.drawText(w=w,
                                           txt="Details: ",
                                           font="B",
                                           ln=0)
                        self.fpdf.drawText(txt=desc, font="I", ctyp="M")
                        if book != new[-1]:
                            self.fpdf.drawText()
                except:
                    pass
            sp.closeSplash()
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            self.opts["conum"],
                            ext="pdf")
        self.fpdf.output(pdfnam, "F")
        head = "Book List as at %s" % (self.curdt)
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header=head,
                  repprt=self.df.repprt,
                  repeml=self.df.repeml)
        self.opts["mf"].closeLoop()

    def pageHeading(self, new=False):
        self.fpdf.setFont("Arial", "B", 15)
        x = self.fpdf.get_x()
        if self.image:
            self.fpdf.image(self.image, 11, 10, 15, 20)
            self.fpdf.image(self.image, 185, 10, 15, 20)
            self.fpdf.cell(20)
        self.fpdf.set_x(x)
        self.fpdf.cell(0, 10, self.opts["conam"], "TLR", 1, "C")
        if self.new:
            txt = "Summary of New Books"
        elif self.stat == "C":
            txt = "Current Books as at %s" % self.curdt
        else:
            txt = "Removed Books as at %s" % self.curdt
        self.fpdf.cell(0, 10, txt, "LRB", 1, "C")
        self.fpdf.ln(8)
        self.fpdf.setFont(style="B")
        if not self.new:
            self.fpdf.cell(
                0, 5, "%-1s %-30s %-4s %-30s %-7s %-12s" %
                ("S", "Title", "Code", "Author", "Mth-Rec", "Owner"), "B")
        self.fpdf.ln(5)

    def getDesc(self, book):
        auth = book[0].strip().lower()
        titl = book[1].strip().lower().replace(",", "")
        if titl[:4] == "the ":
            titl = titl[4:]
        elif titl[-4:] == " the":
            titl = titl[:-4]
        get = requests.get("https://www.googleapis.com/books/v1/volumes?q="\
            "{intitle:'%s'+inauthor:'%s'" % (titl, auth), timeout=5)
        if get.status_code == 200 and get.json()["totalItems"]:
            ok = False
            for item in get.json()["items"]:
                tita = titl.lower().\
                    replace("the ","").replace(", the", "")
                titb = item["volumeInfo"]["title"].lower().\
                    replace("the ","").replace(", the", "")
                if titb.count(tita):
                    if "description" in item["volumeInfo"]:
                        ok = True
                        break
            if ok:
                return item["volumeInfo"]["description"]

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
コード例 #2
0
class sc3010(object):
    def __init__(self, **opts):
        self.opts = opts
        self.setVariables()
        self.mainProcess()
        self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, "scpcmp",
            prog=self.__class__.__name__)
        t = time.localtime()
        self.sysdt = time.strftime("%d %B %Y %H:%M:%S", t)
        self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "bowls.png")
        if not os.path.exists(self.image):
            getImage("bowls", fle=self.image)
        if not os.path.exists(self.image):
            self.image = None

    def mainProcess(self):
        com = {
            "stype": "R",
            "tables": ("scpcmp",),
            "cols": (
                ("scp_ccod", "", 0, "Cod"),
                ("scp_name", "", 0, "Name", "Y")),
            "where": [("scp_cono", "=", self.opts["conum"])]}
        fld = (
            (("T",0,0,0),"I@scp_ccod",0,"Code","",
                "","N",self.doCmpCod,com,None,("notzero",)),
            (("T",0,0,0),"ONA",30,""))
        tnd = ((self.doEnd,"y"),)
        txt = (self.doExit,)
        self.df = TartanDialog(self.opts["mf"], tops=False,
            eflds=fld, tend=tnd, txit=txt, view=("N","V"))

    def doCmpCod(self, frt, pag, r, c, p, i, w):
        chk = self.sql.getRec("scpcmp", cols=["scp_name"],
            where=[("scp_cono", "=", self.opts["conum"]), ("scp_ccod", "=",
            w)], limit=1)
        if not chk:
            return "Invalid Competition Code"
        self.ccod = w
        self.cnam = chk[0]
        self.df.loadEntry(frt, pag, p+1, data=self.cnam)

    def doEnd(self):
        self.df.closeProcess()
        col = ["scm_scod", "scm_surname", "scm_names", "scm_gender",
            "scc_name", "scm_phone"]
        whr = [
            ("sce_cono", "=", self.opts["conum"]),
            ("sce_ccod", "=", self.ccod),
            ("scm_cono=sce_cono",),
            ("scm_scod=sce_scod",),
            ("scc_club=scm_club",)]
        recs = self.sql.getRec(tables=["scpent", "scpmem", "scpclb"], cols=col,
            where=whr, order="scm_surname")
        if recs:
            self.fpdf = MyFpdf(auto=True, name="sc3010", head=90)
            self.fpdf.header = self.doHead
            self.fpdf.add_page()
            cwth = self.fpdf.cwth
            for num, rec in enumerate(recs):
                self.fpdf.drawText(txt="%6s" % rec[0], w=cwth*7, h=5, ln=0)
                nm = rec[1].strip() + ", %s" % rec[2].split()[0]
                self.fpdf.drawText(txt=nm, w=cwth*31, h=5, ln=0)
                self.fpdf.drawText(txt=rec[3], w=cwth*2, h=5, ln=0)
                self.fpdf.drawText(txt=rec[4], w=cwth*31, h=5, ln=0)
                ph = rec[5].replace(" ", "").strip()
                self.fpdf.drawText(txt=ph, w=cwth*16, h=5, ln=1)
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                self.__class__.__name__, self.opts["conum"], ext="pdf")
            self.fpdf.output(pdfnam, "F")
            doPrinter(mf=self.opts["mf"], pdfnam=pdfnam,
                repprt=self.df.repprt,
                repeml=self.df.repeml)
        self.opts["mf"].closeLoop()

    def doHead(self):
        if os.path.isfile(self.image):
            self.fpdf.image(self.image, 10, 10, 15, 11)
        self.fpdf.set_font("Arial","B",15)
        self.fpdf.cell(20)
        self.fpdf.cell(0,10,"Players Entered in the %s" % self.cnam,1,0,"C")
        self.fpdf.ln(20)
        self.fpdf.setFont(style="B")
        self.fpdf.cell(0, 5, "%-6s %-30s %-1s %-30s %-15s" % \
            ("Reg-No", "Name", "G", "Club", "Contact"), "B")
        self.fpdf.ln(5)

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
コード例 #3
0
class bc3020(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            self.mainProcess()
            self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["bwldrm", "bwldrt", "bwltab"],
                       prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        bwlctl = gc.getCtl("bwlctl", self.opts["conum"])
        if not bwlctl:
            return
        self.nstart = bwlctl["ctb_nstart"]
        self.fromad = bwlctl["ctb_emadd"]
        t = time.localtime()
        self.sysdt = time.strftime("%d %B %Y %H:%M:%S", t)
        self.curdt = time.strftime("%Y-%m", t)
        self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "bowls.png")
        if not os.path.exists(self.image):
            getImage("bowls", fle=self.image)
        if not os.path.exists(self.image):
            self.image = None
        self.drawn = "Y"
        self.bounce = "N"
        self.teams = "N"
        return True

    def mainProcess(self):
        r1s = (("Yes", "Y"), ("No", "N"))
        fld = ((("T", 0, 0, 0), "Id2", 7, "Starting Period", "", "", "N",
                self.doStartPeriod, None, None, ("efld", )),
               (("T", 0, 1, 0), "Id2", 7, "Ending Period", "", "", "N",
                self.doEndPeriod, None, None,
                ("efld", )), (("T", 0, 2, 0), ("IRB", r1s), 0, "All Tabs", "",
                              "Y", "N", self.doTabs, None, None, None),
               (("T", 0, 3, 0), ("ICB", "Tabs-In"), 0, "Draw Types", "",
                self.drawn, "N", self.doType, None, None,
                None), (("T", 0, 3, 0), ("ICB", "Bounce"), 0, "", "",
                        self.bounce, "N", self.doType, None, None, None),
               (("T", 0, 3, 0), ("ICB", "Teams"), 0, "", "", self.teams, "N",
                self.doType, None, None,
                None), (("T", 0, 4, 0), ("IRB", r1s), 0, "Totals Only", "",
                        "N", "N", self.doTots, None, None, None))
        tnd = ((self.doEnd, "y"), )
        txt = (self.doExit, )
        self.df = TartanDialog(self.opts["mf"],
                               tops=False,
                               eflds=fld,
                               tend=tnd,
                               txit=txt,
                               view=("N", "V"),
                               mail=("Y", "Y"))

    def doStartPeriod(self, frt, pag, r, c, p, i, w):
        if w:
            self.start = CCD((w * 100) + 1, "D1", 7)
        else:
            self.start = CCD(0, "UI", 1)

    def doEndPeriod(self, frt, pag, r, c, p, i, w):
        if w:
            self.end = CCD(mthendDate((w * 100) + 1), "D1", 7)
        else:
            self.end = CCD(0, "d1", 7)
            self.end.disp = self.curdt

    def doTabs(self, frt, pag, r, c, p, i, w):
        self.whole = w

    def doType(self, frt, pag, r, c, p, i, w):
        if p == 3:
            self.drawn = w
        elif p == 4:
            self.bounce = w
        else:
            self.teams = w

    def doTots(self, frt, pag, r, c, p, i, w):
        self.tots = w

    def doEnd(self):
        self.df.closeProcess()
        dat = []
        tps = []
        if self.drawn == "Y":
            tps.extend(["B", "D"])
        if self.bounce == "Y":
            tps.append("A")
        if self.teams == "Y":
            tps.append("C")
        where = [("bdt_cono", "=", self.opts["conum"]),
                 ("bdt_tab", "<", self.nstart), ("bdt_flag", "in", tps)]
        if self.start.work:
            where.append(("bdt_date", ">=", self.start.work))
        if self.end.work:
            where.append(("bdt_date", "<=", self.end.work))
        whr = copyList(where)
        if self.whole == "N":
            tab = []
            rec = getSingleRecords(self.opts["mf"],
                                   "bwldrt", ("bdt_tab", "bdt_name"),
                                   head=["X", "Tab-No", "Name"],
                                   where=whr,
                                   group="bdt_tab, bdt_name",
                                   order="bdt_name",
                                   selcol="bdt_name")
            if not rec:
                self.opts["mf"].closeLoop()
                return
            for r in rec:
                tab.append(r[1])
            whr.append(("bdt_tab", "in", tab))
        odr = "bdt_name, bdt_date"
        rec = self.sql.getRec("bwldrt", where=whr, order=odr)
        c = self.sql.bwldrt_col
        l = ""
        self.dic = {}
        for r in rec:
            dte = CCD(r[c.index("bdt_date")], "D1", 10)
            tim = r[c.index("bdt_time")]
            bdm = self.sql.getRec("bwldrm",
                                  where=[("bdm_cono", "=", self.opts["conum"]),
                                         ("bdm_date", "=", dte.work),
                                         ("bdm_time", "=", tim)],
                                  limit=1)
            if bdm[self.sql.bwldrm_col.index("bdm_dhist")] == "N":
                continue
            self.clash = ""
            side = [["", ""], ["", ""], ["", ""], ["", ""]]
            self.tab = r[c.index("bdt_tab")]
            if self.tab not in self.dic:
                self.dic[self.tab] = []
            nam = self.getName(self.tab)
            pos = (0 - (r[c.index("bdt_pos")] - 4))
            side[pos] = ["", nam]
            for x in range(1, 4):
                tm = self.getName(r[c.index("bdt_team%s" % x)])
                if not tm:
                    continue
                if self.clash:
                    cl = "X"
                else:
                    cl = ""
                pos = (0 - (r[c.index("bdt_pos%s" % x)] - 4))
                side[pos] = [cl, tm]
            if self.tab != l:
                if l:
                    dat.append([])
                d = [nam]
            else:
                d = [""]
            d.extend([dte.disp, side[0], side[1], side[2], side[3]])
            dat.append(d)
            l = self.tab
        self.fpdf = MyFpdf(name=self.__class__.__name__, head=120, auto=True)
        self.fpdf.header = self.pageHeading
        if self.tots == "N":
            # Print teams
            self.heading = "main"
            self.fpdf.add_page()
            cwth = self.fpdf.get_string_width("X")
            for d in dat:
                if not d:
                    self.fpdf.drawText(txt="", w=0, h=5, border=0, ln=1)
                else:
                    self.fpdf.cell(w=cwth * 21, h=5, txt=d[0], border=0, ln=0)
                    self.fpdf.cell(w=cwth * 11, h=5, txt=d[1], border=0, ln=0)
                    if d[2][0]:
                        self.fpdf.cell(w=cwth * 21,
                                       h=5,
                                       txt=d[2][1],
                                       border=1,
                                       ln=0)
                    else:
                        self.fpdf.cell(w=cwth * 21,
                                       h=5,
                                       txt=d[2][1],
                                       border=0,
                                       ln=0)
                    if d[3][0]:
                        self.fpdf.cell(w=cwth * 21,
                                       h=5,
                                       txt=d[3][1],
                                       border=1,
                                       ln=0)
                    else:
                        self.fpdf.cell(w=cwth * 21,
                                       h=5,
                                       txt=d[3][1],
                                       border=0,
                                       ln=0)
                    if d[4][0]:
                        self.fpdf.cell(w=cwth * 21,
                                       h=5,
                                       txt=d[4][1],
                                       border=1,
                                       ln=0)
                    else:
                        self.fpdf.cell(w=cwth * 21,
                                       h=5,
                                       txt=d[4][1],
                                       border=0,
                                       ln=0)
                    if d[5][0]:
                        self.fpdf.cell(w=cwth * 21,
                                       h=5,
                                       txt=d[5][1],
                                       border=1,
                                       ln=1)
                    else:
                        self.fpdf.cell(w=cwth * 21,
                                       h=5,
                                       txt=d[5][1],
                                       border=0,
                                       ln=1)
        if self.whole == "Y" or self.tots == "Y":
            # Print top attendees
            self.heading = "summary"
            whr = copyList(where)
            whr.append(("bdt_tab", "<", self.nstart))
            self.cnt = self.sql.getRec("bwldrt",
                                       cols=["count(*) as count", "bdt_tab"],
                                       where=whr,
                                       group="bdt_tab",
                                       order="count desc, bdt_name")
            while self.cnt:
                self.fpdf.add_page()
                if len(self.cnt) < 26:
                    left = copyList(self.cnt)
                    self.cnt = []
                    right = []
                else:
                    left = self.cnt[:25]
                    self.cnt = self.cnt[25:]
                    if len(self.cnt) < 26:
                        right = copyList(self.cnt)
                        self.cnt = []
                    else:
                        right = self.cnt[:25]
                        self.cnt = self.cnt[25:]
                left = left + (25 - len(left)) * [["", ""]]
                right = right + (25 - len(right)) * [["", ""]]
                self.fpdf.set_font("Arial", "", 15)
                cwth = self.fpdf.get_string_width("X")
                for x in range(25):
                    if left[x][1]:
                        left[x][1] = self.getName(left[x][1], cls=False)
                    if right[x][1]:
                        right[x][1] = self.getName(right[x][1], cls=False)
                    self.fpdf.cell(cwth * 5, 8, "%5s " % left[x][0], 0, 0, "R")
                    self.fpdf.cell(cwth * 24, 8, left[x][1], 0, 0, "L")
                    self.fpdf.cell(cwth * 5, 8, "%5s " % right[x][0], 0, 0,
                                   "R")
                    self.fpdf.cell(cwth * 20, 8, right[x][1], 0, 1, "L")
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                            self.__class__.__name__,
                            self.opts["conum"],
                            ext="pdf")
        self.fpdf.output(pdfnam, "F")
        head = "Tabs Draw Summary for the period %s to %s" % (self.start.disp,
                                                              self.end.disp)
        doPrinter(mf=self.opts["mf"],
                  conum=self.opts["conum"],
                  pdfnam=pdfnam,
                  header=head,
                  repprt=self.df.repprt,
                  fromad=self.fromad,
                  repeml=self.df.repeml)
        self.opts["mf"].closeLoop()

    def getName(self, tab, cls=True):
        self.clash = False
        if not tab:
            return ""
        rec = self.sql.getRec("bwltab",
                              cols=["btb_surname", "btb_names", "btb_rate1"],
                              where=[("btb_tab", "=", tab)],
                              limit=1)
        if not rec:
            return "VISITOR, A"
        if rec[1]:
            nam = "%s, %s" % (rec[0], rec[1][0])
        else:
            nam = rec[0]
        nam = nam.replace("VAN DER", "V D")
        nam = nam.replace("JANSE VAN", "J V")
        if cls:
            if tab in self.dic[self.tab]:
                self.clash = True
            self.dic[self.tab].append(tab)
        return nam

    def pageHeading(self):
        self.fpdf.setFont("Arial", "B", 15)
        if os.path.isfile(self.image):
            self.fpdf.image(self.image, 10, 10, 15, 11)
            self.fpdf.cell(20)
        x = self.fpdf.get_x()
        self.fpdf.cell(0, 10, self.opts["conam"], "TLR", 1, "C")
        self.fpdf.set_x(x)
        if self.heading == "main":
            self.fpdf.cell(0, 10, "Tabs-In for the period %s to %s" % \
                (self.start.disp, self.end.disp), "LRB", 1, "C")
            self.fpdf.ln(8)
            self.fpdf.setFont(style="B")
            self.fpdf.cell(0, 5, "%-20s %-10s %-20s %-20s %-20s %-20s" % \
                ("Member", "   Date", "Skip", "Third", "Second", "Lead"), "B")
            self.fpdf.ln(5)
        else:
            self.fpdf.cell(0, 10, "Top Attendees for the period "\
                "%s to %s" % (self.start.disp, self.end.disp),
                "LRB", 0, "C")
            self.fpdf.ln(15)
            self.fpdf.cell(
                0, 5,
                "%5s %-50s %5s %-30s" % ("Count", "Member", "Count", "Member"),
                "B")
            self.fpdf.ln(10)

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
コード例 #4
0
ファイル: bc3070.py プロジェクト: paulmalherbe/Tartan
class bc3070(object):
    def __init__(self, **opts):
        self.opts = opts
        self.setVariables()
        self.mainProcess()
        self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["bwlcmp", "bwlent", "bwltab"],
            prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        bwlctl = gc.getCtl("bwlctl", self.opts["conum"])
        if not bwlctl:
            return
        self.fromad = bwlctl["ctb_emadd"]
        t = time.localtime()
        self.sysdt = time.strftime("%d %B %Y %H:%M:%S", t)
        self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "bowls.png")
        if not os.path.exists(self.image):
            getImage("bowls", fle=self.image)
        if not os.path.exists(self.image):
            self.image = None

    def mainProcess(self):
        com = {
            "stype": "R",
            "tables": ("bwlcmp",),
            "cols": (
                ("bcm_code", "", 0, "Cod"),
                ("bcm_name", "", 0, "Name", "Y"),
                ("bcm_date", "", 0, "Date")),
            "where": [("bcm_cono", "=", self.opts["conum"])]}
        r1s = (("Alphabtic", "A"), ("Numeric", "N"))
        fld = (
            (("T",0,0,0),"I@bcm_code",0,"","",
                "","N",self.doCmpCod,com,None,("notzero",)),
            (("T",0,0,0),"ONA",30,""),
            (("T",0,1,0),("IRB",r1s),0,"Order","",
                "A","N",self.doCmpOrd,None,None,None))
        tnd = ((self.doEnd,"y"),)
        txt = (self.doExit,)
        self.df = TartanDialog(self.opts["mf"], tops=False,
            eflds=fld, tend=tnd, txit=txt, view=("N","V"), mail=("Y","Y"))

    def doCmpCod(self, frt, pag, r, c, p, i, w):
        chk = self.sql.getRec("bwlcmp", cols=["bcm_name"],
            where=[("bcm_cono", "=", self.opts["conum"]), ("bcm_code", "=",
            w)], limit=1)
        if not chk:
            return "Invalid Competition Code"
        self.ccod = w
        self.cnam = chk[0]
        self.df.loadEntry(frt, pag, p+1, data=self.cnam)

    def doCmpOrd(self, frt, pag, r, c, p, i, w):
        self.cord = w

    def doEnd(self):
        self.df.closeProcess()
        col = ["btb_tab", "btb_surname", "btb_names", "btb_cell",
            "btb_mail", "bce_tcod"]
        whr = [
            ("bce_cono", "=", self.opts["conum"]),
            ("bce_ccod", "=", self.ccod),
            ("btb_cono=bce_cono",),
            ("btb_tab=bce_scod",)]
        if self.cord == "A":
            odr = "btb_surname"
        else:
            odr = "btb_tab"
        recs = self.sql.getRec(tables=["bwlent", "bwltab"], cols=col,
            where=whr, order=odr)
        if recs:
            self.fpdf = MyFpdf(auto=True)
            self.fpdf.header = self.doHead
            self.fpdf.add_page()
            self.fpdf.set_font("Courier","",9)
            cwth = self.fpdf.get_string_width("X")
            for num, rec in enumerate(recs):
                tab = CCD(rec[0], "UI", 6).disp
                self.fpdf.drawText(txt=tab, w=cwth*7, h=5, ln=0)
                nm = rec[1].strip()
                if rec[2]:
                    nm += ", %s" % rec[2].split()[0].upper()
                self.fpdf.drawText(txt=nm, w=cwth*31, h=5, ln=0)
                self.fpdf.drawText(txt=rec[3], w=cwth*16, h=5, ln=0)
                self.fpdf.drawText(txt=rec[4], w=cwth*41, h=5, ln=0)
                self.fpdf.drawText(txt=rec[5], w=cwth*2, h=5, ln=1)
            pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
                self.__class__.__name__, self.opts["conum"], ext="pdf")
            self.fpdf.output(pdfnam, "F")
            head = "%s - Entered Teams" % self.cnam
            doPrinter(mf=self.opts["mf"], conum=self.opts["conum"],
                pdfnam=pdfnam, header=head, repprt=self.df.repprt,
                fromad=self.fromad, repeml=self.df.repeml)
        self.opts["mf"].closeLoop()

    def doHead(self):
        if os.path.isfile(self.image):
            self.fpdf.image(self.image, 10, 10, 15, 11)
        self.fpdf.set_font("Arial","B",15)
        self.fpdf.cell(20)
        self.fpdf.cell(0,10,"Players Entered in the %s" % self.cnam,1,0,"C")
        self.fpdf.ln(20)
        self.fpdf.set_font("Courier","B",9)
        self.fpdf.cell(0, 5, "%-6s %-30s %-15s %-40s %1s" % \
            ("Number", "Name", "Mobile", "Email", "T"), "B")
        self.fpdf.ln(5)

    def doExit(self):
        self.df.closeProcess()
        self.opts["mf"].closeLoop()
コード例 #5
0
ファイル: bc3080.py プロジェクト: paulmalherbe/Tartan
class bc3080(object):
    def __init__(self, **opts):
        self.opts = opts
        if self.setVariables():
            if "args" in self.opts:
                self.ctyp = self.opts["args"][0]
                self.cnam = self.opts["args"][1]
                self.card = False
                self.qty = 1
                self.doEnd()
            else:
                self.mainProcess()
                if "wait" in self.opts:
                    self.df.mstFrame.wait_window()
                else:
                    self.opts["mf"].startLoop()

    def setVariables(self):
        self.sql = Sql(self.opts["mf"].dbm, ["bwlcmp", "bwltyp", "bwlpts",
            "bwlnot"], prog=self.__class__.__name__)
        if self.sql.error:
            return
        gc = GetCtl(self.opts["mf"])
        bwlctl = gc.getCtl("bwlctl", self.opts["conum"])
        if not bwlctl:
            return
        self.fromad = bwlctl["ctb_emadd"]
        t = time.localtime()
        self.sysdt = time.strftime("%d %B %Y %H:%M:%S", t)
        self.image = os.path.join(self.opts["mf"].rcdic["wrkdir"], "bowls.png")
        if not os.path.exists(self.image):
            getImage("bowls", fle=self.image)
        if not os.path.exists(self.image):
            self.image = None
        self.card = True
        return True

    def mainProcess(self):
        self.tit = ("%03i %s" % (self.opts["conum"], self.opts["conam"]),
            "Competition Format")
        com = {
            "stype": "R",
            "tables": ("bwlcmp",),
            "cols": (
                ("bcm_code", "", 0, "Cod"),
                ("bcm_name", "", 0, "Name", "Y"),
                ("bcm_date", "", 0, "Date")),
            "where": [("bcm_cono", "=", self.opts["conum"])]}
        r1s = (("A4 Page", "P"), ("A6 Card", "C"))
        fld = (
            (("T",0,0,0),"I@bcm_code",0,"","",
                "","Y",self.doCmpCod,com,None,("notzero",)),
            (("T",0,0,0),"ONA",30,""),
            (("T",0,1,0),"ITV",(50,10),"Notes","",
                "","N",self.doNotes,None,None,None,None,"""Enter All Additional Rules and Notes for the Competition e.g. what to do in these cases:

Trial Ends - Only 1 trial end per game.
Burnt Ends - Replay the end."""),
            (("T",0,2,0),("IRB",r1s),0,"Paper Type","",
                "P","N",self.doPaper,None,None,None),
            (("T",0,3,0),"IUI",2,"Quantity","",
                1,"N",self.doQty,None,None,("notzero",)))
        but = (("Edit Notes", None, self.doEdit, 0, ("T",0,4), ("T",0,5)),)
        tnd = ((self.doEnd,"y"),)
        txt = (self.doExit,)
        self.df = TartanDialog(self.opts["mf"], title=self.tit,
            eflds=fld, butt=but, tend=tnd, txit=txt, view=("N","V"),
            mail=("Y","N"))

    def doCmpCod(self, frt, pag, r, c, p, i, w):
        chk = self.sql.getRec("bwlcmp", cols=["bcm_name", "bcm_type"],
            where=[("bcm_cono", "=", self.opts["conum"]), ("bcm_code", "=", w)],
            limit=1)
        if not chk:
            return "Invalid Competition Code"
        self.ccod = w
        self.cnam = chk[0]
        self.ctyp = chk[1]
        self.df.loadEntry(frt, pag, p+1, data=self.cnam)
        nte = self.sql.getRec("bwlnot", where=[("bcn_cono", "=",
            self.opts["conum"]), ("bcn_ccod", "=", self.ccod)], limit=1)
        if nte:
            self.notes = nte[2]
            self.df.loadEntry(frt, pag, p+2, self.notes)
            return "sk2"

    def doEdit(self):
        self.df.focusField("T", 0, 3, tag=False)

    def doNotes(self, frt, pag, r, c, p, i, w):
        self.notes = w

    def doPaper(self, frt, pag, r, c, p, i, w):
        if w == "P":
            self.card = False
        else:
            self.card = True

    def doQty(self, frt, pag, r, c, p, i, w):
        self.qty = w

    def doEnd(self):
        if "args" not in self.opts:
            hdr = self.tit
            prt = copyList(self.df.repprt)
            eml = copyList(self.df.repeml)
            self.df.closeProcess()
        else:
            hdr = "%03i %s - %s" % (self.opts["conum"], self.opts["conam"],
            "Competition Format")
            prt = ["Y", "V", "view"]
            eml = None
        self.drawFormat()
        pdfnam = getModName(self.opts["mf"].rcdic["wrkdir"],
            self.__class__.__name__, self.opts["conum"], ext="pdf")
        self.fpdf.output(pdfnam, "F")
        doPrinter(mf=self.opts["mf"], pdfnam=pdfnam, header=hdr,
            repprt=prt, fromad=self.fromad, repeml=eml)
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()

    def drawFormat(self):
        whr = [
            ("bct_cono", "=", self.opts["conum"]),
            ("bct_code", "=", self.ctyp)]
        rec = self.sql.getRec("bwltyp", where=whr, limit=1)
        ldic = {}
        for col in self.sql.bwltyp_col[3:]:
            ldic[col] = rec[self.sql.bwltyp_col.index(col)]
        whr = [
            ("bcp_cono", "=", self.opts["conum"]),
            ("bcp_code", "=", self.ctyp)]
        rec = self.sql.getRec("bwlpts", where=whr)
        for r in rec:
            if r[self.sql.bwlpts_col.index("bcp_ptyp")] == "D":
                ptyp = "drawn"
            else:
                ptyp = "svs"
            ldic[ptyp] = {}
            for col in self.sql.bwlpts_col[3:]:
                ldic[ptyp][col] = r[self.sql.bwlpts_col.index(col)]
        if self.card:
            self.fpdf = MyFpdf(auto=True)
            self.fpdf.set_margins(55, 5, 55)
            self.fpdf.c_margin = self.fpdf.c_margin * 2
            self.fpdf.set_font("Arial","",8)
            h = 3.5
        else:
            self.fpdf = MyFpdf(auto=True)
            self.fpdf.set_font("Arial","",14)
            h = 6
        self.fpdf.header = self.pageHeading
        cwth = self.fpdf.get_string_width("X")
        x1 = self.fpdf.l_margin + (cwth * 20)
        x2 = self.fpdf.l_margin + (cwth * 22)
        for page in range(self.qty):
            self.fpdf.add_page()
            self.fpdf.drawText(txt=self.sql.bwltyp_dic["bct_cfmat"][4],
                h=h, ln=0)
            if ldic["bct_cfmat"] == "T":
                txt = "Tournament"
            elif ldic["bct_cfmat"] in ("D", "K"):
                txt = "Knockout"
            elif ldic["bct_cfmat"] == "R":
                txt = "Round Robin"
            else:
                txt = "Match"
            self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M")
            self.fpdf.drawText(txt=self.sql.bwltyp_dic["bct_tsize"][4],
                h=h, ln=0)
            self.fpdf.drawText(txt=ldic["bct_tsize"], x=x1, h=h, ctyp="M")
            #if ldic["bct_cfmat"] in ("D", "K", "R"):
            #    return
            self.fpdf.drawText(txt="Draw", h=h, ln=0)
            if ldic["bct_drawn"] == ldic["bct_games"]:
                txt = "All Games will be Random Draws."
            else:
                if ldic["bct_drawn"] == 1:
                    txt = "The First Game will be a Random Draw and "\
                        "thereafter Strength v Strength."
                else:
                    txt = "The First %s Games will be Random Draws and "\
                        "thereafter Strength v Strength." % ldic["bct_drawn"]
            self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M")
            if ldic["bct_games"]:
                self.fpdf.drawText(txt=self.sql.bwltyp_dic["bct_games"][4],
                    h=h, ln=0)
                self.fpdf.drawText(txt=ldic["bct_games"], x=x1, h=h, ctyp="M")
            self.fpdf.drawText(txt=self.sql.bwltyp_dic["bct_ends"][4],h=h,ln=0)
            self.fpdf.drawText(txt=ldic["bct_ends"], x=x1, h=h, ctyp="M")
            if ldic["bct_grgame"]:
                self.fpdf.drawText(txt="Groups", h=h, ln=0)
                txt = "Teams will be Split into Groups After Game %s." % \
                    ldic["bct_grgame"]
                self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M")
                if ldic["bct_adjust"] == "Y":
                    txt = "With the Exception of Group A, the Scores will be "\
                        "Adjusted as follows:"
                    self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M")
                    if ldic["bct_expunge"]:
                        gms = ldic["bct_expunge"].split(",")
                        if len(gms) == 1:
                            txt = "Game %s will be Expunged" % gms[0]
                        else:
                            txt = "Games %s" % gms[0]
                            for n, g in enumerate(gms[1:]):
                                if n == len(gms) - 2:
                                    txt = "%s and %s" % (txt, g)
                                else:
                                    txt = "%s, %s" % (txt, g)
                            txt = "%s will be Expunged." % txt
                        self.fpdf.drawText(txt=txt, x=x2, h=h, ctyp="M")
                    if ldic["bct_percent"]:
                        if ldic["bct_expunge"]:
                            txt = "The Balance of the Games"
                        else:
                            txt = "All Games"
                        txt = "%s will Retain %s%s of their score." % (txt,
                            ldic["bct_percent"], "%")
                        self.fpdf.drawText(txt=txt, x=x2, h=h, ctyp="M")
            # Points
            self.fpdf.drawText(h=h)
            if ldic["bct_pdiff"] == "Y":
                nums = ["drawn", "svs"]
            else:
                nums = ["drawn"]
            for ptyp in nums:
                if ldic["bct_pdiff"] == "N":
                    txt = "Scoring for All Games"
                elif ptyp == "drawn":
                    txt = "Scoring for Drawn Games"
                else:
                    txt = "Scoring for S v S Games"
                self.fpdf.drawText(txt=txt, h=h)
                self.fpdf.underLine(h=h, txt=txt)
                if ldic[ptyp]["bcp_sends"]:
                    self.fpdf.drawText(txt="Skins", h=h, ln=0)
                    self.fpdf.drawText(txt="Each Set of %s Ends will "\
                        "Constitute a Skin." % ldic[ptyp]["bcp_sends"], x=x1,
                        h=h, ctyp="M")
                self.fpdf.drawText(txt="Points", h=h, ln=0)
                txt = ""
                pts = 0
                if ldic[ptyp]["bcp_e_points"]:
                    if ldic[ptyp]["bcp_e_points"] == 1:
                        txt = "%s Point per End" % ldic[ptyp]["bcp_e_points"]
                    else:
                        txt = "%s Points per End" % ldic[ptyp]["bcp_e_points"]
                    self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M")
                    pts += (ldic[ptyp]["bcp_e_points"] * ldic["bct_ends"])
                if ldic[ptyp]["bcp_s_points"]:
                    if ldic[ptyp]["bcp_s_points"] == 1:
                        txt = "%s Point per Skin" % ldic[ptyp]["bcp_s_points"]
                    else:
                        txt = "%s Points per Skin" % ldic[ptyp]["bcp_s_points"]
                    self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M")
                    pts += (ldic[ptyp]["bcp_s_points"] *
                        int(ldic["bct_ends"] / ldic[ptyp]["bcp_sends"]))
                if ldic[ptyp]["bcp_g_points"]:
                    if ldic[ptyp]["bcp_g_points"] == 1:
                        txt = "%s Point per Game" % ldic[ptyp]["bcp_g_points"]
                    else:
                        txt = "%s Points per Game" % ldic[ptyp]["bcp_g_points"]
                    self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M")
                    pts += ldic[ptyp]["bcp_g_points"]
                if ldic[ptyp]["bcp_bonus"] == "Y":
                    txt = "1 Bonus Point will be Awarded as Follows:"
                    self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M")
                    txt = "Winning by %s or More Shots or" % \
                        (ldic[ptyp]["bcp_win_by"] + 1)
                    self.fpdf.drawText(txt=txt, x=x2, h=h, ctyp="M")
                    txt = "Losing by %s or Less Shots" % \
                        (ldic[ptyp]["bcp_lose_by"] - 1)
                    self.fpdf.drawText(txt=txt, x=x2, h=h, ctyp="M")
                    pts += 1
                if pts:
                    if pts == 1:
                        txt = "Point"
                    else:
                        txt = "Points"
                    txt = "Therefore a Maximum of %s %s per Game." % (pts, txt)
                    self.fpdf.drawText(txt=txt, x=x1, h=h, ctyp="M")
            if self.notes:
                txt = "Notes"
                self.fpdf.drawText(h=h)
                self.fpdf.drawText(txt=txt, h=h)
                self.fpdf.underLine(h=h, txt=txt)
                self.fpdf.drawText(txt=self.notes, h=h, ctyp="M")
                self.sql.delRec("bwlnot", where=[("bcn_cono", "=",
                    self.opts["conum"]), ("bcn_ccod", "=", self.ccod)])
                self.sql.insRec("bwlnot", data=[self.opts["conum"],
                    self.ccod, self.notes])
                self.opts["mf"].dbm.commitDbase()

    def pageHeading(self):
        if self.card:
            self.fpdf.set_fill_color(220)
            self.fpdf.set_font("Arial","B",12)
            self.fpdf.drawText("Competiton Format and Points", h=6, align="C",
                border="TLRB", fill=True)
            self.fpdf.set_line_width(1)
            self.fpdf.rect(self.fpdf.l_margin, self.fpdf.t_margin, 100, 140)
            self.fpdf.set_line_width(0)
            self.fpdf.ln(4)
            return
        if self.image:
            if self.card:
                self.fpdf.image(self.image, x=10, y=10, w=7, h=5)
            else:
                self.fpdf.image(self.image, x=10, y=10, w=15, h=11)
        self.fpdf.set_font("Arial","B",15)
        self.fpdf.cell(20)
        self.fpdf.cell(0,10,"Format Sheet for the %s" % self.cnam,1,0,"C")
        self.fpdf.ln(20)

    def doExit(self):
        self.df.closeProcess()
        if "wait" not in self.opts:
            self.opts["mf"].closeLoop()