[pywin32-bugs] [ pywin32-Bugs-1648655 ] Wrong args order with event handler
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: SourceForge.net <no...@so...> - 2007-08-26 02:33:08
|
Bugs item #1648655, was opened at 2007-01-31 05:09 Message generated for change (Comment added) made by rupole You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=1648655&group_id=78018 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: com Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: atsuo ishimoto (ishimoto) Assigned to: Nobody/Anonymous (nobody) Summary: Wrong args order with event handler Initial Comment: Order of args doesn't match with prototype generated by makepy. To reproduce, please run script below and Save workbook on the Excel. # <<<<<< BEGIN >>>>>> import win32com.client class WorkbookEvent: def OnBeforeSave(self, SaveAsUI, Cancel): print "OnBeforeSave", SaveAsUI, Cancel return False xl = win32com.client.Dispatch("Excel.Application") xl.Visible = 1 wb = DispatchWithEvents(xl.Workbooks.Add(), WorkbookEvent) while 1: pythoncom.PumpWaitingMessages() # <<<<<< END >>>>>> When I save workbook, WorkbookEvent.OnBeforeSave called with SaveAsUI=False and Cancel=False. But on SaveAs, args passed are SaveAsUI=False and Cancel=True, which should be SaveAsUI=True and Cancel=False. Python2.4.3,pywin32-210,MS-Excel 2000 ---------------------------------------------------------------------- >Comment By: Roger Upole (rupole) Date: 2007-08-25 21:33 Message: Logged In: YES user_id=771074 Originator: NO I think the problem is that the args wind up backwards when they're passed as named args. For a different event with 3 parms: def OnSheetBeforeDoubleClick(self, Sh, Target, Cancel): print Sh, Target, Cancel return False This prints False None <win32com.gen_py.Microsoft Excel 9.0 Object Library._Worksheet instance at 0x21747576> The first arg Sh should be the worksheet, but I get a boolean as the first parm, and the worksheet ends up as the 3rd arg. >From stepping through in the debugger, both of these events are passing named parms. The code that creates the arg tuple to pass to the event method isn't doing any mapping between names and DISPID's. It only verifies that the named params are in sequential order (which they are not actually required to be). However, it then goes on to process the named args in reverse order just as if they were positional args. ---------------------------------------------------------------------- Comment By: atsuo ishimoto (ishimoto) Date: 2007-07-28 07:35 Message: Logged In: YES user_id=463672 Originator: YES Thank you for comment. But same script with VB.NET, correct values are passed with correct order. So, I guess typelib is corrent. Part of VB script follows. Private WithEvents e1 As Excel.Application Private Sub e1_WorkbookBeforeSave(ByVal Wb As Excel.Workbook, ByVal SaveAsUI As Boolean, ByRef Cancel As Boolean) Handles e1.WorkbookBeforeSave MsgBox("SaveAsUI:" + Str(SaveAsUI) + " Cancel:" + Str(Cancel)) End Sub End Class ---------------------------------------------------------------------- Comment By: Mark Hammond (mhammond) Date: 2007-07-28 02:17 Message: Logged In: YES user_id=14198 Originator: NO Sorry, but I can't see a bug of ours here. It sounds like the type info Excel gives out is wrong - otherwise I'd expect *all* params to be reversed for all events, and I don't think that is the case. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=551954&aid=1648655&group_id=78018 |