summaryrefslogtreecommitdiffstats
path: root/Mac/Modules
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1996-01-29 15:45:59 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1996-01-29 15:45:59 (GMT)
commitd390325bbb1a75b384b0caec98f49bb3ae0baf41 (patch)
tree01b14b24f49bc44ea0048189d7fc6280ba2c1b67 /Mac/Modules
parent7e156a70fa5a26e11c50f2d5bff44935345c4ea9 (diff)
downloadcpython-d390325bbb1a75b384b0caec98f49bb3ae0baf41.zip
cpython-d390325bbb1a75b384b0caec98f49bb3ae0baf41.tar.gz
cpython-d390325bbb1a75b384b0caec98f49bb3ae0baf41.tar.bz2
Modules implementing WWW and URL suite, and a module to control netscape.
Diffstat (limited to 'Mac/Modules')
-rw-r--r--Mac/Modules/ae/nsremote.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/Mac/Modules/ae/nsremote.py b/Mac/Modules/ae/nsremote.py
new file mode 100644
index 0000000..cace374
--- /dev/null
+++ b/Mac/Modules/ae/nsremote.py
@@ -0,0 +1,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()
+