blob: d823216bcb6739ec5e8b4e4d99f352b08ccd1a19 [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
17import Standard_Suite
18import WWW_Suite
19import MacOS
20
21class Netscape(aetools.TalkTo, Standard_Suite.Standard_Suite, WWW_Suite.WWW_Suite):
22 pass
23
24SIGNATURE='MOSS'
25
26Error = 'nsremote.Error'
27
28_talker = None
29
30def _init():
31 global _talker
32 if _talker == None:
33 _talker = Netscape(SIGNATURE)
34
35def list(dpyinfo=""):
36 _init()
37 list = _talker.list_windows()
38 return map(lambda x: (x, 'version unknown'), list)
39
40def geturl(windowid=0, dpyinfo=""):
41 _init()
42 if windowid == 0:
43 ids = _talker.list_windows()
44 if not ids:
45 raise Error, 'No netscape windows open'
46 windowid = ids[0]
47 info = _talker.get_window_info(windowid)
48 return info
49
50def openurl(url, windowid=0, dpyinfo=""):
51 _init()
52 if windowid == 0:
53 _talker.OpenURL(url)
54 else:
55 _talker.OpenURL(url, toWindow=windowid)
56
57def _test():
58 """Test program: Open www.python.org in all windows, then revert"""
59 import sys
60 windows_and_versions = list()
61 windows_and_urls = map(lambda x: (x[0], geturl(x[0])[0]), windows_and_versions)
62 for id, version in windows_and_versions:
63 openurl('http://www.python.org/', windowid=id)
64 print 'Type return to revert to old contents-'
65 sys.stdin.readline()
66 for id, url in windows_and_urls:
67 openurl(url, id)
68
69if __name__ == '__main__':
70 _test()
71