O'Reilly logo

Python Programming On Win32 by Mark Hammond, Andy Robinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Providing a Startup Script

A useful customization is to allow an option for a startup script. The script could be a standard, hardcoded filename or a configuration variable. Users can do almost anything with this script; they can put in a series of standard import statements, go off and import commonly used data files from elsewhere, and (as we’ll see) set up the BookSet as they want with validation rules and custom views. The script executes after the BookSet has been initialized, so it can’t control the way BookSet initializes.

This feature is easy to provide with the tools we’ve just built. In Figure 8.3, we’ve gone for a user-defined script name in an Options dialog.

Specifying a startup script from the client
Figure 8.3. Specifying a startup script from the client

Earlier on we put two public methods in frmMain called InitCOMServer and CloseCOMServer , and never used the latter. Here there’s a good use for it. InitCOMServer has been expanded as follows (ignoring error trapping to save space):

Sub InitCOMServer() Dim startupScript As String 'called when the program starts On Error GoTo InitCOMServer_error Set BookServer = CreateObject("Doubletalk.BookServer") On Error GoTo 0 'tell it to capture output for the console BookServer.beginTrappingOutput 'if there is an init script, run it If frmOptions.txtStartupScript.text <> "" Then On Error GoTo InitCOMServer_StartupScriptError BookServer.execFile frmOptions.txtStartupScript.text ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required