def __init__(self, parent, title="", caption="", buttons=Ok, width=0, height=0, auto_spawn=True): widget.__init__(self, 'dialogbox', width, height) self.auto_spawn = auto_spawn self.button_width = 60 self.button_height = 20 self.button_offset = 10 self.title_bar_height = 20 self.font = font.get_font() self.buttons = buttons self.__buttons = [] self.parent = parent if self.width == 0 and self.height == 0: #applying default dimension self.width = self.DefaultWidth self.height = self.DefaultHeight self.caption = caption self.title = title self.dialog_action = None self.__generate_buttons() if self.auto_spawn: self.spawn()
def __init__(self, width=0, height=0): widget.__init__(self, "textarea", width, height) self.font = font.get_font() self.line_height = self.font.size('a')[1] self.line_offset = self.LineOffset self.line_separator = self.LineSeparator self.text = ""
def __init__( self, text, family='Sans', size=16, bold=False, italic=False, color=(1.0, 1.0, 1.0, 1.0), x=0, y=0, z=0, anchor_x='left', anchor_y='baseline', filename='./Arial.ttf'): self._text = text self._font = get_font(filename, size) self._color = color self._x = x self._y = y self._z = z self._anchor_x = anchor_x self._anchor_y = anchor_y self.build()
def __init__(self, width=0, height=0): highlight_widget.__init__(self, "combobox", width, height) self.items = [] self.selected_index = 0 self.dropdown_height = 80 self.dropdown_open = False self.font = font.get_font() self.item_height = 20 self.__receivers = [] if self.height == 0: self.height = 22
def draw_text_el(draw, dpi, el): for par in el: par_coords = box_from_par(par) if par_coords is not None: render(draw, par, 'par', par_coords) tl, rb = par_coords t = '' for att, nick in [ ('align', 'ta'), ('leftIndent', 'li'), ('rightIndent', 'ri'), ('startIndent', 'si'), ('lineSpacing', 'ls') ]: att_txt = par.get(att) if att_txt is not None: t += nick + ':' + att_txt + ' ' if len(t) > 0: f = font.get_font("Courier", dpi / opts.scale, 12) draw.text(tl, t, font=f, fill=color.green) for line in par: render(draw, line, 'line'); for fmt in line: assert_d(fmt.tag == abyns+'formatting') font_name = fmt.get('ff') font_size = fmt.get('fs') font_size = int(re.sub('\.', '', font_size)) font_ital = (fmt.get('italic') == 'true') f = font.get_font(font_name, dpi / opts.scale, font_size, font_ital) for cp in fmt: assert_d(cp.tag == abyns+'charParams') if opts.text: draw.text((int(cp.get('l')) / opts.scale, int(cp.get('b')) / opts.scale), cp.text.encode('utf-8'), font=f, fill=color.yellow)
def __init__(self, width=0, height=0): widget.widget.__init__(self, "slider", width, height) self.items = [] self.selected_index = 0 self.font = font.get_font() self.left_arrow = pygame.image.load(self.LeftArrow) self.right_arrow = pygame.image.load(self.RightArrow) self.selection_changed = None if width == 0 and height == 0: self.width = self.left_arrow.get_width() + self.right_arrow.get_width() + 50 self.height = self.left_arrow.get_height()
def __init__(self, width=0, height=0): widget.widget.__init__(self, "slider", width, height) self.items = [] self.selected_index = 0 self.font = font.get_font() self.left_arrow = pygame.image.load(self.LeftArrow) self.right_arrow = pygame.image.load(self.RightArrow) self.selection_changed = None if width == 0 and height == 0: self.width = self.left_arrow.get_width( ) + self.right_arrow.get_width() + 50 self.height = self.left_arrow.get_height()
def __init__(self, buf, font=None, colour=WEISS, shadow_colour=SCHWARZ, topleft=None): self.buffer = buf if not font: fontname = get_font_names()[0] self.font = get_font(fontname, 10) else: self.font = font self.font_colour = colour self.bg_colour = shadow_colour if not topleft: blit_x = 10 blit_y = self.buffer.get_height() - 15 else: blit_x, blit_y = topleft[0], topleft[1] self.message_blitpos = (blit_x, blit_y)
def __init__(self, text, family='Sans', size=16, bold=False, italic=False, color=(1.0, 1.0, 1.0, 1.0), x=0, y=0, z=0, anchor_x='left', anchor_y='baseline', filename='./Arial.ttf'): self._text = text self._font = get_font(filename, size) self._color = color self._x = x self._y = y self._z = z self._anchor_x = anchor_x self._anchor_y = anchor_y self.build()
def __init__(self, width=0, height=0): highlight_widget.__init__(self, "button", width, height) self.caption = "" self.font = font.get_font() self.__receivers = []
def __init__(self, width=0, height=0): widget.__init__(self, "label", width, height) self.font = font.get_font() self.text = "" self.auto_size = True
def drawtext(self, text, coord, face='Courier', size=10): import font coord = coord.scale(self.scale) f = font.get_font(face, self.page.book.dpi / self.scale,size) self.draw.text(coord, text, font=f) # fill=color.yellow
def scan_pages(context, scandata, iabook): book_id = iabook.get_book_id() scandata_pages = scandata.pageData.page scandata_ns = iabook.get_scandata_ns() try: # dpi isn't always there dpi = int(scandata.bookData.dpi.text) except AttributeError: dpi = 300 i = 0 f = ImageFont.load_default() # f = ImageFont.load('/Users/mccabe/s/archive/epub/Times-18.bdf') for event, page in context: orig_width = int(page.get('width')) orig_height = int(page.get('height')) orig_size = (orig_width, orig_height) requested_size = (orig_width / scale, orig_height / scale) image = Image.new('RGB', requested_size) image_str = iabook.get_page_image(i, requested_size, out_img_type='ppm', kdu_reduce=kdu_reduce) page_image = None if image_str is not None: page_image = Image.open(StringIO.StringIO(image_str)) if requested_size != page_image.size: page_image = page_image.resize(requested_size) try: image = Image.blend(image, page_image, .2) except ValueError: print 'blending - images didn\'t match' debug() pass draw = ImageDraw.Draw(image) for word in page.findall('.//WORD'): print word.text # for el in page: # if el.tag == 'IMAGE': # render(draw, el, 'block_picture') # if el.tag == 'BLOCK': # par_coords = box_from_par(el) # if par_coords is not None: # render(draw, el, 'par', par_coords) # for text in el: # render(draw, text, 'line') # for token in text: # render(draw, token, 'token') # font_name = token.get('font-name') # font_size = token.get('font-size') # font_size = int(re.sub('\..*', '', font_size)) # font_ital = token.get('italic') == 'yes' # font_bold = token.get('bold') == 'yes' # f = font.get_font(font_name, dpi / scale, font_size / scale, font_ital) # draw.text((int(math.floor(float(token.get('x'))))/scale, # int(math.floor(float(token.get('base'))))/scale), # token.text.encode('utf-8'), # font=f, # fill=color.yellow) if not include_page(scandata_pages[i]): draw.line([(0, 0), image.size], width=50, fill=color.red) page_scandata = iabook.get_page_scandata(i) if page_scandata is not None: t = page_scandata.pageType.text # pageno_string = page_scandata.pageNumber.text pageno = page_scandata.find(scandata_ns + 'pageNumber') if pageno: pageno_string = pageno.text t += ' ' + pageno_string handside = page_scandata.find(scandata_ns + 'handSide') if handside: t += ' ' + handside.text f = font.get_font("Courier", dpi / scale, 12) page_w, page_h = image.size draw.text((.02 * dpi, .02 * dpi), t.encode('utf-8'), font=f, fill=color.green) image.save(outdir + '/img' + scandata_pages[i].get('leafNum') + '.png') print 'page index: ' + str(i) page.clear() i += 1 if top_page is not None: if i > top_page: sys.exit(0) return None
def scan_pages(context, scandata, iabook): book_id = iabook.get_book_id() scandata_pages = scandata.pageData.page try: # dpi isn't always there dpi = int(scandata.bookData.dpi.text) except AttributeError: dpi = 300 i = 0 f = ImageFont.load_default() # f = ImageFont.load('/Users/mccabe/s/archive/epub/Times-18.bdf') for event, page in context: orig_width = int(page.get('width')) orig_height = int(page.get('height')) width = orig_width / s height = orig_height / s image = Image.new('RGB', (width, height)) page_image = None image_str = iabook.get_page_image(i, width, height, out_img_type='ppm') if image_str is not None: page_image = Image.open(StringIO.StringIO(image_str)) (nw, nh) = page_image.size if nw != width or nh != height: page_image = page_image.resize((width, height)) # image.paste(page_image, None) try: image = Image.blend(image, page_image, .2) except ValueError: print 'blending - images didn\'t match' debug() pass draw = ImageDraw.Draw(image) for block in page: if block.get('blockType') == 'Picture' and page_image is not None: cropped = page_image.crop(four_coords(block, scale)) image.paste(cropped, four_coords(block, scale)) for block in page: if block.get('blockType') == 'Text': render(draw, block, 'block_text') if block.get('blockType') == 'Picture': render(draw, block, 'block_picture') if block.get('blockType') == 'Table': render(draw, block, 'block_table') # else: # render(draw, block, 'block_picture') # if i > 0: # cropped = page_image.crop(four_coords(block)) # image.paste(cropped, four_coords(block)) for el in block: if el.tag == abyns+'region': pass elif el.tag == abyns+'row': for cell in el: for text in cell: for par in text: par_coords = box_from_par(par) if par_coords is not None: render(draw, par, 'par', par_coords) for line in par: render(draw, line, 'line'); for fmt in line: assert_d(fmt.tag == abyns+'formatting') font_name = fmt.get('ff') font_size = fmt.get('fs') font_size = int(re.sub('\.', '', font_size)) font_ital = (fmt.get('italic') == 'true') f = font.get_font(font_name, dpi / scale, font_size, font_ital) for cp in fmt: assert_d(cp.tag == abyns+'charParams') draw.text((int(cp.get('l'))/s, int(cp.get('b'))/s), cp.text.encode('utf-8'), font=f, fill=color.yellow) elif el.tag == abyns+'text': for par in el: par_coords = box_from_par(par) if par_coords is not None: render(draw, par, 'par', par_coords) for line in par: render(draw, line, 'line'); for fmt in line: assert_d(fmt.tag == abyns+'formatting') font_name = fmt.get('ff') font_size = fmt.get('fs') font_size = int(re.sub('\.', '', font_size)) font_ital = (fmt.get('italic') == 'true') f = font.get_font(font_name, dpi / scale, font_size, font_ital) for cp in fmt: assert_d(cp.tag == abyns+'charParams') draw.text((int(cp.get('l'))/s, int(cp.get('b'))/s), cp.text.encode('utf-8'), font=f, fill=color.yellow) elif (el.tag == abyns+'row'): pass else: print('unexpected tag type' + el.tag) sys.exit(-1) if not include_page(scandata_pages[i]): draw.line([(0, 0), image.size], width=50, fill=color.red) image.save(outdir + '/img' + scandata_pages[i].get('leafNum') + '.png') print 'page index: ' + str(i) page.clear() i += 1 return None
def drawtext(self, text, coord, face='Courier', size=10): import font coord = coord.scale(self.scale) f = font.get_font(face, self.page.book.dpi / self.scale, size) self.draw.text(coord, text, font=f) # fill=color.yellow
def __init__(self, width=0, height=0): widget.__init__(self, "textbox", width, height) self.font = font.get_font() self.text = "" self.tick = 0 self.text_changed = None
def scan_pages(context, scandata, iabook): book_id = iabook.get_book_id() scandata_pages = scandata.pageData.page scandata_ns = iabook.get_scandata_ns() try: # dpi isn't always there dpi = int(scandata.bookData.dpi.text) except AttributeError: dpi = 300 i = 0 f = ImageFont.load_default() # f = ImageFont.load('/Users/mccabe/s/archive/epub/Times-18.bdf') for event, page in context: if opts.first > 0: if i < opts.first: i += 1 continue orig_width = int(page.get('width')) orig_height = int(page.get('height')) orig_size = (orig_width, orig_height) requested_size = (orig_width / opts.scale, orig_height / opts.scale) image = Image.new('RGB', requested_size) image_str = iabook.get_page_image(i, requested_size, out_img_type='ppm', kdu_reduce=opts.reduce) page_image = None if image_str is not None: page_image = Image.open(StringIO.StringIO(image_str)) if requested_size != page_image.size: page_image = page_image.resize(requested_size) try: image = Image.blend(image, page_image, .2) except ValueError: print 'blending - images didn\'t match' debug() pass draw = ImageDraw.Draw(image) for block in page: if block.get('blockType') == 'Picture' and page_image is not None: cropped = page_image.crop(four_coords(block, opts.scale)) image.paste(cropped, four_coords(block, opts.scale)) for block in page: blocktype = '' if block.get('blockType') == 'Text': blocktype = 'Text' render(draw, block, 'block_text') if block.get('blockType') == 'Picture': blocktype = 'Picture' render(draw, block, 'block_picture') if block.get('blockType') == 'Table': blocktype = 'Table' render(draw, block, 'block_table') # else: # render(draw, block, 'block_picture') # if i > 0: # cropped = page_image.crop(four_coords(block)) # image.paste(cropped, four_coords(block)) for el in block: if el.tag == abyns+'region': for rect in el: if rect.tag != abyns+'rect': raise 'found non-rect in region: ' + rect.tag render(draw, rect, 'rect') elif el.tag == abyns+'row': for cell in el: for text in cell: draw_text_el(draw, dpi, text) elif el.tag == abyns+'text': draw_text_el(draw, dpi, el) elif (el.tag == abyns+'row'): raise 'unexpected row el' else: print('unexpected tag type' + el.tag) sys.exit(-1) if not include_page(scandata_pages[i]): draw.line([(0, 0), image.size], width=50, fill=color.red) page_scandata = iabook.get_page_scandata(i) if page_scandata is not None: t = page_scandata.pageType.text # pageno_string = page_scandata.pageNumber.text pageno = page_scandata.find(scandata_ns + 'pageNumber') if pageno: pageno_string = pageno.text t += ' ' + pageno_string handside = page_scandata.find(scandata_ns + 'handSide') if handside: t += ' ' + handside.text f = font.get_font("Courier", dpi / opts.scale, 12) page_w, page_h = image.size draw.text((.02 * dpi, .02 * dpi), t.encode('utf-8'), font=f, fill=color.green) image.save(opts.outdir + '/img' + scandata_pages[i].get('leafNum').zfill(3) + '.png') print 'leaf index: ' + str(i) page.clear() i += 1 if opts.last > 0: if i > opts.last: sys.exit(0) return None