def __init__(self, view, builder, parent): self.view = view self.loading = False self.checkinv = False self.checkfilt = 0 self.coremodel = view.get_model() self.model = self.coremodel.filter_new() self.model.set_visible_func(self.checkfilter) self.view.set_model(self.model) self.builder = builder self.parent = parent self.picinfo = None self.selection = view.get_selection() self.picrect = None self.currows = [] self.curriter = None self.bookfilters = None sel = self.view.get_selection() sel.set_mode = Gtk.SelectionMode.SINGLE sel.connect("changed", self.row_select) for k, v in _form_structure.items(): w = builder.get_object(v) sig = "changed" if v.startswith("s_"): sig = "value-changed" w.connect("focus-out-event", self.item_changed, k) elif v.startswith("c_"): sig = "clicked" w.connect(sig, self.item_changed, k) self.previewBuf = GdkPixbuf.Pixbuf.new_from_file( os.path.join(pycodedir(), "picLocationPreviews.png")) self.clear() self.loading = False
def __init__(self, parent, filters, prjdir, xrfile, listsize, source, localfile): self.parent = parent self.prjdir = prjdir self.template = "\n\\AddTrigger {book}{dotref}\n\\x - \\xo {colnobook}\u00A0\\xt {refs}\\x*\n\\EndTrigger\n" if not parent.ptsettings.hasLocalBookNames: usfms = parent.printer.get_usfms() usfms.makeBookNames() parent.ptsettings.bkStrs = usfms.booknames.bookStrs parent.ptsettings.bookNames = usfms.booknames.bookNames parent.hasLocalBookNames = True logger.debug(f"Source: {source}") if source == "strongs": self.xrefs = XMLXrefs(os.path.join(pycodedir(), "strongs.xml"), filters, localfile, context=parent.ptsettings) elif xrfile is None: self.xrefs = StandardXrefs(os.path.join(pycodedir(), "cross_references.txt"), filters, listsize=listsize) elif xrfile.endswith(".xml"): self.xrefs = XMLXrefs(xrfile, filters, context=parent.ptsettings) else: self.xrefs = XrefFileXrefs(xrfile, filters) gc.collect()
def __new__(cls, localfile=None): if cls._singletemp is not None: return cls._singletemp else: cls._singletemp = list.__new__(cls) if localfile is None: localfile = os.path.join(pycodedir(), "sfm", "ucdata_pickle.bz2") if not os.path.exists(localfile): res = cls._singletemp elif localfile.endswith(".bz2"): with bz2.open(localfile, "rb") as inf: res = pickle.load(inf) elif localfile.endswith(".pickle"): with open(localfile, "rb") as inf: res = pickle.load(inf) else: res = cls._singletemp cls._singletemp = None return res
def fixpdfrgb(trailer, **kw): oi = trailer.Root.OutputIntents iccdat = None if oi is not None and len(oi): iccprofile = oi[0].DestOutputProfile if isinstance(iccprofile, PdfIndirect): iccprofile = iccprofile.real_value() uncompress([iccprofile], leave_raw=True) iccprofile[PdfName('Binary')] = True iccdat = iccprofile.stream if iccdat is None: iccfile = os.path.join(pycodedir(), "sRGB.icc") if os.path.exists(iccfile): with open(iccfile, "rb") as inf: iccdat = inf.read() if iccdat is None: return icc = PdfDict(indirect=True, Binary=True, N=3, Alternate=PdfName("DeviceRGB"), stream=iccdat) for pagenum, page in enumerate(trailer.pages, 1): r = page.Resources if r is None: r = page.Resources = PdfDict() colrs = r.ColorSpace if colrs is None: colrs = r.ColorSpace = PdfDict() i = 0 while "/CS" + str(i) in colrs: i += 1 key = "CS" + str(i) iccclr = colrs[PdfName(key)] = PdfArray([PdfName("ICCBased"), icc]) iccclr.indirect = True pstate = PageRGBState() pstate.parsepage(page, trailer, cskey=key, **kw) xobjs = r.XObject if xobjs is not None: for k, v in xobjs.items(): if v.ColorSpace == "/DeviceRGB": v.ColorSpace = iccclr
def __init__(self, localfile=None, basedict=None): if basedict is not None: super().__init__(basedict) if localfile is None: localfile = os.path.join(pycodedir(), "sfm", "allkeys.txt") self.implicits = [] self.specials = { 'first tertiary ignorable': (0, 0, 0), 'last tertiary ignorable': (0, 0, 0), 'first secondary ignorable': (0, 0, 0), 'last secondary ignorable': (0, 0, 0x1F), # not really, but highest tertiary value 'first primary ignorable': (0, 0x20, 0), 'last primary ignorable': (0, 0, 0), # calculated 'first variable': (0x0200, 0, 0), 'last variable': (0, 0, 0), # calculated 'first regular': (0xFFFF, 0, 0), # calculated 'last regular': (0, 0, 0), # calculated 'last implicit': (0xFCC1, 0, 0), # 0xFBC0 + 0x10FFFF >> 15 'first trailing': (0xFCC2, 0, 0), # next after last implicit 'last trailing': (0xFFFC, 0, 0) } self.parameters = { 'alternate': 'non-ignorable', 'maxVariable': 'punct', 'normalization': 'off', 'strength': '3', 'backwards': '0', 'caseLevel': 'off', 'caseFirst': 'off', 'numericOrdering': 'off', 'hiraganaQ': 'off', 'supressContractions': '', 'optimize': '', 'reorder': '' } if basedict is not None: return with open(localfile) as inf: for l in inf.readlines(): line = l.split("#", 1)[0].rstrip() if not line or line.startswith("@version"): continue if line.startswith("@implicitweights "): chrange, base = line[17:].split(";") start, end = chrange.split("..") basev = pack(">H", int(base, 16)) starti = int(start, 16) for i in range(starti, int(end, 16) + 1): key = chr(i) self[key] = basev + b"\00\00\00\00" + pack( ">H", i - starti + 0x8000) + b"\00\00\00\00" continue k, v = line.split(";", 1) key = "".join(chr(int(x, 16)) for x in k.rstrip().split()) vals = [] vs = re.findall( r"\[([.*])([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\]\s*", v.lstrip()) for vm in vs: vals.append(b"".join( pack(">H", int(x, 16)) for x in vm[1:])) self[key] = (b"".join(vals), vs[0][0] == '*') ce = tuple(int(x, 16) for x in vs[0][1:]) if vs[0][0] == "*" and ce > self.specials['last variable']: self.specials['last variable'] = ce if vs[0][0] == "." and ce < self.specials['first regular']: self.specials['first regular'] = ce if ce[0] < 0xFFF0 and ce > self.specials['last regular']: self.specials['last regular'] = ce if ce[0] == 0 and ce[1] > self.specials[ 'last primary ignorable'][1]: self.specials['last primary ignorable'] = (0, ce[1], 0)
def loadvrs(cls, fname=None): if fname is None: fname = os.path.join(pycodedir(), 'eng.vrs') cls.vrs = readvrs(fname) return cls.vrs
from functools import reduce from copy import deepcopy from .. import sfm import bz2 import contextlib import operator import os import pickle import re import site from ptxprint.utils import pycodedir _PALASO_DATA = os.path.join( site.getuserbase(), 'ptxprint', 'sfm') _package_dir = os.path.join(pycodedir(), 'sfm') def _check_paths(pred, paths): return next(filter(pred, map(os.path.normpath, paths)), None) def _source_path(path): return _check_paths(os.path.exists, [os.path.join(_PALASO_DATA, path), os.path.join(_package_dir, path)]) def _newer(cache, benchmark): return os.path.getmtime(benchmark) <= os.path.getmtime(cache)