On Tue, 2005-09-08 at 11:01 +0200, Luigi Pantano wrote:
> i want create a help browser like this:
> http://www.cs.cf.ac.uk/systems/html/322/node7.html
> but multiplatform.
> 

Why create one when you can just import one from python.


Here is some code from our program.  we recently added a custom web
browser choice if the user wishes rather than the the default web
browser that python knows about.  dprint() is our utils print function
that prints to stderr if the debug flag was passed at startup.

[code]


# if using gnome, see if we can import it
try:
    import gnome
    try:
        import gnomevfs
    except: # try the depricated module
        import gnome.vfs
except ImportError:
    # no gnome module
    #print >>stderr, ('Module "gnome" not found. '
    #                 'You will not be able to use gnome to open web pages.')
    dprint('LOADERS: Module "gnome" not found. '
           'You will not be able to use gnome to open web pages.')
    
# get the standard webbrowser module
try:
    import webbrowser
except ImportError:
    #print >>stderr, ('Module "webbrowser" not found. '
    #                 'You may not be able to open web pages.')
    dprint(' * LOADERS: Module "webbrowser" not found. You may not be able to 
open web pages.')


def load_web_page(name, prefs):
    """Try to load a web page in the default browser"""
    dprint("LOADERS: load_web_page(); starting browser thread")
    browser = web_page(name, prefs)
    browser.start()
    return

def load_help_page(name, prefs):
    """Load a locale-specific help page with the default browser."""
    dprint("LOADERS: load_help_page: %s" % name)
    lc = prefs.globals.LANG
    if not lc: lc = "en"
    helpdir = os.path.join(prefs.DATA_PATH, 'help')
    if os.access(os.path.join(helpdir, lc, name), os.R_OK):
        pagename = "file://" + os.path.join(helpdir, lc, name)
    elif os.access(os.path.join(helpdir, lc.split('_')[0], name), os.R_OK):
        pagename = "file://" + os.path.join(helpdir, lc.split('_')[0], name)
    elif os.access(os.path.join(helpdir, "en", name), os.R_OK):
        pagename = "file://" + os.path.join(helpdir, "en", name)
    else:
        dprint(" * LOADERS: failed to find help file '%s' with LANG='%s'!" %
            (name, prefs.globals.LANG))
        return False
    load_web_page(pagename, prefs)


class web_page(threading.Thread):
    """Try to load a web page in the default browser"""
    def __init__(self, name, prefs):
        dprint("LOADERS: web_page.__init__()")
        threading.Thread.__init__(self)
        self.name = name
        self.prefs = prefs
        self.setDaemon(1)  # quit even if this thread is still running

    def run(self):
        dprint("LOADERS: web_page.run()")
        if self.name == '' or self.name == None:
            return
        if self.prefs.globals.use_custom_browser:
            command = self.prefs.globals.custom_browser_command
            if '%s' not in command: command += ' %s'
            browser = webbrowser.GenericBrowser(command)
            try:
                browser.open(self.name)
            except:
                dprint("LOADERS: failed to open '%s' with browser command '%s'" 
% (self.name, command))
        else:
            try:
                gnome.url_show(self.name)
            except:
                dprint("LOADERS: Gnome failed trying to open: %s" %self.name)
                try:
                    webbrowser.open(self.name)
                except:
                    dprint("LOADERS: webbrowser failed trying to open: %s  -- 
giving up" %self.name)
                    pass
        dprint("LOADERS: Browser call_completed for: %s" %self.name)

[/code]
-- 
Brian <[EMAIL PROTECTED]>

_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to