Пример #1
0
def launch_editor(path_to_edit,
                  path_is_raw=False,
                  syntax='html',
                  callback=None):
    from calibre.gui2.tweak_book import dictionaries
    from calibre.gui2.tweak_book.main import option_parser
    from calibre.gui2.tweak_book.ui import Main
    from calibre.gui2.tweak_book.editor.syntax.html import refresh_spell_check_status
    dictionaries.initialize()
    refresh_spell_check_status()
    opts = option_parser().parse_args([])
    app = QApplication([])
    # Create the actions that are placed into the editors toolbars
    main = Main(opts)  # noqa
    if path_is_raw:
        raw = path_to_edit
    else:
        with open(path_to_edit, 'rb') as f:
            raw = f.read().decode('utf-8')
        ext = path_to_edit.rpartition('.')[-1].lower()
        if ext in ('html', 'htm', 'xhtml', 'xhtm'):
            syntax = 'html'
        elif ext in ('css', ):
            syntax = 'css'
    t = Editor(syntax)
    t.data = raw
    if callback is not None:
        callback(t)
    t.show()
    app.exec_()
Пример #2
0
def launch_editor(path_to_edit, path_is_raw=False, syntax='html', callback=None):
    from calibre.gui2.tweak_book import dictionaries
    from calibre.gui2.tweak_book.main import option_parser
    from calibre.gui2.tweak_book.ui import Main
    from calibre.gui2.tweak_book.editor.syntax.html import refresh_spell_check_status
    dictionaries.initialize()
    refresh_spell_check_status()
    opts = option_parser().parse_args([])
    app = QApplication([])
    # Create the actions that are placed into the editors toolbars
    main = Main(opts)  # noqa
    if path_is_raw:
        raw = path_to_edit
    else:
        with open(path_to_edit, 'rb') as f:
            raw = f.read().decode('utf-8')
        ext = path_to_edit.rpartition('.')[-1].lower()
        if ext in ('html', 'htm', 'xhtml', 'xhtm'):
            syntax = 'html'
        elif ext in ('css',):
            syntax = 'css'
    t = Editor(syntax)
    t.data = raw
    if callback is not None:
        callback(t)
    t.show()
    app.exec_()
Пример #3
0
def options(option_parser):
    parser = option_parser()
    options = parser.option_list
    for group in parser.option_groups:
        options += group.option_list
    opts = []
    for opt in options:
        opts.extend(opt._short_opts)
        opts.extend(opt._long_opts)
    return opts
Пример #4
0
def options(option_parser):
    parser = option_parser()
    options = parser.option_list
    for group in parser.option_groups:
        options += group.option_list
    opts = []
    for opt in options:
        opts.extend(opt._short_opts)
        opts.extend(opt._long_opts)
    return opts
Пример #5
0
    def do_ebook_edit(self, f):
        from calibre.ebooks.oeb.polish.main import SUPPORTED
        from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
        from calibre.gui2.tweak_book.main import option_parser
        tweakable_fmts = SUPPORTED | IMPORTABLE
        parser = option_parser()
        opt_lines = []
        for opt in parser.option_list:
            lo, so = opt._long_opts, opt._short_opts
            if opt.takes_value():
                lo = [x + '=' for x in lo]
                so = [x + '+' for x in so]
            ostrings = lo + so
            ostrings = u'{%s}' % ','.join(ostrings) if len(
                ostrings) > 1 else '"%s"' % ostrings[0]
            h = opt.help or ''
            h = h.replace('"',
                          "'").replace('[', '(').replace(']', ')').replace(
                              '\n', ' ').replace(':', '\\:').replace('`', "'")
            h = h.replace('%default', unicode_type(opt.default))
            help_txt = u'"[%s]"' % h
            opt_lines.append(ostrings + help_txt + ' \\')
        opt_lines = ('\n' + (' ' * 8)).join(opt_lines)

        polyglot_write(f)((u'''
_ebook_edit() {
    local curcontext="$curcontext" state line ebookfile expl
    typeset -A opt_args

    _arguments -C -s \\
        %s
        "1:ebook file:_files -g '(#i)*.(%s)'" \\
        '*:file in ebook:->files' && return 0

    case $state in
        files)
            ebookfile=${~${(Q)line[1]}}

            if [[ -f "$ebookfile" && "$ebookfile" =~ '\\.[eE][pP][uU][bB]$' ]]; then
                _zip_cache_name="$ebookfile"
                _zip_cache_list=( ${(f)"$(zipinfo -1 $_zip_cache_name 2>/dev/null)"} )
            else
                return 1
            fi
            _wanted files expl 'file from ebook' \\
            _multi_parts / _zip_cache_list && return 0
            ;;
    esac

    return 1
}
''' % (opt_lines, '|'.join(tweakable_fmts)) + '\n\n'))
Пример #6
0
    def do_ebook_edit(self, f):
        from calibre.ebooks.oeb.polish.main import SUPPORTED
        from calibre.ebooks.oeb.polish.import_book import IMPORTABLE
        from calibre.gui2.tweak_book.main import option_parser
        tweakable_fmts = SUPPORTED | IMPORTABLE
        parser = option_parser()
        opt_lines = []
        for opt in parser.option_list:
            lo, so = opt._long_opts, opt._short_opts
            if opt.takes_value():
                lo = [x+'=' for x in lo]
                so = [x+'+' for x in so]
            ostrings = lo + so
            ostrings = u'{%s}'%','.join(ostrings) if len(ostrings) > 1 else '"%s"'%ostrings[0]
            h = opt.help or ''
            h = h.replace('"', "'").replace('[', '(').replace(
                ']', ')').replace('\n', ' ').replace(':', '\\:').replace('`', "'")
            h = h.replace('%default', type(u'')(opt.default))
            help_txt = u'"[%s]"'%h
            opt_lines.append(ostrings + help_txt + ' \\')
        opt_lines = ('\n' + (' ' * 8)).join(opt_lines)

        f.write((ur'''
_ebook_edit() {
    local curcontext="$curcontext" state line ebookfile expl
    typeset -A opt_args

    _arguments -C -s \
        %s
        "1:ebook file:_files -g '(#i)*.(%s)'" \
        '*:file in ebook:->files' && return 0

    case $state in
        files)
            ebookfile=${~${(Q)line[1]}}

            if [[ -f "$ebookfile" && "$ebookfile" =~ '\.[eE][pP][uU][bB]$' ]]; then
                _zip_cache_name="$ebookfile"
                _zip_cache_list=( ${(f)"$(zipinfo -1 $_zip_cache_name 2>/dev/null)"} )
            else
                return 1
            fi
            _wanted files expl 'file from ebook' \
            _multi_parts / _zip_cache_list && return 0
            ;;
    esac

    return 1
}
''' % (opt_lines, '|'.join(tweakable_fmts)) + '\n\n').encode('utf-8'))
Пример #7
0
def launch_editor(path_to_edit, path_is_raw=False, syntax='html'):
    from calibre.gui2.tweak_book.main import option_parser
    from calibre.gui2.tweak_book.ui import Main
    opts = option_parser().parse_args([])
    app = QApplication([])
    # Create the actions that are placed into the editors toolbars
    main = Main(opts)  # noqa
    if path_is_raw:
        raw = path_to_edit
    else:
        with open(path_to_edit, 'rb') as f:
            raw = f.read().decode('utf-8')
        ext = path_to_edit.rpartition('.')[-1].lower()
        if ext in ('html', 'htm', 'xhtml', 'xhtm'):
            syntax = 'html'
        elif ext in ('css',):
            syntax = 'css'
    t = Editor(syntax)
    t.data = raw
    t.show()
    app.exec_()
Пример #8
0
def launch_editor(path_to_edit, path_is_raw=False, syntax='html'):
    from calibre.gui2.tweak_book.main import option_parser
    from calibre.gui2.tweak_book.ui import Main
    opts = option_parser().parse_args([])
    app = QApplication([])
    # Create the actions that are placed into the editors toolbars
    main = Main(opts)  # noqa
    if path_is_raw:
        raw = path_to_edit
    else:
        with open(path_to_edit, 'rb') as f:
            raw = f.read().decode('utf-8')
        ext = path_to_edit.rpartition('.')[-1].lower()
        if ext in ('html', 'htm', 'xhtml', 'xhtm'):
            syntax = 'html'
        elif ext in ('css', ):
            syntax = 'css'
    t = Editor(syntax)
    t.data = raw
    t.show()
    app.exec_()
Пример #9
0
def launch_editor(path_to_edit, path_is_raw=False, syntax="html"):
    from calibre.gui2.tweak_book.main import option_parser
    from calibre.gui2.tweak_book.ui import Main

    opts = option_parser().parse_args([])
    app = QApplication([])
    # Create the actions that are placed into the editors toolbars
    main = Main(opts)  # noqa
    if path_is_raw:
        raw = path_to_edit
    else:
        with open(path_to_edit, "rb") as f:
            raw = f.read().decode("utf-8")
        ext = path_to_edit.rpartition(".")[-1].lower()
        if ext in ("html", "htm", "xhtml", "xhtm"):
            syntax = "html"
        elif ext in ("css",):
            syntax = "css"
    t = Editor(syntax)
    t.data = raw
    t.show()
    app.exec_()
Пример #10
0
    def restore_all_defaults(self):
        for i in xrange(self.stacks.count()):
            w = self.stacks.widget(i)
            w.restore_defaults()

    def restore_current_defaults(self):
        self.stacks.currentWidget().restore_defaults()

    def accept(self):
        tprefs.set('preferences_geom', bytearray(self.saveGeometry()))
        for i in xrange(self.stacks.count()):
            w = self.stacks.widget(i)
            w.commit()
        QDialog.accept(self)

    def reject(self):
        tprefs.set('preferences_geom', bytearray(self.saveGeometry()))
        QDialog.reject(self)

if __name__ == '__main__':
    from calibre.gui2 import Application
    from calibre.gui2.tweak_book.main import option_parser
    from calibre.gui2.tweak_book.ui import Main
    app = Application([])
    opts = option_parser().parse_args(['dev'])
    main = Main(opts)
    d = Preferences(main)
    d.exec_()

Пример #11
0
def main():
    p = option_parser()
    opts, args = p.parse_args()
    PostInstall(opts)
    return 0
Пример #12
0
    def restore_all_defaults(self):
        for i in xrange(self.stacks.count()):
            w = self.stacks.widget(i)
            w.restore_defaults()

    def restore_current_defaults(self):
        self.stacks.currentWidget().restore_defaults()

    def accept(self):
        tprefs.set('preferences_geom', bytearray(self.saveGeometry()))
        for i in xrange(self.stacks.count()):
            w = self.stacks.widget(i)
            w.commit()
        QDialog.accept(self)

    def reject(self):
        tprefs.set('preferences_geom', bytearray(self.saveGeometry()))
        QDialog.reject(self)


if __name__ == '__main__':
    from calibre.gui2 import Application
    from calibre.gui2.tweak_book.main import option_parser
    from calibre.gui2.tweak_book.ui import Main
    app = Application([])
    opts = option_parser().parse_args(['dev'])
    main = Main(opts)
    d = Preferences(main)
    d.exec_()
Пример #13
0
def main():
    p = option_parser()
    opts, args = p.parse_args()
    PostInstall(opts)
    return 0
Пример #14
0
    def do_ebook_edit(self, f):
        from calibre.ebooks.oeb.polish.main import SUPPORTED
        from calibre.gui2.tweak_book.main import option_parser

        parser = option_parser()
        opt_lines = []
        for opt in parser.option_list:
            lo, so = opt._long_opts, opt._short_opts
            if opt.takes_value():
                lo = [x + "=" for x in lo]
                so = [x + "+" for x in so]
            ostrings = lo + so
            ostrings = u"{%s}" % ",".join(ostrings) if len(ostrings) > 1 else '"%s"' % ostrings[0]
            h = opt.help or ""
            h = (
                h.replace('"', "'")
                .replace("[", "(")
                .replace("]", ")")
                .replace("\n", " ")
                .replace(":", "\\:")
                .replace("`", "'")
            )
            h = h.replace("%default", type(u"")(opt.default))
            help_txt = u'"[%s]"' % h
            opt_lines.append(ostrings + help_txt + " \\")
        opt_lines = ("\n" + (" " * 8)).join(opt_lines)

        f.write(
            (
                ur"""
_ebook_edit() {
    local curcontext="$curcontext" state line ebookfile expl
    typeset -A opt_args

    _arguments -C -s \
        %s
        "1:ebook file:_files -g '(#i)*.(%s)'" \
        '*:file in ebook:->files' && return 0

    case $state in
        files)
            ebookfile=${~${(Q)line[1]}}

            if [[ -f "$ebookfile" && "$ebookfile" =~ '\.[eE][pP][uU][bB]$' ]]; then
                _zip_cache_name="$ebookfile"
                _zip_cache_list=( ${(f)"$(zipinfo -1 $_zip_cache_name 2>/dev/null)"} )
            else
                return 1
            fi
            _wanted files expl 'file from ebook' \
            _multi_parts / _zip_cache_list && return 0
            ;;
    esac

    return 1
}
"""
                % (opt_lines, "|".join(SUPPORTED))
                + "\n\n"
            ).encode("utf-8")
        )
Пример #15
0
        if changed:
            msg = ngettext(
                "One disabled confirmation prompt was restored",
                "{} disabled confirmation prompts were restored",
                changed,
            ).format(changed)
        info_dialog(self, _("Disabled confirmations restored"), msg, show=True)

    def accept(self):
        tprefs.set("preferences_geom", bytearray(self.saveGeometry()))
        for i in xrange(self.stacks.count()):
            w = self.stacks.widget(i)
            w.commit()
        QDialog.accept(self)

    def reject(self):
        tprefs.set("preferences_geom", bytearray(self.saveGeometry()))
        QDialog.reject(self)


if __name__ == "__main__":
    from calibre.gui2 import Application
    from calibre.gui2.tweak_book.main import option_parser
    from calibre.gui2.tweak_book.ui import Main

    app = Application([])
    opts = option_parser().parse_args(["dev"])
    main = Main(opts)
    d = Preferences(main)
    d.exec_()