def print_(self): dialog = QtPrintSupport.QPrintDialog(self.printer, self.parent) if not dialog.exec_(): return self.printer.setPaperSize(QtPrintSupport.QPrinter.A5) painter = QtGui.QPainter(self.printer) pageRect = self.printer.pageRect() painter.setPen(QtCore.Qt.black) font = QtGui.QFont("Times", 11) fm = QtGui.QFontMetrics(font) fontLineHeight = fm.height() painter.setFont(font) rect = QtCore.QRectF(pageRect.width() / 6, pageRect.height() / 20, pageRect.width() * 5 / 6, pageRect.height() / 3) text = "%s %s %s\n%s\n" % (self.pt.title, self.pt.fname, self.pt.sname, self.pt.address) text += "Our ref %d\n\n" % self.pt.serialno painter.drawText(rect, text) option = QtGui.QTextOption(QtCore.Qt.AlignCenter) option.setWrapMode(QtGui.QTextOption.WordWrap) y = pageRect.height() / 3 painter.drawLine(0, int(y), int(pageRect.width()), int(y)) y += fontLineHeight * 1.5 font.setBold(True) painter.setFont(font) rect = QtCore.QRectF(0, y, pageRect.width(), fontLineHeight * 1.5) painter.drawText(rect, "You have the following appointments with us", option) font.setBold(False) painter.setFont(font) for appt in self.appts: y += fontLineHeight * 1.5 atime = localsettings.wystimeToHumanTime(appt.atime) adate = localsettings.longDate(appt.date) text = "%s - %s with %s" % (atime, adate, appt.dent_inits) rect = QtCore.QRectF(0, y, pageRect.width(), fontLineHeight * 1.5) painter.drawText(rect, text, option) y = pageRect.height() * 2 / 3 painter.drawLine(0, int(y), int(pageRect.width()), int(y)) font.setItalic(True) painter.setFont(font) rect = QtCore.QRectF(0, y, pageRect.width(), pageRect.height() * 1 / 3) painter.drawText(rect, localsettings.APPOINTMENT_CARD_FOOTER, option)
def print_(self): dialog = QtGui.QPrintDialog(self.printer) if not dialog.exec_(): return self.printer.setPaperSize(QtGui.QPrinter.A5) painter = QtGui.QPainter(self.printer) pageRect = self.printer.pageRect() painter.setPen(QtCore.Qt.black) font = QtGui.QFont("Times", 11) fm = QtGui.QFontMetrics(font) fontLineHeight = fm.height() painter.setFont(font) rect = QtCore.QRectF(pageRect.width()/6, pageRect.height()/20, pageRect.width()*5/6, pageRect.height()/3) text = "%s %s %s\n%s\n"%( self.pt.title, self.pt.fname, self.pt.sname, self.pt.address) text += "Our ref %d\n\n"% self.pt.serialno painter.drawText(rect, text) option = QtGui.QTextOption(QtCore.Qt.AlignCenter) option.setWrapMode(QtGui.QTextOption.WordWrap) y = pageRect.height()/3 painter.drawLine(0,int(y),int(pageRect.width()),int(y)) y += fontLineHeight*1.5 font.setBold(True) painter.setFont(font) rect = QtCore.QRectF(0, y, pageRect.width(), fontLineHeight*1.5) painter.drawText(rect, "You have the following appointments with us", option) font.setBold(False) painter.setFont(font) for appt in self.appts: y += fontLineHeight*1.5 atime = localsettings.wystimeToHumanTime(appt.atime) adate = localsettings.longDate(appt.date) text = "%s - %s with %s"%(atime, adate, appt.dent_inits) rect = QtCore.QRectF(0, y, pageRect.width(), fontLineHeight*1.5) painter.drawText(rect, text, option) y = pageRect.height() *2/3 painter.drawLine(0,int(y),int(pageRect.width()),int(y)) font.setItalic(True) painter.setFont(font) rect = QtCore.QRectF(0, y, pageRect.width(), pageRect.height()*1/3) painter.drawText(rect, localsettings.APPOINTMENT_CARD_FOOTER, option)
def getHtml(description, pt): ''' get the HTML for a letter to referral_centre identified by description about this pt ''' db = connect() cursor = db.cursor() cursor.execute(ADDRESS_QUERY, (description, )) row = cursor.fetchone() cursor.close() if not row: return HTML greeting, addr1, addr2, addr3, addr4, addr5, addr6, addr7 = row tel = _("Telephone") + " :- " for i, val in enumerate((pt.tel1, pt.tel2, pt.mobile)): if val != "": tel += "%s %s " % ((_("home"), _("work "), _("mobile "))[i], val) return HTML % ("<br />".join([ a for a in (addr1, addr2, addr3, addr4, addr5, addr6, addr7) if a != "" ]), localsettings.longDate(localsettings.currentDay()), greeting, pt.title.title(), pt.fname.title(), pt.sname.title(), _("D.O.B."), localsettings.formatDate(pt.dob), ",".join([ a for a in (pt.addr1, pt.addr2, pt.addr3, pt.town, pt.county, pt.pcde) if a != "" ]), tel, _("Yours Sincerely"))
def getHtml(description, pt): """ get the HTML for a letter to referral_centre identified by description about this pt """ db = connect() cursor = db.cursor() cursor.execute(ADDRESS_QUERY, (description,)) row = cursor.fetchone() cursor.close() if not row: return HTML greeting, addr1, addr2, addr3, addr4, addr5, addr6, addr7 = row tel = _("Telephone") + " :- " for i, val in enumerate((pt.tel1, pt.tel2, pt.mobile)): if val != "": tel += "%s %s " % ((_("home"), _("work "), _("mobile "))[i], val) return HTML % ( "<br />".join([a for a in (addr1, addr2, addr3, addr4, addr5, addr6, addr7) if a != ""]), localsettings.longDate(localsettings.currentDay()), greeting, pt.title.title(), pt.fname.title(), pt.sname.title(), _("D.O.B."), localsettings.formatDate(pt.dob), ",".join([a for a in (pt.addr1, pt.addr2, pt.addr3, pt.town, pt.county, pt.pcde) if a != ""]), tel, _("Yours Sincerely"), )
def getHtml(pt): return TEMPLATE % (pt.name, pt.address.replace("\n", "<br />"), localsettings.longDate(localsettings.currentDay()), _("Dear"), pt.name.title(), _("Yours Sincerely") )
def raisememoDialog(parent): ''' allow user to input a memo ''' Dialog = QtGui.QDialog(parent) dl = Ui_editmemos.Ui_Dialog() dl.setupUi(Dialog) d = parent.selectedDate header_text = "%s" % localsettings.longDate(d) datekey = "%d%02d" % (d.month, d.day) if datekey in parent.headingdata: header_text += "<br>%s" % parent.headingdata[datekey] dl.label.setText(header_text) dl.layout = QtGui.QVBoxLayout(dl.scrollArea) dl.layout.setSpacing(0) key = "%d%02d" % (parent.selectedDate.month, parent.selectedDate.day) memoDict = {} if key in parent.data: memoDict = parent.data[key] memowidget_dict = {} for dentix in parent.dents: if dentix in memoDict: memo = memoDict[dentix].memo else: memo = "" if dentix == 0: dl.lineEdit.setText(memo) memowidget_dict[0] = dl.lineEdit else: widg = QtGui.QWidget() memoitem = Ui_memo_item.Ui_Form() memoitem.setupUi(widg) memoitem.label.setText( localsettings.apptix_reverse.get(dentix, "??")) memoitem.lineEdit.setText(memo) dl.layout.addWidget(widg) memowidget_dict[dentix] = memoitem.lineEdit spacerItem = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) dl.layout.addItem(spacerItem) if Dialog.exec_(): retarg = [] memo = str(dl.lineEdit.text().toAscii()) for dent in parent.dents: memo = str(memowidget_dict[dent].text().toAscii()) if memo != memoDict.get(dent, ""): retarg.append((dent, memo),) # print retarg parent.emit(QtCore.SIGNAL("add_memo"), tuple(retarg))
def __init__(self, date_, parent=None): ExtendableDialog.__init__(self, parent, remove_stretch=True) self.date = date_ label = WarningLabel( "%s %s" % (_("Edit Memos for"), localsettings.longDate(date_)) ) self.bank_hol_label = QtGui.QLabel("") font = self.font() font.setBold(True) font.setItalic(True) self.bank_hol_label.setFont(font) self.bank_hol_label.setAlignment(QtCore.Qt.AlignCenter) self.bank_hol_label.hide() self.global_lineedit = QtGui.QLineEdit() frame = QtGui.QFrame() form_layout = QtGui.QFormLayout(frame) form_layout.addRow(_("Global Memo"), self.global_lineedit) frame2 = QtGui.QFrame() form_layout = QtGui.QFormLayout(frame2) self.le_dict = {} for apptix in localsettings.activedent_ixs + localsettings.activehyg_ixs: le = QtGui.QLineEdit() form_layout.addRow(localsettings.apptix_reverse.get(apptix), le) self.le_dict[apptix] = le scroll_area = QtGui.QScrollArea() scroll_area.setWidget(frame2) scroll_area.setWidgetResizable(True) clinician_groupbox = QtGui.QGroupBox() clinician_groupbox.setTitle(_("Clinician Memos")) layout = QtGui.QVBoxLayout(clinician_groupbox) layout.addWidget(scroll_area) self.public_holiday_le = QtGui.QLineEdit() public_holiday_widget = QtGui.QFrame() form_layout = QtGui.QFormLayout(public_holiday_widget) form_layout.addRow(_("Public Holiday Text"), self.public_holiday_le) self.add_advanced_widget(public_holiday_widget) self.set_advanced_but_text(_("Edit Public Holiday Text")) self.insertWidget(label) self.insertWidget(self.bank_hol_label) self.insertWidget(frame) self.insertWidget(clinician_groupbox) self.setMinimumSize(self.sizeHint()) self.check_before_reject_if_dirty = True QtCore.QTimer.singleShot(100, self.load_values)
def __init__(self, date_, parent=None): ExtendableDialog.__init__(self, parent, remove_stretch=True) self.date = date_ label = WarningLabel( "%s %s" % (_("Edit Memos for"), localsettings.longDate(date_))) self.bank_hol_label = QtWidgets.QLabel("") font = self.font() font.setBold(True) font.setItalic(True) self.bank_hol_label.setFont(font) self.bank_hol_label.setAlignment(QtCore.Qt.AlignCenter) self.bank_hol_label.hide() self.global_lineedit = QtWidgets.QLineEdit() frame = QtWidgets.QFrame() form_layout = QtWidgets.QFormLayout(frame) form_layout.addRow(_("Global Memo"), self.global_lineedit) frame2 = QtWidgets.QFrame() form_layout = QtWidgets.QFormLayout(frame2) self.le_dict = {} for apptix in \ localsettings.activedent_ixs + localsettings.activehyg_ixs: le = QtWidgets.QLineEdit() form_layout.addRow(localsettings.apptix_reverse.get(apptix), le) self.le_dict[apptix] = le scroll_area = QtWidgets.QScrollArea() scroll_area.setWidget(frame2) scroll_area.setWidgetResizable(True) clinician_groupbox = QtWidgets.QGroupBox() clinician_groupbox.setTitle(_("Clinician Memos")) layout = QtWidgets.QVBoxLayout(clinician_groupbox) layout.addWidget(scroll_area) self.public_holiday_le = QtWidgets.QLineEdit() public_holiday_widget = QtWidgets.QFrame() form_layout = QtWidgets.QFormLayout(public_holiday_widget) form_layout.addRow(_("Public Holiday Text"), self.public_holiday_le) self.add_advanced_widget(public_holiday_widget) self.set_advanced_but_text(_("Edit Public Holiday Text")) self.insertWidget(label) self.insertWidget(self.bank_hol_label) self.insertWidget(frame) self.insertWidget(clinician_groupbox) self.setMinimumSize(self.sizeHint()) self.check_before_reject_if_dirty = True QtCore.QTimer.singleShot(100, self.load_values)
def publicHolidayEnter(parent): ''' enter/modify the stored public holiday field ''' d = parent.selectedDate print "edit pub hol for", d datekey = "%d%02d"%(d.month, d.day) current = parent.headingdata.get(datekey, "") new, result = QtGui.QInputDialog.getText(parent, _("Public Holidays"), _("Enter the information for ")+localsettings.longDate(d), QtGui.QLineEdit.Normal, current) if result and current != str(new.toAscii()): parent.emit(QtCore.SIGNAL("add_pub_hol"), str(new.toAscii()))
def __init__(self, dayDate): self.dayName = localsettings.longDate(dayDate) self.publicHoliday = "" self.dents = {}
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()
def getHtml(pt): return TEMPLATE % (pt.name, pt.address.replace( "\n", "<br />"), localsettings.longDate(localsettings.currentDay()), _("Dear"), pt.name.title(), _("Yours Sincerely"))
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()