[python-win32] pythonwin not catching all events

Johannes Frank jmfrank63 at gmail.com
Thu Feb 7 17:54:31 CET 2013


Hello,

now I got it working with python33. In win32com.client in function
WithEvents I exchanged event_class with user_event_class:

result_class = new_type("COMEventClass", (user_event_class, events_class),
{})

Same has to be done with the DispatchWithEvent function. If someone gives
me a hand on how to supply a patch I'll be glad do this.

Now it runs, but the behaviour didn't change: No events without focus. I am
starting to run out of ideas. :-(

Kind regards

Johannes Frank


2013/2/6 Johannes Frank <jmfrank63 at gmail.com>

> Hello Newsgroup,
>
> I am currently programming ProgeCAD an AutoCAD Clone and having
> difficulties catching all events.
>
> My code:
>
> import win32com.client
> import pythoncom,pywintypes
> import time
> import tkFileDialog
> import tkSimpleDialog
> import IntelliCAD
> import sys
>
> icad_CLSID = '{77E49E57-976B-11CF-8CCB-00A0245B09EB}'
> icad_ProgID = 'Icad.Application'
> icad_mod = win32com.client.gencache.EnsureModule(icad_CLSID, 0,1,0)
>
> defaultNamedOptArg=pythoncom.Empty
> defaultNamedNotOptArg=pythoncom.Empty
> defaultUnnamedArg=pythoncom.Empty
>
> class WorkspaceEvents(IntelliCAD._IcadWorkspaceEvents):
>     def __init__(self, oobj=None):
>         IntelliCAD._IcadWorkspaceEvents.__init__(self, oobj)
>
> # If you create handlers, they should have the following prototypes:
>     def OnBeginFileDrop(self, FileName=defaultNamedNotOptArg,
> Cancel=pythoncom.Missing):
>         print 'OnBeginFileDrop Occurs when a file is dropped on the
> application window'
>     def OnNewDrawing(self):
>         print 'OnNewDrawing Occurs when a new drawing is about to be
> created'
>     def OnAddinRun(self, AddinFunctionName=defaultNamedNotOptArg):
>         print 'OnAddinRun Occurs when the user runs an add-in function
> from the command line'
>     def OnEndModal(self):
>         print 'OnEndModal Occurs when a modal dialog is closed'
>     def OnExit(self):
>         print 'OnExit Occurs when the application is about to exit.'
>     def OnLispCancelled(self):
>         print 'OnLispCancelled Occurs when evaluation of a LISP expression
> is cancelled'
>     def OnNew(self, NewDocument=defaultNamedNotOptArg):
>         print 'OnNew Occurs when a new drawing has been created.'
>     def OnBeginOpen(self, DrawingName=defaultNamedNotOptArg):
>         print 'OnBeginOpen Occurs when a drawing is requested to be opened'
>     def OnEndSave(self, FileName=defaultNamedNotOptArg):
>         print 'OnEndSave Occurs when a request to save the drawing has
> been completed'
>     def OnEndCommand(self, CommandName=defaultNamedNotOptArg):
>         print 'OnEndCommand Occurs when a command is completed'
>     def OnEndPlot(self, DrawingName=defaultNamedNotOptArg):
>         print 'OnEndPlot Occurs when drawing has been sent to the printer'
>     def OnSave(self, Document=defaultNamedNotOptArg):
>         print 'OnSave Occurs when a drawing is about to be saved.'
>     def OnBeginLisp(self, FirstLine=defaultNamedNotOptArg):
>         print 'OnBeginLisp Occurs when receives a request to evaluate a
> LISP expression'
>     def OnEndOpen(self, DrawingName=defaultNamedNotOptArg):
>         print 'OnEndOpen Occurs after a drawing has been opened'
>     def OnBeginQuit(self, Cancel=pythoncom.Missing):
>         print 'OnBeginQuit Occurs when the application starts to shut
> down.  Returning False will terminate the shutdown.'
>     def OnReinitialize(self):
>         print 'OnReinitialize Occurs each time you open or create a
> drawing'
>     def OnAppDeactivate(self):
>         print 'OnAppDeactivate Occurs when the application window is
> deactivated'
>     def OnBeginSave(self, FileName=defaultNamedNotOptArg):
>         print 'OnBeginSave Occurs when receives a request to save the
> drawing'
>     def OnBeforeExit(self, Cancel=pythoncom.Missing):
>         print 'OnBeforeExit Occurs when the application starts to shut
> down.  Returning False will terminate the shutdown.'
>     def OnEndLisp(self):
>         print 'OnEndLisp Occurs when evaluation of a LISP expression is
> completed'
>     def OnWindowChanged(self, vicWindowState=defaultNamedNotOptArg):
>         print 'OnWindowChanged Occurs when window state is changed'
>     def OnBeginPlot(self, DrawingName=defaultNamedNotOptArg):
>         print 'OnBeginPlot Occurs when receives a request to print drawing'
>     def OnAppActivate(self):
>         print 'OnAppActivate Occurs when the application window is
> activated'
>     def OnStartup(self):
>         print 'OnStartup Occurs when the application is starting up.'
> #    def OnSysVarChanged(self, SysVarName=defaultNamedNotOptArg,
> NewVal=defaultNamedNotOptArg):
> #        print 'Occurs when the value of a system variable is changed'
>     def OnBeginModal(self):
>         print 'OnBeginModal Occurs when a modal dialog is about to be
> displayed'
>     def OnWindowMovedOrResized(self, HWNDFrame=defaultNamedNotOptArg,
> bMoved=defaultNamedNotOptArg):
>         print 'OnWindowMovedOrResized Occurs when window is moved or
> resized'
>     def OnClose(self, Document=defaultNamedNotOptArg):
>         print 'OnClose Occurs when a drawing is about to be closed.'
>     def OnBeginCommand(self, CommandName=defaultNamedNotOptArg):
>         print 'OnBeginCommand Occurs when a command is called'
>     def OnOpen(self, Document=defaultNamedNotOptArg):
>         print 'OnOpen Occurs after a drawing has been opened.'
>
>
> class DocumentEvents(IntelliCAD._EIcadDocument):
>     def __init__(self,oobj=None):
>         IntelliCAD._EIcadDocument.__init__(self, oobj)
>
> # If you create handlers, they should have the following prototypes:
>
>     def OnDeactivate(self):
>         print 'OnDeactivate Occurs when a document window is deactivated'
>     def OnBeginDocClose(self, Cancel=pythoncom.Missing):
>         print 'OnBeginDocClose Occurs when IntelliCAD receives a request
> to close the drawing'
>     def OnBeginPlot(self, DrawingName=defaultNamedNotOptArg):
>         print 'OnBeginPlot Occurs when receives a request to print drawing'
>     def OnBeginClose(self):
>         print 'OnBeginClose Occurs when IntelliCAD receives a request to
> close the drawing'
>     def OnEndCommand(self, CommandName=defaultNamedNotOptArg):
>         print 'OnEndCommand Occurs when a command completed'
>     def OnEndPlot(self, DrawingName=defaultNamedNotOptArg):
>         print 'OnEndPlot Occurs when drawing has been sent to the printer'
>     def OnSave(self):
>         print 'OnSave Occurs when a drawing is about to be saved.'
>     def OnBeginLisp(self, FirstLine=defaultNamedNotOptArg):
>         print 'OnBeginLisp Occurs when receives a request to evaluate a
> LISP expression'
>     def OnSelectionChanged(self):
>         print 'OnSelectionChanged Occurs when the current selection set is
> changed'
>     def OnLayoutSwitched(self, LayoutName=defaultNamedNotOptArg):
>         print 'OnLayoutSwitched Occurs after switching to a different
> layout'
>     def OnBeginSave(self, FileName=defaultNamedNotOptArg):
>         print 'OnBeginSave Occurs when receives a request to save the
> drawing'
>     def OnEndLisp(self):
>         print 'OnEndLisp Occurs when evaluating of a LISP expression
> completed'
>     def OnBeginDoubleClick(self, PickPoint=defaultNamedNotOptArg):
>         print 'OnBeginDoubleClick Occurs when the user double-clicks on
> the drawing window'
>     def OnWindowChanged(self, vicWindowState=defaultNamedNotOptArg):
>         print 'OnWindowChanged Occurs when window state changed'
>     def OnBeginRightClick(self, PickPoint=defaultNamedNotOptArg):
>         print 'OnBeginRightClick Occurs when the user right-clicks on the
> drawing window'
>     def OnLispCanceled(self):
>         print 'OnLispCanceled Occurs when evaluating of a LISP expression
> canceled'
>     def OnActivate(self):
>         print 'OnActivate Occurs when a document window is activated'
>     def OnEndSave(self, FileName=defaultNamedNotOptArg):
>         print 'OnEndSave Occurs when a request to save the drawing has
> been completed'
>     def OnWindowMovedOrResized(self, HWNDFrame=defaultNamedNotOptArg,
> bMoved=defaultNamedNotOptArg):
>         print 'OnWindowMovedOrResized Occurs when window moved or resized'
>     def OnClose(self,cancel=pythoncom.Missing):
>         print 'OnClose Occurs when a drawing is about to be closed.'
>     def OnBeginCommand(self, CommandName=defaultNamedNotOptArg):
>         print 'OnBeginCommand Occurs when receives a command'
>     def OnOpen(self):
>         print 'OnOpen Occurs after a drawing has been opened.'
>
> icad = win32com.client.Dispatch(icad_ProgID,'Administrator')
> app = icad.Application
> ws = icad.Workspace
> ad = icad.ActiveDocument
> ws_ev = win32com.client.WithEvents(app,WorkspaceEvents)
> doc_ev = win32com.client.WithEvents(ad,DocumentEvents)
>
> #pythoncom.PumpMessages()
>
> import Tkinter
> root = Tkinter.Tk()
> root.mainloop()
>
> Some workspace events are catched (like OnAppActivate and OnAppDeactivate)
> or for document events (OnActivate, OnDeactivate) but most are not.
> For instance opening drawings or adding new ones is ignored. If however I
> call the method for creating new documents or opening existing the events
> work. So the hint might be it has something to do with the focus.
> In VB2010 everything works as exspected so I think the program is ok.
>
> Neither root.mainloop() nor pythoncom.PumpMessages() work. I also tried a
> different implementation of the events:
>
> icad = IntelliCAD.Application()
> WSClass = ClassType("COMEventClass", (icad.__class__, icad.default_source,
>  WorkspaceEvents), {'__setattr__': win32com.client._event_setattr_})
> wse = WSClass(icad._oleobj_)
> icad.default_source.__init__(wse,wse)
> icad = win32com.client.EventsProxy(wse)
>
> ...but the behavior is just the same.
>
> Could threading be a solution to my problem? I've never done threading
> before and I am relativly new to python so if anyone could give me a
> starting hand for threading I'll be glad.
>
> Any other suggestions are also welcome.
>
> Thank you for your audience.
>
> Kind regards
>
> Johannes Frank
>
>
>
>
>
>
>
> --
> Dipl.-Ing. (FH) Johannes-Maria Frank
> Bildungsberater
> Königsberger-Str. 19b
> 76139 Karlsruhe
> Tel. +49(170) 3833849
> e-mail: jmfrank63 at gmail.com
>



-- 
Dipl.-Ing. (FH) Johannes-Maria Frank
Bildungsberater
Königsberger-Str. 19b
76139 Karlsruhe
Tel. +49(170) 3833849
e-mail: jmfrank63 at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20130207/0980c93e/attachment-0001.html>


More information about the python-win32 mailing list