Esempio n. 1
0
def profile():
    import sys
    from qt.core import QTextDocument

    from calibre.gui2 import Application
    from calibre.gui2.tweak_book import set_book_locale
    from calibre.gui2.tweak_book.editor.themes import get_theme
    app = Application([])
    set_book_locale('en')
    with open(sys.argv[-2], 'rb') as f:
        raw = f.read().decode('utf-8')
    doc = QTextDocument()
    doc.setPlainText(raw)
    h = Highlighter()
    theme = get_theme(tprefs['editor_theme'])
    h.apply_theme(theme)
    h.set_document(doc)
    h.join()
    import cProfile
    print('Running profile on', sys.argv[-2])
    h.rehighlight()
    cProfile.runctx('h.join()', {}, {'h': h}, sys.argv[-1])
    print('Stats saved to:', sys.argv[-1])
    del h
    del doc
    del app
Esempio n. 2
0
def profile():
    import sys
    from PyQt5.Qt import QTextDocument
    from calibre.gui2 import Application
    from calibre.gui2.tweak_book import set_book_locale
    from calibre.gui2.tweak_book.editor.themes import get_theme

    app = Application([])
    set_book_locale("en")
    raw = open(sys.argv[-2], "rb").read().decode("utf-8")
    doc = QTextDocument()
    doc.setPlainText(raw)
    h = HTMLHighlighter()
    theme = get_theme(tprefs["editor_theme"])
    h.apply_theme(theme)
    h.set_document(doc)
    h.join()
    import cProfile

    print("Running profile on", sys.argv[-2])
    h.rehighlight()
    cProfile.runctx("h.join()", {}, {"h": h}, sys.argv[-1])
    print("Stats saved to:", sys.argv[-1])
    del h
    del doc
    del app
Esempio n. 3
0
 def test(cls):
     from calibre.ebooks.oeb.polish.container import get_container
     from calibre.gui2.tweak_book import set_current_container
     set_current_container(get_container(sys.argv[-1], tweak_mode=True))
     set_book_locale(current_container().mi.language)
     d = cls()
     QTimer.singleShot(0, d.refresh)
     d.exec_()
Esempio n. 4
0
def profile():
    import sys
    from PyQt5.Qt import QTextDocument
    from calibre.gui2 import Application
    from calibre.gui2.tweak_book import set_book_locale
    from calibre.gui2.tweak_book.editor.themes import get_theme
    app = Application([])
    set_book_locale('en')
    raw = open(sys.argv[-2], 'rb').read().decode('utf-8')
    doc = QTextDocument()
    doc.setPlainText(raw)
    h = Highlighter()
    theme = get_theme(tprefs['editor_theme'])
    h.apply_theme(theme)
    h.set_document(doc)
    h.join()
    import cProfile
    print ('Running profile on', sys.argv[-2])
    h.rehighlight()
    cProfile.runctx('h.join()', {}, {'h':h}, sys.argv[-1])
    print ('Stats saved to:', sys.argv[-1])
    del h
    del doc
    del app
Esempio n. 5
0
            text = getattr(node, attr)
        replacement = loc.elided_prefix + new_word
        rtext, replaced = replace(text, loc.original_word, replacement, locale.langcode)
        if replaced:
            if undo_cache is not None:
                undo_cache[(loc.file_name, node, is_attr, attr)] = text
            if is_attr:
                node.set(attr, rtext)
            else:
                setattr(node, attr, rtext)
            container.replace(loc.file_name, node.getroottree().getroot())
            changed.add(loc.file_name)
    return changed


def undo_replace_word(container, undo_cache):
    changed = set()
    for (file_name, node, is_attr, attr), text in iteritems(undo_cache):
        node.set(attr, text) if is_attr else setattr(node, attr, text)
        container.replace(file_name, node.getroottree().getroot())
        changed.add(file_name)
    return changed


if __name__ == '__main__':
    import pprint
    from calibre.gui2.tweak_book import set_book_locale, dictionaries
    container = get_container(sys.argv[-1], tweak_mode=True)
    set_book_locale(container.mi.language)
    pprint.pprint(get_all_words(container, dictionaries.default_locale))