Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Python Programming on Win32
Cover
Python Programming on Win32
A Note Regarding Supplemental Files
Copyright
Preface
About This Book
Who Is This Book for?
How the Book Is Organized
Part I
Part II
Part III
Part IV
About the Examples
Font Conventions Used in This Book
How to Contact Us
Acknowledgments
1. Introduction to Python
1. What Is Python?
1.1. Language Features
1.2. Python as an Integration Tool
1.2.1. Working with Files
1.2.2. Working with DLLs and C Programs
1.2.3. COM
1.2.4. Networking
1.2.5. Distributed Objects
1.2.6. Where Python Fits in the Development Picture
1.3. Case Studies of Python Deployment
1.3.1. A Japanese Python?
1.3.2. There’s a Python on the Scoreboard!
1.3.3. Other Python Sightings in the Wild
1.4. The Python Community
1.5. Installation and Setup
1.6. Conclusion
2. Python Language Review
2.1. A Crash Course
2.1.1. Numbers, Strings, and Variables
2.1.2. Lists and Tuples
2.1.3. Control Structures
2.1.4. Functions
2.1.5. Dictionaries
2.1.6. Modules
2.1.7. Classes
2.1.8. Exception Handling
2.2. Conclusion
2.3. References
3. Python on Windows
3.1. The Python Core on Windows
3.1.1. The Windows Registry
3.1.2. Windows Explorer Integration
3.1.3. Using the Windows Command Prompt
3.1.4. Windows Gotchas
3.2. The Python for Windows Extensions
3.2.1. Win32 Extensions
3.2.2. PythonWin
3.2.3. PythonCOM
3.3. The Python Imaging Library (PIL)
3.4. PyOpenGL
3.5. Web Publishing Tools
3.5.1. Medusa
3.5.2. Zope
3.6. The mx Extensions
3.6.1. mxDateTime
3.6.2. mxTextTools
3.6.3. mxODBC
3.6.4. mxStack
3.6.5. mxTools
3.6.6. mxCrypto
3.6.7. mxProxy
3.7. Scientific Tools
3.8. XML
3.9. Conclusion
4. Integrated Development Environments for Python
4.1. The PythonWin IDE
4.1.1. The PythonWin Environment
4.1.2. Command-Line Parameters
4.1.3. The Interactive Window
4.1.4. The Python Editor
4.1.5. Python Path Browser
4.1.6. Object Browser
4.1.7. Windows Explorer Integration
4.1.8. The Debugger
4.2. IDLE
4.2.1. Platforms and Versions
4.2.2. Shell Window
4.2.3. The Python Editor
4.2.4. Path and Class Browsers
4.2.5. Running and Importing Scripts
4.2.6. The Debugger
4.3. Conclusion
5. Introduction to COM
5.1. What It Is
5.2. Using COM Objects from Python
5.3. Implementing COM Objects with Python
5.4. Globally Unique Identifiers
5.5. Conclusion
2. Building an Advanced Python Application
6. A Financial Modeling Toolkit in Python
6.1. Doubletalk
6.2. A Crash Course in Accounting
6.2.1. Transactions
6.2.2. The Chart of Accounts
6.2.3. Back to Python
6.2.4. Coding Transactions
6.2.5. BookSets
6.2.6. Storing Extra Information in Transactions
6.3. The Doubletalk Toolkit at Work
6.3.1. Comparing, Combining, and Contrasting Accounts
6.3.2. Building Business Models
6.3.3. Multidimensional Analysis of Financial Data
6.3.4. Cash-Flow Analysis
6.3.5. Putting It Together
6.4. Conclusion
7. Building a GUI with COM
7.1. Designing COM Servers
7.2. A VB Client
7.2.1. Building the First View
7.2.2. More About Transactions
7.2.3. Adding and Editing Transactions
7.2.4. Building Views with Arrays
7.2.5. Graphics and Callbacks
7.2.6. Debugging COM Servers
7.3. Writing a Delphi User Interface
7.3.1. Instantiating the Server
7.3.2. Unpacking Variant Arrays
7.4. Conclusion
8. Adding a Macro Language
8.1. Dynamic Code Evaluation
8.1.1. Executing Commands and Evaluating Expressions
8.1.2. Grabbing Python’s Output
8.1.3. Building an Interactive Console
8.1.4. Industrial-Strength Consoles
8.1.5. Executing Scripts
8.1.6. Importing a Module
8.1.7. Providing a Startup Script
8.1.8. Defining User and System-Code Directories
8.2. Making an Application Extensible
8.2.1. Changing the Delegate Class
8.2.2. A Delegation Framework for Responding to Events
8.2.3. Views and Validators
8.2.4. A User-Defined View: The Backend
8.2.5. A User-Defined View: The Front End
8.2.6. User-Defined Validations
8.2.7. More Ways to Extend the Application
8.2.8. A Note on Performance
8.3. Conclusion
9. Integration with Excel
9.1. Client-Side COM and the Excel Object Model
9.1.1. Starting Excel
9.1.2. Navigating Through Collections
9.1.3. Keyword Arguments
9.1.4. Passing Data In and Out
9.1.5. Accessing Ranges
9.1.6. Arrays
9.2. Excel Concluded
9.3. Putting It All Together: Importing Financial Data
9.4. Server-Side COM Again: Excel as a GUI
9.5. Conclusion
9.6. References
10. Printed Output
10.1. Business Requirements
10.1.1. Different Document Models
10.1.2. Methodologies and Lessons from Experience
10.1.3. Output Formats
10.2. Automating Word
10.2.1. A Simple Example
10.2.2. Using a Template
10.2.3. A Document Wrapper
10.2.4. Adding Paragraphs and Styles
10.2.5. Tables
10.2.6. Adding a Chart
10.2.7. Putting It Together
10.2.8. Inserting HTML and Other Formats
10.2.9. Using Python COM Objects From Word
10.2.10. The Last Word
10.3. Direct Output to the Printer with Windows
10.3.1. Choosing a Coordinate System
10.4. PIDDLE: A Python Graphics API
10.4.1. Available Backends
10.4.2. Fonts
10.4.3. Colors
10.4.4. Coordinate System
10.4.5. Canvas Graphics Methods
10.4.6. Canvas Attributes
10.4.7. Text Output
10.4.8. Image Support
10.4.9. Test Framework
10.4.10. Video Recorder
10.5. PostScript
10.6. Portable Document Format
10.6.1. The Structure of PDF
10.6.2. Implementing the Frontend
10.7. Putting It Together: A High-Volume Invoicing System
10.7.1. Advanced Techniques and Possibilities with PDF and PIDDLE
10.8. Conclusion
10.9. References
11. Distributing Our Application
11.1. DCOM
11.2. Conclusion
3. Python on Windows Cookbook
12. Advanced Python and COM
12.1. Advanced COM
12.1.1. Interfaces and Objects
12.1.2. The IDispatch Interface
12.1.3. Late- Versus Early-Bound IDispatch
12.1.4. Using or Implementing Objects
12.1.5. InProc Versus LocalServer Versus RemoteServer
12.2. Python and COM
12.3. Using Automation Objects from Python
12.3.1. Late-Bound Automation
12.3.2. Early-Bound Automation
12.3.3. Forcing Early or Late Binding
12.3.4. Differences Between Early and Late Binding
12.3.5. Using COM Constants
12.3.6. Passing and Obtaining Python Objects from COM
12.4. Using Other COM Interfaces
12.5. Error Handling
12.6. Implementing COM Objects in Python
12.6.1. Implementing a COM Server
12.6.2. Registering Your COM Server
12.6.3. Error Handling for COM Servers
12.6.4. Policies
12.6.5. Wrapping and Unwrapping
12.6.6. Debugging Python COM Objects
12.6.7. The Final Sample
12.7. Python and DCOM
12.7.1. Configure DCOM on the Remote Machine
12.7.2. Configure DCOM and the Object on the Local Machine
12.7.3. Testing a Remote Object Using DCOM-Specific Calls
12.8. Conclusion
13. Databases
13.1. DAO, ADO, ODBC, OLEDB, and Other GBFLAs
13.1.1. Proprietary APIs
13.1.2. Open Database Connectivity
13.1.3. Data Access Objects, JET, and Access
13.1.4. Remote Data Objects
13.1.5. OLEDB
13.1.6. ActiveX Data Objects
13.1.7. So What’s Worth Using?
13.2. Python’s Database API
13.3. Getting at Your Data
13.3.1. Fetching Data with the PythonWin ODBC Module
13.3.2. The mxODBC and mxDateTime Extensions
13.3.3. Sam Rushing’s ODBC Module
13.3.4. Connecting with Data Access Objects
13.3.5. Connecting with ADO
13.4. A Note on Speed
13.5. Gadfly, the Pure Python Relational Database
13.5.1. Interactive Use
13.5.2. Introspection
13.5.3. Network Use
13.5.4. What’s It Good for?
13.6. Data Laundering with Python
13.6.1. Data as Rows
13.6.2. Geometric Operations
13.6.3. Data as Dictionaries
13.6.4. Inserting Data into the Destination Database
13.7. A Three-Tier Architecture with Business Objects
13.7.1. Dynamic Attributes
13.7.2. Lazy Fetches
13.8. Conclusion
13.9. References
14. Working with Email
14.1. SMTP and POP3
14.1.1. Sending an SMTP Message
14.1.2. Receiving via POP3
14.2. Microsoft Exchange/Outlook
14.2.1. Collaboration Data Objects
14.3. Conclusion
15. Using the Basic Internet Protocols
15.1. HTTP and HTML
15.1.1. Fetching Data via HTTP
15.1.2. Serving Data via HTTP
15.2. FTP
15.2.1. Fetching Data via FTP
15.3. NNTP
15.3.1. Fetching News Articles via NNTP
15.4. Conclusion
16. Windows NT Administration
16.1. Working with Users and Groups
16.1.1. Obtaining Information About a User or Group
16.1.2. Creating, Changing, and Deleting Users and Groups
16.2. Server and Share Information
16.2.1. Querying Information About Servers
16.2.2. Working with Share Information
16.2.3. User and Share Sample
16.3. Rebooting a Machine
16.3.1. Obtaining the Necessary Privileges
16.3.2. Sample Code to Reboot the Current Machine
16.4. Conclusion
16.5. References
17. Processes and Files
17.1. Portable File Manipulation
17.1.1. Working with Files on Disk
17.1.2. Working with Python File Objects
17.2. Native File Manipulation: The win32file Module
17.2.1. Opening and Creating Files
17.2.2. Reading and Writing Files
17.2.3. Overlapped I/O
17.3. Pipes
17.3.1. Anonymous Pipes
17.3.2. Named Pipes
17.4. Processes
17.4.1. Portable Process Control: The os Module
17.4.2. Better Process Control: The win32api Module
17.4.3. Ultimate Process Control: The win32process Module
17.5. Conclusion
18. Windows NT Services
18.1. Services in Brief
18.1.1. Service Control Manager
18.1.2. Starting and Stopping
18.1.3. User Interface
18.1.4. Error Reporting and Handling
18.1.5. Performance Monitor
18.2. Controlling Services with Python
18.2.1. Connecting to the SCM
18.2.2. Connecting to a Service
18.2.3. Querying the Status of a Service
18.2.4. Controlling a Service
18.2.5. Closing Service Handles
18.2.6. Utility Functions to Simplify Working with Services
18.3. Reading the Event Log
18.3.1. Python EventLogRecord Object
18.3.2. How to Read the Event Log
18.3.3. A Simpler Way to Read Event Log Records
18.3.4. Obtaining the Message for an Event Log Record
18.4. Windows NT Performance Monitor Data
18.4.1. Anatomy of the Performance Monitor
18.4.2. Reading the Performance Monitor from Python
18.5. Writing Services in Python
18.5.1. The Anatomy of a Service
18.5.2. The Anatomy of a Python Service
18.5.3. The win32serviceutil.ServiceFramework Class
18.5.4. The Smallest Possible Python Service
18.5.5. Installing, Debugging, and Running a Python Service
18.6. Sample Service Written in Python
18.7. Writing to the Event Log
18.7.1. The servicemanager Module
18.7.2. Modifying the Service to Add Messages
18.7.3. Custom Event Log Writing
18.8. Providing Performance Monitor Information
18.8.1. Performance Monitor Data from Python
18.9. A Final Service
18.10. Conclusion
19. Communications
19.1. Serial Communications
19.1.1. How COM Ports Are Accessed
19.1.2. The Serial Module
19.1.3. The Microsoft Communications Control (MSComm)
19.2. Remote Access Services
19.3. Sockets
19.3.1. A Simple Socket Server
19.3.2. Communication Between Sockets
19.3.3. Where to Go from Here
19.4. Other Communications Tools
19.4.1. Named Pipes
19.4.2. Remote Procedure Call (RPC)
19.5. Conclusion
19.6. References
20. GUI Development
20.1. Tkinter
20.1.1. Terminology
20.1.2. Pros and Cons of Tkinter
20.1.3. Running GUI Applications
20.1.4. Widgets
20.1.5. Geometry Management
20.1.6. Tkinter Sample Code
20.1.7. Tkinter Conclusion
20.2. PythonWin
20.2.1. Introduction to MFC
20.2.2. The PythonWin Object Model
20.2.3. Developing a PythonWin Sample Application
20.2.4. Defining a Simple Framework
20.2.5. Enhancing the DocumentTemplate
20.2.6. Enhancing the Document
20.2.7. Defining the View
20.2.8. Creating the Application Object
20.2.9. PythonWin and Resources
20.2.10. PythonWin Conclusion
20.3. wxPython
20.3.1. wxWindows
20.3.2. wxWindows + Python = wxPython
20.3.3. Using wxPython
20.3.4. Building a Doubletalk Browser with wxPython
20.3.5. wxPython Conclusion
21. Active Scripting
21.1. Registering the Python Active Script Support
21.2. Python and Popular Microsoft Applications
21.2.1. Internet Explorer
21.2.2. Internet Information Server
21.2.3. Configuring IIS
21.2.4. Windows Scripting Host
21.3. Active Debugging
21.4. How Active Scripting Works
21.5. Active Script Hosting in Python
21.6. Conclusion
22. Extending and Embedding with Visual C++ and Delphi
22.1. Python and Visual C++
22.1.1. One Size Doesn’t Fit All
22.1.2. Building an Extension Using Visual C++
22.1.3. Debug Versus Release Builds
22.1.4. Building Python Itself
22.1.5. Embedding a Python Interpreter in a C++ Application
22.2. Simplified Wrapper and Interface Generator
22.3. Python and Delphi
22.3.1. Embedding Python in a Delphi Application
22.3.2. Extending Python with a Delphi DLL
22.3.3. Accessing Delphi’s Visual Component Library
22.4. Dynamic DLL Access
22.4.1. Installation and Setup
22.4.2. Using WinDll
22.4.3. C Strings and Passing by Reference
22.5. References
22.6. Conclusion
4. Appendixes
A. Key Python Modules and Functions
A.1. Built-in Types
A.1.1. Truth Value Testing
A.1.2. Boolean Operations
A.1.3. Comparisons
A.1.4. Numeric Types
A.1.5. Bit-String Operations on Integer Types
A.1.6. Sequence Types
A.1.7. More String Operations
A.1.8. Mutable Sequence Types
A.1.9. Mapping Types
A.1.10. Other Built-in Types
A.2. Built-in Exceptions
A.3. Built-in Functions
A.4. module sys: System-Specific Parameters and Functions
A.5. module string: Common String Operations
A.6. module os: Miscellaneous OS Interfaces
A.6.1. Process Parameters
A.6.2. File Object Creation
A.6.3. File Descriptor Operations
A.6.4. Files and Directories
A.6.5. Process Management
A.6.6. Miscellaneous System Data
A.6.7. module os.path: Common Pathname Manipulations
B. Win32 Extensions Reference
B.1. Common Win32 Python Objects
PyHANDLE
PyIID
PySTARTUPINFO
B.2. pythoncom Module
CoCreateInstance( )
CoInitialize( )
CoInitializeEx( )
CoUninitialize( )
CoMarshalInterThreadInterfaceInStream( )
CoGetInterfaceAndReleaseStream( )
B.3. win32api Module
ShellExecute( )
WinExec( )
OpenProcess( )
GetSystemMetrics( )
GetDomainName( )
GetUserName( )
GetComputerName( )
InitiateSystemShutdown( )
AbortSystemShutdown( )
GetCurrentThreadId( )
GetCurrentProcessId( )
B.4. win32event Module
WaitForSingleObject( )
WaitForMultipleObjects( )
MsgWaitForMultipleObjects( )
CreateEvent( )
SetEvent( )
ResetEvent( )
B.5. win32evtlog Module
CloseEventLog( )
OpenEventLog( )
ReadEventLog( )
PyEVENTLOGRECORD object
Messages
B.6. win32file Module
CreateFile( )
ReadFile( )
WriteFile( )
B.7. win32pipe Module
CallNamedPipe( )
CreatePipe( )
B.8. win32process Module
CreateProcess( )
TerminateProcess( )
GetProcessAffinityMask( )
SetProcessAffinityMask( )
SetThreadAffinityMask( )
SetPriorityClass( )
B.9. Service-Related Modules
B.9.1. win32serviceutil Module
ControlService( )
QueryServiceStatus( )
StartService( )
StopService( )
B.9.2. win32service Module
OpenSCManager( )
OpenService( )
CloseServiceHandle( )
ControlService( )
QueryServiceStatus( )
StartService( )
B.9.3. servicemanager Module
LogMsg( )
LogInfoMsg(), LogWarningMsg(), LogErrorMsg()
Messages
B.10. win32net Module
NetGroupGetInfo
NetGroupGetUsers
NetGroupSetUsers( )
NetGroupSetInfo( )
NetGroupAdd( )
NetGroupAddUser( )
NetGroupDel( )
NetGroupDelUser( )
NetGroupEnum
NetLocalGroupAddMembers( )
NetLocalGroupDelMembers( )
NetLocalGroupGetMembers
NetLocalGroupSetMembers( )
NetMessageBufferSend( )
NetServerEnum
NetServerGetInfo
NetServerSetInfo( )
NetShareAdd( )
NetShareDel( )
NetShareCheck
NetShareEnum
NetShareGetInfo
NetShareSetInfo( )
NetUserAdd( )
NetUserChangePassword( )
NetUserEnum
NetUserGetInfo
NetUserSetInfo( )
NetUserDel( )
B.11. USER_INFO Structures
USER_INFO_0
USER_INFO_1
USER_INFO_2
USER_INFO_3
USER_INFO_10
USER_INFO_11
USER_INFO_20
USER_INFO_1003
USER_INFO_1005
USER_INFO_1006
USER_INFO_1007
USER_INFO_1008
USER_INFO_1009
USER_INFO_1010
USER_INFO_1011
B.12. SERVER_INFO Structures
SERVER_INFO_100
SERVER_INFO_101
SERVER_INFO_102
SERVER_INFO_402
SERVER_INFO_403
SERVER_INFO_502
SERVER_INFO_503
B.13. GROUP_INFO Structures
GROUP_INFO_0
GROUP_INFO_1
GROUP_INFO_2
GROUP_INFO_1002
GROUP_INFO_1005
B.14. GROUP_USERS_INFO Structures
GROUP_USERS_INFO_1
B.15. LOCALGROUP_USERS_INFO Structures
LOCALGROUP_USERS_INFO_0
B.16. LOCALGROUP_INFO Structures
LOCALGROUP_INFO_0
LOCALGROUP_INFO_1
LOCALGROUP_INFO_1002
B.17. LOCALGROUP_MEMBERS_INFO Structures
LOCALGROUP_MEMBERS_INFO_0
LOCALGROUP_MEMBERS_INFO_1
LOCALGROUP_MEMBERS_INFO_2
LOCALGROUP_MEMBERS_INFO_3
C. The Python Database API Version 2.0
C.1. Python Database API Specification 2.0
C.2. Module Interface
C.3. Connection Objects
C.4. Cursor Objects
C.5. Type Objects and Constructors
C.5.1. Implementation Hints
C.6. Major Changes from Version 1.0 to Version 2.0
C.7. Open Issues
C.8. Endnotes
Note 1
Note 2
Note 3
Note 4
Note 5
Note 6
Note 7
D. Threads
D.1. Python Thread Support
D.2. Win32 Thread Support
D.2.1. Native Win32 Threads
D.2.2. win32event Module
D.3. COM Threading Models
D.3.1. Apartment Living
D.4. What Apartment Do I Live in?
D.4.1. What Are the Apartment Rules?
D.4.2. Apartments Open for Inspection
D.4.3. More Information on COM Threading
D.5. Threads and the User Interface
D.6. Conclusion
About the Authors
Colophon
Copyright
← Prev
Back
Next →
← Prev
Back
Next →