Exemple #1
0
def details(regdent, trtdent, startdate, enddate, filters=""):
    '''
    returns an html table, for regdent, trtdent,startdate,enddate
    '''
    dent_conditions = ""
    dents = []
    try:
        if regdent != "*ALL*":
            dent_conditions = 'dntid=%s and '
            dents.append(localsettings.ops_reverse[regdent])
        if trtdent != "*ALL*":
            dent_conditions += 'trtid=%s and '
            dents.append(localsettings.ops_reverse[trtdent])
    except KeyError:
        print "Key Error - %s or %s unregconised" % (regdent, trtdent)
        return '<html><body>%s</body></html>' % _(
            "Error - unrecognised practioner- sorry")

    total, nettotal = 0, 0

    iterDate = QDate(startdate.year(), startdate.month(), 1)

    retarg = '''
    <html><body><h4>%s %s %s %s %s %s %s %s %s</h4>''' % (
        _("Patients of"), regdent, _("treated by"), trtdent, _("between"),
        localsettings.formatDate(startdate.toPyDate()), _("and"),
        localsettings.formatDate(enddate.toPyDate()), filters)

    retarg += '''<table width="100%" border="1"><tr><th>DATE</th>
    <th>Dents</th><th>Serial Number</th><th>Name</th>
    <th>Pt Type</th><th>Treatment</th><th></th>
    <th>Gross Fee</th><th>Net Fee</th>'''

    db = connect.connect()
    cursor = db.cursor()

    query = DETAILS_QUERY.replace("{{DENT CONDITIONS}}", dent_conditions)
    query = query.replace("{{FILTERS}}", filters)

    while enddate >= iterDate:
        monthtotal, monthnettotal = 0, 0

        if startdate > iterDate:
            queryStartDate = startdate
        else:
            queryStartDate = iterDate

        queryEndDate = iterDate.addMonths(1).addDays(-1)
        if enddate < queryEndDate:
            queryEndDate = enddate

        values = tuple(
            dents + [queryStartDate.toPyDate(), queryEndDate.toPyDate()])

        cursor.execute(query, (values))

        rows = cursor.fetchall()

        for i, row in enumerate(rows):
            retarg += '<tr>' if i % 2 else '<tr bgcolor="#eeeeee">'

            retarg += "<td>%s</td>" % row[0]
            try:
                retarg += '<td> %s / ' % localsettings.ops[row[4]]
            except KeyError:
                retarg += "<td>?? / "
            try:
                retarg += localsettings.ops[row[5]]
            except KeyError:
                retarg += "??"

            retarg += '</td><td>%s</td><td>%s</td><td>%s</td>' % (row[1:4])

            tx = ""
            for item in (6, 7, 8, 9, 10, 11, 12, 13, 14, 15):
                if row[item] is not None and row[item] != "":
                    tx += "%s " % row[item]

            if ALLOW_TX_EDITS:
                extra_link = ' / <a href="daybook_id_edit?%s">%s</a>' % (
                    row[19], _("Edit Tx"))
            else:
                extra_link = ""
            retarg += '''<td>%s</td>
            <td><a href="daybook_id?%sfeesa=%sfeesb=%s">%s</a>%s</td>
            <td align="right">%s</td>
            <td align="right">%s</td></tr>''' % (tx.strip("%s " % chr(0)),
                                                 row[19], row[16], row[17],
                                                 _("Ests"),
                                                 extra_link,
                                                 localsettings.formatMoney(
                                                 row[16]),
                                                 localsettings.formatMoney(row[17]))

            total += int(row[16])
            monthtotal += int(row[16])

            nettotal += int(row[17])
            monthnettotal += int(row[17])
        retarg += '''<tr><td colspan="6"></td><td><b>SUBTOTAL - %s %s</b></td>
        <td align="right"><b>%s</b></td>
        <td align="right"><b>%s</b></td></tr>''' % (
            localsettings.monthName(iterDate.toPyDate()),
            iterDate.year(),
            localsettings.formatMoney(monthtotal),
            localsettings.formatMoney(monthnettotal))
        iterDate = iterDate.addMonths(1)
    cursor.close()
    # db.close()

    retarg += '''<tr><td colspan="6"></td><td><b>GRAND TOTAL</b></td>
    <td align="right"><b>%s</b></td>
    <td align="right"><b>%s</b></td></tr></table></body></html>''' % (
        localsettings.formatMoney(total), localsettings.formatMoney(nettotal))

    return retarg
Exemple #2
0
    def paintEvent(self, event=None):
        '''
        draws the widget - recalled at any point by instance.update()
        '''
        self.setFont()
        self.setMinimumWidth(self.minimumWidth())
        painter = QtGui.QPainter(self)
        painter.setFont(self.font)

        rowHeight = self.height() / (self.rowNo)

        # HEADER ROW - the month and year, highlighted
        painter.setBrush(self.palette().highlight())
        rect = QtCore.QRectF(0, 0, self.width(), rowHeight)
        painter.drawRect(rect)
        painter.setPen(self.palette().color(self.palette().HighlightedText))
        self.font.setBold(True)
        painter.setFont(self.font)

        c_date = datetime.date(self.year, self.month, 1)
        my_text = "%s %s" % (localsettings.monthName(c_date), self.year)
        painter.drawText(rect, my_text, CENTRE)

        self.font.setBold(False)
        painter.setFont(self.font)

        for day in range(0, self.rowNo - 1):
            rect = QtCore.QRectF(0, (day + 1) * rowHeight, self.vheaderwidth,
                                 rowHeight)

            painter.setPen(self.palette().color(self.palette().WindowText))
            brush = self.palette().base()

            if day == 0:
                option = CENTRE
                my_text = _("DATE")
                c_date = datetime.date(1900, 1, 1)
                brush = self.palette().button()

            else:
                option = RIGHT
                c_date = datetime.date(self.year, self.month, day)
                my_text = "%s %2s " % (localsettings.dayName(c_date), day)

                brush = self.palette().base()
                if c_date.isoweekday() > 5:
                    brush = self.palette().alternateBase()
                if c_date == self.selectedDate:
                    brush = self.palette().highlight()
                elif c_date == self.highlightedDate:
                    brush = self.mouseBrush

            painter.setBrush(brush)

            painter.save()
            painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))
            painter.drawRect(rect)
            painter.restore()
            if c_date in (self.selectedDate, self.highlightedDate):
                painter.setPen(self.palette().color(
                               self.palette().HighlightedText))
                painter.drawText(rect, my_text, option)

            elif c_date.isoweekday() < 6:
                painter.setPen(self.palette().color(
                               self.palette().WindowText))
                painter.drawText(rect, my_text, option)

            else:
                painter.save()
                painter.setPen(QtCore.Qt.red)
                painter.drawText(rect, my_text, option)
                painter.restore()

            rect = rect.adjusted(self.vheaderwidth, 0, self.bankHolColwidth,
                                 0)

            painter.save()
            painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))
            painter.drawRect(rect)
            painter.restore()

            key = "%d%02d" % (self.month, day)
            if key in self.headingdata:
                my_text = str(self.headingdata.get(key))
                self.font.setItalic(True)
                painter.setFont(self.font)
                painter.drawText(rect, my_text, CENTRE)
                self.font.setItalic(False)
                painter.setFont(self.font)

            #- text column
            x = self.bankHolColwidth + self.vheaderwidth
            rect = rect.adjusted(self.bankHolColwidth, 0, 0, 0)

            for col in range(self.colNo):
                dentix = self.dents[col]
                my_text = ""

                colWidth = self.dentColWidths[dentix]
                rect = rect.adjusted(0, 0, colWidth, 0)

                painter.save()
                painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))
                painter.drawRect(rect)
                painter.restore()
                option = LEFT
                if day == 0:
                    my_text = "%s" % localsettings.apptix_reverse.get(dentix,
                                                                      "all")
                    option = CENTRE
                elif key in self.data:
                    dent = self.data[key].get(dentix)
                    if dent:
                        if dentix == 0:
                            my_text = dent.memo.upper()
                        else:
                            if not dent.flag:
                                times = ""
                            else:
                                times = "%s - %s " % (
                                    localsettings.wystimeToHumanTime(
                                        dent.start),
                                    localsettings.wystimeToHumanTime(dent.end))
                            my_text = "%s%s" % (times, dent.memo)

                if my_text:
                    painter.drawText(
                        rect.adjusted(2,
                                      0,
                                      0,
                                      0),
                        my_text,
                        option)

                rect = rect.adjusted(colWidth, 0, 0, 0)
        painter.setPen(QtGui.QColor("black"))

        painter.drawLine(self.bankHolColwidth + self.vheaderwidth, rowHeight,
                         self.bankHolColwidth + self.vheaderwidth, self.height())
Exemple #3
0
    def paintEvent(self, event=None):
        '''
        draws the widget - recalled at any point by instance.update()
        '''
        self.setFont()
        painter = QtGui.QPainter(self)
        painter.setFont(self.font)

        rowHeight = self.height() / 13

        self.columnWidth = (self.width() - self.vheaderwidth) / self.columnNo

        for month in range(13):
            rect = QtCore.QRectF(0, month * rowHeight, self.vheaderwidth,
                                 rowHeight)

            painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))

            if month == 0:
                #-- draw the year
                painter.setBrush(self.palette().highlight())
                painter.drawRect(rect)

                painter.setPen(self.palette().color(
                               self.palette().HighlightedText))
                painter.drawText(rect, QtCore.Qt.AlignCenter, str(self.year))

                # rectLeft = rect.adjusted(0, 0,-rect.width()/4, 0)
                # painter.drawPixmap(rectLeft, QtGui.QPixmap(":/back.png"))
                # return
                for col in range(self.columnNo):
                    rect = QtCore.QRectF(
                        self.vheaderwidth + col * self.columnWidth,
                        month * rowHeight, self.columnWidth, rowHeight)

                    painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))
                    painter.drawRect(rect)

                    dayno = col % 7
                    my_text = ("M", "Tu", "W", "Th", "F", "Sa", "Su")[dayno]

                    painter.setPen(self.palette().color(
                                   self.palette().HighlightedText))

                    painter.drawText(rect, QtCore.Qt.AlignCenter, my_text)

            else:
                if month % 2 == 0:
                    painter.setBrush(self.palette().base())
                else:
                    painter.setBrush(self.palette().alternateBase())

                painter.drawRect(rect)

                painter.setPen(self.palette().color(
                               self.palette().WindowText))

                c_date = datetime.date(self.year, month, 1)
                my_text = str(localsettings.monthName(c_date))
                painter.drawText(rect, QtCore.Qt.AlignCenter, my_text)
                startday = c_date.weekday()

                for col in range(self.columnNo):

                    rect = QtCore.QRectF(
                        self.vheaderwidth + col * self.columnWidth,
                        month * rowHeight, self.columnWidth, rowHeight)

                    painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))

                    painter.drawRect(rect)

                    painter.setPen(self.palette().color(
                                   self.palette().WindowText))

                    if col >= startday:
                        try:
                            c_date = datetime.date(self.year, month,
                                                   col - startday + 1)
                            my_text = str(c_date.day)

                            if c_date == self.selectedDate:
                                painter.save()
                                painter.setBrush(self.palette().color(
                                                 self.palette().Highlight))

                                painter.setPen(self.palette().color(
                                               self.palette().HighlightedText))

                                painter.drawRect(rect)
                                painter.drawText(rect,
                                                 QtCore.Qt.AlignCenter, my_text)

                                painter.restore()

                            elif c_date == self.highlightedDate:
                                #--mouseOver
                                painter.save()
                                painter.setBrush(self.mouseBrush)

                                painter.setPen(self.palette().color(
                                               self.palette().HighlightedText))

                                painter.drawRect(rect)
                                painter.drawText(rect,
                                                 QtCore.Qt.AlignCenter, my_text)

                                painter.restore()

                            elif c_date.isoweekday() > 5:
                                # weekend
                                painter.setPen(QtCore.Qt.red)
                                painter.drawText(rect,
                                                 QtCore.Qt.AlignCenter, my_text)

                            else:
                                painter.setPen(self.palette().color(
                                               self.palette().WindowText))
                                painter.drawText(rect,
                                                 QtCore.Qt.AlignCenter, my_text)

                            datekey = "%d%02d" % (month, c_date.day)

                            if datekey in self.headingdata:
                                #-- draw a gray underscore!
                                painter.save()
                                painter.setBrush(QtCore.Qt.lightGray)
                                painter.setPen(QtCore.Qt.lightGray)
                                rheight = rect.height() * 0.8

                                painter.drawRect(
                                    rect.adjusted(1, rheight, -1, 0))

                                painter.restore()

                            if self.flags.get(datekey, False):
                                #-- draw a blue triangle!
                                painter.save()
                                painter.setBrush(QtCore.Qt.blue)
                                painter.setPen(QtCore.Qt.blue)
                                topleftX = rect.topLeft().x() +\
                                    rect.width() / 2

                                topY = rect.topLeft().y() + 2
                                rightX = rect.topRight().x()
                                bottomrightY = rect.topRight().y() +\
                                    rect.width() / 2

                                shape = QtGui.QPolygon([topleftX, topY,
                                                        rightX, topY, rightX, bottomrightY])

                                painter.drawPolygon(shape)
                                painter.restore()

                        except ValueError:
                            # month doesn't have this day eg feb 30th
                            pass
Exemple #4
0
    def print_(self):
        dialog = QtGui.QPrintDialog(self.printer, self.om_gui)
        if not dialog.exec_():
            return

        font = QtGui.QFont("Helvetica", 11)
        fm = QtGui.QFontMetrics(font)
        line_height = fm.height()

        italic_font = QtGui.QFont(font)
        italic_font.setItalic(True)

        sigFont = QtGui.QFont("URW Chancery L", 18)
        sigFont.setBold(True)
        sig_font_height = QtGui.QFontMetrics(sigFont).height() * 1.2

        pageRect = self.printer.pageRect()

        LEFT = 60
        RIGHT = 80
        TOP = 170
        RECT_WIDTH = pageRect.width() - (LEFT + RIGHT)

        ADDRESS_LEFT = 80
        ADDRESS_HEIGHT = 140
        FOOTER_HEIGHT = 180
        DATE_HEIGHT = 2 * line_height
        BODY_HEIGHT = pageRect.height() - (
            TOP + ADDRESS_HEIGHT + FOOTER_HEIGHT + DATE_HEIGHT)

        addressRect = QtCore.QRectF(ADDRESS_LEFT, TOP,
                                    300, ADDRESS_HEIGHT)

        dateRect = QtCore.QRectF(LEFT, addressRect.bottom(),
                                 RECT_WIDTH, DATE_HEIGHT)

        bodyRect = QtCore.QRectF(LEFT, dateRect.bottom(),
                                 RECT_WIDTH, BODY_HEIGHT)

        footerRect = QtCore.QRectF(LEFT,
                                   pageRect.height() - FOOTER_HEIGHT,
                                   RECT_WIDTH, FOOTER_HEIGHT)

        painter = QtGui.QPainter(self.printer)

        first_page = True
        page_no = 0

        for letter in self.iterate_letters():
            page_no += 1

            if dialog.printRange() == dialog.PageRange:
                if page_no < dialog.fromPage():
                    continue
                if dialog.toPage() != 0 and page_no > dialog.toPage():
                    continue

            if not first_page:
                self.printer.newPage()
            first_page = False

            painter.save()
            painter.setFont(font)
            painter.setPen(QtCore.Qt.black)

            option = QtGui.QTextOption(QtCore.Qt.AlignLeft)
            option.setWrapMode(QtGui.QTextOption.WordWrap)

            # address
            painter.drawText(addressRect, letter.address, option)
            if DEBUG:
                painter.drawRect(addressRect.adjusted(2, 2, -2, -2))
            # date

            if self.use_given_recall_date:
                pdate = letter.recd
            else:
                pdate = self.adate

            if self.LONGDATE:
                pdate_str = localsettings.longDate(pdate)
            else:
                pdate_str = "%s %s" % (localsettings.monthName(pdate),
                                       pdate.year)

            painter.drawText(dateRect, pdate_str,
                             QtGui.QTextOption(QtCore.Qt.AlignRight))
            if DEBUG:
                painter.drawRect(dateRect.adjusted(2, 2, -2, -2))
            # salutation
            rect = bodyRect.adjusted(
                0, 0, 0, 2 * line_height - bodyRect.height())
            painter.drawText(rect, letter.salutation, option)
            if DEBUG:
                painter.drawRect(rect.adjusted(2, 2, -2, -2))

            # subject
            # option = QtGui.QTextOption(QtCore.Qt.AlignCenter)
            font.setBold(True)
            painter.setFont(font)
            subject_count = len(letter.subjects) + 1
            rect = QtCore.QRectF(
                rect.bottomLeft().x(), rect.bottomLeft().y(),
                bodyRect.width(), line_height * subject_count)

            subj_rect = rect.adjusted(50, 0, -50, 0)
            painter.drawText(subj_rect, letter.subject_text, option)
            if DEBUG:
                painter.drawRect(subj_rect.adjusted(2, 2, -2, -2))
            font.setBold(False)
            painter.setFont(font)

            # body
            line_count = letter.text.count("\n") + 3
            body_rect = QtCore.QRectF(
                rect.bottomLeft().x(), subj_rect.bottomLeft().y(),
                bodyRect.width(), line_height * line_count)

            painter.drawText(body_rect, letter.text, option)
            if DEBUG:
                painter.drawRect(body_rect.adjusted(2, 2, -2, -2))

            # custom
            line_count = CUSTOM_TEXT.count("\n") + 5
            custom_rect = QtCore.QRectF(
                body_rect.bottomLeft().x(), body_rect.bottomLeft().y(),
                bodyRect.width(), line_height * line_count)

            painter.setFont(font)
            painter.drawText(custom_rect, CUSTOM_TEXT, option)

            if DEBUG:
                painter.drawRect(custom_rect.adjusted(2, 2, -2, -2))

            # signature
            # place signature immediately after the body
            # + custom text (which will vary)

            sign_off_rect = QtCore.QRectF(
                custom_rect.bottomLeft().x(), custom_rect.bottomLeft().y(),
                body_rect.width(), line_height * 1.5)
            painter.drawText(sign_off_rect, SIGN_OFF, option)
            if DEBUG:
                painter.drawRect(sign_off_rect.adjusted(2, 2, -2, -2))

            sig_rect = sign_off_rect.adjusted(
                20, sign_off_rect.height(), 0, sig_font_height)
            painter.save()
            painter.setFont(sigFont)
            painter.drawText(sig_rect, localsettings.PRACTICE_NAME, option)
            if DEBUG:
                painter.drawRect(sig_rect.adjusted(2, 2, -2, -2))
            painter.restore()

            # ps
            line_count = PS_TEXT.count("\n") + 2
            ps_rect = QtCore.QRectF(
                body_rect.bottomLeft().x(),
                sig_rect.bottomLeft().y() + line_height*2,
                bodyRect.width(), line_height * line_count)

            painter.setFont(font)
            painter.drawText(ps_rect, PS_TEXT, option)

            if DEBUG:
                painter.drawRect(ps_rect.adjusted(2, 2, -2, -2))

            # footer
            option = QtGui.QTextOption(QtCore.Qt.AlignHCenter)
            option.setWrapMode(QtGui.QTextOption.WordWrap)

            painter.drawLine(footerRect.topLeft(), footerRect.topRight())
            painter.setFont(italic_font)

            painter.drawText(footerRect, FOOTER, option)
            if DEBUG:
                painter.drawRect(footerRect.adjusted(2, 2, -2, -2))

            # fold marks
            pen = QtGui.QPen(QtGui.QBrush(QtCore.Qt.black), 3)
            painter.setPen(pen)
            top_fold_y = pageRect.height() / 3
            painter.drawLine(0, top_fold_y, 10, top_fold_y)

            top_fold_y = pageRect.height() * 2 / 3
            painter.drawLine(0, top_fold_y, 10, top_fold_y)

            painter.restore()
Exemple #5
0
def details(regdent, trtdent, startdate, enddate):
    '''
    returns an html table, for regdent, trtdent,startdate,enddate
    '''
    cond1, cond2 = "", ""
    try:
        if regdent != "*ALL*":
            cond1 = 'dntid=%s and' % localsettings.ops_reverse[regdent]
        if trtdent != "*ALL*":
            cond2 = 'trtid=%s and' % localsettings.ops_reverse[trtdent]
    except KeyError:
        print "Key Error - %s or %s unregconised" % (regdent, trtdent)
        return '<html><body>%s</body></html>' % _(
            "Error - unrecognised practioner- sorry")

    total, nettotal = 0, 0

    iterDate = QDate(startdate.year(), startdate.month(), 1)

    db = connect()
    cursor = db.cursor()
    retarg = '''<html><body>
    <h3>Patients of %s treated by %s between %s and %s (inclusive)</h3>''' % (
        regdent, trtdent,
        localsettings.formatDate(startdate.toPyDate()),
        localsettings.formatDate(enddate.toPyDate()))

    retarg += '''<table width="100%" border="1"><tr><th>DATE</th>
    <th>Dents</th><th>Serial Number</th><th>Name</th>
    <th>Pt Type</th><th>Treatment</th><th>Gross Fee</th><th>Net Fee</th>'''

    while enddate >= iterDate:
        monthtotal, monthnettotal = 0, 0

        if startdate > iterDate:
            queryStartDate = startdate
        else:
            queryStartDate = iterDate

        queryEndDate = iterDate.addMonths(1).addDays(-1)
        if enddate < queryEndDate:
            queryEndDate = enddate

        #-- note - mysqldb doesn't play nice with DATE_FORMAT
        #-- hence the string is formatted entirely using python formatting
        query = '''select DATE_FORMAT(date,'%s'), serialno, coursetype, dntid,
        trtid, diagn, perio, anaes, misc, ndu, ndl, odu, odl, other, chart,
        feesa, feesb, feesc, id from daybook
        where %s %s date >= '%s' and date <= '%s' order by date''' % (
            localsettings.OM_DATE_FORMAT, cond1, cond2,
            queryStartDate.toPyDate(), queryEndDate.toPyDate())

        cursor.execute(query)

        rows = cursor.fetchall()

        odd = True
        for row in rows:
            if odd:
                retarg += '<tr bgcolor="#eeeeee">'
                odd = False
            else:
                retarg += '<tr>'
                odd = True
            retarg += "<td>'%s' %s</td>" % (row[18], row[0])
            try:
                retarg += '<td> %s / ' % localsettings.ops[row[3]]
            except KeyError:
                retarg += "<td>?? / "
            try:
                retarg += localsettings.ops[row[4]]
            except KeyError:
                retarg += "??"

            retarg += '</td><td>%s</td>' % row[1]

            cursor.execute(
                'select fname,sname from patients where serialno=%s' % row[1])

            names = cursor.fetchall()
            if names != ():
                name = names[0]
                retarg += '<td>%s %s</td>' % (name[0].title(), name[1].title())
            else:
                retarg += "<td>NOT FOUND</td>"
            retarg += '<td>%s</td>' % row[2]

            tx = ""
            for item in (5, 6, 7, 8, 9, 10, 11, 12, 13, 14):
                if row[item] is not None and row[item] != "":
                    tx += "%s " % row[item]

            retarg += '''<td>%s</td><td align="right">%s</td>
            <td align="right">%s</td></tr>''' % (tx.strip("%s " % chr(0)),
                                                 localsettings.formatMoney(
                                                 row[15]),
                                                 localsettings.formatMoney(row[16]))

            total += int(row[15])
            monthtotal += int(row[15])

            nettotal += int(row[16])
            monthnettotal += int(row[16])
        retarg += '''<tr><td colspan="5"></td><td><b>%s TOTAL</b></td>
        <td align="right"><b>%s</b></td>
        <td align="right"><b>%s</b></td></tr>''' % (
            localsettings.monthName(iterDate.toPyDate()),
            localsettings.formatMoney(monthtotal),
            localsettings.formatMoney(monthnettotal))
        iterDate = iterDate.addMonths(1)
    cursor.close()
    # db.close()

    retarg += '''<tr><td colspan="5"></td><td><b>GRAND TOTAL</b></td>
    <td align="right"><b>%s</b></td>
    <td align="right"><b>%s</b></td></tr></table></body></html>''' % (
        localsettings.formatMoney(total), localsettings.formatMoney(nettotal))

    return retarg
Exemple #6
0
    def paintEvent(self, event=None):
        '''
        draws the widget - recalled at any point by instance.update()
        '''
        self.setFont()
        painter = QtGui.QPainter(self)
        painter.setFont(self.font)

        rowHeight = self.height() / 13

        self.columnWidth = (self.width() - self.vheaderwidth) / self.columnNo

        for month in range(13):
            rect = QtCore.QRectF(0, month * rowHeight, self.vheaderwidth,
                                 rowHeight)

            painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))

            if month == 0:
                # draw the year
                painter.setBrush(self.palette().highlight())
                painter.drawRect(rect)

                painter.setPen(self.palette().color(
                    self.palette().HighlightedText))
                painter.drawText(rect, QtCore.Qt.AlignCenter, str(self.year))

                # rectLeft = rect.adjusted(0, 0,-rect.width()/4, 0)
                # painter.drawPixmap(rectLeft, QtGui.QPixmap(":/back.png"))
                # return
                for col in range(self.columnNo):
                    rect = QtCore.QRectF(
                        self.vheaderwidth + col * self.columnWidth,
                        month * rowHeight, self.columnWidth, rowHeight)

                    painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))
                    painter.drawRect(rect)

                    dayno = col % 7
                    my_text = ("M", "Tu", "W", "Th", "F", "Sa", "Su")[dayno]

                    painter.setPen(self.palette().color(
                        self.palette().HighlightedText))

                    painter.drawText(rect, QtCore.Qt.AlignCenter, my_text)

            else:
                if month % 2 == 0:
                    painter.setBrush(self.palette().base())
                else:
                    painter.setBrush(self.palette().alternateBase())

                painter.drawRect(rect)

                painter.setPen(self.palette().color(self.palette().WindowText))

                c_date = datetime.date(self.year, month, 1)
                my_text = str(localsettings.monthName(c_date))
                painter.drawText(rect, QtCore.Qt.AlignCenter, my_text)
                startday = c_date.weekday()

                for col in range(self.columnNo):

                    rect = QtCore.QRectF(
                        self.vheaderwidth + col * self.columnWidth,
                        month * rowHeight, self.columnWidth, rowHeight)

                    painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))

                    painter.drawRect(rect)

                    painter.setPen(self.palette().color(
                        self.palette().WindowText))

                    if col >= startday:
                        try:
                            c_date = datetime.date(self.year, month,
                                                   col - startday + 1)
                            my_text = str(c_date.day)

                            if c_date == self.selectedDate:
                                painter.save()
                                painter.setBrush(self.palette().color(
                                    self.palette().Highlight))

                                painter.setPen(self.palette().color(
                                    self.palette().HighlightedText))

                                painter.drawRect(rect)
                                painter.drawText(rect, QtCore.Qt.AlignCenter,
                                                 my_text)

                                painter.restore()

                            elif c_date == self.highlightedDate:
                                # mouseOver
                                painter.save()
                                painter.setBrush(self.mouseBrush)

                                painter.setPen(self.palette().color(
                                    self.palette().HighlightedText))

                                painter.drawRect(rect)
                                painter.drawText(rect, QtCore.Qt.AlignCenter,
                                                 my_text)

                                painter.restore()

                            elif c_date.isoweekday() > 5:
                                # weekend
                                painter.setPen(QtCore.Qt.red)
                                painter.drawText(rect, QtCore.Qt.AlignCenter,
                                                 my_text)

                            else:
                                painter.setPen(self.palette().color(
                                    self.palette().WindowText))
                                painter.drawText(rect, QtCore.Qt.AlignCenter,
                                                 my_text)

                            datekey = "%d%02d" % (month, c_date.day)

                            if datekey in self.headingdata:
                                # draw a gray underscore!
                                painter.save()
                                painter.setBrush(QtCore.Qt.lightGray)
                                painter.setPen(QtCore.Qt.lightGray)
                                rheight = rect.height() * 0.8

                                painter.drawRect(
                                    rect.adjusted(1, rheight, -1, 0))

                                painter.restore()

                            if self.flags.get(datekey, False):
                                # draw a blue triangle!
                                painter.save()
                                painter.setBrush(QtCore.Qt.blue)
                                painter.setPen(QtCore.Qt.blue)
                                topleftX = rect.topLeft().x() +\
                                    rect.width() / 2

                                topY = rect.topLeft().y() + 2
                                rightX = rect.topRight().x()
                                bottomrightY = rect.topRight().y() +\
                                    rect.width() / 2

                                shape = QtGui.QPolygon()
                                shape.setPoints([
                                    topleftX, topY, rightX, topY, rightX,
                                    bottomrightY
                                ])

                                painter.drawPolygon(shape)
                                painter.restore()

                        except ValueError:
                            # month doesn't have this day eg feb 30th
                            pass
Exemple #7
0
    def paintEvent(self, event=None):
        '''
        draws the widget - recalled at any point by instance.update()
        '''
        self.setFont()
        self.setMinimumWidth(self.minimumWidth())
        painter = QtGui.QPainter(self)
        painter.setFont(self.font)

        rowHeight = self.height() / (self.rowNo)

        # HEADER ROW - the month and year, highlighted
        painter.setBrush(self.palette().highlight())
        rect = QtCore.QRectF(0, 0, self.width(), rowHeight)
        painter.drawRect(rect)
        painter.setPen(self.palette().color(self.palette().HighlightedText))
        self.font.setBold(True)
        painter.setFont(self.font)

        c_date = datetime.date(self.year, self.month, 1)
        my_text = "%s %s" % (localsettings.monthName(c_date), self.year)
        painter.drawText(rect, my_text, CENTRE)

        self.font.setBold(False)
        painter.setFont(self.font)

        for day in range(0, self.rowNo - 1):
            rect = QtCore.QRectF(0, (day + 1) * rowHeight, self.vheaderwidth,
                                 rowHeight)

            painter.setPen(self.palette().color(self.palette().WindowText))
            brush = self.palette().base()

            if day == 0:
                option = CENTRE
                my_text = _("DATE")
                c_date = datetime.date(1900, 1, 1)
                brush = self.palette().button()

            else:
                option = RIGHT
                c_date = datetime.date(self.year, self.month, day)
                my_text = "%s %2s " % (localsettings.dayName(c_date), day)

                brush = self.palette().base()
                if c_date.isoweekday() > 5:
                    brush = self.palette().alternateBase()
                if c_date == self.selectedDate:
                    brush = self.palette().highlight()
                elif c_date == self.highlightedDate:
                    brush = self.mouseBrush

            painter.setBrush(brush)

            painter.save()
            painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))
            painter.drawRect(rect)
            painter.restore()
            if c_date in (self.selectedDate, self.highlightedDate):
                painter.setPen(self.palette().color(
                    self.palette().HighlightedText))
                painter.drawText(rect, my_text, option)

            elif c_date.isoweekday() < 6:
                painter.setPen(self.palette().color(self.palette().WindowText))
                painter.drawText(rect, my_text, option)

            else:
                painter.save()
                painter.setPen(QtCore.Qt.red)
                painter.drawText(rect, my_text, option)
                painter.restore()

            rect = rect.adjusted(self.vheaderwidth, 0, self.bankHolColwidth, 0)

            painter.save()
            painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))
            painter.drawRect(rect)
            painter.restore()

            key = "%d%02d" % (self.month, day)
            if key in self.headingdata:
                my_text = str(self.headingdata.get(key))
                self.font.setItalic(True)
                painter.setFont(self.font)
                painter.drawText(rect, my_text, CENTRE)
                self.font.setItalic(False)
                painter.setFont(self.font)

            # text column
            rect = rect.adjusted(self.bankHolColwidth, 0, 0, 0)

            for col in range(self.colNo):
                dentix = self.dents[col]
                my_text = ""

                colWidth = self.dentColWidths[dentix]
                rect = rect.adjusted(0, 0, colWidth, 0)

                painter.save()
                painter.setPen(QtGui.QPen(QtCore.Qt.gray, 1))
                painter.drawRect(rect)
                painter.restore()
                option = LEFT
                if day == 0:
                    my_text = "%s" % localsettings.apptix_reverse.get(
                        dentix, "all")
                    option = CENTRE
                elif key in self.data:
                    dent = self.data[key].get(dentix)
                    if dent:
                        if dentix == 0:
                            my_text = dent.memo.upper()
                        else:
                            if not dent.flag:
                                times = ""
                            else:
                                times = "%s - %s " % (
                                    localsettings.wystimeToHumanTime(
                                        dent.start),
                                    localsettings.wystimeToHumanTime(dent.end))
                            my_text = "%s%s" % (times, dent.memo)

                if my_text:
                    painter.drawText(rect.adjusted(2, 0, 0, 0), my_text,
                                     option)

                rect = rect.adjusted(colWidth, 0, 0, 0)
        painter.setPen(QtGui.QColor("black"))

        painter.drawLine(self.bankHolColwidth + self.vheaderwidth,
                         rowHeight, self.bankHolColwidth + self.vheaderwidth,
                         self.height())
Exemple #8
0
    def print_(self):
        dialog = QtGui.QPrintDialog(self.printer, self.om_gui)
        if not dialog.exec_():
            return

        font = QtGui.QFont("Helvetica", 11)
        fm = QtGui.QFontMetrics(font)
        line_height = fm.height()

        italic_font = QtGui.QFont(font)
        italic_font.setItalic(True)

        sigFont = QtGui.QFont("URW Chancery L", 18)
        sigFont.setBold(True)
        sig_font_height = QtGui.QFontMetrics(sigFont).height() * 1.2

        pageRect = self.printer.pageRect()

        LEFT = 60
        RIGHT = 80
        TOP = 170
        RECT_WIDTH = pageRect.width() - (LEFT + RIGHT)

        ADDRESS_LEFT = 80
        ADDRESS_HEIGHT = 140
        FOOTER_HEIGHT = 180
        DATE_HEIGHT = 2 * line_height
        BODY_HEIGHT = pageRect.height() - (TOP + ADDRESS_HEIGHT +
                                           FOOTER_HEIGHT + DATE_HEIGHT)

        addressRect = QtCore.QRectF(ADDRESS_LEFT, TOP, 300, ADDRESS_HEIGHT)

        dateRect = QtCore.QRectF(LEFT, addressRect.bottom(), RECT_WIDTH,
                                 DATE_HEIGHT)

        bodyRect = QtCore.QRectF(LEFT, dateRect.bottom(), RECT_WIDTH,
                                 BODY_HEIGHT)

        footerRect = QtCore.QRectF(LEFT,
                                   pageRect.height() - FOOTER_HEIGHT,
                                   RECT_WIDTH, FOOTER_HEIGHT)

        painter = QtGui.QPainter(self.printer)

        first_page = True
        page_no = 0

        for letter in self.iterate_letters():
            page_no += 1

            if dialog.printRange() == dialog.PageRange:
                if page_no < dialog.fromPage():
                    continue
                if dialog.toPage() != 0 and page_no > dialog.toPage():
                    continue

            if not first_page:
                self.printer.newPage()
            first_page = False

            painter.save()
            painter.setFont(font)
            painter.setPen(QtCore.Qt.black)

            option = QtGui.QTextOption(QtCore.Qt.AlignLeft)
            option.setWrapMode(QtGui.QTextOption.WordWrap)

            # address
            painter.drawText(addressRect, letter.address, option)
            if DEBUG:
                painter.drawRect(addressRect.adjusted(2, 2, -2, -2))
            # date

            if self.use_given_recall_date:
                pdate = letter.recd
            else:
                pdate = self.adate

            if self.LONGDATE:
                pdate_str = localsettings.longDate(pdate)
            else:
                pdate_str = "%s %s" % (localsettings.monthName(pdate),
                                       pdate.year)

            painter.drawText(dateRect, pdate_str,
                             QtGui.QTextOption(QtCore.Qt.AlignRight))
            if DEBUG:
                painter.drawRect(dateRect.adjusted(2, 2, -2, -2))
            # salutation
            rect = bodyRect.adjusted(0, 0, 0,
                                     2 * line_height - bodyRect.height())
            painter.drawText(rect, letter.salutation, option)
            if DEBUG:
                painter.drawRect(rect.adjusted(2, 2, -2, -2))

            # subject
            # option = QtGui.QTextOption(QtCore.Qt.AlignCenter)
            font.setBold(True)
            painter.setFont(font)
            subject_count = len(letter.subjects) + 1
            rect = QtCore.QRectF(rect.bottomLeft().x(),
                                 rect.bottomLeft().y(), bodyRect.width(),
                                 line_height * subject_count)

            subj_rect = rect.adjusted(50, 0, -50, 0)
            painter.drawText(subj_rect, letter.subject_text, option)
            if DEBUG:
                painter.drawRect(subj_rect.adjusted(2, 2, -2, -2))
            font.setBold(False)
            painter.setFont(font)

            # body
            line_count = letter.text.count("\n") + 3
            body_rect = QtCore.QRectF(rect.bottomLeft().x(),
                                      subj_rect.bottomLeft().y(),
                                      bodyRect.width(),
                                      line_height * line_count)

            painter.drawText(body_rect, letter.text, option)
            if DEBUG:
                painter.drawRect(body_rect.adjusted(2, 2, -2, -2))

            # custom
            line_count = CUSTOM_TEXT.count("\n") + 5
            custom_rect = QtCore.QRectF(body_rect.bottomLeft().x(),
                                        body_rect.bottomLeft().y(),
                                        bodyRect.width(),
                                        line_height * line_count)

            painter.setFont(font)
            painter.drawText(custom_rect, CUSTOM_TEXT, option)

            if DEBUG:
                painter.drawRect(custom_rect.adjusted(2, 2, -2, -2))

            # signature
            # place signature immediately after the body
            # + custom text (which will vary)

            sign_off_rect = QtCore.QRectF(custom_rect.bottomLeft().x(),
                                          custom_rect.bottomLeft().y(),
                                          body_rect.width(), line_height * 1.5)
            painter.drawText(sign_off_rect, SIGN_OFF, option)
            if DEBUG:
                painter.drawRect(sign_off_rect.adjusted(2, 2, -2, -2))

            sig_rect = sign_off_rect.adjusted(20, sign_off_rect.height(), 0,
                                              sig_font_height)
            painter.save()
            painter.setFont(sigFont)
            painter.drawText(sig_rect, localsettings.PRACTICE_NAME, option)
            if DEBUG:
                painter.drawRect(sig_rect.adjusted(2, 2, -2, -2))
            painter.restore()

            # ps
            line_count = PS_TEXT.count("\n") + 2
            ps_rect = QtCore.QRectF(
                body_rect.bottomLeft().x(),
                sig_rect.bottomLeft().y() + line_height * 2, bodyRect.width(),
                line_height * line_count)

            painter.setFont(font)
            painter.drawText(ps_rect, PS_TEXT, option)

            if DEBUG:
                painter.drawRect(ps_rect.adjusted(2, 2, -2, -2))

            # footer
            option = QtGui.QTextOption(QtCore.Qt.AlignHCenter)
            option.setWrapMode(QtGui.QTextOption.WordWrap)

            painter.drawLine(footerRect.topLeft(), footerRect.topRight())
            painter.setFont(italic_font)

            painter.drawText(footerRect, FOOTER, option)
            if DEBUG:
                painter.drawRect(footerRect.adjusted(2, 2, -2, -2))

            # fold marks
            pen = QtGui.QPen(QtGui.QBrush(QtCore.Qt.black), 3)
            painter.setPen(pen)
            top_fold_y = pageRect.height() / 3
            painter.drawLine(0, top_fold_y, 10, top_fold_y)

            top_fold_y = pageRect.height() * 2 / 3
            painter.drawLine(0, top_fold_y, 10, top_fold_y)

            painter.restore()