Netscape Plugins ================ The Python/WPY Netscape plugin DLL supports the Netscape plugin API. That means you can write Python programs which access this API and run in a Netscape window. To use the plugin DLLs, copy either npwpynt.dll (for Windows 95 or NT) or npwpy31.dll (for Windows 3.1 and 3.11) to the "plugins" directory located wherever you installed "netscape.exe". This is often c:/netscape/program/plugins on NT and c:/netscape/plugins on Win3.1. Then try the menu item Help/Plugins and see if the plugin is listed. The NT version also needs the python NT DLL py13an.dll to be on your path. To run a Python program, just open the Python program URL, for example, demo_ns1.py or demo_ns2.py. To run in embedded mode, open a URL which has an EMBED tag, such as demo_ns.htm. Programming Model ================= The programming model for a Netscape plugin WPY program is a little different, and WPY programs must be modified before they can run in a Netscape window. Netscape provides only a single view window to run in. There is no status bar nor menu bar. You must specify your doc/frame/view classes as usual, but only the view will get messages from the system. You can call your document methods but don't call frame methods, because Netscape does not permit access to the frame. See the demos demo_ns*.py. The current version requires the Python libraries to be present on the system running Netscape if you use any "import" statements. You may want to use the NPN_GetURL feature to bring over the required Python library files. Bugs ==== There are some problems with the 16-bit Windows 3.1 DLL. It is not possible to create CEdit controls for some reason I have yet to find, and the program will GPF if you try. The Plugin API ============== All messages from Netscape to the plugin start with "NPP_" and are directed to the CWinApp instance or to a stream object instance. Netscape methods which you can call start with "NPN_". See the Netscape plugin API "plugin.htm" for more information. All constants are in the module wpycon. Use "wpycon.NPRES_DONE" etc. class CWinApp Methods void NPP_New(self, type, mode, args, saved): This is called exactly once before any other NPP methods. It can be used to initialize a new app. string type: The MIME type. int mode: The mode NP_EMBED, NP_FULL, or NP_BACKGROUND. dict args: A dictionary. It gives the HTML attributes if the mode is NP_EMBED. string saved: A string saved from a previous run, or None. void NPP_SetWindow(self, rect): This is called when the window size changes. The default implementation calls the view's OnSize method. Rect is a CRect giving the size and location of the window for this app. string NPP_Destroy(self): This app is being destroyed. Return a string which Netscape may or may not save and return to the next instance of this app. int NPN_PostURL(self, url, window, buf, file): Post data to a URL. int NPN_NewStream(self, type): Send data to be interpreted by Netscape. This creates a stream from the plugin to Netscape. There can be only one such stream open at a time. Manipulate this stream with NPN_Write and NPN_DestroyStream. int NPN_Write(self, buffer): Write to the Netscape stream. int NPN_DestroyStream(self, reason): Destroy the Netscape stream. int NPN_Status(self, message): Write the string message to Netscape's status window. class CNetscapeStream This class represents a stream object. It is used to request Netscape to return a URL using its network and caching facilities. See demo_ns1.py. The methods are: int NPN_GetURL(self, url, window = ""): To direct Netscape to return a URL, create an instance of CNetscapeStream and call NPN_GetURL with the string url and the window "". Netscape will return an error code. Eventually, it will call the remaining methods as the URL is received. int NPP_NewStream(self, type, seekable): A new stream is available for this app. Return wpycon.NP_ASFILE if you want the stream to be written to a file (NPP_StreamAsFile will be called). Otherwise, the NPP_Write() method will return the data as it is received. Netscape discourages the use of NP_ASFILE. string type: The MIME type of the stream. int seekable: Boolean: Whether the stream supports seek. Seek is not supported in this version of Python/WPY. int NPP_WriteReady(self): Called before any data is returned from the stream. Return the maximum number of bytes your NPP_Write() method is prepared to accept. Do not implement if you use NP_ASFILE. int NPP_Write(self, buffer, offset): This method is called to return data from the stream unless you have specified NP_ASFILE. You can return a negative number to abort the stream. Do not implement if you use NP_ASFILE. string buffer: Data bytes from the stream. int offset: Stream offset. void NPP_DestroyStream(self, reason): The stream is being destroyed. You must call the base class method. int reason: The reason NPRES_NETWORK_ERR, NPRES_USER_BREAK, or NPRES_DONE. void NPP_StreamAsFile(self, filename): A stream is available as a file (NP_ASFILE was used). string filename: The full path of the file.