def __init__(self, name, width=None): self.name = name self.value_list = [] if width: self.width = width else: self.width = 72 self.height = 9 # Header self.header = Field(name) self.header.format = format_title self.header.style.bold = True self.header.style.color = (1,1,1) self.header.style.horizontal_alignment = alignment.CENTER # self.header.box.bottom_border = 1 self.header.box.background_color = (0,0,0) # Row self.row = Field() self.row.style.bold = False # Footer self.footer = Field() self.footer.style.bold = True self.footer.box.top_border = 1 self.footer.style.horizontal_alignment = alignment.CENTER self.footer.value = None
def __init__(self, value=None, vertical_padding=None, bold=None, size=None, horizontal_alignment=None, skip=None, drew_skip=None, drew_title=None): if value: self.field = Field(value) else: self.field = Field() if vertical_padding is not None: self.field.style.vertical_padding = vertical_padding else: self.field.style.vertical_padding = 2 if bold: self.field.style.bold = True else: self.field.style.bold = bold if size is not None: self.field.style.size = size else: self.field.style.size = 10 if horizontal_alignment: self.field.style.horizontal_alignment = horizontal_alignment else: self.field.style.horizontal_alignment = alignment.CENTER if skip is not None: self.skip = skip else: self.skip = 8 if drew_skip: self._drew_skip = drew_skip else: self._drew_skip = True if drew_title: self._drew_title = drew_title else: self._drew_title = False
############################################################################### # file: podunk/prefab/fields.py # author: Jim Storch ############################################################################### from manexreport.prefab.boxes import HEADER_BOX from manexreport.prefab.styles import HEADER_STYLE from manexreport.widget.field import Field # You need to do a copy.copy(FIELD_NAME) in order to use a prefab field in # multiple spots HEADER_FIELD = Field() HEADER_FIELD.style = HEADER_STYLE HEADER_FIELD.box = HEADER_BOX
def __init__(self, pdf_file=None, paper_type=None, time_zone=None, left_margin=None, top_margin=None, right_margin=None, bottom_margin=None, date_flag=None, flag_footer=None, logo=None, logo_filename=None, logo_width=None, logo_height=None, logo_top_margin=None): self.pdf_file = pdf_file self.title = '' self.author = 'Manexware S.A.' self.department = 'OpenEduNav' self.date_flag = date_flag self.logo = logo self.logo_filename = logo_filename self.logo_width = logo_width self.logo_height = logo_height self.flag_footer = flag_footer if time_zone: local_tz = pytz.timezone(time_zone) else: local_tz = pytz.timezone('America/Guayaquil') utc_dt = datetime.datetime.utcnow() local_dt = utc_dt.replace(tzinfo=pytz.utc).astimezone(local_tz) date_time = local_tz.normalize(local_dt) if paper_type: self.page_width, self.page_height = paper_type else: self.page_width, self.page_height = paper.A4_LANDSCAPE if left_margin is not None: self.left_margin = left_margin else: self.left_margin = 50 if top_margin is not None: self.top_margin = top_margin else: self.top_margin = 40 if right_margin is not None: self.right_margin = right_margin else: self.right_margin = 50 if bottom_margin is not None: self.bottom_margin = bottom_margin else: self.bottom_margin = 40 if logo_top_margin is not None: self.logo_top_margin = logo_top_margin else: self.logo_top_margin = 70 # Metrics self._top_edge = self.page_height - 1 self._right_edge = self.page_width - 1 self._bottom_edge = 0 self._left_edge = 0 self._working_width = self.page_width - (self.right_margin + self.left_margin) self._working_height = self.page_height - (self.top_margin + self.bottom_margin) # Create the ReportLab Canvas self.canvas = Canvas(self.pdf_file, pagesize=(self.page_width, self.page_height)) # Create the page header self.header = Field() # self.header.box.bottom_border = 2 # self.header.box.line_cap = 1 # self.header.box.border_color = (.6,.6,.6) self.header.style.vertical_padding = 6 self.header.style.bold = True self.header.style.size = 10 # self.header.style.color = (.6,.6,.6) self.header.style.horizontal_alignment = alignment.RIGHT self.header.width = self._working_width # Create the page footer self.footer = Field() self.footer.box.top_border = 1 self.footer.box.line_cap = 1 # self.footer.box.border_color = (.6,.6,.6) self.footer.style.horizontal_alignment = alignment.CENTER self.footer.style.vertical_alignment = alignment.TOP # self.footer.style.color = (.6,.6,.6) self.footer.width = self._working_width self.footer.style.size = 8 # Create the date label self.date = Field(date_time) self.date.format = format_report_date self.date.style.vertical_alignment = alignment.TOP # self.date.style.color = (.6,.6,.6) # self.date.style.horizontal_padding = 0 self.date.style.size = 9 # Create the department label self.departmentField = Field() self.departmentField.style.vertical_alignment = alignment.TOP # self.date.style.color = (.6,.6,.6) # self.date.style.horizontal_padding = 0 self.departmentField.style.size = 8 # Create the page number label; 'Page X of' self.page_num = Field() self.page_num.style.horizontal_alignment = alignment.RIGHT self.page_num.style.vertical_alignment = alignment.TOP self.page_num.width = self._working_width - 13 # self.page_num.style.color = (.6,.6,.6) self.page_num.horizontal_padding = 0 self.page_num.style.size = 8 # Create the last page number label self.last_page = Field() # self.last_page.style.horizontal_alignment = alignment.LEFT self.last_page.style.vertical_alignment = alignment.TOP # self.last_page.width = self._working_width # self.last_page.style.color = (.6,.6,.6) self.last_page.horizontal_padding = 0 self.last_page.style.size = 8 # Objects to be drawn self.draw_list = [] self._page_count = 1