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