云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > PythonWindowsTutorial

PythonWindowsTutorial

  • 62 次阅读
  • 3 次下载
  • 2025/6/24 12:13:33

Using Python To Harness Windows

Advanced ? ? ?

map from one accounts structure to another analyse and trace cash flows Multidimensional analysis

5.10 What we’d like…

Page 21 of 71

6795.doc

Using Python To Harness Windows

5.11 Design Patterns for the COM Server

COM servers and Python apps handle some arg types differently… ? Unicode String Handling – Gotcha Number One! (hopefully goes in 1.6) # our ordinary save method for use from Python def save(self, filename): f = open(filename,'wb') cPickle.dump(self.__journal,f) f.close() # what we would need for use from COM def save(self, unicode_filename): # convert it to a python string: python_filename = str(unicode_filename) f = open(python_filename,'wb') cPickle.dump(self.__journal,f) f.close() ?

…so a single class not the best design for real apps. Others options: ? ? ?

We go for option 3: Delegate. Keeps our Python package pure and portable.

Startup Code: # comservers.py – to be expanded class COMBookSet: _reg_clsid_ = '{38CB8241-D698-11D2-B806-0060974AB8A9}' _reg_progid_ = 'Doubletalk.BookServer' _public_methods_ = ['double'] def __init__(self): self.__BookSet = doubletalk.bookset.BookSet() def double(self, arg): # trivial test function to check it is alive return arg * 2 if __name__ == '__main__': win32com.server.register.UseCommandLine(COMBookSet)

COM Base Class, Python Server Pure Python Base Class, COM Subclass COM interface, Python Delegate Wrap/Unwrap subobjects

Page 22 of 71

6795.doc

Using Python To Harness Windows

5.12 Visual Basic GUI Startup Code

Public BookServer As Object Private Sub MDIForm_Load() InitCOMServer frmJournal.Show End Sub Private Sub MDIForm_Unload(Cancel As Integer) CloseCOMServer End Sub Sub InitCOMServer() 'called when the program starts On Error GoTo InitCOMServer_error Set BookServer = CreateObject(\ Exit Sub InitCOMServer_error: Dim msg As String msg = \BookServer.\ \the Python \ \ MsgBox msg End End Sub Sub CloseCOMServer() Set BookServer = Nothing End Sub Sub TestCOMServer() 'just to check it is alive Dim hopefully_four As Integer hopefully_four = BookServer.Double(2) MsgBox \alive\End Sub Private Sub mnuToolsTestServer_Click() 'this helps establish if the COM server is alive 'using a minimal diagnostic function in the modMain module TestCOMServer End Sub With a little luck…

Page 23 of 71

6795.doc

Using Python To Harness Windows

5.13 Our first view – The Journal

Goal:

Date-Ordered List of Transactions

Python Code Needed:

# more methods for COMBookSet – must be named in _public_methods_ def load(self, filename): self.__BookSet.load(str(filename)) def count(self): # return number of transactions return len(self.__BookSet) def getTransactionString(self, index): return self.__BookSet[index].asString() Visual Basic Code – File / Open handler

Private Sub mnuFileOpen_Click() Dim sFile As String With dlgCommonDialog .DialogTitle = \ .CancelError = False 'ToDo: set the flags and attributes of the common dialog control .Filter = \ .ShowOpen If Len(.FileName) = 0 Then Exit Sub End If sFile = .FileName End With BookServer.Load sFile 'display something helpful in the Journal caption frmJournal.Caption = sFile & \Transactions\End Sub

Page 24 of 71

6795.doc

搜索更多关于: PythonWindowsTutorial 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

Using Python To Harness Windows Advanced ? ? ? map from one accounts structure to another analyse and trace cash flows Multidimensional analysis 5.10 What we’d like… Page 21 of 71 6795.doc Using Python To Harness Windows 5.11 Design Patterns for the COM Server COM servers and Python apps handle some arg types differently… ? Unico

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com