def _intern_afm(font, text): global _undefined_font_warned r = afm.dir.afm.get(font, None) if r: return r font2 = _font_aliases.get(font, None) if font2: r = afm.dir.afm.get(font2, None) if r: return r try: exec("import pychart.afm.%s" % re.sub("-", "_", font)) return afm.dir.afm[font] except: if not font2 and not _undefined_font_warned.has_key(font): pychart_util.warn('Warning: unknown font "%s" while parsing "%s"' % (font, text)) _undefined_font_warned[font] = 1 if font2: try: exec('import pychart.afm.%s' % re.sub('-', '_', font2)) return afm.dir.afm[font2] except: if not _undefined_font_warned.has_key(font): pychart_util.warn('Warning: unknown font "%s" while parsing "%s"' % (font, text)) _undefined_font_warned[font] = 1 return None
def _intern_afm(font, text): global _undefined_font_warned font2 = _font_aliases.has_key(font) and _font_aliases[font] if afm.dir.afm.has_key(font): return afm.dir.afm[font] if afm.dir.afm.has_key(font2): return afm.dir.afm[font2] try: exec("import pychart.afm.%s" % re.sub("-", "_", font)) return afm.dir.afm[font] except: if not font2 and not _undefined_font_warned.has_key(font): pychart_util.warn("Warning: unknown font '%s' while parsing '%s'" % (font, text)) _undefined_font_warned[font] = 1 if font2: try: exec("import pychart.afm.%s" % re.sub("-", "_", font2)) return afm.dir.afm[font2] except: if not _undefined_font_warned.has_key(font): pychart_util.warn( "Warning: unknown font '%s' while parsing '%s'" % (font, text)) _undefined_font_warned[font] = 1 return None
def _intern_afm(font, text): global _undefined_font_warned font2 = _font_aliases.has_key(font) and _font_aliases[font] if afm.dir.afm.has_key(font): return afm.dir.afm[font] if afm.dir.afm.has_key(font2): return afm.dir.afm[font2] try: exec("import pychart.afm.%s" % re.sub("-", "_", font)) return afm.dir.afm[font] except: if not font2 and not _undefined_font_warned.has_key(font): pychart_util.warn("Warning: unknown font '%s' while parsing '%s'" % (font, text)) _undefined_font_warned[font] = 1 if font2: try: exec("import pychart.afm.%s" % re.sub("-", "_", font2)) return afm.dir.afm[font2] except: if not _undefined_font_warned.has_key(font): pychart_util.warn("Warning: unknown font '%s' while parsing '%s'" % (font, text)) _undefined_font_warned[font] = 1 return None
def set_defaults(cls, **dict): keys = getattr(cls, "keys") for attr in dict.keys(): if not keys.has_key(attr): pychart_util.warn(cls, ": unknown attribute ", attr) pychart_util.warn("Use pydoc to see the documentation of the class.") sys.exit(1) tuple = keys[attr] keys[attr] = (tuple[0], tuple[1], dict[attr], tuple[2])
def nearest_match(data, col, val): min_delta = None match = None for d in data: if min_delta == None or abs(d[col] - val) < min_delta: min_delta = abs(d[col] - val) match = d pychart_util.warn("XXX ", match) return match
def __init__(self, compress_p_): self.__reset_context() self.__next_obj_id = 1 self.__next_font_id = 1 self.__obj_offsets = {} self.__registered_fonts = {} self.__lines = [] self.__nr_gsave = 0 if compress_p_ and not zlib_available_p: pychart_util.warn("Zlib not available. Compression request ignored.\n") compress_p_ = 0 self.__compress_p = compress_p_
def discover_afm_files_in_dir(dir): reg2 = re.compile("FontName (.*)") found = 0 for file in dircache.listdir(dir): if re.search("afm$", file) != None: try: path = os.path.join(dir, file) fp = open(path) found = 1 for line in fp.readlines(): mo = reg2.match(line) if mo != None: _afm_files[mo.group(1)] = path fp.close() except IOError, why: pychart_util.warn(path + ":" + why)
def __init__(self, fname, compress_p_): basecanvas.T.__init__(self) self.__out_fname = fname self.__reset_context() self.__next_obj_id = 1 self.__next_font_id = 1 self.__obj_offsets = {} # Maps font name -> integer font ID. self.__registered_fonts = {} self.__lines = [] self.__nr_gsave = 0 if compress_p_ and not _zlib_available_p: pychart_util.warn("Zlib not available. Compression request ignored.\n") compress_p_ = 0 self.__compress_p = compress_p_
def __init__(self, fname, compress_p_): basecanvas.T.__init__(self) self.__out_fname = fname self.__reset_context() self.__next_obj_id = 1 self.__next_font_id = 1 self.__obj_offsets = {} # Maps font name -> integer font ID. self.__registered_fonts = {} self.__lines = [] self.__nr_gsave = 0 if compress_p_ and not _zlib_available_p: pychart_util.warn( "Zlib not available. Compression request ignored.\n") compress_p_ = 0 self.__compress_p = compress_p_
def __init__(self, fname, compress_p): basecanvas.T.__init__(self) self.__out_fname = fname self.__reset_context() self.__next_obj_id = 1 self.__next_font_id = 1 # Maps integer object id -> the file offset where the object definition # is found self.__obj_offsets = {} # Maps font name -> integer font ID. self.__registered_fonts = {} self.__lines = [] self.__nr_gsave = 0 if compress_p and not _zlib_available_p: pychart_util.warn('Zlib not available. Compression request ignored.\n') compress_p = 0 self.__compress_p = compress_p
def _check_attr_types(obj, keys): for attr in obj.__dict__.keys(): if not keys.has_key(attr): pychart_util.warn(obj, ": unknown attribute ", attr) pychart_util.warn("Use pydoc to see the documentation of the class.") typeval, can_be_none, default_value, docstring, = keys[attr][0:4] val = getattr(obj, attr) if val == None: if not can_be_none: raise Exception, "%s: Missing attribute '%s'" % (obj, attr) continue if typeval == pychart_util.AnyType: pass elif isinstance(typeval, types.FunctionType): # user-defined check procedure error = apply(typeval, (val,)) if error != "": raise Exception, "%s: %s for attribute '%s', but got '%s'" % (obj, error, attr, val) elif 1: try: if isinstance(val, typeval): pass except: pychart_util.warn("OBJ=", obj, "VAL=", val, "TYPE=", typeval, "ATTR=", attr, keys[attr]) sys.exit(1) else: raise Exception, "%s: attribute '%s' expects type %s but found %s" % (obj, attr, typeval, val)
def fwrite_csv(fd, delim=','): """This function is deprecated. Use write_csv instead.""" pychart_util.warn( "chart_data.fwrite_csv is deprecated. Use write_csv instead.") return write_csv(fd, delim)
def read_afm(path): fp = open(path) table = {} # maps charcode -> width for line in fp.readlines(): mo = _afm_line_re_pat.match(line) if not mo: continue table[int(mo.group(1))] = int(mo.group(2)) fp.close() return table for dir in _afm_paths: if discover_afm_files_in_dir(dir): pychart_util.warn("Found AFM dir: ", dir) break if len(_afm_files) == 0: pychart_util.warn( "Warning: AFM files not found. I searched the following directories:") for dir in _afm_paths: pychart_util.warn(" " + dir) sys.exit(1) for (f, g) in _font_aliases.items(): if _afm_files.has_key(g): _afm_files[f] = _afm_files[g] init_fp = open(os.path.join("afm", "__init__.py"), "wb") init_fp.write("__all__ = [")
def read_afm(path): fp = open(path) table = {} # maps charcode -> width for line in fp.readlines(): mo = _afm_line_re_pat.match(line) if not mo: continue table[int(mo.group(1))] = int(mo.group(2)) fp.close() return table for dir in _afm_paths: if discover_afm_files_in_dir(dir): pychart_util.warn("Found AFM dir: ", dir) break if len(_afm_files) == 0: pychart_util.warn("Warning: AFM files not found. I searched the following directories:") for dir in _afm_paths: pychart_util.warn(" "+dir) sys.exit(1) for (f,g) in _font_aliases.items(): if _afm_files.has_key(g): _afm_files[f] = _afm_files[g] init_fp = open(os.path.join("afm", "__init__.py"), "wb") init_fp.write("__all__ = [") for font, afm_path in _afm_files.items():
def fwrite_csv(fd, delim = ','): """This function is deprecated. Use write_csv instead.""" pychart_util.warn("chart_data.fwrite_csv is deprecated. Use write_csv instead.") return write_csv(fd, delim)