Example #1
0
    def set_url(self, url, baseurl=None, target=None, histify=1):
        """Set loaded URL, base URL and target for the current page.

        The loaded URL is what this page was loaded from; the base URL
        is used to calculate relative links, and defaults to the
        loaded URL.  The target is the default viewer name
        where followed links will appear, and defaults to this viewer.

        HISTIFY flag, if true, adds the URL to the history stack.

        """
        if url and histify:
            # don't lose title if we have one:
            title, when = self.app.global_history.lookup_url(url)
            self.app.global_history.remember_url(url, title or '')
            if not self.page:
                self.page = History.PageInfo(url)
                self.history.append_page(self.page)
            else:
                self.page.set_url(url)
                self.page.set_title("")  # Will be reset from fresh HTML
                self.history.refresh()
        else:
            if self.future >= 0:
                self.page = self.history.page(self.future)
                self.future = -1
            else:
                self.page = None
        URIContext.set_url(self, url, baseurl=baseurl)
        self._target = target
        if self.on_top():
            self.browser.set_url(self.get_url())
        self.applet_group = None
Example #2
0
    def set_url(self, url, baseurl=None, target=None, histify=1):
        """Set loaded URL, base URL and target for the current page.

        The loaded URL is what this page was loaded from; the base URL
        is used to calculate relative links, and defaults to the
        loaded URL.  The target is the default viewer name
        where followed links will appear, and defaults to this viewer.

        HISTIFY flag, if true, adds the URL to the history stack.

        """
        if url and histify:
            # don't lose title if we have one:
            title, when = self.app.global_history.lookup_url(url)
            self.app.global_history.remember_url(url, title or '')
            if not self.page:
                self.page = History.PageInfo(url)
                self.history.append_page(self.page)
            else:
                self.page.set_url(url)
                self.page.set_title("") # Will be reset from fresh HTML
                self.history.refresh()
        else:
            if self.future >= 0:
                self.page = self.history.page(self.future)
                self.future = -1
            else:
                self.page = None
        URIContext.set_url(self, url, baseurl=baseurl)
        self._target = target
        if self.on_top():
            self.browser.set_url(self.get_url())
        self.applet_group = None
Example #3
0
    def set_baseurl(self, baseurl=None, target=None):
        """Set the base URL and target for the current page.

        The base URL is taken relative to the existing base URL.

        """
        URIContext.set_baseurl(self, baseurl)
        if target:
            self._target = target
Example #4
0
    def set_baseurl(self, baseurl=None, target=None):
        """Set the base URL and target for the current page.

        The base URL is taken relative to the existing base URL.

        """
        URIContext.set_baseurl(self, baseurl)
        if target:
            self._target = target
Example #5
0
 def __init__(self, viewer, browser):
     URIContext.__init__(self)
     self.viewer = viewer
     self.browser = browser
     self.history = History.History()
     self.history_dialog = None
     self.app = browser.app
     self.root = self.browser.root   # XXX Really a Toplevel instance
     self.readers = []
     self.page = None
     self.future = -1
     self.source = None
     self._target = None
     self.last_status_update = 0.0   # Time when last status update was done
     self.next_status_update = None  # ID of next scheduled status update
     self.show_source = 0
     self.applet_group = None
     self.notifications = []         # callbacks when no readers left
     self.image_maps = {}            # For ImageMap
     self.set_headers({})
     self.set_postdata(None)
     self.local_api_handlers = {}    # This pages local API handlers
Example #6
0
 def __init__(self, viewer, browser):
     URIContext.__init__(self)
     self.viewer = viewer
     self.browser = browser
     self.history = History.History()
     self.history_dialog = None
     self.app = browser.app
     self.root = self.browser.root  # XXX Really a Toplevel instance
     self.readers = []
     self.page = None
     self.future = -1
     self.source = None
     self._target = None
     self.last_status_update = 0.0  # Time when last status update was done
     self.next_status_update = None  # ID of next scheduled status update
     self.show_source = 0
     self.applet_group = None
     self.notifications = []  # callbacks when no readers left
     self.image_maps = {}  # For ImageMap
     self.set_headers({})
     self.set_postdata(None)
     self.local_api_handlers = {}  # This pages local API handlers
Example #7
0
    #
    # open the output file
    #
    if outfile[0] == '|':
        cmd = string.strip(outfile[1:])
        outfile = '|' + cmd
        outfp = os.popen(cmd, 'w')
    elif outfile == '-':
        outfp = sys.stdout
    else:
        outfp = open(outfile, 'w')
    if outfile != '-':
        print 'Outputting PostScript to', outfile

    if url:
        context = URIContext(url)
    elif infile:
        url = infile
        context = URIContext(url)
    else:
        # BOGOSITY: reading from stdin
        context = URIContext("file:/index.html")
    context.app = app
    paper = printing.paper.PaperInfo(settings.papersize,
                                     margins=settings.margins,
                                     rotation=settings.orientation)
    if tabstop and tabstop > 0:
        paper.TabStop = tabstop
    if utils.get_debugging('paper'):
        paper.dump()
    # create the writer & parser
Example #8
0
    #
    # open the output file
    #
    if outfile[0] == '|':
        cmd = string.strip(outfile[1:])
        outfile = '|' + cmd
        outfp = os.popen(cmd, 'w')
    elif outfile == '-':
        outfp = sys.stdout
    else:
        outfp = open(outfile, 'w')
    if outfile != '-':
        print 'Outputting PostScript to', outfile

    if infile:
        context = URIContext(infile)
        if not url:
            url = infile
    else:
        # BOGOSITY: reading from stdin
        context = URIContext("file:/index.html")
    context.app = app
    paper = printing_paper.PaperInfo(settings.papersize,
                                     margins=settings.margins,
                                     rotation=settings.orientation)
    if tabstop and tabstop > 0:
        paper.TabStop = tabstop
    if utils.get_debugging('paper'):
        paper.dump()
    # create the writer & parser
    fontsize, leading = settings.get_fontsize()
def run(app):
    global logfile
    import getopt
    import paper
    import settings
    settings = settings.get_settings(app.prefs)
    # do this after loading the settings so the user can just call
    # get_settings() w/out an arg to get a usable object.
    load_rcscript()
    context = None
    help = None
    error = 0
    logfile = None
    title = ''
    url = ''
    tabstop = None
    multi = 0
    verbose = 0
    printer = None
    copies = 1
    levels = None
    outfile = None
    #
    try:
        options, args = getopt.getopt(sys.argv[1:],
                                      'mvhdcaUl:u:t:sp:o:f:C:P:T:', [
                                          'color',
                                          'copies=',
                                          'debug',
                                          'fontsize=',
                                          'footnote-anchors',
                                          'help',
                                          'images',
                                          'logfile=',
                                          'multi',
                                          'orientation=',
                                          'output=',
                                          'papersize=',
                                          'paragraph-indent=',
                                          'paragraph-skip=',
                                          'printer=',
                                          'strict-parsing',
                                          'tab-width=',
                                          'tags=',
                                          'title=',
                                          'underline-anchors',
                                          'url=',
                                          'verbose',
                                      ])
    except getopt.error as err:
        error = 1
        help = 1
        options = ()
        sys.stderr.write("option failure: %s\n" % err)
    for opt, arg in options:
        if opt in ('-h', '--help'):
            help = 1
        elif opt in ('-a', '--footnote-anchors'):
            settings.footnoteflag = not settings.footnoteflag
        elif opt in ('-i', '--images'):
            settings.imageflag = not settings.imageflag
        elif opt in ('-d', '--debug'):
            utils.set_debugging(1)
        elif opt in ('-l', '--logfile'):
            logfile = arg
        elif opt in ('-o', '--orientation'):
            settings.orientation = arg
        elif opt in ('-f', '--fontsize'):
            settings.set_fontsize(arg)
        elif opt in ('-t', '--title'):
            title = arg
        elif opt in ('-u', '--url'):
            url = arg
        elif opt in ('-U', '--underline-anchors'):
            settings.underflag = not settings.underflag
        elif opt in ('-c', '--color'):
            settings.greyscale = not settings.greyscale
        elif opt in ('-p', '--papersize'):
            settings.papersize = arg
        elif opt in ('-s', '--strict-parsing'):
            settings.strict_parsing = not settings.strict_parsing
        elif opt in ('-C', '--copies'):
            copies = int(arg)
        elif opt in ('-P', '--printer'):
            printer = arg
        elif opt in ('-T', '--tab-width'):
            tabstop = float(arg)
        elif opt in ('-m', '--multi'):
            multi = 1
        elif opt in ('-v', '--verbose'):
            verbose = verbose + 1
        elif opt == '--output':
            outfile = arg
        elif opt == '--tags':
            if not load_tag_handler(app, arg):
                error = 2
                help = 1
        elif opt == '--paragraph-indent':
            # negative indents should indicate hanging indents, but we don't
            # do those yet, so force to normal interpretation
            settings.paragraph_indent = max(float(arg), 0.0)
        elif opt == '--paragraph-skip':
            settings.paragraph_skip = max(float(arg), 0.0)
    if help:
        usage(settings)
        sys.exit(error)
    # crack open log file if given
    stderr = sys.stderr
    if logfile:
        try:
            sys.stderr = open(logfile, 'a')
        except IOError:
            sys.stderr = stderr
    utils.debug("Using Python version " + sys.version)
    # crack open the input file, or stdin
    outfp = None
    if printer:
        if copies < 1:
            copies = 1
        outfile = "|lpr -#%d -P%s" % (copies, printer)
    if args:
        infile = args[0]
        if args[1:]:
            multi = 1
        infp, outfn = open_source(infile)
        if not outfile:
            outfile = (os.path.splitext(outfn)[0] or 'index') + '.ps'
    else:
        infile = None
        infp = sys.stdin
        outfile = '-'
    #
    # open the output file
    #
    if outfile[0] == '|':
        cmd = str.strip(outfile[1:])
        outfile = '|' + cmd
        outfp = os.popen(cmd, 'w')
    elif outfile == '-':
        outfp = sys.stdout
    else:
        outfp = open(outfile, 'w')
    if outfile != '-':
        print('Outputting PostScript to', outfile)

    if url:
        context = URIContext(url)
    elif infile:
        url = infile
        context = URIContext(url)
    else:
        # BOGOSITY: reading from stdin
        context = URIContext("file:/index.html")
    context.app = app
    paper = printing.paper.PaperInfo(settings.papersize,
                                     margins=settings.margins,
                                     rotation=settings.orientation)
    if tabstop and tabstop > 0:
        paper.TabStop = tabstop
    if utils.get_debugging('paper'):
        paper.dump()
    # create the writer & parser
    fontsize, leading = settings.get_fontsize()
    w = PSWriter.PSWriter(
        outfp,
        title or None,
        url or '',
        #varifamily='Palatino',
        paper=paper,
        settings=settings)
    ctype = "text/html"
    mod = app.find_type_extension("printing.filetypes", ctype)
    if not mod.parse:
        sys.exit("cannot load printing support for " + ctype)
    p = mod.parse(w, settings, context)
    if multi:
        if args[1:]:
            xform = explicit_multi_transform(args[1:])
        else:
            xform = multi_transform(context, levels)
        p.add_anchor_transform(xform)
        p.feed(infp.read())
        docs = [(context.get_url(), 1, w.ps.get_title(), 1)]
        #
        # This relies on xform.get_subdocs() returning the list used
        # internally to accumulate subdocs.  Make a copy to go only one
        # level deep.
        #
        for url in xform.get_subdocs():
            xform.set_basedoc(url)
            while p.sgml_parser.get_depth():
                p.sgml_parser.lex_endtag(p.sgml_parser.get_stack()[0])
            try:
                infp, fn = open_source(url)
            except IOError as err:
                if verbose and outfp is not sys.stdout:
                    print("Error opening subdocument", url)
                    print("   ", err)
            else:
                new_ctype = get_ctype(app, url, infp)
                if new_ctype != ctype:
                    if verbose:
                        print("skipping", url)
                        print("  wrong content type:", new_ctype)
                    continue
                if verbose and outfp is not sys.stdout:
                    print("Subdocument", url)
                w.ps.close_line()
                if MULTI_DO_PAGE_BREAK:  # must be true for now, not sure why
                    pageend = w.ps.push_page_end()
                    context.set_url(url)
                    w.ps.set_pageno(w.ps.get_pageno() + 1)
                    w.ps.set_url(url)
                    w.ps.push_page_start(pageend)
                else:
                    context.set_url(url)
                    w.ps.set_url(url)
                pageno = w.ps.get_pageno()
                p.feed(infp.read())
                infp.close()
                title = w.ps.get_title()
                p._set_docinfo(url, pageno, title)
                spec = (url, pageno, title, xform.get_level(url))
                docs.append(spec)
    else:
        p.feed(infp.read())
    p.close()
    w.close()