[Python-Dev] webbrowser module

Peter Funk pf@artcom-gmbh.de
Fri, 7 Jul 2000 14:26:38 +0200 (MEST)


Hi,

Fred L. Drake, Jr.:
>   Ok, I've checked in the documentation for the webbrowser
> documentation.  The implementation can go in as soon as SF clears a
> bogus read lock (support request files 6.5 hours ago).
[...]

May I suggest the patch below?  It add's support for the 
Linux KDE file manager KFM (aka Konquerer) as the default 
web browser.  This esspecially makes sense on smaller Linux 
machines, where users don't want to spend the huge amount of 
memory needed by a browser bloated to no avail with trashy
stuff like Java / Javascript ....

Regards, Peter
-- 
Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260
office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen)
---- 8< ---- 8< ---- cut here ---- 8< ---- schnipp ---- 8< ---- schnapp ----
*** webbrowser.py.orig	Fri Jul  7 10:28:05 2000
--- webbrowser.py	Fri Jul  7 14:08:32 2000
***************
*** 1,4 ****
! """Remote-control interfaces to some browsers."""
  
  import os
  import sys
--- 1,4 ----
! """webbrowser -- Remote-control interfaces to some browsers."""
  
  import os
  import sys
***************
*** 30,35 ****
--- 30,36 ----
          L[1] = L[0]()
      return L[1]
  
+ # Please note: the following definition hides a builtin function.
  
  def open(url, new=0):
      get().open(url, new)
***************
*** 56,61 ****
--- 57,63 ----
      if os.environ.get("DISPLAY"):
          _browsers.extend([
              ("netscape", "netscape %s >/dev/null &"),
+ 	    ("kfmclient", "kfmclient openURL %s"),
              ("mosaic", "mosaic %s >/dev/null &"),
              ])
      _browsers.extend([
***************
*** 102,107 ****
--- 104,131 ----
  register("netscape", Netscape)
  
  
+ class Konquerer:
+     """see http://developer.kde.org/documentation/other/kfmclient.html"""
+     def _remote(self, action):
+         cmd = "kfmclient %s >/dev/null 2>&1" % action
+         rc = os.system(cmd)
+         if rc:
+             import time
+             os.system("kfm -d &")
+             time.sleep(PROCESS_CREATION_DELAY)
+             rc = os.system(cmd)
+         return not rc
+ 
+     def open(self, url, new=1):
+ 	# XXX currently I know no way to prevent KFM from opening a new win.
+         self.open_new(url)
+ 
+     def open_new(self, url):
+         self._remote("openURL %s" % url)
+ 
+ register("kfm", Konquerer)
+ 
+ 
  class Grail:
      # There should be a way to maintain a connection to Grail, but the
      # Grail remote control protocol doesn't really allow that at this
***************
*** 167,172 ****
--- 191,208 ----
      DEFAULT_BROWSER = "windows-default"
  elif not os.environ.get("DISPLAY"):
      DEFAULT_BROWSER = "command-line-browser"
+ elif sys.platform == "linux2":
+     def small_ram():
+ 	"""returns True on machines with less than 128 MB Ram"""
+ 	import string, __builtin__
+         memtotal = long(string.split(
+ 	    __builtin__.open("/proc/meminfo").readlines()[1])[1])
+ 	return memtotal < 128L * 1024 * 1024 # less than 128 MB
+ 
+     if small_ram():	
+ 	DEFAULT_BROWSER = "kfm"
+     else:
+ 	DEFAULT_BROWSER = "netscape"
  else:
      DEFAULT_BROWSER = "netscape"