From win32com at ml.schieke.net Sun Aug 1 16:07:56 2004 From: win32com at ml.schieke.net (Jaco Schieke) Date: Sun Aug 1 16:10:30 2004 Subject: [python-win32] Tab-completion of data/properties and win32com Message-ID: <410CF93C.3020302@ml.schieke.net> Hi all, I am new to both python & win32com, so please see this question in context: I am trying to use IPython interactively to do some win32com programming and want to use the completion feature. The problem is that tab-completion only completes the object methods, and not the associated properties, for instance: After compiling the COM interface using makepy (through pythonwin) for Excel for instance, I try the following: >>> import win32com.client >>> xl=win32com.client.Dispatch("Excel.Application") >>> xl. xl.ActivateMicrosoftApp xl.InputBox xl.AddChartAutoFormat xl.Intersect xl.AddCustomList xl.MacroOptions xl.CLSID xl.MailLogoff xl.Calculate xl.MailLogon xl.CalculateFull xl.NextLetter xl.CalculateFullRebuild xl.OnKey xl.CentimetersToPoints xl.OnRepeat ... etc Now this only returns the methods associated with Excel.Application and not the properties. Is there any way to get access to the properties as well? Tx for any help. Regards, Jaco Schieke From mhammond at skippinet.com.au Mon Aug 2 10:47:13 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon Aug 2 10:47:12 2004 Subject: [python-win32] Tab-completion of data/properties and win32com In-Reply-To: <410CF93C.3020302@ml.schieke.net> Message-ID: <05f601c4786d$5748be50$0200a8c0@eden> > I am trying to use IPython interactively to do some win32com > programming > and want to use the completion feature. The problem is that > tab-completion only completes the object methods, and not the > associated > properties, for instance: IDLE doesn't have special knowledge of COM objects. Pythonwin does though - it shows the Excel properties in that example. You could try and find the place in IDLE where the list is built, and copy the code from pywin\scintilla\view.py - look for the comment "# The object may be a COM object with typelib support - lets see if we can get its props." Then submit a patch for IDLE, and it may well be accepted. Another cute idea would be to hack makepy to use "properties" for 2.3 and later - this should make them look more "real" - but IDLE may not support that yet (and it would be non-trivial anyway) Mark. From win32com at ml.schieke.net Tue Aug 3 00:37:49 2004 From: win32com at ml.schieke.net (Jaco Schieke) Date: Tue Aug 3 00:37:47 2004 Subject: [python-win32] Tab-completion of data/properties and win32com In-Reply-To: <05f601c4786d$5748be50$0200a8c0@eden> References: <05f601c4786d$5748be50$0200a8c0@eden> Message-ID: <410EC23D.1070901@ml.schieke.net> Mark Hammond wrote: >>I am trying to use IPython interactively to do some win32com >>programming >>and want to use the completion feature. The problem is that >>tab-completion only completes the object methods, and not the >>associated >>properties, for instance: >> >> > >IDLE doesn't have special knowledge of COM objects. Pythonwin does though - >it shows the Excel properties in that example. > >You could try and find the place in IDLE where the list is built, and copy >the code from pywin\scintilla\view.py - look for the comment "# The object >may be a COM object with typelib support - lets see if we can get its >props." Then submit a patch for IDLE, and it may well be accepted. > >Another cute idea would be to hack makepy to use "properties" for 2.3 and >later - this should make them look more "real" - but IDLE may not support >that yet (and it would be non-trivial anyway) > >Mark. > > > > > Mark, Thanks for the advice. We misunderstood each other, but I got it working. What I ended up doing is to patch rlcompleter.py to allow it to get all the attributes of the COM object (as is done in pywin's view.py). I'm currently using IPython (ipython.scipy.org) which is using a modified rlcompleter.py due to limitations of the exising rlcompleter.py implementation. I'll submit a patch to IPython and see if it gets accepted there. Would there be any point in submitting a patch against 2.3's rlcompleter? This is a win32 specific feature, and if I understand you correctly, it can be solved in other ways by fixing makepy. Regards & tx for the assistance, Jaco From mhammond at skippinet.com.au Tue Aug 3 02:22:54 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue Aug 3 02:22:43 2004 Subject: [python-win32] Tab-completion of data/properties and win32com In-Reply-To: <410EC23D.1070901@ml.schieke.net> Message-ID: <02e201c478f0$056cb130$0200a8c0@eden> > Would there be any point in submitting a patch against 2.3's > rlcompleter? I don't see why not - people may find it useful, and you can allow the rlcompleter maintainer/expert to decide. > This is a win32 specific feature, and if I understand you > correctly, it can be solved in other ways by fixing makepy. It could, but that is a big job :) It may be an interesting side-project for someone wanting to dig into how all this works, but I won't be doing it just for its own sake. Mark. From hgrund at gmx.de Tue Aug 3 11:23:23 2004 From: hgrund at gmx.de (Hannes Grund) Date: Tue Aug 3 11:23:24 2004 Subject: [python-win32] wxPython/Pythonwin interplay/Richtext Controls Message-ID: <6925.1091525003@www34.gmx.net> Dear all, The original problem I had was the need of an richtext control to be used within a wxWidgets/wxPython gui running on an MSWin platform. wxTextCtrl as provided by wxWidgets uses (internally) the richtext ctrl (as provided by MSW), however, it exposes not its rich text capabilities (simply due to the platform specific nature) within the wxPython framework, there is one option to set (wxTE_RICH, wxTE_RICH2), precisly the version of the underlying rich edit dll to use, the use of this option affects also the window class set by wxWidgets. The following works well, textctrl = wxTextCtrl(parent,-1,"",style=wxTE_RICH) pywnd = win32ui.CreateWindowFromHandle(textctrl.GetHandle()) The resulting pywin object is of type PyCRichEditCtrl, consquently, any rich text specific features can be accessed. The problem is that want to use some features only available by using the wxTE_RICH2 option (in the code example above wxTE_RICH is used.) The above construction refuses to work then, the resulting pythonwin object is only a PyCWnd object, the rich text api is not accessible. My question is now, if there is any way to force the creation of an PyCRichEditCtrl instance from an given handle. Thanks in advance, Hannes Grund -- NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler! GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl From hgrund at gmx.de Tue Aug 3 11:36:47 2004 From: hgrund at gmx.de (Hannes Grund) Date: Tue Aug 3 11:36:48 2004 Subject: [python-win32] IPersistStorage ? Message-ID: <25213.1091525807@www34.gmx.net> Dear all, I have the following problem: I have an instance of an COM-Object stemming from some commercial software. (created by using win32com.client.Dispatch), which I want to be written on disk by using .OleSaveToStream from the pythoncom module. According to the vendor the objects supports the IPersistStream interface, but I was'nt able to figure out the neccessary transformations - does anybody has a cookbook approach ? Thanks in advance, Hannes Grund -- NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler! GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl From mhammond at skippinet.com.au Wed Aug 4 00:21:19 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed Aug 4 00:21:35 2004 Subject: [python-win32] wxPython/Pythonwin interplay/Richtext Controls In-Reply-To: <6925.1091525003@www34.gmx.net> Message-ID: <051201c479a8$40ec2160$0200a8c0@eden> I'm afraid I don't know what a "RICH2" control is exactly, and why Pythonwin doesn't know about it. However, you should also keep in mind that the win32gui module should allow you to send whatever Windows messages you like. SendMessage in win32gui allows you to pass strings and buffers for these params, meaning the struct or array modules can be used to pack the raw data. Not as "nice" as the pythonwin OO framework, but should still work. Mark. > -----Original Message----- > From: python-win32-bounces@python.org > [mailto:python-win32-bounces@python.org]On Behalf Of Hannes Grund > Sent: Tuesday, 3 August 2004 7:23 PM > To: python-win32@python.org > Subject: [python-win32] wxPython/Pythonwin interplay/Richtext Controls > > > Dear all, > > The original problem I had was the need of an richtext control > to be used within a wxWidgets/wxPython gui running on an > MSWin platform. > wxTextCtrl as provided by wxWidgets uses (internally) the richtext > ctrl (as provided by MSW), however, it exposes not its rich text > capabilities (simply due to the platform specific nature) within > the wxPython framework, there is one option to set > (wxTE_RICH, wxTE_RICH2), > precisly the version > of the underlying rich edit dll to use, the use of this option > affects also the window class set by wxWidgets. > > The following works well, > > textctrl = wxTextCtrl(parent,-1,"",style=wxTE_RICH) > pywnd = win32ui.CreateWindowFromHandle(textctrl.GetHandle()) > > The resulting pywin object is of type PyCRichEditCtrl, > consquently, any > rich text specific features can be accessed. > > The problem is that want to use some features only available > by using the > wxTE_RICH2 option (in the code example above wxTE_RICH is used.) > The above construction refuses to work then, the resulting > pythonwin object > is only a PyCWnd object, the rich text api is not accessible. > > My question is now, if there is any way to force the creation of an > PyCRichEditCtrl instance from an given handle. > > Thanks in advance, > > Hannes Grund > > -- > NEU: WLAN-Router f|r 0,- EUR* - auch f|r DSL-Wechsler! > GMX DSL = superg|nstig & kabellos http://www.gmx.net/de/go/dsl > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 From martindemello at gmail.com Wed Aug 4 09:41:04 2004 From: martindemello at gmail.com (Martin DeMello) Date: Wed Aug 4 09:41:06 2004 Subject: [python-win32] Simple scintilla example Message-ID: Hi, I'm trying to get a simple program running to open a new scintilla window. Here's what I tried: >>> import win32ui >>> template = pywin.mfc.docview.DocTemplate(None) >>> doc = pywin.scintilla.document.CScintillaDocument(template) >>> view = pywin.scintilla.view.CScintillaView(doc) >>> fr = win32ui.GetMainFrame() >>> view.CreateWindow(fr) Which appeared to do something (at least, the interpreter didn't complain), but then I got stuck trying to display the view. Any pointers? martin From hgrund at gmx.de Wed Aug 4 10:46:09 2004 From: hgrund at gmx.de (Hannes Grund) Date: Wed Aug 4 10:46:11 2004 Subject: [python-win32] wxPython/Pythonwin interplay/Richtext Controls References: <051201c479a8$40ec2160$0200a8c0@eden> Message-ID: <31326.1091609169@www20.gmx.net> Thanks for reply, Sorry for posting incomplete information, the options passed to wxTextCtrl determine the the version of the used RichEdit.dll and (according to the sources) the window class string. (I don't know anything about the mechanism how pythonwin recognizes which of its classes to instanciate, maybe this is my problem). The use of wxTE_RICH option causes the window class string to be "RICHEDIT", when using the option wxTE_RICH2 the window class string will be "RichEdit20". I considered to do it via SendMessage, but on one hand some options cannot be set after the creation of the control (and I have to create within wx), I tried to construct the EditStreamCallback functions manually by using struct and array but I simply failed (anybody out there with an pointer to an working example ??) Thanks in advance, Hannes Grund > I'm afraid I don't know what a "RICH2" control is exactly, and why > Pythonwin > doesn't know about it. However, you should also keep in mind that the > win32gui module should allow you to send whatever Windows messages you > like. > SendMessage in win32gui allows you to pass strings and buffers for these > params, meaning the struct or array modules can be used to pack the raw > data. Not as "nice" as the pythonwin OO framework, but should still work. > > Mark. > > > -----Original Message----- > > From: python-win32-bounces@python.org > > [mailto:python-win32-bounces@python.org]On Behalf Of Hannes Grund > > Sent: Tuesday, 3 August 2004 7:23 PM > > To: python-win32@python.org > > Subject: [python-win32] wxPython/Pythonwin interplay/Richtext Controls > > > > > > Dear all, > > > > The original problem I had was the need of an richtext control > > to be used within a wxWidgets/wxPython gui running on an > > MSWin platform. > > wxTextCtrl as provided by wxWidgets uses (internally) the richtext > > ctrl (as provided by MSW), however, it exposes not its rich text > > capabilities (simply due to the platform specific nature) within > > the wxPython framework, there is one option to set > > (wxTE_RICH, wxTE_RICH2), > > precisly the version > > of the underlying rich edit dll to use, the use of this option > > affects also the window class set by wxWidgets. > > > > The following works well, > > > > textctrl = wxTextCtrl(parent,-1,"",style=wxTE_RICH) > > pywnd = win32ui.CreateWindowFromHandle(textctrl.GetHandle()) > > > > The resulting pywin object is of type PyCRichEditCtrl, > > consquently, any > > rich text specific features can be accessed. > > > > The problem is that want to use some features only available > > by using the > > wxTE_RICH2 option (in the code example above wxTE_RICH is used.) > > The above construction refuses to work then, the resulting > > pythonwin object > > is only a PyCWnd object, the rich text api is not accessible. > > > > My question is now, if there is any way to force the creation of an > > PyCRichEditCtrl instance from an given handle. > > > > Thanks in advance, > > > > Hannes Grund > > > > -- > > NEU: WLAN-Router f|r 0,- EUR* - auch f|r DSL-Wechsler! > > GMX DSL = superg|nstig & kabellos http://www.gmx.net/de/go/dsl > > > > _______________________________________________ > > Python-win32 mailing list > > Python-win32@python.org > > http://mail.python.org/mailman/listinfo/python-win32 > -- NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler! GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl From alienoid at is.lg.ua Wed Aug 4 11:08:10 2004 From: alienoid at is.lg.ua (Ruslan) Date: Wed Aug 4 11:08:15 2004 Subject: [python-win32] python and 'byte array' Message-ID: <1091610489.5637.8.camel@dev.is.lg.ua> Hello. I use win32com package to call WinHTTP COM methods. One of them is 'Send'. I can pass string parameter to 'Send' method from python - it's OK, but to send binary data i need somehow pass in 'Send' method data of _byte array_ type(Visual Basic type). Does anybody know how to mimic that 'byte array' type of Visual Basic in Python (i need to pass big chunks of binary data in 'Send')? ------------- fin = open('binary.dat', 'rb') body = fin.read() fin.close() ------------- As a result the 'body' is of type 'string' and i need somehow make it similar to VB's 'byte array', otherwise 'Send(body)' just sends 10-15 bytes to server. I tried struct.pack, but that doesn't seem to be an option. Thanks in advance. Your help is very appreciated. Best regards, Ruslan From niki at vintech.bg Wed Aug 4 12:24:30 2004 From: niki at vintech.bg (Niki Spahiev) Date: Wed Aug 4 12:50:13 2004 Subject: [python-win32] Simple scintilla example In-Reply-To: References: Message-ID: <4110B95E.4050104@vintech.bg> Martin DeMello wrote: > Hi, > > I'm trying to get a simple program running to open a new scintilla > window. Here's what I tried: > > >>>>import win32ui >>>>template = pywin.mfc.docview.DocTemplate(None) >>>>doc = pywin.scintilla.document.CScintillaDocument(template) >>>>view = pywin.scintilla.view.CScintillaView(doc) >>>>fr = win32ui.GetMainFrame() >>>>view.CreateWindow(fr) > > > Which appeared to do something (at least, the interpreter didn't > complain), but then I got stuck trying to display the view. Any > pointers? Your script has no windows message loop. Try running pythonwin /app script, but first get patch about /app from sourceforge. Niki Spahiev From martindemello at gmail.com Wed Aug 4 13:04:42 2004 From: martindemello at gmail.com (Martin DeMello) Date: Wed Aug 4 13:04:46 2004 Subject: [python-win32] Simple scintilla example In-Reply-To: <4110B95E.4050104@vintech.bg> References: <4110B95E.4050104@vintech.bg> Message-ID: On Wed, 04 Aug 2004 13:24:30 +0300, Niki Spahiev wrote: > > Your script has no windows message loop. Try running pythonwin /app > script, but first get patch about /app from sourceforge. Doesn't pythonwin itself have a windows message loop? I'm trying to make the scintilla window a child of the pythonwin app, which I hoped the use of GetMainFrame would accomplish. martin From mhammond at skippinet.com.au Wed Aug 4 14:59:00 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed Aug 4 14:58:45 2004 Subject: [python-win32] Simple scintilla example In-Reply-To: Message-ID: <006101c47a22$d078f040$0200a8c0@eden> > I'm trying to get a simple program running to open a new scintilla > window. Here's what I tried: Look at the pythonwin demos - eg, Demos\dibdemo.py. After looking at that, the following seems to work: >>> import win32ui >>> template = pywin.mfc.docview.DocTemplate(None) >>> doc = pywin.scintilla.document.CScintillaDocument(template) >>> view = pywin.scintilla.view.CScintillaView(doc) >>> frame = win32ui.CreateMDIChild() >>> frame.LoadFrame() >>> frame.ShowWindow() From mhammond at skippinet.com.au Wed Aug 4 15:02:07 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed Aug 4 15:01:49 2004 Subject: [python-win32] python and 'byte array' In-Reply-To: <1091610489.5637.8.camel@dev.is.lg.ua> Message-ID: <006401c47a23$3f4a6260$0200a8c0@eden> > I use win32com package to call WinHTTP COM methods. > One of them is 'Send'. I can pass string parameter to 'Send' > method from > python - it's OK, but to send binary data i need somehow pass > in 'Send' > method data of _byte array_ type(Visual Basic type). Does anybody know > how to mimic that 'byte array' type of Visual Basic in Python > (i need to > pass big chunks of binary data in 'Send')? If you have run makepy for the object, passing a string will work (it already knows a byte array is expected, so converts it). If you havent't run makepy, pass buffer(the_string) - this will mean that Python guesses byte-array as the type (where passing a string itself results in guessing VT_BSTR) Mark. From jody.burgess at sewardconsulting.com Wed Aug 4 19:08:26 2004 From: jody.burgess at sewardconsulting.com (Jody Burgess) Date: Wed Aug 4 19:06:49 2004 Subject: [python-win32] RE: Python-win32 Digest, Vol 17, Issue 4 In-Reply-To: <20040804100105.427D11E4017@bag.python.org> Message-ID: Good Morning; I am fairly new to Python and am writing a program that will will, hopefully, allow me to print images from specific printer trays depending on their size. I have review the win32print and win32ui modules and cannot find any way to print files to specific printer trays. Has anyone encountered this before? Is so, any help or examples would be greatly appreciated. Thank You. Jody Burgess ISP Systems Analyst Seward Consulting Ltd. 780.702.5103 jody.burgess@sewardconsulting.com From johnbaker at att.com Wed Aug 4 19:26:57 2004 From: johnbaker at att.com (Baker, John D, ALABS) Date: Thu Aug 5 00:02:55 2004 Subject: [python-win32] psyco win32com acrobat ole automation and memory Message-ID: <9473683187ADC049A855ED2DA739ABCA0706438E@KCCLUST06EVS1.ugd.att.com> i put together a quick win32com script to walk through a pdf using acrobat's ole automation & have odd memory usage when using psyco. python 2.3.4 and acrobat 4 typelib. With Psyco enabled and I ran this on a very large PDF (5000+ pages), the memory usage exploded to 400M+ before I killed it. With Psyco Removed, memory use is constant at 6M or so. Maybe this is normal, but it was a surprise to me. JB # abbreviated ... o = win32com.client.Dispatch("acroexch.pddoc") o.Open(os.path.abspath(f)) pages = o.GetNumPages for p in range(pages): page=o.AcquirePage(p) # Creates a COM object textselect = page.CreateWordHilite(hlist) # Creates a COM object # Do Some Stuff del page del textselect o.Close del o From jody.burgess at sewardconsulting.com Wed Aug 4 23:20:39 2004 From: jody.burgess at sewardconsulting.com (Jody Burgess) Date: Thu Aug 5 00:02:55 2004 Subject: [python-win32] PCL Printer programming Message-ID: If I had specific PCL codes and a graphic file that I wanted to send to a specific network printer that I may or may not be connected to, how can this be accomplished in Python? Jody Burgess ISP Systems Analyst Seward Consulting Ltd. 780.702.5103 jody.burgess@sewardconsulting.com From alienoid at is.lg.ua Thu Aug 5 00:03:16 2004 From: alienoid at is.lg.ua (Ruslan) Date: Thu Aug 5 00:03:26 2004 Subject: [python-win32] python and 'byte array' In-Reply-To: <006401c47a23$3f4a6260$0200a8c0@eden> References: <006401c47a23$3f4a6260$0200a8c0@eden> Message-ID: <1091656996.8714.41.camel@dev.is.lg.ua> Ð’ Срд, 04.08.2004, в 16:02, Mark Hammond пишет: > > I use win32com package to call WinHTTP COM methods. > > One of them is 'Send'. I can pass string parameter to 'Send' > > method from > > python - it's OK, but to send binary data i need somehow pass > > in 'Send' > > method data of _byte array_ type(Visual Basic type). Does anybody know > > how to mimic that 'byte array' type of Visual Basic in Python > > (i need to > > pass big chunks of binary data in 'Send')? > > If you have run makepy for the object, passing a string will work (it > already knows a byte array is expected, so converts it). > > If you havent't run makepy, pass buffer(the_string) - this will mean that > Python guesses byte-array as the type (where passing a string itself results > in guessing VT_BSTR) > > Mark. > > Thanks you ever so much. buffer(string) solved my problem, but need to note - i have run makepy on winhttp.dll because without it i couldn't use Option property to set option, only to read, after running makepy i was able to set property with generated SetOption method. Dunno why, but only explicitly writing buffer(str) solves my problem. Anyway thanks for your help and for your great product. Best regards, Ruslan From jens.jorgensen at tallan.com Thu Aug 5 00:48:10 2004 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Thu Aug 5 00:48:23 2004 Subject: [python-win32] PCL Printer programming In-Reply-To: References: Message-ID: <411167AA.20303@tallan.com> Your question is heading towards definite RTFM territory. This can probably be easily done through a basic sequence of: from win32print import * OpenPrinter(...) StartDocPrinter(...) WritePrinter(...) These are documented inthe win32all extensions documentation. For more detail about how the underlying calls work, refer to the on-line MSDN library. Jody Burgess wrote: >If I had specific PCL codes and a graphic file that I wanted to send to a >specific network printer that I may or may not be connected to, how can this >be accomplished in Python? > >Jody Burgess ISP >Systems Analyst >Seward Consulting Ltd. >780.702.5103 >jody.burgess@sewardconsulting.com > > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 2861 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.python.org/pipermail/python-win32/attachments/20040804/3cdbec88/smime.bin From rwupole at msn.com Thu Aug 5 05:31:50 2004 From: rwupole at msn.com (Roger Upole) Date: Thu Aug 5 05:13:14 2004 Subject: [python-win32] RE: Python-win32 Digest, Vol 17, Issue 4 Message-ID: <000801c47a9c$c02c92d0$d417c943@rupole> Looks like it's not possible right now, due to level 2 info not supported for SetJob. It would be a real pain to implement, as JOB_INFO_2 is a large structure. Also would require wrapping DEVMODE which is another huge struct containing unions and at least one more structure. There was some discussion a while back about wrapping DEVMODE for use in changing display settings, but I don't remember what came of it. Roger >>> Good Morning; >>> I am fairly new to Python and am writing a program that will will, >>> hopefully, allow me to print images from specific printer trays depending on >>> their size. I have review the win32print and win32ui modules and cannot find >>> any way to print files to specific printer trays. Has anyone encountered >>> this before? Is so, any help or examples would be greatly appreciated. >>> Thank You. >>> Jody Burgess ISP >>> Systems Analyst >>> Seward Consulting Ltd. >>> 780.702.5103 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040804/fc2ef554/attachment-0001.html From jens.jorgensen at tallan.com Thu Aug 5 16:43:30 2004 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Thu Aug 5 16:44:29 2004 Subject: [python-win32] RE: Python-win32 Digest, Vol 17, Issue 4 In-Reply-To: <000801c47a9c$c02c92d0$d417c943@rupole> References: <000801c47a9c$c02c92d0$d417c943@rupole> Message-ID: <41124792.9080104@tallan.com> Roger, Can you really not send just PCL? I know I've personally sent raw postscript to a printer just using the level 1 information. I just assumed that sending PCL would work too. Roger Upole wrote: > Looks like it's not possible right now, due to level 2 info not > supported for SetJob. > It would be a real pain to implement, as JOB_INFO_2 is a large structure. > Also would require wrapping DEVMODE which is another huge struct > containing > unions and at least one more structure. There was some discussion a while > back about wrapping DEVMODE for use in changing display settings, but I > don't remember what came of it. > Roger > > > > >>> Good Morning; > >>> I am fairly new to Python and am writing a program that will will, > >>> hopefully, allow me to print images from specific printer trays > depending on > >>> their size. I have review the win32print and win32ui modules and > cannot find > >>> any way to print files to specific printer trays. Has anyone > encountered > >>> this before? Is so, any help or examples would be greatly appreciated. > > >>> Thank You. > > >>> Jody Burgess ISP > >>> Systems Analyst > >>> Seward Consulting Ltd. > >>> 780.702.5103 > >------------------------------------------------------------------------ > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" From jjl at pobox.com Thu Aug 5 21:22:39 2004 From: jjl at pobox.com (John J Lee) Date: Thu Aug 5 21:22:43 2004 Subject: [python-win32] psyco win32com acrobat ole automation and memory In-Reply-To: <9473683187ADC049A855ED2DA739ABCA0706438E@KCCLUST06EVS1.ugd.att.com> References: <9473683187ADC049A855ED2DA739ABCA0706438E@KCCLUST06EVS1.ugd.att.com> Message-ID: On Wed, 4 Aug 2004, Baker, John D, ALABS wrote: [...] > With Psyco enabled and I ran this on a very large PDF (5000+ pages), the memory usage exploded to 400M+ before I killed it. > > With Psyco Removed, memory use is constant at 6M or so. > > Maybe this is normal, but it was a surprise to me. [...] Yes, psyco does do that. our-chief-weapons-are-surprise-and-outlandish-memory-usage-ly y'rs, John From beast at ludens.elte.hu Thu Aug 5 21:48:06 2004 From: beast at ludens.elte.hu (=?ISO-8859-15?B?SW1yZSBBbmRy4XMgUvNiZXJ0?=) Date: Thu Aug 5 21:52:28 2004 Subject: [python-win32] Windows service features and Python Message-ID: <704466662.20040805214806@ludens.elte.hu> Hello list, I'm transforming some Python code into a Windows service. I started with pywin32-202.win32-py2.2.exe, and investigated the demo pipeTestService. This worked fine, so I started converting my code, with no paticular Windows system programming experience. After reading through the help, the newsgroups and searching on the web, I still have the following questions: Q1) How can I make my Python service support pause/ continue? Implementing SvcPause() and SvcContinue() seems to be not enough, as I get 'Could not pause ... service on Local Computer. The service did not return an error. ...' dialog despite that the SvcPause() method is executed. After this dialog I found that the service was stopped, ending within SvcDoRun(). Please refer to the attached code. Q2) How can I register my own event IDs/categories? I don't know where/how to define my own IDs/cats. The demo seems to support two IDs, servicemanager.PYS_SERVICE_STARTED and servicemanager.PYS_SERVICE_STOPPED. Q3) How can I add counters to the Python service? Looking at the files perf_install.ini and perf_install.h, this could be possible, but after install I do not see these counters in PerfMon. I do not see the way these files are connected to the service demo source code... Maybe these are already installed as the readme indicates, but where should I look? After all the package is quite useful with the start/stop service feature itself, but I would welcome some fancy stuff as well... -- Thanks, Andr?s From beast at ludens.elte.hu Thu Aug 5 21:57:35 2004 From: beast at ludens.elte.hu (=?ISO-8859-15?B?SW1yZSBBbmRy4XMgUvNiZXJ0?=) Date: Thu Aug 5 21:57:33 2004 Subject: [python-win32] Re: Windows service features and Python In-Reply-To: <704466662.20040805214806@ludens.elte.hu> References: <704466662.20040805214806@ludens.elte.hu> Message-ID: <1573709751.20040805215735@ludens.elte.hu> Hello list, I always forgot attaching what I promise... Sorry, Andr?s Thursday, August 5, 2004, 9:48:06 PM, you wrote: > Hello list, > I'm transforming some Python code into a Windows > service. I started with pywin32-202.win32-py2.2.exe, > and investigated the demo pipeTestService. This > worked fine, so I started converting my code, with > no paticular Windows system programming experience. > After reading through the help, the newsgroups and > searching on the web, I still have the following questions: > Q1) How can I make my Python service support pause/ > continue? Implementing SvcPause() and SvcContinue() > seems to be not enough, as I get 'Could not pause > ... service on Local Computer. The service did not > return an error. ...' dialog despite that the > SvcPause() method is executed. After this dialog > I found that the service was stopped, ending within > SvcDoRun(). Please refer to the attached code. > Q2) How can I register my own event IDs/categories? I don't > know where/how to define my own IDs/cats. The demo seems > to support two IDs, servicemanager.PYS_SERVICE_STARTED and > servicemanager.PYS_SERVICE_STOPPED. > Q3) How can I add counters to the Python service? Looking at > the files perf_install.ini and perf_install.h, this > could be possible, but after install I do not see these > counters in PerfMon. I do not see the way these files > are connected to the service demo source code... Maybe > these are already installed as the readme indicates, > but where should I look? > After all the package is quite useful with the start/stop > service feature itself, but I would welcome some fancy stuff > as well... -------------- next part -------------- import win32serviceutil, win32service import pywintypes, win32con, winerror # Use "import *" to keep this looking as much as a "normal" service # as possible. Real code shouldn't do this. from win32event import * from win32file import * from win32pipe import * from win32api import * from ntsecuritycon import * import traceback import thread def ApplyIgnoreError(fn, args): try: return apply(fn, args) except error: # Ignore win32api errors. return None class PythonTestService(win32serviceutil.ServiceFramework): _svc_name_ = "PythonTestService" _svc_display_name_ = "Python Test Service" def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = CreateEvent(None, 0, 0, None) self.overlapped = pywintypes.OVERLAPPED() self.overlapped.hEvent = CreateEvent(None,0,0,None) # self.thread_handles = [] def SvcStop(self): import servicemanager servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, 12121, (self._svc_name_, 'SvcStop') ) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) SetEvent(self.hWaitStop) def SvcPause(self): import servicemanager servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, 11111, (self._svc_name_, 'SvcPause') ) self.ReportServiceStatus(win32service.SERVICE_PAUSE_PENDING) SetEvent(self.hWaitStop) servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, 11111, (self._svc_name_, 'SvcPause end') ) def SvcContinue(self): import servicemanager servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, 22222, (self._svc_name_, 'SvcContinue') ) self.ReportServiceStatus(win32service.SERVICE_CONTINUE_PENDING) SetEvent(self.hWaitStop) def SvcInterrogate(self): import servicemanager servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, 33333, (self._svc_name_, 'SvcInterrogate') ) self.ReportServiceStatus(win32service.SERVICE_INTERROGATE) SetEvent(self.hWaitStop) def SvcShutdown(self): import servicemanager servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, 44444, (self._svc_name_, 'SvcShutdown') ) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) SetEvent(self.hWaitStop) def SvcOther(self, control): import servicemanager servicemanager.LogMsg( servicemanager.EVENTLOG_WARNING_TYPE, 55555, (self._svc_name_, "SvcOther, code %d" % (control)) ) def SvcDoRun(self): # Write an event log record - in debug mode we will also # see this message printed. import servicemanager servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, 12345, (self._svc_name_, 'SvcDoRun') ) while 1: print "." rc = WaitForMultipleObjects((self.hWaitStop, self.overlapped.hEvent), 0, INFINITE) if rc==WAIT_OBJECT_0: # Stop event break Sleep(500) # Sleep to ensure that any new threads are in the list, and then # wait for all current threads to finish. # What is a better way? # Sleep(500) # while self.thread_handles: # self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 5000) # print "Waiting for %d threads to finish..." % (len(self.thread_handles)) # WaitForMultipleObjects(self.thread_handles, 1, 3000) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 5000) # Write another event log record. servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, 54321, (self._svc_name_, 'SvcDoRun ends') ) if __name__=='__main__': win32serviceutil.HandleCommandLine(PythonTestService) From mhammond at skippinet.com.au Fri Aug 6 02:16:06 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri Aug 6 02:15:47 2004 Subject: [python-win32] Re: Windows service features and Python In-Reply-To: <1573709751.20040805215735@ludens.elte.hu> Message-ID: <05bc01c47b4a$9153ef90$0200a8c0@eden> > > I'm transforming some Python code into a Windows > > service. I started with pywin32-202.win32-py2.2.exe, > > and investigated the demo pipeTestService. This > > worked fine, so I started converting my code, with > > no paticular Windows system programming experience. I'm afraid your problems relate to this lack of Windows experience more than to Python itself. "Python Programming on Win32" does cover alot of this stuff in some detail, but general overviews of Windows services would be useful. > > Q1) How can I make my Python service support pause/ > > continue? Implementing SvcPause() and SvcContinue() > > seems to be not enough, as I get 'Could not pause > > ... service on Local Computer. The service did not > > return an error. ...' dialog despite that the > > SvcPause() method is executed. After this dialog > > I found that the service was stopped, ending within > > SvcDoRun(). Please refer to the attached code. You need to report a status of PAUSED to the service control manager, in the same way that RUNNING, START_PENDING, STOP_PENDING and STOPPED are alreay reported. Indeed, if your pause takes some time, you must periodically report PAUSE_PENDING, until you actually enter the PAUSED state. What "pause" means is up to you and your code. One strategy would be to use an event, much in the same way that "stop" is handled in the samples. > > Q2) How can I register my own event IDs/categories? I don't > > know where/how to define my own IDs/cats. The demo seems > > to support two IDs, servicemanager.PYS_SERVICE_STARTED and > > servicemanager.PYS_SERVICE_STOPPED. See PPWin32 - in a nutshell, there are a number of predefined messages, and unfortunately you need to look in win32\src\PythonServiceMessages.mc in the source distribution (or via the CVS viewer). These .mc files are compiled using MSVC6 tools, so there is currently no easy to to define your own. You are free to use the various "general" ones in PythonServiceMessages.mc. > > Q3) How can I add counters to the Python service? Looking at > > the files perf_install.ini and perf_install.h, this > > could be possible, but after install I do not see these > > counters in PerfMon. I do not see the way these files > > are connected to the service demo source code... Maybe > > these are already installed as the readme indicates, > > but where should I look? Sorry, but I can't recall exactly. perfmon counters are not for the feint hearted. Again, PPWin32 covers that. Mark. From jody.burgess at sewardconsulting.com Fri Aug 6 16:27:04 2004 From: jody.burgess at sewardconsulting.com (Jody Burgess) Date: Fri Aug 6 16:25:13 2004 Subject: [python-win32] RE: Python-win32 Digest, Vol 17, Issue 4 In-Reply-To: <20040806100050.888701E4015@bag.python.org> Message-ID: Jens; Were you successful is sending the raw PCL code? Jody Burgess ISP Systems Analyst Seward Consulting Ltd. 780.702.5103 jody.burgess@sewardconsulting.com From timr at probo.com Fri Aug 6 18:32:27 2004 From: timr at probo.com (Tim Roberts) Date: Fri Aug 6 18:32:31 2004 Subject: [python-win32] RE: Python-win32 Digest, Vol 17, Issue 4 In-Reply-To: <20040806100050.888701E4015@bag.python.org> References: <20040806100050.888701E4015@bag.python.org> Message-ID: <4113B29B.5060600@probo.com> On Thu, 05 Aug 2004 09:43:30 -0500, "Jens B. Jorgensen" wrote: >Roger, > >Can you really not send just PCL? I know I've personally sent raw >postscript to a printer just using the level 1 information. I just >assumed that sending PCL would work too. > > It depends on the printer driver. Not all of them accept the "raw" escape. Also, the interaction with whatever PCL the printer driver is spewing is not as well defined as it is with Postscript. It's an icky job. -- - Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc. From stephene at sjsoft.com Fri Aug 6 20:10:37 2004 From: stephene at sjsoft.com (stephene@sjsoft.com) Date: Fri Aug 6 20:10:40 2004 Subject: [python-win32] MAPI ModifyRecipients Message-ID: <176080-22004856181037230@M2W087.mail2web.com> I am using extended MAPI to send emails through outlook and have gotten as far as creating the message in the outbox. The next step is to set the recipients of the email, and thats where I am totally stumped. I am wanting to use PyIMessage.ModifyRecipients() but I have no idea what argument to pass it. The documentation I have read says that it required (flags,mods) but what is mods? I spent some time looking through the pywin32 source and I *think* that it should be a set of nested tuples that look something something like (((flag,value))) Does anyone know the correct format of the "mods" argument for this function? also, I am using activestate's documentation for the python-win32 mapi extensions here: http://aspn.activestate.com/ASPN/docs/ActivePython/2.2/PyWin32/PyIMessage__M odifyRecipients_meth.html Is there any more comprehensive documentation? Thanks Stephen Emslie -------------------------------------------------------------------- mail2web - Check your email from the web at http://mail2web.com/ . From rob at dolphinsearch.com Sat Aug 7 01:55:53 2004 From: rob at dolphinsearch.com (Rob Nikander) Date: Sat Aug 7 02:02:57 2004 Subject: [python-win32] PyTime bug in 2.3 ? Message-ID: <41141A89.60905@dolphinsearch.com> Hi all, I'm wondering if anyone else as this problem. In Python 2.3, with win32 extensions installed... > t = pywintypes.Time((1601,1,1,0,0,0)) > print t ... python dies without an exception. t.Format() also kills it. Yes, the date is weird (year 1601), but we get dates like this from Outlook and we have to handle them. This doesn't happen in Python 2.2. Thanks, Rob From mhammond at skippinet.com.au Sat Aug 7 04:23:23 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat Aug 7 04:23:18 2004 Subject: [python-win32] MAPI ModifyRecipients In-Reply-To: <176080-22004856181037230@M2W087.mail2web.com> Message-ID: <090f01c47c25$8b1af390$0200a8c0@eden> > I spent some time looking through the pywin32 source and I > *think* that it > should be a set of nested tuples that look something something like > (((flag,value))) > > Does anyone know the correct format of the "mods" argument for this > function? MS document this as being a ADRLIST structure, which is an array of ADRENTRY structures. An ADRENTRY is the same an an SRowSet - an array of property values. So Python will be wanting a list/tuple of objects (ie, the ADRLIST), with each object being an array of property values. A property value is a tuple of (prop_tag, prop_value). So, something like: prop_list1 = ((PT_SOMETHING, "hello"), (PT_SOMETHINGELSE, 123)) prop_list2 = ... addrlist = prop_list1, prop_list2 > also, I am using activestate's documentation for the python-win32 mapi > extensions here: > http://aspn.activestate.com/ASPN/docs/ActivePython/2.2/PyWin32 > /PyIMessage__ModifyRecipients_meth.html > Is there any more comprehensive documentation? I'm afrad not specific to Python - but as usual, contributions welcome! Mark. From fmml at cedval.org Sun Aug 8 14:24:19 2004 From: fmml at cedval.org (fmml@cedval.org) Date: Sun Aug 8 14:31:14 2004 Subject: [python-win32] Writing event to event log... Message-ID: <4143.192.168.41.52.1091967859.squirrel@whoami3.cedval.org> Hi all, I am looking for a way to write to the windows event log, abritrary events. For example, I have written a script that check the presense of certain processes, if one of them is not present, I want to write an event. How can I do that, can someone show me an example... Thanks in advance, Francois From beast at ludens.elte.hu Mon Aug 9 03:39:34 2004 From: beast at ludens.elte.hu (=?ISO-8859-1?B?SW1yZSBBbmRy4XMgUvNiZXJ0?=) Date: Mon Aug 9 04:23:55 2004 Subject: [python-win32] Writing event to event log... In-Reply-To: <4143.192.168.41.52.1091967859.squirrel@whoami3.cedval.org> References: <4143.192.168.41.52.1091967859.squirrel@whoami3.cedval.org> Message-ID: <1212480976.20040809033934@ludens.elte.hu> Hello fmml, The ReportEvent method is a decent one to try, you may find in in win32evtlogutil.py. The servicemanager module contains some simple methods for this as well: LogMsg Write an specific message to the log. LogInfoMsg Write an informational message to the log. LogErrorMsg Write an error message to the log. LogWarningMsg Logs a generic warning message to the event log. Supposed you installed pywin32, you could have a look at these in use in demos under \Lib\site-packages\win32\Demos directory. Especially eventLogDemo.py and service\pipeTestService.py. That's a good starting point. Should you need to define your own categories and event IDs, things will get harder. If still interested, you may find an ongoing discussion on this topic in the following thread here: [Windows service features and Python] Hope this helps, Andr?s Sunday, August 8, 2004, 2:24:19 PM, you wrote: > Hi all, > I am looking for a way to write to the windows event log, abritrary > events. For example, I have written a script that check the presense of > certain processes, if one of them is not present, I want to write an > event. > How can I do that, can someone show me an example... > Thanks in advance, > Francois > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 From beast at ludens.elte.hu Mon Aug 9 04:24:16 2004 From: beast at ludens.elte.hu (=?ISO-8859-15?B?SW1yZSBBbmRy4XMgUvNiZXJ0?=) Date: Mon Aug 9 04:23:56 2004 Subject: [python-win32] Re: Windows service features and Python In-Reply-To: <05bc01c47b4a$9153ef90$0200a8c0@eden> References: <05bc01c47b4a$9153ef90$0200a8c0@eden> Message-ID: <1086682785.20040809042416@ludens.elte.hu> Hello Mark, Friday, August 6, 2004, 2:16:06 AM, you wrote: >> > I'm transforming some Python code into a Windows >> > service. I started with pywin32-202.win32-py2.2.exe, >> > and investigated the demo pipeTestService. This >> > worked fine, so I started converting my code, with >> > no paticular Windows system programming experience. > I'm afraid your problems relate to this lack of Windows experience more than > to Python itself. "Python Programming on Win32" does cover alot of this > stuff in some detail, but general overviews of Windows services would be > useful. I studied PPWin32 and MSDN too. Now I'm a bit brighter... >> > Q1) How can I make my Python service support pause/ >> > continue? Implementing SvcPause() and SvcContinue() >> > seems to be not enough, as I get 'Could not pause >> > ... service on Local Computer. The service did not >> > return an error. ...' dialog despite that the >> > SvcPause() method is executed. After this dialog >> > I found that the service was stopped, ending within >> > SvcDoRun(). Please refer to the attached code. > You need to report a status of PAUSED to the service control manager, in the > same way that RUNNING, START_PENDING, STOP_PENDING and STOPPED are alreay > reported. Indeed, if your pause takes some time, you must periodically > report PAUSE_PENDING, until you actually enter the PAUSED state. My error was that in SvcPause I used to set PAUSE_PENDING and then SetEvent(self.hWaitStop), and sent no periodic reports. Now I set status to PAUSED immediately, and omitted that SetEvent. Similarly, SvcContinue sets status to RUNNING immediately. This works. I also realized that its me who have to manage the periodic reporting in pending states. I haven't tried this yet, but I think I see the picture. > What "pause" means is up to you and your code. One strategy would be to use > an event, much in the same way that "stop" is handled in the samples. >> > Q2) How can I register my own event IDs/categories? I don't >> > know where/how to define my own IDs/cats. The demo seems >> > to support two IDs, servicemanager.PYS_SERVICE_STARTED and >> > servicemanager.PYS_SERVICE_STOPPED. > See PPWin32 - in a nutshell, there are a number of predefined messages, and > unfortunately you need to look in win32\src\PythonServiceMessages.mc in the > source distribution (or via the CVS viewer). These .mc files are compiled > using MSVC6 tools, so there is currently no easy to to define your own. You > are free to use the various "general" ones in PythonServiceMessages.mc. Based on the downloaded source, I created a dll with MSVC, and managed to write events with IDs from that dll. However, for custom categories I had to create the registry keys by hand, because I found no method for this in PyWin32. Now I'm trying to figure out how can I make these IDs visible by symbolic name in my Python source, like pipeTestService uses servicemanager.pyd. I don't want to define these twice, and keep in sync all the time... >> > Q3) How can I add counters to the Python service? Looking at >> > the files perf_install.ini and perf_install.h, this >> > could be possible, but after install I do not see these >> > counters in PerfMon. I do not see the way these files >> > are connected to the service demo source code... Maybe >> > these are already installed as the readme indicates, >> > but where should I look? > Sorry, but I can't recall exactly. perfmon counters are not for the feint > hearted. Again, PPWin32 covers that. PPWin32's examples contains PipeService2.py, and this matches with its ini files, as uses IDs defined there. (PyWin32 source example does not use any counters.) But this only works if the service is installed with the --perfmonini switch. Once installed this way, I can see all those counters in PerfMon. I found this out only by looking at the source, as its help does not mention this switch. It would also be nice if this would support pause and continue functions. Thanks for the help so far. It seems that now I got all the answers, except for one new question: Q4) I can't make my service interactive. I never get a console window despite that I use the --interactive flag, and I can see it set under the logon tab of service properties. What did I get wrong? -- Thanks, Andr?s > Mark. From mhammond at skippinet.com.au Mon Aug 9 14:28:08 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon Aug 9 14:27:54 2004 Subject: [python-win32] Re: Windows service features and Python In-Reply-To: <1086682785.20040809042416@ludens.elte.hu> Message-ID: <017301c47e0c$544bd620$0200a8c0@eden> > Based on the downloaded source, I created a dll with MSVC, and managed > to write events with IDs from that dll. However, for custom categories > I had to create the registry keys by hand, because I found no > method for > this in PyWin32. win32evtlogutil.py may have some helpers you find useful - it can register new event categories. win32service* only provide service specific functions - even though services usually use event logging functions, they are a discrete set of APIs. > Now I'm trying to figure out how can I make these IDs visible by > symbolic name in my Python source, like pipeTestService uses > servicemanager.pyd. I don't want to define these twice, and > keep in sync all the time... Check out "h2py" in the Python "Tools\scripts" directory for one option. > I found this out only by looking at the source, as its help does > not mention this switch. It would also be nice if this would > support pause and continue functions. I agree. I'd welcome specific suggestions as to what needs better docs (and welcome even more the specific text to use ). The --perfmon switches were a (possibly poor) attempt at merging services and the permon API, but although often used by services, just like the event logging functions they are a different set of APIs > Thanks for the help so far. > > It seems that now I got all the answers, except for one new question: > > Q4) I can't make my service interactive. I never get a console > window despite that I use the --interactive flag, and I can > see it set under the logon tab of service properties. What > did I get wrong? I believe that flag controls the service's access to the win32 "desktop" (which is not the same as the Windows Explorer deskop). ie, if your service is "interactive", then you should see modal dialogs and other windows displayed by the service. However, you don't see a console created for the service itself (in the same way as you don't see a console created for other services when you set this flag via the standard Windows services GUI) As I said before, you need to assume your questions are *not* Python related (until you can show otherwise), rather than the other way around :) Mark. From lbates at syscononline.com Mon Aug 9 15:26:26 2004 From: lbates at syscononline.com (Larry Bates) Date: Mon Aug 9 15:26:33 2004 Subject: [python-win32] Writing event to event log... In-Reply-To: <20040809100028.A4FD21E4013@bag.python.org> Message-ID: <001c01c47e14$79c054f0$5d00a8c0@LABWXP> If you don't already have it, pick up a copy of Mark Hammond's excellent Python Programming on Win32. It has good examples of writing to event log along with a bunch of other Windows "specific" information that is difficult to find anywhere else. HTH, Larry Bates Syscon, Inc. ------------------------------------------------------------------ Message: 1 Date: Sun, 8 Aug 2004 08:24:19 -0400 (EDT) From: fmml@cedval.org Subject: [python-win32] Writing event to event log... To: python-win32@python.org Message-ID: <4143.192.168.41.52.1091967859.squirrel@whoami3.cedval.org> Content-Type: text/plain;charset=iso-8859-1 Hi all, I am looking for a way to write to the windows event log, abritrary events. For example, I have written a script that check the presense of certain processes, if one of them is not present, I want to write an event. How can I do that, can someone show me an example... Thanks in advance, Francois ------------------------------ Message: 2 Date: Mon, 9 Aug 2004 03:39:34 +0200 From: Imre Andr?s R?bert Subject: Re: [python-win32] Writing event to event log... To: fmml@cedval.org, python-win32@python.org Message-ID: <1212480976.20040809033934@ludens.elte.hu> Content-Type: text/plain; charset=ISO-8859-1 Hello fmml, The ReportEvent method is a decent one to try, you may find in in win32evtlogutil.py. The servicemanager module contains some simple methods for this as well: LogMsg Write an specific message to the log. LogInfoMsg Write an informational message to the log. LogErrorMsg Write an error message to the log. LogWarningMsg Logs a generic warning message to the event log. Supposed you installed pywin32, you could have a look at these in use in demos under \Lib\site-packages\win32\Demos directory. Especially eventLogDemo.py and service\pipeTestService.py. That's a good starting point. Should you need to define your own categories and event IDs, things will get harder. If still interested, you may find an ongoing discussion on this topic in the following thread here: [Windows service features and Python] Hope this helps, Andras Sunday, August 8, 2004, 2:24:19 PM, you wrote: > Hi all, > I am looking for a way to write to the windows event log, abritrary > events. For example, I have written a script that check the presense of > certain processes, if one of them is not present, I want to write an > event. > How can I do that, can someone show me an example... > Thanks in advance, > Francois > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 ------------------------------ Message: 3 Date: Mon, 9 Aug 2004 04:24:16 +0200 From: Imre Andr?s R?bert Subject: Re[2]: [python-win32] Re: Windows service features and Python To: "Mark Hammond" Cc: python-win32@python.org Message-ID: <1086682785.20040809042416@ludens.elte.hu> Content-Type: text/plain; charset=ISO-8859-15 Hello Mark, Friday, August 6, 2004, 2:16:06 AM, you wrote: >> > I'm transforming some Python code into a Windows >> > service. I started with pywin32-202.win32-py2.2.exe, >> > and investigated the demo pipeTestService. This >> > worked fine, so I started converting my code, with >> > no paticular Windows system programming experience. > I'm afraid your problems relate to this lack of Windows experience more than > to Python itself. "Python Programming on Win32" does cover alot of this > stuff in some detail, but general overviews of Windows services would be > useful. I studied PPWin32 and MSDN too. Now I'm a bit brighter... >> > Q1) How can I make my Python service support pause/ >> > continue? Implementing SvcPause() and SvcContinue() >> > seems to be not enough, as I get 'Could not pause >> > ... service on Local Computer. The service did not >> > return an error. ...' dialog despite that the >> > SvcPause() method is executed. After this dialog >> > I found that the service was stopped, ending within >> > SvcDoRun(). Please refer to the attached code. > You need to report a status of PAUSED to the service control manager, in the > same way that RUNNING, START_PENDING, STOP_PENDING and STOPPED are alreay > reported. Indeed, if your pause takes some time, you must periodically > report PAUSE_PENDING, until you actually enter the PAUSED state. My error was that in SvcPause I used to set PAUSE_PENDING and then SetEvent(self.hWaitStop), and sent no periodic reports. Now I set status to PAUSED immediately, and omitted that SetEvent. Similarly, SvcContinue sets status to RUNNING immediately. This works. I also realized that its me who have to manage the periodic reporting in pending states. I haven't tried this yet, but I think I see the picture. > What "pause" means is up to you and your code. One strategy would be to use > an event, much in the same way that "stop" is handled in the samples. >> > Q2) How can I register my own event IDs/categories? I don't >> > know where/how to define my own IDs/cats. The demo seems >> > to support two IDs, servicemanager.PYS_SERVICE_STARTED and >> > servicemanager.PYS_SERVICE_STOPPED. > See PPWin32 - in a nutshell, there are a number of predefined messages, and > unfortunately you need to look in win32\src\PythonServiceMessages.mc in the > source distribution (or via the CVS viewer). These .mc files are compiled > using MSVC6 tools, so there is currently no easy to to define your own. You > are free to use the various "general" ones in PythonServiceMessages.mc. Based on the downloaded source, I created a dll with MSVC, and managed to write events with IDs from that dll. However, for custom categories I had to create the registry keys by hand, because I found no method for this in PyWin32. Now I'm trying to figure out how can I make these IDs visible by symbolic name in my Python source, like pipeTestService uses servicemanager.pyd. I don't want to define these twice, and keep in sync all the time... >> > Q3) How can I add counters to the Python service? Looking at >> > the files perf_install.ini and perf_install.h, this >> > could be possible, but after install I do not see these >> > counters in PerfMon. I do not see the way these files >> > are connected to the service demo source code... Maybe >> > these are already installed as the readme indicates, >> > but where should I look? > Sorry, but I can't recall exactly. perfmon counters are not for the feint > hearted. Again, PPWin32 covers that. PPWin32's examples contains PipeService2.py, and this matches with its ini files, as uses IDs defined there. (PyWin32 source example does not use any counters.) But this only works if the service is installed with the --perfmonini switch. Once installed this way, I can see all those counters in PerfMon. I found this out only by looking at the source, as its help does not mention this switch. It would also be nice if this would support pause and continue functions. Thanks for the help so far. It seems that now I got all the answers, except for one new question: Q4) I can't make my service interactive. I never get a console window despite that I use the --interactive flag, and I can see it set under the logon tab of service properties. What did I get wrong? -- Thanks, Andras > Mark. ------------------------------ _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 End of Python-win32 Digest, Vol 17, Issue 8 ******************************************* From fmml at cedval.org Mon Aug 9 21:33:03 2004 From: fmml at cedval.org (fmml@cedval.org) Date: Mon Aug 9 21:40:06 2004 Subject: [python-win32] Writing event to event log... In-Reply-To: <1212480976.20040809033934@ludens.elte.hu> References: <4143.192.168.41.52.1091967859.squirrel@whoami3.cedval.org> <1212480976.20040809033934@ludens.elte.hu> Message-ID: <58569.206.47.191.243.1092079983.squirrel@whoami3.cedval.org> Hi Andr?s, Thanks for directing me to the demo directory, found what I needed by using ReportEvent modules. Even if I get "Event ID ( 1 ) in Source ( Application ) cannot be found" I can still post the info I needed. Would be nice if there were some kind of generic message ID that I could make use of, but for now this does the job. Thanks a million, Francois > Hello fmml, > > The ReportEvent method is a decent one to try, > you may find in in win32evtlogutil.py. > > The servicemanager module contains some simple > methods for this as well: > > LogMsg > Write an specific message to the log. > > LogInfoMsg > Write an informational message to the log. > > LogErrorMsg > Write an error message to the log. > > LogWarningMsg > Logs a generic warning message to the event log. > > > Supposed you installed pywin32, you could have a look at > these in use in demos under \Lib\site-packages\win32\Demos > directory. Especially eventLogDemo.py and service\pipeTestService.py. > > That's a good starting point. Should you need to define your own > categories and event IDs, things will get harder. If still interested, > you may find an ongoing discussion on this topic in the following thread > here: [Windows service features and Python] > > > Hope this helps, > Andr?s > > > Sunday, August 8, 2004, 2:24:19 PM, you wrote: > >> Hi all, > >> I am looking for a way to write to the windows event log, abritrary >> events. For example, I have written a script that check the presense of >> certain processes, if one of them is not present, I want to write an >> event. > >> How can I do that, can someone show me an example... > >> Thanks in advance, > >> Francois >> _______________________________________________ >> Python-win32 mailing list >> Python-win32@python.org >> http://mail.python.org/mailman/listinfo/python-win32 > > > > From s_herman at web.de Mon Aug 9 22:28:45 2004 From: s_herman at web.de (Sandra Herman) Date: Mon Aug 9 22:28:48 2004 Subject: [python-win32] com_error when creating excel sheet Message-ID: <25381873@web.de> Hi, The following script results in the error listed below: import win32com.client from win32com.client import Dispatch x1App = Dispatch("Excel.Application") x1App.Visible=1 x1App.Workbooks.Add() x1Sheet=x1App.Sheets(1) x1Sheet.Name="Sheet 1" x2Sheet = x1App.Sheets(2) x2Sheet.Name = "Sheeet 2" x3Sheet = x1App.Sheets(3) x3Sheet.Name="Sheet 3" Traceback... line 8, in ? x2Sheet = x1App.Sheets(2) ... com_error: (-2147352567, 'Exception occurred.', (0. None, None, None, 0, -2147352565), None) Running Python 2.3.3 on XP. Excel 2002 installed. Does anybody know what the solution to the problem is? Thanks! ____________________________________________________ Aufnehmen, abschicken, nah sein - So einfach ist WEB.DE Video-Mail: http://freemail.web.de/?mc=021200 From beast at ludens.elte.hu Tue Aug 10 12:46:45 2004 From: beast at ludens.elte.hu (=?ISO-8859-1?B?SW1yZSBBbmRy4XMgUvNiZXJ0?=) Date: Tue Aug 10 12:45:38 2004 Subject: [python-win32] Writing event to event log... In-Reply-To: <58569.206.47.191.243.1092079983.squirrel@whoami3.cedval.org> References: <4143.192.168.41.52.1091967859.squirrel@whoami3.cedval.org> <1212480976.20040809033934@ludens.elte.hu> <58569.206.47.191.243.1092079983.squirrel@whoami3.cedval.org> Message-ID: <1481817987.20040810124645@ludens.elte.hu> Hello Francois, In fact, there are such generic IDs available in e.g. win32evtlog.pyd, servicemanager.pyd. Windows displays text for event IDs from a message file specified under the following reg key, based on the application name: HKLM\SYSTEM\CurrentControlSet\Services\Eventlog\ The EventMessageFile keys specify the dll or exe that will be used to find constant text identified by the ID. In this way the event log just contain references instead of full text, which makes it smaller. I suggest that your app installer should call win32evtlogutil.AddSourceToRegistry (as this needs to be done only once) while the uninstaller should call RemoveSourceFromRegistry. If you specify only the app name, win32evtlog.pyd will be used to resolve IDs for that app, and in here these general IDs are from 1 to 9. There is no constant text for them, all of these are specified as %1, so will just use the strings passed to ReportEvent, thus no space will be saved. (Each time the full text will be appended to the log, not just a reference.) If you'd like to save space, you should create your own dll for this. Regards, Andr?s Monday, August 9, 2004, 9:33:03 PM, you wrote: > Hi Andr?s, > Thanks for directing me to the demo directory, found what I needed by > using ReportEvent modules. Even if I get "Event ID ( 1 ) in Source ( > Application ) cannot be found" I can still post the info I needed. > Would be nice if there were some kind of generic message ID that I could > make use of, but for now this does the job. > Thanks a million, > Francois From graham.bloice at trihedral.com Tue Aug 10 16:24:45 2004 From: graham.bloice at trihedral.com (Graham Bloice) Date: Tue Aug 10 16:24:56 2004 Subject: [python-win32] com_error when creating excel sheet In-Reply-To: <25381873@web.de> Message-ID: > Hi, > > The following script results in the error listed below: > > import win32com.client > from win32com.client import Dispatch > x1App = Dispatch("Excel.Application") > x1App.Visible=1 > x1App.Workbooks.Add() > x1Sheet=x1App.Sheets(1) > x1Sheet.Name="Sheet 1" > x2Sheet = x1App.Sheets(2) > x2Sheet.Name = "Sheeet 2" > x3Sheet = x1App.Sheets(3) > x3Sheet.Name="Sheet 3" > > Traceback... line 8, in ? x2Sheet = x1App.Sheets(2) > ... > com_error: (-2147352567, 'Exception occurred.', (0. None, None, > None, 0, -2147352565), None) > > Running Python 2.3.3 on XP. Excel 2002 installed. > > Does anybody know what the solution to the problem is? > Might it be that your copy of excel is configured so that there is only 1 sheet in a new workbook. See Tools | Options | General | Sheets in new workbook. Regards, Graham Bloice From timr at probo.com Tue Aug 10 18:34:22 2004 From: timr at probo.com (Tim Roberts) Date: Tue Aug 10 18:34:26 2004 Subject: [python-win32] com_error when creating excel sheet In-Reply-To: <20040810100055.6A2B11E400E@bag.python.org> References: <20040810100055.6A2B11E400E@bag.python.org> Message-ID: <4118F90E.3060602@probo.com> On Mon, 09 Aug 2004 22:28:45 +0200, "Sandra Herman" wrote: >The following script results in the error listed below: > >import win32com.client >from win32com.client import Dispatch >x1App = Dispatch("Excel.Application") >x1App.Visible=1 >x1App.Workbooks.Add() >x1Sheet=x1App.Sheets(1) >x1Sheet.Name="Sheet 1" >x2Sheet = x1App.Sheets(2) >x2Sheet.Name = "Sheeet 2" >x3Sheet = x1App.Sheets(3) >x3Sheet.Name="Sheet 3" > >Traceback... line 8, in ? x2Sheet = x1App.Sheets(2) >... >com_error: (-2147352567, 'Exception occurred.', (0. None, None, None, 0, -2147352565), None) > >Running Python 2.3.3 on XP. Excel 2002 installed. > >Does anybody know what the solution to the problem is? > > Well, I just cut-and-pasted your exact script here, and it worked perfectly with Python 2.3 and Excel 2003. Based on the error message, is it possible your default workbook does not start out with three sheets? Have you tried, for example, something like this: ... x1App.Sheets.Add() x2Sheet = x1App.Sheets(2) -- - Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc. From paul at alanweberassociates.com Tue Aug 10 21:01:44 2004 From: paul at alanweberassociates.com (paul@alanweberassociates.com) Date: Tue Aug 10 20:58:25 2004 Subject: [python-win32] Access COM object thru other than default interface Message-ID: I am working with a COM object that has the following custom COM class, with two coclass_interfaces (names have been changed to protect the proprietary): class MainObject(CoClassBaseClass): # A CoClass # Brand X MainObject Class CLSID = IID('{DEADBEEF-FFFF-1111-2222-000000000000}') coclass_sources = [ ] coclass_interfaces = [ IAAAObject, IBBBObject, ] default_interface = IAAAObject I am able to create a MainObject using myobj = win32com.client.Dispatch("BrandX.MainObject") and this gives me a myobj that repr's as: and on myobj I can do invoke all of the IAAAObject methods. Now I need to do some IBBBObject-type work. How do I get to the IBBBObject methods? I've tried just invoking them, but I get the following error: Traceback (most recent call last): File "", line 1, in ? File "C:\Python23\Lib\site-packages\win32com\client\__init__.py", line 454, in __getattr__ raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) AttributeError: '' object has no attribute 'IBBBObjectMethod' (I've looked thru Python Programming on Win32, but I've not seen anything that looks relevant.) Thanks for the help, even if you can just RTFM me to an existing doc resource. -- Paul From jens.jorgensen at tallan.com Tue Aug 10 21:44:26 2004 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Tue Aug 10 21:44:39 2004 Subject: [python-win32] Access COM object thru other than default interface In-Reply-To: References: Message-ID: <4119259A.9060105@tallan.com> It's been a while since I've done exactly this but I think what you want to do is create an IBBBObject passing the object reference to it as a parameter. I think you'll need to be using the makepy'd module for this but I notice you are creating the object through Dispatch rather than the module. Are you not including a makepy'd module? paul@alanweberassociates.com wrote: >I am working with a COM object that has the following custom COM class, with two coclass_interfaces (names have been changed to protect the proprietary): > >class MainObject(CoClassBaseClass): # A CoClass > # Brand X MainObject Class > CLSID = IID('{DEADBEEF-FFFF-1111-2222-000000000000}') > coclass_sources = [ > ] > coclass_interfaces = [ > IAAAObject, > IBBBObject, > ] > default_interface = IAAAObject > >I am able to create a MainObject using > myobj = win32com.client.Dispatch("BrandX.MainObject") >and this gives me a myobj that repr's as: > > >and on myobj I can do invoke all of the IAAAObject methods. > >Now I need to do some IBBBObject-type work. How do I get to the IBBBObject methods? I've tried just invoking them, but I get the following error: > >Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python23\Lib\site-packages\win32com\client\__init__.py", line 454, in __getattr__ > raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) >AttributeError: '' object has no attribute 'IBBBObjectMethod' > >(I've looked thru Python Programming on Win32, but I've not seen anything that looks relevant.) > >Thanks for the help, even if you can just RTFM me to an existing doc resource. > >-- Paul > > > >------------------------------------------------------------------------ > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 2861 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.python.org/pipermail/python-win32/attachments/20040810/765c328a/smime.bin From mhammond at skippinet.com.au Tue Aug 10 23:53:56 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue Aug 10 23:53:46 2004 Subject: [python-win32] Access COM object thru other than default interface In-Reply-To: <4119259A.9060105@tallan.com> Message-ID: <0a2c01c47f24$89193fa0$0200a8c0@eden> > It's been a while since I've done exactly this but I think > what you want > to do is create an IBBBObject passing the object reference to it as a > parameter. I think you'll need to be using the makepy'd > module for this > but I notice you are creating the object through Dispatch rather than > the module. Are you not including a makepy'd module? I has been a while since I was last asked this too :) Apart from Jens' suggestion, y9ou can also try an explicit QI for the second interface. I believe that also works (via the exact same mechanism that Jens' idea does) Mark. From craig at coot.net Wed Aug 11 01:16:46 2004 From: craig at coot.net (Craig H. Anderson) Date: Wed Aug 11 01:16:49 2004 Subject: [python-win32] Marking a Python COM server safe for Internet Explorer Message-ID: Help. I've seen this subject in the archives, but I don't understand any solution for this. Implementing IObjectSafety sounds groovy, but I need help with how to do this. Mark Hammond wrote, in part: > [T]he win32com.axscript.axscript module supports IObjectSafety. > Once you import this module any Python COM object can implement > this interface like any other. We run IIS 5 for an internal site. I want to install Python Com servers that the Vbscript developers can use. Thanks. From paul at alanweberassociates.com Wed Aug 11 07:53:59 2004 From: paul at alanweberassociates.com (paul@alanweberassociates.com) Date: Wed Aug 11 07:50:35 2004 Subject: [python-win32] Access COM object thru other than default interface In-Reply-To: <4119259A.9060105@tallan.com> Message-ID: Thanks, this is just what worked. (Yes, Jens, I am using makepy'ed modules, but I can't just create an IBBBObject() - the only thing that works is to first create a Dispatch, and then use that to construct an IBBBObject.) myobj = win32com.client.Dispatch("BrandX.MainObject") objWith2ndInterface = BrandX.IBBBObject( myobj ) objWith2ndInterface.IBBBObjectMethod() -- Paul -----Original Message----- From: Jens B. Jorgensen [mailto:jens.jorgensen@tallan.com] Sent: Tuesday, August 10, 2004 2:44 PM To: paul@alanweberassociates.com Cc: python-win32@python.org Subject: Re: [python-win32] Access COM object thru other than default interface It's been a while since I've done exactly this but I think what you want to do is create an IBBBObject passing the object reference to it as a parameter. I think you'll need to be using the makepy'd module for this but I notice you are creating the object through Dispatch rather than the module. Are you not including a makepy'd module? paul@alanweberassociates.com wrote: >I am working with a COM object that has the following custom COM class, with two coclass_interfaces (names have been changed to protect the proprietary): > >class MainObject(CoClassBaseClass): # A CoClass > # Brand X MainObject Class > CLSID = IID('{DEADBEEF-FFFF-1111-2222-000000000000}') > coclass_sources = [ > ] > coclass_interfaces = [ > IAAAObject, > IBBBObject, > ] > default_interface = IAAAObject > >I am able to create a MainObject using > myobj = win32com.client.Dispatch("BrandX.MainObject") >and this gives me a myobj that repr's as: > > >and on myobj I can do invoke all of the IAAAObject methods. > >Now I need to do some IBBBObject-type work. How do I get to the IBBBObject methods? I've tried just invoking them, but I get the following error: > >Traceback (most recent call last): > File "", line 1, in ? > File "C:\Python23\Lib\site-packages\win32com\client\__init__.py", line 454, in __getattr__ > raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) >AttributeError: '' object has no attribute 'IBBBObjectMethod' > >(I've looked thru Python Programming on Win32, but I've not seen anything that looks relevant.) > >Thanks for the help, even if you can just RTFM me to an existing doc resource. > >-- Paul > > > >------------------------------------------------------------------------ > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" From bartek.b at eranet.pl Wed Aug 11 09:13:05 2004 From: bartek.b at eranet.pl (Bartek Bargiel) Date: Wed Aug 11 09:13:15 2004 Subject: [python-win32] problem with detecting when another app finished Message-ID: <1569159670.20040811091305@eranet.pl> Hi! I've got a problem with detection of the moment when the chosen application was closed. There are some apps whose .exe files are only 'constructors' for the main app (such as Microsoft Word). Is there a way to 'catch'&spy them? My solutions which failed: 1. Starting the app with help of win32process - it doesn't work - reasons mentioned in first paragraph above 2. Acquiring a lock on the file being edited in a loop; if it's possible, it means the app has already finished. Well, it works often but not ALWAYS. It may happen (moreover: it DOES HAPPEN) that my application acquires a lock before MS Word which is then unable to open the file. 3. Taking a look at app's windows' titles. I thought that was good. But from to time my app crashed and I couldn't find out why. :-( Any suggestions, any ideas? -- Bartek Bargiel From mhammond at skippinet.com.au Wed Aug 11 09:14:24 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed Aug 11 09:14:10 2004 Subject: [python-win32] Marking a Python COM server safe for InternetExplorer In-Reply-To: Message-ID: <005001c47f72$d53f20e0$0200a8c0@eden> > Help. > > I've seen this subject in the archives, but I > don't understand any solution for this. > > Implementing IObjectSafety sounds groovy, but I > need help with how to do this. > > Mark Hammond wrote, in part: > > [T]he win32com.axscript.axscript module supports IObjectSafety. > > Once you import this module any Python COM object can implement > > this interface like any other. Start by creating a standard COM object, but register it for debugging. Test it out. If one of the last messages you see relates to a failed QI for IID_IObjectSafety, then you can implement this interface just like you would any other non-Dispatch based interface - ie, add it to "_com_interfaces_", add the methods to _public_methods_, and implement them! The debug output should then show the QI succeed, then the methods being called. > We run IIS 5 for an internal site. I want to > install Python Com servers that the Vbscript > developers can use. If they are calling it from ASP, then there should be no need to implement this interface. Any COM object should work. AFAIK, there is only an issue when trying to run it on the client. Mark. From craig at coot.net Wed Aug 11 17:25:40 2004 From: craig at coot.net (Craig H. Anderson) Date: Wed Aug 11 17:25:55 2004 Subject: [python-win32] Marking a Python COM server safe for InternetExplorer Message-ID: Mark is correct. Server side ASP vbscript can use the Python COM object just fine. After a good night's sleep I tried another test and everything works fine. I'll tack my test code on the end. > Mark Hammond wrote: > If they are calling it from ASP, then there should be no need to implement > this interface. Any COM object should work. AFAIK, there is only an issue > when trying to run it on the client. ######################## ComTest.py class ComTestPy: _reg_progid_ = "Gcspython.ComTestPy" # use "print pythoncom.CreateGuid()" _reg_clsid_ = "{723745E2-B43F-46F7-A799-5EA990D1893E}" _public_methods_ = ["Echo","GetList"] _public_attrs_ = ["Version"] _readonly_attrs_ = ["Version"] def __init__(self): print 'ComTestPy.__init__' self.Version = "MyVersion" def Echo(self,msg): return 'Echo: %s' % str(msg) def GetList(self,listName): retList = [] retList.append('You requested list: %s' % listName) retList.append('1') retList.append('2') retList.append('3') return retList # Registration support. if __name__=='__main__': import win32com.server.register win32com.server.register.UseCommandLine(ComTestPy) ######################## TestPythonCom.asp Test of Python Com <% Dim comObj,rslt,echo,listRslt Set comObj = CreateObject("Gcspython.ComTestPy") rslt = comObj.Version echo = comObj.Echo("From Asp") listRslt = comObj.GetList("Active List") %> ComObj Version is <%=rslt%>
ComObj echo is <%=echo%>
ComObj listRslt is <%For i = LBound(listRslt) to UBound(listRslt)%> <%=listRslt(i)%> , <%Next%>
######################## Output is ComObj Version is MyVersion ComObj echo is Echo: From Asp ComObj listRslt is You requested list: Active List , 1 , 2 , 3 , From gustabares at verizon.net Wed Aug 11 22:12:22 2004 From: gustabares at verizon.net (Gus Tabares) Date: Wed Aug 11 22:12:37 2004 Subject: [python-win32] Automated Install Message-ID: <004e01c47fdf$868c6940$0200a8c0@blackbetty> Hello all, It looks as though you will be able to automate the install for Python 2.4 via the msiexec's command line options. Are there any plans for this capability for the win32 extensions or is there already a way? Thanks, Gus From mhammond at skippinet.com.au Wed Aug 11 23:58:44 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Wed Aug 11 23:58:24 2004 Subject: [python-win32] Automated Install In-Reply-To: <004e01c47fdf$868c6940$0200a8c0@blackbetty> Message-ID: <02ba01c47fee$5fb1d350$0200a8c0@eden> > It looks as though you will be able to automate the install for Python > 2.4 via the msiexec's command line options. Are there any > plans for this > capability for the win32 extensions or is there already a way? No plans, but assistance gratefully received. Mark From timothy at torpedogames.com Thu Aug 12 07:34:24 2004 From: timothy at torpedogames.com (Timothy Toroni) Date: Thu Aug 12 07:28:10 2004 Subject: [python-win32] COM Server and TypeLibraries. obj._oleobj_.GetTypeInfoCount() = 0? Message-ID: <20040812003234.U32786-100000@guadalcanal.torpedogames.com> Hello All, I am working on making a python COM server work with Labview which requires the type libraries for the IDispatch interface... Granted... at the moment I'm not even able to have Makepy run on my objects. It blows up as shown below. I'm guessing my problem lies in that when I create an object, the object.GetTypeInfoCount() returns 0, then object.GetTypeInfo() just blows up. I tried making all this work with the pippo example. My com server is modeled after it. ** Pippo not returning a PyITypeInfo object. >>> o = Dispatch('Python.Test.Pippo') >>> o._oleobj_.GetTypeInfoCount() 0 >>> o._oleobj_.GetTypeInfo() Traceback (most recent call last): File "", line 1, in -toplevel- o._oleobj_.GetTypeInfo() com_error: (-2147352567, 'Exception occurred.', None, None) >>> ** Now because the above fails - the below also fails, which should call the makepy thing which creates the python class with all the functions locally defined.... I actually found the above "issue" from looking at line 543 of gencache.py. >>> oo = EnsureDispatch('Python.Test.Pippo') Traceback (most recent call last): File "", line 1, in -toplevel- oo = EnsureDispatch('Python.Test.Pippo') File "C:\Python23\Lib\site-packages\win32com\client\gencache.py", line 543, in EnsureDispatch raise TypeError, "This COM object can not automate the makepy process - please run makepy manually for this object" TypeError: This COM object can not automate the makepy process - please run makepy manually for this object >>> ** Now if I take another working application... (for which makepy works too) >>> oo = Dispatch('Excel.Application') >>> oo._oleobj_.GetTypeInfoCount() 1 >>> oo._oleobj_.GetTypeInfo() >>> ** I get a PyITypeInfo object back. So what is the deal. What is not in the Pippo COM server which causes this failure? I've registered the type libraries.. in fact below I've attached the .IDL file that oleview dumps. I'm rather stumped at this point. Any advice is much apprieached. I realize that Python COM servers have come up in the past on this list which use type libraries and I've gone over the messages... but I must be missing something. It seems like the object is not associating the type library with the application? 73, Timothy // Generated .IDL file (by the OLE/COM Object Viewer) // // typelib filename: pippo.tlb [ uuid(41059C57-975F-4B36-8FF3-C5117426647A), version(1.0), helpstring("TestServer 1.0 Type Library"), custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 100663657), custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1082621398), custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, Created by MIDL version 6.00.0361 at Thu Apr 22 18:09:57 2004 ) ] library TESTSERVERLib { // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} importlib("stdole2.tlb"); // Forward declare all types defined in this typelib interface ITestServerApp; interface IPippo; [ uuid(49E44E89-5A72-4456-B1D5-68268A19E798), helpstring("TestServerApp Class") ] coclass TestServerApp { [default] interface ITestServerApp; }; [ odl, uuid(50086EE8-F535-464B-806E-365ADBB727CF), helpstring("ITestServerApp Interface"), dual, oleautomation ] interface ITestServerApp : IDispatch { [id(0x00000001), helpstring("method Test1")] HRESULT Test1([out, retval] ITestServerApp** pVal); [id(0x00000002), helpstring("method Test2")] HRESULT Test2([out, retval] VARIANT* pVar); [id(0x00000003), propget, helpstring("property MyProp1")] HRESULT MyProp1([out, retval] long* pVal); }; [ uuid(E19C0A68-F61C-450B-A974-A7BA6957829C), helpstring("Pippo Class") ] coclass Pippo { [default] interface IPippo; }; [ odl, uuid(F1A3CC2E-4B2A-4A81-992D-67862076949B), helpstring("IPippo Interface"), dual, oleautomation ] interface IPippo : IDispatch { [id(0x00000001), helpstring("method Method1")] HRESULT Method1([out, retval] IPippo** val); [id(0x00000002), propget, helpstring("property MyProp1")] HRESULT MyProp1([out, retval] long* pVal); }; }; -- Timothy Toroni, AB9GC, Sgt. York, timothy@torpedogames.com http://www.torpedogames.com From mhammond at skippinet.com.au Thu Aug 12 08:53:14 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu Aug 12 08:53:02 2004 Subject: [python-win32] COM Server and TypeLibraries.obj._oleobj_.GetTypeInfoCount() = 0? In-Reply-To: <20040812003234.U32786-100000@guadalcanal.torpedogames.com> Message-ID: <000701c48039$0b125ae0$0200a8c0@eden> > I am working on making a python COM server work with Labview which > requires the type libraries for the IDispatch interface... > Granted... at > the moment I'm not even able to have Makepy run on my > objects. It blows > up as shown below. > ** I get a PyITypeInfo object back. So what is the deal. > What is not in > the Pippo COM server which causes this failure? I've > registered the type > libraries.. in fact below I've attached the .IDL file that > oleview dumps. > > I'm rather stumped at this point. Any advice is much apprieached. I > realize that Python COM servers have come up in the past on this list > which use type libraries and I've gone over the messages... > but I must be > missing something. > > It seems like the object is not associating the type library with the > application? You are correct - the typelib is not associated. Mainly as I just didn't think of it at the time :) I'll attach an update in private mail that at least makes things work for pippo. Mark. From timothy at torpedogames.com Fri Aug 13 02:19:32 2004 From: timothy at torpedogames.com (Timothy Toroni) Date: Fri Aug 13 02:36:38 2004 Subject: [python-win32] COM Server and TypeLibraries.obj._oleobj_.GetTypeInfoCount() = 0? In-Reply-To: <000701c48039$0b125ae0$0200a8c0@eden> Message-ID: <20040812185100.D497-100000@guadalcanal.torpedogames.com> Hello Mark, Thanks much for your help. The patches worked, except.. My current situation is that I'm able to get the makepy utility to run and generate the .py files in the gencache directory -- I'm still however unable to get the COM server to work under labview. The problem I'm having is that upon opening the device for usage (I suppose a CreateObject equiviliant) LabView returns the following error: -=-=-=- Error -2147221164 occurred at Automation Open This error code is undefined. No one has provided a description for this code, or you might have wired a number that is not an error code to the error code input. -=-=-=- It appears that the above error code is REGDB_E_CLASSNOTREG = 0x80040154. (From net references) So I'm not sure why LabView thinks the class is not registered... I get this error for both my testcom server (compiled /w py2exe) and Pippo (.py only) from within labview. Is it possible that there is something else not fully implemented that's causing an error? In searching LabView's webpage for help on this error I find a few cases of this error. But no real answers except for how to register a .tlb. Which I've done... Otherwise how would I be able to select my testcom or Pippo from the COM dropdown list in Labview?! http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RNAME=ViewQuestion&HOID=506500000008000000AD4A0000&ECategory=LabVIEW.LabVIEW+General I wonder if the problem has to do with something in the .idl file? I have another VB app with ActiveX/COM interface to labview that works and I'll be looking over it's idl file for differences... some include: appobject keyword in the [ ] section above 'coclass Pippo' hidden and nonextensible keywords in the [ ] section above 'interface IPippo : IDispatch' There are other custom( -- ) declarations at other points in the working .idl file. Is there a tool I can use to monitor API calls to see what is failing? Actually I found APISpy32 at http://www.internals.com/utilities_main.htm but I've not got around to figuring out which API calls I need to look for and what files they are located in. I also don't have MSVC for Spy++(?). Any advice on approaches to solving this problem or within what realm they exist -- me, labview, idl/tlb, pythoncom is most welcome! 73, Timothy -- Timothy Toroni, AB9GC, Sgt. York, timothy@torpedogames.com http://www.torpedogames.com On Thu, 12 Aug 2004, Mark Hammond wrote: > > I am working on making a python COM server work with Labview which > > requires the type libraries for the IDispatch interface... > > Granted... at > > the moment I'm not even able to have Makepy run on my > > objects. It blows > > up as shown below. > > > ** I get a PyITypeInfo object back. So what is the deal. > > What is not in > > the Pippo COM server which causes this failure? I've > > registered the type > > libraries.. in fact below I've attached the .IDL file that > > oleview dumps. > > > > I'm rather stumped at this point. Any advice is much apprieached. I > > realize that Python COM servers have come up in the past on this list > > which use type libraries and I've gone over the messages... > > but I must be > > missing something. > > > > It seems like the object is not associating the type library with the > > application? > > You are correct - the typelib is not associated. Mainly as I just didn't > think of it at the time :) I'll attach an update in private mail that at > least makes things work for pippo. > > Mark. > > From mhammond at skippinet.com.au Fri Aug 13 05:41:47 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri Aug 13 05:41:39 2004 Subject: [python-win32] COM Server and TypeLibraries.obj._oleobj_.GetTypeInfoCount() = 0? In-Reply-To: <20040812185100.D497-100000@guadalcanal.torpedogames.com> Message-ID: <02f301c480e7$764a2d70$0200a8c0@eden> > My current situation is that I'm able to get the makepy > utility to run and > generate the .py files in the gencache directory -- I'm still however > unable to get the COM server to work under labview. The problem I'm > having is that upon opening the device for usage (I suppose a > CreateObject > equiviliant) LabView returns the following error: > > > -=-=-=- > Error -2147221164 occurred at Automation Open > > This error code is undefined. No one has provided a > description for this > code, or you might have wired a number that is not an error > code to the > error code input. > -=-=-=- > > It appears that the above error code is REGDB_E_CLASSNOTREG = > 0x80040154. > (From net references) > > So I'm not sure why LabView thinks the class is not > registered... I get > this error for both my testcom server (compiled /w py2exe) > and Pippo (.py > only) from within labview. That specific error code will be returned by the Pythoncom framework (and py2exe) if creating an instance of the class failed. You should be able to write a trivial VBScript script that uses CreateObject() to instantiate your object, and that may give some clues. If you run it from 'cscript.exe', you may even see error messages printed to the console. Are you sure you need to use py2exe? It may be possible that labview will still pick it up when running from source - a .dll is still named in the registry as exposing the object, and I see no reason it would work under py2exe, but *not* from source. If you can get it running from source, just register it with "--debug". It may work - in which case we need to track down a py2exe specific issue. If it fails, you should see an exception in the Pythonwin trace collector. Mark From ewang at esri.com Fri Aug 13 22:55:33 2004 From: ewang at esri.com (Enzhou Wang) Date: Fri Aug 13 22:55:37 2004 Subject: [python-win32] Release public header and lib files with pywin32 release? Message-ID: Hello, Thanks Mark for the excellent work on PythonCOM. I'm interested in using Python with ArcGIS, which has a huge collection of COM objects. Most of them do not implement Idispatch. I've experimented implementing python extensions the same way as the MAPI/Shell examples in pywin32 com source code. To do this, you need to include a few header files like "PythonCom.h" and link to pythoncom.lib and pywintypes.lib. I cannot seem to find an easy way to get the lib files and go ahead to build pywin32 locally. With a little struggle, I actually can use most of the Iunknown based com objects, and can even generate pure python wrappers to hide the details of CreateInstance, QueryInterface, etc.. The whole thing works really well, all because of PythonCOM. But when I try to generate python extensions for a particular win32all version (build 151), I cannot seem to get the correct source code for b151 (not all source files are tagged b151). I want build 151 because ArcGIS version 9 comes with python 2.1 and win32all 151 (there's some functionality using python). When I tried using some early version whenever b151 is missing, the python extensions built does not work with the *released* win32all 151... If Mark can release the public header and lib files with each pywin32 release, it will really help anyone trying to use Python to work with COM objects not implementing Idispatch. It can be put in pywin32 install just as Python installs its header and lib files, or a separate install for those interested. It will make extending PythonCOM so much easier. Best regards, Enzhou -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040813/d16fedd4/attachment.html From flory at fdu.edu Sun Aug 15 05:51:45 2004 From: flory at fdu.edu (David Flory) Date: Sun Aug 15 05:51:58 2004 Subject: [python-win32] pyRegistry AttributeError Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I just downloaded pyRegistry (the 2004-08-11 binary update, v1.0.3) and am having a problem. My test code is: =============== import pyRegistry baseKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" basereg = pyRegistry.open(baseKey) print basereg.getValueNames() print basereg.getKeyNames() ============ Which returns ================= D:\bin>test_pyRegistry ('Drop Shadow', 'Flat Menus', 'SetupVersion', 'InstallTheme', 'InstallVisualStyle') Traceback (most recent call last): File "D:\bin\test_pyRegistry.py", line 5, in ? print basereg.getKeyNames() AttributeError: getKeyNames ============ It appears as though open() and getValueNames() both work fine while getKeyNames throws an error. I am running Python 2.3.4 on a WinXP machine. Any suggestions? In advance, many thanks for any help. - -------------------------------------------------- David Flory, Ph.D. Professor of Physics Fairleigh Dickinson University 1000 River Road, Mail Stop T-Bec2-03 Teaneck, New Jersey 07666 Office: Becton Hall Room 111 Voice: 201-692-7064 Email: flory@fdu.edu (regular email) Pager: flory@vText.com (subj + text < 150 char) http://TheFlorys.org/David.Flory/ <== My PGP key is here -----BEGIN PGP SIGNATURE----- Version: PGP 8.1 Comment: 201-692-7064 iQA/AwUBQR7d0Fe2/rcN3lp8EQJv1QCgtSQJFilwnonfp4qrgeL3TL5fmIgAnj9E Mg8Y4PpRujvkFz/q0EciXiXs =hXJw -----END PGP SIGNATURE----- From jody.burgess at sewardconsulting.com Sun Aug 15 22:18:48 2004 From: jody.burgess at sewardconsulting.com (Jody Burgess) Date: Sun Aug 15 22:16:40 2004 Subject: [python-win32] RE: Python-win32 Digest, Vol 17, Issue 15 In-Reply-To: <20040815100012.6B0291E401F@bag.python.org> Message-ID: Can someone please tell me why I would receive the following error in the interactive window from this command? Command: hWD = os.system('lpr -S 192.168.168.9 -P queue- myqueue ' + tmpfile) Error: [Dbg]>>> Traceback (most recent call last): File "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\dbgcommands.py", line 73, in OnGo self._DoOrStart("do_set_continue", scriptutils.RS_DEBUGGER_GO) File "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\dbgcommands.py", line 57, in _DoOrStart method() File "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 636, in do_set_continue if self.GUIAboutToRun(): File "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 787, in GUIAboutToRun if not self.StopDebuggerPump(): File "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 485, in StopDebuggerPump if self.GUIAboutToFinishInteract(): File "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\debugger.py", line 836, in GUIAboutToFinishInteract self.oldForeground.EnableWindow(1) win32ui: The window handle does not specify a valid window win32ui: Error in Command Message handler for command ID 15022, Code 0 Is there anything I can do to prevent the error from occuring? I have win32ui imported correctly. Jody Burgess ISP Systems Analyst Seward Consulting Ltd. 780.702.5103 jody.burgess@sewardconsulting.com -----Original Message----- From: python-win32-bounces@python.org [mailto:python-win32-bounces@python.org]On Behalf Of python-win32-request@python.org Sent: Sunday, August 15, 2004 4:00 AM To: python-win32@python.org Subject: Python-win32 Digest, Vol 17, Issue 15 Send Python-win32 mailing list submissions to python-win32@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-win32 or, via email, send a message with subject or body 'help' to python-win32-request@python.org You can reach the person managing the list at python-win32-owner@python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-win32 digest..." Today's Topics: 1. pyRegistry AttributeError (David Flory) ---------------------------------------------------------------------- Message: 1 Date: Sat, 14 Aug 2004 23:51:45 -0400 From: "David Flory" Subject: [python-win32] pyRegistry AttributeError To: Message-ID: Content-Type: text/plain; charset="us-ascii" -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I just downloaded pyRegistry (the 2004-08-11 binary update, v1.0.3) and am having a problem. My test code is: =============== import pyRegistry baseKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" basereg = pyRegistry.open(baseKey) print basereg.getValueNames() print basereg.getKeyNames() ============ Which returns ================= D:\bin>test_pyRegistry ('Drop Shadow', 'Flat Menus', 'SetupVersion', 'InstallTheme', 'InstallVisualStyle') Traceback (most recent call last): File "D:\bin\test_pyRegistry.py", line 5, in ? print basereg.getKeyNames() AttributeError: getKeyNames ============ It appears as though open() and getValueNames() both work fine while getKeyNames throws an error. I am running Python 2.3.4 on a WinXP machine. Any suggestions? In advance, many thanks for any help. - -------------------------------------------------- David Flory, Ph.D. Professor of Physics Fairleigh Dickinson University 1000 River Road, Mail Stop T-Bec2-03 Teaneck, New Jersey 07666 Office: Becton Hall Room 111 Voice: 201-692-7064 Email: flory@fdu.edu (regular email) Pager: flory@vText.com (subj + text < 150 char) http://TheFlorys.org/David.Flory/ <== My PGP key is here -----BEGIN PGP SIGNATURE----- Version: PGP 8.1 Comment: 201-692-7064 iQA/AwUBQR7d0Fe2/rcN3lp8EQJv1QCgtSQJFilwnonfp4qrgeL3TL5fmIgAnj9E Mg8Y4PpRujvkFz/q0EciXiXs =hXJw -----END PGP SIGNATURE----- ------------------------------ _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 End of Python-win32 Digest, Vol 17, Issue 15 ******************************************** From mhammond at skippinet.com.au Mon Aug 16 05:31:52 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon Aug 16 05:31:31 2004 Subject: [python-win32] RE: Python-win32 Digest, Vol 17, Issue 15 In-Reply-To: Message-ID: <07df01c48341$92fe2aa0$0200a8c0@eden> It looks like the foreground window has died, and we unconditionally try and set it foreground. The attached patch should work - please let me know that it does, and I will check it in for the next version. A short term work around is obviously to run the script directly from Python.exe, or I also expect just "running" it in pythonwin. Mark. > -----Original Message----- > From: python-win32-bounces@python.org > [mailto:python-win32-bounces@python.org]On Behalf Of Jody Burgess > Sent: Monday, 16 August 2004 6:19 AM > To: python-win32@python.org > Subject: [python-win32] RE: Python-win32 Digest, Vol 17, Issue 15 > > > Can someone please tell me why I would receive the following > error in the > interactive window from this command? > > Command: > hWD = os.system('lpr -S 192.168.168.9 -P queue- myqueue ' + tmpfile) > > > Error: > [Dbg]>>> Traceback (most recent call last): > File > "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\dbgco > mmands.py", > line 73, in OnGo > self._DoOrStart("do_set_continue", scriptutils.RS_DEBUGGER_GO) > File > "C:\Python23\lib\site-packages\Pythonwin\pywin\framework\dbgco > mmands.py", > line 57, in _DoOrStart > method() > File > "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\debugger.py", > line 636, in do_set_continue > if self.GUIAboutToRun(): > File > "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\debugger.py", > line 787, in GUIAboutToRun > if not self.StopDebuggerPump(): > File > "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\debugger.py", > line 485, in StopDebuggerPump > if self.GUIAboutToFinishInteract(): > File > "C:\Python23\lib\site-packages\Pythonwin\pywin\debugger\debugger.py", > line 836, in GUIAboutToFinishInteract > self.oldForeground.EnableWindow(1) > win32ui: The window handle does not specify a valid window > win32ui: Error in Command Message handler for command ID 15022, Code 0 > > > Is there anything I can do to prevent the error from occuring? I have > win32ui imported correctly. > > > Jody Burgess ISP > Systems Analyst > Seward Consulting Ltd. > 780.702.5103 > jody.burgess@sewardconsulting.com > > > -----Original Message----- > From: python-win32-bounces@python.org > [mailto:python-win32-bounces@python.org]On Behalf Of > python-win32-request@python.org > Sent: Sunday, August 15, 2004 4:00 AM > To: python-win32@python.org > Subject: Python-win32 Digest, Vol 17, Issue 15 > > > Send Python-win32 mailing list submissions to > python-win32@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-win32 > or, via email, send a message with subject or body 'help' to > python-win32-request@python.org > > You can reach the person managing the list at > python-win32-owner@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-win32 digest..." > > > Today's Topics: > > 1. pyRegistry AttributeError (David Flory) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sat, 14 Aug 2004 23:51:45 -0400 > From: "David Flory" > Subject: [python-win32] pyRegistry AttributeError > To: > Message-ID: > > DAT0HvxsKAAAAQ > AAAAAkCuZRxldEq1KCa8TecjHgEAAAAA@fdu.edu> > > Content-Type: text/plain; charset="us-ascii" > > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > I just downloaded pyRegistry (the 2004-08-11 binary update, > v1.0.3) and am > having a problem. My test code is: > > =============== > import pyRegistry > baseKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" > basereg = pyRegistry.open(baseKey) > print basereg.getValueNames() > print basereg.getKeyNames() > ============ > > Which returns > > ================= > D:\bin>test_pyRegistry > ('Drop Shadow', 'Flat Menus', 'SetupVersion', 'InstallTheme', > 'InstallVisualStyle') > Traceback (most recent call last): > File "D:\bin\test_pyRegistry.py", line 5, in ? > print basereg.getKeyNames() > AttributeError: getKeyNames > ============ > > It appears as though open() and getValueNames() both work fine while > getKeyNames throws an error. > > I am running Python 2.3.4 on a WinXP machine. Any suggestions? > > In advance, many thanks for any help. > > - -------------------------------------------------- > David Flory, Ph.D. > Professor of Physics > Fairleigh Dickinson University > 1000 River Road, Mail Stop T-Bec2-03 > Teaneck, New Jersey 07666 > > Office: Becton Hall Room 111 > Voice: 201-692-7064 > Email: flory@fdu.edu (regular email) > Pager: flory@vText.com (subj + text < 150 char) > http://TheFlorys.org/David.Flory/ <== My PGP key is here > > > -----BEGIN PGP SIGNATURE----- > Version: PGP 8.1 > Comment: 201-692-7064 > > iQA/AwUBQR7d0Fe2/rcN3lp8EQJv1QCgtSQJFilwnonfp4qrgeL3TL5fmIgAnj9E > Mg8Y4PpRujvkFz/q0EciXiXs > =hXJw > -----END PGP SIGNATURE----- > > > > ------------------------------ > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > End of Python-win32 Digest, Vol 17, Issue 15 > ******************************************** > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 -------------- next part -------------- A non-text attachment was scrubbed... Name: debugger.patch Type: application/octet-stream Size: 896 bytes Desc: not available Url : http://mail.python.org/pipermail/python-win32/attachments/20040816/74c297f0/debugger.obj From beast at ludens.elte.hu Mon Aug 16 13:59:03 2004 From: beast at ludens.elte.hu (=?ISO-8859-15?B?SW1yZSBBbmRy4XMgUvNiZXJ0?=) Date: Mon Aug 16 13:57:51 2004 Subject: [python-win32] Re: Windows service features and Python In-Reply-To: <017301c47e0c$544bd620$0200a8c0@eden> References: <017301c47e0c$544bd620$0200a8c0@eden> Message-ID: <1611200232.20040816135903@ludens.elte.hu> Hello Mark, Monday, August 9, 2004, 2:28:08 PM, you wrote: >> Based on the downloaded source, I created a dll with MSVC, and managed >> to write events with IDs from that dll. However, for custom categories >> I had to create the registry keys by hand, because I found no >> method for >> this in PyWin32. > win32evtlogutil.py may have some helpers you find useful - it can register > new event categories. win32service* only provide service specific > functions - even though services usually use event logging functions, they > are a discrete set of APIs. win32evtlogutil.py deals with EventMessageFile and TypesSupported reg keys only. For categories two additional keys should be used, CategoryMessageFile and CategoryCount. These two keys I did not find throughout all the source. Should I log the need for category support as an RFE? Maybe we could add this to the registering method like: def AddSourceToRegistry(appName, msgDLL = None, eventLogType = "Application", eventLogFlags = None, catDLL = None, catCount = 0): >> Now I'm trying to figure out how can I make these IDs visible by >> symbolic name in my Python source, like pipeTestService uses >> servicemanager.pyd. I don't want to define these twice, and >> keep in sync all the time... > Check out "h2py" in the Python "Tools\scripts" directory for one option. Yes, that would be fine for some sort of automatic translation of IDs into Python source, provided I modified it for handling .mc syntax instead of .h, but I'd like to see these IDs in only one source. I'm trying to create a .cpp with these constants. Since I didnt find a minimal Windows .dll example that can be used for Python, I will try to deduce one from servicemanager.cpp. >> I found this out only by looking at the source, as its help does >> not mention this switch. It would also be nice if this would >> support pause and continue functions. > I agree. I'd welcome specific suggestions as to what needs better docs (and > welcome even more the specific text to use ). The --perfmon switches > were a (possibly poor) attempt at merging services and the permon API, but > although often used by services, just like the event logging functions they > are a different set of APIs I think the perfmon switches are quite ok, as they really have a relationship with services. Should I log the need for cmd line pause and continue as an RFE? May I suggest adding the following usage information: --perfmonini file: .ini file to use for registering performance monitor data --perfmondll file: .dll file to use when querying the service for performance data, default = perfmondata.dll >> Thanks for the help so far. >> >> It seems that now I got all the answers, except for one new question: >> >> Q4) I can't make my service interactive. I never get a console >> window despite that I use the --interactive flag, and I can >> see it set under the logon tab of service properties. What >> did I get wrong? > I believe that flag controls the service's access to the win32 "desktop" > (which is not the same as the Windows Explorer deskop). ie, if your service > is "interactive", then you should see modal dialogs and other windows > displayed by the service. However, you don't see a console created for the > service itself (in the same way as you don't see a console created for other > services when you set this flag via the standard Windows services GUI) There are some services which give a console window when this flag is set. I thought pythonservice.exe is such a console app. I suppose with some modifications it would be suitable to compile it as a console app. -- Thanks, Andr?s > As I said before, you need to assume your questions are *not* Python related > (until you can show otherwise), rather than the other way around :) > Mark. From mhammond at skippinet.com.au Mon Aug 16 14:50:12 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon Aug 16 14:50:04 2004 Subject: [python-win32] Re: Windows service features and Python In-Reply-To: <1611200232.20040816135903@ludens.elte.hu> Message-ID: <08e201c4838f$92ca9b10$0200a8c0@eden> > win32evtlogutil.py deals with EventMessageFile and TypesSupported reg > keys only. For categories two additional keys should be used, > CategoryMessageFile and CategoryCount. These two keys I did not find > throughout all the source. Should I log the need for category support > as an RFE? Yes, but unfortunately not much will happen. If you can provide a patch, I will be happy to look at it and get it in, but I doubt I will find the time to firstly research it, then implement it. > Maybe we could add this to the registering method like: > def AddSourceToRegistry(appName, msgDLL = None, eventLogType = > "Application", eventLogFlags = None, catDLL = None, catCount = 0): Sounds great! :) Just make a patch or if necessary, send me a the complete modified source. > >> Now I'm trying to figure out how can I make these IDs visible by > >> symbolic name in my Python source, like pipeTestService uses > >> servicemanager.pyd. I don't want to define these twice, and > >> keep in sync all the time... > > > Check out "h2py" in the Python "Tools\scripts" directory > for one option. > > Yes, that would be fine for some sort of automatic translation of IDs > into Python source, provided I modified it for handling .mc syntax > instead of .h, but I'd like to see these IDs in only one source. > I'm trying to create a .cpp with these constants. Since I didnt > find a minimal Windows .dll example that can be used for Python, > I will try to deduce one from servicemanager.cpp. You should find an 'example_nt' directory somewhere (maybe only in the Python sources). This will create a .pyd - but a .pyd is just a .dll with a funky extension :) > >> I found this out only by looking at the source, as its help does > >> not mention this switch. It would also be nice if this would > >> support pause and continue functions. ... > Should I log the need for cmd line pause and continue as an RFE? As above - I've no shortage on nice things to do :) > May I suggest adding the following usage information: > --perfmonini file: .ini file to use for registering > performance monitor data > --perfmondll file: .dll file to use when querying the service for > performance data, default = perfmondata.dll Thanks - I've checked that in. > There are some services which give a console window when this flag > is set. I thought pythonservice.exe is such a console app. I suppose > with some modifications it would be suitable to compile it as a > console app. I believe this flag will simply allow these services to *create* a console. Eg, a service with this flag can call CreateProcess, and you will see the new process' console. When the parent service does not have it set, you don't see the console. The win32 console API could also be used by a service to create a console, but I'm not aware of how you can get a console for the service itself. Mark. From aloys at alamaison.fr Mon Aug 16 15:58:10 2004 From: aloys at alamaison.fr (Aloys Baillet) Date: Mon Aug 16 17:50:22 2004 Subject: [python-win32] wmi + pythonservice : multithreading issues Message-ID: Hello, I recently discovered Tim Golden's wmi package, which is a very sweet addon to Mark Hammond's work. (BTW, Thank you very much to you two!) But now I am stuck with a multi-threading issue. Actually, I have build a distributed calculation framework (all in Python) based on a service running on several Win2K machines, which can communicate with each other via XML-RPC. And I wanted to give the user a real-time info on the percent of CPU used. The only way to go (I believe) is to use WMI. But I noticed that I can use wmi only in the main thread of the application (if not, I get "x_wmi: 0x800401e4 - Syntaxe incorrecte" error messages). After some searches, I found in the MSDN site two lines about my problem: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mmc/mmc/mmc_and_wmi.asp Threading Issues and Accessing WMI Data To prevent their user interface from being blocked, snap-ins might choose to create a background thread for connecting to WMI. Note that snap-ins that obtain IWbemServices or IEnumWbemClassObject pointers in a background thread must marshal it into their main thread or any other dialog's thread. Unfortunately the service framework lauches SvcDoRun in a separate thread. Has anybody an idea of how to bypass this Microsoft-related limitation? Or maybe I am completely wrong and I could get the wmi data in any thread? Or maybe I could hack pythonservice framework to run SvcDoRun in the main thread... Thank you very much to share your thoughts! -- Aloys Baillet R&D @ La Maison www.alamaison.fr From timr at probo.com Mon Aug 16 18:58:53 2004 From: timr at probo.com (Tim Roberts) Date: Mon Aug 16 18:58:59 2004 Subject: [python-win32] pyRegistry AttributeError In-Reply-To: <20040815100012.6B0291E401F@bag.python.org> References: <20040815100012.6B0291E401F@bag.python.org> Message-ID: <4120E7CD.6060407@probo.com> On Sat, 14 Aug 2004 23:51:45 -0400, "David Flory" wrote: > I just downloaded pyRegistry (the 2004-08-11 binary update, v1.0.3) and am > having a problem. My test code is: > > =============== > import pyRegistry > baseKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" > basereg = pyRegistry.open(baseKey) > print basereg.getValueNames() > print basereg.getKeyNames() > ============ > > Which returns > ... > AttributeError: getKeyNames > > It appears as though open() and getValueNames() both work fine while > getKeyNames throws an error. Right. The documentation says "getKeyNames", but the source code actually implements "getSubKeys". -- - Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc. From brian at assess.net Mon Aug 16 19:26:56 2004 From: brian at assess.net (Brian Brown) Date: Mon Aug 16 19:27:32 2004 Subject: [python-win32] Building from source Message-ID: <1092677216.4120ee60bffd6@www.teuton.org> Greetings all, I'm working with Python-2.3.4 with PyWin32 on the Pocket PC and would like to try to build some additional modules, specifically aygshell. How would I go about adding aygshell to the build environment? I've followed the instructions on http://www.validus.com/~kashtan and have one other problem, when I try to do "nmake all" it says the makefile has invalid syntax (PCbuild/WinCE/makefile) Brian /--------------------------- AbleLink Technologies, Inc. Cognitive Support Technology http://www.ablelinktech.com From Paul_S_Johnson at mnb.uscourts.gov Mon Aug 16 19:46:28 2004 From: Paul_S_Johnson at mnb.uscourts.gov (Paul_S_Johnson@mnb.uscourts.gov) Date: Mon Aug 16 19:51:09 2004 Subject: [python-win32] Controlling IE file input boxes Message-ID: We are testing a web site we are developing by controlling IE through Python and need to be able to input the value of an INPUT tag where TYPE=FILE. I understand the security concern of MS not allowing this, but isn't there some way around it? The python code below initiates the windows file dialog (what happens when someone clicks the "browse" button of the file input box). Is there anyway to script through this and input a file name? =============================== HTML: My Site

=============================== Python code: from win32com.client import DispatchEx ie = DispatchEx('InternetExplorer.Application') ie.Navigate("file://C:/myhtml.html") ie.Visible = 1 myfilebox = ie.Document.forms[0].elements.all["file_1"] myfilebox.click() #??? now what??? ================================ Paul Johnson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040816/e8155d03/attachment.htm From jens.jorgensen at tallan.com Mon Aug 16 20:12:13 2004 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Mon Aug 16 20:12:24 2004 Subject: [python-win32] pyRegistry AttributeError In-Reply-To: References: Message-ID: <4120F8FD.5010305@tallan.com> Doh! I just changed the docs because I thought that I already had changed the function name. Ack. I shall fix this later tonight and it shall be getKeyNames as it really should be. Sorry! David Flory wrote: > >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >I just downloaded pyRegistry (the 2004-08-11 binary update, v1.0.3) and am >having a problem. My test code is: > >=============== >import pyRegistry >baseKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" >basereg = pyRegistry.open(baseKey) >print basereg.getValueNames() >print basereg.getKeyNames() >============ > >Which returns > >================= >D:\bin>test_pyRegistry >('Drop Shadow', 'Flat Menus', 'SetupVersion', 'InstallTheme', >'InstallVisualStyle') >Traceback (most recent call last): > File "D:\bin\test_pyRegistry.py", line 5, in ? > print basereg.getKeyNames() >AttributeError: getKeyNames >============ > >It appears as though open() and getValueNames() both work fine while >getKeyNames throws an error. > >I am running Python 2.3.4 on a WinXP machine. Any suggestions? > >In advance, many thanks for any help. > >- -------------------------------------------------- >David Flory, Ph.D. >Professor of Physics >Fairleigh Dickinson University >1000 River Road, Mail Stop T-Bec2-03 >Teaneck, New Jersey 07666 > >Office: Becton Hall Room 111 >Voice: 201-692-7064 >Email: flory@fdu.edu (regular email) >Pager: flory@vText.com (subj + text < 150 char) >http://TheFlorys.org/David.Flory/ <== My PGP key is here > > >-----BEGIN PGP SIGNATURE----- >Version: PGP 8.1 >Comment: 201-692-7064 > >iQA/AwUBQR7d0Fe2/rcN3lp8EQJv1QCgtSQJFilwnonfp4qrgeL3TL5fmIgAnj9E >Mg8Y4PpRujvkFz/q0EciXiXs >=hXJw >-----END PGP SIGNATURE----- > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" From therve at neocles.com Tue Aug 17 09:40:33 2004 From: therve at neocles.com (Thomas Herve) Date: Tue Aug 17 09:40:50 2004 Subject: [python-win32] wmi + pythonservice : multithreading issues In-Reply-To: References: Message-ID: <4121B671.1090700@neocles.com> Aloys Baillet wrote: > Hello, Hi, [...] > And I wanted to give the user a real-time info on the percent of CPU > used. The only way to go (I believe) is to use WMI. I can help here, as there's another way using win32pdh library. And I'm (almost) sure it works in multithreading program. Although be careful as there's some subtle issues with pdh (localized names, need to fetch the counter 2 times to initialise it...). -- Thomas Herve From aloys at alamaison.fr Tue Aug 17 10:29:15 2004 From: aloys at alamaison.fr (Aloys Baillet) Date: Tue Aug 17 10:29:20 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues In-Reply-To: <4121B671.1090700@neocles.com> References: <4121B671.1090700@neocles.com> Message-ID: Thank you very much Thomas, With your infos I found an exemple of using the win32pdh library for what I need: import win32pdh, time path = win32pdh.MakeCounterPath( \ (None,"Process","Idle", None, -1, "% Processor Time") ) # open the query, and add the counter to the query base = win32pdh.OpenQuery() counter = win32pdh.AddCounter(base, path) # collect the data for the query object. We need to collect # the query data # twice to be able to calculate the % Processor Time win32pdh.CollectQueryData(base) time.sleep(0.1) win32pdh.CollectQueryData(base) # Get the formatted value of the counter print win32pdh.GetFormattedCounterValue( \ counter,win32pdh.PDH_FMT_LONG)[1] And I understand that I have to call the counter 2 times. But this script fails to run with the following error (I use pywin32 build 202 and Python 2.3.4) : Traceback (most recent call last): File "Q:\Perforce\aloys\tools\lmRenderFarm\Tests\pdhclient.py", line 7, in ? counter = win32pdh.AddCounter(base, path) pywintypes.error: (-1073738824, 'AddCounter', 'No error message is available') I think I begin to know quite well Python, but I am new with pywin32... I am surely missing something simple here, but I can't figure it out! Thanks for your help! -- Aloys Baillet R&D @ La Maison www.alamaison.fr Thomas Herve wrote: > Aloys Baillet wrote: > >> Hello, > > > Hi, > > [...] > >> And I wanted to give the user a real-time info on the percent of CPU >> used. The only way to go (I believe) is to use WMI. > > > I can help here, as there's another way using win32pdh library. And I'm > (almost) sure it works in multithreading program. Although be careful as > there's some subtle issues with pdh (localized names, need to fetch the > counter 2 times to initialise it...). > From aloys at alamaison.fr Tue Aug 17 11:05:32 2004 From: aloys at alamaison.fr (Aloys Baillet) Date: Tue Aug 17 11:05:40 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues -> pdh returns an error In-Reply-To: References: <4121B671.1090700@neocles.com> Message-ID: Hello all, With some more searches, I discovered the win32pdhutil package, and I tried the sample example given in the win32pdhutil.py file: import win32pdhutil print win32pdhutil.GetPerformanceAttributes("Memory", "Available Bytes") Unfortunately it returned me the same error: Traceback (most recent call last): File "Q:\Perforce\aloys\tools\lmRenderFarm\Tests\pdhclient.py", line 2, in ? print win32pdhutil.GetPerformanceAttributes("Memory", "Available Bytes") File "D:\Python23\Lib\site-packages\win32\lib\win32pdhutil.py", line 55, in GetPerformanceAttributes hc = win32pdh.AddCounter(hq, path) pywintypes.error: (-1073738824, 'AddCounter', 'No error message is available') Just to remember, I am under Windows 2000 SP4 (french) and I use Python 2.3.4 with pywin32 build 202. Has anybody seen this error before? And if yes, how can I get rid of it? Thank you for your attention! -- Aloys Baillet R&D @ La Maison www.alamaison.fr Aloys Baillet wrote: > Thank you very much Thomas, > With your infos I found an exemple of using the win32pdh library for > what I need: > > > > import win32pdh, time > > path = win32pdh.MakeCounterPath( \ > (None,"Process","Idle", None, -1, "% Processor Time") ) > > # open the query, and add the counter to the query > base = win32pdh.OpenQuery() > counter = win32pdh.AddCounter(base, path) > > # collect the data for the query object. We need to collect > # the query data > # twice to be able to calculate the % Processor Time > win32pdh.CollectQueryData(base) > time.sleep(0.1) > win32pdh.CollectQueryData(base) > > # Get the formatted value of the counter > print win32pdh.GetFormattedCounterValue( \ > counter,win32pdh.PDH_FMT_LONG)[1] > > > > And I understand that I have to call the counter 2 times. > But this script fails to run with the following error > (I use pywin32 build 202 and Python 2.3.4) : > > > Traceback (most recent call last): > File "Q:\Perforce\aloys\tools\lmRenderFarm\Tests\pdhclient.py", line > 7, in ? > counter = win32pdh.AddCounter(base, path) > pywintypes.error: (-1073738824, 'AddCounter', 'No error message is > available') > > > I think I begin to know quite well Python, but I am new with pywin32... > I am surely missing something simple here, but I can't figure it out! > > Thanks for your help! > > -- > Aloys Baillet > R&D @ La Maison > www.alamaison.fr > > > Thomas Herve wrote: > >> Aloys Baillet wrote: >> >>> Hello, >> >> >> >> Hi, >> >> [...] >> >>> And I wanted to give the user a real-time info on the percent of CPU >>> used. The only way to go (I believe) is to use WMI. >> >> >> >> I can help here, as there's another way using win32pdh library. And >> I'm (almost) sure it works in multithreading program. Although be >> careful as there's some subtle issues with pdh (localized names, need >> to fetch the counter 2 times to initialise it...). >> From cedric.delfosse at linbox.com Tue Aug 17 11:14:29 2004 From: cedric.delfosse at linbox.com (Cedric Delfosse) Date: Tue Aug 17 11:14:29 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues -> pdh returns an error In-Reply-To: References: <4121B671.1090700@neocles.com> Message-ID: <1092734068.19147.61.camel@replic.metz> Le mar 17/08/2004 ? 11:05, Aloys Baillet a ?crit : > Hello all, > > With some more searches, I discovered the win32pdhutil package, and I > tried the sample example given in the win32pdhutil.py file: > > import win32pdhutil > print win32pdhutil.GetPerformanceAttributes("Memory", "Available Bytes") > > I think you need to do it like that import win32pdhutil memory = win32pdhutil.find_pdh_counter_localized_name("Memory") avail = win32pdhutil.find_pdh_counter_localized_name("Available Bytes") print win32pdhutil.GetPerformanceAttributes(memory, avail) because of l10n. Regards, -- C?dric Delfosse Linbox / Free&ALter Soft 152, rue de Grigy - Technopole Metz 57070 Metz - FRANCE t?l: +33 (0)3 87 50 87 90 http://linbox.com From aloys at alamaison.fr Tue Aug 17 11:24:28 2004 From: aloys at alamaison.fr (Aloys Baillet) Date: Tue Aug 17 11:24:31 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues -> pdh returns an error In-Reply-To: <1092734068.19147.61.camel@replic.metz> References: <4121B671.1090700@neocles.com> <1092734068.19147.61.camel@replic.metz> Message-ID: Thank you very much C?dric! It worked indeed! I will investigate more on this l10n thing... But you saved my day! Best regards, -- Aloys Baillet R&D @ La Maison www.alamaison.fr Cedric Delfosse wrote: > Le mar 17/08/2004 ? 11:05, Aloys Baillet a ?crit : > >>Hello all, >> >>With some more searches, I discovered the win32pdhutil package, and I >>tried the sample example given in the win32pdhutil.py file: >> >>import win32pdhutil >>print win32pdhutil.GetPerformanceAttributes("Memory", "Available Bytes") >> >> > > I think you need to do it like that > > > import win32pdhutil > > memory = win32pdhutil.find_pdh_counter_localized_name("Memory") > avail = win32pdhutil.find_pdh_counter_localized_name("Available Bytes") > > print win32pdhutil.GetPerformanceAttributes(memory, avail) > > > because of l10n. > > Regards, > From mhammond at skippinet.com.au Tue Aug 17 11:54:01 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue Aug 17 11:53:39 2004 Subject: [python-win32] wmi + pythonservice : multithreading issues In-Reply-To: Message-ID: <0a9901c48440$20576bb0$0200a8c0@eden> I'm glad other's have responded re WMI, but to you original problem: > > Threading Issues and Accessing WMI Data > > To prevent their user interface from being blocked, snap-ins might > choose to create a background thread for connecting to WMI. Note that > snap-ins that obtain IWbemServices or IEnumWbemClassObject > pointers in a > background thread must marshal it into their main thread or any other > dialog's thread. > > > Unfortunately the service framework lauches SvcDoRun in a > separate thread. > Has anybody an idea of how to bypass this Microsoft-related > limitation? > Or maybe I am completely wrong and I could get the wmi data > in any thread? > Or maybe I could hack pythonservice framework to run SvcDoRun in the > main thread... Unfortunately, nothing in your quote implies that WMI will not run on multiple threads - just that you *may* wish to prevent your UI blocking while the WMI calls execute by using a background thread. COM threading is subtle though, so if you do follow this route, you should look for general information on COM threading apartments, and exactly what "must marshal it into their ... thread" means. Python Programming on Win32 has such a description ;) Mark From mhammond at skippinet.com.au Tue Aug 17 12:00:27 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue Aug 17 12:00:19 2004 Subject: [python-win32] wmi + pythonservice : multithreading issues In-Reply-To: <0a9901c48440$20576bb0$0200a8c0@eden> Message-ID: <0aa301c48441$0ce82e60$0200a8c0@eden> > I'm glad other's have responded re WMI Oops - I meant "re PDH" Mark. From aloys at alamaison.fr Tue Aug 17 12:21:41 2004 From: aloys at alamaison.fr (Aloys Baillet) Date: Tue Aug 17 12:21:52 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues In-Reply-To: <0aa301c48441$0ce82e60$0200a8c0@eden> References: <0a9901c48440$20576bb0$0200a8c0@eden> <0aa301c48441$0ce82e60$0200a8c0@eden> Message-ID: Thank you very much, Mark. And actually I plan to buy the book very soon : its the last Python-related book we don't have...;) Regarding my multi-threading issue, I am sure that it can be workarounded, but unfortunately I don't have the enough time at the moment. Thank you again, and best regards, Mark Hammond wrote: >>I'm glad other's have responded re WMI > > > Oops - I meant "re PDH" > > Mark. From Paul_S_Johnson at mnb.uscourts.gov Tue Aug 17 15:32:57 2004 From: Paul_S_Johnson at mnb.uscourts.gov (Paul_S_Johnson@mnb.uscourts.gov) Date: Tue Aug 17 15:36:47 2004 Subject: [python-win32] Controlling IE file input boxes In-Reply-To: <1332.81.244.171.214.1092729127.squirrel@81.244.171.214> Message-ID: "Ludovic Reenaers" wrote on 08/17/2004 02:52:07 AM: > MAy be try this: > from win32com.client import DispatchEx > > ie = DispatchEx('InternetExplorer.Application') > ie.Navigate("file://C:/myhtml.html") > ie.Visible = 1 > myfilebox = ie.Document.forms[0].elements.all["file_1"] > [myfilebox.Value='c:\\xx\\xx.txt'] OR [myfilebox.Value('c:\\xx\\xx.txt')] > It should be possible that kind of way. > > Ludo I wish it was as simple as that. For INPUT tags of where type=FILE, the Value attribute is read-only. I can fetch a value that was manually input by the user, but I cannot set it. This, I suppose, is for security reasons so evil web programmers cannot go phishing for files on the user's hard drive. > > We are testing a web site we are developing by controlling IE through > > Python and need to be able to input the value of an INPUT tag where > > TYPE=FILE. I understand the security concern of MS not allowing this, but > > isn't there some way around it? The python code below initiates the > > windows file dialog (what happens when someone clicks the "browse" button > > of the file input box). Is there anyway to script through this and input > > a file name? > > > > =============================== > > HTML: > > > > > > > > My Site > > > > > >
> >
> >
> > > > > > =============================== > > Python code: > > > > from win32com.client import DispatchEx > > > > ie = DispatchEx('InternetExplorer.Application') > > ie.Navigate("file://C:/myhtml.html") > > ie.Visible = 1 > > myfilebox = ie.Document.forms[0].elements.all["file_1"] > > myfilebox.click() > > #??? now what??? > > ================================ > > > > Paul Johnson > > _______________________________________________ > > Python-win32 mailing list > > Python-win32@python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040817/91fd29e7/attachment.htm From wnvcole at peppermillcas.com Tue Aug 17 16:36:39 2004 From: wnvcole at peppermillcas.com (Vernon Cole) Date: Tue Aug 17 16:36:49 2004 Subject: [python-win32] Controlling IE file input boxes Message-ID: <07AF3C77A0FBD311A99F00508B65203903272C92@SEBASTIAN> Check out http://users.swing.be/wintclsend/windpysend/ . Windpysend is a package which will emulate typing and/or mouse clicks on another window. Vincent (the author) charges a modest license fee for this. I am hoping that someone will make a good donation to him so that he will release the source. It is a very handy function for a scripting language to have. ---------- Vernon -----Original Message----- From: Paul_S_Johnson@mnb.uscourts.gov [mailto:Paul_S_Johnson@mnb.uscourts.gov] Sent: Tuesday, August 17, 2004 7:33 AM To: python-win32@python.org Cc: Ludovic Reenaers Subject: Re: [python-win32] Controlling IE file input boxes "Ludovic Reenaers" wrote on 08/17/2004 02:52:07 AM: > MAy be try this: > from win32com.client import DispatchEx > > ie = DispatchEx('InternetExplorer.Application') > ie.Navigate("file://C:/myhtml.html") > ie.Visible = 1 > myfilebox = ie.Document.forms[0].elements.all["file_1"] > [myfilebox.Value='c:\\xx\\xx.txt'] OR [myfilebox.Value('c:\\xx\\xx.txt')] > It should be possible that kind of way. > > Ludo I wish it was as simple as that. For INPUT tags of where type=FILE, the Value attribute is read-only. I can fetch a value that was manually input by the user, but I cannot set it. This, I suppose, is for security reasons so evil web programmers cannot go phishing for files on the user's hard drive. > > We are testing a web site we are developing by controlling IE through > > Python and need to be able to input the value of an INPUT tag where > > TYPE=FILE. I understand the security concern of MS not allowing this, but > > isn't there some way around it? The python code below initiates the > > windows file dialog (what happens when someone clicks the "browse" button > > of the file input box). Is there anyway to script through this and input > > a file name? > > > > =============================== > > HTML: > > > > > > > > My Site > > > > > >
> >
> >
> > > > > > =============================== > > Python code: > > > > from win32com.client import DispatchEx > > > > ie = DispatchEx('InternetExplorer.Application') > > ie.Navigate("file://C:/myhtml.html") > > ie.Visible = 1 > > myfilebox = ie.Document.forms[0].elements.all["file_1"] > > myfilebox.click() > > #??? now what??? > > ================================ > > > > Paul Johnson > > _______________________________________________ > > Python-win32 mailing list > > Python-win32@python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040817/33d01541/attachment.html From Paul_S_Johnson at mnb.uscourts.gov Tue Aug 17 18:13:14 2004 From: Paul_S_Johnson at mnb.uscourts.gov (Paul_S_Johnson@mnb.uscourts.gov) Date: Tue Aug 17 18:17:00 2004 Subject: [python-win32] Controlling IE file input boxes In-Reply-To: <07AF3C77A0FBD311A99F00508B65203903272C92@SEBASTIAN> Message-ID: Thanks for the tip Vernon. It plays very nicely with the win32 module. Just set the focus on the form element you want to control before sending the input text. Here's what worked for me. It's painless: ========================= from win32com.client import DispatchEx import WindPySend as W ie = DispatchEx('InternetExplorer.Application') ie.Navigate("file://C:/myhtml.html") ie.Visible = 1 myfilebox = ie.Document.forms[0].elements.all["file_1"] myfilebox.focus() W.send("C:\mydir\myfile.txt") Paul S. Johnson Vernon Cole <> wrote on 08/17/2004 09:36:39 AM: > Check out http://users.swing.be/wintclsend/windpysend/ . > Windpysend is a package which will emulate typing and/or mouse > clicks on another window. Vincent (the author) charges a modest > license fee for this. I am hoping that someone will make a good > donation to him so that he will release the source. It is a very > handy function for a scripting language to have. > ---------- > Vernon > > -----Original Message----- > From:Paul S. Johnson [mailto:] > Sent: Tuesday, August 17, 2004 7:33 AM > To: python-win32@python.org > Cc: Ludovic Reenaers > Subject: Re: [python-win32] Controlling IE file input boxes > > "Ludovic Reenaers" wrote on 08/17/2004 02:52:07 AM: > > > MAy be try this: > > from win32com.client import DispatchEx > > > > ie = DispatchEx('InternetExplorer.Application') > > ie.Navigate("file://C:/myhtml.html") > > ie.Visible = 1 > > myfilebox = ie.Document.forms[0].elements.all["file_1"] > > [myfilebox.Value='c:\\xx\\xx.txt'] OR [myfilebox.Value('c:\\xx\\xx.txt')] > > It should be possible that kind of way. > > > > Ludo > > I wish it was as simple as that. For INPUT tags of where type=FILE, > the Value attribute is read-only. I can fetch a value that was > manually input by the user, but I cannot set it. This, I suppose, is > for security reasons so evil web programmers cannot go phishing for > files on the user's hard drive. > > > > > We are testing a web site we are developing by controlling IE through > > > Python and need to be able to input the value of an INPUT tag where > > > TYPE=FILE. I understand the security concern of MS not allowingthis, but > > > isn't there some way around it? The python code below initiates the > > > windows file dialog (what happens when someone clicks the "browse" button > > > of the file input box). Is there anyway to script through this and input > > > a file name? > > > > > > =============================== > > > HTML: > > > > > > > > > > > > My Site > > > > > > > > >
> > >
> > >
> > > > > > > > > =============================== > > > Python code: > > > > > > from win32com.client import DispatchEx > > > > > > ie = DispatchEx('InternetExplorer.Application') > > > ie.Navigate("file://C:/myhtml.html") > > > ie.Visible = 1 > > > myfilebox = ie.Document.forms[0].elements.all["file_1"] > > > myfilebox.click() > > > #??? now what??? > > > ================================ > > > > > > Paul Johnson > > > _______________________________________________ > > > Python-win32 mailing list > > > Python-win32@python.org > > > http://mail.python.org/mailman/listinfo/python-win32 > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040817/c8fb980f/attachment.html From jens.jorgensen at tallan.com Thu Aug 19 02:11:59 2004 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Thu Aug 19 02:12:11 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues In-Reply-To: References: <0a9901c48440$20576bb0$0200a8c0@eden><0aa301c48441$0ce82e60$0200a8c0@eden> Message-ID: <4123F04F.7040809@tallan.com> I should throw in here that yet another way to get the perfmon counters is to go to the "source". You get the raw data through a registry interface. The main challenge is that the registry data you get is variable-length and doesn't work like other registry data. However, it is for just these reasons that I wrote pyRegistry. In this case you'll need to parse out the data yourself (it's a C struct kinda) but if you're interested in giving this a try I can supply you with some code to use. Email me if you're interested. With this methodology you will also compute the values yourself but this is the most low-level means of getting the data possible. If you're interested in this module you can look at the information on www.python.org/pypi Aloys Baillet wrote: > Thank you very much, Mark. > And actually I plan to buy the book very soon : its the last > Python-related book we don't have...;) > Regarding my multi-threading issue, I am sure that it can be > workarounded, but unfortunately I don't have the enough time at the > moment. > Thank you again, and best regards, > > Mark Hammond wrote: > >>> I'm glad other's have responded re WMI >> >> >> >> Oops - I meant "re PDH" >> >> Mark. > > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" From jens.jorgensen at tallan.com Thu Aug 19 04:03:41 2004 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Thu Aug 19 04:03:51 2004 Subject: [python-win32] pyRegistry AttributeError In-Reply-To: <4120F8FD.5010305@tallan.com> References: <4120F8FD.5010305@tallan.com> Message-ID: <41240A7D.6030508@tallan.com> Ok, a version 1.0.4 is out now. getSubKeys is still there but causes a deprecation warning. getKeyNames is now in place as the "right" way to do it since this naming is more symmetric. I thought about adding an iterator to the object that'd go through the sub-keys and value names. However, it was a bit more than I could do at the moment and wanted to put this fix out there. Jens B. Jorgensen wrote: > Doh! I just changed the docs because I thought that I already had > changed the function name. Ack. I shall fix this later tonight and it > shall be getKeyNames as it really should be. > > Sorry! > > David Flory wrote: > >> >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> I just downloaded pyRegistry (the 2004-08-11 binary update, v1.0.3) >> and am >> having a problem. My test code is: >> >> =============== >> import pyRegistry >> baseKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes" >> basereg = pyRegistry.open(baseKey) print basereg.getValueNames() >> print basereg.getKeyNames() >> ============ >> >> Which returns >> >> ================= >> D:\bin>test_pyRegistry >> ('Drop Shadow', 'Flat Menus', 'SetupVersion', 'InstallTheme', >> 'InstallVisualStyle') >> Traceback (most recent call last): >> File "D:\bin\test_pyRegistry.py", line 5, in ? >> print basereg.getKeyNames() >> AttributeError: getKeyNames >> ============ >> >> It appears as though open() and getValueNames() both work fine while >> getKeyNames throws an error. >> I am running Python 2.3.4 on a WinXP machine. Any suggestions? >> >> In advance, many thanks for any help. >> >> - -------------------------------------------------- > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" From aloys at alamaison.fr Thu Aug 19 10:44:25 2004 From: aloys at alamaison.fr (Aloys Baillet) Date: Thu Aug 19 10:44:33 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues In-Reply-To: <4123F04F.7040809@tallan.com> References: <0a9901c48440$20576bb0$0200a8c0@eden><0aa301c48441$0ce82e60$0200a8c0@eden> <4123F04F.7040809@tallan.com> Message-ID: Hello, I just downloaded your pyRegistry module (BTW I don't have read access to the v1.0.4, only the v1.0.3). And I would accept gracefully if you have some code with performance data retrieving to send to me... For the moment I retrieve CPU data with win32pdh and win32pdhutil, and I use ctypes to retrieve memory usage (performance data seem to not provide total physical memory). And now I would like to unify the methods... pyRegistry could help me a lot! Thank you very much, Aloys Jens B. Jorgensen wrote: > I should throw in here that yet another way to get the perfmon counters > is to go to the "source". You get the raw data through a registry > interface. The main challenge is that the registry data you get is > variable-length and doesn't work like other registry data. However, it > is for just these reasons that I wrote pyRegistry. In this case you'll > need to parse out the data yourself (it's a C struct kinda) but if > you're interested in giving this a try I can supply you with some code > to use. Email me if you're interested. With this methodology you will > also compute the values yourself but this is the most low-level means of > getting the data possible. If you're interested in this module you can > look at the information on www.python.org/pypi > > Aloys Baillet wrote: > >> Thank you very much, Mark. >> And actually I plan to buy the book very soon : its the last >> Python-related book we don't have...;) >> Regarding my multi-threading issue, I am sure that it can be >> workarounded, but unfortunately I don't have the enough time at the >> moment. >> Thank you again, and best regards, >> >> Mark Hammond wrote: >> >>>> I'm glad other's have responded re WMI >>> >>> >>> >>> >>> Oops - I meant "re PDH" >>> >>> Mark. >> >> >> >> _______________________________________________ >> Python-win32 mailing list >> Python-win32@python.org >> http://mail.python.org/mailman/listinfo/python-win32 > > > > From anand.k.rayudu at esi-group.com Thu Aug 19 15:49:58 2004 From: anand.k.rayudu at esi-group.com (Anand K Rayudu) Date: Thu Aug 19 15:51:10 2004 Subject: [python-win32] raw string Message-ID: <4124B006.8090203@esi-group.com> Hi all, i have com interface which returns a string. in my case it is returning "E:\data\models\neonmodel.dat" if i print the value \n is interpted as new line charcter and if i use os.access(file,os.R_OK) it returns false. How can i specify not to consider the string in raw mode in static string i would have used it as r"E:\data\modes\neonmodel.dat" but if i have that already as variable, how can i do it Thanks for help my python code looks like this from win32com.client import Dispatch aa=Dispatch("MyExecutive.MyAPIs") file=aa.getFileName() import os #file=r"E:\data\models\model.dat" // if i uncomment it is ok if(os.access(file,os.R_OK)==True): // access files as it is not in raw aa.readFile(file) Regards Anand From jens.jorgensen at tallan.com Thu Aug 19 17:24:53 2004 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Thu Aug 19 17:25:14 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues In-Reply-To: References: <0a9901c48440$20576bb0$0200a8c0@eden><0aa301c48441$0ce82e60$0200a8c0@eden> <4123F04F.7040809@tallan.com> Message-ID: <4124C645.9010507@tallan.com> Aloys Baillet wrote: > Hello, > > I just downloaded your pyRegistry module (BTW I don't have read access > to the v1.0.4, only the v1.0.3). Crap, I always forget something. This is now fixed. (I really have to write a script to upload new versions.) > And I would accept gracefully if you have some code with performance > data retrieving to send to me... > For the moment I retrieve CPU data with win32pdh and win32pdhutil, and > I use ctypes to retrieve memory usage (performance data seem to not > provide total physical memory). > And now I would like to unify the methods... pyRegistry could help me > a lot! Ok, for whatever reason at the moment I can't find this module I had called PerfData that did the parsing. I'm still looking though, I'll let you know. Hopefully I still have this as I seem to remember putting a fair amount of work into it. > Thank you very much, > > Aloys > > Jens B. Jorgensen wrote: > >> I should throw in here that yet another way to get the perfmon >> counters is to go to the "source". You get the raw data through a >> registry interface. The main challenge is that the registry data you >> get is variable-length and doesn't work like other registry data. >> However, it is for just these reasons that I wrote pyRegistry. In >> this case you'll need to parse out the data yourself (it's a C struct >> kinda) but if you're interested in giving this a try I can supply you >> with some code to use. Email me if you're interested. With this >> methodology you will also compute the values yourself but this is the >> most low-level means of getting the data possible. If you're >> interested in this module you can look at the information on >> www.python.org/pypi >> >> Aloys Baillet wrote: >> >>> Thank you very much, Mark. >>> And actually I plan to buy the book very soon : its the last >>> Python-related book we don't have...;) >>> Regarding my multi-threading issue, I am sure that it can be >>> workarounded, but unfortunately I don't have the enough time at the >>> moment. >>> Thank you again, and best regards, >>> >>> Mark Hammond wrote: >>> >>>>> I'm glad other's have responded re WMI >>>> >>>> >>>> >>>> >>>> >>>> Oops - I meant "re PDH" >>>> >>>> Mark. >>> >>> >>> >>> >>> _______________________________________________ >>> Python-win32 mailing list >>> Python-win32@python.org >>> http://mail.python.org/mailman/listinfo/python-win32 >> >> >> >> >> > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" From davidf at sjsoft.com Thu Aug 19 17:29:15 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu Aug 19 17:29:22 2004 Subject: [python-win32] How to send mail via Extended MAPI Message-ID: <4124C74B.90608@sjsoft.com> Hi I'm sure this code will be useful to others 'cause it took some blood sweat and tears to work out ... Perhaps it could be included (in some form) in the win32 mapi classes? David PS You can send mail easily using the Simple MAPI COM wrappers but it has several problems with various patches for Outlook that bring up dialogs etc. -------------- next part -------------- #!/usr/bin/env python """this sample code sends mail with Extended MAPI using the pywin32 mapi wrappers...""" from win32com.mapi import mapi from win32com.mapi import mapitags import types def SendEMAPIMail(Subject="", Message="", SendTo=None, SendCC=None, SendBCC=None, MAPIProfile=None): """ Sends an email to the recipient using the extended MAPI interface """ # initialize and log on mapi.MAPIInitialize(None) session = mapi.MAPILogonEx(0, MAPIProfile, None, mapi.MAPI_EXTENDED | mapi.MAPI_USE_DEFAULT) adminprofiles = mapi.MAPIAdminProfiles(0) messagestorestable = session.GetMsgStoresTable(0) statustable = session.GetStatusTable(0) messagestorestable.SetColumns((mapitags.PR_ENTRYID, mapitags.PR_DISPLAY_NAME_A, mapitags.PR_DEFAULT_STORE),0) while (True): rows = messagestorestable.QueryRows(1, 0) if len(rows) != 1: break row = rows[0] property,value = row[0] if (property == mapitags.PR_DEFAULT_STORE and value == True): break # unpack the row and open the message store (eid_tag, eid), (name_tag, name), (def_store_tag, def_store) = row msgstore = session.OpenMsgStore(0,eid,None,mapi.MDB_NO_DIALOG | mapi.MAPI_BEST_ACCESS) # get the outbox hr, props = msgstore.GetProps((mapitags.PR_IPM_OUTBOX_ENTRYID), 0) (tag, eid) = props[0] outboxfolder = msgstore.OpenEntry(eid,None,mapi.MAPI_BEST_ACCESS) # create the message and the addrlist message = outboxfolder.CreateMessage(None,0) pal = [] def makeentry(recipient, recipienttype): return ((mapitags.PR_RECIPIENT_TYPE, recipienttype), (980484099, 0), (mapitags.PR_SEND_RICH_INFO, False), (mapitags.PR_DISPLAY_TYPE, 0), (mapitags.PR_OBJECT_TYPE, 6), (mapitags.PR_EMAIL_ADDRESS_A, recipient), (mapitags.PR_ADDRTYPE_A, 'SMTP'), (mapitags.PR_DISPLAY_NAME_A, recipient)) if SendTo: pal.extend([makeentry(recipient, mapi.MAPI_TO) for recipient in SendTo.split(",")]) if SendCC: pal.extend([makeentry(recipient, mapi.MAPI_CC) for recipient in SendCC.split(",")]) if SendBCC: pal.extend([makeentry(recipient, mapi.MAPI_BCC) for recipient in SendBCC.split(",")]) # add the resolved recipients to the message message.ModifyRecipients(mapi.MODRECIP_ADD,pal) message.SetProps([(mapitags.PR_BODY_A,Message), (mapitags.PR_SUBJECT_A,Subject)]) # save changes and submit outboxfolder.SaveChanges(0) message.SubmitMessage(0) if __name__ == '__main__': MAPIProfile = "" SendTo = "python-win32@python.org" SendMessage = "testing one two three" SendSubject = "Testing Extended MAPI!!" SendEMAPIMail(SendSubject, SendMessage, SendTo, MAPIProfile=MAPIProfile) From wnvcole at peppermillcas.com Thu Aug 19 18:04:25 2004 From: wnvcole at peppermillcas.com (Vernon Cole) Date: Thu Aug 19 18:04:30 2004 Subject: [python-win32] Testing Extended MAPI!! Message-ID: <1DE30EB3ECE266409FDE6E7032F178C41397F2@pcimail1s.peppermillcas.com> testing one two three From wnvcole at peppermillcas.com Thu Aug 19 18:23:46 2004 From: wnvcole at peppermillcas.com (Vernon Cole) Date: Thu Aug 19 18:23:55 2004 Subject: YIKES!!! It works very well! RE: [python-win32] Testing Extend ed MAPI!! Message-ID: <1DE30EB3ECE266409FDE6E7032F178C41397F3@pcimail1s.peppermillcas.com> David Fraser's module works just fine right out of the box. If you inadvertantly RUN it, rather than EDIT it, it will send a lovely test message to the sig. Sorry. ------------- Vernon -----Original Message----- From: Vernon Cole [mailto:wnvcole@peppermillcas.com] Sent: Thursday, August 19, 2004 10:04 AM To: python-win32@python.org Subject: [python-win32] Testing Extended MAPI!! testing one two three _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32 From davidf at sjsoft.com Thu Aug 19 20:28:08 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu Aug 19 20:28:14 2004 Subject: [python-win32] How to send mail via Extended MAPI In-Reply-To: References: <4124C74B.90608@sjsoft.com> Message-ID: <4124F138.8070400@sjsoft.com> John J Lee wrote: >On Thu, 19 Aug 2004, David Fraser wrote: > > > >>I'm sure this code will be useful to others 'cause it took some blood >>sweat and tears to work out ... >> >> >[...] > >Wow, I'm impressed. I once tried to figure out how to do this, and ran >away screaming. > >Thanks for sharing it. > > >John > My colleague Stephen Emslie managed to find some C++ code on the web that did this and then it was a matter of translating it to Python ... but you're right, its a scary process. David From davidf at sjsoft.com Thu Aug 19 21:19:19 2004 From: davidf at sjsoft.com (David Fraser) Date: Thu Aug 19 21:19:26 2004 Subject: [python-win32] How to send mail via Extended MAPI In-Reply-To: References: <4124C74B.90608@sjsoft.com> <4124F138.8070400@sjsoft.com> Message-ID: <4124FD37.8050502@sjsoft.com> John J Lee wrote: >On Thu, 19 Aug 2004, David Fraser wrote: >[...] > > >>My colleague Stephen Emslie managed to find some C++ code on the web >>that did this and then it was a matter of translating it to Python ... >>but you're right, its a scary process. >> >> >[...] > >Where is that C++ code? I spent quite some time looking for something >like that myself. > > http://www.codeproject.com/internet/mapadmin.asp In particular, take a look at CreateMessage. David From mhammond at skippinet.com.au Thu Aug 19 23:51:02 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu Aug 19 23:50:37 2004 Subject: [python-win32] How to send mail via Extended MAPI In-Reply-To: <4124C74B.90608@sjsoft.com> Message-ID: <026101c48636$9f480630$0200a8c0@eden> This looks good. Would it be possible for you to: * Add a bit of a header, including that URL you ported it from. * Give yourself credit for writing it. * Make the default target email address a variable, and set it somewhere invalid :) Then send it back to me, and I will stick it in the next distribution. Mark. > -----Original Message----- > From: python-win32-bounces@python.org > [mailto:python-win32-bounces@python.org]On Behalf Of David Fraser > Sent: Friday, 20 August 2004 1:29 AM > To: python-win32@python.org > Subject: [python-win32] How to send mail via Extended MAPI > > > Hi > > I'm sure this code will be useful to others 'cause it took some blood > sweat and tears to work out ... > Perhaps it could be included (in some form) in the win32 mapi classes? > > David > > PS You can send mail easily using the Simple MAPI COM wrappers but it > has several problems with various patches for Outlook that bring up > dialogs etc. > > From fguzman_slotown at yahoo.com Fri Aug 20 01:10:50 2004 From: fguzman_slotown at yahoo.com (Fabricio Guzman) Date: Fri Aug 20 01:10:53 2004 Subject: [python-win32] Using win32 Function GetMenuItemInfo Message-ID: <20040819231050.19429.qmail@web11509.mail.yahoo.com> Caution: I'm as newbeeish as they come, read at your own risk :-) I'm trying to use the win32 function GetMenuItemInfo. How do I set up the fourth argument in this function. The documentation says the fourth argument should be "A string or buffer in the format of a MENUITEMINFO structure." I don't know what this means. Here's what I've tried to no avail: buff = 'MyString' win32gui.GetMenuItemInfo(131917, 0, 57600, buff) This gives me the following error message: TypeError: Cannot use string as modifiable buffer Thanks in advance, Fabricio _______________________________ Do you Yahoo!? Win 1 of 4,000 free domain names from Yahoo! Enter now. http://promotions.yahoo.com/goldrush From henrik.weber at sdm.de Fri Aug 20 08:55:18 2004 From: henrik.weber at sdm.de (Weber, Henrik) Date: Fri Aug 20 08:55:29 2004 Subject: [python-win32] Using win32 Function GetMenuItemInfo Message-ID: <75380B749B91794AA6D474615B329E1303A4BA@bnmail1.sdm.de> > Caution: I'm as newbeeish as they come, read at your > own risk :-) > > I'm trying to use the win32 function GetMenuItemInfo. > How do I set up the fourth argument in this function. > The documentation says the fourth argument should be > "A string or buffer in the format of a MENUITEMINFO > structure." > > I don't know what this means. Here's what I've tried > to no avail: > buff = 'MyString' > win32gui.GetMenuItemInfo(131917, 0, 57600, buff) > > This gives me the following error message: > TypeError: Cannot use string as modifiable buffer Well, in Python strings are immutable, so you cannot use a string if you want to write something into it. Also, if it wants a MENUITEMINFO structure, you need to supply something that has the size of that structure. You could use a buffer (create with the buffer built-in function) or maybe an array. After calling GetMenuItemInfo you can unpack the result with the struct module. You can find a description of the structure at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Resources/Menus/MenuReference/MenuStructures/MENUITEMINFO.asp If you are trying to extract a string from a menu item, see what the description says about the dwTypeData member. You'll have to play around with pointers a bit. Maybe the ctypes module can help you out there. Have fun! -- Henrik From davidf at sjsoft.com Fri Aug 20 14:20:56 2004 From: davidf at sjsoft.com (David Fraser) Date: Fri Aug 20 14:21:02 2004 Subject: [python-win32] How to send mail via Extended MAPI In-Reply-To: <026101c48636$9f480630$0200a8c0@eden> References: <026101c48636$9f480630$0200a8c0@eden> Message-ID: <4125ECA8.4020907@sjsoft.com> Hi Mark Attached. In retrospect, setting the target address to the list wasn't the wisest thing! David Mark Hammond wrote: >This looks good. Would it be possible for you to: >* Add a bit of a header, including that URL you ported it from. >* Give yourself credit for writing it. >* Make the default target email address a variable, and set it somewhere >invalid :) > >Then send it back to me, and I will stick it in the next distribution. > >Mark. > > > >>-----Original Message----- >>From: python-win32-bounces@python.org >>[mailto:python-win32-bounces@python.org]On Behalf Of David Fraser >>Sent: Friday, 20 August 2004 1:29 AM >>To: python-win32@python.org >>Subject: [python-win32] How to send mail via Extended MAPI >> >> >>Hi >> >>I'm sure this code will be useful to others 'cause it took some blood >>sweat and tears to work out ... >>Perhaps it could be included (in some form) in the win32 mapi classes? >> >>David >> >>PS You can send mail easily using the Simple MAPI COM wrappers but it >>has several problems with various patches for Outlook that bring up >>dialogs etc. >> -------------- next part -------------- #!/usr/bin/env python """module to send mail with Extended MAPI using the pywin32 mapi wrappers...""" # this was based on Jason Hattingh's C++ code at http://www.codeproject.com/internet/mapadmin.asp # written by David Fraser and Stephen Emslie # you can test this by changing the variables at the bottom and running from the command line from win32com.mapi import mapi from win32com.mapi import mapitags # Pre 2.2.1 compat. try: True, False except NameError: True = 1==1; False = 1==0 def SendEMAPIMail(Subject="", Message="", SendTo=None, SendCC=None, SendBCC=None, MAPIProfile=None): """Sends an email to the recipient using the extended MAPI interface Subject and Message are strings Send{To,CC,BCC} are comma-separated address lists MAPIProfile is the name of the MAPI profile""" # initialize and log on mapi.MAPIInitialize(None) session = mapi.MAPILogonEx(0, MAPIProfile, None, mapi.MAPI_EXTENDED | mapi.MAPI_USE_DEFAULT) messagestorestable = session.GetMsgStoresTable(0) messagestorestable.SetColumns((mapitags.PR_ENTRYID, mapitags.PR_DISPLAY_NAME_A, mapitags.PR_DEFAULT_STORE),0) while (True): rows = messagestorestable.QueryRows(1, 0) if len(rows) != 1: break row = rows[0] propertyid, propertyvalue = row[0] if (propertyid == mapitags.PR_DEFAULT_STORE and propertyvalue == True): break # unpack the row and open the message store (eid_tag, eid), (name_tag, name), (def_store_tag, def_store) = row msgstore = session.OpenMsgStore(0,eid,None,mapi.MDB_NO_DIALOG | mapi.MAPI_BEST_ACCESS) # get the outbox hr, props = msgstore.GetProps((mapitags.PR_IPM_OUTBOX_ENTRYID), 0) (tag, eid) = props[0] outboxfolder = msgstore.OpenEntry(eid,None,mapi.MAPI_BEST_ACCESS) # create the message and the addrlist message = outboxfolder.CreateMessage(None,0) # note: you can use the resolveaddress functions for this. but you may get headaches pal = [] def makeentry(recipient, recipienttype): return ((mapitags.PR_RECIPIENT_TYPE, recipienttype), (mapitags.PR_SEND_RICH_INFO, False), (mapitags.PR_DISPLAY_TYPE, 0), (mapitags.PR_OBJECT_TYPE, 6), (mapitags.PR_EMAIL_ADDRESS_A, recipient), (mapitags.PR_ADDRTYPE_A, 'SMTP'), (mapitags.PR_DISPLAY_NAME_A, recipient)) if SendTo: pal.extend([makeentry(recipient, mapi.MAPI_TO) for recipient in SendTo.split(",")]) if SendCC: pal.extend([makeentry(recipient, mapi.MAPI_CC) for recipient in SendCC.split(",")]) if SendBCC: pal.extend([makeentry(recipient, mapi.MAPI_BCC) for recipient in SendBCC.split(",")]) # add the resolved recipients to the message message.ModifyRecipients(mapi.MODRECIP_ADD,pal) message.SetProps([(mapitags.PR_BODY_A,Message), (mapitags.PR_SUBJECT_A,Subject)]) # save changes and submit outboxfolder.SaveChanges(0) message.SubmitMessage(0) if __name__ == '__main__': MAPIProfile = "" # Change this to a valid email address to test SendTo = "an.invalid@address" SendMessage = "testing one two three" SendSubject = "Testing Extended MAPI!!" SendEMAPIMail(SendSubject, SendMessage, SendTo, MAPIProfile=MAPIProfile) From lbates at syscononline.com Fri Aug 20 15:36:55 2004 From: lbates at syscononline.com (Larry Bates) Date: Fri Aug 20 15:37:02 2004 Subject: [python-win32] raw string In-Reply-To: <20040820065612.5B2C91E401B@bag.python.org> Message-ID: <005101c486ba$c3249490$5d00a8c0@LABWXP> The following works for me: a="E:\data\models\neonmodel.dat" a=a.replace("\n","\\n") HTH, Larry Bates Syscon, Inc. Message: 1 Date: Thu, 19 Aug 2004 19:19:58 +0530 From: Anand K Rayudu Subject: [python-win32] raw string To: python-win32@python.org Message-ID: <4124B006.8090203@esi-group.com> Content-Type: text/plain; charset=us-ascii; format=flowed Hi all, i have com interface which returns a string. in my case it is returning "E:\data\models\neonmodel.dat" if i print the value \n is interpted as new line charcter and if i use os.access(file,os.R_OK) it returns false. How can i specify not to consider the string in raw mode in static string i would have used it as r"E:\data\modes\neonmodel.dat" but if i have that already as variable, how can i do it Thanks for help From anand.k.rayudu at esi-group.com Fri Aug 20 16:23:07 2004 From: anand.k.rayudu at esi-group.com (Anand K Rayudu) Date: Fri Aug 20 16:23:59 2004 Subject: [python-win32] raw string In-Reply-To: <005101c486ba$c3249490$5d00a8c0@LABWXP> References: <005101c486ba$c3249490$5d00a8c0@LABWXP> Message-ID: <4126094B.1030208@esi-group.com> Hi Larry, Thanks a lot, yes it works fine Just wondering if there is a way to replace all special characters, or a way to tell python to consider this string as in raw mode. Thanks Again Anand Larry Bates wrote: >The following works for me: > >a="E:\data\models\neonmodel.dat" >a=a.replace("\n","\\n") > >HTH, >Larry Bates >Syscon, Inc. > >Message: 1 >Date: Thu, 19 Aug 2004 19:19:58 +0530 >From: Anand K Rayudu >Subject: [python-win32] raw string >To: python-win32@python.org >Message-ID: <4124B006.8090203@esi-group.com> >Content-Type: text/plain; charset=us-ascii; format=flowed > > >Hi all, > >i have com interface which returns a string. in my case it is returning >"E:\data\models\neonmodel.dat" >if i print the value \n is interpted as new line charcter and if i use >os.access(file,os.R_OK) it returns false. > >How can i specify not to consider the string in raw mode > >in static string i would have used it as r"E:\data\modes\neonmodel.dat" >but if i have that already as variable, how can i do it > >Thanks for help > > > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > > > -- Anand K Rayudu Project Manager Product Development Group ESI Software India Private Limited #213, Nagaprabha Chambers 3rd Main, 4th Cross Chamarajpet, Bangalore - 18 Tel: +91 80 26672984/26602365. Extn. 122 Mobile: +91 98451 80071 www.esi-group.com *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- Confidentiality Statement: This message is intended only for the individual or entity to which it is addressed. It may contain privileged, confidential information which is exempt from disclosure under applicable laws. If you are not the intended recipient, please note that you are strictly prohibited from disseminating or distributing this information (other than to the intended recipient) or copying this information. If you have received this communication in error, please notify us immediately by e-mail or by telephone *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- From alazerus at hotmail.com Wed Aug 18 07:37:51 2004 From: alazerus at hotmail.com (xero) Date: Fri Aug 20 17:10:55 2004 Subject: [python-win32] win32 raw sockets problem Message-ID: you did not say what os you attempted use the sockets on sounds like your problem is SP2 on windowsXP the "internet firewall and ICS service" prevents socket AF_INET, SOCK_RAW, IPPROTO_TCP and i think it filters out all IPPROTO_RAW data and some other stuff, it is said that if you disable the service everything turns back to normal however if your OS is 2000 this does not help -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040817/699efb8d/attachment.htm From timr at probo.com Fri Aug 20 18:59:04 2004 From: timr at probo.com (Tim Roberts) Date: Fri Aug 20 18:59:15 2004 Subject: [python-win32] raw string In-Reply-To: <20040820065612.6554B1E4017@bag.python.org> References: <20040820065612.6554B1E4017@bag.python.org> Message-ID: <41262DD8.10500@probo.com> On Thu, 19 Aug 2004 19:19:58 +0530, Anand K Rayudu wrote: >Hi all, > >i have com interface which returns a string. in my case it is returning >"E:\data\models\neonmodel.dat" >if i print the value \n is interpted as new line charcter and if i use os.access(file,os.R_OK) it returns false. > > Are you SURE the \n is being interpreted as a newline, or are you GUESSING that because os.access fails? >How can i specify not to consider the string in raw mode > >in static string i would have used it as r"E:\data\modes\neonmodel.dat" >but if i have that already as variable, how can i do it > > The intepretation of \n and other escape characters is only done when the interpreter reads literal strings in your program source code. Backslash intepretation is not done on string variables. Consider this: myString1 = "e:\n" # this variable contains 3 characters myString2 = "e:\\n" # this variable contains 4 characters myString3 = r"e:\n" # this variable contains 4 characters myString1 contains a newline. The other two do not. Once it is in that form, they will not be re-examined for backslashes. Now, if you print myString2 or myString3 in the interpreter, it will look like 5 characters ('e:\\n'), but that's just a side effect of the interpreter. The strings contain 4, and they will contain 4 no matter where you send it. If your program receives a string with those 4 characters, it will never be misinterpreted as containing a newline. Now, if this string is coming to you from a C object, it's possible that the object's code is doing the wrong thing. For example, consider this C code with a common error: STDMETHODIMP HRESULT GiveMeAString( LPSTR psz ) { strcpy( psz, "e:\data\models\neomodel.dat"; return S_OK; } This code will return to you a string that contains a newline. The string does NOT contain the two characters "backslash n" that later need to be convered into a newline. If you get this string in a Python program, you will have a string with a newline. The correct way to do this in C is: STDMETHODIMP HRESULT GiveMeAString( LPSTR psz ) { strcpy( psz, "e:\\data\\models\\neomodel.dat"; return S_OK; } >my python code looks like this > >from win32com.client import Dispatch > >aa=Dispatch("MyExecutive.MyAPIs") >file=aa.getFileName() >import os >#file=r"E:\data\models\model.dat" // if i uncomment it is ok >if(os.access(file,os.R_OK)==True): // access files as it is not in raw > aa.readFile(file) > > There is nothing wrong with this code. The bug must be in the MyExecutive object. -- - Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc. From fguzman_slotown at yahoo.com Sat Aug 21 01:11:39 2004 From: fguzman_slotown at yahoo.com (Fabricio Guzman) Date: Sat Aug 21 01:11:42 2004 Subject: [python-win32] Using win32 Function GetMenuItemInfo In-Reply-To: <75380B749B91794AA6D474615B329E1303A4BA@bnmail1.sdm.de> Message-ID: <20040820231139.30853.qmail@web11507.mail.yahoo.com> Henrik, I tried using the built-in buffer function: >>> buff = 'MyString' >>> buff = buffer(buff) >>> win32gui.GetMenuItemInfo(131917, 0, 57600, buff) and received the following error: >>> TypeError: buffer is read-only According to the documentation on buffer(), the function only exists for backward compatability. I can't find any other built-in buffer function. How are buffers created with modern python? Thanks for all the help -Fabricio --- "Weber, Henrik" wrote: > > Caution: I'm as newbeeish as they come, read at > your > > own risk :-) > > > > I'm trying to use the win32 function > GetMenuItemInfo. > > How do I set up the fourth argument in this > function. > > The documentation says the fourth argument should > be > > "A string or buffer in the format of a > MENUITEMINFO > > structure." > > > > I don't know what this means. Here's what I've > tried > > to no avail: > > buff = 'MyString' > > win32gui.GetMenuItemInfo(131917, 0, 57600, buff) > > > > This gives me the following error message: > > TypeError: Cannot use string as modifiable buffer > > Well, in Python strings are immutable, so you cannot > use a string if you want to write something into it. > Also, if it wants a MENUITEMINFO structure, you need > to supply something that has the size of that > structure. You could use a buffer (create with the > buffer built-in function) or maybe an array. After > calling GetMenuItemInfo you can unpack the result > with the struct module. > > You can find a description of the structure at > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Resources/Menus/MenuReference/MenuStructures/MENUITEMINFO.asp > > If you are trying to extract a string from a menu > item, see what the description says about the > dwTypeData member. You'll have to play around with > pointers a bit. Maybe the ctypes module can help you > out there. > > Have fun! > -- > Henrik > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 > __________________________________ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail From mhammond at skippinet.com.au Sat Aug 21 01:45:41 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat Aug 21 01:45:17 2004 Subject: [python-win32] Using win32 Function GetMenuItemInfo In-Reply-To: <20040819231050.19429.qmail@web11509.mail.yahoo.com> Message-ID: <057001c4870f$ce61ed80$0200a8c0@eden> Check out win32gui_struct, and the PackMENUITEMINFO/UnpackMENUITEMINFO functions. You should make sure you have pywin32-202 - it has been enhanced over the last few version. PackMENUITEMINFO provides you with a mutable buffer to pass to the function, and Unpack takes that same buffer (presumably after being modified by a Windows call) and extract back the fields. Mark. > -----Original Message----- > From: python-win32-bounces@python.org > [mailto:python-win32-bounces@python.org]On Behalf Of Fabricio Guzman > Sent: Friday, 20 August 2004 9:11 AM > To: python-win32@python.org > Subject: [python-win32] Using win32 Function GetMenuItemInfo > > > Caution: I'm as newbeeish as they come, read at your > own risk :-) > > I'm trying to use the win32 function GetMenuItemInfo. > How do I set up the fourth argument in this function. > The documentation says the fourth argument should be > "A string or buffer in the format of a MENUITEMINFO > structure." > > I don't know what this means. Here's what I've tried > to no avail: > buff = 'MyString' > win32gui.GetMenuItemInfo(131917, 0, 57600, buff) > > This gives me the following error message: > TypeError: Cannot use string as modifiable buffer > > Thanks in advance, > Fabricio > > > > _______________________________ > Do you Yahoo!? > Win 1 of 4,000 free domain names from Yahoo! Enter now. > http://promotions.yahoo.com/goldrush > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 From fguzman_slotown at yahoo.com Sat Aug 21 02:47:52 2004 From: fguzman_slotown at yahoo.com (Fabricio Guzman) Date: Sat Aug 21 02:47:55 2004 Subject: [python-win32] Using win32 Function GetMenuItemInfo In-Reply-To: <057001c4870f$ce61ed80$0200a8c0@eden> Message-ID: <20040821004752.26081.qmail@web11503.mail.yahoo.com> Thanks a mill Mark... it works! -Fabricio --- Mark Hammond wrote: > Check out win32gui_struct, and the > PackMENUITEMINFO/UnpackMENUITEMINFO > functions. You should make sure you have > pywin32-202 - it has been enhanced > over the last few version. PackMENUITEMINFO > provides you with a mutable > buffer to pass to the function, and Unpack takes > that same buffer > (presumably after being modified by a Windows call) > and extract back the > fields. > > Mark. > > > -----Original Message----- > > From: python-win32-bounces@python.org > > [mailto:python-win32-bounces@python.org]On Behalf > Of Fabricio Guzman > > Sent: Friday, 20 August 2004 9:11 AM > > To: python-win32@python.org > > Subject: [python-win32] Using win32 Function > GetMenuItemInfo > > > > > > Caution: I'm as newbeeish as they come, read at > your > > own risk :-) > > > > I'm trying to use the win32 function > GetMenuItemInfo. > > How do I set up the fourth argument in this > function. > > The documentation says the fourth argument should > be > > "A string or buffer in the format of a > MENUITEMINFO > > structure." > > > > I don't know what this means. Here's what I've > tried > > to no avail: > > buff = 'MyString' > > win32gui.GetMenuItemInfo(131917, 0, 57600, buff) > > > > This gives me the following error message: > > TypeError: Cannot use string as modifiable buffer > > > > Thanks in advance, > > Fabricio > > > > > > > > _______________________________ > > Do you Yahoo!? > > Win 1 of 4,000 free domain names from Yahoo! Enter > now. > > http://promotions.yahoo.com/goldrush > > _______________________________________________ > > Python-win32 mailing list > > Python-win32@python.org > > > http://mail.python.org/mailman/listinfo/python-win32 > > _______________________________ Do you Yahoo!? Win 1 of 4,000 free domain names from Yahoo! Enter now. http://promotions.yahoo.com/goldrush From timr at probo.com Sat Aug 21 03:19:55 2004 From: timr at probo.com (Tim Roberts) Date: Sat Aug 21 03:19:59 2004 Subject: [python-win32] raw string In-Reply-To: <20040821004756.CA48D1E400D@bag.python.org> References: <20040821004756.CA48D1E400D@bag.python.org> Message-ID: <4126A33B.9060702@probo.com> On Fri, 20 Aug 2004 19:53:07 +0530, Anand K Rayudu wrote: >Larry Bates wrote: > >>The following works for me: >> >>a="E:\data\models\neonmodel.dat" >>a=a.replace("\n","\\n") >> >> >Hi Larry, > >Thanks a lot, yes it works fine >Just wondering if there is a way to replace all special characters, or a >way to tell python to consider this string as in raw mode. > > THIS IS NOT THE RIGHT WAY TO FIX THIS! If Larry's code actually helped you, that means the C code is sending you a file name which contains a newline. THAT IS A BUG IN THE C CODE. You should not be working around the bug in your Python code. Instead, you should fix the actual bug, in the COM object that is sending the string. -- - Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc. From joe at goldthwaites.com Mon Aug 23 18:44:01 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Mon Aug 23 18:44:06 2004 Subject: [python-win32] Can't figure out how to get the Excel copy method to work correctly. Message-ID: <005801c48930$655ff700$6401a8c0@jgold82> Hello Everyone, This is my first post to this list. I ran into a problem while converting some old VB applications to Python and I don't have a clue on how to get around it. I have this sample VB subroutine; Sub Test() Set XLApp = CreateObject("Excel.Application") XLApp.Visible = -1 Set XLWorkbook = XLApp.Workbooks.Open("c:\Someworkbook.xls") Set XLWorksheets = XLWorkbook.Worksheets Set LastWorksheet = XLWorksheets(XLWorksheets.Count) XLWorksheets(1).Copy After:=LastWorksheet End Sub What is does is made a copy of worksheet 1 and puts it as the last tab of the workbook. The worksheet copy method says that if you specify the "Before" or "After" parameters, it inserts the copy before or after the worksheet passed. is means that you have to pass a worksheet object to the copy method. If you leave the before or after parameters off, the new worksheet is copied to a new workbook. The above code works fine. Here's my Python equivalent; from win32com.client import Dispatch XLApp = Dispatch("Excel.Application") XLApp.Visible = -1 XLWorkbook = XLApp.Workbooks.Open("c:\EFS01.0\Extensions\ISRecapTemplate.xls") XLWorksheets = XLWorkbook.Worksheets LastWorksheet = XLWorksheets(XLWorksheets.count) XLWorksheets(1).Copy(After=LastWorksheet) When this is run, the worksheet get's copied to a new workbook instead of getting appended to the existing workbook. I know it's passing something to the "After" parameter because if I spell "After" with a lower case "A", I get an error that it's an unknown method. I also know that LastWorksheet has a reference to the last worksheet in the workbook because I can see all the properties. For some reason, Excel doesnt' recognize LastWorksheet as a valid worksheet reference. I suspect that the Win32 routines are doing some translating of the COM objects so they can work from python but doesn't do it if you pass a COM object as a parameter. Does anyone have any ideas on how I can get this functionality working? Thanks. Joe Goldthwaite From bgailer at alum.rpi.edu Mon Aug 23 19:52:47 2004 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Mon Aug 23 19:53:03 2004 Subject: [python-win32] Can't figure out how to get the Excel copy method to work correctly. In-Reply-To: <005801c48930$655ff700$6401a8c0@jgold82> References: <005801c48930$655ff700$6401a8c0@jgold82> Message-ID: <6.1.0.6.0.20040823115048.047e93f0@mail.mric.net> At 10:44 AM 8/23/2004, Joe Goldthwaite wrote: >Hello Everyone, > >This is my first post to this list. I ran into a problem while converting >some old VB applications to Python and I don't have a clue on how to get >around it. I have this sample VB subroutine; > > Sub Test() > Set XLApp = CreateObject("Excel.Application") > XLApp.Visible = -1 > Set XLWorkbook = XLApp.Workbooks.Open("c:\Someworkbook.xls") > Set XLWorksheets = XLWorkbook.Worksheets > Set LastWorksheet = XLWorksheets(XLWorksheets.Count) > XLWorksheets(1).Copy After:=LastWorksheet > End Sub > > >What is does is made a copy of worksheet 1 and puts it as the last tab of >the workbook. The worksheet copy method says that if you specify the >"Before" or "After" parameters, it inserts the copy before or after the >worksheet passed. is means that you have to pass a worksheet object to the >copy method. If you leave the before or after parameters off, the new >worksheet is copied to a new workbook. The above code works fine. Here's my >Python equivalent; > > from win32com.client import Dispatch > > XLApp = Dispatch("Excel.Application") > XLApp.Visible = -1 > XLWorkbook = >XLApp.Workbooks.Open("c:\EFS01.0\Extensions\ISRecapTemplate.xls") > XLWorksheets = XLWorkbook.Worksheets > LastWorksheet = XLWorksheets(XLWorksheets.count) At which pont I get: AttributeError: '' object has no attribute 'count' After capitalizing Count and rerunning I get a 4th worksheet in one book. Don't know why your mileage varies. > XLWorksheets(1).Copy(After=LastWorksheet) > >When this is run, the worksheet get's copied to a new workbook instead of >getting appended to the existing workbook. I know it's passing something to >the "After" parameter because if I spell "After" with a lower case "A", I >get an error that it's an unknown method. I also know that LastWorksheet >has a reference to the last worksheet in the workbook because I can see all >the properties. For some reason, Excel doesnt' recognize LastWorksheet as a >valid worksheet reference. > >I suspect that the Win32 routines are doing some translating of the COM >objects so they can work from python but doesn't do it if you pass a COM >object as a parameter. Does anyone have any ideas on how I can get this >functionality working? > >Thanks. > >Joe Goldthwaite > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 Bob Gailer bgailer@alum.rpi.edu 303 442 2625 home 720 938 2625 cell From fguzman_slotown at yahoo.com Mon Aug 23 19:56:53 2004 From: fguzman_slotown at yahoo.com (Fabricio Guzman) Date: Mon Aug 23 19:57:09 2004 Subject: [python-win32] Can't figure out how to get the Excel copy method to work correctly. In-Reply-To: <005801c48930$655ff700$6401a8c0@jgold82> Message-ID: <20040823175653.39555.qmail@web11506.mail.yahoo.com> Joe, It worked over here with: xlsheets(1).Copy(None, xllstsheet) give it shoot. -Fabricio --- Joe Goldthwaite wrote: > Hello Everyone, > > This is my first post to this list. I ran into a > problem while converting > some old VB applications to Python and I don't have > a clue on how to get > around it. I have this sample VB subroutine; > > Sub Test() > Set XLApp = CreateObject("Excel.Application") > XLApp.Visible = -1 > Set XLWorkbook = > XLApp.Workbooks.Open("c:\Someworkbook.xls") > Set XLWorksheets = XLWorkbook.Worksheets > Set LastWorksheet = > XLWorksheets(XLWorksheets.Count) > XLWorksheets(1).Copy After:=LastWorksheet > End Sub > > > What is does is made a copy of worksheet 1 and puts > it as the last tab of > the workbook. The worksheet copy method says that > if you specify the > "Before" or "After" parameters, it inserts the copy > before or after the > worksheet passed. is means that you have to pass a > worksheet object to the > copy method. If you leave the before or after > parameters off, the new > worksheet is copied to a new workbook. The above > code works fine. Here's my > Python equivalent; > > from win32com.client import Dispatch > > XLApp = Dispatch("Excel.Application") > XLApp.Visible = -1 > XLWorkbook = > XLApp.Workbooks.Open("c:\EFS01.0\Extensions\ISRecapTemplate.xls") > XLWorksheets = XLWorkbook.Worksheets > LastWorksheet = XLWorksheets(XLWorksheets.count) > XLWorksheets(1).Copy(After=LastWorksheet) > > When this is run, the worksheet get's copied to a > new workbook instead of > getting appended to the existing workbook. I know > it's passing something to > the "After" parameter because if I spell "After" > with a lower case "A", I > get an error that it's an unknown method. I also > know that LastWorksheet > has a reference to the last worksheet in the > workbook because I can see all > the properties. For some reason, Excel doesnt' > recognize LastWorksheet as a > valid worksheet reference. > > I suspect that the Win32 routines are doing some > translating of the COM > objects so they can work from python but doesn't do > it if you pass a COM > object as a parameter. Does anyone have any ideas > on how I can get this > functionality working? > > Thanks. > > Joe Goldthwaite > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 > __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail From joe at goldthwaites.com Mon Aug 23 20:14:28 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Mon Aug 23 20:14:34 2004 Subject: [python-win32] Can't figure out how to get the Excel copy method to work correctly. In-Reply-To: <6.1.0.6.0.20040823115048.047e93f0@mail.mric.net> Message-ID: <000801c4893d$087f5730$6401a8c0@jgold82> It is strange that you got the error message on the count method. I wasn't getting any error but it looks like it's not returning a valid worksheet object. Here's a second attempt; XLApp = Dispatch("Excel.Application") XLApp.Visible = -1 XLWorkbook = XLApp.Workbooks.Open("c:\EFS01.0\Extensions\ISRecapTemplate.xls") XLWorksheets = XLWorkbook.Worksheets cnt = XLWorksheets.Count print XLWorksheets(cnt).Name XLWorksheets(1).Copy(After=XLWorksheets(cnt)) I get the count of worksheets in the cnt variable (q) and when I print the name of XLWorksheets(cnt), I get the correct name. The worksheet is still getting copied to a new workbook instead of the end of the current workbook. It sounds like this is what you got also. Excel is not recognizing XLWorksheets(cnt) as a worksheet object. -----Original Message----- From: Bob Gailer [mailto:bgailer@alum.rpi.edu] Sent: Monday, August 23, 2004 10:53 AM To: joe@goldthwaites.com; Python-win32@python.org Subject: Re: [python-win32] Can't figure out how to get the Excel copy method to work correctly. At 10:44 AM 8/23/2004, Joe Goldthwaite wrote: >Hello Everyone, > >This is my first post to this list. I ran into a problem while converting >some old VB applications to Python and I don't have a clue on how to get >around it. I have this sample VB subroutine; > > Sub Test() > Set XLApp = CreateObject("Excel.Application") > XLApp.Visible = -1 > Set XLWorkbook = XLApp.Workbooks.Open("c:\Someworkbook.xls") > Set XLWorksheets = XLWorkbook.Worksheets > Set LastWorksheet = XLWorksheets(XLWorksheets.Count) > XLWorksheets(1).Copy After:=LastWorksheet > End Sub > > >What is does is made a copy of worksheet 1 and puts it as the last tab of >the workbook. The worksheet copy method says that if you specify the >"Before" or "After" parameters, it inserts the copy before or after the >worksheet passed. is means that you have to pass a worksheet object to the >copy method. If you leave the before or after parameters off, the new >worksheet is copied to a new workbook. The above code works fine. Here's my >Python equivalent; > > from win32com.client import Dispatch > > XLApp = Dispatch("Excel.Application") > XLApp.Visible = -1 > XLWorkbook = >XLApp.Workbooks.Open("c:\EFS01.0\Extensions\ISRecapTemplate.xls") > XLWorksheets = XLWorkbook.Worksheets > LastWorksheet = XLWorksheets(XLWorksheets.count) At which pont I get: AttributeError: '' object has no attribute 'count' After capitalizing Count and rerunning I get a 4th worksheet in one book. Don't know why your mileage varies. > XLWorksheets(1).Copy(After=LastWorksheet) > >When this is run, the worksheet get's copied to a new workbook instead of >getting appended to the existing workbook. I know it's passing something to >the "After" parameter because if I spell "After" with a lower case "A", I >get an error that it's an unknown method. I also know that LastWorksheet >has a reference to the last worksheet in the workbook because I can see all >the properties. For some reason, Excel doesnt' recognize LastWorksheet as a >valid worksheet reference. > >I suspect that the Win32 routines are doing some translating of the COM >objects so they can work from python but doesn't do it if you pass a COM >object as a parameter. Does anyone have any ideas on how I can get this >functionality working? > >Thanks. > >Joe Goldthwaite > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 Bob Gailer bgailer@alum.rpi.edu 303 442 2625 home 720 938 2625 cell From joe at goldthwaites.com Mon Aug 23 20:39:59 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Mon Aug 23 20:40:17 2004 Subject: [python-win32] Can't figure out how to get the Excel copy method to work correctly. In-Reply-To: <20040823175653.39555.qmail@web11506.mail.yahoo.com> Message-ID: <000f01c48940$98ed0940$6401a8c0@jgold82> That did it! I thought I had tried that before but I must have screwed something up because it worked this time. Thanks!!!! -----Original Message----- From: Fabricio Guzman [mailto:fguzman_slotown@yahoo.com] Sent: Monday, August 23, 2004 10:57 AM To: joe@goldthwaites.com; Python-win32@python.org Subject: Re: [python-win32] Can't figure out how to get the Excel copy method to work correctly. Joe, It worked over here with: xlsheets(1).Copy(None, xllstsheet) give it shoot. -Fabricio --- Joe Goldthwaite wrote: > Hello Everyone, > > This is my first post to this list. I ran into a > problem while converting > some old VB applications to Python and I don't have > a clue on how to get > around it. I have this sample VB subroutine; > > Sub Test() > Set XLApp = CreateObject("Excel.Application") > XLApp.Visible = -1 > Set XLWorkbook = > XLApp.Workbooks.Open("c:\Someworkbook.xls") > Set XLWorksheets = XLWorkbook.Worksheets > Set LastWorksheet = > XLWorksheets(XLWorksheets.Count) > XLWorksheets(1).Copy After:=LastWorksheet > End Sub > > > What is does is made a copy of worksheet 1 and puts > it as the last tab of > the workbook. The worksheet copy method says that > if you specify the > "Before" or "After" parameters, it inserts the copy > before or after the > worksheet passed. is means that you have to pass a > worksheet object to the > copy method. If you leave the before or after > parameters off, the new > worksheet is copied to a new workbook. The above > code works fine. Here's my > Python equivalent; > > from win32com.client import Dispatch > > XLApp = Dispatch("Excel.Application") > XLApp.Visible = -1 > XLWorkbook = > XLApp.Workbooks.Open("c:\EFS01.0\Extensions\ISRecapTemplate.xls") > XLWorksheets = XLWorkbook.Worksheets > LastWorksheet = XLWorksheets(XLWorksheets.count) > XLWorksheets(1).Copy(After=LastWorksheet) > > When this is run, the worksheet get's copied to a > new workbook instead of > getting appended to the existing workbook. I know > it's passing something to > the "After" parameter because if I spell "After" > with a lower case "A", I > get an error that it's an unknown method. I also > know that LastWorksheet > has a reference to the last worksheet in the > workbook because I can see all > the properties. For some reason, Excel doesnt' > recognize LastWorksheet as a > valid worksheet reference. > > I suspect that the Win32 routines are doing some > translating of the COM > objects so they can work from python but doesn't do > it if you pass a COM > object as a parameter. Does anyone have any ideas > on how I can get this > functionality working? > > Thanks. > > Joe Goldthwaite > > _______________________________________________ > Python-win32 mailing list > Python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 > __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail From joe at goldthwaites.com Tue Aug 24 00:35:12 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Tue Aug 24 00:35:17 2004 Subject: [python-win32] Cannot assign values to the Excel Colors property Message-ID: <002701c48961$74a09310$6401a8c0@jgold82> Here's another strange one. Automating Excel with Python is turning out to be a little more difficult than I thought. I'm trying to set the color property of the workbook object. In VB it goes like this; Workbook.Colors(1) = &H254A70 When I try doing this in Python, It complains about the syntax and tells me I can't assign a value to a function call. I also tried this; Workbook.Colors[1] = 0xH254A70 But it tells me "TypeError: object doesn't support item assignment". I'm sure there's a way to do it but the syntax eludes me. Anyone have any ideas? Thanks again. From bgailer at alum.rpi.edu Tue Aug 24 04:16:53 2004 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Tue Aug 24 04:19:15 2004 Subject: {Spam?} RE: [python-win32] Can't figure out how to get the Excel copy method to work correctly. In-Reply-To: <000801c4893d$087f5730$6401a8c0@jgold82> References: <6.1.0.6.0.20040823115048.047e93f0@mail.mric.net> <000801c4893d$087f5730$6401a8c0@jgold82> Message-ID: <6.1.0.6.0.20040823192711.047d7240@mail.mric.net> At 12:14 PM 8/23/2004, Joe Goldthwaite wrote: >It is strange that you got the error message on the count method. Case sensitivity gets "turned on" as a result of makepy. If you did not run makepy for Excel then it won't matter. >it looks like it's not returning a valid worksheet >object. Here's a second attempt; > >XLApp = Dispatch("Excel.Application") >XLApp.Visible = -1 >XLWorkbook = >XLApp.Workbooks.Open("c:\EFS01.0\Extensions\ISRecapTemplate.xls") >XLWorksheets = XLWorkbook.Worksheets >cnt = XLWorksheets.Count >print XLWorksheets(cnt).Name >XLWorksheets(1).Copy(After=XLWorksheets(cnt)) > >I get the count of worksheets in the cnt variable (q) and when I print the >name of XLWorksheets(cnt), I get the correct name. That should guarantee that XLWorksheets(cnt) is a worksheet. >The worksheet is still getting copied to a new workbook instead of the end >of the current workbook. Consider Excel Help: expression.Copy(Before, After) [snip] Before Optional Variant. The sheet before which the copied sheet will be placed. You cannot specify Before if you specify After. After Optional Variant. The sheet after which the copied sheet will be placed. You cannot specify After if you specify Before. Remarks If you don't specify either Before or After, Microsoft Excel creates a new workbook that contains the copied sheet. Based on this it sounds like Excel is not getting the Before or after. Try: XLWorksheets(1).Copy(None, XLWorksheets(cnt)) # treat before,after as postional parameters. >It sounds like this is what you got also. Excel is not recognizing >XLWorksheets(cnt) as a worksheet object. > > >-----Original Message----- >From: Bob Gailer [mailto:bgailer@alum.rpi.edu] >Sent: Monday, August 23, 2004 10:53 AM >To: joe@goldthwaites.com; Python-win32@python.org >Subject: Re: [python-win32] Can't figure out how to get the Excel copy >method to work correctly. > > >At 10:44 AM 8/23/2004, Joe Goldthwaite wrote: > >Hello Everyone, > > > >This is my first post to this list. I ran into a problem while converting > >some old VB applications to Python and I don't have a clue on how to get > >around it. I have this sample VB subroutine; > > > > Sub Test() > > Set XLApp = CreateObject("Excel.Application") > > XLApp.Visible = -1 > > Set XLWorkbook = XLApp.Workbooks.Open("c:\Someworkbook.xls") > > Set XLWorksheets = XLWorkbook.Worksheets > > Set LastWorksheet = XLWorksheets(XLWorksheets.Count) > > XLWorksheets(1).Copy After:=LastWorksheet > > End Sub > > > > > >What is does is made a copy of worksheet 1 and puts it as the last tab of > >the workbook. The worksheet copy method says that if you specify the > >"Before" or "After" parameters, it inserts the copy before or after the > >worksheet passed. is means that you have to pass a worksheet object to the > >copy method. If you leave the before or after parameters off, the new > >worksheet is copied to a new workbook. The above code works fine. Here's >my > >Python equivalent; > > > > from win32com.client import Dispatch > > > > XLApp = Dispatch("Excel.Application") > > XLApp.Visible = -1 > > XLWorkbook = > >XLApp.Workbooks.Open("c:\EFS01.0\Extensions\ISRecapTemplate.xls") > > XLWorksheets = XLWorkbook.Worksheets > > LastWorksheet = XLWorksheets(XLWorksheets.count) > >At which pont I get: >AttributeError: 'instance at 0x34498360>' object has no attribute 'count' > >After capitalizing Count and rerunning I get a 4th worksheet in one book. >Don't know why your mileage varies. > > > XLWorksheets(1).Copy(After=LastWorksheet) > > > >When this is run, the worksheet get's copied to a new workbook instead of > >getting appended to the existing workbook. I know it's passing something >to > >the "After" parameter because if I spell "After" with a lower case "A", I > >get an error that it's an unknown method. I also know that LastWorksheet > >has a reference to the last worksheet in the workbook because I can see all > >the properties. For some reason, Excel doesnt' recognize LastWorksheet as >a > >valid worksheet reference. > > > >I suspect that the Win32 routines are doing some translating of the COM > >objects so they can work from python but doesn't do it if you pass a COM > >object as a parameter. Does anyone have any ideas on how I can get this > >functionality working? > > > >Thanks. > > > >Joe Goldthwaite > > > >_______________________________________________ > >Python-win32 mailing list > >Python-win32@python.org > >http://mail.python.org/mailman/listinfo/python-win32 > >Bob Gailer >bgailer@alum.rpi.edu >303 442 2625 home >720 938 2625 cell > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 Bob Gailer bgailer@alum.rpi.edu 303 442 2625 home 720 938 2625 cell -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040823/e845a2bb/attachment-0001.htm From niki at vintech.bg Tue Aug 24 09:53:41 2004 From: niki at vintech.bg (Niki Spahiev) Date: Tue Aug 24 10:50:04 2004 Subject: [python-win32] Cannot assign values to the Excel Colors property In-Reply-To: <002701c48961$74a09310$6401a8c0@jgold82> References: <002701c48961$74a09310$6401a8c0@jgold82> Message-ID: <412AF405.7070408@vintech.bg> Joe Goldthwaite wrote: > Here's another strange one. Automating Excel with Python is turning out to > be a little more difficult than I thought. I'm trying to set the color > property of the workbook object. In VB it goes like this; > > Workbook.Colors(1) = &H254A70 > > When I try doing this in Python, It complains about the syntax and tells me > I can't assign a value to a function call. I also tried this; > > Workbook.Colors[1] = 0xH254A70 > > But it tells me "TypeError: object doesn't support item assignment". I'm > sure there's a way to do it but the syntax eludes me. Anyone have any > ideas? > Maybe workbook.Colors(1, 0x223344) ? Niki Spahiev From joe at goldthwaites.com Tue Aug 24 17:48:39 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Tue Aug 24 17:48:46 2004 Subject: [python-win32] Cannot assign values to the Excel Colors property In-Reply-To: <412AF405.7070408@vintech.bg> Message-ID: <001901c489f1$d4389c60$6401a8c0@jgold82> Thanks Niki! Nice try :). I got an error message "TypeError: 'tuple' object is not callable". I would think that the only way to do this would be to use the list assignment syntax. I guess the COM interface doesn't support it though. I'm sure there must be a way to do it. I'm going to try writting a VB macro and then see if I can get Python to execute it. Then I'll delete the macro before I save the workbook. It's kind of a round about way but it should get the job done until I can find out the right way to do it. Joe Goldthwaite -----Original Message----- From: Niki Spahiev [mailto:niki@vintech.bg] Sent: Tuesday, August 24, 2004 12:54 AM To: joe@goldthwaites.com Cc: Python-win32@python.org Subject: Re: [python-win32] Cannot assign values to the Excel Colors property Joe Goldthwaite wrote: > Here's another strange one. Automating Excel with Python is turning out to > be a little more difficult than I thought. I'm trying to set the color > property of the workbook object. In VB it goes like this; > > Workbook.Colors(1) = &H254A70 > > When I try doing this in Python, It complains about the syntax and tells me > I can't assign a value to a function call. I also tried this; > > Workbook.Colors[1] = 0xH254A70 > > But it tells me "TypeError: object doesn't support item assignment". I'm > sure there's a way to do it but the syntax eludes me. Anyone have any > ideas? > Maybe workbook.Colors(1, 0x223344) ? Niki Spahiev From graham.bloice at trihedral.com Tue Aug 24 18:14:20 2004 From: graham.bloice at trihedral.com (Graham Bloice) Date: Tue Aug 24 18:14:32 2004 Subject: [python-win32] Cannot assign values to the Excel Colors property In-Reply-To: <001901c489f1$d4389c60$6401a8c0@jgold82> Message-ID: > Thanks Niki! > > Nice try :). I got an error message "TypeError: 'tuple' object is not > callable". I would think that the only way to do this would be to use the > list assignment syntax. I guess the COM interface doesn't support it > though. I'm sure there must be a way to do it. I'm going to try > writting a > VB macro and then see if I can get Python to execute it. Then I'll delete > the macro before I save the workbook. It's kind of a round about > way but it > should get the job done until I can find out the right way to do it. > > Joe Goldthwaite > > -----Original Message----- > From: Niki Spahiev [mailto:niki@vintech.bg] > Sent: Tuesday, August 24, 2004 12:54 AM > To: joe@goldthwaites.com > Cc: Python-win32@python.org > Subject: Re: [python-win32] Cannot assign values to the Excel Colors > property > > > Joe Goldthwaite wrote: > > Here's another strange one. Automating Excel with Python is turning out > to > > be a little more difficult than I thought. I'm trying to set the color > > property of the workbook object. In VB it goes like this; > > > > Workbook.Colors(1) = &H254A70 > > > > When I try doing this in Python, It complains about the syntax and tells > me > > I can't assign a value to a function call. I also tried this; > > > > Workbook.Colors[1] = 0xH254A70 > > > > But it tells me "TypeError: object doesn't support item > assignment". I'm > > sure there's a way to do it but the syntax eludes me. Anyone have any > > ideas? > > > > Maybe workbook.Colors(1, 0x223344) ? > > Niki Spahiev try workbook.SetColors(1, xxx) The Colors property of the Workbook interface is an indexed property, and the Python COM support has to provide Setxxx and GetXXX methods to support the indexing. Have a look in the COM MakePy generated file for more info. Graham From joe at goldthwaites.com Tue Aug 24 20:06:29 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Tue Aug 24 20:06:47 2004 Subject: [python-win32] Cannot assign values to the Excel Colors property In-Reply-To: Message-ID: <000401c48a05$155ecb20$6401a8c0@jgold82> Hello again, I got it working. I first created a macro in my Excel template called SetColor; Sub SetColor(Workbook, c1, c2, c3, c4, c5, c6, c7, c8, c9) 'Set the first nine colors With Workbook .Colors(1) = c1 .Colors(2) = c2 .Colors(3) = c3 .Colors(4) = c4 .Colors(5) = c5 .Colors(6) = c6 .Colors(7) = c7 .Colors(8) = c8 .Colors(9) = c9 End With 'Remove all the macros from the passed workbook For x = Workbook.VBProject.vbcomponents.Count To 1 Step -2 On Error Resume Next Workbook.VBProject.vbcomponents.Remove Workbook.VBProject.vbcomponents(x) Next End Sub Next, I just execute this line in Python; XLApp.Run("ISRecapTemplate.xls!SetColor", self.XLWorkbook, C[0], C[1], C[2], C[3], C[4], C[5], C[6], C[7], C[8]) C is a list of the colors that I want to use to set the first nine Excel pallet entries. The loop in the SetColor subroutine removes all macros from the workbook. I tested it out and it worked! I get the correct color settings and there are no macro's in the resulting workbook. It isn't pretty but it does work. I'd still like to find out how to set the colors directly. This is a pretty kludgy way of doing it. Graham, I tried the SetColors(1, xxx) but I get an error message that there is not SetColors attribute. I looked for it in my Excel VBA language reference and couldn't find it there either. Thanks for the help everyone. Joe Goldthwaite -----Original Message----- From: Graham Bloice [mailto:graham.bloice@trihedral.com] Sent: Tuesday, August 24, 2004 9:14 AM To: joe@goldthwaites.com Cc: python-win32@python.org Subject: RE: [python-win32] Cannot assign values to the Excel Colors property > Thanks Niki! > > Nice try :). I got an error message "TypeError: 'tuple' object is not > callable". I would think that the only way to do this would be to use the > list assignment syntax. I guess the COM interface doesn't support it > though. I'm sure there must be a way to do it. I'm going to try > writting a > VB macro and then see if I can get Python to execute it. Then I'll delete > the macro before I save the workbook. It's kind of a round about > way but it > should get the job done until I can find out the right way to do it. > > Joe Goldthwaite > > -----Original Message----- > From: Niki Spahiev [mailto:niki@vintech.bg] > Sent: Tuesday, August 24, 2004 12:54 AM > To: joe@goldthwaites.com > Cc: Python-win32@python.org > Subject: Re: [python-win32] Cannot assign values to the Excel Colors > property > > > Joe Goldthwaite wrote: > > Here's another strange one. Automating Excel with Python is turning out > to > > be a little more difficult than I thought. I'm trying to set the color > > property of the workbook object. In VB it goes like this; > > > > Workbook.Colors(1) = &H254A70 > > > > When I try doing this in Python, It complains about the syntax and tells > me > > I can't assign a value to a function call. I also tried this; > > > > Workbook.Colors[1] = 0xH254A70 > > > > But it tells me "TypeError: object doesn't support item > assignment". I'm > > sure there's a way to do it but the syntax eludes me. Anyone have any > > ideas? > > > > Maybe workbook.Colors(1, 0x223344) ? > > Niki Spahiev try workbook.SetColors(1, xxx) The Colors property of the Workbook interface is an indexed property, and the Python COM support has to provide Setxxx and GetXXX methods to support the indexing. Have a look in the COM MakePy generated file for more info. Graham From graham.bloice at trihedral.com Tue Aug 24 20:45:18 2004 From: graham.bloice at trihedral.com (Graham Bloice) Date: Tue Aug 24 20:45:37 2004 Subject: [python-win32] Cannot assign values to the Excel Colors property In-Reply-To: <000401c48a05$155ecb20$6401a8c0@jgold82> Message-ID: > Graham, > > I tried the SetColors(1, xxx) but I get an error message that there is not > SetColors attribute. I looked for it in my Excel VBA language > reference and > couldn't find it there either. As I (thought I had) explained, the Python COM support doesn't directly support the VB notion of index properties, i.e. Workbook.Colors(1) = &H254A70. Colors is a property of the Workbook object that has to be indexed. The Python COM support turns the property access into a method access by prepending either Get, for a property read, or Set, for a property write to the name of the property and passing the index value as a parameter of the method. >>> xl = Dispatch("Excel.Application") >>> xl >>> xl.Visible = -1 >>> wb = xl.Workbooks.Add() >>> wb >>> wb.GetColors(2) 16777215.0 >>> wb.SetColors(2, 0) And sure enough, if I open the Format | Cells | Patterns dialog, the second color in the palette is black. Note that you can't set the color when the dialog is open. Are you sure you've run the MakePy utility on Excel ?? Graham From joe at goldthwaites.com Tue Aug 24 22:17:10 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Tue Aug 24 22:17:24 2004 Subject: [python-win32] Cannot assign values to the Excel Colors property In-Reply-To: Message-ID: <001501c48a17$56abb130$6401a8c0@jgold82> Hi Graham, Sorry, I'm still a beginner at Python and don't really understand what the MakePy utility is doing. I started off playing with it last month and was able to generate a big Excel.py file but I couldn't import it or anything. Since your sample shows that the Dispatch function is using it somehow, I went back to the Web to try and figure out what you are talking about. I found another reference that describes running MakePy from the PythonWin menu. I tried that and it created a big file in the win32com\gen_py folder under a name that looks like it's probably Excel's GUID. I gather that when you try to create an Excel application with Dispatch, it somehow finds that file and imports it. After running MakePy, the SetColors function did work! That's pretty slick. It must be doing a lot of stuff behind the scenes. Do you know if MakePy does early binding? Do you know what the performance difference is (good or bad)? Not that it matters. I'd rather have clean code than high performing code. I'll replace my Macro kludge with SetColors. I'd like to know what's going on though. Thanks for taking the time to respond. I really appreciate it. Joe Goldthwaite -----Original Message----- From: Graham Bloice [mailto:graham.bloice@trihedral.com] Sent: Tuesday, August 24, 2004 11:45 AM To: joe@goldthwaites.com Cc: python-win32@python.org Subject: RE: [python-win32] Cannot assign values to the Excel Colors property > Graham, > > I tried the SetColors(1, xxx) but I get an error message that there is not > SetColors attribute. I looked for it in my Excel VBA language > reference and > couldn't find it there either. As I (thought I had) explained, the Python COM support doesn't directly support the VB notion of index properties, i.e. Workbook.Colors(1) = &H254A70. Colors is a property of the Workbook object that has to be indexed. The Python COM support turns the property access into a method access by prepending either Get, for a property read, or Set, for a property write to the name of the property and passing the index value as a parameter of the method. >>> xl = Dispatch("Excel.Application") >>> xl >>> xl.Visible = -1 >>> wb = xl.Workbooks.Add() >>> wb >>> wb.GetColors(2) 16777215.0 >>> wb.SetColors(2, 0) And sure enough, if I open the Format | Cells | Patterns dialog, the second color in the palette is black. Note that you can't set the color when the dialog is open. Are you sure you've run the MakePy utility on Excel ?? Graham From graham.bloice at trihedral.com Wed Aug 25 11:38:47 2004 From: graham.bloice at trihedral.com (Graham Bloice) Date: Wed Aug 25 11:38:54 2004 Subject: [python-win32] Cannot assign values to the Excel Colors property In-Reply-To: <001501c48a17$56abb130$6401a8c0@jgold82> Message-ID: > Sorry, I'm still a beginner at Python and don't really understand what the > MakePy utility is doing. I started off playing with it last month and was > able to generate a big Excel.py file but I couldn't import it or anything. > Since your sample shows that the Dispatch function is using it somehow, I > went back to the Web to try and figure out what you are talking about. > > I found another reference that describes running MakePy from the PythonWin > menu. I tried that and it created a big file in the > win32com\gen_py folder > under a name that looks like it's probably Excel's GUID. I > gather that when > you try to create an Excel application with Dispatch, it somehow > finds that > file and imports it. > > After running MakePy, the SetColors function did work! That's > pretty slick. > It must be doing a lot of stuff behind the scenes. Do you know if MakePy > does early binding? Do you know what the performance difference > is (good or > bad)? Not that it matters. I'd rather have clean code than high > performing > code. I'll replace my Macro kludge with SetColors. I'd like to > know what's > going on though. > I can only point you in the usual directions for more info. See the PythonWin Help stuff (Help | Pythonwin reference), in particular the Quick start to Python COM, and of course Mark's book "Python Programming on Win32". Graham From joe at goldthwaites.com Wed Aug 25 23:36:26 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Wed Aug 25 23:36:33 2004 Subject: [python-win32] Having more Excel troubles. Message-ID: <000d01c48aeb$93ee4470$6401a8c0@jgold82> Hello Again, I thought I had all my problems worked out then I ran head on into another one. The application I've been trying to develop is Zope based. I've got some financial reports that they can browse through using a web interface. What I'm trying to do is have a link on the page that will download the report they're viewing into a local Excel worksheet. I decided to use com because I want the worksheet to have colors, print settings, formatting, etc. that I already have working in VB. I've looked into XML and Pyxlwriter but it looks like a new learning curve compared to just translating my VB com commands into Python. I'm using Visual Studio .Net 2003 with Active Python as my development environment. When I submit the URL that creates the XL worksheet in development, it works like a top. In testing, I've generated 50 different worksheets without any problems. When I try to run the same code in Zope I have problems. Under Zope, I take the submitted URL and create a worksheet that I save to a file. Then I return a meta command to redirect the browser to the newly created file which is downloaded to the users computer. The good news is that it works perfectly - sometimes. Other times I get this error message; Module ExcelReport, line 48, in __init__ Module win32com.client, line 95, in Dispatch Module win32com.client.dynamic, line 91, in _GetGoodDispatchAndUserName Module win32com.client.dynamic, line 79, in _GetGoodDispatch com_error: (-2147221008, 'CoInitialize has not been called.', None, None) I know this is probably a Zope problem but the error message is coming back from the line; XLApp = Dispatch("Excel.Application"). I'm going to post a message on the Zope developers list to see if they have any clue. The really strange thing is that the error seems to be random. Sometimes it works, sometimes it doesn't. I haven't been able to determine any rhyme or reason to it. When I restart Zope, it will work one to as many as 10 times. Then I'll get the error message. If I keep trying the same URL, it might eventually work or I may have to restart Zope to get it working again. Does anyone have any idea as to what's going on here? Thanks, Joe Goldthwaite From bgailer at alum.rpi.edu Thu Aug 26 00:37:33 2004 From: bgailer at alum.rpi.edu (Bob Gailer) Date: Thu Aug 26 00:37:36 2004 Subject: {Spam?} [python-win32] Having more Excel troubles. In-Reply-To: <000d01c48aeb$93ee4470$6401a8c0@jgold82> References: <000d01c48aeb$93ee4470$6401a8c0@jgold82> Message-ID: <6.1.0.6.0.20040825163329.04856ba8@mail.mric.net> At 03:36 PM 8/25/2004, Joe Goldthwaite wrote: >Hello Again, > >I thought I had all my problems worked out then I ran head on into another >one. The application I've been trying to develop is Zope based. I've got >some financial reports that they can browse through using a web interface. >What I'm trying to do is have a link on the page that will download the >report they're viewing into a local Excel worksheet. > >I decided to use com because I want the worksheet to have colors, print >settings, formatting, etc. that I already have working in VB. I've looked >into XML and Pyxlwriter but it looks like a new learning curve compared to >just translating my VB com commands into Python. I just remembered that sometimes I put the Excel VB code into an Excel module and invoke the module from the Python side. You might give that a try. In some cases that has saved my butt when (due to an Excel com bug) I could not set a particular property, so I wrote the VB module to set the property and called it from Python. This can also result in a performance improvement. (Especially in Word is this true). >[snip] Bob Gailer bgailer@alum.rpi.edu 303 442 2625 home 720 938 2625 cell From mhammond at skippinet.com.au Thu Aug 26 06:06:50 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu Aug 26 06:06:37 2004 Subject: [python-win32] Having more Excel troubles. In-Reply-To: <000d01c48aeb$93ee4470$6401a8c0@jgold82> Message-ID: <082801c48b22$1e0a0aa0$0200a8c0@eden> > _GetGoodDispatchAndUserName > Module win32com.client.dynamic, line 79, in _GetGoodDispatch > com_error: (-2147221008, 'CoInitialize has not been > called.', None, > None) That error means "CoInitialize has not been called *on this thread*". Try calling pythoncom.CoInitialize() at the top of your script - it should not throw an error if it has already been called. I'm not sure this is a great idea though - you would be better off creating your own thread that processes *all* excel requests, possibly using the queue module. Consider what will happen when 2 people try and perform the conversion at the same time. By using DispatchEx() you can force each thread to get its own Excel, but I'm not sure that is a great idea even then. Mark From mhammond at skippinet.com.au Thu Aug 26 10:47:39 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu Aug 26 10:47:21 2004 Subject: [python-win32] Release public header and lib files with pywin32release? In-Reply-To: Message-ID: <088401c48b49$58df5000$0200a8c0@eden> Sorry for the delay in responding: > If Mark can release the public header and lib files with each > pywin32 release, it will really help anyone trying to use Python > to work with COM objects not implementing Idispatch. It can be > put in pywin32 install just as Python installs its header and > lib files, or a separate install for those interested. It will > make extending PythonCOM so much easier. I'm afraid I am really short on time, but would happily accept patches that did this. I obviously don't need it as I always have the built versions. Anyone who needs it now must currently grab and build the source-code version - hopefully one of those people will step up to the plate, and do what is necessary to save that pain for others. Mark. From mbamford at marketpipe.com Thu Aug 26 17:21:06 2004 From: mbamford at marketpipe.com (Michael Bamford) Date: Thu Aug 26 17:36:53 2004 Subject: [python-win32] win32com error Message-ID: <200408261521.i7QFLBH05197@raq157.servercity.co.uk> As a company we are start to use python to automated testing for our web based application. I have moved our testsuite from Windows 2000 to Windows XP. When I try to run our testsuite, the first time it triggers javascript in IE 6, I get the following error com_error: (-2147024891, 'Access is denied.', None, None) I am running Python 2.3.4 & win32com 1.6.3 Can any help? Kind Regards Mike Bamford -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040826/81b824fd/attachment.htm From beast at ludens.elte.hu Thu Aug 26 18:34:56 2004 From: beast at ludens.elte.hu (=?ISO-8859-15?B?SW1yZSBBbmRy4XMgUvNiZXJ0?=) Date: Thu Aug 26 18:34:01 2004 Subject: [python-win32] Re: Windows service features and Python In-Reply-To: <08e201c4838f$92ca9b10$0200a8c0@eden> References: <08e201c4838f$92ca9b10$0200a8c0@eden> Message-ID: <892719424.20040826183456@ludens.elte.hu> Hello Mark, Monday, August 16, 2004, 2:50:12 PM, you wrote: >> Maybe we could add this to the registering method like: >> def AddSourceToRegistry(appName, msgDLL = None, eventLogType = >> "Application", eventLogFlags = None, catDLL = None, catCount = 0): > Sounds great! :) Just make a patch or if necessary, send me a the complete > modified source. >> >> I found this out only by looking at the source, as its help does >> >> not mention this switch. It would also be nice if this would >> >> support pause and continue functions. > ... >> Should I log the need for cmd line pause and continue as an RFE? > As above - I've no shortage on nice things to do :) Ok, I'd like to contribute. Namely, I will try adding the following things: - message category handling for services - cmd line pause/continue options for services - opportunity to define description for services upon install I will download the recent source, and add things. Is there anything that I should know before starting hacking? (Verification, test guidelines? I dont wanna spoil things...) -- Thanks, Andr?s From mhammond at skippinet.com.au Fri Aug 27 03:03:15 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri Aug 27 03:03:10 2004 Subject: [python-win32] Re: Windows service features and Python In-Reply-To: <892719424.20040826183456@ludens.elte.hu> Message-ID: <0ad901c48bd1$ae31edf0$0200a8c0@eden> > Ok, I'd like to contribute. Namely, I will try adding the > following things: > - message category handling for services > - cmd line pause/continue options for services > - opportunity to define description for services upon install Sounds good! > I will download the recent source, and add things. Is there anything > that I should know before starting hacking? (Verification, test > guidelines? I dont wanna spoil things...) Not really - I just install the test service, and quickly test it. I would *love* to have a new win32\test\test_service test - it could install the sample service, flex start/stop/pause, and a number of other cool things. Feel free to mail me with questions. Mark. From amonroe at columbus.rr.com Fri Aug 27 15:20:39 2004 From: amonroe at columbus.rr.com (R. Alan Monroe) Date: Fri Aug 27 15:20:45 2004 Subject: [python-win32] Newbie question - how do I use the constants generated by makepy? Message-ID: <113125688881.20040827092039@columbus.rr.com> I'm trying to use ADODB from Python, but it's not clear to me how I'm supposed to access the constants for various enums... Traceback (most recent call last): File "adotest.py", line 10, in ? conn.CursorLocation = adUseClient NameError: name 'adUseClient' is not defined Am I supposed to manually import the EF53050B-882E-4776-B643-EDA472E8E3F2x0x2x7.py file that makepy generated at the top of my own program, or is it supposed to get automagically imported when I call win32com.client.Dispatch? If it's automatic, how do I get at the constants? Alan From mbamford at marketpipe.com Fri Aug 27 15:51:25 2004 From: mbamford at marketpipe.com (Michael Bamford) Date: Fri Aug 27 16:21:34 2004 Subject: [python-win32] win32com error Message-ID: <200408271351.i7RDpUH04035@raq157.servercity.co.uk> As a company we are start to use python to automated testing for our web based application. I have moved our testsuite from Windows 2000 to Windows XP. When I try to run our testsuite, the first time it triggers javascript in IE 6, I get the following error com_error: (-2147024891, 'Access is denied.', None, None) I am running Python 2.3.4 & win32com 1.6.3. PLEASE NOTE - this has only begun occurring since we applied SP2 to XP. Can anybody help? Kind Regards Mike Bamford -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040827/75875771/attachment.htm From tim.golden at viacom-outdoor.co.uk Fri Aug 27 17:46:43 2004 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Fri Aug 27 17:50:36 2004 Subject: [python-win32] wmi + pythonservice : multithreading issues Message-ID: Sorry, just got back off a three-week long course, so I've only just picked up this thread. It seems as though the dust has now settled on your original question and the responses. Could I just clarify the main points you initially raised re WMI / threading and Services. As I understand it: 1) You're using WMI in a service 2) The service framework implicitly starts a separate thread inside which you're doing some WMI work. 3) As a result of this threading, a WMI syntax? error is thrown. Have I understood correctly? The thing is that I have successfully used WMI inside a (near-trivial) service, and -- although I can't at the moment find my code -- inside a (near-trivial) thread, both times without any problems. I'm running Python 2.3 on Win2K. Additionally, I can't really understand why a WMI syntax error should result, as opposed to some sort of runtime error. If it's possible, I'd be interested to see the code which caused the error, or at least to narrow down the possibilities. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From jens.jorgensen at tallan.com Fri Aug 27 18:32:39 2004 From: jens.jorgensen at tallan.com (Jens B. Jorgensen) Date: Fri Aug 27 18:32:54 2004 Subject: [python-win32] Newbie question - how do I use the constantsgenerated by makepy? In-Reply-To: <113125688881.20040827092039@columbus.rr.com> References: <113125688881.20040827092039@columbus.rr.com> Message-ID: <412F6227.60501@tallan.com> Constants are a bit of a problm in COM because in point of fact they have nothing to do with the COM interface per se. COM constants are actually laid out in type libraries. If you're run makepy.py and selected the correct type library then when you create an instance of that object then the constant you are after is in: win32com.client.constants.adUseClient R. Alan Monroe wrote: >I'm trying to use ADODB from Python, but it's not clear to me how I'm >supposed to access the constants for various enums... > >Traceback (most recent call last): > File "adotest.py", line 10, in ? > conn.CursorLocation = adUseClient >NameError: name 'adUseClient' is not defined > >Am I supposed to manually import the >EF53050B-882E-4776-B643-EDA472E8E3F2x0x2x7.py file that makepy >generated at the top of my own program, or is it supposed to get >automagically imported when I call win32com.client.Dispatch? If it's >automatic, how do I get at the constants? > >Alan > >_______________________________________________ >Python-win32 mailing list >Python-win32@python.org >http://mail.python.org/mailman/listinfo/python-win32 > > -- Jens B. Jorgensen jens.jorgensen@tallan.com "With a focused commitment to our clients and our people, we deliver value through customized technology solutions" -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/x-pkcs7-signature Size: 2861 bytes Desc: S/MIME Cryptographic Signature Url : http://mail.python.org/pipermail/python-win32/attachments/20040827/704547cb/smime.bin From ewang at esri.com Fri Aug 27 18:37:37 2004 From: ewang at esri.com (Enzhou Wang) Date: Fri Aug 27 18:37:54 2004 Subject: [python-win32] win32com error Message-ID: I heard of SP2 closes "unused" ports for you. Maybe the error has something to do with it? Enzhou Wang _____ From: Michael Bamford [mailto:mbamford@marketpipe.com] Sent: Friday, August 27, 2004 6:51 AM To: python-win32@python.org Subject: [python-win32] win32com error As a company we are start to use python to automated testing for our web based application. I have moved our testsuite from Windows 2000 to Windows XP. When I try to run our testsuite, the first time it triggers javascript in IE 6, I get the following error com_error: (-2147024891, 'Access is denied.', None, None) I am running Python 2.3.4 & win32com 1.6.3. PLEASE NOTE - this has only begun occurring since we applied SP2 to XP. Can anybody help? Kind Regards Mike Bamford -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20040827/a6c6c865/attachment.htm From joe at goldthwaites.com Fri Aug 27 19:50:56 2004 From: joe at goldthwaites.com (Joe Goldthwaite) Date: Fri Aug 27 19:51:20 2004 Subject: [python-win32] Having more Excel troubles. In-Reply-To: <082801c48b22$1e0a0aa0$0200a8c0@eden> Message-ID: <004101c48c5e$67da22e0$6401a8c0@jgold82> Hi Mark, I didn't expect you to reply. I checked the archive and see that you're very active on the list. That's great! I changed from Dispatch() to DispatchEx() since that sounds like the better choice for my application. It didn't fix the problem though. The pythoncom.CoInitialize() seems to have done the trick. Thank you very much for your help. And thanks all your work on the Win32 stuff. I ordered a copy of your book. Thanks for taking the time to write it. I'm still new in the open source arena and one of the biggest challenges is figuring how to get this stuff to work. Joe Goldthwaite -----Original Message----- From: Mark Hammond [mailto:mhammond@skippinet.com.au] Sent: Wednesday, August 25, 2004 9:07 PM To: joe@goldthwaites.com; python-win32@python.org Subject: RE: [python-win32] Having more Excel troubles. > _GetGoodDispatchAndUserName > Module win32com.client.dynamic, line 79, in _GetGoodDispatch > com_error: (-2147221008, 'CoInitialize has not been > called.', None, > None) That error means "CoInitialize has not been called *on this thread*". Try calling pythoncom.CoInitialize() at the top of your script - it should not throw an error if it has already been called. I'm not sure this is a great idea though - you would be better off creating your own thread that processes *all* excel requests, possibly using the queue module. Consider what will happen when 2 people try and perform the conversion at the same time. By using DispatchEx() you can force each thread to get its own Excel, but I'm not sure that is a great idea even then. Mark From -= Sat Aug 28 15:55:11 2004 From: -= (-=) Date: Sat Aug 28 15:55:20 2004 Subject: [python-win32] Some compile hints for Win32 Message-ID: Hello! I'm newbie in Python, but i've already understood it's power! I prefer to use own built Python (I use MSVC 6 on Win98) & want to share some win32's compile hints with Python community. Tips: ----- 1. Use /FILEALIGN:0x200 linker option on every .pyd, .exe, .dll file to remove empty space between PE sections (Is it MS linker bug on Win98?). -------------------------------------------------------------------------- 2. To build _bsddb.pyd you just need to build a "db_static" project in Berkeley_DB Workspace and not WHOLE "build_all". Change properties of "db_static" to "Multithreaded DLL" (/MD option of compiler) and you will NOT get this message: " LINK : warning LNK4049: locally defined symbol "_malloc" imported LINK : warning LNK4049: locally defined symbol "_free" imported LINK : warning LNK4049: locally defined symbol "_fclose" imported LINK : warning LNK4049: locally defined symbol "_fopen" imported " Of course, your Python's _bsddb.pyd must have the same /MD option and NOT "ignore msvcrt lib" ------------------- 3. I prefer to build _ssl module manually with this steps: in OPENSSL dir: a) perl configure VC-WIN32 b) ms\do_nasm.bat i use nasm to compile asm modules. just place nasmw.exe in somewhere in "PATH" dir before compile. c) nmake -f ms\nt.mak after OPENSSL've finished change current dir to Python's build dir and find "_ssl.mak" d) SET SSL_DIR=your OPENSSL dir e) nmake -f _ssl.mak (you may add /FILEALIGN:0x200 option in .mak file as mentioned above) ------------------- 4. You can use UPX with "--best" option to pack all .exe,.pyd,.dll files into small ones. For very greedy persons: you can use realign tools like PEditor, LordPE to rebuild and realign files after UPX compression (saves 100-700 bytes ;) ) ------------------------- 5. You can build Tcl+Tk with "threads" option, just do not forget to change "tcl84.lib" and "tk84.lib" in "_tkinter" project to "tcl84t.lib" and "tk84t.lib" respectively. ------------------------- 6. Of course, you can use newer versions of Berkeley DB, Tcl+Tk, Zlib in your Python's modules - just do not forget to change path and name of import libs. ------------ 7. That's all for now! Sorry for my bad English :( Good luck to all Python's community!!! From aloys at alamaison.fr Mon Aug 30 09:34:24 2004 From: aloys at alamaison.fr (Aloys Baillet) Date: Mon Aug 30 09:34:43 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues In-Reply-To: References: Message-ID: Hello Tim, Thank you for replying! As you said, I allready managed to get some code working to retrieve performance infos using the registry directly. And you have well understood my problem! So I wrote a very tiny test you can maybe run on your config, just to see if it's just me that hear voices... ;) import wmi import threading class lmPerformancesInfos(threading.Thread): def __init__(self): threading.Thread.__init__(self) print 'In Main Thread' c = wmi.WMI () for process in c.Win32_Process (): print process.ProcessId, process.Name def run(self): print 'In Another Thread...' c = wmi.WMI () while 1: for process in c.Win32_Process (): print process.ProcessId, process.Name if __name__ == '__main__': perfs = lmPerformancesInfos() perfs.start() And the result was: In Main Thread 0 System Idle Process 8 System [...] 1500 soffice.exe 1508 thunderbird.exe 1544 CMD.EXE 600 firefox.exe 1400 python.exe In Another Thread... D:\Python23\lib\site-packages\wmi.py:126: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4 and up exception_string = ["%s - %s" % (hex (hresult_code), hresult_name)] Exception in thread Thread-1: Traceback (most recent call last): File "D:\Python23\lib\threading.py", line 436, in __bootstrap self.run() File "Q:\Perforce\aloys\tools\lmRenderFarm\Tests\wmi_thread.py", line 14, in run c = wmi.WMI () File "D:\Python23\Lib\site-packages\wmi.py", line 519, in __init__ handle_com_error (error_info) File "D:\Python23\Lib\site-packages\wmi.py", line 131, in handle_com_error raise x_wmi, "\n".join (exception_string) x_wmi: 0x800401e4 - Syntaxe incorrecte Et voil?! Maybe the fact that my Windows version is french causes problems? Anyway, here is my config : Win2k SP4, 2 AMD CPUs, 2Gb RAM, Python 2.3.4 Don't hesitate to ask if you need more details! -- Aloys Baillet - R&D @ La Maison - http://www.alamaison.fr Tim Golden wrote: > Sorry, just got back off a three-week long course, so > I've only just picked up this thread. It seems as though > the dust has now settled on your original question and > the responses. Could I just clarify the main points you > initially raised re WMI / threading and Services. > > As I understand it: > > 1) You're using WMI in a service > > 2) The service framework implicitly starts a > separate thread inside which you're doing > some WMI work. > > 3) As a result of this threading, a WMI syntax? > error is thrown. > > Have I understood correctly? > > The thing is that I have successfully used WMI inside > a (near-trivial) service, and -- although I can't at > the moment find my code -- inside a (near-trivial) > thread, both times without any problems. I'm running > Python 2.3 on Win2K. > > Additionally, I can't really understand why a WMI > syntax error should result, as opposed to some sort > of runtime error. > > If it's possible, I'd be interested to see the code > which caused the error, or at least to narrow down > the possibilities. > > TJG > > ________________________________________________________________________ > This e-mail has been scanned for all viruses by Star Internet. The > service is powered by MessageLabs. For more information on a proactive > anti-virus service working around the clock, around the globe, visit: > http://www.star.net.uk > ________________________________________________________________________ From mc at mclaveau.com Mon Aug 30 11:00:33 2004 From: mc at mclaveau.com (Michel Claveau) Date: Mon Aug 30 11:00:40 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues References: Message-ID: <000401c48e6f$d0a7fa00$0701a8c0@PORTABLES> Bonjour ! Ce message : "FutureWarning: XXX int will return a signed string in Python 2.4 and up", je l'ai (trop) souvent. Et je ne comprend pas du tout ? quoi ?a correspond. J'ai bien post? des messages sur fclp et sur clp, mais ils sont rest?s sans r?ponse. @-salutations -- Michel Claveau From aloys at alamaison.fr Mon Aug 30 11:18:34 2004 From: aloys at alamaison.fr (Aloys Baillet) Date: Mon Aug 30 11:18:39 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues In-Reply-To: <000401c48e6f$d0a7fa00$0701a8c0@PORTABLES> References: <000401c48e6f$d0a7fa00$0701a8c0@PORTABLES> Message-ID: Bonjour! As this "Future Warning" thing seems to come from win32com, sure that Mark Hammond knows about it. One of my Python usage is scripting in the 3D app named XSI, based on Mark's work, I also get this warning quite often. Personnaly I really don't care about it, but I heard some of my script users complaining about wierd warning messages... This is the fear of the unknown... Anyway, I would suggest those messages come from the code generated by makepy, as this warning appears when the classes in the sites-package\win32com\genpy folder are loaded. But its only a guess! Aloys Michel Claveau wrote: > Bonjour ! > > > Ce message : "FutureWarning: XXX int will return a signed string in Python > 2.4 and up", > je l'ai (trop) souvent. Et je ne comprend pas du tout ? quoi ?a correspond. > > J'ai bien post? des messages sur fclp et sur clp, mais ils sont rest?s sans > r?ponse. > > @-salutations From mhammond at skippinet.com.au Tue Aug 31 00:28:47 2004 From: mhammond at skippinet.com.au (Mark Hammond) Date: Tue Aug 31 00:28:17 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issues In-Reply-To: Message-ID: <024d01c48ee0$b7549a10$0200a8c0@eden> > As this "Future Warning" thing seems to come from win32com, sure that > Mark Hammond knows about it. Actually, the warning in your original message was: D:\Python23\lib\site-packages\wmi.py:126: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4 and up exception_string = ["%s - %s" % (hex (hresult_code), hresult_name)] Which looks like it is in wmi.py, not win32com. A "hex()" on a COM error code will almost always yield that error (as all COM error codes are negative) I believe almost all furture warnings are removed from win32com (but also believe one or 2 obscure cases still exist). I'd be happy to get mail when you hit one. Mark. From tim.golden at viacom-outdoor.co.uk Tue Aug 31 09:42:24 2004 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue Aug 31 09:46:25 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issue s Message-ID: | > As this "Future Warning" thing seems to come from win32com, | sure that | > Mark Hammond knows about it. | | Actually, the warning in your original message was: | | D:\Python23\lib\site-packages\wmi.py:126: FutureWarning: | hex()/oct() of | negative int will return a signed string in Python 2.4 and up | exception_string = ["%s - %s" % (hex (hresult_code), hresult_name)] | | Which looks like it is in wmi.py, not win32com. Just to clarify, the warning clearly arises from my hex (hresult_code). For those who don't know, doing this in Python <= 2.3.x: print hex (-1) will generate this (wrapped slightly for readability): Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print hex (-1) __main__:1: FutureWarning: hex()/oct() of negative int will return a signed string in Python 2.4 and up 0xffffffff >>> Since my code is calling hex() on the hresult, you'll always get this error unless you use the warnings module to disable it. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From tim.golden at viacom-outdoor.co.uk Tue Aug 31 10:39:57 2004 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue Aug 31 10:43:50 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issue s Message-ID: [Aloys Baillet] | | import wmi | import threading | | class lmPerformancesInfos(threading.Thread): | def __init__(self): | threading.Thread.__init__(self) | print 'In Main Thread' | c = wmi.WMI () | for process in c.Win32_Process (): | print process.ProcessId, process.Name | | def run(self): | print 'In Another Thread...' | c = wmi.WMI () | while 1: | for process in c.Win32_Process (): | print process.ProcessId, process.Name | | if __name__ == '__main__': | perfs = lmPerformancesInfos() | perfs.start() | | [... snip resulting error ...] Well, a couple of things occur to me here, one definitely pertinent, the other less so. First, whenever you're using COM/DCOM in anything other than the main thread of a program, you need to call pythoncom.CoInitialize () first. Just one of those things. Secondly, I'm not sure that you entirely understand the way the threading.Thread class is supposed to work. There are, of course, several ways to do things, but the usual approach is to create one or more subthreads from the main program thread (ie from what you usually think of as the program) and then to start those threads. By virtue of the way Python works, anything in the Thread __init__ will in effect be called in the main thread, before the subthread has started, but it's not the most logical place. The code below does, I believe, what your code sample did, and doesn't give any errors. import pythoncom import wmi import threading class lmPerformancesInfos(threading.Thread): def __init__(self): threading.Thread.__init__(self) def run(self): print 'In Another Thread...' pythoncom.CoInitialize () c = wmi.WMI () while 1: for process in c.Win32_Process (): print process.ProcessId, process.Name if __name__ == '__main__': print 'In Main Thread' c = wmi.WMI () for process in c.Win32_Process (): print process.ProcessId, process.Name perfs = lmPerformancesInfos() perfs.start() Having said all that, I've not encountered this particular problem in a service, with or without a CoInitialize. For example, the following code works: import os, sys import threading import time import win32serviceutil import win32service import win32event import wmi class Service (win32serviceutil.ServiceFramework): _svc_name_ = "WMIService" _svc_display_name_ = "WMI Service" def __init__ (self, args): win32serviceutil.ServiceFramework.__init__ (self, args) self.hWaitStop = win32event.CreateEvent (None, 0, 0, None) self.computer = wmi.WMI () open ("c:/temp/wmi-service.log", "w").write ("Started at %s\n" % time.asctime ()) def SvcStop (self): self.ReportServiceStatus (win32service.SERVICE_STOP_PENDING) win32event.SetEvent (self.hWaitStop) def SvcDoRun (self): while 1: result = win32event.WaitForSingleObject (self.hWaitStop, 5000) if result == win32event.WAIT_TIMEOUT: f = open ("c:/temp/wmi-service.log", "a") f.write ("%s\n" % time.asctime ()) for i in self.computer.Win32_Process (): f.write ("%s\n" % i.Caption) f.close () else: open ("c:/temp/wmi-service.log", "a").write ("Finished at %s\n" % time.asctime ()) break if __name__ == '__main__': win32serviceutil.HandleCommandLine (Service) I realise that by now you'll have implemented your performance code some other way, but I did want to take the opportunity to track down problems with WMI if there were any. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From aloys at alamaison.fr Tue Aug 31 11:19:02 2004 From: aloys at alamaison.fr (Aloys Baillet) Date: Tue Aug 31 11:19:07 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issue s In-Reply-To: References: Message-ID: Thank you very much for your explainations! I was'n aware of this pythoncom.CoInitialize function. For the threading thing, you are absolutely right, and I don't usually do things like that, it was just a quick and dirty test script to show you my problem... And finally, for the service, I didn't try with the pywin32 service, and I totally believe you if you say it works. I just forgot to say that I use the py2exe module to generate my service, and I did get the same error with it... I will try with the CoInitialize to see if it works! Again, thank you for the time you spent on my problem, and for your kindness in showing me my errors! -- Aloys Baillet - R&D @ La Maison Tim Golden wrote: > [Aloys Baillet] > | > | import wmi > | import threading > | > | class lmPerformancesInfos(threading.Thread): > | def __init__(self): > | threading.Thread.__init__(self) > | print 'In Main Thread' > | c = wmi.WMI () > | for process in c.Win32_Process (): > | print process.ProcessId, process.Name > | > | def run(self): > | print 'In Another Thread...' > | c = wmi.WMI () > | while 1: > | for process in c.Win32_Process (): > | print process.ProcessId, process.Name > | > | if __name__ == '__main__': > | perfs = lmPerformancesInfos() > | perfs.start() > | > | > > [... snip resulting error ...] > > Well, a couple of things occur to me here, one > definitely pertinent, the other less so. > > First, whenever you're using COM/DCOM in anything other > than the main thread of a program, you need to call > pythoncom.CoInitialize () first. Just one of those things. > > Secondly, I'm not sure that you entirely understand the > way the threading.Thread class is supposed to work. There > are, of course, several ways to do things, but the usual > approach is to create one or more subthreads from the main > program thread (ie from what you usually think of as the > program) and then to start those threads. By virtue of the > way Python works, anything in the Thread __init__ will in > effect be called in the main thread, before the subthread > has started, but it's not the most logical place. > > The code below does, I believe, what your code sample > did, and doesn't give any errors. > > > import pythoncom > import wmi > import threading > > class lmPerformancesInfos(threading.Thread): > def __init__(self): > threading.Thread.__init__(self) > > def run(self): > print 'In Another Thread...' > pythoncom.CoInitialize () > c = wmi.WMI () > while 1: > for process in c.Win32_Process (): > print process.ProcessId, process.Name > > if __name__ == '__main__': > print 'In Main Thread' > c = wmi.WMI () > for process in c.Win32_Process (): > print process.ProcessId, process.Name > > perfs = lmPerformancesInfos() > perfs.start() > > > Having said all that, I've not encountered this particular > problem in a service, with or without a CoInitialize. For > example, the following code works: > > > import os, sys > import threading > import time > > import win32serviceutil > import win32service > import win32event > > import wmi > > class Service (win32serviceutil.ServiceFramework): > _svc_name_ = "WMIService" > _svc_display_name_ = "WMI Service" > > def __init__ (self, args): > win32serviceutil.ServiceFramework.__init__ (self, args) > self.hWaitStop = win32event.CreateEvent (None, 0, 0, None) > self.computer = wmi.WMI () > open ("c:/temp/wmi-service.log", "w").write ("Started at %s\n" % > time.asctime ()) > > def SvcStop (self): > self.ReportServiceStatus (win32service.SERVICE_STOP_PENDING) > win32event.SetEvent (self.hWaitStop) > > def SvcDoRun (self): > while 1: > result = win32event.WaitForSingleObject (self.hWaitStop, 5000) > if result == win32event.WAIT_TIMEOUT: > f = open ("c:/temp/wmi-service.log", "a") > f.write ("%s\n" % time.asctime ()) > for i in self.computer.Win32_Process (): > f.write ("%s\n" % i.Caption) > f.close () > else: > open ("c:/temp/wmi-service.log", "a").write ("Finished at %s\n" % > time.asctime ()) > break > > if __name__ == '__main__': > win32serviceutil.HandleCommandLine (Service) > > > I realise that by now you'll have implemented your performance > code some other way, but I did want to take the opportunity to > track down problems with WMI if there were any. > > TJG > > ________________________________________________________________________ > This e-mail has been scanned for all viruses by Star Internet. The > service is powered by MessageLabs. For more information on a proactive > anti-virus service working around the clock, around the globe, visit: > http://www.star.net.uk > ________________________________________________________________________ From tim.golden at viacom-outdoor.co.uk Tue Aug 31 11:32:49 2004 From: tim.golden at viacom-outdoor.co.uk (Tim Golden) Date: Tue Aug 31 11:36:43 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issue s Message-ID: [Aloys Baillet] | Thank you very much for your explainations! | I was'n aware of this pythoncom.CoInitialize function. | For the threading thing, you are absolutely right, and I don't usually | do things like that, it was just a quick and dirty test script to show | you my problem... | And finally, for the service, I didn't try with the pywin32 | service, and | I totally believe you if you say it works. I just forgot to say that I | use the py2exe module to generate my service, and I did get the same | error with it... I will try with the CoInitialize to see if it works! | Again, thank you for the time you spent on my problem, and for your | kindness in showing me my errors! Not at all, that's the point of a community. Goodness knows, I've had enough help from people on this and on the main Python list. I'm only too happy to put something back in. TJG ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ From theller at python.net Tue Aug 31 22:12:28 2004 From: theller at python.net (Thomas Heller) Date: Tue Aug 31 22:12:35 2004 Subject: [python-win32] Re: wmi + pythonservice : multithreading issue s References: Message-ID: <1xhnt6c3.fsf@python.net> Aloys Baillet writes: > And finally, for the service, I didn't try with the pywin32 service, and > I totally believe you if you say it works. I just forgot to say that I > use the py2exe module to generate my service, and I did get the same > error with it... I will try with the CoInitialize to see if it works! py2exe makes it easy (I believe ;) to create an executable, but you should only make an exe after you are absolutely sure that you code works in Python as expected. Thomas