except ImportError, e: # Only catch this is grailrc itself doesn't import, # otherwise propogate. if string.split(e.args[0])[-1] != "grailrc": raise except: app.exception_dialog('during import of startup file') # Load the initial page (command line argument or from preferences) if not embedded: from Browser import Browser browser = Browser(app.root, app, geometry=geometry) if url: browser.context.load(url) elif prefs.GetBoolean('browser', 'load-initial-page'): browser.home_command() if not embedded: # Give the user control app.go() class URLReadWrapper: def __init__(self, api, meta): self.api = api self.meta = meta self.eof = 0 def read(self, nbytes=-1): buf = ''
def main(args=None): prefs = grailbase.GrailPrefs.AllPreferences() # XXX Disable cache for NT if sys.platform == 'win32': prefs.Set('disk-cache', 'size', '0') global ilu_tk ilu_tk = 0 if prefs.GetBoolean('security', 'enable-ilu'): try: import ilu_tk except ImportError: pass if args is not None: embedded = 1 else: args = sys.argv[1:] embedded = 0 try: opts, args = getopt.getopt(args, 'd:g:iq', ['display=', 'geometry=', 'noimages']) if len(args) > 1: raise getopt.error("too many arguments") except getopt.error as msg: sys.stdout = sys.stderr print("Command line error:", msg) print(USAGE) sys.exit(2) geometry = prefs.Get('browser', 'initial-geometry') display = None user_init = 1 for o, a in opts: if o in ('-i', '--noimages'): load_images = 0 if o in ('-g', '--geometry'): geometry = a if o in ('-d', '--display'): display = a if o == "-q": user_init = 0 if args: url = grailutil.complete_url(args[0]) else: url = None global app app = Application(prefs=prefs, display=display) app.embedded = embedded if __name__ != '__main__': import __main__ __main__.app = app __main__.GRAILVERSION = GRAILVERSION def load_images_vis_prefs(app=app): app.load_images = app.prefs.GetBoolean('browser', 'load-images') try: app.load_images = load_images except NameError: load_images_vis_prefs() prefs.AddGroupCallback('browser', load_images_vis_prefs) from utils import Safetkinter Safetkinter._castrate(app.root.tk) tktools.install_keybindings(app.root) # Make everybody who's still using urllib.urlopen go through the cache urllib.urlopen = app.open_url_simple # Add $GRAILDIR/user/ to sys.path subdir = os.path.join(app.graildir, 'user') if subdir not in sys.path: sys.path.insert(0, subdir) # Import user's grail startup file, defined as # $GRAILDIR/user/grailrc.py if it exists. if user_init: try: from SampleGrailDir import grailrc except ImportError as e: # Only catch this if grailrc itself doesn't import, # otherwise propogate. if str.split(e.args[0])[-1] != "grailrc": raise except: app.exception_dialog('during import of startup file') # Load the initial page (command line argument or from preferences) if not embedded: from Browser import Browser browser = Browser(app.root, app, geometry=geometry) if url: browser.context.load(url) elif prefs.GetBoolean('browser', 'load-initial-page'): browser.home_command() if not embedded: # Give the user control app.go()
except ImportError, e: # Only catch this if grailrc itself doesn't import, # otherwise propagate. if string.split(e.args[0])[-1] != "grailrc": raise except: app.exception_dialog('during import of startup file') # Load the initial page (command line argument or from preferences) if not embedded: from Browser import Browser browser = Browser(app.root, app, geometry=geometry) if url: browser.context.load(url) elif prefs.GetBoolean('browser', 'load-initial-page'): browser.home_command() if not embedded: # Give the user control app.go() class URLReadWrapper: def __init__(self, api, meta): self.api = api self.meta = meta self.eof = 0 def read(self, nbytes=-1): buf = ''