summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/ae/nsremote.py
blob: cace37450ea31cc9bac77e983173bf5958a4b262 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""nsremote - Control Netscape from python.

Interface modelled after unix-interface done
by hassan@cs.stanford.edu.

Jack Jansen, CWI, January 1996.
"""
#
# Note: this module currently uses the funny SpyGlass AppleEvents, since
# these seem to be the only way to get the info from Netscape. It would
# be nicer to use the more "object oriented" standard OSA stuff, when it
# is implemented in Netscape.
#
import addpack
import sys

addpack.addpack('Tools')
addpack.addpack('bgen')
addpack.addpack('ae')

import aetools
import Standard_Suite
import WWW_Suite
import MacOS

class Netscape(aetools.TalkTo, Standard_Suite.Standard_Suite, WWW_Suite.WWW_Suite):
	pass	
	
SIGNATURE='MOSS'

Error = 'nsremote.Error'

_talker = None

def _init():
	global _talker
	if _talker == None:
		_talker = Netscape(SIGNATURE)

def list(dpyinfo=""):
	_init()
	list = _talker.list_windows()
	return map(lambda x: (x, 'version unknown'), list)
	
def geturl(windowid=0, dpyinfo=""):
	_init()
	if windowid == 0:
		ids = _talker.list_windows()
		if not ids:
			raise Error, 'No netscape windows open'
		windowid = ids[0]
	info = _talker.get_window_info(windowid)
	return info
	
def openurl(url, windowid=0, dpyinfo=""):
	_init()
	if windowid == 0:
		_talker.OpenURL(url)
	else:
		_talker.OpenURL(url, toWindow=windowid)
		
def _test():
	"""Test program: Open www.python.org in all windows, then revert"""
	import sys
	windows_and_versions = list()
	windows_and_urls = map(lambda x: (x[0], geturl(x[0])[0]), windows_and_versions)
	for id, version in windows_and_versions:
		openurl('http://www.python.org/', windowid=id)
	print 'Type return to revert to old contents-'
	sys.stdin.readline()
	for id, url in windows_and_urls:
		openurl(url, id)
		
if __name__ == '__main__':
	_test()