From 742ca0385a7c42f5672db82a093f29a22f3dd7a7 Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Sun, 20 Aug 2000 20:06:51 +0000 Subject: Updated for new AppleScript structure and moved to Lib (it's far too useful to lurk in the source folder). --- Mac/Lib/nsremote.py | 65 ++++++++++++++++++++++++++++++++++++++++++ Mac/Modules/ae/nsremote.py | 71 ---------------------------------------------- 2 files changed, 65 insertions(+), 71 deletions(-) create mode 100644 Mac/Lib/nsremote.py delete mode 100644 Mac/Modules/ae/nsremote.py diff --git a/Mac/Lib/nsremote.py b/Mac/Lib/nsremote.py new file mode 100644 index 0000000..a12cd35 --- /dev/null +++ b/Mac/Lib/nsremote.py @@ -0,0 +1,65 @@ +"""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 sys + +import aetools +import Netscape +import MacOS + +Error = 'nsremote.Error' + +_talker = None + +def _init(): + global _talker + if _talker == None: + _talker = Netscape.Netscape() + +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() + diff --git a/Mac/Modules/ae/nsremote.py b/Mac/Modules/ae/nsremote.py deleted file mode 100644 index c406294..0000000 --- a/Mac/Modules/ae/nsremote.py +++ /dev/null @@ -1,71 +0,0 @@ -"""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 sys - -import aetools -import Standard_Suite -import WWW_Suite -import MacOS - -class Netscape(aetools.TalkTo, Standard_Suite.Standard_Suite, WWW_Suite.WorldWideWeb_suite_2c__as_defined_in_Spyglass_spec_2e_): - 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() - -- cgit v0.12