From matteo.boscolo at boscolini.eu Tue May 3 12:29:16 2011 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Tue, 03 May 2011 12:29:16 +0200 Subject: [python-win32] win32gui.SetParent method with pyqt Message-ID: <4DBFD8FC.1000106@boscolini.eu> Hi All, I got a win mfc application and I have extended it win win32com using the pyqt as windows manager.. all work well but the two windows (pyqt diaolog and mfc application ) are in the some level but I need that the pyqt dialog is modal to the mfc application .. I use this function to set the parent . def setParentTD(self,objectDialog): try: main_app = 'thinkdesign' calc_hwnd = win32gui.FindWindow(None, main_app) print "calc_hwnd ",str(calc_hwnd ) print "self.winId ",objectDialog.winId() win32gui.SetParent(objectDialog.winId(),calc_hwnd) except: print "error on set parent" where objectDialog is the pyqt dialog ... in this way the pyqt dialog disappear .. any idea how to do such a think ..?? regards, Matteo From michael.illgner at googlemail.com Tue May 3 13:15:46 2011 From: michael.illgner at googlemail.com (Michael Illgner) Date: Tue, 3 May 2011 13:15:46 +0200 Subject: [python-win32] DispatchWithEvents Message-ID: Hi I have got some questions regarding win32com.client.DispatchEventWithEvents() Is there any documentation available for this method? I am writing a kind for a network proxy for a custom COM api. and I am using a simple socket server based on the standard python classes. The implemented request handler reads some data from the socket, transforms it suitable for the COM api and send the result back. the COM objects are constructed in the "main" thread using win32com.client.Dispatch() Now I am working on a handler for asychronous COM events, it is sufficient to replace Dispatch() with DispatchWithEvents() or do I have to start a new thread for every COM object using an event handler ? In my understanding the argument for DispatchWithEvents is a class and not an instance, so how can i configure or initialize my handler instance eg. for a handler specific TCP callback ? Any help or pointers to documentation/examples are greatly appreciated. Regards Michael From mhammond at skippinet.com.au Tue May 3 14:55:54 2011 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue, 03 May 2011 22:55:54 +1000 Subject: [python-win32] DispatchWithEvents In-Reply-To: References: Message-ID: <4DBFFB5A.1000607@skippinet.com.au> On 3/05/2011 9:15 PM, Michael Illgner wrote: > Hi > I have got some questions regarding win32com.client.DispatchEventWithEvents() > > Is there any documentation available for this method? Only the docstring. > I am writing a kind for a network proxy for a custom COM api. and I am > using a simple socket server based on the standard python classes. The > implemented request handler reads some data from the socket, > transforms it suitable for the COM api and send the result back. the > COM objects are constructed in the "main" thread using > win32com.client.Dispatch() > Now I am working on a handler for asychronous COM events, it is > sufficient to replace Dispatch() with DispatchWithEvents() or do I > have to start a new thread for every COM object using an event handler > ? There is nothing magic about events - you need to provide your own magic :) All the calls are still normal blocking calls - so if you want a model where methods on your com object are done in the background and fire when complete, you need to fully arrange for however that happens (be it threads or other non-blocking features.) A win32 message queue is often used, which is why it is a common requirement that apps using such objects must ensure a message loop is running on the main thread. > In my understanding the argument for DispatchWithEvents is a class and > not an instance, so how can i configure or initialize my handler > instance eg. for a handler specific TCP callback ? DispatchWithEvents takes or creates a COM object, then instantiates a single instance of the event class and hooks it up with the object - so there is a 1:1 relationship. Mark. > > Any help or pointers to documentation/examples are greatly appreciated. > > Regards > Michael > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From michael.illgner at googlemail.com Tue May 3 16:39:03 2011 From: michael.illgner at googlemail.com (Michael Illgner) Date: Tue, 3 May 2011 16:39:03 +0200 Subject: [python-win32] DispatchWithEvents In-Reply-To: <4DBFFB5A.1000607@skippinet.com.au> References: <4DBFFB5A.1000607@skippinet.com.au> Message-ID: 2011/5/3 Mark Hammond : > There is nothing magic about events - you need to provide your own magic :) > ?All the calls are still normal blocking calls - so if you want a model > where methods on your com object are done in the background and fire when > complete, you need to fully arrange for however that happens (be it threads > or other non-blocking features.) ?A win32 message queue is often used, which > is why it is a common requirement that apps using such objects must ensure a > message loop is running on the main thread. Hmm My application does not use any win32 functions aside of COM, so a simple time.sleep(1) pythoncom.PumpWaitingMessages() loop started in a thread is sufficient ? > > DispatchWithEvents takes or creates a COM object, then instantiates a single > instance of the event class and hooks it up with the object - so there is a > 1:1 relationship. OK so the eventhandler should be implemented as a kind of singleton ? From matteo.boscolo at boscolini.eu Tue May 3 21:17:16 2011 From: matteo.boscolo at boscolini.eu (Matteo Boscolo) Date: Tue, 03 May 2011 21:17:16 +0200 Subject: [python-win32] win32gui.SetParent method with pyqt In-Reply-To: <4DBFD8FC.1000106@boscolini.eu> References: <4DBFD8FC.1000106@boscolini.eu> Message-ID: <4DC054BC.4020904@boscolini.eu> hi all, I solve the problem in this way: this is the definition of the pyqt dialog: .. ... class ClientInterface(QDialog): ''' Class that manage all the interface actions ''' def __init__(self,hwid=False): ''' Dialog Constructor ''' parent=None # QDialog.__init__(self,parent) self.setParent=False def setParentTD(self,objectDialog): try: if self.setParent!=True: main_app = 'thinkdesign' calc_hwnd = win32gui.FindWindow(None, main_app) win32gui.SetParent(objectDialog.winId(),calc_hwnd) self.setParent=True except: print "error on set parent" def showWarning(self,message): """ show a warning message """ self.setParentTD(self) self._message("warning", message) def _message(self,type,message): self.setParentTD(self) msg=QMessageBox(self) msg.setText(message) if type=="warning": msg.setIcon(QMessageBox.Warning) elif type=="error": msg.setIcon(QMessageBox.Critical) else: msg.setIcon(QMessageBox.Information) msg.exec_() .. .... ... the ClientInterface in this case is an hidden object that wrap around the mfc main application. Hope that helps someone .. Regards, Matteo Il 03/05/2011 12:29, Matteo Boscolo ha scritto: > Hi All, > I got a win mfc application and I have extended it win win32com using > the pyqt as windows manager.. > > all work well but the two windows (pyqt diaolog and mfc application ) > are in the some level but I need that the pyqt dialog is modal to the > mfc application .. > I use this function to set the parent . > > def setParentTD(self,objectDialog): > try: > main_app = 'thinkdesign' > calc_hwnd = win32gui.FindWindow(None, main_app) > print "calc_hwnd ",str(calc_hwnd ) > print "self.winId ",objectDialog.winId() > win32gui.SetParent(objectDialog.winId(),calc_hwnd) > except: > print "error on set parent" > where objectDialog is the pyqt dialog ... > > in this way the pyqt dialog disappear .. > > any idea how to do such a think ..?? > > regards, > Matteo > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > > ----- > Nessun virus nel messaggio. > Controllato da AVG - www.avg.com > Versione: 10.0.1209 / Database dei virus: 1500/3611 - Data di > rilascio: 02/05/2011 > > From amit.paunikar at gmail.com Wed May 4 08:09:58 2011 From: amit.paunikar at gmail.com (DonAmit) Date: Tue, 3 May 2011 23:09:58 -0700 (PDT) Subject: [python-win32] Probelm with win32api dll load failed In-Reply-To: References: Message-ID: <31538793.post@talk.nabble.com> You can do this easy by adding this to the options dict in setup.py 'dll_excludes': [ "mswsock.dll", "powrprof.dll" ] source: http://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed -Amit Andrew Spagnoletti wrote: > > Hi, > ? > I have developed an application with Python 2.6 and wxPython and prepared > the set up using py2exe and InstallJammer. > ? > When I generated the installation from ?my Vista machine and then install > it on an XP computer (not sure if there is any significance to the Vista > -> XP), when I run the installed program on the XP machine I get the > following log (note that LegaliteInvoice contains the following import, > but so does LegaliteMain ? which calls LegaliteViewTransactions which > calls LegaliteInvoice): - > from win32com.client import Dispatch > ? > Traceback (most recent call last): > ? File "LegaliteMain.pyw", line 13, in > ? File "LegaliteViewTransactions.pyc", line 8, in > ? File "LegaliteInvoice.pyc", line 7, in > ? File "win32com\__init__.pyc", line 5, in > ? File "win32api.pyc", line 12, in > ? File "win32api.pyc", line 10, in __load > ImportError: DLL load failed: The specified procedure could not be found. > ? > Any ideas? > ? > > Andrew Spagnoletti > > -------------------------- > Sent using BlackBerry > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > -- View this message in context: http://old.nabble.com/Probelm-with-win32api-dll-load-failed-tp22778150p31538793.html Sent from the Python - python-win32 mailing list archive at Nabble.com. From mhammond at skippinet.com.au Wed May 4 08:25:53 2011 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 04 May 2011 16:25:53 +1000 Subject: [python-win32] DispatchWithEvents In-Reply-To: References: <4DBFFB5A.1000607@skippinet.com.au> Message-ID: <4DC0F171.6010004@skippinet.com.au> On 4/05/2011 12:39 AM, Michael Illgner wrote: > 2011/5/3 Mark Hammond: > >> There is nothing magic about events - you need to provide your own magic :) >> All the calls are still normal blocking calls - so if you want a model >> where methods on your com object are done in the background and fire when >> complete, you need to fully arrange for however that happens (be it threads >> or other non-blocking features.) A win32 message queue is often used, which >> is why it is a common requirement that apps using such objects must ensure a >> message loop is running on the main thread. > > Hmm > My application does not use any win32 functions aside of COM, so a simple > > time.sleep(1) > pythoncom.PumpWaitingMessages() > > loop started in a thread is sufficient ? Generally in the main thread, yes. And I basically mis-spoke in my previous reply - the message queue is often used due to COM using messaging to marshal between threads rather than the COM objects using it directly. It all depends on the object emitting the events - if the COM object delivers the events synchronously, you would get them delivered as they are generated - in effect, the COM object is just calling a "normal" blocking function - it just happens to be your event handler. They are just normal callbacks all on one thread. But some objects have a model where you call a method to start some process and the method returns immediately. In that case the object will make its own arrangements about how to manage the outstanding "work" after the start method returns. If it uses a different thread, it will need to "marshal" the event handlers to that other thread - then, when it tries to call the event handler, the COM marshaller will use the message queue so the callback actually happens on the main thread even though they were emitted from the worker thread - hence the main thread needs the message pump. If everything is happening in a free-threaded context though, no message loop is generally required. >> DispatchWithEvents takes or creates a COM object, then instantiates a single >> instance of the event class and hooks it up with the object - so there is a >> 1:1 relationship. > OK > so the eventhandler should be implemented as a kind of singleton ? If you want every object to wind up calling the same "handler", then yeah, you would have your event handler delegate to some other singleton. Cheers, Mark From jeffpeery at seametrics.com Wed May 4 20:09:22 2011 From: jeffpeery at seametrics.com (Jeff Peery) Date: Wed, 4 May 2011 11:09:22 -0700 Subject: [python-win32] Problem Automating IE on W7 Message-ID: <22D249B9E041654AA140F32C0E6F942753D5346565@EXVMBX018-3.exch018.msoutlookonline.net> Hello, I'm using the code pasted below to print a document with internet explorer. The code worked great on my XP machine. I moved it to my W7 machine and it gives the error below. The weird thing is that it works great if printing a html doc from the web (such as www.google.com), but it errors when printing a html doc from my desktop. The document loads (as I can see it on the screen) but it chokes when printing. Perhaps it is a problem with a new version of IE? Any have a similar problem? thanks, Jeff line 23, in Print win32com.client.constants.OLECMDEXECOPT_DONTPROMPTUSER) File "C:\Python27\lib\site-packages\win32com\gen_py\EAB22AC0-30C1-11CF-A7EB-0000C05BAE0Bx0x1x1.py", line 1186, in ExecWB , cmdexecopt, pvaIn, pvaOut) File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 456, in _ApplyTypes_ self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args), com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147221248), None) import win32com.client from time import sleep class Printer(): def __init__(self): pass def WaitBusy(self, ie): while ie.Busy: sleep(0.5) def WaitUntilReady(self, ie): while ie.ReadyState!=4: sleep(0.5) def Print(self, doc_name): ie = win32com.client.Dispatch("InternetExplorer.Application") ie.Visible = 1 ie.Navigate(doc_name) # wait for ie to open before printing self.WaitBusy(ie) ie.ExecWB(win32com.client.constants.OLECMDID_PRINT, win32com.client.constants.OLECMDEXECOPT_DONTPROMPTUSER) ## ie.Quit() p = Printer() p.Print('test.htm') -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Wed May 4 20:39:00 2011 From: timr at probo.com (Tim Roberts) Date: Wed, 4 May 2011 11:39:00 -0700 Subject: [python-win32] Problem Automating IE on W7 In-Reply-To: <22D249B9E041654AA140F32C0E6F942753D5346565@EXVMBX018-3.exch018.msoutlookonline.net> References: <22D249B9E041654AA140F32C0E6F942753D5346565@EXVMBX018-3.exch018.msoutlookonline.net> Message-ID: <4DC19D44.409@probo.com> Jeff Peery wrote: > > > I'm using the code pasted below to print a document with internet > explorer. The code worked great on my XP machine. I moved it to my W7 > machine and it gives the error below. The weird thing is that it works > great if printing a html doc from the web (such as www.google.com > ), but it errors when printing a html doc from > my desktop. The document loads (as I can see it on the screen) but it > chokes when printing. Perhaps it is a problem with a new version of IE? > > ... > > com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, > 0, -2147221248), None) -2147221248 is 0x80040100, which is either DRAGDROP_E_NOTREGISTERED (unlikely) OLECMDERR_E_NOTSUPPORTED. I know they've tightened up security quite a bit, but it's hard to see how that applies here. Is this a "funky" web page, or just a simple HTML doc? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From jeffpeery at seametrics.com Wed May 4 21:35:15 2011 From: jeffpeery at seametrics.com (Jeff Peery) Date: Wed, 4 May 2011 12:35:15 -0700 Subject: [python-win32] Problem Automating IE on W7 In-Reply-To: <4DC19D44.409@probo.com> References: <22D249B9E041654AA140F32C0E6F942753D5346565@EXVMBX018-3.exch018.msoutlookonline.net> <4DC19D44.409@probo.com> Message-ID: <22D249B9E041654AA140F32C0E6F942753D53465B8@EXVMBX018-3.exch018.msoutlookonline.net> This is just a standard html doc. As simple as it gets. -----Original Message----- From: python-win32-bounces+jeffpeery=seametrics.com at python.org [mailto:python-win32-bounces+jeffpeery=seametrics.com at python.org] On Behalf Of Tim Roberts Sent: Wednesday, May 04, 2011 11:39 AM To: Python-Win32 List Subject: Re: [python-win32] Problem Automating IE on W7 Jeff Peery wrote: > > > I'm using the code pasted below to print a document with internet > explorer. The code worked great on my XP machine. I moved it to my W7 > machine and it gives the error below. The weird thing is that it works > great if printing a html doc from the web (such as www.google.com > ), but it errors when printing a html doc from > my desktop. The document loads (as I can see it on the screen) but it > chokes when printing. Perhaps it is a problem with a new version of IE? > > ... > > com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, > 0, -2147221248), None) -2147221248 is 0x80040100, which is either DRAGDROP_E_NOTREGISTERED (unlikely) OLECMDERR_E_NOTSUPPORTED. I know they've tightened up security quite a bit, but it's hard to see how that applies here. Is this a "funky" web page, or just a simple HTML doc? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From mhammond at skippinet.com.au Thu May 5 01:51:55 2011 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 05 May 2011 09:51:55 +1000 Subject: [python-win32] DispatchWithEvents In-Reply-To: References: <4DBFFB5A.1000607@skippinet.com.au> <4DC0F171.6010004@skippinet.com.au> Message-ID: <4DC1E69B.5060501@skippinet.com.au> [re-added the mailing list - please keep everything there] On 4/05/2011 6:09 PM, Michael Illgner wrote: > 2011/5/4 Mark Hammond: >> On 4/05/2011 12:39 AM, Michael Illgner wrote: >>> > >> If everything is happening in a free-threaded context though, no message >> loop is generally required. > > my server "architecture" is quiet simple > > com_object = win32com.client.DispatchWithEvents("xyz.xyz", MyEventHandler) > tcp_handler = MyTCPHandler(com_object) > server = ThreadedTCPServer((host,port), tcp_handler) > server.serve_forever() The question is more about the object xyz.xyz - if it is marked in the registry and either free-threading or "both", then you can arrange to set sys.coinit_flags=0 (which is COINIT_MULTITHREADED), you should be good to go - the objects can probably be used across threads without complication. The threads do force some complication - the com_object can't be used on any other thread directly - you must pass it to a different thread via pythoncom.CoMarshalInterThreadInterfaceInStream - you will probably need to search for samples. I believe that depending on the threading model, the object returned will either marshal back the main thread or just make the call directly on the new thread depending on all the threading models involved. To be quite honest, I'm really not sure what will happen to the incoming events though - I'm pretty sure no thread marshalling will occur and the events will be called directly on the thread used by the COM object - so in your example, the threaded tcp server handlers will never see the events on its own thread. Thus, how your main thread needs to stay alive will depend on the implementation of xyz.xyz - if it can send events while it's main thread isn't running (ie, after it has returned from a call you made on it), then it presumably will want to use a message loop to dispatch them. > I have some experience in writing messages loops in C, but can you > provide me with an example in python ? pythoncom.PumpMessages() or a loop using pythoncom.PumpWaitingMessages is all you need. However, that will be complicated in your model, as the main thread will be in the TCP server's listen loop. You probably need the creation of the server to be in its own thread, which would be dedicates to the listen and spawning new threads for handlers. >> If you want every object to wind up calling the same "handler", then yeah, >> you would have your event handler delegate to some other singleton. >> > My handler needs some configuration data like an inet adress to send > data back to the client, my first idea was to pass this data to the > constructor / __init__ method, but i can use a kind of static or > global configuration data object for this purpose too. So in effect you are just "broadcasting" on the tcp-server in response to the COM events? I expect you will wind up needing a queue per connection, with each COM event sticking stuff in the queue and the tcp handlers reading from one. Cheers, Mark From michael.illgner at googlemail.com Thu May 5 09:49:19 2011 From: michael.illgner at googlemail.com (Michael Illgner) Date: Thu, 5 May 2011 09:49:19 +0200 Subject: [python-win32] DispatchWithEvents In-Reply-To: <4DC1E69B.5060501@skippinet.com.au> References: <4DBFFB5A.1000607@skippinet.com.au> <4DC0F171.6010004@skippinet.com.au> <4DC1E69B.5060501@skippinet.com.au> Message-ID: 2011/5/5 Mark Hammond : > [re-added the mailing list - please keep everything there] > Sorry, my fault > On 4/05/2011 6:09 PM, Michael Illgner wrote: >> >> 2011/5/4 Mark Hammond: >>> > The question is more about the object xyz.xyz - if it is marked in the > registry and either free-threading or "both", then you can arrange to set > sys.coinit_flags=0 (which is COINIT_MULTITHREADED), you should be good to go > - the objects can probably be used across threads without complication. > > The threads do force some complication - the com_object can't be used on any > other thread directly - you must pass it to a different thread via > pythoncom.CoMarshalInterThreadInterfaceInStream - you will probably need to > search for samples. ?I believe that depending on the threading model, the > object returned will either marshal back the main thread or just make the > call directly on the new thread depending on all the threading models > involved. > I just took a look at the registry, the InprocServer32 key of my COM component has an entry ThreadingModel with value "both". So I if create the COM objects in the main thread and the socket server starts a new thread for every incoming request (socketserver.ThreadingMixIn) and the request handler uses pythoncom.CoInitialize/CoUninitialize for every request I should be on the right side ? This seems to work, but should I expect memory leaks, dangling handles etc. ? > pythoncom.PumpMessages() or a loop using pythoncom.PumpWaitingMessages is > all you need. ?However, that will be complicated in your model, as the main > thread will be in the TCP server's listen loop. ?You probably need the > creation of the server to be in its own thread, which would be dedicates to > the listen and spawning new threads for handlers. > Ok, I will start the server_forever() loop in a separate thread, this should be simple ;-) >>> If you want every object to wind up calling the same "handler", then >>> yeah, >>> you would have your event handler delegate to some other singleton. >>> >> My handler needs some configuration data like ?an inet adress to send >> data back to the client, my first idea was to pass this data to the >> constructor / __init__ method, but i can use a kind of static or >> global configuration data object for this purpose too. > > So in effect you are just "broadcasting" on the tcp-server in response to > the COM events? ?I expect you will wind up needing a queue per connection, > with each COM event sticking stuff in the queue and the tcp handlers reading > from one. yes, the COM object send some status events during their lifetime, not directly related to other COM calls. The python event handler just collects the data for an event and sends them to another server using a socket. regards Michael From skippy.hammond at gmail.com Thu May 5 14:43:26 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 05 May 2011 22:43:26 +1000 Subject: [python-win32] DispatchWithEvents In-Reply-To: References: <4DBFFB5A.1000607@skippinet.com.au> <4DC0F171.6010004@skippinet.com.au> <4DC1E69B.5060501@skippinet.com.au> Message-ID: <4DC29B6E.7040001@gmail.com> On 5/05/2011 5:49 PM, Michael Illgner wrote: > I just took a look at the registry, the InprocServer32 key of my COM > component has an entry ThreadingModel with value "both". > So I if create the COM objects in the main thread and the socket > server starts a new thread for every incoming request > (socketserver.ThreadingMixIn) and the request handler uses > pythoncom.CoInitialize/CoUninitialize for every request I should be on > the right side ? This seems to work, but should I expect memory leaks, > dangling handles etc. ? Should be fine. >> So in effect you are just "broadcasting" on the tcp-server in response to >> the COM events? I expect you will wind up needing a queue per connection, >> with each COM event sticking stuff in the queue and the tcp handlers reading >> from one. > yes, the COM object send some status events during their lifetime, not > directly related to other COM calls. The python event handler just > collects the data for an event and sends them to another server using > a socket. Sounds good too - so long as you have a handle on the fact the events may be delivered on a different thread than the server response thread, you should be in good shape :) Cheers, Mark From maillist at schwertberger.de Sat May 7 12:32:57 2011 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Sat, 07 May 2011 12:32:57 +0200 Subject: [python-win32] Interaction between wxPython and win32ui on Win 7 Message-ID: <4DC51FD9.5010702@schwertberger.de> Hi! I'm observing some strange interaction between wxPython and win32ui on Windows 7 PCs. I've been using DDE code from Pythonwin which in turn uses win32ui. When I use win32ui and SetToolTipString from wxPython in the same program, the Python interpreter will not exit any more (until it's killed from the task manager or by closing the console window.) See below for the code. If I omit "import win32ui" or "panel.SetToolTipString(...)", then the interpreter will exit as expected. I've posted the problem on the wxPython mailing list and Robin Dunn suggested the workaround of calling wx.Exit(), which is more or less the equivalent to killing the interpreter. Robin's comment: > It seems that something that is done during the import of win32ui > is conflicting somehow with what is done when a wxToolTip object > is created. The wx side of things is not too complex, it basically > just adds a new WndProc function to the chain of WndProcs for the > window that will respond to the tooltip messages. Maybe win32ui is > doing something similar and is getting stuck when it is trying to > clean up at exit? Am I missing anything? Is there e.g. a finalize function or something like that? Calling wx.Exit() works for me, but it's not a nice way to finish... The versions: pywin32 build 216 wxPython 2.8.12.0 or 2.8.11.0 Python 2.7 (same with 2.6 and an older version of wxPython and pywin32) With Windows XP or 2000 everything works as expected. I think I had the problem already with Vista, but I'm not sure. One user has reported that the code works for him under Win7 with Python 2.6.5. Regards, Dietmar import wx import win32ui class MyFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, -1, "test frame") panel = wx.Panel(self, -1) panel.SetToolTipString("test") self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) def OnCloseWindow(self, event): self.Destroy() import sys app = wx.App() frame = MyFrame(None) frame.Show(True) app.MainLoop() print "calling sys.exit()" sys.exit() From mc at mclaveau.com Sat May 7 15:33:42 2011 From: mc at mclaveau.com (Michel Claveau) Date: Sat, 7 May 2011 15:33:42 +0200 Subject: [python-win32] Interaction between wxPython and win32ui on Win 7 In-Reply-To: <4DC51FD9.5010702@schwertberger.de> References: <4DC51FD9.5010702@schwertberger.de> Message-ID: <6BF6313478E542C18311AD3D0314F1B8@MCI1330> Hi! I have the same problem, in several cases without wx (OCX+pywin32 ; ATL+ctypes ; etc.) For terminate these "rebel" scripts, I use this code: import os pid=os.getpid() os.system("TASKKILL /F /PID "+str(pid)) @-salutations -- Michel Claveau From skippy.hammond at gmail.com Mon May 9 03:03:42 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 09 May 2011 11:03:42 +1000 Subject: [python-win32] Interaction between wxPython and win32ui on Win 7 In-Reply-To: <4DC51FD9.5010702@schwertberger.de> References: <4DC51FD9.5010702@schwertberger.de> Message-ID: <4DC73D6E.8030608@gmail.com> On 7/05/2011 8:32 PM, Dietmar Schwertberger wrote: > Hi! > > I'm observing some strange interaction between wxPython and win32ui > on Windows 7 PCs. win32ui is built around the MFC framework, so has a fair bit of complications just from that layer. However, just importing win32ui and not creating any win32ui specific behaviour shouldn't be a problem. ... > app.MainLoop() > > print "calling sys.exit()" > sys.exit() Where exactly does things get stuck? Do you see that print statement, or is it app.MainLoop which fails to return? Mark From maillist at schwertberger.de Mon May 9 20:56:12 2011 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Mon, 09 May 2011 20:56:12 +0200 Subject: [python-win32] Interaction between wxPython and win32ui on Win 7 In-Reply-To: <4DC73D6E.8030608@gmail.com> References: <4DC51FD9.5010702@schwertberger.de> <4DC73D6E.8030608@gmail.com> Message-ID: <4DC838CC.4080903@schwertberger.de> Am 09.05.2011 03:03, schrieb Mark Hammond: > Where exactly does things get stuck? Do you see that print statement, or > is it app.MainLoop which fails to return? The main loop retuns such that I see the print statement. But the interpreter does not exit. Even if I move the win32ui import right after the mainloop, it does not exit. Regards, Dietmar From palla74 at gmail.com Wed May 11 11:52:53 2011 From: palla74 at gmail.com (Palla) Date: Wed, 11 May 2011 11:52:53 +0200 Subject: [python-win32] EuroPython: Early Bird will end in 2 days! Message-ID: Hi all, If you plan to attend, you could save quite a bit on registration fees! The end of Early bird is on May 12th, Friday, 23:59:59 CEST. We'd like to ask to you to forward this post to anyone that you feel may be interested. We have an amazing lineup of tutorials, events and talks. We have some excellent keynote speakers and a very complete partner program... but early bird registration ends in 2 days! Right now, you still get discounts on talks and tutorials so if you plan to attend Register Now: http://ep2011.europython.eu/registration/ While you are booking, remember to have a look at the partner program and our offer for a prepaid, data+voice+tethering SIM. We'd like to ask to you to forward this post to anyone that you feel may be interested. All the best, -- ->PALLA From adam at adamplowman.co.uk Sun May 15 11:08:41 2011 From: adam at adamplowman.co.uk (Adam Plowman) Date: Sun, 15 May 2011 10:08:41 +0100 Subject: [python-win32] ImpersonateLoggedOnUser and IIS Message-ID: <24A0B690-FCBC-47A1-9914-5EA6A3D3F48B@adamplowman.co.uk> Hello, I am looking to create a integrated project that can connect into exchange and sharepoint using the TG2 framework. I don't want the user to log in several times. In asp i could use impersonate to get the access token from IIS and pass this across the network but Python is my language. Microsoft seem to have locked down this access token to asp only. Is there away of getting this token with Python? I have seen ImpersonateLoggedOnUser function. WIll this do the job? Regards Adam -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Tue May 17 07:58:07 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 17 May 2011 17:58:07 +1200 Subject: [python-win32] Bundling font with application? Message-ID: <4DD20E6F.7050302@canterbury.ac.nz> Is there a way to tell an ordinary Windows application to look for fonts in a specific directory, or load a font from a specific file? The only things I've been able to find about this using Google all relate to .NET. -- Greg From gagsl-py2 at yahoo.com.ar Tue May 17 14:36:30 2011 From: gagsl-py2 at yahoo.com.ar (Gabriel Genellina) Date: Tue, 17 May 2011 09:36:30 -0300 Subject: [python-win32] Bundling font with application? References: <4DD20E6F.7050302@canterbury.ac.nz> Message-ID: En Tue, 17 May 2011 02:58:07 -0300, Greg Ewing escribi?: > Is there a way to tell an ordinary Windows application to > look for fonts in a specific directory, or load a font from > a specific file? The only things I've been able to find about > this using Google all relate to .NET. I think AddFontResourceEx is what you are looking for. http://msdn.microsoft.com/en-us/library/dd183327(v=VS.85).aspx -- Gabriel Genellina From jacobk at proscanmobility.co.za Tue May 17 15:16:08 2011 From: jacobk at proscanmobility.co.za (Jacob Kruger) Date: Tue, 17 May 2011 15:16:08 +0200 Subject: [python-win32] First post to list, etc. Message-ID: <3D868BC5B4106041A7D4CF582A8871EA73E4BB31E7@proserver-1.proscan.local> I'm now (finally) starting to actually try get started with python, etc., and aside from being partly interested in the symbian/phone implementation thereof, I am initially just starting off looking into python apps running on windows systems, but aside from an actually installed interpreter, etc., am also just wondering about things like the sort of wrapper possibilities, where you can include some sort of compiled python code in an .exe file etc. That should then be able to (hopefully) run on most windows machines as a sort of standalone app, but if I'm totally confused about possibilities, then would also like to know for sure, and also wondering if this might be related to being limited to only certain versions of python, etc.? Currently have both 2.6 and 3.2 installed on this machine - windows7 32 bit, but also on my other primary machine - windows7 64 bit, but I do also have another windows XP machine that might also want to test/try these things out on. Alternatively, where's the best place to start looking for things like this? TIA Jacob Name: Jacob Kruger Job Title: Software Developer Mobile: +27 11 615 3103 email: jacobk at proscanmobility.co.za Disclaimer: The information contained in this communication from the sender is confidential and may be legally privileged. It is intended solely for use by recipient and others authorized to receive it. If you are not the recipient you are hereby notified that any disclosure, copying, distribution or taking action in reliance of the contents of this information is strictly prohibited and may be unlawful. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 111051715132002002.gif Type: image/gif Size: 4461 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 111051715132002202.gif Type: image/gif Size: 28142 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: 111051715132002402.gif Type: image/gif Size: 33203 bytes Desc: not available URL: From mail at timgolden.me.uk Tue May 17 15:35:36 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 17 May 2011 14:35:36 +0100 Subject: [python-win32] First post to list, etc. In-Reply-To: <3D868BC5B4106041A7D4CF582A8871EA73E4BB31E7@proserver-1.proscan.local> References: <3D868BC5B4106041A7D4CF582A8871EA73E4BB31E7@proserver-1.proscan.local> Message-ID: <4DD279A8.7080107@timgolden.me.uk> On 17/05/2011 14:16, Jacob Kruger wrote: > I?m now (finally) starting to actually try get started with python, > etc., and aside from being partly interested in the symbian/phone > implementation thereof, I am initially just starting off looking into > python apps running on windows systems, but aside from an actually > installed interpreter, etc., am also just wondering about things like > the sort of wrapper possibilities, where you can include some sort of > compiled python code in an .exe file etc. That should then be able to > (hopefully) run on most windows machines as a sort of standalone app, > but if I?m totally confused about possibilities, then would also like to > know for sure, and also wondering if this might be related to being > limited to only certain versions of python, etc.? py2exe[1] is the usual recommendation. There's also pyInstaller[2]. > Alternatively, where?s the best place to start looking for things like this? This is probably as good a place as any. There's also the main Python mailing list[3] (which has more readers...) TJG [1] http://www.py2exe.org/ [2] http://www.pyinstaller.org/ [3] http://mail.python.org/mailman/listinfo/python-list From vernondcole at gmail.com Tue May 17 16:47:52 2011 From: vernondcole at gmail.com (Vernon Cole) Date: Tue, 17 May 2011 08:47:52 -0600 Subject: [python-win32] First post to list, etc. In-Reply-To: <3D868BC5B4106041A7D4CF582A8871EA73E4BB31E7@proserver-1.proscan.local> References: <3D868BC5B4106041A7D4CF582A8871EA73E4BB31E7@proserver-1.proscan.local> Message-ID: Jacob: Sounds like you have arrived at the "read a book" stage. For Python in general try: "Dive into Python" http://diveintopython.org/ which is available on line or in print. For Windows specific applications, the book by Mark Hammond still has good information, even though it was written ten years ago and is based on a very old version of python. "Python Programming on Win 32". I think an electronic version of it may have been pirated on line as well. Yes, everything in pywin32 works on 64 bit versions of Windows and Python, too. -- Vernon Cole On Tue, May 17, 2011 at 7:16 AM, Jacob Kruger wrote: > > I?m now (finally) starting to actually try get started with python, etc., and aside from being partly interested in the symbian/phone implementation thereof, I am initially just starting off looking into python apps running on windows systems, but aside from an actually installed interpreter, etc., am also just wondering about things like the sort of wrapper possibilities, where you can include some sort of compiled python code in an .exe file etc. That should then be able to (hopefully) run on most windows machines as a sort of standalone app, but if I?m totally confused about possibilities, then would also like to know for sure, and also wondering if this might be related to being limited to only certain versions of python, etc.? > > > > Currently have both 2.6 and 3.2 installed on this machine ? windows7 32 bit, but also on my other primary machine ? windows7 64 bit, but I do also have another windows XP machine that might also want to test/try these things out on. > > > > Alternatively, where?s the best place to start looking for things like this? > > > > TIA > > > > Jacob > > Jacob Kruger > Software Developer > Tel: +27 11 615 3103 > Fax: +27 11 615 2811 > Fax to Email: 086 590 5107 > email: jacobk at proscanmobility.co.za > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rays at blue-cove.com Tue May 17 17:00:05 2011 From: rays at blue-cove.com (RayS) Date: Tue, 17 May 2011 08:00:05 -0700 Subject: [python-win32] First post to list, etc. In-Reply-To: <3D868BC5B4106041A7D4CF582A8871EA73E4BB31E7@proserver-1.pro scan.local> References: <3D868BC5B4106041A7D4CF582A8871EA73E4BB31E7@proserver-1.proscan.local> Message-ID: <20110517150032.UOCL17030.fed1rmfepo101.cox.net@fed1rmimpo01.cox.net> An HTML attachment was scrubbed... URL: From timr at probo.com Tue May 17 19:51:49 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 17 May 2011 10:51:49 -0700 Subject: [python-win32] First post to list, etc. In-Reply-To: <3D868BC5B4106041A7D4CF582A8871EA73E4BB31E7@proserver-1.proscan.local> References: <3D868BC5B4106041A7D4CF582A8871EA73E4BB31E7@proserver-1.proscan.local> Message-ID: <4DD2B5B5.2080304@probo.com> Jacob Kruger wrote: > > I?m now (finally) starting to actually try get started with python, > etc., and aside from being partly interested in the symbian/phone > implementation thereof, I am initially just starting off looking into > python apps running on windows systems, but aside from an actually > installed interpreter, etc., am also just wondering about things like > the sort of wrapper possibilities, where you can include some sort of > compiled python code in an .exe file etc. That should then be able to > (hopefully) run on most windows machines as a sort of standalone app, > but if I?m totally confused about possibilities, then would also like > to know for sure, and also wondering if this might be related to being > limited to only certain versions of python, etc.? > Python code is not compiled, at least not in the mainstream implementations. There must always be an interpreter. Packages like py2exe bundle up your script, the interpreter, and the necessary files from the standard library into a single file that can be run AS IF it were a compiled binary. At run time, the pieces are unzipped into a local directory, executed, and then released. That does have a certain amount of overhead, but it means you always use the version you expect. In our local office, I've pushed a copy of the interpreter onto all of our machines, just so I can run scripts without that overhead. By the way, the HTML email overhead in your message was quite obnoxious. Less than 1/3 of the surface area of your email was dedicated to your message. The rest was advertising and a legally pointless disclaimer. I'm sure you don't have any control over that, but I hope you remind your management team once in a while that many people really dislike that kind of email. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From cappy2112 at gmail.com Tue May 17 20:45:39 2011 From: cappy2112 at gmail.com (Tony Cappellini) Date: Tue, 17 May 2011 11:45:39 -0700 Subject: [python-win32] Getting address for Parallel port Message-ID: We are using PCI &PCIe Parallel Port plugin cards to control some external hardware because newer motherboards no longer have built-in parallel ports. The address is NOT 0x378 as it would be if the parallel port was on the motherboard. The OS is Windows XP, SP3. These plugin cards can get mapped into various address spaces when the driver loads. In order to minimize hard-coding these addresses on each system, I would like to find out if there is a way to get this address via Pythonwin or Ctypes. To turn the port on & off, I use this call: ctypes.windll.inpout32.Out32(parallelPortAddress, onOff) via ctypes, and this DLL http://logix4u.net/Legacy_Ports/Parallel_Port/Inpout32.dll_for_Windows_98/2000/NT/XP.html Is there a way I can get the address of the parallel port- from Python? Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue May 17 21:54:14 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 17 May 2011 12:54:14 -0700 Subject: [python-win32] Getting address for Parallel port In-Reply-To: References: Message-ID: <4DD2D266.2010309@probo.com> Tony Cappellini wrote: > > We are using PCI &PCIe Parallel Port plugin cards to control some > external hardware because newer motherboards no longer have built-in > parallel ports. It would be a much better long term strategy to move to USB for this. There are a large number of very simple USB cards with 16 or 24 fully programmable I/O pins. The hacked up I/O port driver you're using is a huge security risk. > These plugin cards can get mapped into various address spaces when the > driver loads. Right -- in most BIOSes, the port number is derived from the PCI slot number. > In order to minimize hard-coding these addresses on each system, I > would like to find out if there is a way to get this address via > Pythonwin or Ctypes. Not easily. You can use the SetupDi APIs to enumerate through the set of parallel port devices, then use SetupDiGetDeviceInfoListDetail and CM_Get_First_Log_Conf_Ex to fetch the resource list, then a couple other CM_ APIs to crack that format and find the port number, but in my opinion it's a lot easier to ask the user to check the Device Manager resources page and type in the port number to use. If you insist, the "devcon" sample in the WDK has code that shows how to do this. > To turn the port on & off, I use this call: > ctypes.windll.inpout32.Out32(parallelPortAddress, onOff) via ctypes, > and this DLL > http://logix4u.net/Legacy_Ports/Parallel_Port/Inpout32.dll_for_Windows_98/2000/NT/XP.html That's dangerous. Any application can use that driver to gain access to any arbitrary I/O port. There's a reason why port access is not allowed from user mode. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From greg.ewing at canterbury.ac.nz Tue May 17 23:46:24 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 18 May 2011 09:46:24 +1200 Subject: [python-win32] Bundling font with application? In-Reply-To: References: <4DD20E6F.7050302@canterbury.ac.nz> Message-ID: <4DD2ECB0.7030400@canterbury.ac.nz> Gabriel Genellina wrote: > I think AddFontResourceEx is what you are looking for. > http://msdn.microsoft.com/en-us/library/dd183327(v=VS.85).aspx Yes, that sounds like it may do what I want, thanks. -- Greg From cappy2112 at gmail.com Wed May 18 21:56:24 2011 From: cappy2112 at gmail.com (Tony Cappellini) Date: Wed, 18 May 2011 12:56:24 -0700 Subject: [python-win32] Getting address for Parallel port Message-ID: > > >>The hacked up I/O port driver you're using is a huge security risk. > Our test machines are not connected to a network, and we don't ship systems or software. The test machines are strictly for use in an engineering testing environment. USB drivers have proven to be too flaky. Some work well, some don't. You never know what you're going to end up with until weeks into a testing period when a driver hangs the machine. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacobk at mailzone.co.za Thu May 19 11:22:07 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Thu, 19 May 2011 11:22:07 +0200 Subject: [python-win32] Next question relating to 'better' versions Message-ID: Ok, firstly, I have moved over to an email address I do actually have some control over the format of, but anyway. Aside from that, I was just wondering what versions of python would be better to actually get used to since while I am currently going through a 4th edition version of Learning Python, which is one of the books I ran across a mention of in the specific tutorial material I was looking at for Eclipse IDE etc. earlier since that's the sort of preferred IDE for some of the guys here at work who want to focus on a specific form of python development for a hand held device, but I see in that book they mention various version changes relating to some built in functions, slight syntax changes, etc., and, for example, while now looking into py2exe, I see that it currently is only meant to support up to around python 2.7 at the moment..? Another simple example was that while playing around at looking into something like a rather simple interactive fiction interpreter that was using to test various tutorial bits of material, I see that while in 3.2 I had been using the input() function, it does something a bit different if I then try execute that piece of scripting/coding via 2.7 or 2.6 - tries to do what 3.2 would call an eval() on it. That's still not the end of the world, but had currently been playing around with python 3.2 on my 2 different machines, but do also have 2.6 and 2.7 installed, but, for example, the environment variable's path variable currently refers to python 3.2, but anyway - just wondering if it's better to not rush into newer versions off-hand, since also think my boss mentioned 2.6 to me or something? Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From mail at timgolden.me.uk Thu May 19 15:15:58 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 19 May 2011 14:15:58 +0100 Subject: [python-win32] Next question relating to 'better' versions In-Reply-To: References: Message-ID: <4DD5180E.2040905@timgolden.me.uk> On 19/05/2011 10:22, Jacob Kruger wrote: > Ok, firstly, I have moved over to an email address I do actually have > some control over the format of, but anyway. Thanks for doing that -- it does make a difference to those of us reading the result :) [... Which version of Python? ...] It's a tricky one (sometimes) and an amount is determined by what libraries or tools you want / need to use. You've mentioned py2exe and Eclipse, and if the lack of those, for example, is a showstopper then your decision is made. That said, PyDev (the Python "mode" for Eclipse) does appear to support Python 3 (I can't find an outright statement to that effect, but there are several mentions of Python3 in their docs). Also, I don't about py2exe, but cx_freeze seems to have versions for Python 3. But regardless of tools, there's the wider issue: which is better to start off with? I think it's worth pointing out that, especially if you're looking at 2.7 -- but even with earlier 2.x versions -- there isn't *that* much difference. My wmi library runs unaltered on versions from 2.4 to 3.3. I did have to make some tiny compromises, but the point I'm making is that Python 3 is *not* worlds away from Python 2. Whichever version you plump for now, you'll be well-placed to use the other one if you ever need to. General guidance would be: go with Python 3 if you're starting afresh, unless you have some overriding need for a library or tool which hasn't been ported (and which you can't easily port yourself... it might be easier than you think). Another of my libraries runs on both versions by virtue of running the 2to3.py library across it on install. (The pywin32 extensions use the same approach). TJG From jacobk at mailzone.co.za Thu May 19 15:38:36 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Thu, 19 May 2011 15:38:36 +0200 Subject: [python-win32] Next question relating to 'better' versions In-Reply-To: <4DD5180E.2040905@timgolden.me.uk> Message-ID: Cool. Thanks. I think that for now, until they maybe confirm that the plugins they'd want to include for actual use won't work with it, etc., I'll just stick to 3.2, and will also worry about turning it into standalone executables at a later stage since that's not really an issue either at this stage - more related to me just thinking about passing some small apps on to various guys who might not have python installed as such at some stage. For now am really just trying to get relatively comfortable with any syntax differences from other environments etc. have worked in the most recently (C# and PHP, and javascript), but will also just say that my one irritation with most languages has always been what I would describe as array content management, and I am so far quite impressed with python handling all it's different types of sequential data object handling, etc. - hope that terminology isn't too far off, but mean things like list, tuple, dictionary objects, etc. etc., and I do also quite like the polymorphism of object/variable types, but along with their built-in function handling/attachment. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' ----- Original Message --------------- Subject: Re: [python-win32] Next question relating to 'better' versions From: Tim Golden Date: Thu, 19 May 2011 14:15:58 +0100 To: Cc: python-win32 at python.org >On 19/05/2011 10:22, Jacob Kruger wrote: >> Ok, firstly, I have moved over to an email address I do actually have >> some control over the format of, but anyway. > >Thanks for doing that -- it does make a difference to those >of us reading the result :) > >[... Which version of Python? ...] > >It's a tricky one (sometimes) and an amount is determined by what >libraries or tools you want / need to use. You've mentioned py2exe >and Eclipse, and if the lack of those, for example, is a showstopper >then your decision is made. That said, PyDev (the Python "mode" for >Eclipse) does appear to support Python 3 (I can't find an outright >statement to that effect, but there are several mentions of Python3 >in their docs). Also, I don't about py2exe, but cx_freeze seems to >have versions for Python 3. > >But regardless of tools, there's the wider issue: which is better >to start off with? I think it's worth pointing out that, especially >if you're looking at 2.7 -- but even with earlier 2.x versions -- >there isn't *that* much difference. My wmi library runs >unaltered on versions from 2.4 to 3.3. I did have to make some >tiny compromises, but the point I'm making is that Python 3 is >*not* worlds away from Python 2. Whichever version you plump for >now, you'll be well-placed to use the other one if you ever need >to. > >General guidance would be: go with Python 3 if you're starting >afresh, unless you have some overriding need for a library or >tool which hasn't been ported (and which you can't easily port >yourself... it might be easier than you think). Another of my >libraries runs on both versions by virtue of running the 2to3.py >library across it on install. (The pywin32 extensions use the >same approach). > >TJG >_______________________________________________ >python-win32 mailing list >python-win32 at python.org >http://mail.python.org/mailman/listinfo/python-win32 From usharma01 at gmail.com Fri May 20 01:03:10 2011 From: usharma01 at gmail.com (umesh) Date: Fri, 20 May 2011 04:33:10 +0530 Subject: [python-win32] Outlook integration Message-ID: <000601cc1678$f1b1cdf0$d51569d0$@com> Actually I am working on Outlook Automation using python and I want to fire a function as a new mail arrived ,for this I am using ItemAdd method so can you please tell me how should write event handler . Umesh Kumar Sharma second year Indian Institute of Technology -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacobk at mailzone.co.za Fri May 20 10:37:01 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Fri, 20 May 2011 10:37:01 +0200 Subject: [python-win32] Ok, version 2.7 is the actual one I should be using/focusing on Message-ID: Ok, only major change have found/made thus far is now that have changed all the input() prompts for command line over to raw_input() for now. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From anthony.seward at ieee.org Fri May 20 17:27:33 2011 From: anthony.seward at ieee.org (Tony Seward) Date: Fri, 20 May 2011 09:27:33 -0600 Subject: [python-win32] Ok, version 2.7 is the actual one I should be using/focusing on In-Reply-To: References: Message-ID: <1305905253.2734.2.camel@florete.mza.com> Here are a couple of links that I keep handy to make sure that when I do transition to Python 3 the change will be less painful http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/ http://wiki.python.org/moin/PortingPythonToPy3k I got these from http://lwn.net/Articles/426906/ I also have been reading http://diveintopython3.org/ Tony On Fri, 2011-05-20 at 04:37 -0400, Jacob Kruger wrote: > Ok, only major change have found/made thus far is now that have changed all the input() prompts for command line over to raw_input() for now. > > Stay well > > Jacob Kruger > Blind Biker > Skype: BlindZA > '...fate had broken his body, but not his spirit...' > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From junkoi2004 at gmail.com Fri May 20 18:58:12 2011 From: junkoi2004 at gmail.com (Jun Koi) Date: Sat, 21 May 2011 00:58:12 +0800 Subject: [python-win32] Create _reg_clsid? Message-ID: hi, i am trying to create my first context menu shell extension. i base my code on the sample context_menu.py. i have a question: how can i create my "_reg_clsid" for my extension? thanks a lot, Jun From skippy.hammond at gmail.com Mon May 23 06:52:19 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Mon, 23 May 2011 14:52:19 +1000 Subject: [python-win32] Create _reg_clsid? In-Reply-To: References: Message-ID: <4DD9E803.7070400@gmail.com> On 21/05/2011 2:58 AM, Jun Koi wrote: > hi, > > i am trying to create my first context menu shell extension. i base my > code on the sample context_menu.py. i have a question: how can i > create my "_reg_clsid" for my extension? I think you just want: >>> import pythoncom >>> pythoncom.CreateGuid() IID('{0B1CC054-749C-4C35-8514-EA15CA86E87D}') >>> Mark From junkoi2004 at gmail.com Mon May 23 07:32:55 2011 From: junkoi2004 at gmail.com (Jun Koi) Date: Mon, 23 May 2011 13:32:55 +0800 Subject: [python-win32] Create _reg_clsid? In-Reply-To: <4DD9E803.7070400@gmail.com> References: <4DD9E803.7070400@gmail.com> Message-ID: On Mon, May 23, 2011 at 12:52 PM, Mark Hammond wrote: > On 21/05/2011 2:58 AM, Jun Koi wrote: >> >> hi, >> >> i am trying to create my first context menu shell extension. i base my >> code on the sample context_menu.py. i have a question: how can i >> create my "_reg_clsid" for my extension? > > I think you just want: > >>>> import pythoncom >>>> pythoncom.CreateGuid() > IID('{0B1CC054-749C-4C35-8514-EA15CA86E87D}') i found another solution, which is OS-independent: import uuid print uuid.uuid1() thanks, J From jacobk at mailzone.co.za Mon May 23 10:09:45 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Mon, 23 May 2011 10:09:45 +0200 Subject: [python-win32] Bit of a strange one using py2exe Message-ID: Not 100% sure if this is for real, but almost seemed like when I tried out making use of py2exe to build an executable from a python script of mine, it didn't accept the use of a string value of exit in single quotes after it had built the executable, as in, something like the following, that would work fine in the normal interpreter rendition, now told me something along the lines of 'exit' is not defined: if act == 'exit': If I switched that over to using double quotation marks, it then seemed happy enough: if act == "exit": I'm guessing that the single quoted version is being handled slightly differently, and that there's something to do with the keyword, exit, or something since I am generally making use of single quotes/apostrophe's for various other string values, without those instances seeming to cause issues? Also, going to look through any sort of documentation can find, but, off-hand, does py2exe need you to in fact include all code etc. in one file? Just asking since am currently importing some functions from an external file, but had to in fact copy that code into the main file when trying this out as such, or else at runtime it tells me it can't find the other module to import a function from. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From mail at timgolden.me.uk Mon May 23 10:17:17 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 23 May 2011 09:17:17 +0100 Subject: [python-win32] Bit of a strange one using py2exe In-Reply-To: References: Message-ID: <4DDA180D.8010900@timgolden.me.uk> On 23/05/2011 09:09, Jacob Kruger wrote: > Not 100% sure if this is for real, but almost seemed like when I > tried out making use of py2exe to build an executable from a python > script of mine, it didn't accept the use of a string value of exit in > single quotes after it had built the executable, as in, something > like the following, that would work fine in the normal interpreter > rendition, now told me something along the lines of 'exit' is not > defined: Usual recommendation: provide the exact traceback (cut-and-pasted if at all possible) rather than "something along the lines of...". My guess is that you used backtick quotes (`) rather than single quotes. Backticks are a little-used alternative to the repr () function -- deprecated in Python 3 ISTR. That would leave the interpreter calling the __repr__ method of the exit object. The interactive interpreter has an exit object: ActivePython 2.7.1.4 (ActiveState Software Inc.) based on Python 2.7.1 (r271:86832, Feb 7 2011, 11:30:38) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> exit Use exit() or Ctrl-Z plus Return to exit >>> ... which probably comes from site.py (I can't be bothered to check right now) which isn't imported if Python isn't running interactively. Such as, within a py2exe bundle. > Also, going to look through any sort of documentation can find, but, > off-hand, does py2exe need you to in fact include all code etc. in > one file? Nope. I have multifile py2exe bundles, eg: from distutils.core import setup import py2exe setup ( console=[ dict (script="web_portraits_lrwp.py"), dict (script="web_contacts_lrwp.py"), dict (script="web_uaccess_lrwp.py"), ], data_files=[ (".", ["header.html"]), ], options={ "py2exe" : { "includes" : ["decimal"], "packages" : ["email"], } } ) Each of those scripts pulls in quite a few other modules, all of which py2exe picks up and bundles into its library.zip. TJG From kycbusiness at kycbusiness.com Mon May 23 11:59:45 2011 From: kycbusiness at kycbusiness.com (kycbusiness at kycbusiness.com) Date: Mon, 23 May 2011 05:59:45 -0400 (EDT) Subject: [python-win32] OLE COM in Python In-Reply-To: <21952419.27903.1306144681831.JavaMail.root@mail9b.brinkster.com> Message-ID: <18397844.27905.1306144785603.JavaMail.root@mail9b.brinkster.com> Dear sir, I am looking for a sample python script to declare VARIANTs similar to one shown below which is for Perl. Your help will be very much appreciated. Sincerely, Kin Cheung My Perl program is: #!"C:\xampp\perl\bin\perl.exe" print "Content-type: text/html \n\n"; #HTTP HEADER # http://localhost/cgi-bin/xampp_perl/Matlab_from_Perl_D.pl $value4=4.0; use Win32::OLE; use Win32::OLE::Variant; # Simple perl script to execute commands in MATLAB. # The name Win32::OLE is misleading; this actually uses COM # Use existing instance if MATLAB is already running. eval {$ml = Win32::OLE->GetActiveObject('Matlab.Application')}; die "MATLAB not installed" if $@; unless (defined $ml) { $ml = Win32::OLE->new('Matlab.Application') or die "Oops, cannot start MATLAB"; } #Create two SAFE_ARRAYs $mRealA = Variant(VT_ARRAY|VT_R8|VT_BYREF,2,2); $mImagA = Variant(VT_ARRAY|VT_R8|VT_BYREF,2,2); #Set the values $mRealA->Put(0,0,1); $mRealA->Put(0,1,2); $mRealA->Put(1,0,3); $mRealA->Put(1,1,$value4); $ml->PutFullMatrix('A','base',$mRealA, $mImagA); # Execute the function in MATLAB and retrieve the results in a Variant array. $ml->Execute('[V,D]=eig(A)'); $mReal = Variant(VT_ARRAY|VT_R8|VT_BYREF,2,2); $mImag = Variant(VT_ARRAY|VT_R8|VT_BYREF,2,2); print "\n>> GetFullMatrix('V', 'base', ",'$mReal, $mImag',")\n"."
"; $ml->GetFullMatrix('V', 'base', $mReal, $mImag); for ($i = 0; $i < 2; $i++) { printf "%10.4f %10.4f\n"."
", $mReal->Get($i,0), $mReal->Get($i,1); } $mReal1 = Variant(VT_ARRAY|VT_R8|VT_BYREF,2,2); $mImag1 = Variant(VT_ARRAY|VT_R8|VT_BYREF,2,2); print "\n>> GetFullMatrix('D', 'base', ",'$mReal1, $mImag1',")\n"."
"; $ml->GetFullMatrix('D', 'base', $mReal1, $mImag1); for ($i = 0; $i < 2; $i++) { printf "%10.4f %10.4f\n"."
", $mReal1->Get($i,0), $mReal1->Get($i,1); } undef $ml; # close MATLAB if we opened it From greg.ewing at canterbury.ac.nz Mon May 23 23:40:13 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 24 May 2011 09:40:13 +1200 Subject: [python-win32] Bit of a strange one using py2exe In-Reply-To: <4DDA180D.8010900@timgolden.me.uk> References: <4DDA180D.8010900@timgolden.me.uk> Message-ID: <4DDAD43D.1080009@canterbury.ac.nz> Tim Golden wrote: > Backticks are a little-used alternative to > the repr () function -- deprecated in Python 3 ISTR. Actually it's been *removed* in Python 3: Python 3.1.2 (r312:79147, Mar 2 2011, 17:43:12) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> `exit` File "", line 1 `exit` ^ SyntaxError: invalid syntax Good riddance, IMO -- there was never a good reason for having it in the first place. -- Greg From skippy.hammond at gmail.com Tue May 24 02:47:14 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 24 May 2011 10:47:14 +1000 Subject: [python-win32] OLE COM in Python In-Reply-To: <18397844.27905.1306144785603.JavaMail.root@mail9b.brinkster.com> References: <18397844.27905.1306144785603.JavaMail.root@mail9b.brinkster.com> Message-ID: <4DDB0012.2020809@gmail.com> On 23/05/2011 7:59 PM, kycbusiness at kycbusiness.com wrote: > Dear sir, > > I am looking for a sample python script to declare VARIANTs > similar to one shown below which is for Perl. Your help will be very > much appreciated. win32com doesn't have a way to explicitly declare variants - you just pass normal Python objects (eg, simple objects like ints or floats, or lists of them) and they are converted to variants internally. HTH, Mark From jacobk at mailzone.co.za Tue May 24 10:44:52 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Tue, 24 May 2011 10:44:52 +0200 Subject: [python-win32] Next step trying to include extra/external file in py2exe output Message-ID: Ok, when I now type in the following command: python setup.py py2exe with the following code in setup.py: #start code from glob import glob from distutils.core import setup import py2exe data_files = [("Microsoft.VC90.CRT", glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*'))] setup( console=[ dict (script="mapData.py") ], data_files=[data_files], options={ "py2exe" : { "includes" : ["c:\\temp\\pythonScripts\\mapDataFn.py"] } } ) #end code It seems to be generating the following exception/error, based on the line where I assume I'm trying to tell it to include the contents of the file, mapDataFn.py? #error text from console window raise ImportError, "No module named " + qname ImportError: No module named c:\temp\pythonScripts\mapDataFn Should I rather copy that file to somewhere else, and then just tell it to do something like: "includes" : ["mapDataFn"] Or should I maybe just run an import higher up inside setup.py itself? Sorry if I'm misunderstanding anything/everything... Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From timr at probo.com Tue May 24 19:23:23 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 24 May 2011 10:23:23 -0700 Subject: [python-win32] Next step trying to include extra/external file in py2exe output In-Reply-To: References: Message-ID: <4DDBE98B.3090000@probo.com> Jacob Kruger wrote: > Ok, when I now type in the following command: > python setup.py py2exe > ... > It seems to be generating the following exception/error, based on the line where I assume I'm trying to tell it to include the contents of the file, mapDataFn.py? > > #error text from console window > raise ImportError, "No module named " + qname > ImportError: No module named c:\temp\pythonScripts\mapDataFn > > Should I rather copy that file to somewhere else, and then just tell it to do something like: > "includes" : ["mapDataFn"] Yes. When you run py2exe, all of the modules you need should be laid out on disk exactly as they would if you were running the script. The "includes" list, as you see, runs an "import" statement on the modules you name. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mark.mordeca at prosensus.ca Tue May 24 21:08:21 2011 From: mark.mordeca at prosensus.ca (Mark Mordeca) Date: Tue, 24 May 2011 15:08:21 -0400 Subject: [python-win32] Error Quitting Excel Instance when One is Already Open Message-ID: <9beadc80acd23faf66ae4273fe6887ec@mail.gmail.com> Greetings, I am having a problem with using win32com to open an instance of Excel when there is already one open. I would appreciate any help. My example goes as follows: The user has an Excel file (and therefore an EXCEL.exe process) open already. I do: xl=win32com.client.DispatchEx("Excel.Application") #create a new instance of EXCEL.exe that will not interfere with the already open process. It remains hidden. book=xl.Workbooks.Open(filename) #open the excel file There are now 2 EXCEL.exe?s in the Task Manager. After this, but before I am done with the Excel file I opened with DispatchEx, the user then closes their open Excel file. There is now only one EXCEL.exe in the task manager, supposedly the one that I opened with DispatchEx. I then call: try: book.Close() and receive the error: Exception pywintypes.com_error: com_error(-2147418111, 'Call was rejected by callee.', None, None) I then go into an except statement and do: nbooks=xl.Workbooks.Count <--FAILS HERE if not xl.Visible and nbooks==0: # if excel is not visible and there are no books open, close excel. # Do this because another program may have excel open in the background. print "Asking Excel to Quit" xl.Quit() xl=None At ?FAILS HERE? I get the same error again: ?Exception pywintypes.com_error: com_error(-2147418111, 'Call was rejected by callee.', None, None)? and the EXCEL.exe is left hanging in the process manager, which I have to now manually kill. Can anyone help me with this error and how to keep connected to the Excel instance I opened with DispatchEx no matter what the user does with their own open Excel which includes the user closing it? Thank you for your assistance. Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: From tobias.oberstein at tavendo.de Tue May 24 19:56:21 2011 From: tobias.oberstein at tavendo.de (Tobias Oberstein) Date: Tue, 24 May 2011 10:56:21 -0700 Subject: [python-win32] RTD Server problem with Excel 2007 Message-ID: Hi, I'm testing the excelRTDServer.py example RTD Server (TimeServer): Win7-SP1 64-Bit Excel 2007 32-Bit Python 2.6.6 32-Bit pywin32-216 and get a generic COM exception when the RTD server tries to notify Excel of data changes (from the trace collector): Traceback (most recent call last): File "C:\Python26\Lib\threading.py", line 532, in __bootstrap_inner self.run() File "C:\Python26\Lib\threading.py", line 736, in run self.function(*self.args, **self.kwargs) File "C:\Data\svnwork\tavendo\mymepad\research\semweb\python\excelRTDServer.py", line 378, in Update self.SignalExcel() File "C:\Data\svnwork\tavendo\mymepad\research\semweb\python\excelRTDServer.py", line 153, in SignalExcel self.__callback.UpdateNotify() File "C:\Python26\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x6.py", line 17088, in UpdateNotify return self._oleobj_.InvokeTypes(10, LCID, 1, (24, 0), (),) com_error: (-2147352567, 'Ausnahmefehler aufgetreten.', (0, None, None, None, 0, 0), None) The COM Error is: "generic COM exception 0x80020009" The callpath that leads to the exception is: excelRTDServer.py ============== L281 ff: class TimeServer(ExcelRTDServer): .. def __init__(self): .. self.ticker = threading.Timer(self.INTERVAL, self.Update) .. L330 ff: def Update(self): .. self.SignalExcel() .. L129 ff: def SignalExcel(self): .. self.__callback.UpdateNotify() .. site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x6.py ================================================================= Line 17080 ff: class IRTDUpdateEvent(DispatchBaseClass): .. def UpdateNotify(self): return self._oleobj_.InvokeTypes(10, LCID, 1, (24, 0), (),) .. ***** After some Googling, the best hint I came up with is: "Apparently in Excel 12 (Excel 2007) the RTD callback object that implements dual IRTDUpdateEvent interface throws exception (generic COM exception 0x80020009) when is called via IDispatch. If you use v-table binding the call to UpdateNotify succeeds. I don?t really know whether it is a bug in Excel 12 or a feature." http://www.nevaobject.com/phpbb3/viewtopic.php?t=516 To check if that is the problem, I'd like to do the callback not via IDispatch, but via VTable. Is that possible in pywin32? Thanks alot, Tobias -------------- next part -------------- An HTML attachment was scrubbed... URL: From usharma01 at gmail.com Tue May 24 21:32:26 2011 From: usharma01 at gmail.com (Umesh Sharma) Date: Wed, 25 May 2011 01:02:26 +0530 Subject: [python-win32] outlook new mail handling Message-ID: hi, i am building application for outlook in my application i need to capture the NewMailEx event of Outlook which fires when a new mail arrived. I have tried using win32event but i failed can please anyone tell me how to capture new mail of outlook using event handler thanks Umesh Kumar Sharma -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue May 24 21:35:54 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 24 May 2011 12:35:54 -0700 Subject: [python-win32] RTD Server problem with Excel 2007 In-Reply-To: References: Message-ID: <4DDC089A.1000706@probo.com> Tobias Oberstein wrote: > ... > and get a generic COM exception when the RTD server tries to notify > Excel of data changes (from the trace collector): > ... > The COM Error is: "generic COM exception 0x80020009" > > The callpath that leads to the exception is: > > > excelRTDServer.py > ============== > > L281 ff: > > class TimeServer(ExcelRTDServer): > .. > def __init__(self): > .. > self.ticker = threading.Timer(self.INTERVAL, self.Update) Does that actually create a new thread? If so, every new thread has to call CoInitialize before it does any COM actions. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue May 24 22:29:38 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 24 May 2011 13:29:38 -0700 Subject: [python-win32] Next step trying to include extra/external file in py2exe output In-Reply-To: <7FEE1C165A754B9BB329FE51208C63EC@jakes> References: <4DDBE98B.3090000@probo.com> <7FEE1C165A754B9BB329FE51208C63EC@jakes> Message-ID: <4DDC1532.8030709@probo.com> Jacob Kruger wrote: > Ok, then why is it not picking up that the 2 files are in fact in same > folder at the time when I'm running the setup.py? > > All I have in the main file is the following in case that's an issue?: > > from mapDataFn import fnTakeItem If you have main.py, setup.py, and mapDataFn.py, all in the same directory, that should work just fine, without any "includes" overrides at all. What error do you see? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue May 24 22:54:24 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 24 May 2011 13:54:24 -0700 Subject: [python-win32] Next step trying to include extra/external file in py2exe output In-Reply-To: <7CF9909ECC4E4EFC9C7BAFE25A32E63A@jakes> References: <4DDBE98B.3090000@probo.com><7FEE1C165A754B9BB329FE51208C63EC@jakes> <4DDC1532.8030709@probo.com> <7CF9909ECC4E4EFC9C7BAFE25A32E63A@jakes> Message-ID: <4DDC1B00.1020802@probo.com> Jacob Kruger wrote: > #error text from console window > raise ImportError, "No module named " + qname > ImportError: No module named c:\temp\pythonScripts\mapDataFn > > Should I rather copy that file to somewhere else, and then just tell it to > do something like: > "includes" : ["mapDataFn"] > > Also tried changing it to: > "includes" : ["mapDataFn.py"] > > and, same issue/error. Here's a trivial example. When I run "python setup.py py2exe", it creates dist\main.exe and dist\library.zip, and the zip contains mapDataFn.pyc, among all the standard modules. C:\Dev\xxx>type main.py from mapDataFn import fnTakeItem print fnTakeItem() C:\Dev\xxx>type mapDataFn.py def fnTakeItem(): return 123 C:\Dev\xxx>type setup.py from distutils.core import setup import py2exe options = { "bundle_files": 1, "ascii": 1, # to make a smaller executable, don't include the encodings "compressed": 1, # compress the library archive } setup( # The first three parameters are not required, if at least a # 'version' is given, then a versioninfo resource is built from # them and added to the executables. version = "1.0.0", description = "Test", name = "MapTest", options = {'py2exe': options}, # targets to build console = ["main.py"], ) C:\Dev\xxx>python setup.py py2exe running py2exe creating C:\Dev\xxx\build creating C:\Dev\xxx\build\bdist.win32 creating C:\Dev\xxx\build\bdist.win32\winexe creating C:\Dev\xxx\build\bdist.win32\winexe\collect-2.6 creating C:\Dev\xxx\build\bdist.win32\winexe\bundle-2.6 creating C:\Dev\xxx\build\bdist.win32\winexe\temp creating C:\Dev\xxx\dist *** searching for required modules *** *** parsing results *** *** finding dlls needed *** *** create binaries *** *** byte compile python files *** byte-compiling C:\Dev\xxx\mapDataFn.py to mapDataFn.pyc byte-compiling c:\apps\python26\lib\StringIO.py to StringIO.pyc ... lots of output deleted ... C:\Dev\xxx>cd dist C:\Dev\xxx\dist>main.exe 123 C:\Dev\xxx\dist> -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From skippy.hammond at gmail.com Wed May 25 01:23:27 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 25 May 2011 09:23:27 +1000 Subject: [python-win32] Error Quitting Excel Instance when One is Already Open In-Reply-To: <9beadc80acd23faf66ae4273fe6887ec@mail.gmail.com> References: <9beadc80acd23faf66ae4273fe6887ec@mail.gmail.com> Message-ID: <4DDC3DEF.5050200@gmail.com> Sadly this is all under the control of Excel, so I've no good advice. The poor advice I can offer is (1) for your own piece of mind, see if you can get the same basic behaviour with wscript and a .vbs script, (2) to try and see if you can find a similar problem in any language/environment (eg, wscript) and how they worked around it and finally (3) see if you can worm around it by catching that exception then discarding the object you have and re-connecting to that instance using normal Dispatch(). HTH, Mark On 25/05/2011 5:08 AM, Mark Mordeca wrote: > Greetings, > > I am having a problem with using win32com to open an instance of Excel > when there is already one open. I would appreciate any help. > > My example goes as follows: > > The user has an Excel file (and therefore an EXCEL.exe process) open > already. > > I do: > > xl=win32com.client.DispatchEx("Excel.Application") #create a new > instance of EXCEL.exe that will not interfere with the already open > process. It remains hidden. > > book=xl.Workbooks.Open(filename) #open the excel file > > There are now 2 EXCEL.exe?s in the Task Manager. > > After this, but before I am done with the Excel file I opened with > DispatchEx, the user then closes their open Excel file. There is now > only one EXCEL.exe in the task manager, supposedly the one that I opened > with DispatchEx. > > I then call: > > try: > > book.Close() > > and receive the error: > > Exception pywintypes.com_error: com_error(-2147418111, 'Call was > rejected by callee.', None, None) > > I then go into an except statement and do: > > nbooks=xl.Workbooks.Count <--FAILS HERE > > if not xl.Visible and nbooks==0: > > # if excel is not visible and there are no books open, > close excel. > > # Do this because another program may have excel open > in the background. > > print "Asking Excel to Quit" > > xl.Quit() > > xl=None > > At ?FAILS HERE? I get the same error again: ?Exception > pywintypes.com_error: com_error(-2147418111, 'Call was rejected by > callee.', None, None)? and the EXCEL.exe is left hanging in the process > manager, which I have to now manually kill. > > Can anyone help me with this error and how to keep connected to the > Excel instance I opened with DispatchEx no matter what the user does > with their own open Excel which includes the user closing it? > > Thank you for your assistance. > > Mark > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From skippy.hammond at gmail.com Wed May 25 01:24:45 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Wed, 25 May 2011 09:24:45 +1000 Subject: [python-win32] outlook new mail handling In-Reply-To: References: Message-ID: <4DDC3E3D.2060507@gmail.com> You should check out the "spambayes" project at sourceforge, and particularly the spambayes\Outlook2000 directory - addin.py and manager.py in particular. Mark On 25/05/2011 5:32 AM, Umesh Sharma wrote: > hi, > i am building application for outlook in my application i need to > capture the NewMailEx event of Outlook which fires when a new mail > arrived. I have tried using win32event but i failed can please anyone > tell me how to capture new mail of outlook using event handler > > thanks > > Umesh Kumar Sharma > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From mhammond at skippinet.com.au Wed May 25 01:44:48 2011 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed, 25 May 2011 09:44:48 +1000 Subject: [python-win32] OLE COM in Python In-Reply-To: <2359311.35891.1306280378999.JavaMail.root@mail9b.brinkster.com> References: <2359311.35891.1306280378999.JavaMail.root@mail9b.brinkster.com> Message-ID: <4DDC42F0.70705@skippinet.com.au> [Re-added pywin32 - please keep replies there] On 25/05/2011 9:39 AM, kycbusiness at kycbusiness.com wrote: > Dear Dr. Hammond, > > Thank you again. > > What I have tried to do is to transmit data from Python > to Matlab, using COM OLE. Here is my code: > >>>> ml=win32com.client.Dispatch("Matlab.Application") >>>> N=3 >>>> ml.Execute("M=N") > u"??? Undefined function or variable 'N'.\n\n" I don't know matlab at all, but I expect you want that second line to say: ml.Execute("N=3") All you have done in your version is set a Python variable named 'N' to 3, not a matlab variable - so matlab is returning a string indicating the error. Python and matlab don't magically share a namespace via COM. HTH, Mark > >>>> ml.Execute("C=magic(3)") > u'\nC =\n\n 8 1 6\n 3 5 7\n 4 9 2\n\n' > > I can only input the integer 3 explicitly inside "Execute()", but not > from Python. > > You are the world's authority in COM, your help will be very much appreciated. > > Sincerely, > > Kin Cheung > > > > > ----- Original Message ----- > From: kycbusiness at kycbusiness.com > To: mhammond at skippinet.com.au > Cc: kycbusiness at kycbusiness.com > Sent: Monday, May 23, 2011 9:34:02 PM > Subject: Re: [python-win32] OLE COM in Python > > Dear Dr. Hammond, > > Thank you very much for your instruction. > > Sincerely, > > Kin Cheung > > > > ----- Original Message ----- > From: "Mark Hammond" > To: kycbusiness at kycbusiness.com > Cc: python-win32 at python.org > Sent: Monday, May 23, 2011 8:47:14 PM > Subject: Re: [python-win32] OLE COM in Python > > On 23/05/2011 7:59 PM, kycbusiness at kycbusiness.com wrote: >> Dear sir, >> >> I am looking for a sample python script to declare VARIANTs >> similar to one shown below which is for Perl. Your help will be very >> much appreciated. > > win32com doesn't have a way to explicitly declare variants - you just > pass normal Python objects (eg, simple objects like ints or floats, or > lists of them) and they are converted to variants internally. > > HTH, > > Mark From tobias.oberstein at tavendo.de Wed May 25 12:11:12 2011 From: tobias.oberstein at tavendo.de (Tobias Oberstein) Date: Wed, 25 May 2011 03:11:12 -0700 Subject: [python-win32] RTD Server problem with Excel 2007 / How to do vtable-call, without IDispatch? Message-ID: <634914A010D0B943A035D226786325D422B8AFB312@EXVMBX020-12.exch020.serverdata.net> > Tim Roberts wrote: > > ... > > and get a generic COM exception when the RTD server tries to notify > > Excel of data changes (from the trace collector): > > ... > > The COM Error is: "generic COM exception 0x80020009" > > > > The callpath that leads to the exception is: > > > > > > excelRTDServer.py > > ============== > > > > L281 ff: > > > > class TimeServer(ExcelRTDServer): > > .. > > def __init__(self): > > .. > > self.ticker = threading.Timer(self.INTERVAL, self.Update) > > Does that actually create a new thread? If so, every new thread has to > call CoInitialize before it does any COM actions. Yes, this creates a new thread. I've replaced that with class MyTimer(threading.Thread): def __init__(self, callback): threading.Thread.__init__(self) self.callback = callback def run(self): pythoncom.CoInitialize() win32trace.write("started and CoInitialize'ed MyTimer-thread " + str(threading.current_thread().ident)) while True: time.sleep(2) win32trace.write("MyTimer - callback") self.callback() Unfortunately, the error remains;( === How can I call on the interface not via IDispatch, but using vtable-based direct call? This gets called from Excel .. "CallbackObject" is provided by Excel and implements IRTDUpdateEvent def ServerStart(self, CallbackObject): .. # Need to "cast" the raw PyIDispatch object to the IRTDUpdateEvent interface IRTDUpdateEventKlass = win32com.client.CLSIDToClass.GetClass('{A43788C1-D91B-11D3-8F39-00C04F3651B8}') self.__callback = IRTDUpdateEventKlass(CallbackObject) Here are the object types resulting from this code: ServerStart - CallbackObject = ServerStart - IRTDUpdateEventKlass = win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x6.IRTDUpdateEvent ServerStart - self.__callback = == What I want to try is cast the CallbackObject to IRTDUpdateEvent using some QueryInterface construct, and then later call methods on that interface ... but NOT via IDispatch. The self.__callback = however is a class IRTDUpdateEvent(DispatchBaseClass): CLSID = IID('{A43788C1-D91B-11D3-8F39-00C04F3651B8}') coclass_clsid = None def UpdateNotify(self): return self._oleobj_.InvokeTypes(10, LCID, 1, (24, 0), (),) and calls UpdateNotify via IDispatch. So: how can I cast/call without IDispatch? Many thanks, Tobias From jacobk at mailzone.co.za Wed May 25 12:40:07 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Wed, 25 May 2011 12:40:07 +0200 Subject: [python-win32] pyTTS in versions later than 2.5 Message-ID: I got hold of pyTTS-3.0.win32-py2.5.exe, but it seems to be like last available version off the sourceforge website - might be able to double check that one when at home, since this machine is a bit slow/unstable when it comes to certain types of web browsing, but anyway - was just wondering if it would then be feasible to do something like install python 2.5, install this plugin/module, and then somehow try to either extract it from there, or wrap it up somehow..? On the other hand, if trying to use something like pythoncom.create() to make use of a com component that doesn't seem available using it's namespace string, is it then possible to instantiate something like that using an actual file path? Asking since do have another DLL here that gives a bit more control over text-to-speech options/usage. TIA Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From skippy.hammond at gmail.com Thu May 26 00:50:24 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 26 May 2011 08:50:24 +1000 Subject: [python-win32] RTD Server problem with Excel 2007 / How to do vtable-call, without IDispatch? In-Reply-To: <634914A010D0B943A035D226786325D422B8AFB312@EXVMBX020-12.exch020.serverdata.net> References: <634914A010D0B943A035D226786325D422B8AFB312@EXVMBX020-12.exch020.serverdata.net> Message-ID: <4DDD87B0.2040409@gmail.com> I'm afraid I can't really help, but: On 25/05/2011 8:11 PM, Tobias Oberstein wrote: > How can I call on the interface not via IDispatch, but using vtable-based direct call? You can't I'm afraid. However, your "casting" code might be suspect: > # Need to "cast" the raw PyIDispatch object to the IRTDUpdateEvent interface > IRTDUpdateEventKlass = win32com.client.CLSIDToClass.GetClass('{A43788C1-D91B-11D3-8F39-00C04F3651B8}') > self.__callback = IRTDUpdateEventKlass(CallbackObject) Look into using CastTo, or at least check that when the DispatchBaseClass is called that extra QueryInterface is done - it looks like it might not be. > class IRTDUpdateEvent(DispatchBaseClass): > CLSID = IID('{A43788C1-D91B-11D3-8F39-00C04F3651B8}') > coclass_clsid = None > > def UpdateNotify(self): > return self._oleobj_.InvokeTypes(10, LCID, 1, (24, 0), (),) > > and calls UpdateNotify via IDispatch. Assuming the above is OK, the fact you got this far means that excel is exposing an IDispatch version of this interface - it is just rejecting it. So maybe using IDispatch isn't the underlying problem... HTH, Mark From skippy.hammond at gmail.com Thu May 26 00:52:44 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Thu, 26 May 2011 08:52:44 +1000 Subject: [python-win32] pyTTS in versions later than 2.5 In-Reply-To: References: Message-ID: <4DDD883C.7000903@gmail.com> On 25/05/2011 8:40 PM, Jacob Kruger wrote: > I got hold of pyTTS-3.0.win32-py2.5.exe, but it seems to be like last > available version off the sourceforge website - might be able to > double check that one when at home, since this machine is a bit > slow/unstable when it comes to certain types of web browsing, but > anyway - was just wondering if it would then be feasible to do > something like install python 2.5, install this plugin/module, and > then somehow try to either extract it from there, or wrap it up > somehow..? Nope - any .pyd files in that package will not be able to be made to work. > On the other hand, if trying to use something like pythoncom.create() > to make use of a com component that doesn't seem available using it's > namespace string, is it then possible to instantiate something like > that using an actual file path? Not really - although most COM objects are self-registering, so if you have the path to the DLL, just use regsvr32.exe on it (or if it is a .exe, there is probably a command-line you can use to self register. > Asking since do have another DLL here that gives a bit more control > over text-to-speech options/usage. No idea I'm afraid, although I thought there was text-to-speech built into Windows and exposed via COM... Cheers, Mark From Andrew.MacIntyre at acma.gov.au Thu May 26 02:19:47 2011 From: Andrew.MacIntyre at acma.gov.au (Andrew MacIntyre) Date: Thu, 26 May 2011 00:19:47 +0000 Subject: [python-win32] pyTTS in versions later than 2.5 [SEC=PERSONAL] In-Reply-To: References: Message-ID: > I got hold of pyTTS-3.0.win32-py2.5.exe, but it seems to be like last available > version off the sourceforge website - might be able to double check that one > when at home, since this machine is a bit slow/unstable when it comes to > certain types of web browsing, but anyway - was just wondering if it would > then be feasible to do something like install python 2.5, install this > plugin/module, and then somehow try to either extract it from there, or > wrap it up somehow..? The pyTTS source seems to be available via subversion. -------------------------> "These thoughts are mine alone!" <--------- Andrew MacIntyre?????????? Operations Branch tel:?? +61 2 6219 5356???? Communications Infrastructure Division fax:?? +61 2 6253 3277???? Australian Communications & Media Authority email: andrew.macintyre at acma.gov.au??????????? http://www.acma.gov.au/ NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. From bwmetz at gmail.com Thu May 26 04:58:24 2011 From: bwmetz at gmail.com (Bobby Metz) Date: Wed, 25 May 2011 19:58:24 -0700 Subject: [python-win32] OLE COM in Python In-Reply-To: References: Message-ID: The Perl is just passing an interpreted string. Couldn't you just do the same in Python? N="3" ml.Execute("M="+N) -or- ml.Execute("M=magic("+N+")") depending on whether magic() is needed. or alternately if you must have integer values in your python var. N=3 cmd="M=%d" % N ml.Execute(cmd) or whatever similar syntax method floats your boat. On May 24, 2011 4:50 PM, "Mark Hammond" wrote: -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacobk at mailzone.co.za Thu May 26 09:20:15 2011 From: jacobk at mailzone.co.za (Jacob Kruger) Date: Thu, 26 May 2011 09:20:15 +0200 Subject: [python-win32] ProgID/class string for MS TTS Engine not working Message-ID: The full class name for a standard TTS synth, when accessing it via .Net comes out as: System.Speech.Synthesis.SpeechSynthesizer And, that is referring to a file called System.Speech.dll, and there are unfortunately also different versions for the varying .net frameworks, but none of the 3 I found on my machine will allow me to execute the regsvr32 on them as such, and in python pythoncom.connect() tells me there's an issue with the class string. One other alternative I have gotten to work is to use the command line app from a guy called Jamal Masry's SayTools applet: http://www.empowermentzone.com/saysetup.exe And that one will alternatively make use of a screen reader, MSSAPI, etc., and I just used it with this: #code import os os.system("sayline 'hullo there...'") #end code That one uses the SayTools.dll that I would have liked to use more directly, but which windows7 doesn't seem to want to register a class name for, etc., but will now just have to look into what files etc. I'll need to copy/move around if I want to produce spoken text aside from normal output, etc. Stay well Jacob Kruger Blind Biker Skype: BlindZA '...fate had broken his body, but not his spirit...' From admin at dmarkey.com Thu May 26 10:36:09 2011 From: admin at dmarkey.com (David Markey) Date: Thu, 26 May 2011 09:36:09 +0100 Subject: [python-win32] win32event.WaitForMultipleObjects and sockets Message-ID: Hi All, Sorry for the n00b question... With win32event.WaitForMultipleObjects, I dont seem to be able to give it a plain socket object. How can I create a PyHANDLE from a socket? In [26]: int = WaitForMultipleObjects([so],False,10000) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) C:\Users\davidmar\ in () TypeError: Handles must be a list of integers Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From amauryfa at gmail.com Thu May 26 11:05:32 2011 From: amauryfa at gmail.com (Amaury Forgeot d'Arc) Date: Thu, 26 May 2011 11:05:32 +0200 Subject: [python-win32] win32event.WaitForMultipleObjects and sockets In-Reply-To: References: Message-ID: 2011/5/26 David Markey : > Hi All, > Sorry for the n00b question... > With win32event.WaitForMultipleObjects, I dont seem to be able to give it a > plain socket object. How can I create a PyHANDLE from a socket? It won't work like this, because a socket has several things you can wait for (available for read, available for write, accept, error, and probably others) You should use WSAEventSelect() to associate a socket with a handle. This is pseudo-code (I don't have Windows at the moment, sorry):: socket_event = WSACreateEvent() WSAEventSelect(mysocket, socket_event, FD_READ | FD_CLOSE) ... then socket_event may be used in WaitForMultipleObjects... WSACloseEvent(socket_event) -- Amaury Forgeot d'Arc From admin at dmarkey.com Thu May 26 11:56:57 2011 From: admin at dmarkey.com (David Markey) Date: Thu, 26 May 2011 10:56:57 +0100 Subject: [python-win32] win32event.WaitForMultipleObjects and sockets In-Reply-To: References: Message-ID: I cant seem to find WSACreateEvent anywhere, is it exposed? There is win32event.CreateEvent but it takes 4 arguments. I can find win32file.WSAEventSelect alright. On 26 May 2011 10:05, Amaury Forgeot d'Arc wrote: > 2011/5/26 David Markey : > > Hi All, > > Sorry for the n00b question... > > With win32event.WaitForMultipleObjects, I dont seem to be able to give it > a > > plain socket object. How can I create a PyHANDLE from a socket? > > It won't work like this, because a socket has several things you > can wait for (available for read, available for write, accept, error, > and probably others) > > You should use WSAEventSelect() to associate a socket with a handle. > > This is pseudo-code (I don't have Windows at the moment, sorry):: > > socket_event = WSACreateEvent() > WSAEventSelect(mysocket, socket_event, FD_READ | FD_CLOSE) > ... then socket_event may be used in WaitForMultipleObjects... > WSACloseEvent(socket_event) > > > -- > Amaury Forgeot d'Arc > -------------- next part -------------- An HTML attachment was scrubbed... URL: From amauryfa at gmail.com Thu May 26 12:03:42 2011 From: amauryfa at gmail.com (Amaury Forgeot d'Arc) Date: Thu, 26 May 2011 12:03:42 +0200 Subject: [python-win32] win32event.WaitForMultipleObjects and sockets In-Reply-To: References: Message-ID: 2011/5/26 David Markey : > I cant seem to find WSACreateEvent anywhere, is it exposed? > There is win32event.CreateEvent but it takes 4 arguments. > > I can find win32file.WSAEventSelect alright. According to msdn: """The WSACreateEvent function creates a manual-reset event object with an initial state of nonsignaled. The handle of the event object returned cannot be inherited by child processes. The event object is unnamed.""" So it should be equivalent to:: win32event.CreateEvent(None, True, False, None) then it can be closed with win32api.CloseHandle(). -- Amaury Forgeot d'Arc From tobias.oberstein at tavendo.de Thu May 26 15:56:45 2011 From: tobias.oberstein at tavendo.de (Tobias Oberstein) Date: Thu, 26 May 2011 06:56:45 -0700 Subject: [python-win32] RTD Server problem with Excel 2007 / How to do vtable-call, without IDispatch? In-Reply-To: <4DDD87B0.2040409@gmail.com> References: <634914A010D0B943A035D226786325D422B8AFB312@EXVMBX020-12.exch020.serverdata.net> <4DDD87B0.2040409@gmail.com> Message-ID: <634914A010D0B943A035D226786325D422B8B8A97D@EXVMBX020-12.exch020.serverdata.net> > Von: Mark Hammond [mailto:skippy.hammond at gmail.com] > Gesendet: Donnerstag, 26. Mai 2011 00:50 > An: Tobias Oberstein > Cc: python-win32 at python.org > Betreff: Re: [python-win32] RTD Server problem with Excel 2007 / How to do > vtable-call, without IDispatch? > > I'm afraid I can't really help, but: Thanks for answering anyway .. > > On 25/05/2011 8:11 PM, Tobias Oberstein wrote: > > > How can I call on the interface not via IDispatch, but using vtable-based > direct call? > > You can't I'm afraid. The reason I was asking is, that after some Googling, the best hint regarding the problem I came up with is: "Apparently in Excel 12 (Excel 2007) the RTD callback object that implements dual IRTDUpdateEvent interface throws exception (generic COM exception 0x80020009) when is called via IDispatch. If you use v-table binding the call to UpdateNotify succeeds. I don?t really know whether it is a bug in Excel 12 or a feature." http://www.nevaobject.com/phpbb3/viewtopic.php?t=516 Anyway, due to time constraints I moved on to C# and ExcelDNA to implement my stuff. Originally, I wanted to prototype in PyWin32 ... which is absolutely great nevertheless! cheers, Tobias From theller at ctypes.org Thu May 26 17:14:46 2011 From: theller at ctypes.org (Thomas Heller) Date: Thu, 26 May 2011 17:14:46 +0200 Subject: [python-win32] Threads, COM, gc Message-ID: I have to fix a tricky problem that we recently discovered in our software. We have a multithreading Python program that uses a lot of COM objects. COM objects have the requirement that they must only be used in the COM apartment where they have been created. Different threads often or even most of the time run in different apartments. This requirement is easy to fulfill (if the programmer is careful), but there is one exception: If the COM object is part of a reference cycle of some other Python objects, then it is not destroyed when it goes out of scope, instead it is destroyed when the Python cycle gc runs. The garbage collector can run in any thread; so the cleanup of the COM object may happen in some arbitrary thread. This is not allowed, and in some circumstances the program hangs or maybe it even crashes. So, it must be ensured that the cleanup of the COM objects happen in the same thread where they have been created. Does anyone have some ideas how this could be approached? Thanks, Thomas From timr at probo.com Thu May 26 19:17:45 2011 From: timr at probo.com (Tim Roberts) Date: Thu, 26 May 2011 10:17:45 -0700 Subject: [python-win32] win32event.WaitForMultipleObjects and sockets In-Reply-To: References: Message-ID: <4DDE8B39.302@probo.com> David Markey wrote: > Hi All, > > Sorry for the n00b question... > > With win32event.WaitForMultipleObjects, I dont seem to be able to give > it a plain socket object. How can I create a PyHANDLE from a socket? Sockets and file handles are not among the list of objects that WaitForMultipleObjects accepts. http://msdn.microsoft.com/en-us/library/ms687025.aspx Are you trying to do asynchronous socket I/O? You should probably be using the built-in Python mechanism for that, in the "asyncore" module. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rasukakishore at gmail.com Fri May 27 13:03:04 2011 From: rasukakishore at gmail.com (Rasuka Kishore) Date: Fri, 27 May 2011 16:33:04 +0530 Subject: [python-win32] automating outlook using python Message-ID: i am trying to automate outlook using python. my code seems to work fine with outlook 2007, however with outlook 2003 it's giving the following error. Traceback (most recent call last): File "",line 1, in File "C:\Python27\lib\site-packages\comtypes\client\_events.py", line 218 in ShowEvents return comtypes.client.GetEvents(source, sink=EventDumper(), interface=interface) File "C:\Python27\lib\site-packages\comtypes\client\_events.py", line 193,in GetEvents interface = FindOutgoingInterface(source) File "C:\Python27\lib\site-packages\comtypes\client\_events.py", line 73 in FindOutgoingInterface raise TypeError("cannot determine source interface") TypeError: cannot determine source interface This is the code i am using from comtypes.client import GetEvents class EventSink(object): def ApplicationEvents_11_NewMailEx(self, this, entryid): print "mail arrived" print entryid def ApplicationEvents_10_NewMailEx(self, this, entryid): print "mail arrived" print entryid from comtypes.client import CreateObject xl = CreateObject("Outlook.Application") from comtypes.client import PumpEvents sink = EventSink() connection = GetEvents(xl, sink) PumpEvents(3000) can anyone plz point out as to what could be possibly wrong. Thanks in advance -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sat May 28 10:55:32 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 28 May 2011 20:55:32 +1200 Subject: [python-win32] Convert RGBA to BGRA using standard library? Message-ID: <4DE0B884.10206@canterbury.ac.nz> Can anyone think of an efficient way to convert a string full of RGBA image data to BGRA, using only what's available in the standard library? I'm trying to add a function to PyGUI for creating an Image object from arbitrary data. The problem I'm having is that GDI+ on Windows expects BGRA, whereas most other platforms deal with RGBA. I don't want to require the user to supply the data in different formats on different platforms, so PyGUI needs to be able to convert where necessary. I know the conversion can be done easily using something like PIL or numpy, but I'm after a solution that doesn't depend on any third-party libraries. -- Greg From gremlin at armarize.com Mon May 30 19:58:52 2011 From: gremlin at armarize.com (Gremlin) Date: Mon, 30 May 2011 19:58:52 +0200 Subject: [python-win32] The "right" way to handle permission issues Message-ID: <6F4CA8D46AA243E79DF7932821362047@BELLO> Hello, I'm having some trouble with Windows 7 and probably Windows Vista as well. My application runs elevated and has to create files and folders within the "Program Files"-Folder. (I can't store the files at another place.) I'm using the os module (Python 2.7), rsync, 7zip and gzip to create those files. The trouble is the assignment of permissions to newly created files and folders. I've already isolated the issue to rsync (I haven't tested 7zip and gzip yet.), files and folders created with open() and os.mkdir are created with the right permissions. (At least I suppose that because I'm able to delete them without altering the security properties.) When I look into the security properties of files created by rsync, there's a group labelled with "None" and if I delete this group, I can delete the file. But unfortunately this doesn't work with folders. The group will be deleted, while Windows says the security properties couldn't be changed. (I see.) However, I'm able to delete a folder if I remove all groups and add myself again. So my question is: How should I handle this issue within my application? Of course, I know the function SetNamedSecurityInfo, but I don't know how to use it "right". What kind of permission should I set? Can I fix this issue with this function at all? How can I prevent further trouble for my users? You see, I'm totally clueless so far. So if you can, please help me solving this. :| Regards, Johannes -------------- next part -------------- An HTML attachment was scrubbed... URL: From mark.mordeca at prosensus.ca Mon May 30 22:26:35 2011 From: mark.mordeca at prosensus.ca (Mark Mordeca) Date: Mon, 30 May 2011 16:26:35 -0400 Subject: [python-win32] Excel "stopped working" after reading in sheet names Message-ID: <8de3eae44155fbd7a60ae1c0cbd43cc8@mail.gmail.com> Greetings, I would appreciate any help I could get with the following problem. 30% of the time after running the following code to get the sheet names out of an excel file, I will receive a windows error saying that ?Microsoft Office Excel has stopped working?. Code: xl=win32com.client.DispatchEx("Excel.Application") book=xl.Workbooks.Open(filename) sheetList=[] for sheet in book.Sheets: sheetList.append(sheet.Name) sheet=None # get rid of reference to sheet try: book.Close() book=None xl.Quit() except: print "getting sheet names exception!" book=None xl.Quit() xl=None return sheetList The sheetList variable is returned fine, the print in the except statement does not appear and the program can continue as normal, however the following Windows error appears: Microsoft Office Excel has stopped working Windows can check online for a solution to the problem ->Check online for a solution and close the program ->Close the program ->Debug the program Problem Details: *Problem signature:* Problem Event Name: APPCRASH Application Name: EXCEL.EXE Application Version: 12.0.6550.5004 Application Timestamp: 4d2cee93 Fault Module Name: ntdll.dll Fault Module Version: 6.1.7601.17514 Fault Module Timestamp: 4ce7ba58 Exception Code: c0000005 Exception Offset: 00038da9 OS Version: 6.1.7601.2.1.0.256.1 Locale ID: 1033 *Additional information about the problem:* LCID: 1033 Brand: Office12Crash skulcid: 1033 While the program can continue as normal, to users using the program, having this error popup and having to click ?close the program? is not acceptable. Can anyone help me with a reason as to why I get this error message (and only sometimes at that) even though no exception is thrown and I retrieved the sheet names perfectly fine? Is there a way to suppress this error from even appearing (though not ideal and it is a windows error not an Excel error so I don?t think this is possible)? I thank you for any assistance. Mark -------------- next part -------------- An HTML attachment was scrubbed... URL: From skippy.hammond at gmail.com Tue May 31 02:00:28 2011 From: skippy.hammond at gmail.com (Mark Hammond) Date: Tue, 31 May 2011 10:00:28 +1000 Subject: [python-win32] The "right" way to handle permission issues In-Reply-To: <6F4CA8D46AA243E79DF7932821362047@BELLO> References: <6F4CA8D46AA243E79DF7932821362047@BELLO> Message-ID: <4DE42F9C.2050506@gmail.com> On 31/05/2011 3:58 AM, Gremlin wrote: > Hello, > > I?m having some trouble with Windows 7 and probably Windows Vista as > well. My application runs elevated and has to create files and folders > within the ?Program Files?-Folder. (I can?t store the files at another > place.) I?m using the os module (Python 2.7), rsync, 7zip and gzip to > create those files. > > The trouble is the assignment of permissions to newly created files and > folders. I?ve already isolated the issue to rsync (I haven?t tested 7zip > and gzip yet.), files and folders created with open() and os.mkdir are > created with the right permissions. (At least I suppose that because I?m > able to delete them without altering the security properties.) > > When I look into the security properties of files created by rsync, > there?s a group labelled with ?None? and if I delete this group, I can > delete the file. But unfortunately this doesn?t work with folders. The > group will be deleted, while Windows says the security properties > couldn?t be changed. (I see?) However, I?m able to delete a folder if I > remove all groups and add myself again. > > So my question is: How should I handle this issue within my application? > > Of course, I know the function SetNamedSecurityInfo, but I don?t know > how to use it ?right?. What kind of permission should I set? Can I fix > this issue with this function at all? How can I prevent further trouble > for my users? > > You see, I?m totally clueless so far. So if you can, please help me > solving this. :| In general, you should look for a way to stop the app from screwing with the permissions in the first place. tar has a similar problem which can be overridden with something like --no-same-permissions. According to http://superuser.com/questions/69620/rsync-file-permissions-on-windows, rsync has a --chmod option that might work. HTH, Mark From mail at timgolden.me.uk Tue May 31 10:09:04 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 31 May 2011 09:09:04 +0100 Subject: [python-win32] Excel "stopped working" after reading in sheet names In-Reply-To: <8de3eae44155fbd7a60ae1c0cbd43cc8@mail.gmail.com> References: <8de3eae44155fbd7a60ae1c0cbd43cc8@mail.gmail.com> Message-ID: <4DE4A220.1080905@timgolden.me.uk> On 30/05/2011 21:26, Mark Mordeca wrote: > Greetings, > > I would appreciate any help I could get with the following problem. 30% > of the time after running the following code to get the sheet names out > of an excel file, I will receive a windows error saying that ?Microsoft > Office Excel has stopped working?. A few points: * The underlying problem is almost certainly going to be a subtle timing interaction around the refcounting on the pywin32 CDispatch objects which are proxying for the underlying Windows objects. It's a maze of twisty passages, so I'll let Mark or Roger comment if they think there's something to be said. * I couldn't reproduce the crash after a few times on my Win7 x64 with Office 2003, Python 2.7, pywin32 2.1.4. I note that you said it only crashed 1 time in 3 so perhaps I didn't try hard enough, but there may be some version-sensitivity there as well. * In general, you don't need to go unsetting sheet or book or whatever (unless you have some requirement which is unstated here). If you get rid of the "sheet=None" etc. lines, does the crash still occur? * As an aside: your for sheet in book.Sheets: loop is basically a list comprehension in disguise: sheetList = [sheet.Name for sheet in book.Sheets] Some people don't feel comfortable with list comps which may be your case. But just in case you weren't even aware of the possiblility, I thought I'd offer it for your further englightenment :) TJG From mark.mordeca at prosensus.ca Tue May 31 17:26:17 2011 From: mark.mordeca at prosensus.ca (Mark Mordeca) Date: Tue, 31 May 2011 11:26:17 -0400 Subject: [python-win32] Excel "stopped working" after reading in sheet names In-Reply-To: <4DE4A220.1080905@timgolden.me.uk> References: <8de3eae44155fbd7a60ae1c0cbd43cc8@mail.gmail.com> <4DE4A220.1080905@timgolden.me.uk> Message-ID: <07af2ef74e4c5d9844339e39294fe703@mail.gmail.com> Thanks for your reply Tim. "* I couldn't reproduce the crash after a few times on my Win7 x64 with Office 2003, Python 2.7, pywin32 2.1.4. I note that you said it only crashed 1 time in 3 so perhaps I didn't try hard enough, but there may be some version-sensitivity there as well." I am using Office 2007, opening a 2003 file, with Python 2.5. My version of pywin32 is build 214. I think that is the same as 2.1.4? Sometimes it did take me a while to get it to come up, so I am not surprised if it didn't come up for you (if it will happen at all). I have had it several times in a row though. "* In general, you don't need to go unsetting sheet or book or whatever (unless you have some requirement which is unstated here). If you get rid of the "sheet=None" etc. lines, does the crash still occur?" I removed the "=None" lines as you suggested. It took me many more tries than before to get the error to come up, but eventually it did. "* The underlying problem is almost certainly going to be a subtle timing interaction around the refcounting on the pywin32 CDispatch objects which are proxying for the underlying Windows objects. It's a maze of twisty passages, so I'll let Mark or Roger comment if they think there's something to be said." If this is true, I hope to get some advice on how to correct the problem. My previous implementation opened the Excel file at a previous point in the program, then later read in the sheets, and then even later closed the file, with possible minutes in between each of these. I never saw the error with this implementation, however it gave the opportunity to the user to interact with their own instance of Excel, potentially causing problems for the instance I created (previous mailing list e-mail: http://mail.python.org/pipermail/python-win32/2011-May/011494.html). So I had to change it so that the new Excel is opened to get the sheet names and then immediately closed. Again, thanks for your response. Any help is appreciated. Mark -----Original Message----- From: python-win32-bounces+mark.mordeca=prosensus.ca at python.org [mailto:python-win32-bounces+mark.mordeca=prosensus.ca at python.org] On Behalf Of Tim Golden Sent: Tuesday, May 31, 2011 4:09 AM To: python-win32 at python.org Subject: Re: [python-win32] Excel "stopped working" after reading in sheet names On 30/05/2011 21:26, Mark Mordeca wrote: > Greetings, > > I would appreciate any help I could get with the following problem. 30% > of the time after running the following code to get the sheet names out > of an excel file, I will receive a windows error saying that "Microsoft > Office Excel has stopped working". A few points: * The underlying problem is almost certainly going to be a subtle timing interaction around the refcounting on the pywin32 CDispatch objects which are proxying for the underlying Windows objects. It's a maze of twisty passages, so I'll let Mark or Roger comment if they think there's something to be said. * I couldn't reproduce the crash after a few times on my Win7 x64 with Office 2003, Python 2.7, pywin32 2.1.4. I note that you said it only crashed 1 time in 3 so perhaps I didn't try hard enough, but there may be some version-sensitivity there as well. * In general, you don't need to go unsetting sheet or book or whatever (unless you have some requirement which is unstated here). If you get rid of the "sheet=None" etc. lines, does the crash still occur? * As an aside: your for sheet in book.Sheets: loop is basically a list comprehension in disguise: sheetList = [sheet.Name for sheet in book.Sheets] Some people don't feel comfortable with list comps which may be your case. But just in case you weren't even aware of the possiblility, I thought I'd offer it for your further englightenment :) TJG _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From mail at timgolden.me.uk Tue May 31 17:38:18 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 31 May 2011 16:38:18 +0100 Subject: [python-win32] Excel "stopped working" after reading in sheet names In-Reply-To: <07af2ef74e4c5d9844339e39294fe703@mail.gmail.com> References: <8de3eae44155fbd7a60ae1c0cbd43cc8@mail.gmail.com> <4DE4A220.1080905@timgolden.me.uk> <07af2ef74e4c5d9844339e39294fe703@mail.gmail.com> Message-ID: <4DE50B6A.7000105@timgolden.me.uk> On 31/05/2011 16:26, Mark Mordeca wrote: > Thanks for your reply Tim. > If this is true, I hope to get some advice on how to correct the problem. ... Just a couple of quick answers, because I'm dashing off. One is that we have code which uses the technique you're demonstrating to *write* Excel dozens of times a day around the business and I'm not aware of ever having seen the Crash Dialog. Obviously that doesn't necessarily help your case, but it is a datapoint nonetheless. If all you're doing is reading data from Excel, you might want to look at xlrd. Try the http://www.python-excel.org/ website. The advantage is that you get a cross-platform, straight-to-the-data API into Excel. The disadvantage is that it doesn't do everything which you can achieve via COM. TJG From mark.mordeca at prosensus.ca Tue May 31 18:48:54 2011 From: mark.mordeca at prosensus.ca (Mark Mordeca) Date: Tue, 31 May 2011 12:48:54 -0400 Subject: [python-win32] Excel "stopped working" after reading in sheet names In-Reply-To: <4DE50B6A.7000105@timgolden.me.uk> References: <8de3eae44155fbd7a60ae1c0cbd43cc8@mail.gmail.com> <4DE4A220.1080905@timgolden.me.uk> <07af2ef74e4c5d9844339e39294fe703@mail.gmail.com> <4DE50B6A.7000105@timgolden.me.uk> Message-ID: "Just a couple of quick answers, because I'm dashing off. One is that we have code which uses the technique you're demonstrating to *write* Excel dozens of times a day around the business and I'm not aware of ever having seen the Crash Dialog. Obviously that doesn't necessarily help your case, but it is a datapoint nonetheless." Fair enough. I wish I could track down what exactly was causing this problem to appear. Hopefully a reply from Mark or Roger could shed some light. " If all you're doing is reading data from Excel, you might want to look at xlrd. Try the http://www.python-excel.org/ website. The advantage is that you get a cross-platform, straight-to-the-data API into Excel. The disadvantage is that it doesn't do everything which you can achieve via COM." When a user does not have Excel installed on their computer, we use xlrd to read the Excel file. However, the Excel files typically opened by the application are very large, with potentially on the order of tens of thousands of rows to be read in. Xlrd was just not fast enough and so that is why we opted for using COM if Excel was installed on the computer. What took Xlrd a couple minutes to read in, only took the COM a minute or less. Thanks, Mark -----Original Message----- From: python-win32-bounces+mark.mordeca=prosensus.ca at python.org [mailto:python-win32-bounces+mark.mordeca=prosensus.ca at python.org] On Behalf Of Tim Golden Sent: Tuesday, May 31, 2011 11:38 AM Cc: python-win32 at python.org Subject: Re: [python-win32] Excel "stopped working" after reading in sheet names On 31/05/2011 16:26, Mark Mordeca wrote: > Thanks for your reply Tim. > If this is true, I hope to get some advice on how to correct the problem. ... Just a couple of quick answers, because I'm dashing off. One is that we have code which uses the technique you're demonstrating to *write* Excel dozens of times a day around the business and I'm not aware of ever having seen the Crash Dialog. Obviously that doesn't necessarily help your case, but it is a datapoint nonetheless. If all you're doing is reading data from Excel, you might want to look at xlrd. Try the http://www.python-excel.org/ website. The advantage is that you get a cross-platform, straight-to-the-data API into Excel. The disadvantage is that it doesn't do everything which you can achieve via COM. TJG _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From timr at probo.com Tue May 31 20:53:43 2011 From: timr at probo.com (Tim Roberts) Date: Tue, 31 May 2011 11:53:43 -0700 Subject: [python-win32] Convert RGBA to BGRA using standard library? In-Reply-To: <4DE0B884.10206@canterbury.ac.nz> References: <4DE0B884.10206@canterbury.ac.nz> Message-ID: <4DE53937.2050108@probo.com> Greg Ewing wrote: > Can anyone think of an efficient way to convert a string > full of RGBA image data to BGRA, using only what's available > in the standard library? > > I'm trying to add a function to PyGUI for creating an Image > object from arbitrary data. The problem I'm having is that > GDI+ on Windows expects BGRA, whereas most other platforms > deal with RGBA. I don't want to require the user to supply > the data in different formats on different platforms, so > PyGUI needs to be able to convert where necessary. > > I know the conversion can be done easily using something > like PIL or numpy, but I'm after a solution that doesn't > depend on any third-party libraries. Nothing other than brute force. bout = [] for i in range(0,len(bin),4): bout.extend( [bin[i+2], bin[i+1], bin[i], bin[i+3]) ) It ain't gonna be quick. If it were me, I'd rather ship PIL. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rays at blue-cove.com Tue May 31 23:00:50 2011 From: rays at blue-cove.com (RayS) Date: Tue, 31 May 2011 14:00:50 -0700 Subject: [python-win32] Convert RGBA to BGRA using standard library? In-Reply-To: <4DE53937.2050108@probo.com> References: <4DE0B884.10206@canterbury.ac.nz> <4DE53937.2050108@probo.com> Message-ID: <20110531210115.IXLC20516.fed1rmfepo103.cox.net@fed1rmimpo02.cox.net> An HTML attachment was scrubbed... URL: From stef.mientki at gmail.com Tue May 31 23:22:50 2011 From: stef.mientki at gmail.com (Stef Mientki) Date: Tue, 31 May 2011 23:22:50 +0200 Subject: [python-win32] inserting an image in a word (2003) document Message-ID: <4DE55C2A.4000300@gmail.com> hello, I have word document, with special words like "$$$Name$$$", which are replaced with values from a database. If the special word starts with an underscore, like "$$$_Example$$$", the text should be replaced by an image. I use the code below, which works quit well for texts, but images, just the filename of that image is inserted. Does anyone has a clue, what I'm doing wrong ? self.app = win32com.client.Dispatch ( "Word.Application" ) self.app.Visible = visible self.app.Documents.Open(filename) """ Find all occurances of 'find_str' and replace with 'replace_str' in the active document. """ self.app.Selection.HomeKey ( Unit = wdStory ) find = self.app.Selection.Find find.Text = find_str while self.app.Selection.Find.Execute(): if find_str.startswith ( '_' ) : #expression.AddPicture(FileName, LinkToFile, SaveWithDocument, Range) #self.app.Selection.InlineShapes.AddPicture ( FileName = replace_str ) #self.app.Selection.InlineShapes.AddPicture ( FileName = replace_str, LinkToFile = True ) self.app.Selection.TypeParagraph() self.app.Selection.InlineShapes.AddPicture ( FileName = replace_str, SaveWithDocument = True ) #objSelection.InlineShapes.AddPicture(?\\servername\netlogon\signature.jpg?) self.app.Selection.TypeParagraph() #LinkToFile:=False else : self.app.Selection.TypeText ( Text = replace_str ) thanks, Stef