コード例 #1
0
def main():
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    with make_temporary_directory() as out_dir:
        with hwp5html(args['<hwp5file>'], out_dir) as index_path:
            base_uri = fspath2url(out_dir) + '/'
            # index_uri = fspath2url(index_path)
            with file(index_path) as f:
                content = f.read()

            view = WebKit.WebView()
            # view.load_uri(index_uri)
            view.load_string(content, 'text/html', 'utf-8', base_uri)

            scrolled_window = Gtk.ScrolledWindow()
            scrolled_window.add(view)

            vbox = Gtk.VBox()
            vbox.pack_start(scrolled_window, expand=True, fill=True, padding=0)

            window = Gtk.Window()
            window.add(vbox)
            window.connect('delete-event', Gtk.main_quit)
            window.set_default_size(600, 400)
            window.show_all()

            Gtk.main()
コード例 #2
0
ファイル: hwp5view.py プロジェクト: sececter/pyhwp
def main():
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    with make_temporary_directory() as out_dir:
        with hwp5html(args['<hwp5file>'], out_dir) as index_path:
            base_uri = fspath2url(out_dir) + '/'
            # index_uri = fspath2url(index_path)
            with file(index_path) as f:
                content = f.read()

            view = WebKit.WebView()
            # view.load_uri(index_uri)
            view.load_string(content, 'text/html', 'utf-8', base_uri)

            scrolled_window = Gtk.ScrolledWindow()
            scrolled_window.add(view)

            vbox = Gtk.VBox()
            vbox.pack_start(scrolled_window, expand=True, fill=True, padding=0)

            window = Gtk.Window()
            window.add(vbox)
            window.connect('delete-event', Gtk.main_quit)
            window.set_default_size(600, 400)
            window.show_all()

            Gtk.main()
コード例 #3
0
ファイル: hwp5view.py プロジェクト: hongry18/pyhwp
def main():
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    with make_temporary_directory() as out_dir:
        with hwp5html(args['<hwp5file>'], out_dir) as index_path:
            base_uri = fspath2url(out_dir) + '/'
            # index_uri = fspath2url(index_path)
            with file(index_path) as f:
                content = f.read()

            view = WebKit.WebView()
            # view.load_uri(index_uri)
            view.load_string(content, 'text/html', 'utf-8', base_uri)

            def on_load(webview, webframe):
                script = ('window.location.href = "dimension:" '
                          '+ document.body.scrollWidth + "x"'
                          '+ document.body.scrollHeight')
                webview.execute_script(script)

            MIN_WIDTH = 300
            MIN_HEIGHT = 400
            MAX_WIDTH = 1024
            MAX_HEIGHT = 800

            view.connect('load-finished', on_load)

            def on_navigation_requested(webview, frame, req, data=None):
                uri = req.get_uri()
                scheme, path = uri.split(':', 1)
                if scheme == 'dimension':
                    width, height = path.split('x', 1)
                    width = int(width)
                    height = int(height)
                    width = min(width, MAX_WIDTH)
                    height = min(height, MAX_HEIGHT)
                    width = max(width, MIN_WIDTH)
                    height = max(height, MIN_HEIGHT)
                    window.resize(width + 4, height)
                    return True
                return False

            view.connect('navigation-requested', on_navigation_requested)

            scrolled_window = Gtk.ScrolledWindow()
            scrolled_window.add(view)

            vbox = Gtk.VBox()
            vbox.pack_start(scrolled_window, expand=True, fill=True, padding=0)

            window = Gtk.Window()
            window.add(vbox)
            window.connect('delete-event', Gtk.main_quit)
            window.set_default_size(600, 800)
            window.show_all()

            Gtk.main()
コード例 #4
0
def main():
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    with make_temporary_directory() as out_dir:
        with hwp5html(args['<hwp5file>'], out_dir) as index_path:
            base_uri = fspath2url(out_dir) + '/'
            # index_uri = fspath2url(index_path)
            with file(index_path) as f:
                content = f.read()

            view = WebKit.WebView()
            # view.load_uri(index_uri)
            view.load_string(content, 'text/html', 'utf-8', base_uri)

            def on_load(webview, webframe):
                script = ('window.location.href = "dimension:" '
                          '+ document.body.scrollWidth + "x"'
                          '+ document.body.scrollHeight')
                webview.execute_script(script)

            MIN_WIDTH = 300
            MIN_HEIGHT = 400
            MAX_WIDTH = 1024
            MAX_HEIGHT = 800

            view.connect('load-finished', on_load)

            def on_navigation_requested(webview, frame, req, data=None):
                uri = req.get_uri()
                scheme, path = uri.split(':', 1)
                if scheme == 'dimension':
                    width, height = path.split('x', 1)
                    width = int(width)
                    height = int(height)
                    width = min(width, MAX_WIDTH)
                    height = min(height, MAX_HEIGHT)
                    width = max(width, MIN_WIDTH)
                    height = max(height, MIN_HEIGHT)
                    window.resize(width + 4, height)
                    return True
                return False

            view.connect('navigation-requested', on_navigation_requested)

            scrolled_window = Gtk.ScrolledWindow()
            scrolled_window.add(view)

            vbox = Gtk.VBox()
            vbox.pack_start(scrolled_window, expand=True, fill=True, padding=0)

            window = Gtk.Window()
            window.add(vbox)
            window.connect('delete-event', Gtk.main_quit)
            window.set_default_size(600, 800)
            window.show_all()

            Gtk.main()
コード例 #5
0
ファイル: hwp5txt.py プロジェクト: ParanScreen/dimidisk-hwp
def main():
    from hwp5 import __version__ as version
    from hwp5.proc import rest_to_docopt
    from hwp5.proc import init_logger
    from docopt import docopt
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    make(args)
コード例 #6
0
def main():
    from hwp5 import __version__ as version
    from hwp5.proc import rest_to_docopt
    from hwp5.proc import init_logger
    from docopt import docopt
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    make(args)
コード例 #7
0
def main():
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    runner = runner_factory()

    with make_temporary_directory() as out_dir:
        with hwp5html(args['<hwp5file>'], out_dir) as index_path:
            runner(args, index_path, out_dir)
コード例 #8
0
ファイル: __init__.py プロジェクト: ParanScreen/dimidisk-hwp
        def main(argv):
            from docopt import docopt
            from hwp5 import __version__
            from hwp5.errors import InvalidHwp5FileError
            from hwp5.dataio import ParseError
            from hwp5.proc import rest_to_docopt
            from hwp5.proc import init_logger

            doc = rest_to_docopt(rest_doc)
            args = docopt(doc, version=__version__, argv=argv)
            init_logger(args)

            try:
                return f(args)
            except InvalidHwp5FileError, e:
                logger.error('%s', e)
                return 1
コード例 #9
0
ファイル: __init__.py プロジェクト: yarang/pyhwp
        def main(argv):
            from docopt import docopt
            from hwp5 import __version__
            from hwp5.errors import InvalidHwp5FileError
            from hwp5.dataio import ParseError
            from hwp5.proc import rest_to_docopt
            from hwp5.proc import init_logger

            doc = rest_to_docopt(rest_doc)
            args = docopt(doc, version=__version__, argv=argv)
            init_logger(args)

            try:
                return f(args)
            except InvalidHwp5FileError, e:
                logger.error('%s', e)
                return 1
コード例 #10
0
ファイル: hwp5html.py プロジェクト: sececter/pyhwp
def main():
    import sys
    from hwp5 import __version__ as version
    from hwp5.proc import rest_to_docopt
    from hwp5.proc import init_logger
    from hwp5.errors import InvalidHwp5FileError
    from docopt import docopt
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    filename = args['<hwp5file>']
    from hwp5.dataio import ParseError
    from hwp5.xmlmodel import Hwp5File
    try:
        hwp5file = Hwp5File(filename)
    except ParseError, e:
        e.print_to_logger(logger)
        sys.exit(1)
コード例 #11
0
ファイル: hwp5odt.py プロジェクト: hanul93/pyhwp
def main():
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    init_with_environ()

    convert = make_converter(args)

    hwpfilename = args['<hwp5file>']
    root = os.path.basename(hwpfilename)
    if root.lower().endswith('.hwp'):
        root = root[0:-4]
    dest_path = root + '.' + convert.dest_ext

    from hwp5.dataio import ParseError
    try:
        with convert.prepare():
            convert.convert(hwpfilename, dest_path)
    except ParseError, e:
        e.print_to_logger(logger)
コード例 #12
0
ファイル: hwp5odt.py プロジェクト: sececter/pyhwp
def main():
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    init_with_environ()

    convert = make_converter(args)

    hwpfilename = args['<hwp5file>']
    root = os.path.basename(hwpfilename)
    if root.lower().endswith('.hwp'):
        root = root[0:-4]
    dest_path = root + '.' + convert.dest_ext

    from hwp5.dataio import ParseError
    try:
        with convert.prepare():
            convert.convert(hwpfilename, dest_path)
    except ParseError, e:
        e.print_to_logger(logger)
コード例 #13
0
ファイル: hwp5odt.py プロジェクト: idkwim/pyhwp
def main():
    import os
    import sys
    from hwp5 import __version__ as version
    from hwp5.proc import rest_to_docopt
    from hwp5.proc import init_logger
    from hwp5 import plat
    from hwp5.errors import InvalidHwp5FileError
    from docopt import docopt
    doc = rest_to_docopt(__doc__)
    args = docopt(doc, version=version)
    init_logger(args)

    if 'PYHWP_XSLTPROC' in os.environ:
        from hwp5.plat import xsltproc
        xsltproc.executable = os.environ['PYHWP_XSLTPROC']
        xsltproc.enable()

    if 'PYHWP_XMLLINT' in os.environ:
        from hwp5.plat import xmllint
        xmllint.executable = os.environ['PYHWP_XMLLINT']
        xmllint.enable()

    xslt = plat.get_xslt()
    if xslt is None:
        logger.error('no XSLT implementation is available.')
        sys.exit(1)

    rng = plat.get_relaxng()
    if rng is None:
        logger.warning('no RelaxNG implementation is available.')

    convert = Converter(xslt, rng)

    from hwp5.dataio import ParseError
    try:
        make(convert, args)
    except ParseError, e:
        e.print_to_logger(logger)