blob: a12cd350bdfe2e3c322c80d34e5d59ab519e0dac [file] [log] [blame]
Jack Jansend3903251996-01-29 15:45:59 +00001"""nsremote - Control Netscape from python.
2
3Interface modelled after unix-interface done
4by hassan@cs.stanford.edu.
5
6Jack Jansen, CWI, January 1996.
7"""
8#
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.
13#
Jack Jansend3903251996-01-29 15:45:59 +000014import sys
15
Jack Jansend3903251996-01-29 15:45:59 +000016import aetools
Jack Jansen742ca032000-08-20 20:06:51 +000017import Netscape
Jack Jansend3903251996-01-29 15:45:59 +000018import MacOS
19
Jack Jansend3903251996-01-29 15:45:59 +000020Error = 'nsremote.Error'
21
22_talker = None
23
24def _init():
25 global _talker
26 if _talker == None:
Jack Jansen742ca032000-08-20 20:06:51 +000027 _talker = Netscape.Netscape()
Jack Jansend3903251996-01-29 15:45:59 +000028
29def list(dpyinfo=""):
30 _init()
31 list = _talker.list_windows()
32 return map(lambda x: (x, 'version unknown'), list)
33
34def 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
43
44def openurl(url, windowid=0, dpyinfo=""):
45 _init()
46 if windowid == 0:
47 _talker.OpenURL(url)
48 else:
49 _talker.OpenURL(url, toWindow=windowid)
50
51def _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)
62
63if __name__ == '__main__':
64 _test()
65