def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.save() self.rect = painter.viewport() self.rect.adjust(0, 0, -1, -1) painter.drawRect(QRectF(self.rect)) self.prj.setupPrism(self.rect.height(), 68) self.prj.setupProjectionMatrix(self.alef, self.bet) # draw the prism self.drawCubick(painter, [0, 0, 0], 63, 16) mineCube = self.parent.presenter.mineCube for y in range(len(mineCube)): for z in range(len(mineCube[0])): for x in range(len(mineCube[0][0])): if mineCube[y][z][x] in self.parent.selectedMinerals.list_: colo = self.parent.selectedMinerals.\ getColor(mineCube[y][z][x]) self.drawCubick(painter, [x, y, z], color=colo) self.drawSliceCursor(painter, self.parent.presenter.elevation) painter.restore() painter.end() del painter
class Printer(object): def __init__(self): self.pages = [] self.handler = QPrinter() def reset(self): self.pages = [] def make_page(self, html): page = QTextDocument() page.setHtml(html) self.pages.append(page) def generate_employee_table(self, employees): html = """ <table align="center" cellpadding="10"> <tr> <th>ID</th> <th>Name</th> <th>Address</th> <th>Phone Number</th> <th>Cell Number</th> <th>Email Address</th> </tr> """ for employee in employees: html += """ <tr> <td>%(id)s</td> <td>%(first_name)s %(last_name)s</td> <td>%(street_address)s<br /> %(city)s %(state)s %(zip_code)s</td> <td>%(phone_number)s</td> <td>%(cell_number)s</td> <td>%(email_address)s</td> </tr> """ % employee html += "</table>" return html def generate_employer_table(self, employer): html = """ <table align="center" width="500"> <tr> <th>ID</th> <td>%(id)s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <th>Company</th> <td>%(name)s</td> </tr> <tr> <th>Address</th> <td> %(street_address)s<br /> %(city)s %(state)s %(zip_code)s </td> </tr> <tr> <th></th> <td></td> </tr> <tr> <th>Contact Person</th> <td>%(contact_person)s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <th>Phone Number</th> <td>%(phone_number)s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <th>Email Address</th> <td>%(email_address)s</td> </tr> </table><br> """ % employer return html def generate_sorted_employee_table(self, employees): html = """ <table align="center" cellspacing="10"> <tr> <th>Overall Score</th> <th>ID</th> <th>Employee</th> <th>Site</th> <th>Overall Comments</th> </tr> """ for employer, employee, score, comments in employees: html += """ <tr> <td>%s</td> <td>%s</td> <td> %s %s<br /> %s<br /> %s %s %s </td> <td>%s<br />(ID# %s)</td> <td>%s</td> </tr> """ % (score, employee["id"], employee["first_name"], employee["last_name"], employee["street_address"], employee["city"], employee["state"], employee["zip_code"], employer["name"], employer["id"], comments) html += "</table>" return html def emit_employer(self, employer, employees): html = """ <img style="float: left;" src=":/img/mmt.png" width="200" height="65"> <h1 align="right">Employer Information</h1> <hr /> <p> <b>CLIENT WORKSITE:</b><br /> %(name)s (ID# %(id)s)<br /> %(street_address)s<br /> %(city)s, %(state)s %(zip_code)s </p> <p> <b>CLIENT CONTACT:</b><br /> %(contact_person)s<br /> %(phone_number)s<br /> %(email_address)s </p> """ % employer if employees: html += '<h2 align="center">Employees</h2><hr />' html += self.generate_employee_table(employees) self.make_page(html) def emit_employee(self, employer, employee): html = """ <img style="float: left;" src=":/img/mmt.png" width="200" height="65" cellspacing=0 cellpadding=1> <h1 align="right">Employee Information</h1> <hr /> """ html += """ <table align="center" cellpadding="1" width="500"> <h2 align="left">Employee</h2> <tr> <th></th> <td></td> </tr> <tr> <th>ID</th> <td>%(id)s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <th>Name</th> <td>%(first_name)s %(last_name)s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <th>Address</th> <td> %(street_address)s<br /> %(city)s %(state)s %(zip_code)s </td> <tr/> <tr> <th></th> <td></td> </tr> <tr> <th>Email Address</th> <td>%(email_address)s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <th>Phone Number</th> <td>%(phone_number)s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <th>Cell Number</th> <td>%(cell_number)s</td> </tr> </table><br /> """ % employee html += '<h2 align="left">Employer</h2><br />' html += self.generate_employer_table(employer) self.make_page(html) def emit_evaluation(self, employer, employee, evaluation): eval_time = QDateTime() eval_time.setTime_t(int(evaluation["date"])) readable_evaluation = eval_time.date().toString("MM.dd.yyyy") next_eval_time = QDateTime() next_eval_time.setTime_t(int(evaluation["next_date"])) readable_next_evaluation = next_eval_time.date().toString("MM.dd.yyyy") recommend = ("Yes" if evaluation["recommended"] else "No") html = """ <img style="float: left;" src=":/img/mmt.png" width="200" height="65"> <h1 align="right"> Individual Employee Evaluation including Comments </h1> <hr /> <p> <b>Employee:</b><br /> %s %s (ID# %s)<br /> %s<br /> %s, %s %s<br /> %s </p> <p> <b>Employment Site:</b><br /> %s<br /> %s<br /> %s, %s, %s </p> <table align="center" width="500"> <tr> <th></th> <td></td> </tr> <tr> <td>Date Evaluated</td> <td>%s</td> </tr> <tr> <td>Next Evaluation Date</td> <td>%s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <td>Quality Score</td> <td>%s</td> </tr> <tr> <td>Quality Comments</td> <td>%s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <td>Habits Score</td> <td>%s</td> </tr> <tr> <td>Habits Comments</td> <td>%s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <td>Knowledge Score</td> <td>%s</td> </tr> <tr> <td>Knowledge Comments</td> <td>%s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <td>Behavior Score</td> <td>%s</td> </tr> <tr> <td>Behavior Comments</td> <td>%s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <td>Employee Score</td> <td>%s</td> </tr> <tr> <td>Overall Score</td> <td>%s</td> </tr> <tr> <th></th> <td></td> </tr> <tr> <td>Comments</td> <td>%s</td> </tr> <tr> <td>Recommended</td> <td>%s</td> </tr> </table> """ % (employee["first_name"], employee["last_name"], employee["id"], employee["street_address"], employee["city"], employee["state"], employee["zip_code"], employee["phone_number"], employer["name"], employer["street_address"], employer["city"], employer["state"], employer["zip_code"], readable_evaluation, readable_next_evaluation, evaluation["quality_score"], evaluation["quality_comments"], evaluation["habits_score"], evaluation["habits_comments"], evaluation["knowledge_score"], evaluation["knowledge_comments"], evaluation["behavior_score"], evaluation["behavior_comments"], evaluation["average_score"], evaluation["overall_score"], evaluation["comments"], recommend) self.make_page(html) def emit_tps_report(self, employees): html = """ <img style="float: left;" src=":/img/mmt.png" width="200" height="65"> <h1 align="right">TPS Report<br /> </h1> <hr /> """ html += self.generate_sorted_employee_table(employees) self.make_page(html) def emit_sorted_employees(self, employees): html = """ <img style="float: left;" src=":/img/mmt.png" width="200" height="65"> <h1 align="right">All Employees sorted by Evalation Score<br />(highest to lowest)</h1> <hr /> <table align="center" cellspacing="10"> <tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Email Address</th> <th>Phone Number</th> <th>Cell Number</th> <th>Overall Score</th> </tr> """ for employer, employee, score, comments in employees: html += """ <tr> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> <td>%s</td> </tr> """ % (employee["id"], employee["first_name"], employee["last_name"], employee["email_address"], employee["phone_number"], employee["cell_number"], score) html += "</table>" self.make_page(html) def paper_mode(self): self.handler.setOutputFormat(QPrinter.NativeFormat) self.handler.setOutputFileName("") def pdf_mode(self, file_name): self.handler.setOutputFormat(QPrinter.PdfFormat) self.handler.setOutputFileName(file_name) def run(self): page_num = 1 last_page = len(self.pages) self.painter = QPainter(self.handler) for page in self.pages: width = self.painter.viewport().width() height = self.painter.viewport().height() rect = QRect(0, 0, width, height) self.painter.save() self.painter.setViewport(rect) page.setTextWidth(width) page.drawContents(self.painter) self.painter.restore() if page_num != last_page: self.handler.newPage() page_num += 1 self.painter.end() self.reset()