This commit was manufactured by cvs2svn to create tag
[python/dscho.git] / Mac / Lib / nsremote.py
bloba12cd350bdfe2e3c322c80d34e5d59ab519e0dac
1 """nsremote - Control Netscape from python.
3 Interface modelled after unix-interface done
4 by hassan@cs.stanford.edu.
6 Jack Jansen, CWI, January 1996.
7 """
9 # Note: this module currently uses the funny SpyGlass AppleEvents, since
10 # these seem to be the only way to get the info from Netscape. It would
11 # be nicer to use the more "object oriented" standard OSA stuff, when it
12 # is implemented in Netscape.
14 import sys
16 import aetools
17 import Netscape
18 import MacOS
20 Error = 'nsremote.Error'
22 _talker = None
24 def _init():
25 global _talker
26 if _talker == None:
27 _talker = Netscape.Netscape()
29 def list(dpyinfo=""):
30 _init()
31 list = _talker.list_windows()
32 return map(lambda x: (x, 'version unknown'), list)
34 def geturl(windowid=0, dpyinfo=""):
35 _init()
36 if windowid == 0:
37 ids = _talker.list_windows()
38 if not ids:
39 raise Error, 'No netscape windows open'
40 windowid = ids[0]
41 info = _talker.get_window_info(windowid)
42 return info
44 def openurl(url, windowid=0, dpyinfo=""):
45 _init()
46 if windowid == 0:
47 _talker.OpenURL(url)
48 else:
49 _talker.OpenURL(url, toWindow=windowid)
51 def _test():
52 """Test program: Open www.python.org in all windows, then revert"""
53 import sys
54 windows_and_versions = list()
55 windows_and_urls = map(lambda x: (x[0], geturl(x[0])[0]), windows_and_versions)
56 for id, version in windows_and_versions:
57 openurl('http://www.python.org/', windowid=id)
58 print 'Type return to revert to old contents-'
59 sys.stdin.readline()
60 for id, url in windows_and_urls:
61 openurl(url, id)
63 if __name__ == '__main__':
64 _test()