From farplagek at gmail.com Tue Apr 1 16:00:58 2008 From: farplagek at gmail.com (Khalid MOULFI) Date: Tue, 1 Apr 2008 18:00:58 +0400 Subject: [python-win32] Wanted to get many kind of infos through Active directory. Message-ID: <7ad508500804010700u6517f06dr3052c5168b83afab@mail.gmail.com> Dear all, we have an active directory on win2000. We use Python 2.2.1. As more and more infos are in our AD, I would like to manage this AD database using Python scipts (Who are there?Which group?Create users?...) I used scripts of TJG (Tim) and I had the following : import active_directory me = active_directory.AD_object ("LDAP://OU=Service Point 17,OU=Unprivileged Users,OU=OSUsers,OU=OSDirectory,DC=toto,DC=fr") me = active_directory.AD_object (GetObject ("LDAP://OU=place1,OU=Unprivileged Users,OU=OSUsers,OU=OSDirectory,DC=toto,DC=fr")) # # Historical method # me = active_directory.AD_object (path="LDAP://OU=place1,OU=Unprivileged Users,OU=OSUsers,OU=OSDirectory,DC=toto,DC=fr") ============================================================================================================================================ but i have : Traceback (most recent call last): File "tyty.py", line 3, in ? me = active_directory.AD_object ("LDAP://OU=Service Point 17,OU=Unprivileged Users,OU=OSUsers,OU=OSDirectory,DC=toto,DC=fr") File "C:\Documents and Settings\khalid\Desktop\Python\modules\active_directory.py", line 263, in __init__ schema = GetObject (self.com_object.Schema) AttributeError: 'str' object has no attribute 'Schema' >Exit code: 1 this test has been done with active_directory version 0.4 and with active_directory version 0.6.7 I have he following error : Traceback (most recent call last): File "tyty.py", line 1, in ? import active_directory File "C:\Documents and Settings\khalid\Desktop\Python\modules\active_directory.py", line 361 return set (name for (bitmask, name) in enum.item_numbers () if item & bitmask) ^ SyntaxError: invalid syntax If anyone can help thanks in advance, Regards, Khalid -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080401/4a885e52/attachment.htm From mail at timgolden.me.uk Tue Apr 1 16:34:28 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 01 Apr 2008 15:34:28 +0100 Subject: [python-win32] Wanted to get many kind of infos through Active directory. In-Reply-To: <7ad508500804010700u6517f06dr3052c5168b83afab@mail.gmail.com> References: <7ad508500804010700u6517f06dr3052c5168b83afab@mail.gmail.com> Message-ID: <47F247F4.10106@timgolden.me.uk> Khalid MOULFI wrote: > we have an active directory on win2000. We use Python 2.2.1. Thanks for reminding me about this, Khalid. I didn't notice before [in private email] that you were using Python 2.2.1. In short I don't think I was considering pre-2.4 installations when I wrote the code. This really should be noted on the web page. I'll come back to that in a moment. You definitely want to use the latest version, by the way; there are a lot of differences. (Improvements, I hope). OK. I've had a look at backporting the code. It's really quite hard. Not impossible, given time, but I've been very free with things like dict (a=1, b=2) as well as sets and the datetime module. None of it's insurmountable, and if you really can't upgrade I'll have a go at making the whole thing work under 2.2, but only if you have no choice :) Let me know TJG From vernondcole at gmail.com Tue Apr 1 17:02:30 2008 From: vernondcole at gmail.com (Vernon Cole) Date: Tue, 1 Apr 2008 09:02:30 -0600 Subject: [python-win32] FTP Task Schedule in Python In-Reply-To: <16296683.post@talk.nabble.com> References: <47E8C5BF.4040407@timgolden.me.uk> <16296683.post@talk.nabble.com> Message-ID: On Windows (XP for example) Run the menu sequence: START -- All Programs -- Accessories -- System Tools -- Scheduled Tasks Click the "Add Scheduled Task" icon. A wizard will start. You will need to browse for the python script, .exe or .bat file you want to run. If the python script requires command line parameters, you will have to build a long command line starting with your python executable (C:\Python25\python.exe C:\utils\myscript.py firstarg secondarg) using the "advanced" checkbox. The catch here is that there is no "stdout", so you get no console output to see what your batch job did. I have cobbled together some code which redirects stdout to a log file, then emails me the log. I also have one which reads a .bat file and logs the result. If there is interest, I could clean it up and publish it. -- Vernon Cole On Wed, Mar 26, 2008 at 1:15 AM, dylan.travis wrote: > > Hi All, > > Thanks for the prompt reply. But the catch here is I am not well-versed > with > any of the things mentioned by TJG & that is the reason I had to take help > of this forum. Still I'll have a look into the scheduled task for WINDOWS. > > If any bothers me I'll just post a new message here. > > Thanks Again > > > > > > Tim Golden-4 wrote: > > > > K-Factory wrote: > >> I need to automate a scheduled weekly task i.e. downloading a file from > >> FTP. > >> This is to be done on WINDOWS but I am unable to make any further > >> development on this as I am stuck with the python scheduler itself. Can > >> somebody help me with this, I just need a skeleton of code further > things > >> I > >> can personally input. Also can any one provide me with the link for any > >> such > >> scheduler code or project. > > > > Is there some reason why you couldn't use either the > > AT service or the Scheduled Tasks service from within > > Windows itself? Both are scriptable from the command > > line and elsewhere and the pywin32 packages include an > > interface to Scheduled Tasks. > > > > TJG > > _______________________________________________ > > python-win32 mailing list > > python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > > > > -- > View this message in context: > http://www.nabble.com/FTP-Task-Schedule-in-Python-tp16268345p16296683.html > Sent from the Python - python-win32 mailing list archive at Nabble.com. > > _______________________________________________ > python-win32 mailing list > python-win32 at 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/20080401/ea591fdd/attachment.htm From marcus at internetnowasp.net Tue Apr 1 13:32:26 2008 From: marcus at internetnowasp.net (Marcus Low) Date: Tue, 1 Apr 2008 19:32:26 +0800 Subject: [python-win32] A shameless COM question Message-ID: <670C45E1CDC44E99A742D6543FB18733@ToolBox> Hi, I am aggressively trying to try and use python for my team's sub commercial project. However we are using a com component and i have the example given in C#. It looks very simple to use and elegent in C# but i need to do the same in python (minus the GUI of course) The C# example is : http://www.internetnow.com.my/download/marcus/Csharp.txt I have generated from makepy the file : http://www.internetnow.com.my/download/marcus/from_genpy.txt How do i even begin to use the same "event" notification in Pytonwin? I have resorted to ask this shameless question given that my COM knowledge is kinda rusty and i could only go as far as : SmtpMail = win32com.client.Dispatch("WeOnlyDo.wodSmtpServerCom.1") SmtpMail.Start() win32gui.PumpMessages() Kindly advise dear Gurus. Marcus. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080401/fb2fa983/attachment.htm From timr at probo.com Wed Apr 2 00:07:01 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 01 Apr 2008 15:07:01 -0700 Subject: [python-win32] A shameless COM question In-Reply-To: <670C45E1CDC44E99A742D6543FB18733@ToolBox> References: <670C45E1CDC44E99A742D6543FB18733@ToolBox> Message-ID: <47F2B205.4080405@probo.com> Marcus Low wrote: > Hi, > > I am aggressively trying to try and use python for my team's sub > commercial project. However we are using a com component and i have the > example given in C#. It looks very simple to use and elegent in C# but > i need to do the same in python (minus the GUI of course) > > The C# example is : > http://www.internetnow.com.my/download/marcus/Csharp.txt > > I have generated from makepy the file : > http://www.internetnow.com.my/download/marcus/from_genpy.txt > > How do i even begin to use the same "event" notification in Pytonwin? > I have resorted to ask this shameless question given that > my COM knowledge is kinda rusty and i could only go as far as : > > SmtpMail = win32com.client.Dispatch("WeOnlyDo.wodSmtpServerCom.1") > SmtpMail.Start() > win32gui.PumpMessages() Please allow me to steer to conversation in a slightly different direction. The code you posted shows using that COM component to create a very simple SMTP server. There are MANY ways of solving that problem in Python without resorting to complicated external components. If the problem you are trying to solve really is just the creation of an SMTP server, then forget about the COM component, and start searching for Pythonic solutions. The Twisted module, for example, makes something like this almost trivial. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From marcus at internetnowasp.net Wed Apr 2 03:11:56 2008 From: marcus at internetnowasp.net (Marcus Low) Date: Wed, 2 Apr 2008 09:11:56 +0800 Subject: [python-win32] A shameless COM question In-Reply-To: <47F2B205.4080405@probo.com> References: <670C45E1CDC44E99A742D6543FB18733@ToolBox> <47F2B205.4080405@probo.com> Message-ID: Hi Tim, Thank you for the alternative view, yes i have the twisted downloaded and inspecting it prior to this question. My only concern would be this is because the said COM component is made to run optimally in Windows and i am not sure i have the same assurance when it comes to Twisted. I needed the events because i need to inspect and log in nearly every level of the smtp transaction so just creating a simple smtp was not the goal, the goal is to create a full fledge mail server with crazy control and logging. I am not familiar with how Twisted is implemented in Windows, if it uses the specific windows apis and asynch model winsock2 directly for optimal performance. So do you still think i should stick with twisted? I am all open for suggestions. Marcus. ----- Original Message ----- From: "Tim Roberts" To: "Python-Win32 List" Sent: Wednesday, April 02, 2008 6:07 AM Subject: Re: [python-win32] A shameless COM question > Marcus Low wrote: >> Hi, >> >> I am aggressively trying to try and use python for my team's sub >> commercial project. However we are using a com component and i have the >> example given in C#. It looks very simple to use and elegent in C# but >> i need to do the same in python (minus the GUI of course) >> >> The C# example is : >> http://www.internetnow.com.my/download/marcus/Csharp.txt >> >> I have generated from makepy the file : >> http://www.internetnow.com.my/download/marcus/from_genpy.txt >> >> How do i even begin to use the same "event" notification in Pytonwin? >> I have resorted to ask this shameless question given that >> my COM knowledge is kinda rusty and i could only go as far as : >> >> SmtpMail = win32com.client.Dispatch("WeOnlyDo.wodSmtpServerCom.1") >> SmtpMail.Start() >> win32gui.PumpMessages() > > Please allow me to steer to conversation in a slightly different > direction. The code you posted shows using that COM component to create > a very simple SMTP server. There are MANY ways of solving that problem > in Python without resorting to complicated external components. If the > problem you are trying to solve really is just the creation of an SMTP > server, then forget about the COM component, and start searching for > Pythonic solutions. The Twisted module, for example, makes something > like this almost trivial. > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From waldemar.osuch at gmail.com Wed Apr 2 08:12:54 2008 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Wed, 2 Apr 2008 00:12:54 -0600 Subject: [python-win32] A shameless COM question In-Reply-To: References: <670C45E1CDC44E99A742D6543FB18733@ToolBox> <47F2B205.4080405@probo.com> Message-ID: <6fae95540804012312q7c10fa76vb021b5c68650c0bc@mail.gmail.com> On Tue, Apr 1, 2008 at 7:11 PM, Marcus Low wrote: > Hi Tim, > > Thank you for the alternative view, yes i have the twisted downloaded and > inspecting it prior to this question. > My only concern would be this is because the said COM component is made to > run optimally in Windows and i am not sure i have the same > assurance when it comes to Twisted. Nobody will give assurances I am afraid but I can give you anecdotal evidence. I have a number of Twisted based services running in Windows environment reliably for years. One of them is even based on smtp.SMTPFactory. Admittedly it does not need to be high performance. It listens for emails and then dispatches requested Scheduled Task on the batch server. > I needed the events because i need to > inspect and log in nearly every level of the smtp transaction so just > creating > a simple smtp was not the goal, the goal is to create a full fledge mail > server with crazy control and logging. If control and logging is you main goal I would definitely recommend Twisted. > I am not familiar with how Twisted is implemented in Windows, if it uses the > specific windows apis and asynch model winsock2 directly for optimal > performance. > > So do you still think i should stick with twisted? Well, it depends. In my case sticking with Twisted worked but your situation maybe different. Are you are the only Python guy in the sea of .Net programmers? Do you have to fight political battles about technology in your office? Is the deadline looming? Do you have patience to learn "Twisted way" of programming? Check out http://twistedmatrix.com/projects/mail/documentation/examples/emailserver.tac for a simple example. Waldemar From hihiren1 at gmail.com Wed Apr 2 13:45:11 2008 From: hihiren1 at gmail.com (hiren kumar) Date: Wed, 2 Apr 2008 17:15:11 +0530 Subject: [python-win32] Anyone is able to install PSE on windows? Message-ID: Hi, Anybody is successfully able to install PSE - Python Servlet Engine on windows? I have installed the Python 2.5 and apache 2.2. I have installed mopd_python and verified it and it is running perfectly fine. I have downloaded PSE 3.0 windows binary installation. But when I try to run it , at the end it is giving me following error. Traceback (most recent call last): File "", line 63, in File "", line 9, in fix_installed_config File "D:\inst\Python25\Lib\site-packages\pse_handler\__init__.py", line 28, in from handler import handler File "D:\inst\Python25\Lib\site-packages\pse_handler\handler.py", line 28, in from mod_python import apache, util File "D:\inst\Python25\Lib\site-packages\mod_python\apache.py", line 949, in stat = _apache.stat AttributeError: 'module' object has no attribute 'stat' *** run_installscript: internal error 0xFFFFFFFF *** Can anybody please help me to solve this? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080402/71be2c81/attachment.htm From newtonian at tsn.cc Wed Apr 2 14:51:44 2008 From: newtonian at tsn.cc (Ian John Newton) Date: Wed, 02 Apr 2008 23:51:44 +1100 Subject: [python-win32] Adding Users to a Specific Organization Unit in a Domain Message-ID: <47F38160.40303@tsn.cc> Hi I need to take a text file with a list of users, groups and Organization Units and then add these users into a Domain. Currently the server is Win 2K, but I will also need to do this on Win2003. I used the BatchUserCreate.py from ch 16 of Mark Hammonds Python Programming on Win32 and then added a win32net.NetGroupAddUser(serverName, group, userName) function to add the user to a particular security group. This all works fine. I can't seem to find a way to change the organizational unit - all users get added to the Default container "Users" in the security group Domain Users. Is there any com method to add them to a specific Organizational Unit? Thanks in advance for any help you may be able to provide. Regards, Ian Newton From timr at probo.com Wed Apr 2 18:22:50 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 02 Apr 2008 09:22:50 -0700 Subject: [python-win32] A shameless COM question In-Reply-To: References: <670C45E1CDC44E99A742D6543FB18733@ToolBox> <47F2B205.4080405@probo.com> Message-ID: <47F3B2DA.5090308@probo.com> Marcus Low wrote: > > Thank you for the alternative view, yes i have the twisted downloaded > and inspecting it prior to this question. > My only concern would be this is because the said COM component is > made to run optimally in Windows and i am not sure i have the same > assurance when it comes to Twisted. I needed the events because i > need to inspect and log in nearly every level of the smtp transaction > so just creating a simple smtp was not the goal, the goal is to create > a full fledge mail server with crazy control and logging. The COM component is "made to run in Windows". I doubt that anyone ever said it was "made to run optimally in Windows". > I am not familiar with how Twisted is implemented in Windows, if it > uses the specific windows apis and asynch model winsock2 directly for > optimal performance. There is no doubt in my mind that the Twisted library is significantly more mature than your COM component, which I had never heard of before yesterday, and has had a significantly larger investment in development and optimization time. Twisted is the basis for quite a large number of production net servers, including a number of full-blown web servers, which have much higher performance demands than a simple SMTP server. Plus, since it is cross-platform, you could move your server to Linux in the future, should that become interesting. Your COM server won't do that. > So do you still think i should stick with twisted? I am all open for > suggestions. If you really are open to ALL suggestions, then I let me step out on a limb to suggest that reimplementing a full SMTP server from scratch in Python is a nutty idea to begin with. Mail serving is a non-trivial activity, filled with pitfalls, configuration strangeness, security issues, scalability problems, network availability issues, and spam and virus sensitivity. It would be much better for you to grab one of the excellent and well-proven open source SMTP servers and make whatever modifications you need to make for your environment. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Thu Apr 3 01:26:59 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 3 Apr 2008 10:26:59 +1100 Subject: [python-win32] Adding Users to a Specific Organization Unit in a Domain In-Reply-To: <47F38160.40303@tsn.cc> References: <47F38160.40303@tsn.cc> Message-ID: <024b01c89519$0ef5f420$2ce1dc60$@com.au> Since Windows 2000, it sometimes better to try and manage users via the ActiveDirectory - and one excellent reason is that VB etc samples can be found, which can make life easier. Here is a little code I've used to create users via AD - I'm afraid you will need to find out how to add OU references - it is likely another property that accepts multiple values. This is cut from a larger project, so some stuff may be missing, and some stuff may be more complicated than necessary in an attempt to work across the entire "global catalog" rather than a single domain. If someone else can help with adding the OU via win32net, you should probably stick with that while you can... Cheers, Mark from win32com import adsi from win32com.adsi.adsicon import * from ntsecuritycon import * from win32netcon import * from win32con import * def GetWellKnownContainerDN(guid, domain = ""): if domain: domain = domain + "/" # suitable for sticking in the path. dse = OpenObject("LDAP://%sRootDSE" % domain, adsi.IID_IADs) dnc = dse.get("defaultNamingContext") bind_string = "LDAP://%s" % (domain, guid, dnc) dirObject = OpenObject(bind_string) # Now open the container itself. return dirObject.get("distinguishedName") def CreateDomainUser(dirObject, cn, domain, samAcctName=None, description = USER_DESCRIPTION): """Creates a user with only the essential properties explicitly set (cn, sAMAccountType), other optional properties set, and IDirectoryObject for the new user object """ if dirObject is None: # Get the default 'users' folder. dn = GetWellKnownContainerDN(GUID_USERS_CONTAINER_A, domain) dirObject = OpenObject("LDAP://" + dn, adsi.IID_IDirectoryObject) dirObject = dirObject.QueryInterface(adsi.IID_IDirectoryObject) samAcctName = samAcctName or cn assert len(samAcctName) <= 20, \ "SamAccountName CANNOT be bigger than 20 characters" attrInfo = [ ( "objectClass", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, ("user",)), ( "sAMAccountName", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, (samAcctName,)), ( "description", ADS_ATTR_UPDATE, ADSTYPE_CASE_IGNORE_STRING, (description,)), ] user = dirObject.CreateDSObject("cn="+cn, attrInfo); EnableDomainAccount(user) return user.QueryInterface(adsi.IID_IADsUser) def EnableDomainAccount(user_ob): # Ensure the user account is enabled. user_ob = user_ob.QueryInterface(adsi.IID_IADs) try: user_ob.put("pwdLastSet", -1) user_ob.SetInfo() except pythoncom.com_error, details: # This appears to fail on 2003-server. logger.warning("Failed to set 'pwdLastSet': %s", details) try: # And the below seems to fail in some. But complicating # things a little is http://groups.google.com.au/group/microsoft.public.adsi.general/browse_frm/t hread/be113549cb62ebbe/a4cf4de3756367ad # which indicates UserAccountControl isn't even used by later # versions of Windows. It says "If you want to unlock a locked out # account, set the lockouttime to 0." # # Mask out the default bits. UF_PASSWD_NOTREQD fails on Win2003. new_val = user_ob.get("UserAccountControl") | ADS_UF_DONT_EXPIRE_PASSWD new_val &= ~(UF_ACCOUNTDISABLE) user_ob.put("UserAccountControl", new_val) user_ob.SetInfo() except pythoncom.com_error, details: # This appears to fail on 2003-server. logger.warning("Failed to set 'UserAccountControl': %s", details) def OpenObject(path, iid = adsi.IID_IADs): return adsi.ADsOpenObject(path, None, None, # username/password ADS_SECURE_AUTHENTICATION, # flags iid) > -----Original Message----- > From: python-win32-bounces at python.org [mailto:python-win32- > bounces at python.org] On Behalf Of Ian John Newton > Sent: Wednesday, 2 April 2008 11:52 PM > To: python-win32 at python.org > Subject: [python-win32] Adding Users to a Specific Organization Unit in > a Domain > > Hi > > I need to take a text file with a list of users, groups and > Organization Units and then add these users into a Domain. Currently > the > server is Win 2K, but I will also need to do this on Win2003. > > I used the BatchUserCreate.py from ch 16 of Mark Hammonds Python > Programming on Win32 and then > added a win32net.NetGroupAddUser(serverName, group, userName) function > to add the user to a particular security group. This all works fine. > > I can't seem to find a way to change the organizational unit - all > users > get added to the Default container "Users" in the security group Domain > Users. > > Is there any com method to add them to a specific Organizational Unit? > > Thanks in advance for any help you may be able to provide. > > Regards, > > Ian Newton > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From waldemar.osuch at gmail.com Thu Apr 3 06:09:55 2008 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Wed, 2 Apr 2008 22:09:55 -0600 Subject: [python-win32] Anyone is able to install PSE on windows? In-Reply-To: References: Message-ID: <6fae95540804022109j583ece16t8dfaf6ec32799ff2@mail.gmail.com> On Wed, Apr 2, 2008 at 5:45 AM, hiren kumar wrote: > Hi, > > Anybody is successfully able to install PSE - Python Servlet Engine on > windows? > > I have installed the Python 2.5 and apache 2.2. > I have installed mopd_python and verified it and it is running perfectly > fine. > > I have downloaded PSE 3.0 windows binary installation. > > But when I try to run it , at the end it is giving me following error. > > Traceback (most recent call last): > File "", line 63, in > File "", line 9, in fix_installed_config > File "D:\inst\Python25\Lib\site > -packages\pse_handler\__init__.py", line 28, in > from handler import handler > File "D:\inst\Python25\Lib\site-packages\pse_handler\handler.py", line 28, > in > from mod_python import apache, util > File "D:\inst\Python25\Lib\site-packages\mod_python\apache.py", line 949, > in > stat = _apache.stat > AttributeError: 'module' object has no attribute 'stat' > *** run_installscript: internal error 0xFFFFFFFF *** > > Can anybody please help me to solve this? I'm afraid, I can not help to solve the immediate problem but it does smell like some version conflict between PSE and mod_python. What I would like to do though is to point you to mod_wsgi instead. You will have many more options on what to use for the web framework. Even if you are not a framework kind of guy WSGI will make it easier to come up with solution tailored to your needs. Waldemar From marcus at internetnowasp.net Thu Apr 3 10:08:38 2008 From: marcus at internetnowasp.net (Marcus Low) Date: Thu, 3 Apr 2008 16:08:38 +0800 Subject: [python-win32] A shameless COM question In-Reply-To: <6fae95540804022057r600750edmb4142fd87497288e@mail.gmail.com> References: <670C45E1CDC44E99A742D6543FB18733@ToolBox> <47F2B205.4080405@probo.com> <6fae95540804012312q7c10fa76vb021b5c68650c0bc@mail.gmail.com> <37BA2E6281484959A43BD0CD905BDFB1@ToolBox> <6fae95540804022057r600750edmb4142fd87497288e@mail.gmail.com> Message-ID: <5EFA238FE9C34435B0251151BBF3DAAE@ToolBox> Hi Waldemar, Thanks, i have bought the twisted book and the journey begin. The COM was optimal for windows because its asynch api winsock2 and that beats berkeley socket "select" anyday on Windows, but your hint on the IO completion port gives twisted an equal footing in terms of raw efficiency. I also agree with Tim that there is a much bigger team on twisted and hey at least you guys did respond on my shameless questions ;-) Yes, i will do a mock up server and bombard it and see for myself if this is viable. Marcus ----- Original Message ----- From: "Waldemar Osuch" To: "Marcus Low" Sent: Thursday, April 03, 2008 11:57 AM Subject: Re: [python-win32] A shameless COM question > On Wed, Apr 2, 2008 at 2:38 AM, Marcus Low > wrote: > >> >> > Are you are the only Python guy in the sea of .Net programmers? >> > Do you have to fight political battles about technology in your >> > office? >> > Is the deadline looming? >> > Do you have patience to learn "Twisted way" of programming? >> > >> >> Actually i am the Project director , > > Well that takes care of the first two questions :-) > >> we have our own mail servers written 8 >> years ago and serving many windows companies. But the time >> has come to rewrite one based on all the requirements and problems we >> have >> documented and collected, even on software like smartermail, imail >> there are just too much requirement in our list that it completely >> justifies a rewrite. (as you notice i am all into Windows market) >> >> I have given my team a strong mandate that all programming must be done >> in >> C# and only drivers will remain as C/C++ (prev everything is C/C++) >> for one reason, productivity. That was until one of my "fun time" of >> learning something new was python .. >> >> So on one hand yes i have can steer the whole team on pythonwin, on the >> other hand being a "windows based" market, i thought that using the COM >> on python would give me the case. >> >> I require that the mailserver needs to handle 1000 concurrent >> connections...and the python code will still need to call logging, AV >> scan, >> antispam apis etc. > > In my opinion Twisted based mail server would be able to handle it. > But do not take my word for it. Maybe ask on Twisted mailing list. > > The good news is that the latest release includes a rewrite of IOCP > reactor that promises to be much better performing on Windows > than the default "select" reactor. > >> >> Will the GIL be a problem here? > > No I do not think so. Twisted is a single threaded, asynchronous > server. You may dispatch blocking calls (database queries, spam > checks, expensive > calculations) to a thread pool using deferToThread calls but the main > reactor > loop stays single threaded at all times. Most of the time one is > waiting for the > network anyways. > >> >> Do you still recommend Twisted ? I have no problem spending whole week >> mastering twisted in office and home if it can handle my criteria. >> > > I would still recommend it but I am biased. > Would I base my new product on the technology I just learned in a week? > Probably not, but I would consider writing a throw away prototype to see > how it performs. Twisted is "good technology" and worth exploring. > > Twisted can be a little bit daunting to learn at the beginning. At least > it > was for me. The "finger" tutorial helped me tremendously to wrap my head > around how Twisted does things but still it took me long time to "get it". > I'm I an expert now? No, but I have learned enough to have confidence > in the approach taken by Twisted developers. From Kyle.Rickey at bakerhughes.com Thu Apr 3 18:07:48 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Thu, 3 Apr 2008 11:07:48 -0500 Subject: [python-win32] Find Target Message-ID: I am trying to figure out how to show a specified file in explorer. I know I can call os.startfile(directory) to show the containing directory, but I would like the file to be selected also. Is there an API call that windows makes to do this? For example, right click on a shortcut and go to properties, then click on the 'Find Target' button. Any ideas? -Kyle Rickey -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080403/493c7edb/attachment.htm From timr at probo.com Thu Apr 3 18:42:08 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 03 Apr 2008 09:42:08 -0700 Subject: [python-win32] Find Target In-Reply-To: References: Message-ID: <47F508E0.4020000@probo.com> Rickey, Kyle W wrote: > > I am trying to figure out how to show a specified file in explorer. I > know I can call os.startfile(directory) to show the containing > directory, but I would like the file to be selected also. Is there an > API call that windows makes to do this? > > > > For example, right click on a shortcut and go to properties, then > click on the ?Find Target? button. Any ideas? > You're talking about controlling the UI here. You could do that by finding the Explorer window, trolling through to find the list control, find the entry, simulate right-click, etc., but it would be an undocumented pain in the rear. However, everything that's in those dialogs is exposed through the shell API. Why don't you just display the dialog yourself? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Thu Apr 3 18:44:36 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 03 Apr 2008 09:44:36 -0700 Subject: [python-win32] A shameless COM question In-Reply-To: <5EFA238FE9C34435B0251151BBF3DAAE@ToolBox> References: <670C45E1CDC44E99A742D6543FB18733@ToolBox> <47F2B205.4080405@probo.com> <6fae95540804012312q7c10fa76vb021b5c68650c0bc@mail.gmail.com> <37BA2E6281484959A43BD0CD905BDFB1@ToolBox> <6fae95540804022057r600750edmb4142fd87497288e@mail.gmail.com> <5EFA238FE9C34435B0251151BBF3DAAE@ToolBox> Message-ID: <47F50974.6010201@probo.com> Marcus Low wrote: > Hi Waldemar, > > Thanks, i have bought the twisted book and the journey begin. The COM was > optimal for windows because its asynch api winsock2 and > that beats berkeley socket "select" anyday on Windows, That is superstitious nonsense. The asynchronous winsock API had to be invented because Windows 3.x did not support pre-emptive multitasking. It has no inherent performance advantage. Now that Windows has threads, many people argue that the synchronous API is the better choice. In the end, it comes down to personal preference. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Kyle.Rickey at bakerhughes.com Thu Apr 3 19:02:03 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Thu, 3 Apr 2008 12:02:03 -0500 Subject: [python-win32] Find Target In-Reply-To: <47F508E0.4020000@probo.com> References: <47F508E0.4020000@probo.com> Message-ID: Tim, let me rephrase. I'm not trying to display the shortcut dialog, only reproduce the behavior that happens when you click 'Find Target'. For instance, I've generated a file and I want show the user that file in explorer. -Kyle Rickey -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tim Roberts Sent: Thursday, April 03, 2008 11:42 AM To: Python-Win32 List Subject: Re: [python-win32] Find Target Rickey, Kyle W wrote: > > I am trying to figure out how to show a specified file in explorer. I > know I can call os.startfile(directory) to show the containing > directory, but I would like the file to be selected also. Is there an > API call that windows makes to do this? > > > > For example, right click on a shortcut and go to properties, then > click on the 'Find Target' button. Any ideas? > You're talking about controlling the UI here. You could do that by finding the Explorer window, trolling through to find the list control, find the entry, simulate right-click, etc., but it would be an undocumented pain in the rear. However, everything that's in those dialogs is exposed through the shell API. Why don't you just display the dialog yourself? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From timr at probo.com Thu Apr 3 19:17:14 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 03 Apr 2008 10:17:14 -0700 Subject: [python-win32] Find Target In-Reply-To: References: <47F508E0.4020000@probo.com> Message-ID: <47F5111A.2080000@probo.com> Rickey, Kyle W wrote: > Tim, let me rephrase. I'm not trying to display the shortcut dialog, > only reproduce the behavior that happens when you click 'Find Target'. > For instance, I've generated a file and I want show the user that file > in explorer. > "Find Target" just follows a shortcut and opens the directory containing that shortcut. The shell library has an API for fetching the target path from a shortcut file. You could just pull the path from the shortcut, and startup a new Explorer in that directory. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Kyle.Rickey at bakerhughes.com Thu Apr 3 19:25:37 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Thu, 3 Apr 2008 12:25:37 -0500 Subject: [python-win32] Find Target In-Reply-To: <47F5111A.2080000@probo.com> References: <47F508E0.4020000@probo.com> <47F5111A.2080000@probo.com> Message-ID: Tim, thanks for your patience :). I think I'm still miscommunicating to you what I need to do. Let's throw the whole shortcut idea out the window and start from scratch. My code generates a file, I want to open the directory (which is known) containing that file and select it. Since I can open the directory with os.startfile(), do I still need to get the hwnd of the explorer window and get the listctrl etc., or is there a simpler way to select a file? -Kyle Rickey -----Original Message----- From: python-win32-bounces+kyle.rickey=bakerhughes.com at python.org [mailto:python-win32-bounces+kyle.rickey=bakerhughes.com at python.org] On Behalf Of Tim Roberts Sent: Thursday, April 03, 2008 12:17 PM To: Python-Win32 List Subject: Re: [python-win32] Find Target Rickey, Kyle W wrote: > Tim, let me rephrase. I'm not trying to display the shortcut dialog, > only reproduce the behavior that happens when you click 'Find Target'. > For instance, I've generated a file and I want show the user that file > in explorer. > "Find Target" just follows a shortcut and opens the directory containing that shortcut. The shell library has an API for fetching the target path from a shortcut file. You could just pull the path from the shortcut, and startup a new Explorer in that directory. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From sirgnip at gmail.com Thu Apr 3 19:39:35 2008 From: sirgnip at gmail.com (Scott Nelson) Date: Thu, 3 Apr 2008 12:39:35 -0500 Subject: [python-win32] Find Target In-Reply-To: References: <47F508E0.4020000@probo.com> <47F5111A.2080000@probo.com> Message-ID: <2682ac9b0804031039h70cbf306i93835efdc9836c92@mail.gmail.com> Kyle, If I understand you correctly, and if your not stuck on using os.startfile(), you can use explorer.exe's command line options to do this (and more). os.system('%SystemRoot%\explorer.exe/e,/select=C:\MyFolder\subfolder\MyFile. txt') See thisfor more info: http://support.microsoft.com/kb/314853 -Scott -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080403/f8f70cfd/attachment.htm From timr at probo.com Thu Apr 3 19:44:25 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 03 Apr 2008 10:44:25 -0700 Subject: [python-win32] Find Target In-Reply-To: References: <47F508E0.4020000@probo.com> <47F5111A.2080000@probo.com> Message-ID: <47F51779.2010100@probo.com> Rickey, Kyle W wrote: > Tim, thanks for your patience :). I think I'm still miscommunicating to > you what I need to do. Let's throw the whole shortcut idea out the > window and start from scratch. > > My code generates a file, I want to open the directory (which is known) > containing that file and select it. Since I can open the directory with > os.startfile(), do I still need to get the hwnd of the explorer window > and get the listctrl etc., or is there a simpler way to select a file? > You're in luck! There IS a simple solution to the problem as you just stated it: explorer /select,c:\windows\notepad.exe For future reference, here's a knowledge base article that describes the command-line parameters to explorer: http://support.microsoft.com/kb/130510 -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From clintonlee.taylor at gmail.com Thu Apr 3 19:54:31 2008 From: clintonlee.taylor at gmail.com (Clinton Lee Taylor) Date: Thu, 3 Apr 2008 19:54:31 +0200 Subject: [python-win32] OT: Version in EXE ... Message-ID: Greetings ... This might be a little off topic, but I'm hoping that some might know how to add version details to exe files created with py2exe so that install system can version control upgrades ... Thanks Mailed LeeT From Kyle.Rickey at bakerhughes.com Thu Apr 3 20:04:26 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Thu, 3 Apr 2008 13:04:26 -0500 Subject: [python-win32] Find Target In-Reply-To: <47F51779.2010100@probo.com> References: <47F508E0.4020000@probo.com> <47F5111A.2080000@probo.com> <47F51779.2010100@probo.com> Message-ID: Tim/Scott, thanks for your replies that is exactly what I needed! :bow: Thanks for both of your times. -Kyle Rickey -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tim Roberts Sent: Thursday, April 03, 2008 12:44 PM To: Python-Win32 List Subject: Re: [python-win32] Find Target Rickey, Kyle W wrote: > Tim, thanks for your patience :). I think I'm still miscommunicating to > you what I need to do. Let's throw the whole shortcut idea out the > window and start from scratch. > > My code generates a file, I want to open the directory (which is known) > containing that file and select it. Since I can open the directory with > os.startfile(), do I still need to get the hwnd of the explorer window > and get the listctrl etc., or is there a simpler way to select a file? > You're in luck! There IS a simple solution to the problem as you just stated it: explorer /select,c:\windows\notepad.exe For future reference, here's a knowledge base article that describes the command-line parameters to explorer: http://support.microsoft.com/kb/130510 -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From theller at ctypes.org Thu Apr 3 20:16:51 2008 From: theller at ctypes.org (Thomas Heller) Date: Thu, 03 Apr 2008 20:16:51 +0200 Subject: [python-win32] OT: Version in EXE ... In-Reply-To: References: Message-ID: Clinton Lee Taylor schrieb: > Greetings ... > > This might be a little off topic, but I'm hoping that some might know > how to add version details to exe files created with py2exe so that > install system can version control upgrades ... > > Thanks > Mailed > LeeT IIRC, py2exe itself has samples that have this. Look into the subdirectories of pythonXY\Lib\site-packages\py2exe\samples. Thomas From marcus at internetnowasp.net Fri Apr 4 04:24:21 2008 From: marcus at internetnowasp.net (Marcus Low) Date: Fri, 4 Apr 2008 10:24:21 +0800 Subject: [python-win32] A shameless COM question In-Reply-To: <47F50974.6010201@probo.com> References: <670C45E1CDC44E99A742D6543FB18733@ToolBox> <47F2B205.4080405@probo.com> <6fae95540804012312q7c10fa76vb021b5c68650c0bc@mail.gmail.com> <37BA2E6281484959A43BD0CD905BDFB1@ToolBox> <6fae95540804022057r600750edmb4142fd87497288e@mail.gmail.com><5EFA238FE9C34435B0251151BBF3DAAE@ToolBox> <47F50974.6010201@probo.com> Message-ID: <942A509DB14D46739D601D95AC36F504@ToolBox> Tim, http://www.patentstorm.us/patents/6223207-description.html The advantage of scalability and performance of using IOCP/asynch for writing servers vs berkeley style select in Windows is a known thing for windows programmers. ICOP is built right into the Windows system drivers with the purpose of giving this advantage. It has nothing to do with what 3.x have or not, this mechanism is introduce for Windows NT line of operating systems (leading to 2k, xp, vista) It doesn't comes down to "personal preference", that choice unfortunately is the choice of ignorant programmers. > It has no inherent performance advantage : Tim Roberts I would suggest you close this thread, if you chose to reply this thread with information from Planet-Megatron, I would not have the courtesy to reply. Marcus. ----- Original Message ----- From: "Tim Roberts" To: "Python-Win32 List" Sent: Friday, April 04, 2008 12:44 AM Subject: Re: [python-win32] A shameless COM question > Marcus Low wrote: >> Hi Waldemar, >> >> Thanks, i have bought the twisted book and the journey begin. The COM >> was >> optimal for windows because its asynch api winsock2 and >> that beats berkeley socket "select" anyday on Windows, > > That is superstitious nonsense. The asynchronous winsock API had to be > invented because Windows 3.x did not support pre-emptive multitasking. > It has no inherent performance advantage. Now that Windows has threads, > many people argue that the synchronous API is the better choice. In the > end, it comes down to personal preference. > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From antonyjoseph89 at gmail.com Fri Apr 4 13:09:20 2008 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Fri, 4 Apr 2008 16:39:20 +0530 Subject: [python-win32] Problem in reading MS Outlook mails. Message-ID: Hi, I am having problems while i read the mails from Ms Outlook. My code: self.session = win32com.client.Dispatch("Mapi.Session") self.session.Logon("Outlook") Error: 1.(-2147467259, 'Unspecified error', None, None). 2.A MS Outlook pop up a message that: "Either there is no default mail client or the current mail client cannot fulfill the messaging request.Please run Microsoft Office Outlook and set it as the default mail client." I detect the problem .I am using ThunderBird as my default mail client. But i donot know how to slove this problem.how can i read the mails without setting the MS Outlook as my default mail client. please help me.how to fix this? Regard Antony -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080404/e2872aa2/attachment.htm From raduciora at yahoo.com Fri Apr 4 13:19:11 2008 From: raduciora at yahoo.com (Radu Ciora) Date: Fri, 4 Apr 2008 04:19:11 -0700 (PDT) Subject: [python-win32] Problem in reading MS Outlook mails. Message-ID: <364880.43651.qm@web50103.mail.re2.yahoo.com> Try: self.session = win32com.client.Dispatch("Outlook.Application") ?Regards, Radu. ----- Original Message ---- From: Antony Joseph To: python-win32 at python.org Sent: Friday, 4 April, 2008 12:09:20 PM Subject: [python-win32] Problem in reading MS Outlook mails. Hi, I am having problems while i read the mails from Ms Outlook. My code: self.session = win32com.client.Dispatch("Mapi.Session") self.session.Logon("Outlook") Error: ????????? 1.(-2147467259, 'Unspecified error', None, None). ????????? 2.A MS? Outlook? pop up a message that: "Either there is no default mail client or the current mail client cannot fulfill the messaging request.Please run Microsoft Office Outlook and set it as the default mail client." I detect the problem .I am using ThunderBird as my default mail client. But i donot know how to slove this problem.how can i read the mails without setting the MS Outlook as my default mail client. please help me.how to fix this? Regard Antony ___________________________________________________________ Yahoo! For Good helps you make a difference http://uk.promotions.yahoo.com/forgood/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080404/ef67829f/attachment.htm From applejump at gmail.com Fri Apr 4 16:38:53 2008 From: applejump at gmail.com (Xue Shan) Date: Fri, 4 Apr 2008 10:38:53 -0400 Subject: [python-win32] A problem on testing COM object with VBA Message-ID: <806d5e790804040738t22399c3fub4c65603f4b30829@mail.gmail.com> Hi all, I'm a Python beginner and trying to run the codes from Chapter 5 of Python pramming on win32. But when I tested the COM object with VBA, I got an error msg saying runtime error 438. Is there anyone can help me out? Thanks in advance! Here are the codes: [Python] class PythonUtilities: _public_methods_ = [ 'SplitString' ] _reg_progid_ = "PythonDemos.Utilities" _reg_clsid_ = "{D81903FB-62F2-4FB1-993E-63CAF4C963A0}" def SplitString(self, val, item=None): import string if item != Nome: item = str(item) return string.split(str(val), item) if __name__=='__main__': print "Registering COM server..." import win32com.server.register win32com.server.register.UseCommandLine(PythonUtilities) After running above scripts, the PythonWin interactive window displayed Registering COM server... Registered: PythonDemos.Utilities [VBA] Sub TestPython() Set PythonUtils = CreateObject("PythonDemos.Utilities") response = PythonUtils.SplitString("Hello from VB") For Each Item In response MsgBox Item Next End Sub The code stopped at "response = PythonUtils.SplitString("Hello from VB")". -- Love. Peace. Music. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080404/c8df4d13/attachment.htm From timr at probo.com Fri Apr 4 18:33:20 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 04 Apr 2008 09:33:20 -0700 Subject: [python-win32] A problem on testing COM object with VBA In-Reply-To: <806d5e790804040738t22399c3fub4c65603f4b30829@mail.gmail.com> References: <806d5e790804040738t22399c3fub4c65603f4b30829@mail.gmail.com> Message-ID: <47F65850.8080105@probo.com> Xue Shan wrote: > Hi all, > I'm a Python beginner and trying to run the codes from Chapter 5 of > Python pramming on win32. But when I tested the COM object with VBA, > I got an error msg saying runtime error 438. Is there anyone can help > me out? Thanks in advance! > > Here are the codes: > [Python] > class PythonUtilities: > _public_methods_ = [ 'SplitString' ] > _reg_progid_ = "PythonDemos.Utilities" > _reg_clsid_ = "{D81903FB-62F2-4FB1-993E-63CAF4C963A0}" > > def SplitString(self, val, item=None): > import string > if item != Nome: item = str(item) > return string.split(str(val), item) The problem here is that "None" is misspelled inside SplitString. This won't be noticed until SplitString is actually executed. By the way, since Python 2.x, you don't need to "import string" any more. You can write that as: def SplitString( self, val, item=None ): if item: item = str(item) return str(val).split( item ) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From applejump at gmail.com Fri Apr 4 18:55:04 2008 From: applejump at gmail.com (Xue Shan) Date: Fri, 4 Apr 2008 12:55:04 -0400 Subject: [python-win32] A problem on testing COM object with VBA In-Reply-To: <47F65850.8080105@probo.com> References: <806d5e790804040738t22399c3fub4c65603f4b30829@mail.gmail.com> <47F65850.8080105@probo.com> Message-ID: <806d5e790804040955l30664a7fk1a3d8ebc2bcd549a@mail.gmail.com> Hi Tim, Thank you very much for pointing out my mistakes. But, it still doesn't work because of runtime error 438. It seems in VBA it doesn't CreateObject sucessfully. Any ideas of solving it? Thanks a lot! Shan 2008/4/4, Tim Roberts : > > Xue Shan wrote: > > Hi all, > > I'm a Python beginner and trying to run the codes from Chapter 5 of > > Python pramming on win32. But when I tested the COM object with VBA, > > I got an error msg saying runtime error 438. Is there anyone can help > > me out? Thanks in advance! > > > > Here are the codes: > > [Python] > > class PythonUtilities: > > _public_methods_ = [ 'SplitString' ] > > _reg_progid_ = "PythonDemos.Utilities" > > _reg_clsid_ = "{D81903FB-62F2-4FB1-993E-63CAF4C963A0}" > > > > def SplitString(self, val, item=None): > > import string > > if item != Nome: item = str(item) > > return string.split(str(val), item) > > > The problem here is that "None" is misspelled inside SplitString. This > won't be noticed until SplitString is actually executed. > > By the way, since Python 2.x, you don't need to "import string" any > more. You can write that as: > > > def SplitString( self, val, item=None ): > > if item: item = str(item) > return str(val).split( item ) > > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > -- Love. Peace. Music. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080404/bf7a5419/attachment.htm From timr at probo.com Fri Apr 4 19:02:25 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 04 Apr 2008 10:02:25 -0700 Subject: [python-win32] A problem on testing COM object with VBA In-Reply-To: <806d5e790804040738t22399c3fub4c65603f4b30829@mail.gmail.com> References: <806d5e790804040738t22399c3fub4c65603f4b30829@mail.gmail.com> Message-ID: <47F65F21.9010308@probo.com> Xue Shan wrote: > Hi all, > I'm a Python beginner and trying to run the codes from Chapter 5 of > Python pramming on win32. But when I tested the COM object with VBA, > I got an error msg saying runtime error 438. Is there anyone can help > me out? Thanks in advance! > > Here are the codes: > [Python] > class PythonUtilities: > _public_methods_ = [ 'SplitString' ] > _reg_progid_ = "PythonDemos.Utilities" > _reg_clsid_ = "{D81903FB-62F2-4FB1-993E-63CAF4C963A0}" > > def SplitString(self, val, item=None): > import string > if item != Nome: item = str(item) > return string.split(str(val), item) > > if __name__=='__main__': > print "Registering COM server..." > import win32com.server.register > win32com.server.register.UseCommandLine(PythonUtilities) Ack, I just noticed your indentation. That's why you are getting the 438 error. SplitString is at the same level as PythonUtilities here. That means that SplitString is a global function -- it is not a member of the PythonUtilities class. There is no SplitString member function, which is why you get error 438: "object doesn't support this property or method". You need to indent the SplitString function. Viz: class PythonUtilities: _public_methods_ = [ 'SplitString' ] _reg_progid_ = "PythonDemos.Utilities" _reg_clsid_ = "{D81903FB-62F2-4FB1-993E-63CAF4C963A0}" def SplitString(self, val, item=None): import string if item: item = str(item) return str(val).split( item) if __name__=='__main__': print "Registering COM server..." import win32com.server.register win32com.server.register.UseCommandLine(PythonUtilities) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mhammond at skippinet.com.au Sat Apr 5 02:06:59 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sat, 5 Apr 2008 11:06:59 +1100 Subject: [python-win32] A shameless COM question In-Reply-To: <942A509DB14D46739D601D95AC36F504@ToolBox> References: <670C45E1CDC44E99A742D6543FB18733@ToolBox> <47F2B205.4080405@probo.com> <6fae95540804012312q7c10fa76vb021b5c68650c0bc@mail.gmail.com> <37BA2E6281484959A43BD0CD905BDFB1@ToolBox> <6fae95540804022057r600750edmb4142fd87497288e@mail.gmail.com><5EFA238FE9C34435B0251151BBF3DAAE@ToolBox> <47F50974.6010201@probo.com> <942A509DB14D46739D601D95AC36F504@ToolBox> Message-ID: <00ef01c896b0$fab6beb0$f0243c10$@com.au> > http://www.patentstorm.us/patents/6223207-description.html > > The advantage of scalability and performance of using IOCP/asynch for > writing servers vs berkeley style select in Windows > is a known thing for windows programmers. ICOP is built right into the > Windows system drivers with the purpose of giving this advantage. > It has nothing to do with what 3.x have or not, this mechanism is > introduce > for Windows NT line of operating systems (leading to 2k, xp, vista) > It doesn't comes down to "personal preference", that choice > unfortunately > is the choice of ignorant programmers. I believe Tim was referring to select versus the blocking socket API. IOCPs are a different breed, and IIUC, twisted supports them just fine (but obviously only on Windows). Don't underestimate the complexity of writing asynchronous IOCP based applications in *any* language - just because something is written in C# and *only* targets one way of handling sockets doesn't make it the best or most reliable solution. Obviously, this is not a comment about the particular .NET object you are talking about, just a general observation. > > It has no inherent performance advantage : Tim Roberts > > I would suggest you close this thread, if you chose to reply this > thread > with information from Planet-Megatron, I would not > have the courtesy to reply. I'm not quite with you here, but I'll give you the benefit of the doubt and assume it wasn't your intention to be rude to someone who has been trying to help you. Regards, Mark From marcus at internetnowasp.net Sat Apr 5 05:04:38 2008 From: marcus at internetnowasp.net (Marcus Low) Date: Sat, 5 Apr 2008 11:04:38 +0800 Subject: [python-win32] A shameless COM question (can we close this?) In-Reply-To: <00ef01c896b0$fab6beb0$f0243c10$@com.au> References: <670C45E1CDC44E99A742D6543FB18733@ToolBox> <47F2B205.4080405@probo.com> <6fae95540804012312q7c10fa76vb021b5c68650c0bc@mail.gmail.com> <37BA2E6281484959A43BD0CD905BDFB1@ToolBox> <6fae95540804022057r600750edmb4142fd87497288e@mail.gmail.com><5EFA238FE9C34435B0251151BBF3DAAE@ToolBox> <47F50974.6010201@probo.com> <942A509DB14D46739D601D95AC36F504@ToolBox> <00ef01c896b0$fab6beb0$f0243c10$@com.au> Message-ID: <23A65325B3B34F6487AED0D21F91C510@ToolBox> Hi Mark, > Don't underestimate the complexity of writing > asynchronous IOCP based applications in *any* language - just because > something is written in C# and *only* targets one way of handling sockets > doesn't make it the best or most reliable solution. No doubt even given the best mechanism, the complexity and programmers skill can bring it to naught, but since my team will be writing a solution from "start", we have to evaluate the best that the OS supports. That is also why Twisted looks so promising, not that it has downright IOCP support but at least from what i read the twisted team is working on it and there are already a reactor with iocp and the framework looks easy. > I'm not quite with you here, but I'll give you the benefit of the doubt > and > assume it wasn't your intention to be rude to someone who has been trying > to > help you. --I am not familiar with how Twisted is implemented in Windows, if it uses the --specific windows apis and asynch model winsock2 directly for optimal --performance. -The COM was -optimal for windows because its asynch api winsock2 and -that beats berkeley socket "select" anyday on Windows, but your hint on the -IO completion port gives twisted an equal footing in terms of raw -efficiency. (the iocp support for sockets is in winsock2...) As you can see Mark, there was never a discussion on blocking sockets vs Select. So i wasn't expecting Tim's reply which i won't be posting here. As i said, lets close the thread. Tim is one of those people that this mailing list needs, i can see he responds quickly to help others while ppl like me would just post questions. Yes i do apologize for using the term "planet megatron" . :-) > > Regards, > > Mark > From sami_islam at hotmail.com Sat Apr 5 23:27:43 2008 From: sami_islam at hotmail.com (Sami Islam) Date: Sat, 5 Apr 2008 21:27:43 +0000 Subject: [python-win32] traceback.print_exception(type, val, tb) not working under 2.5.2 Message-ID: Hello, I am new to Python. This is my code: ------------------------------------------- import sys import traceback def MyExHook(typ, val, tb): print "Inside MyExHook" tb.print_exception(typ, val, tb) T, V, B = sys.exc_info() sys.excepthook = MyExHook(T, V, B) x = 1/0 ------------------------------------------- and this is what I get ------------------------------------------ Inside MyExHook Traceback (most recent call last): File "E:/Home/Programming/Python/TryProjects/ExceptHandling1/Except4.py", line 11, in sys.excepthook = MyExHook(T, V, B) File "E:/Home/Programming/Python/TryProjects/ExceptHandling1/Except4.py", line 6, in MyExHook tb.print_exception(typ, val, tb) AttributeError: print_exception -------------------------------------------------------------------------------------------------------- I can see that my MyExHook is being called (it wasn't being called when I had previously set sys.excepthook = MyExHook without parameters). The parameters to print_exception are what they should be. What am I doing wrong? Thanks, Sami _________________________________________________________________ Amazing prizes every hour with Live Search Big Snap http://www.bigsnapsearch.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080405/d77575e0/attachment.htm From timr at probo.com Mon Apr 7 19:30:58 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 07 Apr 2008 10:30:58 -0700 Subject: [python-win32] traceback.print_exception(type, val, tb) not working under 2.5.2 In-Reply-To: References: Message-ID: <47FA5A52.1060809@probo.com> Sami Islam wrote: > > I am new to Python. > > This is my code: > ------------------------------------------- > import sys > import traceback > > def MyExHook(typ, val, tb): > print "Inside MyExHook" > tb.print_exception(typ, val, tb) > > T, V, B = sys.exc_info() > sys.excepthook = MyExHook(T, V, B) > > x = 1/0 > ------------------------------------------- > and this is what I get > ------------------------------------------ > Inside MyExHook > > Traceback (most recent call last): > File > "E:/Home/Programming/Python/TryProjects/ExceptHandling1/Except4.py", > line 11, in > sys.excepthook = MyExHook(T, V, B) > File > "E:/Home/Programming/Python/TryProjects/ExceptHandling1/Except4.py", > line 6, in MyExHook > tb.print_exception(typ, val, tb) > AttributeError: print_exception > -------------------------------------------------------------------------------------------------------- > > I can see that my MyExHook is being called (it wasn't being called when > I had previously set sys.excepthook = MyExHook without parameters). The > parameters to print_exception are what they should be. No, they aren't. Did you try adding print typ, val, tb in MyExHook? In my Python 2.4 environment, it prints "None None None", because that's what sys.exc_info returns when there has not been an exception. > What am I doing wrong? sys.excepthook needs to be set to a function. You are calling MyExHook with three garbage parameters, and then passing its result (which is None in this case) to sys.excepthook. MyExHook is not being called when the exception happens, because the exception hook is set to None. The right way to do this is: sys.excepthook = MyExHook x = 1/0 I just tried that, and it worked fine. If that's not working for you, tell us what you do get. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From jepe_abrantes at hotmail.com Tue Apr 8 16:54:20 2008 From: jepe_abrantes at hotmail.com (=?iso-8859-1?Q?Jo=E3o_Abrantes?=) Date: Tue, 8 Apr 2008 14:54:20 +0000 Subject: [python-win32] Window Handler Message-ID: Hello, I am trying to make a program that sends text to the notepad using win32api.SendMessage function. The thing is that I don't know how to get the child window edit handler of notepad and i can't find any documentation about win32(python), can you help me? regards. _________________________________________________________________ News, entertainment and everything you care about at Live.com. Get it now! http://www.live.com/getstarted.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080408/c843aae8/attachment.htm From jepe_abrantes at hotmail.com Tue Apr 8 22:03:16 2008 From: jepe_abrantes at hotmail.com (=?iso-8859-1?Q?Jo=E3o_Abrantes?=) Date: Tue, 8 Apr 2008 20:03:16 +0000 Subject: [python-win32] Child Windows Message-ID: Hello, I am trying to make a program that sends text to notepad using win32api.SendMessage function. The thing is that I don't know how to get the notepad child window edit handler and I can't find any documentation about win32 (python) can you help me? Regards. _________________________________________________________________ Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080408/dcceb275/attachment.htm From python at kareta.de Tue Apr 8 23:51:05 2008 From: python at kareta.de (=?ISO-8859-1?Q?J=FCrgen_Kareta?=) Date: Tue, 08 Apr 2008 23:51:05 +0200 Subject: [python-win32] Child Windows In-Reply-To: References: Message-ID: <47FBE8C9.3080201@kareta.de> Jo?o Abrantes schrieb: > Hello, > > I am trying to make a program that sends text to notepad using > win32api.SendMessage function. The thing is that I don't know how to > get the notepad child window edit handler and I can't find any > documentation about win32 (python) can you help me? > > Regards. > > ------------------------------------------------------------------------ > Invite your mail contacts to join your friends list with Windows Live > Spaces. It's easy! Try it! > > > ------------------------------------------------------------------------ > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > Hi Jo?o, this doesn't answer your question but nevertheless there is the sendkeys package wich can do it and maybe give you some thoughts: http://www.rutherfurd.net/python/sendkeys/ regards J?rgen From timr at probo.com Tue Apr 8 23:53:40 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 08 Apr 2008 14:53:40 -0700 Subject: [python-win32] Child Windows In-Reply-To: References: Message-ID: <47FBE964.2030509@probo.com> Jo?o Abrantes wrote: > Hello, > > I am trying to make a program that sends text to notepad using > win32api.SendMessage function. The thing is that I don't know how to > get the notepad child window edit handler and I can't find any > documentation about win32 (python) can you help me? Mark Hammond wrote a book on using Python with Win32. Google has lots of information about it. In large part, however, you are expected to be pretty comfortable with the Win32 API, and if you are, then figuring out the Python translations isn't that hard. In the meantime can use win32api.FindWindow. The "edit" within Notepad had control ID 0x0f. So, start up an empty Notepad. Then: import win32gui import win32con notepad = win32gui.FindWindow( None, "Untitled - Notepad" ) npedit = win32gui.GetDlgItem( notepad, 0x000f ) win32gui.SendMessage( npedit, win32con.WM_SETTEXT, 0, "Testing" ) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From jepe_abrantes at hotmail.com Tue Apr 8 23:54:47 2008 From: jepe_abrantes at hotmail.com (=?iso-8859-1?Q?Jo=E3o_Abrantes?=) Date: Tue, 8 Apr 2008 21:54:47 +0000 Subject: [python-win32] Child Windows In-Reply-To: <47FBE8C9.3080201@kareta.de> References: <47FBE8C9.3080201@kareta.de> Message-ID: The thing is that i just gave the notepad as an example. What I really want is to send long keystrokes to a child window of a game. And the sendkeys module doesn't allow you to send long keystrokes. So I think that i really need to use win32api.sendmessage. > Date: Tue, 8 Apr 2008 23:51:05 +0200 > From: python at kareta.de > To: python-win32 at python.org > Subject: Re: [python-win32] Child Windows > > Jo?o Abrantes schrieb: > > Hello, > > > > I am trying to make a program that sends text to notepad using > > win32api.SendMessage function. The thing is that I don't know how to > > get the notepad child window edit handler and I can't find any > > documentation about win32 (python) can you help me? > > > > Regards. > > > > ------------------------------------------------------------------------ > > Invite your mail contacts to join your friends list with Windows Live > > Spaces. It's easy! Try it! > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > python-win32 mailing list > > python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > Hi Jo?o, > > this doesn't answer your question but nevertheless there is the sendkeys > package wich can do it and maybe give you some thoughts: > http://www.rutherfurd.net/python/sendkeys/ > > regards > J?rgen > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080408/dec2ebd1/attachment.htm From timr at probo.com Wed Apr 9 00:13:06 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 08 Apr 2008 15:13:06 -0700 Subject: [python-win32] Child Windows In-Reply-To: References: <47FBE8C9.3080201@kareta.de> Message-ID: <47FBEDF2.6010905@probo.com> Jo?o Abrantes wrote: > > The thing is that i just gave the notepad as an example. What I really > want is to send long keystrokes to a child window of a game. And the > sendkeys module doesn't allow you to send long keystrokes. So I think > that i really need to use win32api.sendmessage. Many games have controls in place to prevent you from doing this sort of thing. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From kveretennicov at gmail.com Wed Apr 9 00:22:47 2008 From: kveretennicov at gmail.com (Konstantin Veretennicov) Date: Wed, 9 Apr 2008 01:22:47 +0300 Subject: [python-win32] makepy.py not working In-Reply-To: <03e9c33d-d957-4bc0-8568-3a40403eadb9@a70g2000hsh.googlegroups.com> References: <03e9c33d-d957-4bc0-8568-3a40403eadb9@a70g2000hsh.googlegroups.com> Message-ID: <4660fe300804081522g61c51b1fk1fe038f530dbde1b@mail.gmail.com> On Tue, Apr 8, 2008 at 4:18 PM, wrote: > Hallo, > > I've a problem getting makepy running. When I start the tool on my > machine with doubleclick everything is fine. > But when I try this in my Code: > > makepy.py -i "Microsoft Excel 11.0 Object Library(1.5)" This syntax is used to run makepy.py script from command line. > > I am getting an Syntax Error and command: > > makepy.py > > bring me this message on the screen: > > Traceback (most recent call last): > File "", line 1, in > NameError: name 'makepy' is not defined > > Any ideas what I am doing wrong? Python interpreter obviously accepts only valid python code, like this: import win32com.client.makepy win32com.client.makepy.ShowInfo("Microsoft Excel 11.0 Object Library(1.5)") -- kv From jepe_abrantes at hotmail.com Wed Apr 9 21:11:41 2008 From: jepe_abrantes at hotmail.com (=?iso-8859-1?Q?Jo=E3o_Abrantes?=) Date: Wed, 9 Apr 2008 19:11:41 +0000 Subject: [python-win32] Child Windows In-Reply-To: <47FBE964.2030509@probo.com> References: <47FBE964.2030509@probo.com> Message-ID: =D thanks! just one more thing.. how do i found the controls ids of a certain application? > Date: Tue, 8 Apr 2008 14:53:40 -0700 > From: timr at probo.com > To: python-win32 at python.org > Subject: Re: [python-win32] Child Windows > > Jo?o Abrantes wrote: > > Hello, > > > > I am trying to make a program that sends text to notepad using > > win32api.SendMessage function. The thing is that I don't know how to > > get the notepad child window edit handler and I can't find any > > documentation about win32 (python) can you help me? > > Mark Hammond wrote a book on using Python with Win32. Google has lots > of information about it. In large part, however, you are expected to be > pretty comfortable with the Win32 API, and if you are, then figuring out > the Python translations isn't that hard. > > In the meantime can use win32api.FindWindow. The "edit" within Notepad > had control ID 0x0f. So, start up an empty Notepad. Then: > > import win32gui > import win32con > notepad = win32gui.FindWindow( None, "Untitled - Notepad" ) > npedit = win32gui.GetDlgItem( notepad, 0x000f ) > win32gui.SendMessage( npedit, win32con.WM_SETTEXT, 0, "Testing" ) > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080409/72198cab/attachment.htm From timr at probo.com Wed Apr 9 22:41:32 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 09 Apr 2008 13:41:32 -0700 Subject: [python-win32] Child Windows In-Reply-To: References: <47FBE964.2030509@probo.com> Message-ID: <47FD29FC.3020101@probo.com> Jo?o Abrantes wrote: > =D thanks! just one more thing.. how do i found the controls ids of a > certain application? I use the "spyxx.exe" tool included with Visual Studio. Borland has a similar tool called Winsight. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From franck.tab at gmail.com Thu Apr 10 10:54:27 2008 From: franck.tab at gmail.com (franck34) Date: Thu, 10 Apr 2008 10:54:27 +0200 Subject: [python-win32] win32service problems Message-ID: <1b092c390804100154vc037555g5fccbe3b00499ff6@mail.gmail.com> Hi the list, I'm on a problem since 2 days now and i don't know where to continu to investigate ... notice i've started python 2 month ago and honestly, i don't know if my problem is pywin32, or py2exe, or pyInstaller (same behavior) or simply my code. The problem is that i don't have any luck to make a simple Windows Service when my python script is compiled in a full standalone executable. I've tried different version of python (2.4.4, 2.5.1 and 2.5.2) with latests version of theses packages: * python 2.5.2 py2exe-0.6.6.win32-py2.5.exe pywin32-210.win32-py2.5.exe * python 2.4.4 py2exe-0.6.6.win32-py2.4.exe pywin32-210.win32-py2.4.exe I'm on a basic Windows XP SP2, completely up-to-date. Here is the code sample, but notice that the sample provided with py2exe (samples\advanced\MyService.py), and the sample provided with pyWin32 (win32\Demos\service\pipeTestService.py) got the same behavior : import win32service import win32serviceutil #import win32traceutil import time import sys #at this point. We're ready to go. #Put simply, a python windows service inherits from win32serviceutils.ServiceFramework #simply extending that class, sets up all you ever need to do. class aservice(win32serviceutil.ServiceFramework): _svc_name_ = "aservice" _svc_display_name_ = "aservice - It Does nothing" def __init__(self,args): win32serviceutil.ServiceFramework.__init__(self,args) self.isAlive = True def SvcDoRun(self): import servicemanager while self.isAlive: servicemanager.LogInfoMsg("aservice - is alive and well") time.sleep(10) #perhaps must use win32.sleep(10) ? servicemanager.LogInfoMsg("aservice - Stopped") def SvcStop(self): import servicemanager servicemanager.LogInfoMsg("aservice - Recieved stop signal") self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) self.isAlive = False #this will make SvcDoRun() break the while loop at the next iteration. if __name__ == '__main__': print "lets's start, args are : " print sys.argv win32serviceutil.HandleCommandLine(aservice) #this line sets it all up to run properly. Notice you can enable win32traceutil to see stdout. In this case, open another Dos console an execute python C:\Python2X\Lib\site-packages\win32\lib\win32traceutil.py * Using python: python myService.py -install: install the service as expected python myService.py start: start the service as expected python myService.py -remove: remove the service as expected * Using pyInstaller compiled version myService.exe -install : install the service as expected myService.exe start : don't work myService.exe -remove : remove the service as expected pyInstaller 1.3 with python 2.4 : in the python win32traceutil window, you can see that when you start the service using "myService.exe start", myService.exe is launched twice ! Same behavior using pyInstaller trunk checkout with python 2.5.2 The error is " The service did not respond to the start or control request in a timely fashion " Replacing "myService.exe start" with "sc start aservice" output the same thing. * Using py2exe compiled version Every time, i've got Connecting to the Service Control Manager Traceback (most recent call last): File "boot_service.py", line 173, in ? pywintypes.error: (1063, 'StartServiceCtrlDispatcher', "Le processus de service n'a pas pu se connecter au contr\xf4leur de service.") --------------- I have Windows XP SP2 with latest updates and i didn't try on another box (because i got only one ;) I've tried lot's of different service code, install or remove always work, start never I saw some "if sys.frozen" in pywin32 so i know the code is a little bit different when the program is an executable or when it's launched using python command line, perhaps it can be a way to find the problem if it's a pywin32 problem .. Should be great if somebody can help me on this, thanks in advance, Regards, Franck From mhammond at skippinet.com.au Thu Apr 10 12:07:42 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Thu, 10 Apr 2008 20:07:42 +1000 Subject: [python-win32] win32service problems In-Reply-To: <1b092c390804100154vc037555g5fccbe3b00499ff6@mail.gmail.com> References: <1b092c390804100154vc037555g5fccbe3b00499ff6@mail.gmail.com> Message-ID: <020e01c89af2$bac93210$305b9630$@com.au> > pyInstaller 1.3 with python 2.4 : in the python win32traceutil window, > you can see that when you start the service using "myService.exe > start", myService.exe is launched twice ! That's normal - the first time it is loaded it simply connects to the Service Control Manager and request the service be started. The SCN then causes the executable to be loaded as part of running the service. Did you check the Windows event log? Errors encountered by the service framework will be dumped there. Cheers, Mark From iceblink at chello.nl Thu Apr 10 13:30:07 2008 From: iceblink at chello.nl (iceblink at chello.nl) Date: Thu, 10 Apr 2008 13:30:07 +0200 Subject: [python-win32] exception while opening excel file Message-ID: <30285009.1207827007144.JavaMail.root@viefep27> Hi all, I'm trying to write a file that does something with excel files. Unfortunately all these files will give an error upon opening: Errors were detected in 'file.xls', but MS Excel was able to open the file by making the repairs listed below. Save the file to make these repairs permanent. Renamed invalid sheet name. I've tried to get some more information through the py-win32 exceptions but only got this output out of my application: The Excel call failed with code -2147352567: Exception occurred. The source of the error is Microsoft Excel The error message is Open method of Workbooks class failed More info can be found in C:\Program Files\Microsoft Office\Office10\1033\xlmain10.chm (id=0) Normally I can just press "close" in the excel error box, and continue to work on the file. But how do I handle this in py-win32? Best regards, Patrick Asselman From whatyoulookin at yahoo.com Thu Apr 10 18:59:54 2008 From: whatyoulookin at yahoo.com (Alec Bennett) Date: Thu, 10 Apr 2008 09:59:54 -0700 (PDT) Subject: [python-win32] How to clear a "dead" icon from system tray? Message-ID: <997714.36610.qm@web54605.mail.re2.yahoo.com> I'm ending task on a process that has a system tray icon, which works but it leaves an icon behind in the system tray, which only goes away if I mouse over it. Can anyone think of a way to force a refresh of the system tray without mousing over it? I know this is adding duct tape over duct tape, but the only way I've found to close this program from Python is with an (automated) end task. Thanks for any help. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From timr at probo.com Thu Apr 10 19:17:08 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 10 Apr 2008 10:17:08 -0700 Subject: [python-win32] How to clear a "dead" icon from system tray? In-Reply-To: <997714.36610.qm@web54605.mail.re2.yahoo.com> References: <997714.36610.qm@web54605.mail.re2.yahoo.com> Message-ID: <47FE4B94.9070905@probo.com> Alec Bennett wrote: > I'm ending task on a process that has a system tray icon, which works but it leaves an icon behind > in the system tray, which only goes away if I mouse over it. Can anyone think of a way to force a > refresh of the system tray without mousing over it? > > I know this is adding duct tape over duct tape, but the only way I've found to close this program > from Python is with an (automated) end task. > Mousing over is really the only way. If you don't get a chance to clean up after yourself, no one else can do it. You're talking about a fairly serious design flaw here. What is preventing you from shutting down in an orderly way? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From whatyoulookin at yahoo.com Thu Apr 10 19:44:00 2008 From: whatyoulookin at yahoo.com (Alec Bennett) Date: Thu, 10 Apr 2008 10:44:00 -0700 (PDT) Subject: [python-win32] How to clear a "dead" icon from system tray? In-Reply-To: <47FE4B94.9070905@probo.com> Message-ID: <736934.39599.qm@web54607.mail.re2.yahoo.com> > You're talking about a fairly serious design flaw here. Agreed. > What is preventing you from shutting down in an orderly way? I'm controlling an onscreen keyboard through a Com interface and when I attempt to close it I get a Com Server error telling me there are still connections to the Com object, am I sure I want to close it? I found a method to show references to the Com object and it would always show 2 references, but I forgot what that code is so I can't repeat it. Here's how I'm launching my Com object: import win32com.client kb = win32com.client.Dispatch("Kbd.mfSoftkeys") kb.LoadKeyboard("keyboard_file.kbd") --- Tim Roberts wrote: > Alec Bennett wrote: > > I'm ending task on a process that has a system tray icon, which works but it leaves an icon > behind > > in the system tray, which only goes away if I mouse over it. Can anyone think of a way to > force a > > refresh of the system tray without mousing over it? > > > > I know this is adding duct tape over duct tape, but the only way I've found to close this > program > > from Python is with an (automated) end task. > > > > Mousing over is really the only way. If you don't get a chance to clean > up after yourself, no one else can do it. > > You're talking about a fairly serious design flaw here. What is > preventing you from shutting down in an orderly way? > > -- > Tim Roberts, timr at probo.com > Providenza & Boekelheide, Inc. > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From timr at probo.com Thu Apr 10 20:14:58 2008 From: timr at probo.com (Tim Roberts) Date: Thu, 10 Apr 2008 11:14:58 -0700 Subject: [python-win32] How to clear a "dead" icon from system tray? In-Reply-To: <736934.39599.qm@web54607.mail.re2.yahoo.com> References: <736934.39599.qm@web54607.mail.re2.yahoo.com> Message-ID: <47FE5922.8030107@probo.com> Alec Bennett wrote: > >> What is preventing you from shutting down in an orderly way? >> > > I'm controlling an onscreen keyboard through a Com interface and when I attempt to close it I get > a Com Server error telling me there are still connections to the Com object, am I sure I want to > close it? I found a method to show references to the Com object and it would always show 2 > references, but I forgot what that code is so I can't repeat it. > > Here's how I'm launching my Com object: > > import win32com.client > kb = win32com.client.Dispatch("Kbd.mfSoftkeys") > kb.LoadKeyboard("keyboard_file.kbd") > Interesting. You're saying that the normal del kb is not enough to clean this up? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From whatyoulookin at yahoo.com Thu Apr 10 20:58:20 2008 From: whatyoulookin at yahoo.com (Alec Bennett) Date: Thu, 10 Apr 2008 11:58:20 -0700 (PDT) Subject: [python-win32] How to clear a "dead" icon from system tray? In-Reply-To: <47FE5922.8030107@probo.com> Message-ID: <805858.4946.qm@web54607.mail.re2.yahoo.com> > Interesting. You're saying that the normal > del kb is not enough to clean this up? Whoops, user error. I had declared my com object as global so I could delete it from somewhere else, but forgot to declare it as global before deleting it.... Works fine now, thanks. And for anyone coming down this path, I mentioned a way to get the reference count of a com object, just remembered how to do it: sys.getrefcount(kb) __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com From mhammond at skippinet.com.au Fri Apr 11 00:48:58 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 11 Apr 2008 08:48:58 +1000 Subject: [python-win32] exception while opening excel file In-Reply-To: <30285009.1207827007144.JavaMail.root@viefep27> References: <30285009.1207827007144.JavaMail.root@viefep27> Message-ID: <02af01c89b5d$13d6fee0$3b84fca0$@com.au> > Normally I can just press "close" in the excel error box, and continue > to work on the file. But how do I handle this in py-win32? So what happens when you try to open it normally? Mark From mhammond at skippinet.com.au Fri Apr 11 00:50:54 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 11 Apr 2008 08:50:54 +1000 Subject: [python-win32] holiday Message-ID: <02b001c89b5d$56891f70$039b5e50$@com.au> Hi all, FYI, I'm off on a 2 week vacation to China (wheeee!) and will not be checking email or doing anything else that is even vaguely related to work! I'll catch up when I get back (and pywin32-211 should be *very* close by then - all installer issues are done - I just gotta get Roger to take a vacation too :) Cheers, Mark From mhammond at skippinet.com.au Fri Apr 11 01:12:28 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Fri, 11 Apr 2008 09:12:28 +1000 Subject: [python-win32] exception while opening excel file In-Reply-To: <02af01c89b5d$13d6fee0$3b84fca0$@com.au> References: <30285009.1207827007144.JavaMail.root@viefep27> <02af01c89b5d$13d6fee0$3b84fca0$@com.au> Message-ID: <02b601c89b60$5bb42f00$131c8d00$@com.au> > > Normally I can just press "close" in the excel error box, and > continue > > to work on the file. But how do I handle this in py-win32? > > So what happens when you try to open it normally? Oops - sorry - I see you already gave the exception you get trying to open the file. I'm afraid I don't know the answer though. Mark From franck.tab at gmail.com Fri Apr 11 08:56:35 2008 From: franck.tab at gmail.com (franck34) Date: Fri, 11 Apr 2008 08:56:35 +0200 Subject: [python-win32] windows service sample using py2exe Message-ID: <1b092c390804102356x4ea466bax4e592205b6e22253@mail.gmail.com> # Warning: setup.py require cmdline_style='pywin32' # Usage: # service.exe install # service.exe start # service.exe stop # service.exe remove # you can see output of this program running python site-packages\win32\lib\win32traceutil # setup.py #from distutils.core import setup #import py2exe # #class Target: # def __init__(self, **kw): # self.__dict__.update(kw) # # for the versioninfo resources # self.version = "0.5.0" # self.company_name = "No Company" # self.copyright = "no copyright" # self.name = "py2exe sample files" # # #myservice = Target( # description = 'foo', # modules = ['service'], # cmdline_style='pywin32' #) # #setup( # options = {"py2exe": {"compressed": 1, "bundle_files": 1} }, # console=["service.py"], # zipfile = None, # service=[myservice] #) import win32service import win32serviceutil import win32event import win32evtlogutil import win32traceutil import time import sys class aservice(win32serviceutil.ServiceFramework): _svc_name_ = "aservice" _svc_display_name_ = "aservice - It Does nothing" _svc_deps_ = ["EventLog"] def __init__(self,args): win32serviceutil.ServiceFramework.__init__(self,args) self.hWaitStop=win32event.CreateEvent(None, 0, 0, None) self.isAlive=True def SvcStop(self): # tell Service Manager we are trying to stop (required) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # write a message in the SM (optional) # import servicemanager # servicemanager.LogInfoMsg("aservice - Recieved stop signal") # set the event to call win32event.SetEvent(self.hWaitStop) self.isAlive=False def SvcDoRun(self): import servicemanager # Write a 'started' event to the event log... (not required) # win32evtlogutil.ReportEvent(self._svc_name_,servicemanager.PYS_SERVICE_STARTED,0, servicemanager.EVENTLOG_INFORMATION_TYPE,(self._svc_name_, '')) # methode 1: wait for beeing stopped ... # win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) # methode 2: wait for beeing stopped ... self.timeout=1000 # In milliseconds (update every second) while self.isAlive: # wait for service stop signal, if timeout, loop again rc=win32event.WaitForSingleObject(self.hWaitStop, self.timeout) print "looping" # and write a 'stopped' event to the event log (not required) # win32evtlogutil.ReportEvent(self._svc_name_,servicemanager.PYS_SERVICE_STOPPED,0, servicemanager.EVENTLOG_INFORMATION_TYPE,(self._svc_name_, '')) self.ReportServiceStatus(win32service.SERVICE_STOPPED) return if __name__ == '__main__': win32serviceutil.HandleCommandLine(aservice) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080411/3cc77312/attachment-0001.htm From franck.tab at gmail.com Fri Apr 11 08:57:08 2008 From: franck.tab at gmail.com (franck34) Date: Fri, 11 Apr 2008 08:57:08 +0200 Subject: [python-win32] windows service sample using pyInstaller Message-ID: <1b092c390804102357s30400c35kd86f7a00c843a26c@mail.gmail.com> # Usage: # service.exe install # service.exe start # service.exe stop # service.exe remove # you can see output of this program running python site-packages\win32\lib\win32traceutil import win32service import win32serviceutil import win32event import win32evtlogutil import win32traceutil import servicemanager import winerror import time import sys class aservice(win32serviceutil.ServiceFramework): _svc_name_ = "aservice" _svc_display_name_ = "aservice - It Does nothing" _svc_deps_ = ["EventLog"] def __init__(self,args): win32serviceutil.ServiceFramework.__init__(self,args) self.hWaitStop=win32event.CreateEvent(None, 0, 0, None) self.isAlive=True def SvcStop(self): # tell Service Manager we are trying to stop (required) self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) # write a message in the SM (optional) # import servicemanager # servicemanager.LogInfoMsg("aservice - Recieved stop signal") # set the event to call win32event.SetEvent(self.hWaitStop) self.isAlive=False def SvcDoRun(self): import servicemanager # Write a 'started' event to the event log... (not required) # win32evtlogutil.ReportEvent(self._svc_name_,servicemanager.PYS_SERVICE_STARTED,0, servicemanager.EVENTLOG_INFORMATION_TYPE,(self._svc_name_, '')) # methode 1: wait for beeing stopped ... # win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) # methode 2: wait for beeing stopped ... self.timeout=1000 # In milliseconds (update every second) while self.isAlive: # wait for service stop signal, if timeout, loop again rc=win32event.WaitForSingleObject(self.hWaitStop, self.timeout) print "looping" # and write a 'stopped' event to the event log (not required) # win32evtlogutil.ReportEvent(self._svc_name_,servicemanager.PYS_SERVICE_STOPPED,0, servicemanager.EVENTLOG_INFORMATION_TYPE,(self._svc_name_, '')) self.ReportServiceStatus(win32service.SERVICE_STOPPED) return if __name__ == '__main__': # if called without argvs, let's run ! if len(sys.argv) == 1: try: evtsrc_dll = os.path.abspath(servicemanager.__file__) servicemanager.PrepareToHostSingle(aservice) servicemanager.Initialize('aservice', evtsrc_dll) servicemanager.StartServiceCtrlDispatcher() except win32service.error, details: if details[0] == winerror.ERROR_FAILED_SERVICE_CONTROLLER_CONNECT: win32serviceutil.usage() else: win32serviceutil.HandleCommandLine(aservice) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080411/eac6c21b/attachment.htm From le.dahut at laposte.net Fri Apr 11 11:58:10 2008 From: le.dahut at laposte.net (le dahut) Date: Fri, 11 Apr 2008 11:58:10 +0200 Subject: [python-win32] Reboot apis don't work in a NT service In-Reply-To: <47E3E447.1050703@laposte.net> References: <47E235FE.4020409@laposte.net> <47E287D2.6050904@timgolden.me.uk> <47E3E447.1050703@laposte.net> Message-ID: <47FF3632.5000709@laposte.net> Actually it seems that this is a behavior corrected in XP Service pack 2. No exception, win32api.InitiateSystemShutdown does correctly his job, fine. le dahut wrote : > With "InitiateSystemShutdown" I get : > 21, "Device is not ready." > > with "WTSShutdownSystem" : > 1702, "The binding handle is invalid." > but even if I don't logon, it reboots after approximately 15 loops of 2 > seconds but after reboot the machine is extremely slow and has a strange > behavior > > "ExitWindowsEx" does its job correctly excepted that the workstation is > extremly slow and need a manual reboot to work fine... > > Klaas > > > Tim Golden wrote : >> le dahut wrote: >>> To reboot the computer I've tried this different functions : >>> win32api.ExitWindowsEx(EWX_REBOOT | EWX_FORCE) >>> win32api.InitiateSystemShutdown(None, '', 0, True, 1) >>> win32ts.WTSShutdownSystem(wts.WTS_CURRENT_SERVER_HANDLE, wts.WTS_WSD_REBOOT) >>> wa.WinExec('shutdown -r -t 0 -f') >>> >>> I've correctly setup 'SeShutdownPrivilege' before calling them. >>> The "bForceAppsClosed" is set to True >>> >>> >>> Since I noticed that they didn't reboot the computer but raised an >>> error, I've put them in a loop : >>> while True: >>> try: >>> wa.ExitWindowsEx(...) >>> break >>> except Exception, e: >>> logging.error('%s'%e) >>> time.sleep(0.5) >>> >>> This permits to reboot the workstation after several minutes (between 3 >>> and 9 minutes). >> I'm not sure I can personally offer much here, le dahut, but >> it would help if you showed the traceback you *are* getting. >> Surely there's some clue in there which might suggest why >> you're prevented from rebooting before a delay period. >> >> TJG From huayang.xia at gmail.com Fri Apr 11 15:41:10 2008 From: huayang.xia at gmail.com (Huayang Xia) Date: Fri, 11 Apr 2008 09:41:10 -0400 Subject: [python-win32] Convert PyIDispatch object to struct IDispatch* Message-ID: <24f059080804110641o280db4dfl3e2b1998063a5e23@mail.gmail.com> I am trying to use ctypes to call dll functions. One of the functions requires argument "struct IDispatch* ". I do have a PyIDispatch object in python. How can I convert this "PyIDispatch object" to "struct IDispatch* "? Thanks in advance. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080411/4df6345a/attachment.htm From theller at ctypes.org Fri Apr 11 18:31:03 2008 From: theller at ctypes.org (Thomas Heller) Date: Fri, 11 Apr 2008 18:31:03 +0200 Subject: [python-win32] Convert PyIDispatch object to struct IDispatch* In-Reply-To: <24f059080804110641o280db4dfl3e2b1998063a5e23@mail.gmail.com> References: <24f059080804110641o280db4dfl3e2b1998063a5e23@mail.gmail.com> Message-ID: Huayang Xia schrieb: > I am trying to use ctypes to call dll functions. One of the functions > requires argument "struct IDispatch* ". I do have a PyIDispatch object > in python. How can I convert this "PyIDispatch object" to "struct > IDispatch* "? > Thanks in advance. The only way (that I know of) to retrieve the 'IDispatch*' pointer from the PyIDispatch object is to print it: >>> from win32com.client import Dispatch >>> ie = Dispatch("InternetExplorer.Application") >>> print ie Windows Internet Explorer >>> repr(ie) '' >>> print ie._oleobj_ >>> The last number is the pointer in question, you can parse it from the repr and pass it to the ctypes function call. For fun, attached is a script that creates a comtypes IDispatch pointer from the PyIDispatch object. Thomas # Shows how to convert an pywin32 PyIDispatch object # into a comtypes COM pointer. from win32com.client import Dispatch d = Dispatch("InternetExplorer.Application") x = d._oleobj_ print repr(x) # repr(x) is like this: # # # The last number is the address of the IDispatch pointer: addr = int(repr(x).split()[-1][2:-1], 16) print hex(addr) from ctypes import * from comtypes.automation import IDispatch from _ctypes import CopyComPointer # create a NULL comtypes pointer p = POINTER(IDispatch)() # put the IDispatch pointer into the comtypes IDispatch # pointer: cast(byref(p), POINTER(c_void_p))[0] = addr # Call AddRef(), since the comtypes pointer will call Release() when # it goes away: p.AddRef() print p From s.khushalani at yahoo.co.uk Fri Apr 11 20:58:48 2008 From: s.khushalani at yahoo.co.uk (Sagar Khushalani) Date: Fri, 11 Apr 2008 11:58:48 -0700 (PDT) Subject: [python-win32] python and soap? Message-ID: <146996.61848.qm@web28311.mail.ukl.yahoo.com> i guess this question has been asked lots of times, but can anyone suggest any good way of using SOAP and python 2.5? if not, is there any other versions (>2.3) that i can use? i need it for a school project and so have to use SOAP... thanks in advance! - sagar Sagar Khushalani Graduate Student, UTA Networking / Systems and Architecture s.khushalani at yahoo.co.uk http://www.sagark.info __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080411/c89d355d/attachment.htm From gerdusvanzyl at gmail.com Fri Apr 11 21:53:08 2008 From: gerdusvanzyl at gmail.com (Gerdus van Zyl) Date: Fri, 11 Apr 2008 21:53:08 +0200 Subject: [python-win32] python and soap? In-Reply-To: <146996.61848.qm@web28311.mail.ukl.yahoo.com> References: <146996.61848.qm@web28311.mail.ukl.yahoo.com> Message-ID: <91882ea90804111253md172502mefcd6a2ee69061cf@mail.gmail.com> See this blog post: http://www.kunxi.org/archives/2008/01/pythonsoap-second-encounter/ http://pywebsvcs.sourceforge.net/ http://trac.optio.webfactional.com/ The choice depends on your requirements. On Fri, Apr 11, 2008 at 8:58 PM, Sagar Khushalani wrote: > i guess this question has been asked lots of times, but can anyone suggest > any good way of using SOAP and python 2.5? if not, is there any other > versions (>2.3) that i can use? > > i need it for a school project and so have to use SOAP... > > thanks in advance! > - sagar > > > *Sagar Khushalani* > Graduate Student, UTA > Networking / Systems and Architecture > s.khushalani at yahoo.co.uk > http://www.sagark.info > > __________________________________________________ > > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > _______________________________________________ > python-win32 mailing list > python-win32 at 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/20080411/b0449aaa/attachment.htm From s.khushalani at yahoo.co.uk Mon Apr 14 00:58:13 2008 From: s.khushalani at yahoo.co.uk (Sagar Khushalani) Date: Mon, 14 Apr 2008 00:58:13 +0200 (CEST) Subject: [python-win32] python and soap? Message-ID: <856327.91761.qm@web28312.mail.ukl.yahoo.com> hey thank you for that...i just downloaded suds. it seems easy to work with. however, i'm having a problem, and you said you've used it so... i tried connecting to http://www.html2xml.nl/Services/Calculator/Version1/Calculator.asmx?WSDL for the service. however, whenever i try to use the "Add" service there, i get the following error: Traceback (most recent call last): File "", line 1, in s.Add(1,2) File "C:\Python25\lib\site-packages\suds-0.1.7-py2.5.egg\suds\serviceproxy.py", line 131, in __call__ raise e WebFault: service endpoint raised fault { faultcode = (soap:Client) faultstring = (Server did not recognize the value of HTTP Header SOAPAction: .) detail = () } how do i set the SOAPAction or what do i do about it? i'm not exactly sure whats going wrong... thanks! - sagar Sagar Khushalani Graduate Student, UTA Networking / System Architecture s.khushalani at yahoo.co.uk http://www.sagark.info ----- Original Message ---- From: Jose Galvez To: Sagar Khushalani Sent: Friday, April 11, 2008 7:53:36 PM Subject: Re: [python-win32] python and soap? depends on if you want to be a SOAP service provider or if you want to use a SOAP service in python? I just finished a project where I am hosting SOAP services and I used pylons and soaplib (http://pypi.python.org/pypi/soaplib/0.7.1dev-r17), I've also used suds (http://pypi.python.org/pypi/suds/0.1.7) to access soap services. Both are pretty easy to use Jose Sagar Khushalani wrote: i guess this question has been asked lots of times, but can anyone suggest any good way of using SOAP and python 2.5? if not, is there any other versions (>2.3) that i can use? i need it for a school project and so have to use SOAP... thanks in advance! - sagar Sagar Khushalani Graduate Student, UTA Networking / Systems and Architecture s.khushalani at yahoo.co.uk http://www.sagark.info __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080414/a5f04764/attachment.htm From andrea.gavana at gmail.com Mon Apr 14 13:49:09 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Mon, 14 Apr 2008 12:49:09 +0100 Subject: [python-win32] Overlay Icon Question... Message-ID: Hi All, I have a GUI app, written in wxPython, which allows the user to load one or more files (always with the extension *.DATA) and to save some data in a database. Now, I would like to assign an overlay to the icon of the files added to the database, leaving the other files (with the same file extension, but not added to the database) with their own icon. One of the guy in the wxPython mailing list pointed me here: http://mail.python.org/pipermail/python-win32/2008-January/006691.html But it looks like his solution does not work: http://mail.python.org/pipermail/python-win32/2008-January/006695.html Anyway, I have a couple of question: 1) I have looked the implementation mentioned in the link above, but it is a bit unclear to me: how do I actually *use* this class? All my users have the extension "*.DATA" associated with the Wordpad or Notepad or similar icons, as they use these editors to open these file? Should I tamper the registry where the *.DATA extension is stored? I am really lost here. 2) Can I assign this overlay icon to a particular file (without touching the others with the same extension)? And if so, how? 3) Is the problem mentioned in the thread above still present? Will it affect also my GUI, even though it is writte in wxPython? Sorry for the very newbie questions, I am just a beginner with win32all. I have tried to mess around with some code found in CodeProject: http://www.codeproject.com/KB/shell/overlayicon.aspx And with the one in TortoiseSVN source code, but both are way over my head :-( Thank you for your suggestions. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From mail at timgolden.me.uk Mon Apr 14 18:07:22 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 14 Apr 2008 17:07:22 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: Message-ID: <4803813A.6000407@timgolden.me.uk> Andrea Gavana wrote: > 1) I have looked the implementation mentioned in the link above, but > it is a bit unclear to me: how do I actually *use* this class? All my > users have the extension "*.DATA" associated with the Wordpad or > Notepad or similar icons, as they use these editors to open these > file? Should I tamper the registry where the *.DATA extension is > stored? I am really lost here. > Sorry for the very newbie questions, I am just a beginner with win32all. > I have tried to mess around with some code found in CodeProject: > http://www.codeproject.com/KB/shell/overlayicon.aspx > And with the one in TortoiseSVN source code, but both are way over my head :-( I'm afraid you haven't chosen a particularly easy entree into the world of Windows! Some shell things (that's things which affect the appearance and actions of Explorer and the Desktop) are fairly easy to effect (and affect), requiring just some simple registry manipulation. But the more complex and interesting things require what's known as a Shell Namespace Extension. Basically, you register interest in one or more file types in the registry, identifying a specific set of callbacks which the Shell (explorer.exe or whatever) calls whenever it sees a file in which you're interested. This is the kind of thing which gives context-sensitive menus depending on file type and content and icon overlays of the sort you're describing. > 2) Can I assign this overlay icon to a particular file (without > touching the others with the same extension)? And if so, how? In principle, yes. I haven't done it myself, but if someone more experienced doesn't chip in with an example, I'll try to put one together myself. I warn you, though, with this kind of thing you're working within Windows: the pywin32 modules are simply wrapping the raw interface. So it won't be pretty! > 3) Is the problem mentioned in the thread above still present? Will it > affect also my GUI, even though it is writte in wxPython? I must admit to no more than a passing familiarity with wxPython, but I'd be rather surprised if it offered something as platform-specific and ticklish as icon overlays for the Windows shell. I'd be very glad to be wrong for your sake! If wxPython *does* offer overlays using pywin32 code, it will share that code's problems; if they have their own implementation then probably not. TJG From rdahlstrom at directedge.com Mon Apr 14 19:39:29 2008 From: rdahlstrom at directedge.com (Dahlstrom, Roger) Date: Mon, 14 Apr 2008 13:39:29 -0400 Subject: [python-win32] IsHungAppWindow or equivalent Message-ID: <68D737040F1D204CA68A38C372141F44CF0E60@jc1wsmail3.global.knight.com> I am trying to determine whether an application is reporting "Not Responding" (like what the task manager shows). I'm not married to the IsHungAppWindow method, it was just suggested to me, and seemed like the right path to go down. My questions are: 1. Are there any win32 Python extensions that expose this? If so, which ones? 2. If there are not extensions, does anyone know what the user32 .dll in windows is expecting as a parameter (using ctypes)? I've tried all the ints to no avail. Sorry if this has been covered - if it has been, I was unable to find it. Thanks -Roger DISCLAIMER: This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof. E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. NOTICE REGARDING PRIVACY AND CONFIDENTIALITY Direct Edge ECN LLC may, at its discretion, monitor and review the content of all e-mail communications. www.directedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080414/7fbd7d54/attachment.htm From timr at probo.com Mon Apr 14 20:14:39 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 14 Apr 2008 11:14:39 -0700 Subject: [python-win32] IsHungAppWindow or equivalent In-Reply-To: <68D737040F1D204CA68A38C372141F44CF0E60@jc1wsmail3.global.knight.com> References: <68D737040F1D204CA68A38C372141F44CF0E60@jc1wsmail3.global.knight.com> Message-ID: <48039F0F.5010804@probo.com> Dahlstrom, Roger wrote: > > I am trying to determine whether an application is reporting "Not > Responding" (like what the task manager shows). I'm not married to > the IsHungAppWindow method, it was just suggested to me, and seemed > like the right path to go down. > It is the same API that Task Manager uses. > My questions are: > > 1. Are there any win32 Python extensions that expose this? If so, > which ones? > I doubt it; it's not available prior to Windows 2000, and MSDN says they might decide to change it later. > 2. If there are not extensions, does anyone know what the user32 .dll > in windows is expecting as a parameter (using ctypes)? > Really? The very first Google hit is the MSDN page, which shows the parameters. It wants a window handle -- an HWND. That is a 32-bit integer on Win32, and a 64-bit integer on Win64. > I've tried all the ints to no avail. > What do you mean by "to no avail"? Where did you get the window handle? What happened when you tried it? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rdahlstrom at directedge.com Mon Apr 14 20:27:06 2008 From: rdahlstrom at directedge.com (Dahlstrom, Roger) Date: Mon, 14 Apr 2008 14:27:06 -0400 Subject: [python-win32] IsHungAppWindow or equivalent In-Reply-To: <48039F0F.5010804@probo.com> References: <68D737040F1D204CA68A38C372141F44CF0E60@jc1wsmail3.global.knight.com> <48039F0F.5010804@probo.com> Message-ID: <68D737040F1D204CA68A38C372141F44CF0E62@jc1wsmail3.global.knight.com> Dahlstrom, Roger wrote: > My questions are: > 1. Are there any win32 Python extensions that expose this? If so, > which ones? I doubt it; it's not available prior to Windows 2000, and MSDN says they might decide to change it later. > 2. If there are not extensions, does anyone know what the user32 .dll > in windows is expecting as a parameter (using ctypes)? Really? The very first Google hit is the MSDN page, which shows the parameters. It wants a window handle -- an HWND. That is a 32-bit integer on Win32, and a 64-bit integer on Win64. > I've tried all the ints to no avail. > What do you mean by "to no avail"? Where did you get the window handle? What happened when you tried it? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. 1. OK, thanks - I will keep going down the IsHungAppWindow path. 2. Yeah - I see the MSDN page and the HWND parameter. I tried the following data types: C_short, c_ushort, c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong. "To no avail" means that I got the same message (which I should've included, sorry) when using any of them. That error is: Traceback (most recent call last): File "enumWindows.py", line 13, in for wind in topWindows: File "enumWindows.py", line 8, in getText resultList.append((hwnd, win32gui.GetWindowText(hwnd), win32process.GetWindowThreadProcessId(hwnd)[1]), u32.IsHungAppWindow(chwnd)) ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong calling convention In the above traceback, hwnd is a Python variable, and chwnd is the ctypes variable assigned from hwnd, which I get from win32gui.EnumWindows(). DISCLAIMER: This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof. E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. NOTICE REGARDING PRIVACY AND CONFIDENTIALITY Direct Edge ECN LLC may, at its discretion, monitor and review the content of all e-mail communications. www.directedge.com From mail at timgolden.me.uk Mon Apr 14 21:09:36 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 14 Apr 2008 20:09:36 +0100 Subject: [python-win32] IsHungAppWindow or equivalent In-Reply-To: <68D737040F1D204CA68A38C372141F44CF0E62@jc1wsmail3.global.knight.com> References: <68D737040F1D204CA68A38C372141F44CF0E60@jc1wsmail3.global.knight.com> <48039F0F.5010804@probo.com> <68D737040F1D204CA68A38C372141F44CF0E62@jc1wsmail3.global.knight.com> Message-ID: <4803ABF0.1040003@timgolden.me.uk> Dahlstrom, Roger wrote: > Yeah - I see the MSDN page and the HWND parameter. > I tried the following data types: C_short, c_ushort, c_int, c_uint, > c_long, c_ulong, c_longlong, c_ulonglong. ctypes includes a handy wintypes subpackage: from ctypes import wintypes print wintype.HWND So, in principle: import win32gui import ctypes from ctypes.wintypes import HWND IsHungAppWindow = ctypes.windll.user32.IsHungAppWindow def callback (hwnd, *args): if IsHungAppWindow (HWND (hwnd)): print win32gui.GetWindowText (hwnd) win32gui.EnumWindows (callback, None) TJG From rdahlstrom at directedge.com Mon Apr 14 21:18:19 2008 From: rdahlstrom at directedge.com (Dahlstrom, Roger) Date: Mon, 14 Apr 2008 15:18:19 -0400 Subject: [python-win32] IsHungAppWindow or equivalent In-Reply-To: <4803ABF0.1040003@timgolden.me.uk> References: <68D737040F1D204CA68A38C372141F44CF0E60@jc1wsmail3.global.knight.com> <48039F0F.5010804@probo.com><68D737040F1D204CA68A38C372141F44CF0E62@jc1wsmail3.global.knight.com> <4803ABF0.1040003@timgolden.me.uk> Message-ID: <68D737040F1D204CA68A38C372141F44CF0E64@jc1wsmail3.global.knight.com> -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Tim Golden Sent: Monday, April 14, 2008 3:10 PM Cc: Python-Win32 List Subject: Re: [python-win32] IsHungAppWindow or equivalent Dahlstrom, Roger wrote: > Yeah - I see the MSDN page and the HWND parameter. > I tried the following data types: C_short, c_ushort, c_int, c_uint, > c_long, c_ulong, c_longlong, c_ulonglong. ctypes includes a handy wintypes subpackage: from ctypes import wintypes print wintype.HWND So, in principle: import win32gui import ctypes from ctypes.wintypes import HWND IsHungAppWindow = ctypes.windll.user32.IsHungAppWindow def callback (hwnd, *args): if IsHungAppWindow (HWND (hwnd)): print win32gui.GetWindowText (hwnd) win32gui.EnumWindows (callback, None) TJG ============================================================= That was exactly it - the HWND data type works perfect. Thanks! -Roger DISCLAIMER: This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof. E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. NOTICE REGARDING PRIVACY AND CONFIDENTIALITY Direct Edge ECN LLC may, at its discretion, monitor and review the content of all e-mail communications. www.directedge.com From andrea.gavana at gmail.com Mon Apr 14 21:44:50 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Mon, 14 Apr 2008 20:44:50 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: <4803813A.6000407@timgolden.me.uk> References: <4803813A.6000407@timgolden.me.uk> Message-ID: Hi Tim, On Mon, Apr 14, 2008 at 5:07 PM, Tim Golden wrote: > Andrea Gavana wrote: > > 1) I have looked the implementation mentioned in the link above, but > > it is a bit unclear to me: how do I actually *use* this class? All my > > users have the extension "*.DATA" associated with the Wordpad or > > Notepad or similar icons, as they use these editors to open these > > file? Should I tamper the registry where the *.DATA extension is > > stored? I am really lost here. > > > Sorry for the very newbie questions, I am just a beginner with win32all. > > I have tried to mess around with some code found in CodeProject: > > http://www.codeproject.com/KB/shell/overlayicon.aspx > > And with the one in TortoiseSVN source code, but both are way over my head :-( > > I'm afraid you haven't chosen a particularly easy entree into > the world of Windows! Some shell things (that's things which > affect the appearance and actions of Explorer and the Desktop) > are fairly easy to effect (and affect), requiring just some simple > registry manipulation. But the more complex and interesting things > require what's known as a Shell Namespace Extension. > > Basically, you register interest in one or more file types in the registry, > identifying a specific set of callbacks which the Shell (explorer.exe or > whatever) calls whenever it sees a file in which you're interested. > This is the kind of thing which gives context-sensitive menus depending > on file type and content and icon overlays of the sort you're describing. Thank you very much for your answer. I am such a newbie with win32all (I have done only very basic things for my open source wxPython widgets) that I don't even know where to look for. > > 2) Can I assign this overlay icon to a particular file (without > > touching the others with the same extension)? And if so, how? > > In principle, yes. I haven't done it myself, but if someone more > experienced doesn't chip in with an example, I'll try to put one together > myself. I warn you, though, with this kind of thing you're working within > Windows: the pywin32 modules are simply wrapping the raw interface. > So it won't be pretty! If you could help me sort this out, it would be great. I don't really care if it is a nice code or not, it's just my users' request and I would like to be able to prove, once again, the power of Python :-D. > > 3) Is the problem mentioned in the thread above still present? Will it > > affect also my GUI, even though it is writte in wxPython? > > I must admit to no more than a passing familiarity with wxPython, but I'd > be rather surprised if it offered something as platform-specific and ticklish > as icon overlays for the Windows shell. I'd be very glad to be wrong for your > sake! If wxPython *does* offer overlays using pywin32 code, it will share that > code's problems; if they have their own implementation then probably not. I am sorry I didn't explain myself very well: no, wxPython does not have this thing, I will be using pywin32 pure code for the overlay icon. wxPython does offer platform indipendent and native-look widgets: the difference between my application and the one mentioned in the thread above, is that I won't use pywin32 GUI code at all, as all the GUI code is provided by wxPython and the underlying platform. So, in theory, the SaveDialog "freezing" experienced by the thread above should not happen... in theory... Thank you for your help and suggestions. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From rwupole at msn.com Tue Apr 15 01:21:51 2008 From: rwupole at msn.com (Roger Upole) Date: Mon, 14 Apr 2008 19:21:51 -0400 Subject: [python-win32] Overlay Icon Question... Message-ID: I've been meaning to look at how this works for some time, so I took a few minutes to cook up an example (attached). Roger -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: IShellIconOverlayIdentifier.py Url: http://mail.python.org/pipermail/python-win32/attachments/20080414/b236b9d1/attachment.txt From mail at timgolden.me.uk Tue Apr 15 09:53:03 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Apr 2008 08:53:03 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: Message-ID: <48045EDF.4090003@timgolden.me.uk> Roger Upole wrote: > I've been meaning to look at how this works for some time, > so I took a few minutes to cook up an example (attached). (Thanks. I didn't really have enough time to put this together at the moment!) > def GetPriority(self): > return 50 I was wondering how all the different handlers fought over who got the overlay. I sort of imagined the icon corners flickering between different images as each handler tried to get its overlay in place :) TJG From andrea.gavana at gmail.com Tue Apr 15 10:40:24 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Tue, 15 Apr 2008 09:40:24 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: Message-ID: Hi Roger, On Tue, Apr 15, 2008 at 12:21 AM, Roger Upole wrote: > I've been meaning to look at how this works for some time, > so I took a few minutes to cook up an example (attached). Thank you very much for the sample! It is really enlighting. I have however some difficulty to understand it (sorry for the dumb questions): 1) How do you actually use the SIOI class? I tried to run the sample, then creating various files here and there in my hard drive, but I don't really know what IsMemberOf() is accepting as fname to make the overlay. Is it the file name? The icon name? Something else? 2) Let's suppose that I want to assign an overlayed icon to a particular file in a directory: let's say this file is called "HELLO.DATA" and the directory contains also other files with the .DATA extension. What should I do to assign the overlayed icon only to this particular file? Thank you very much for the sample, I am going to use some google-fu to understand better how it works. And thanks for your suggestions. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From mail at timgolden.me.uk Tue Apr 15 10:42:32 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Apr 2008 09:42:32 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: Message-ID: <48046A78.6080609@timgolden.me.uk> Roger Upole wrote: > class SIOI: [...] > _com_interfaces_=[shell.IID_IShellIconOverlayIdentifier, > pythoncom.IID_IDispatch] Was the IDispatch a hangover from a cut-and-paste? I can't see why it would be there otherwise. Or have I missed sthg? TJG From mail at timgolden.me.uk Tue Apr 15 11:03:54 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Apr 2008 10:03:54 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: Message-ID: <48046F7A.5030708@timgolden.me.uk> Andrea Gavana wrote: > Hi Roger, > > On Tue, Apr 15, 2008 at 12:21 AM, Roger Upole wrote: >> I've been meaning to look at how this works for some time, >> so I took a few minutes to cook up an example (attached). > > Thank you very much for the sample! It is really enlighting. I have > however some difficulty to understand it (sorry for the dumb > questions): (I think Roger's in a different timezone, so I'll answer what I can for the purposes of expediency. He can obviously speak for himself when he's online). You really want to look at: http://msdn2.microsoft.com/en-us/library/bb776858(VS.85).aspx?topic=306117 for the inside story. > 1) How do you actually use the SIOI class? As a class, you don't. It's simply the mechanism for serving the COM object which contains the methods the shell will be calling back. There's some magic which the UseCommandLine call does on your behalf to register the class as the COM server which the shell expects. > I tried to run the sample, > then creating various files here and there in my hard drive, but I > don't really know what IsMemberOf() is accepting as fname to make the > overlay. Is it the file name? The icon name? Something else? Find an icon file that exists, unless you happen to have something on your J: drive which exactly matches Roger's example. I used the TortoiseSVN icons on my machine under: c:\Program Files\TortoiseSVN\icons\Classic\TortoiseAdded.ico Replace the path in GetOverlayInfo with whatever you've chosen. This is the icon which will be overlaid (in miniature) over whatever existing icon a file has. Have the IsMemberOf method return S_OK for every file whose icon you want overlaid. The first param is the filename. Roger's example simply looks for the world "overlay" in the filename. > 2) Let's suppose that I want to assign an overlayed icon to a > particular file in a directory: let's say this file is called > "HELLO.DATA" and the directory contains also other files with the > .DATA extension. What should I do to assign the overlayed icon only to > this particular file? Change the .IsMemberOf function to say something like: if os.path.basename (fname) == "HELLO.DATA": return winerror.S_OK return winerror.E_FAIL Hope that helps TJG From rwupole at msn.com Tue Apr 15 12:47:53 2008 From: rwupole at msn.com (Roger Upole) Date: Tue, 15 Apr 2008 06:47:53 -0400 Subject: [python-win32] Overlay Icon Question... Message-ID: "Tim Golden" wrote in message news:48046F7A.5030708 at timgolden.me.uk... > Andrea Gavana wrote: >> Hi Roger, >> >> On Tue, Apr 15, 2008 at 12:21 AM, Roger Upole wrote: >>> I've been meaning to look at how this works for some time, >>> so I took a few minutes to cook up an example (attached). >> >> Thank you very much for the sample! It is really enlighting. I have >> however some difficulty to understand it (sorry for the dumb >> questions): > > (I think Roger's in a different timezone, so I'll answer what > I can for the purposes of expediency. He can obviously speak > for himself when he's online). Sometimes I think I'm in an entirely different universe ;). > You really want to look at: > > http://msdn2.microsoft.com/en-us/library/bb776858(VS.85).aspx?topic=306117 > > for the inside story. > >> 1) How do you actually use the SIOI class? > > As a class, you don't. It's simply the mechanism for serving the > COM object which contains the methods the shell will be calling > back. This is often a difficult concept for people new to shell extensions. > There's some magic which the UseCommandLine call does > on your behalf to register the class as the COM server which the > shell expects. > >> I tried to run the sample, >> then creating various files here and there in my hard drive, but I >> don't really know what IsMemberOf() is accepting as fname to make the >> overlay. Is it the file name? The icon name? Something else? > > Find an icon file that exists, unless you happen to have something > on your J: drive which exactly matches Roger's example. I used the > TortoiseSVN icons on my machine under: > > c:\Program Files\TortoiseSVN\icons\Classic\TortoiseAdded.ico > > Replace the path in GetOverlayInfo with whatever you've chosen. > This is the icon which will be overlaid (in miniature) over whatever > existing icon a file has. > > Have the IsMemberOf method return S_OK for every file whose icon > you want overlaid. The first param is the filename. Roger's example simply > looks for the world "overlay" in the filename. I was actually testing the overlay on the script that produces the overlay. (it seemed like a good idea at the time ...) >> 2) Let's suppose that I want to assign an overlayed icon to a >> particular file in a directory: let's say this file is called >> "HELLO.DATA" and the directory contains also other files with the >> .DATA extension. What should I do to assign the overlayed icon only to >> this particular file? > > Change the .IsMemberOf function to say something like: > > if os.path.basename (fname) == "HELLO.DATA": > return winerror.S_OK > return winerror.E_FAIL > > Hope that helps > > TJG Also, you'll probably need to log off and log back on for changes to the class to take effect. Roger From mail at timgolden.me.uk Tue Apr 15 13:00:45 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Apr 2008 12:00:45 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: Message-ID: <48048ADD.8020908@timgolden.me.uk> Roger Upole wrote: > Sometimes I think I'm in an entirely different universe ;). Hehe. If you don't mind my asking, where are you based? > Also, you'll probably need to log off and log back on for changes to > the class to take effect. This is probably the biggest pain when it comes to developing / testing shell extensions: you either have to employ various hacky things which I've now forgotten (forcing explorer to launch in a new process each time, or something). Or suffer the logoff-logon cycle, on a spare machine if that's feasible! Thanks v. much for the example, Roger. It's re-kickstarted my intention to write up a series of pages on writing these things with Python. (Altho' I still have to find the time to do that: at least the intention's there!) TJG From rwupole at msn.com Tue Apr 15 13:32:36 2008 From: rwupole at msn.com (Roger Upole) Date: Tue, 15 Apr 2008 07:32:36 -0400 Subject: [python-win32] Overlay Icon Question... Message-ID: Tim Golden wrote: > Roger Upole wrote: >> Sometimes I think I'm in an entirely different universe ;). > > Hehe. If you don't mind my asking, where are you based? > I'm on the east coast of the US, not far from Ocean City, MD. Regarding the redundant IID_IDispatch you asked about, I'm not even sure how that snuck in. Copy-n-paste seems a likely enough scapegoat. Roger From andrea.gavana at gmail.com Tue Apr 15 15:44:36 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Tue, 15 Apr 2008 14:44:36 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: <48046F7A.5030708@timgolden.me.uk> References: <48046F7A.5030708@timgolden.me.uk> Message-ID: Hi Tim, Roger & All, On Tue, Apr 15, 2008 at 10:03 AM, Tim Golden wrote: > Andrea Gavana wrote: > > Hi Roger, > > > > On Tue, Apr 15, 2008 at 12:21 AM, Roger Upole wrote: > >> I've been meaning to look at how this works for some time, > >> so I took a few minutes to cook up an example (attached). > > > > Thank you very much for the sample! It is really enlighting. I have > > however some difficulty to understand it (sorry for the dumb > > questions): > > (I think Roger's in a different timezone, so I'll answer what > I can for the purposes of expediency. He can obviously speak > for himself when he's online). > > You really want to look at: > > http://msdn2.microsoft.com/en-us/library/bb776858(VS.85).aspx?topic=306117 > > for the inside story. > > > 1) How do you actually use the SIOI class? > > As a class, you don't. It's simply the mechanism for serving the > COM object which contains the methods the shell will be calling > back. There's some magic which the UseCommandLine call does > on your behalf to register the class as the COM server which the > shell expects. > > > I tried to run the sample, > > then creating various files here and there in my hard drive, but I > > don't really know what IsMemberOf() is accepting as fname to make the > > overlay. Is it the file name? The icon name? Something else? > > Find an icon file that exists, unless you happen to have something > on your J: drive which exactly matches Roger's example. I used the > TortoiseSVN icons on my machine under: > > c:\Program Files\TortoiseSVN\icons\Classic\TortoiseAdded.ico > > Replace the path in GetOverlayInfo with whatever you've chosen. > This is the icon which will be overlaid (in miniature) over whatever > existing icon a file has. > > Have the IsMemberOf method return S_OK for every file whose icon > you want overlaid. The first param is the filename. Roger's example simply > looks for the world "overlay" in the filename. > > > 2) Let's suppose that I want to assign an overlayed icon to a > > particular file in a directory: let's say this file is called > > "HELLO.DATA" and the directory contains also other files with the > > .DATA extension. What should I do to assign the overlayed icon only to > > this particular file? > > Change the .IsMemberOf function to say something like: > > if os.path.basename (fname) == "HELLO.DATA": > return winerror.S_OK > return winerror.E_FAIL > > Hope that helps Yes, thank you, it helps a lot... although I still have some doubts. These are my modifications of the class Roger posted: class SIOI(object): _reg_clsid_='{02844251-42C2-44CA-B43D-424FCE4F4660}' _reg_progid_='K-SVR.IShellIconOverlayIdentifier' _reg_desc_='Python implementation of IShellIconOverlayIdentifier' _public_methods_ = ['GetOverlayInfo','GetPriority','IsMemberOf'] _com_interfaces_=[shell.IID_IShellIconOverlayIdentifier, pythoncom.IID_IDispatch] __name__ = "SIOI" def __init__(self, fileNames): self.fileNames = fileNames def AddFile(self, fileName): if fileName not in self.fileNames: self.fileNames.append(fileName) def RemoveFile(self, fileName): if fileName in self.fileNames: self.fileNames.remove(fileName) def GetOverlayInfo(self): return (r'icons/KSVROverlay.ico', 0, shellcon.ISIOI_ICONFILE) def GetPriority(self): return 50 def IsMemberOf(self, fname, attributes): if fname in self.fileNames: return winerror.S_OK return winerror.E_FAIL def IconOverlay(fileNames): import win32com.server.register overlayClass = SIOI(fileNames) win32com.server.register.UseCommandLine(overlayClass) keyname=r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\KSVROverlayHandler' key=win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, keyname) win32api.RegSetValue(key, None, win32con.REG_SZ, SIOI._reg_clsid_) return overlayClass And this is what I do: 1) When my app is launched, the database returns a list of file names (with the full path) stored inside the variable fileNames; 2) I then call the method IconOverlay, which initializes the class SIOI with these fileNames; 3) in the IsMemberOf method, if a file name is in the fileNames list, the icon should be overlayed. I can't see any icon overlayed on my PC, even after logging off and on (or restarting). I am doing something stupid for sure, althought I am too newbie to find out what I am doing wrong :-( I suppose I can't initialize the SIOI class as I am doing, or I can't test IsMemberOf using the fileNames list as I am doing... Am I missing something? Is there another way to accomplish what I am looking for? Thank you for your suggestions. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From andrea.gavana at gmail.com Tue Apr 15 15:51:45 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Tue, 15 Apr 2008 14:51:45 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: <48046F7A.5030708@timgolden.me.uk> Message-ID: Hi All, On Tue, Apr 15, 2008 at 2:44 PM, Andrea Gavana wrote: > Hi Tim, Roger & All, > > > On Tue, Apr 15, 2008 at 10:03 AM, Tim Golden wrote: > > Andrea Gavana wrote: > > > Hi Roger, > > > > > > On Tue, Apr 15, 2008 at 12:21 AM, Roger Upole wrote: > > >> I've been meaning to look at how this works for some time, > > >> so I took a few minutes to cook up an example (attached). > > > > > > Thank you very much for the sample! It is really enlighting. I have > > > however some difficulty to understand it (sorry for the dumb > > > questions): > > > > (I think Roger's in a different timezone, so I'll answer what > > I can for the purposes of expediency. He can obviously speak > > for himself when he's online). > > > > You really want to look at: > > > > http://msdn2.microsoft.com/en-us/library/bb776858(VS.85).aspx?topic=306117 > > > > for the inside story. > > > > > 1) How do you actually use the SIOI class? > > > > As a class, you don't. It's simply the mechanism for serving the > > COM object which contains the methods the shell will be calling > > back. There's some magic which the UseCommandLine call does > > on your behalf to register the class as the COM server which the > > shell expects. > > > > > I tried to run the sample, > > > then creating various files here and there in my hard drive, but I > > > don't really know what IsMemberOf() is accepting as fname to make the > > > overlay. Is it the file name? The icon name? Something else? > > > > Find an icon file that exists, unless you happen to have something > > on your J: drive which exactly matches Roger's example. I used the > > TortoiseSVN icons on my machine under: > > > > c:\Program Files\TortoiseSVN\icons\Classic\TortoiseAdded.ico > > > > Replace the path in GetOverlayInfo with whatever you've chosen. > > This is the icon which will be overlaid (in miniature) over whatever > > existing icon a file has. > > > > Have the IsMemberOf method return S_OK for every file whose icon > > you want overlaid. The first param is the filename. Roger's example simply > > looks for the world "overlay" in the filename. > > > > > 2) Let's suppose that I want to assign an overlayed icon to a > > > particular file in a directory: let's say this file is called > > > "HELLO.DATA" and the directory contains also other files with the > > > .DATA extension. What should I do to assign the overlayed icon only to > > > this particular file? > > > > Change the .IsMemberOf function to say something like: > > > > if os.path.basename (fname) == "HELLO.DATA": > > return winerror.S_OK > > return winerror.E_FAIL > > > > Hope that helps > > Yes, thank you, it helps a lot... although I still have some doubts. > These are my modifications of the class Roger posted: > > class SIOI(object): > _reg_clsid_='{02844251-42C2-44CA-B43D-424FCE4F4660}' > _reg_progid_='K-SVR.IShellIconOverlayIdentifier' > _reg_desc_='Python implementation of IShellIconOverlayIdentifier' > _public_methods_ = ['GetOverlayInfo','GetPriority','IsMemberOf'] > _com_interfaces_=[shell.IID_IShellIconOverlayIdentifier, > pythoncom.IID_IDispatch] > __name__ = "SIOI" > > def __init__(self, fileNames): > self.fileNames = fileNames > > def AddFile(self, fileName): > if fileName not in self.fileNames: > self.fileNames.append(fileName) > > def RemoveFile(self, fileName): > if fileName in self.fileNames: > self.fileNames.remove(fileName) > > def GetOverlayInfo(self): > return (r'icons/KSVROverlay.ico', 0, shellcon.ISIOI_ICONFILE) > > def GetPriority(self): > return 50 > > def IsMemberOf(self, fname, attributes): > if fname in self.fileNames: > return winerror.S_OK > return winerror.E_FAIL > > > def IconOverlay(fileNames): > > import win32com.server.register > overlayClass = SIOI(fileNames) > win32com.server.register.UseCommandLine(overlayClass) > keyname=r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\KSVROverlayHandler' > key=win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, keyname) > win32api.RegSetValue(key, None, win32con.REG_SZ, SIOI._reg_clsid_) > > return overlayClass > > > And this is what I do: > > 1) When my app is launched, the database returns a list of file names > (with the full path) stored inside the variable fileNames; > 2) I then call the method IconOverlay, which initializes the class > SIOI with these fileNames; > 3) in the IsMemberOf method, if a file name is in the fileNames list, > the icon should be overlayed. > > I can't see any icon overlayed on my PC, even after logging off and on > (or restarting). I am doing something stupid for sure, althought I am > too newbie to find out what I am doing wrong :-( > I suppose I can't initialize the SIOI class as I am doing, or I can't > test IsMemberOf using the fileNames list as I am doing... Am I missing > something? Is there another way to accomplish what I am looking for? > > Thank you for your suggestions. Sorry to break in again... something unusual happened: when I start my app, as soon as I open a file dialog from my app, I get this nice error from PythonCom: D:\MyProjects\K-SVR>K-SVR.py Registered: K-SVR.IShellIconOverlayIdentifier Registered: K-SVR.IShellIconOverlayIdentifier ==> Here I open the file dialog <== pythoncom error: ERROR: server.policy could not create an instance. Traceback (most recent call last): File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 144, in CreateInstance return retObj._CreateInstance_(clsid, reqIID) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 202, in _CreateInstance_ myob = call_func(classSpec) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 739, in call_func return resolve_func(spec)(*args) : __init__() takes exactly 2 arguments (1 given) pythoncom error: Unexpected gateway error Traceback (most recent call last): File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 144, in CreateInstance return retObj._CreateInstance_(clsid, reqIID) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 202, in _CreateInstance_ myob = call_func(classSpec) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 739, in call_func return resolve_func(spec)(*args) : __init__() takes exactly 2 arguments (1 given) pythoncom error: CPyFactory::CreateInstance failed to create instance. (80004005) I have no idea of what this means, but for sure I have messed up with something :-( :-( Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From mail at timgolden.me.uk Tue Apr 15 16:20:45 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Apr 2008 15:20:45 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: <48046F7A.5030708@timgolden.me.uk> Message-ID: <4804B9BD.1090401@timgolden.me.uk> Andrea Gavana wrote: > Yes, thank you, it helps a lot... although I still have some doubts. > These are my modifications of the class Roger posted: > > class SIOI(object): > _reg_clsid_='{02844251-42C2-44CA-B43D-424FCE4F4660}' > _reg_progid_='K-SVR.IShellIconOverlayIdentifier' > _reg_desc_='Python implementation of IShellIconOverlayIdentifier' > _public_methods_ = ['GetOverlayInfo','GetPriority','IsMemberOf'] > _com_interfaces_=[shell.IID_IShellIconOverlayIdentifier, > pythoncom.IID_IDispatch] > __name__ = "SIOI" > > def __init__(self, fileNames): > self.fileNames = fileNames > > def AddFile(self, fileName): > if fileName not in self.fileNames: > self.fileNames.append(fileName) > > def RemoveFile(self, fileName): > if fileName in self.fileNames: > self.fileNames.remove(fileName) > > def GetOverlayInfo(self): > return (r'icons/KSVROverlay.ico', 0, shellcon.ISIOI_ICONFILE) > > def GetPriority(self): > return 50 > > def IsMemberOf(self, fname, attributes): > if fname in self.fileNames: > return winerror.S_OK > return winerror.E_FAIL Hmmm... Let's see how to explain this. Basically, this class isn't one you instantiate within your own program as you've done here. The instantiation is done by the underlying shell integration mechanism. Think of it as a Windows Service, running permanently. You don't start it with your app; it's either running or it's not, regardless of what apps are running. If you want it to adjust its overlays according to some changing data characteristics, you're going to have to establish some kind of mechanism by which the COM server which the class represents can request the latest list of filenames from some other piece of running code (or from a file or whatever). That more-or-less also explains the error you reported in your later email: the underlying mechanism expects an unadulterated __init__, not one which you've altered to pass in your filenames. Sorry if this isn't very clear; I did warn that this was not the easiest part of Windows programming to get into. What it means is that your app comes in two pieces: 1) This Namespace Extension which determines -- somehow -- when an icon requires an overlay and responds appropriately to requests from the shell. You register it on its own and leave it alone. 2) The main app, doing whatever it's doing, possibly cooperating with the Icon Overlay extension, for example by writing a list of filenames to a file from time to time. TJG From mail at timgolden.me.uk Tue Apr 15 16:31:51 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Apr 2008 15:31:51 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: <4804B9BD.1090401@timgolden.me.uk> References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> Message-ID: <4804BC57.20701@timgolden.me.uk> Tim Golden wrote: > Andrea Gavana wrote: >> def GetOverlayInfo(self): >> return (r'icons/KSVROverlay.ico', 0, shellcon.ISIOI_ICONFILE) By the way, I'm not how the callback mechanism will cope with relative paths like this. Not very well, I guess. Bear in mind also that the shell functions are usually unfriendly towards the otherwise acceptable forward-slash path separators. In other words, you might be better off by wrapping the path above in os.path.abspath (which will also normalise the slashes for you). TJG From andrea.gavana at gmail.com Tue Apr 15 18:25:16 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Tue, 15 Apr 2008 17:25:16 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: <4804B9BD.1090401@timgolden.me.uk> References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> Message-ID: Hi Tim & All, On Tue, Apr 15, 2008 at 3:20 PM, Tim Golden wrote: > > Andrea Gavana wrote: > > Yes, thank you, it helps a lot... although I still have some doubts. > > These are my modifications of the class Roger posted: > > > > class SIOI(object): > > _reg_clsid_='{02844251-42C2-44CA-B43D-424FCE4F4660}' > > _reg_progid_='K-SVR.IShellIconOverlayIdentifier' > > _reg_desc_='Python implementation of IShellIconOverlayIdentifier' > > _public_methods_ = ['GetOverlayInfo','GetPriority','IsMemberOf'] > > _com_interfaces_=[shell.IID_IShellIconOverlayIdentifier, > > pythoncom.IID_IDispatch] > > __name__ = "SIOI" > > > > def __init__(self, fileNames): > > self.fileNames = fileNames > > > > def AddFile(self, fileName): > > if fileName not in self.fileNames: > > self.fileNames.append(fileName) > > > > def RemoveFile(self, fileName): > > if fileName in self.fileNames: > > self.fileNames.remove(fileName) > > > > def GetOverlayInfo(self): > > return (r'icons/KSVROverlay.ico', 0, shellcon.ISIOI_ICONFILE) > > > > def GetPriority(self): > > return 50 > > > > def IsMemberOf(self, fname, attributes): > > if fname in self.fileNames: > > return winerror.S_OK > > return winerror.E_FAIL > > Hmmm... Let's see how to explain this. Basically, this class > isn't one you instantiate within your own program as you've > done here. The instantiation is done by the underlying shell > integration mechanism. Think of it as a Windows Service, > running permanently. You don't start it with your app; it's > either running or it's not, regardless of what apps are running. > > If you want it to adjust its overlays according to some changing > data characteristics, you're going to have to establish some kind > of mechanism by which the COM server which the class represents > can request the latest list of filenames from some other piece of > running code (or from a file or whatever). > > That more-or-less also explains the error you reported in your > later email: the underlying mechanism expects an unadulterated > __init__, not one which you've altered to pass in your filenames. > > Sorry if this isn't very clear; I did warn that this was not the easiest > part of Windows programming to get into. What it means is that > your app comes in two pieces: > > 1) This Namespace Extension which determines -- somehow -- when > an icon requires an overlay and responds appropriately to requests > from the shell. You register it on its own and leave it alone. > > 2) The main app, doing whatever it's doing, possibly cooperating with > the Icon Overlay extension, for example by writing a list of filenames to > a file from time to time. Thank you a lot, now everything is perfectly clear. I made this class communicate with the registry where I store a file name (in which I have all my files for which I want the overlay icon), and it works like a charm, with IsMemberOf checking this particular registry key and returning the appropriate value if the file name is in my list of files. It works very well from the command line, but not at all once I compile it py2exe... there is no traceback, no error in the setup.py, no exception in the exe file, but the COM server is never started (i.e., the IsMemberOf method of the SIOI class is never invoked or called). Is there anything special I should do in order to make this thing work in an executable created by py2exe? Thank you so much for your help, it's invaluable! Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From tom.moulton at cox.net Tue Apr 15 19:07:46 2008 From: tom.moulton at cox.net (tom.moulton at cox.net) Date: Tue, 15 Apr 2008 13:07:46 -0400 Subject: [python-win32] Accessing a Remote Registry.... Message-ID: <20080415130746.WBHUA.115687.imail@eastrmwml14.mgt.cox.net> I have found many references to accessing a registry remotely; however, none that work for me. Admittedly, I am a bit green on understanding Windows security permissions and the like. I have tried a number of solutions (i.e., wmi, win32api, _winreg), but to no avail. I am trying to update registry settings between Windows XP systems using user a local administrator account for authentication. I've tried the following... BEGIN SNIPPET 1: c = wmi.WMI(computer='', user='', password='') reg = c.Registry()[0] reg.EnumKey (hDefKey=_winreg.HKEY_LOCAL_MACHINE, sSubKeyName="Software") Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\site-packages\wmi.py", line 491, in __getattr__ return getattr (self.ole_object, attribute) File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 496, in __getattr__ raise AttributeError, "%s.%s" % (self._username_, attr) AttributeError: .EnumKey END SNIPPET 1 BEGIN SNIPPET 2: objSWbemLocator = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemServices = objSWbemLocator.ConnectServer('','root\default:Cimv2', '', '') objReg = objSWbemServices.Get('StdRegProv') objReg.EnumKey(hDefKey=_winreg.HKEY_LOCAL_MACHINE, sSubKeyName='Software') Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 491, in __getattr__ raise pythoncom.com_error, details com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemObjectEx', 'Invalid parameter ', None, 0, -2147217400), None) END SNIPPET 2 I've looked at using the wmi.Registry function; however, it only allows you to specify the computer name and not any credentials (i.e., username and password). I've also tried a various forms of monikers (e.g., ///root/default); however, anytime I specify the IP address within the moniker I get an Access Denied error (see below). Also, passing in the moniker seems to override use of the user, password and computer arguments. BEGIN SNIPPET 3: reg = wmi.WMI(computer=', moniker='winmgmts:///root/default:StdRegProv', user='', password='') Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\site-packages\wmi.py", line 1190, in connect handle_com_error (error_info) File "C:\Python25\lib\site-packages\wmi.py", line 189, in handle_com_error raise x_wmi, "\n".join (exception_string) x_wmi: -0x7ff8fffb - Access is denied. END SNIPPET 3 Thanks, Tom From mail at timgolden.me.uk Tue Apr 15 19:34:54 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Apr 2008 18:34:54 +0100 Subject: [python-win32] Accessing a Remote Registry.... In-Reply-To: <20080415130746.WBHUA.115687.imail@eastrmwml14.mgt.cox.net> References: <20080415130746.WBHUA.115687.imail@eastrmwml14.mgt.cox.net> Message-ID: <4804E73E.2090002@timgolden.me.uk> Quick answer because I don't have time for a slow one right now :). Do something like this: import wmi reg = wmi.WMI ( "other-box", user="tim", password="secret", namespace="root/default" ).StdRegProv TJG From mail at timgolden.me.uk Tue Apr 15 19:44:41 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 15 Apr 2008 18:44:41 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> Message-ID: <4804E989.9000107@timgolden.me.uk> Andrea Gavana wrote: > Thank you a lot, now everything is perfectly clear. I made this class > communicate with the registry where I store a file name (in which I > have all my files for which I want the overlay icon), and it works > like a charm, with IsMemberOf checking this particular registry key > and returning the appropriate value if the file name is in my list of > files. Not that it matters too much, but if you're using a registry entry anyway, why not simply list the files in the registry instead of the double-indirection of having the registry reference a file which holds the other files !? > Is there anything special I should do in order to make this thing work > in an executable created by py2exe? You probably need to post your setup.py (or however you're doing things with py2exe). I seem to recall that py2exe has some specifics to support COM servers, but I'm no expert. TJG From iceblink at chello.nl Wed Apr 16 09:37:19 2008 From: iceblink at chello.nl (iceblink at chello.nl) Date: Wed, 16 Apr 2008 9:37:19 +0200 Subject: [python-win32] exception while opening excel file Message-ID: <26545011.1208331441844.JavaMail.root@viefep27> ---- Mark Hammond schreef: > > > Normally I can just press "close" in the excel error box, and > > continue > > > to work on the file. But how do I handle this in py-win32? > > > > So what happens when you try to open it normally? > > Oops - sorry - I see you already gave the exception you get trying to open > the file. I'm afraid I don't know the answer though. > In answer to my own question, the following code seems to work: xlApp = Dispatch("Excel.Application") wb1=xlApp.Workbooks.Open(inputfile,ReadOnly=1,CorruptLoad=1) xlApp.SendKeys("{Enter}",Wait=1) xlApp.DisplayAlerts = 0 xlApp.Quit() del xlApp The trick was to find the right CorruptLoad statement and corresponding number for "xlRepairFile". The DisplayAlerts is needed to prevent Excel from asking if it should save a file that was opened as ReadOnly in the first place... hmmmm. Best regards, Patrick Asselman From andrea.gavana at gmail.com Wed Apr 16 12:13:52 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Wed, 16 Apr 2008 11:13:52 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: <4804E989.9000107@timgolden.me.uk> References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> Message-ID: Hi Tim & All, On Tue, Apr 15, 2008 at 6:44 PM, Tim Golden wrote: > Andrea Gavana wrote: > > Thank you a lot, now everything is perfectly clear. I made this class > > communicate with the registry where I store a file name (in which I > > have all my files for which I want the overlay icon), and it works > > like a charm, with IsMemberOf checking this particular registry key > > and returning the appropriate value if the file name is in my list of > > files. > > Not that it matters too much, but if you're using a registry entry > anyway, why not simply list the files in the registry instead > of the double-indirection of having the registry reference a > file which holds the other files !? I initially thought to do that, but then by reading this: http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/pywin32/win32api__RegSetValue_meth.html And specifically this comment: "Value lengths are limited by available memory. Long values (more than 2048 bytes) should be stored as files with the filenames stored in the configuration registry. This helps the registry perform efficiently." I decided to do the double-indirection. It's not that complicated in the end :-D > > Is there anything special I should do in order to make this thing work > > in an executable created by py2exe? > > You probably need to post your setup.py (or however you're > doing things with py2exe). I seem to recall that py2exe has > some specifics to support COM servers, but I'm no expert. I was compiling my com server with the wrong py2exe parameters... now it works. I have a question anyway: since I don't know anything about COM servers and friends, will my COM server be restarted by Windows when the computer restart or a user logoff and logon again? Or should I find a way to register and restart it every time a user switch off and on his/her computer? Thank you for your suggestions, this list has been very helpful and kind towards a completely pywin32-ignorant like me :-D Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From python at kareta.de Wed Apr 16 13:07:10 2008 From: python at kareta.de (python at kareta.de) Date: Wed, 16 Apr 2008 13:07:10 +0200 Subject: [python-win32] Overlay Icon Question and network drives In-Reply-To: References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> Message-ID: <1208344030.4805dddea6f0e@webmail.ldc.de> Hi Andrea, the code in my first link was from the mercurial extension TortoiseHG. They found some issues that the icon overlay slows down network devices. See here: https://sourceforge.net/tracker/index.php?func=detail&aid=1892791&group_id=199155&atid=968354 Could you please tell if you have the same issues with the code Roger posted ? Thanks, J?rgen ------------------------------------------------- Versandt durch den Webmaildienst der LDC GmbH Bonn From mail at timgolden.me.uk Wed Apr 16 13:13:05 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 16 Apr 2008 12:13:05 +0100 Subject: [python-win32] Overlay Icon Question... In-Reply-To: References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> Message-ID: <4805DF41.7030200@timgolden.me.uk> [Tim Golden] >> Not that it matters too much, but if you're using a registry entry >> anyway, why not simply list the files in the registry instead >> of the double-indirection of having the registry reference a >> file which holds the other files !? [Andrea Gavana] > I initially thought to do that, but then by reading this: > > http://aspn.activestate.com/ASPN/docs/ActivePython/2.5/pywin32/win32api__RegSetValue_meth.html > > And specifically this comment: > > "Value lengths are limited by available memory. Long values (more than > 2048 bytes) should be stored as files with the filenames stored in the > configuration registry. This helps the registry perform efficiently." > > I decided to do the double-indirection. It's not that complicated in the end :-D Fair enough. [Andrea Gavana] > I was compiling my com server with the wrong py2exe parameters... now > it works. I have a question anyway: since I don't know anything about > COM servers and friends, will my COM server be restarted by Windows > when the computer restart or a user logoff and logon again? Or should > I find a way to register and restart it every time a user switch off > and on his/her computer? It's not quite a "server" in that sense. I don't know about the exact mechanics, but in essence the shell will start it up on demand. (Probably when the session starts, but I wouldn't be certain). The code you copied from beneath the class definition achieves two things: 1) It says: "Whenever someone asks for server {01-23-45} go to *this* DLL and pass it *that* id". 2) And it says: "Whenever the shell displays an icon, pass it along to server {01-23-45} to let it overlay if it wants" The effect is that the first time explorer wants to display an icon, it runs through the list of icon-overlay-handlers, which includes yours, finds your server's id (that {xx-yy} thing), finds that server's entry in the registry, fires up the relevant code and passes along whatever it does, causing your code to return an overlay or not. Or near enough. > Thank you for your suggestions, this list has been very helpful and > kind towards a completely pywin32-ignorant like me :-D Glad we could help: that's what we're here for! TJG From andrea.gavana at gmail.com Wed Apr 16 14:29:09 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Wed, 16 Apr 2008 13:29:09 +0100 Subject: [python-win32] Overlay Icon Question and network drives In-Reply-To: <1208344030.4805dddea6f0e@webmail.ldc.de> References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> <1208344030.4805dddea6f0e@webmail.ldc.de> Message-ID: Hi Jurgen & All, On Wed, Apr 16, 2008 at 12:07 PM, wrote: > the code in my first link was from the mercurial extension TortoiseHG. They > found some issues that the icon overlay slows down network devices. See here: > > https://sourceforge.net/tracker/index.php?func=detail&aid=1892791&group_id=199155&atid=968354 > > Could you please tell if you have the same issues with the code Roger posted ? I am still having some problem with this class... it's an incredible amount of time/work spent on a very small issue, but that is what the users want :-). Anyway, on my computer, Roger's version doesn't slow down anything. Our 4 network drives are as fast as usual. However, I am not able to make it work from a compiled py2exe COM server. It works only from a python script. For the compiled py2exe COM server, I have looked into the file c:/comerror.txt, which says: PATH is ['D:\\ResWizard\\KSVR_COMServer.exe'] Registered: K-SVR.IShellIconOverlayIdentifier The registry keys are correctly written but there is no icon overlay, nothing has changed visually :-( :-( . If I run it from a Python script, the icon overlay works fine but every time I open a file dialog from one of my applications I get this nice error in the app.exe.log file created by py2exe: pythoncom error: PythonCOM Server - The 'win32com.server.policy' module could not be loaded. : No module named server.policy pythoncom error: CPyFactory::CreateInstance failed to create instance. (80004005) Which, as usual, doesn't mean anything to me... So, I don't see any slowdown but I can't make this little sweet thing play nice :-( :-( Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From mbelzile at softimage.com Wed Apr 16 14:49:22 2008 From: mbelzile at softimage.com (=?iso-8859-1?Q?Marc-Andr=E9_Belzile?=) Date: Wed, 16 Apr 2008 08:49:22 -0400 Subject: [python-win32] Building Pywin32 on vista x64 question Message-ID: <0BCB4AE868D8934A8B3DCE3A58126A8901ED9C05@tewk-mbpf3> Hello, I'm trying to build pywin32 on vista 64 based on the latest setup.py (10/04/2008). I've installed python 2.6, windows sdk and directx sdk (as advertised) and got this link error: LINK : warning LNK4012: invalid value 'x86_64', must be 'ARM, EBC, IA64, MIPS, MIPS16, MIPSFPU, MIPSFPU16, SH4, THUMB, X64, or X86'; option ignored Also c:\Python26\PCbuild doesn't exist in the python26 installation. Do I need to rebuild it first prior to build pywin32 ? thanks for the help -mab C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:c:\Python26\libs /LIBPATH:c:\Python26\PCbuild /LIBPATH:build\temp.win-x86_64-2.6\Release "/LIBPATH:C:\Program Files\Microsoft Platform SDK\lib" advapi32.lib user32.lib ole32.lib oleaut32.lib /EXPORT:initpywintypes build\temp.win-x86_64-2.6\Release\win32\src\PyACL.obj build\temp.win-x86_64-2.6\Release\win32\src\PyDEVMODE.obj build\temp.win-x86_64-2.6\Release\win32\src\PyHANDLE.obj build\temp.win-x86_64-2.6\Release\win32\src\PyIID.obj build\temp.win-x86_64-2.6\Release\win32\src\PyLARGE_INTEGER.obj build\temp.win-x86_64-2.6\Release\win32\src\PyOVERLAPPED.obj build\temp.win-x86_64-2.6\Release\win32\src\PySECURITY_ATTRIBUTES.obj build\temp.win-x86_64-2.6\Release\win32\src\PySECURITY_DESCRIPTOR.obj build\temp.win-x86_64-2.6\Release\win32\src\PySID.obj build\temp.win-x86_64-2.6\Release\win32\src\PyTime.obj build\temp.win-x86_64-2.6\Release\win32\src\PyUnicode.obj build\temp.win-x86_64-2.6\Release\win32\src\PyWAVEFORMATEX.obj build\temp.win-x86_64-2.6\Release\win32\src\PyWinTypesmodule.obj /OUT:build\lib.win-x86_64-2.6\pywin32_system32\pywintypes26.dll /IMPLIB:build\temp.win-x86_64-2.6\Release\win32\src\pywintypes26.lib /MACHINE:x86_64 /BASE:0x1e7d0000 /DEBUG /PDB:build\temp.win-x86_64-2.6\Release\pywintypes.pdb LINK : warning LNK4012: invalid value 'x86_64', must be 'ARM, EBC, IA64, MIPS, MIPS16, MIPSFPU, MIPSFPU16, SH4, THUMB, X64, or X86'; option ignored PyWinTypesmodule.obj : warning LNK4197: export 'initpywintypes' specified multiple times; using first specification Creating library build\temp.win-x86_64-2.6\Release\win32\src\pywintypes26.lib and object build\temp.win-x86_64-2.6\Release\win32\src\pywintypes26.exp PyTime.obj : error LNK2001: unresolved external symbol GUID_NULL PyUnicode.obj : error LNK2001: unresolved external symbol GUID_NULL PyWAVEFORMATEX.obj : error LNK2001: unresolved external symbol GUID_NULL PyWinTypesmodule.obj : error LNK2001: unresolved external symbol GUID_NULL PyOVERLAPPED.obj : error LNK2001: unresolved external symbol GUID_NULL PySECURITY_ATTRIBUTES.obj : error LNK2001: unresolved external symbol GUID_NULL PySECURITY_DESCRIPTOR.obj : error LNK2001: unresolved external symbol GUID_NULL PySID.obj : error LNK2001: unresolved external symbol GUID_NULL PyACL.obj : error LNK2001: unresolved external symbol GUID_NULL PyDEVMODE.obj : error LNK2001: unresolved external symbol GUID_NULL PyHANDLE.obj : error LNK2001: unresolved external symbol GUID_NULL PyIID.obj : error LNK2001: unresolved external symbol GUID_NULL PyACL.obj : error LNK2019: unresolved external symbol __imp_InitializeAcl referenced in function "public: static struct _object * __cdecl PyACL::Initialize(struct _object *,struct _object *)" (?Initialize at PyACL@@SAPEAU_object@@PEAU2 at 0@Z ) PyACL.obj : error LNK2019: unresolved external symbol __imp_IsValidAcl referenced in function "public: static struct _object * __cdecl PyACL::IsValid(struct _object *,struct _object *)" (?IsValid at PyAC L@@SAPEAU_object@@PEAU2 at 0@Z) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080416/7e62a3d1/attachment.htm From mail at timgolden.me.uk Wed Apr 16 15:39:04 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 16 Apr 2008 14:39:04 +0100 Subject: [python-win32] Overlay Icon Question and network drives In-Reply-To: <1208344030.4805dddea6f0e@webmail.ldc.de> References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> <1208344030.4805dddea6f0e@webmail.ldc.de> Message-ID: <48060178.40605@timgolden.me.uk> python at kareta.de wrote: > Hi Andrea, > > the code in my first link was from the mercurial extension TortoiseHG. They > found some issues that the icon overlay slows down network devices. See here: > > https://sourceforge.net/tracker/index.php?func=detail&aid=1892791&group_id=199155&atid=968354 > > Could you please tell if you have the same issues with the code Roger posted ? Worth noting that *any* code which is messing with icon overlays should be just about as tight as it can possibly be. TortoiseSVN, which is written in C++ has been doing this for years, tweaks its overlay & cache code on pretty much every minor release to squeeze some more performance. I had a quick glance at the TortoiseHg code and was a bit surprised that the key _get_state function isn't as tight as it might be. I say that, however, with a huge amount of diffidence as I've had nothing whatsoever to do with it and I imagine the developer's tried all sorts of tricks to speed things up. If the problem only seriously affects network drives, it's likely that the code's doing too many calls to query file existence and attributes, all of which will suffer on a (slower) network connection. Be interesting knowing whether other overlay handlers such as TortoiseSVN/CVS cause the same problem, whether a simple no-op or one-op implementation of _get_state ameliorates things, or whether the added layer of the Python interpreter is causing the problems. As a side note, might be worth tying in to the TortoiseOverlays projects which provides for a shared set of overlays for all Tortoise.. projects, preventing problems with the rather low system limit. (Don't imagine it would help speed things up, tho', since it introduces *another* layer into the stack). Perusing the code at: http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/src/TortoiseShell/IconOverlay.cpp was very instructive! Worth checking the repos out to look at the log, too. TJG From kxroberto at googlemail.com Wed Apr 16 15:57:28 2008 From: kxroberto at googlemail.com (Robert) Date: Wed, 16 Apr 2008 15:57:28 +0200 Subject: [python-win32] SetSystemTime: A required privilege is not held by the client Message-ID: SetSystemTime on Vista admin account throws: (1314, 'SetSystemTime', 'A required privilege is not held by the client.') Not known from previous Windows versions. With what switch or whatever can this be enabled? Robert From mail at timgolden.me.uk Wed Apr 16 16:53:17 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 16 Apr 2008 15:53:17 +0100 Subject: [python-win32] SetSystemTime: A required privilege is not held by the client In-Reply-To: References: Message-ID: <480612DD.3010501@timgolden.me.uk> Robert wrote: > SetSystemTime on Vista admin account throws: > > (1314, 'SetSystemTime', 'A required privilege is not held by > the client.') > > > Not known from previous Windows versions. > With what switch or whatever can this be enabled? According to the docs: (warning: URL will self-destruct in two months) http://msdn2.microsoft.com/en-us/library/ms724942(VS.85).aspx this operation automatically enables the SE_SYSTEMTIME_NAME priv which is disabled by default. But if your user doesn't *have* the priv to start with, it won't be enabled and you'll get the error message above. I don't run Vista, but I assume it has some kind of user-management user interface? Find whatever bit of that deals with privileges (*not* groups) and add this priv to the user in question. TJG From mail at timgolden.me.uk Wed Apr 16 17:56:38 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 16 Apr 2008 16:56:38 +0100 Subject: [python-win32] Overlay Icon Question and network drives In-Reply-To: References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> <1208344030.4805dddea6f0e@webmail.ldc.de> Message-ID: <480621B6.8050103@timgolden.me.uk> Andrea Gavana wrote: > ...If I run it from a Python > script, the icon overlay works fine but every time I open a file > dialog from one of my applications I get this nice error in the > app.exe.log file created by py2exe: > > pythoncom error: PythonCOM Server - The 'win32com.server.policy' > module could not be loaded. > > : No module named server.policy > pythoncom error: CPyFactory::CreateInstance failed to create instance. > (80004005) My guess is that you've fallen foul of the magic which win32com does with the path. Probably a case of specifying that module as a specific inclusion in the py2exe dict in setup.py. But I'm not really up on py2exe. Worth trying their own mailing list? TJG From bsneddon at yahoo.com Wed Apr 16 18:02:21 2008 From: bsneddon at yahoo.com (Bill Sneddon) Date: Wed, 16 Apr 2008 09:02:21 -0700 (PDT) Subject: [python-win32] Windows programing cookbook? Message-ID: <45944.91104.qm@web62412.mail.re1.yahoo.com> Does anyone know of a website with windows code examples? I have googled this have not found much. I know about Activestate's site but does not seemed to be organized in a way to get these easily. Is there a FAQ for this mail list? Right know I am interested in finding out how to access a windows server share in Python 2.4. Seems to work fine in Python 2.5 with win32 installed, but the MoinMoin server at work has not been upgraded. The problem is this open can not use this kind of path. I don't have access to the network now but the problem is like this example: txtFile = open(r'\\aServer\share$\myfile.txt','r') This command is unable to find the file on Python 2.4. I apologies if this is a FAQ but I have looked some. Is there a work around to this problem, can I map a network drive on the at runtime? Bill Sneddon ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ From mail at timgolden.me.uk Wed Apr 16 18:23:33 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 16 Apr 2008 17:23:33 +0100 Subject: [python-win32] Windows programing cookbook? In-Reply-To: <45944.91104.qm@web62412.mail.re1.yahoo.com> References: <45944.91104.qm@web62412.mail.re1.yahoo.com> Message-ID: <48062805.8010206@timgolden.me.uk> Bill Sneddon wrote: > Right know I am interested in finding out how to > access a windows server share in Python 2.4. Seems to > work fine in Python 2.5 with win32 installed, but the > MoinMoin server at work has not been upgraded. > The problem is this open can not use this kind of > path. OK. There's absolutely no reason why -- with or without pywin32 installed -- Python shouldn't be able to open a share in the way you describe. Just to make absolutely sure, I've just installed a vanilla Python 2.4.4 from python.org, no extensions, nothing. Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> open (r"\\vogbp393\c$\boot.ini", "r") >>> No problem. Are you sure there isn't something else in the way? Permissions? Connectivity, even? What error are you getting? Can you dump the traceback? TJG From timr at probo.com Wed Apr 16 19:48:43 2008 From: timr at probo.com (Tim Roberts) Date: Wed, 16 Apr 2008 10:48:43 -0700 Subject: [python-win32] SetSystemTime: A required privilege is not held by the client In-Reply-To: References: Message-ID: <48063BFB.5080709@probo.com> Robert wrote: > SetSystemTime on Vista admin account throws: > > (1314, 'SetSystemTime', 'A required privilege is not held by > the client.') > > Not known from previous Windows versions. > With what switch or whatever can this be enabled? > Remember that, on Vista, unlike previous systems, logging in as an administrator does not automatically give every process administrator privileges. This is one of the most invasive and annoying attributes of Vista. To get administrator privileges, a process has to be "elevated" (memories of Young Frankenstein). As a first test, does it work if you run it from an elevated command line? -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From python at kareta.de Wed Apr 16 23:21:02 2008 From: python at kareta.de (=?ISO-8859-1?Q?J=FCrgen_Kareta?=) Date: Wed, 16 Apr 2008 23:21:02 +0200 Subject: [python-win32] Overlay Icon Question and network drives In-Reply-To: <48060178.40605@timgolden.me.uk> References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> <1208344030.4805dddea6f0e@webmail.ldc.de> <48060178.40605@timgolden.me.uk> Message-ID: <48066DBE.3060902@kareta.de> Tim Golden schrieb: > python at kareta.de wrote: > >> Hi Andrea, >> >> the code in my first link was from the mercurial extension TortoiseHG. They >> found some issues that the icon overlay slows down network devices. See here: >> >> https://sourceforge.net/tracker/index.php?func=detail&aid=1892791&group_id=199155&atid=968354 >> >> Could you please tell if you have the same issues with the code Roger posted ? >> > > Worth noting that *any* code which is messing with icon overlays should > be just about as tight as it can possibly be. TortoiseSVN, which is written in > C++ has been doing this for years, tweaks its overlay & cache code on > pretty much every minor release to squeeze some more performance. > > I had a quick glance at the TortoiseHg code and was a bit surprised that > the key _get_state function isn't as tight as it might be. I say that, however, > with a huge amount of diffidence as I've had nothing whatsoever to do with > it and I imagine the developer's tried all sorts of tricks to speed things up. > > If the problem only seriously affects network drives, it's likely that the code's > doing too many calls to query file existence and attributes, all of which will > suffer on a (slower) network connection. > > Be interesting knowing whether other overlay handlers such as TortoiseSVN/CVS > cause the same problem, whether a simple no-op or one-op implementation > of _get_state ameliorates things, or whether the added layer of the Python > interpreter is causing the problems. > > As a side note, might be worth tying in to the TortoiseOverlays projects > which provides for a shared set of overlays for all Tortoise.. projects, > preventing problems with the rather low system limit. (Don't imagine it > would help speed things up, tho', since it introduces *another* layer > into the stack). > > Perusing the code at: > > http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/src/TortoiseShell/IconOverlay.cpp > > was very instructive! Worth checking the repos out to look at the log, too. > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > > > Andrea: Thanks for testing and reporting Tim: Thanks for giving so much detailed insights to it and of course I'm looking forward to read your cookbook about shell extensions written in Python ;-). By the way I have nothing to do with TortoiseHg, it was just one codeexample discussed on this list last january that I linked to on the wxpython list. While Rogers code seems to be a bit shorter, my quick and inexperienced look at the codes made me thinking that both examples do basically the same. That was the reason for my question. But nevertheless either the shell extensions and TortoiseHg are really interesting topics. And maybe the TortoiseHg project can also get their benefit out of this discussion. J?rgen From sjmachin at lexicon.net Thu Apr 17 00:39:05 2008 From: sjmachin at lexicon.net (John Machin) Date: Thu, 17 Apr 2008 08:39:05 +1000 Subject: [python-win32] exception while opening excel file In-Reply-To: <30285009.1207827007144.JavaMail.root@viefep27> References: <30285009.1207827007144.JavaMail.root@viefep27> Message-ID: <48068009.7050507@lexicon.net> iceblink at chello.nl wrote: > Hi all, > > I'm trying to write a file that does something with excel files. Unfortunately all these files will give an error upon opening: I don't quite understand the first sentence above : "write a file that does something with excel files"??? What is your underlying problem? (1) You are creating corrupt XLS files, and are now trying to get information about the nature of the corruption, so that you can fix the creating code? (2) You have a collection of corrupt XLS files, and you are now trying to recover data from them? Cheers, John From andrea.gavana at gmail.com Thu Apr 17 10:26:44 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Thu, 17 Apr 2008 09:26:44 +0100 Subject: [python-win32] Overlay Icon Question and network drives In-Reply-To: <48066DBE.3060902@kareta.de> References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> <1208344030.4805dddea6f0e@webmail.ldc.de> <48060178.40605@timgolden.me.uk> <48066DBE.3060902@kareta.de> Message-ID: Hi All, On Wed, Apr 16, 2008 at 10:21 PM, J?rgen Kareta wrote: > Tim Golden schrieb: > > > python at kareta.de wrote: > > > >> Hi Andrea, > >> > >> the code in my first link was from the mercurial extension TortoiseHG. They > >> found some issues that the icon overlay slows down network devices. See here: > >> > >> https://sourceforge.net/tracker/index.php?func=detail&aid=1892791&group_id=199155&atid=968354 > >> > >> Could you please tell if you have the same issues with the code Roger posted ? > >> > > > > Worth noting that *any* code which is messing with icon overlays should > > be just about as tight as it can possibly be. TortoiseSVN, which is written in > > C++ has been doing this for years, tweaks its overlay & cache code on > > pretty much every minor release to squeeze some more performance. > > > > I had a quick glance at the TortoiseHg code and was a bit surprised that > > the key _get_state function isn't as tight as it might be. I say that, however, > > with a huge amount of diffidence as I've had nothing whatsoever to do with > > it and I imagine the developer's tried all sorts of tricks to speed things up. > > > > If the problem only seriously affects network drives, it's likely that the code's > > doing too many calls to query file existence and attributes, all of which will > > suffer on a (slower) network connection. > > > > Be interesting knowing whether other overlay handlers such as TortoiseSVN/CVS > > cause the same problem, whether a simple no-op or one-op implementation > > of _get_state ameliorates things, or whether the added layer of the Python > > interpreter is causing the problems. > > > > As a side note, might be worth tying in to the TortoiseOverlays projects > > which provides for a shared set of overlays for all Tortoise.. projects, > > preventing problems with the rather low system limit. (Don't imagine it > > would help speed things up, tho', since it introduces *another* layer > > into the stack). > > > > Perusing the code at: > > > > http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/src/TortoiseShell/IconOverlay.cpp > > > > was very instructive! Worth checking the repos out to look at the log, too. > > > > TJG > > _______________________________________________ > > python-win32 mailing list > > python-win32 at python.org > > http://mail.python.org/mailman/listinfo/python-win32 > > > > > > > Andrea: Thanks for testing and reporting > > Tim: Thanks for giving so much detailed insights to it and of course I'm > looking forward to read your cookbook about shell extensions written in > Python ;-). By the way I have nothing to do with TortoiseHg, it was just > one codeexample discussed on this list last january that I linked to on > the wxpython list. While Rogers code seems to be a bit shorter, my quick > and inexperienced look at the codes made me thinking that both examples > do basically the same. That was the reason for my question. But > nevertheless either the shell extensions and TortoiseHg are really > interesting topics. And maybe the TortoiseHg project can also get their > benefit out of this discussion. Just an update: I have managed to make it running both as a Python script and as a standalone executable/dll. It's working fine and it's not slowing down our network connections: everything seems as fast as before. A big thank you to Roger and Tim for their kind help! Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From mail at timgolden.me.uk Thu Apr 17 12:57:43 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 17 Apr 2008 11:57:43 +0100 Subject: [python-win32] Overlay Icon Question and network drives In-Reply-To: References: <48046F7A.5030708@timgolden.me.uk> <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> <1208344030.4805dddea6f0e@webmail.ldc.de> <48060178.40605@timgolden.me.uk> <48066DBE.3060902@kareta.de> Message-ID: <48072D27.30206@timgolden.me.uk> Andrea Gavana wrote: > Just an update: I have managed to make it running both as a Python > script and as a standalone executable/dll. It's working fine and it's > not slowing down our network connections: everything seems as fast as > before. A big thank you to Roger and Tim for their kind help! Thanks for the update, Andrea. Glad we could help. Is it worth your posting the solution to the problems you were having with py2exe for anyone following this thread? TJG From andrea.gavana at gmail.com Thu Apr 17 13:16:16 2008 From: andrea.gavana at gmail.com (Andrea Gavana) Date: Thu, 17 Apr 2008 12:16:16 +0100 Subject: [python-win32] Overlay Icon Question and network drives In-Reply-To: <48072D27.30206@timgolden.me.uk> References: <4804B9BD.1090401@timgolden.me.uk> <4804E989.9000107@timgolden.me.uk> <1208344030.4805dddea6f0e@webmail.ldc.de> <48060178.40605@timgolden.me.uk> <48066DBE.3060902@kareta.de> <48072D27.30206@timgolden.me.uk> Message-ID: Hi Tim, On Thu, Apr 17, 2008 at 11:57 AM, Tim Golden wrote: > Andrea Gavana wrote: > > Just an update: I have managed to make it running both as a Python > > script and as a standalone executable/dll. It's working fine and it's > > not slowing down our network connections: everything seems as fast as > > before. A big thank you to Roger and Tim for their kind help! > > Thanks for the update, Andrea. Glad we could help. > Is it worth your posting the solution to the problems you were > having with py2exe for anyone following this thread? Yes, sorry I didn't think about it. The main problem I was having was due to the way I compiled the COM server with py2exe: every time I opened some file dialogs from my apps I got this traceback: pythoncom error: PythonCOM Server - The 'win32com.server.policy' module could not be loaded. : No module named server.policy pythoncom error: CPyFactory::CreateInstance failed to create instance. (80004005) Then, I just took the Setup.py file from TortoiseHG, modified it for my COM server and compiled it using the py2exe option bundle_files=1 (i.e., single executable without external dependencies). This works very well now. For the curious, this is my Setup.py file for my COM server: # ---------------------------------- # BEGIN CODE # ---------------------------------- # SetupCOMServer.py from distutils.core import setup import py2exe import sys import shutil # Remove the build tree... ALWAYS do that! shutil.rmtree("build", ignore_errors=True) # List of modules to exclude from the executable excludes = ["pywin", "pywin.debugger", "pywin.debugger.dbgcon", "pywin.dialogs", "pywin.dialogs.list"] # List of modules to include in the executable includes = ["win32com.server"] # ModuleFinder can't handle runtime changes to __path__, but win32com uses them try: # if this doesn't work, try import modulefinder import py2exe.mf as modulefinder import win32com for p in win32com.__path__[1:]: modulefinder.AddPackagePath("win32com", p) for extra in ["win32com.shell", "win32com.server"]: #,"win32com.mapi" __import__(extra) m = sys.modules[extra] for p in m.__path__[1:]: modulefinder.AddPackagePath(extra, p) except ImportError: # no build path setup, no worries. pass # Set up py2exe with all the options setup( options = {"py2exe": {"compressed": 2, "optimize": 2, "bundle_files": 1, "dist_dir": "COMDist", "excludes": excludes, "includes": includes}}, # The lib directory contains everything except the executables and the python dll. # Can include a subdirectory name. zipfile = None, com_server = ['KSVR_COMServer'], ) # ---------------------------------- # END CODE # ---------------------------------- I hope this will help someone in the future :-D Thanks for your help! Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.alice.it/infinity77/ From singhai.nish at gmail.com Fri Apr 18 14:56:42 2008 From: singhai.nish at gmail.com (kNish) Date: Fri, 18 Apr 2008 18:26:42 +0530 Subject: [python-win32] scheduler function weekdaytask Message-ID: <81bfef2e0804180556o13927887ib4c915a7d00afd34@mail.gmail.com> Hi, scheduler.py has a function weekdaytask. It needs five parameters as stated in the scheduler.py. weekdays and timeonday I figured out. what is name and action, args=None, kw=None ? BRgds, kNish ===================================================== class WeekdayTask(DayTaskRescheduler, Task): """A task that is called at specific days in a week (1-7), at a fixed time on the day.""" def __init__(self, name, weekdays, timeonday, action, args=None, kw=None): if type(timeonday) not in (list,tuple) or len(timeonday) != 2: raise TypeError("timeonday must be a 2-tuple (hour,minute)") if type(weekdays) not in (list,tuple): raise TypeError("weekdays must be a sequence of weekday numbers 1-7 (1 is Monday)") DayTaskRescheduler.__init__(self, timeonday) Task.__init__(self, name, action, args, kw) self.days=weekdays def execute(self): # This is called every day, at the correct time. We only need to # check if we should run this task today (this day of the week). weekday=time.localtime().tm_wday+1 if weekday in self.days: self.action(*self.args, **self.kw) ======================================================== -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080418/ba5ef4ff/attachment.htm From timr at probo.com Fri Apr 18 19:41:17 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 18 Apr 2008 10:41:17 -0700 Subject: [python-win32] scheduler function weekdaytask In-Reply-To: <81bfef2e0804180556o13927887ib4c915a7d00afd34@mail.gmail.com> References: <81bfef2e0804180556o13927887ib4c915a7d00afd34@mail.gmail.com> Message-ID: <4808DD3D.9090609@probo.com> kNish wrote: > Hi, > > scheduler.py has a function weekdaytask. It needs five parameters as > stated in the scheduler.py. weekdays and timeonday I figured out. > what is name and action, args=None, kw=None ? This is a TurboGears question, right? As such, this is not really the right place to ask about it. However, it's pretty easy to figure out what these are for, given the source code. All four of those parameters are passed without change to the Task constructor, which simply stores them for future use. You can see them being used in WeekdayTask.execute. The "name" is not terribly important. "action" is the function to be called when the task is executed. "args" and "kw" are passed to the "action" function at that time. "args" should be the list of positional parameters you need to pass to the "action" function (if any). "kw" should be a dictionary of the keyword parameters you need to pass. So, if you wanted to create a task to execute the following function: birthday( hwnd, name="kNish", year=2008 ) you would do something like this: : wt = scheduler.WeekdayTask( "A birthday", xxx, xxx, birthday, (hwnd,), {"name": "kNish", "year": 2008 } ) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From Kyle.Rickey at bakerhughes.com Sat Apr 19 02:10:23 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Fri, 18 Apr 2008 19:10:23 -0500 Subject: [python-win32] GetFileVersionInfo blocks main thread Message-ID: I'm trying to get the file version of an executable file on our network. At times our network is quite slow, so to prevent blocking of my main application, I decided to put the code into a separate thread. Depending on the network speed, it can take up to 30 seconds to return. This is because of a vpn connection etc. But when put in a separate thread, it will block the entire application until the function returns. Take the following code for example: import threading, time, os, win32api file = r"\\network_share\file.exe" def get_version_number(): if os.path.exists(file): info = win32api.GetFileVersionInfo(file, "\\") ms = info['FileVersionMS'] ls = info['FileVersionLS'] return win32api.HIWORD(ms), win32api.LOWORD(ms), win32api.HIWORD(ls), win32api.LOWORD(ls) def test(): print ".".join([str(i) for i in get_version_number()]) print "AA" threading.Thread(target=test).start() while 1: print "AA" time.sleep(0.5) The output looks like this: AA AA 2.0.0.15 AA .. The problem is after those 1st to "AA"'s got printed, no more were printed until the version number came back. Any ideas why this is happening? I've got python 2.5 and pywin32-210. -Kyle Rickey From antonyjoseph89 at gmail.com Sat Apr 19 10:22:57 2008 From: antonyjoseph89 at gmail.com (Antony Joseph) Date: Sat, 19 Apr 2008 13:52:57 +0530 Subject: [python-win32] working Directory get changed-mapi.MAPIInitialize(None) Message-ID: hi, 1. mapi.MAPIInitialize(None) changed the working directory to "C:\Program Files\Common Files\SYSTEM\MSMAPI\1033". is there anyway to initialize the MAPI which should not change the current working directory. Thanks Antony -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-win32/attachments/20080419/ccda33ef/attachment.htm From jcanto at hispasec.com Sat Apr 19 10:27:30 2008 From: jcanto at hispasec.com (Julio Canto) Date: Sat, 19 Apr 2008 10:27:30 +0200 Subject: [python-win32] win32all for win2008? In-Reply-To: References: Message-ID: <4809ACF2.1050407@hispasec.com> Hello, I know it may sound quite like a 'rush-like' question but, is there plans for releasing the win32 extensions for python that work at Windows 2008 environment? Thanks in advance for the feedback :) -- Regards, Julio Canto | VirusTotal.com | Hispasec Sistemas Lab | Tlf: +34.902.161.025 | Fax: +34.952.028.694 | PGP Key ID: EF618D2B | jcanto at hispasec.com From mail at timgolden.me.uk Sat Apr 19 11:43:55 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 19 Apr 2008 10:43:55 +0100 Subject: [python-win32] GetFileVersionInfo blocks main thread In-Reply-To: References: Message-ID: <4809BEDB.3020907@timgolden.me.uk> Rickey, Kyle W wrote: > I'm trying to get the file version of an executable file on our network. > At times our network is quite slow, so to prevent blocking of my main > application, I decided to put the code into a separate thread. > > Depending on the network speed, it can take up to 30 seconds to return. > This is because of a vpn connection etc. > > But when put in a separate thread, it will block the entire application > until the function returns. Take the following code for example: > > import threading, time, os, win32api > > file = r"\\network_share\file.exe" > > def get_version_number(): > if os.path.exists(file): > info = win32api.GetFileVersionInfo(file, "\\") > ms = info['FileVersionMS'] > ls = info['FileVersionLS'] > return win32api.HIWORD(ms), win32api.LOWORD(ms), > win32api.HIWORD(ls), win32api.LOWORD(ls) > > def test(): > print ".".join([str(i) for i in get_version_number()]) > > print "AA" > threading.Thread(target=test).start() > while 1: > print "AA" > time.sleep(0.5) > > The output looks like this: > > AA > AA > 2.0.0.15 > AA > .. > > The problem is after those 1st to "AA"'s got printed, no more were > printed until the version number came back. Any ideas why this is > happening? > I've got python 2.5 and pywin32-210. Works for me with the same setup. I stuck a time.sleep into the test function to simulate the slowness of your network. Might make a difference, I suppose. Couple of tangential points: 1) If you're on a slow connection anyway, don't have the double-whammy of checking the file's existence and then fetching its version info. Just go for the version info and catch the exception. CAVEAT: The exception seems to be identical for a non-existent file and a file with no version info. 2) [This may just be because this is self-contained sample code] You're generally going to be better of using a Queue or something suitably locked sharing mechanism to get info to and from a thread. I can't see anything else obvious. Do you see the same behaviour with a local drive and a faked delay, eg time.sleep (5)? If not then it might be that the various levels of your network setup are conspiring to block the process. Not really sure there. If that does prove to be a showstopper, you might consider the processing module which is plug-compatible with threading but uses processes instead. Bit of a sledgehammer to crack a nut, maybe but... TJG From mail at timgolden.me.uk Sat Apr 19 11:53:23 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 19 Apr 2008 10:53:23 +0100 Subject: [python-win32] GetFileVersionInfo blocks main thread In-Reply-To: <4809BEDB.3020907@timgolden.me.uk> References: <4809BEDB.3020907@timgolden.me.uk> Message-ID: <4809C113.1080602@timgolden.me.uk> Tim Golden wrote: > Works for me with the same setup. Sorry, by "the same setup" I meant: Python 2.5, pywin 210, *not* a slow VPN connection. I was just testing against a standard office LAN. TJG From mail at timgolden.me.uk Sat Apr 19 12:40:34 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 19 Apr 2008 11:40:34 +0100 Subject: [python-win32] working Directory get changed-mapi.MAPIInitialize(None) In-Reply-To: References: Message-ID: <4809CC22.2070206@timgolden.me.uk> Antony Joseph wrote: > hi, > > 1. mapi.MAPIInitialize(None) changed the working directory to "C:\Program > Files\Common Files\SYSTEM\MSMAPI\1033". > is there anyway to initialize the MAPI which should not change the current > working directory. No. It's a documented "feature": http://support.microsoft.com/kb/245557 TJG From mdriscoll at co.marshall.ia.us Sat Apr 19 19:27:21 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Sat, 19 Apr 2008 12:27:21 -0500 (CDT) Subject: [python-win32] Windows programing cookbook? Message-ID: <689306.1271208626041931.JavaMail.root@zimbra> Bill Sneddon wrote: > Does anyone know of a website with windows code > examples? > I'm surprised Golden didn't mention his site. It has lots of examples on it. http://timgolden.me.uk/python/index.html I had originally thought I would create a wiki for this very purpose. However, my interest waned and I stupidly dropped it. The good news is that that has continued to bother me, so I hope to get it going again, even if it's just to create a basic skeleton and then let all the good people on here have a whack at it. If anyone thinks that's a good idea, let me know. I'm thinking it would be good to do a CookBook / FAQ style plus something like this guy is doing with the Python Standard Library: http://pbe.lightbird.net/ Maybe my ideas are too grandiose though... > I have googled this have not found much. I know about > Activestate's site but does not seemed to be organized > in a way to get these easily. > > Is there a FAQ for this mail list? > > Right know I am interested in finding out how to > access a windows server share in Python 2.4. Seems to > work fine in Python 2.5 with win32 installed, but the > MoinMoin server at work has not been upgraded. > The problem is this open can not use this kind of > path. > > I don't have access to the network now but the problem > is like this example: > > txtFile = open(r'\\aServer\share$\myfile.txt','r') > > This command is unable to find the file on Python 2.4. > I apologies if this is a FAQ but I have looked some. > > Is there a work around to this problem, can I map a > network drive on the at runtime? > > Bill Sneddon > > As Golden pointed out, this should work just fine with standard Python code. I do it all the time at work. Oh, and if you're just going to read it, you don't even need to include that flag. It can just be: txtFile = open(r'\\aServer\share$\myfile.txt') Mike From rwupole at msn.com Mon Apr 21 05:11:23 2008 From: rwupole at msn.com (Roger Upole) Date: Sun, 20 Apr 2008 23:11:23 -0400 Subject: [python-win32] GetFileVersionInfo blocks main thread Message-ID: Kyle Rickey wrote: > I'm trying to get the file version of an executable file on our network. > At times our network is quite slow, so to prevent blocking of my main > application, I decided to put the code into a separate thread. > > Depending on the network speed, it can take up to 30 seconds to return. > This is because of a vpn connection etc. > > But when put in a separate thread, it will block the entire application > until the function returns. Take the following code for example: > > import threading, time, os, win32api > > file = r"\\network_share\file.exe" > > def get_version_number(): > if os.path.exists(file): > info = win32api.GetFileVersionInfo(file, "\\") > ms = info['FileVersionMS'] > ls = info['FileVersionLS'] > return win32api.HIWORD(ms), win32api.LOWORD(ms), > win32api.HIWORD(ls), win32api.LOWORD(ls) > > def test(): > print ".".join([str(i) for i in get_version_number()]) > > print "AA" > threading.Thread(target=test).start() > while 1: > print "AA" > time.sleep(0.5) > > The output looks like this: > > AA > AA > 2.0.0.15 > AA > .. > > The problem is after those 1st to "AA"'s got printed, no more were > printed until the version number came back. Any ideas why this is > happening? > I've got python 2.5 and pywin32-210. > > -Kyle Rickey This function doesn't release the thread lock when making the API calls. I'll try to remedy this before the next release. Roger From Kyle.Rickey at bakerhughes.com Mon Apr 21 15:20:54 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Mon, 21 Apr 2008 08:20:54 -0500 Subject: [python-win32] GetFileVersionInfo blocks main thread In-Reply-To: References: Message-ID: Thanks Roger/Tim. In the mean time I'm going to check out the processing module Tim pointed me to. Hopefully I'll have some free time to test it out. Thanks again for your help. -Kyle Rickey -----Original Message----- From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Roger Upole Sent: Sunday, April 20, 2008 10:11 PM To: python-win32 at python.org Subject: [python-win32] GetFileVersionInfo blocks main thread Kyle Rickey wrote: > I'm trying to get the file version of an executable file on our network. > At times our network is quite slow, so to prevent blocking of my main > application, I decided to put the code into a separate thread. > > Depending on the network speed, it can take up to 30 seconds to return. > This is because of a vpn connection etc. > > But when put in a separate thread, it will block the entire application > until the function returns. Take the following code for example: > > import threading, time, os, win32api > > file = r"\\network_share\file.exe" > > def get_version_number(): > if os.path.exists(file): > info = win32api.GetFileVersionInfo(file, "\\") > ms = info['FileVersionMS'] > ls = info['FileVersionLS'] > return win32api.HIWORD(ms), win32api.LOWORD(ms), > win32api.HIWORD(ls), win32api.LOWORD(ls) > > def test(): > print ".".join([str(i) for i in get_version_number()]) > > print "AA" > threading.Thread(target=test).start() > while 1: > print "AA" > time.sleep(0.5) > > The output looks like this: > > AA > AA > 2.0.0.15 > AA > .. > > The problem is after those 1st to "AA"'s got printed, no more were > printed until the version number came back. Any ideas why this is > happening? > I've got python 2.5 and pywin32-210. > > -Kyle Rickey This function doesn't release the thread lock when making the API calls. I'll try to remedy this before the next release. Roger _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From Kyle.Rickey at bakerhughes.com Mon Apr 21 15:22:32 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Mon, 21 Apr 2008 08:22:32 -0500 Subject: [python-win32] FW: GetFileVersionInfo blocks main thread Message-ID: I just realized that this conversation didn't make it to the whole list so read below if anyone is interested. -Kyle Rickey -----Original Message----- From: Tim Golden [mailto:mail at timgolden.me.uk] Sent: Saturday, April 19, 2008 12:20 PM To: Rickey, Kyle W Subject: Re: [python-win32] GetFileVersionInfo blocks main thread Rickey, Kyle W wrote: > Tim, thanks for your response. By not checking for the existence of the > file, I've shaved off a few more seconds of my startup time. > > It is pretty strange that if I try it with a local file it doesn't > block. Something in the network then, I imagine. > Also, when you mention the process module do you mean win32process or > subprocess? Neither. This one: http://pypi.python.org/pypi/processing TJG From simon.king at motorola.com Mon Apr 21 14:56:54 2008 From: simon.king at motorola.com (King Simon-NFHD78) Date: Mon, 21 Apr 2008 13:56:54 +0100 Subject: [python-win32] os.startfile mysteriously failing Message-ID: <8D20BBB55F590E42AADF592A815E86170322A49C@zuk35exm65.ds.mot.com> Hello all, I am developing an application that, amongst other things, exports files and then launches them in their associated applications using os.startfile. It also uses webbrowser.open, which I see uses os.startfile. Everything works on my PC and on all the other PCs in the office that I have tested on. However, when we released our first version, a few users reported unhandled exceptions that seem to be coming from os.startfile. Here are some examples: Traceback (most recent call last): File "link_planner\wxapp\main_frame.pyc", line 1505, in _on_csv File "link_planner\utils\platform_win32.pyc", line 17, in openfile WindowsError: [Error 2] The system cannot find the file specified: 'c:\\docume~1\\admin\\locals~1\\temp\\tmpjotxlk.csv' Traceback (most recent call last): File "link_planner\wxapp\main_frame.pyc", line 1528, in _on_google_earth File "link_planner\utils\platform_win32.pyc", line 17, in openfile WindowsError: [Error -2147024809] The parameter is incorrect: 'c:\\docume~1\\bfults\\locals~1\\temp\\tmphjyfy-.kml' Traceback (most recent call last): File "link_planner\wxapp\html_window.pyc", line 7, in OnLinkClicked File "link_planner\wxapp\about_frame.pyc", line 41, in _on_link_clicked File "webbrowser.pyc", line 60, in open File "webbrowser.pyc", line 516, in open WindowsError: [Error 2] The system cannot find the file specified: u'http://www.motorola.com/ptp' In the last instance, the user said the problem went away when he changed his default browser from firefox to IE, so it may be a red herring, but I'd like to be sure. In the first two cases, I use tempfile.mkstemp to generate the temporary files, so I am fairly sure that they exist. I've searched for any information about similar issues, and this is what I've found: This guy sounds like he has exactly the same problem, but there is no solution given: http://groups.google.co.uk/group/comp.lang.python/browse_thread/thread/d d86ba0e6420a2b4/75c8cacd8e6c06ed This recipe describes os.startfile failing for URLs: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/334665 It includes a link to another page saying that ShellExecute doesn't work from a multi-threaded apartment. I don't think that is my problem here, as I am not using multiple threads, and I'm not (as far as I am aware) using COM anywhere. I made a quick test, and the error message I get is different: WindowsError: [Error 14007] The requested lookup key was not found in any active activation context: 'http://www.python.org'. I think my next step is going to be reimplementing os.startfile in python and adding more logging, but I just wondered whether anyone else had ever had problems with os.startfile? BTW, all this is from Python 2.5.1, but the application has been packaged using py2exe, in case that makes a difference. Thanks a lot for any suggestions, Simon King From mail at timgolden.me.uk Mon Apr 21 15:56:11 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 21 Apr 2008 14:56:11 +0100 Subject: [python-win32] os.startfile mysteriously failing In-Reply-To: <8D20BBB55F590E42AADF592A815E86170322A49C@zuk35exm65.ds.mot.com> References: <8D20BBB55F590E42AADF592A815E86170322A49C@zuk35exm65.ds.mot.com> Message-ID: <480C9CFB.2070907@timgolden.me.uk> King Simon-NFHD78 wrote: > Hello all, > > I am developing an application that, amongst other things, exports files > and then launches them in their associated applications using > os.startfile. It also uses webbrowser.open, which I see uses > os.startfile. > > Everything works on my PC and on all the other PCs in the office that I > have tested on. However, when we released our first version, a few users > reported unhandled exceptions that seem to be coming from os.startfile. > Here are some examples: [... snipped ...] Unless someone comes in with something more authoritative, here are a few avenues to try: 1) According to this: http://groups.google.co.uk/group/microsoft.public.platformsdk.shell/msg/943b9844d480b029 ShellExecute on a URL invokes a shell extension handler which will operate in apartment threading mode. (ie you're using COM whether you like it or not). Exactly how this affects your situation I'm sure I couldn't say, especially since you seem to have tried that route and you're not specifying a COM threading model. 2) Is there any kind of consistency? ie does one user always fail on .csv while another fails on .kml? I'm sure this is stuff you'll have gone over yourself; I'm just trying to eliminate unknowns. I tried the obvious lack of associations and that comes up with a different message. 3) os.startfile basically just calls ShellExecute with the appropriate params. As an alternative, you could use FindExecutable from the win32api module of the pywin32 extensions, coupled with subprocess.call. Something like this: import win32api import subprocess FILENAME = "c:/temp/test.csv" _, exename = win32api.FindExecutable (FILENAME) subprocess.call ([exename, FILENAME]) Workaround, undoubtedly, and it won't work for URLs, but at least it might take you somewhere if you can't get the other thing working. TJG From simon.king at motorola.com Mon Apr 21 19:33:24 2008 From: simon.king at motorola.com (King Simon-NFHD78) Date: Mon, 21 Apr 2008 18:33:24 +0100 Subject: [python-win32] os.startfile mysteriously failing In-Reply-To: <480C9CFB.2070907@timgolden.me.uk> Message-ID: <8D20BBB55F590E42AADF592A815E86170322A54D@zuk35exm65.ds.mot.com> Tim Golden wrote: > King Simon-NFHD78 wrote: > > Hello all, > > > > I am developing an application that, amongst other things, > exports files > > and then launches them in their associated applications using > > os.startfile. It also uses webbrowser.open, which I see uses > > os.startfile. > > > > Everything works on my PC and on all the other PCs in the > office that I > > have tested on. However, when we released our first > version, a few users > > reported unhandled exceptions that seem to be coming from > os.startfile. > > Here are some examples: > > [... snipped ...] > > Unless someone comes in with something more authoritative, here > are a few avenues to try: > Hi Tim, Thanks a lot for responding. > 1) According to this: > > > http://groups.google.co.uk/group/microsoft.public.platformsdk. > shell/msg/943b9844d480b029 > > ShellExecute on a URL invokes a shell extension handler which > will operate > in apartment threading mode. (ie you're using COM whether you > like it or > not). Exactly how this affects your situation I'm sure I > couldn't say, especially > since you seem to have tried that route and you're not > specifying a COM > threading model. > I built the example code from that thread, and was able to get ShellExecute to fail by using COINIT_MULTITHREADED, but A) It only failed for URLs - launching a .txt file seemed to work either way. B) When it did fail, the error message was the same as the one I was getting in python - "The requested lookup key was not found in any active activation context." I don't think this is my problem. > > 2) Is there any kind of consistency? ie does one user always > fail on .csv while > another fails on .kml? I'm sure this is stuff you'll have > gone over yourself; I'm > just trying to eliminate unknowns. I tried the obvious lack > of associations and > that comes up with a different message. > I need to investigate this further. Remote debugging via email, with users in different time zones, is a slow process :-) > 3) os.startfile basically just calls ShellExecute with the > appropriate params. As > an alternative, you could use FindExecutable from the > win32api module of the > pywin32 extensions, coupled with subprocess.call. Something like this: > > > import win32api > import subprocess > > FILENAME = "c:/temp/test.csv" > _, exename = win32api.FindExecutable (FILENAME) > subprocess.call ([exename, FILENAME]) > > > > Workaround, undoubtedly, and it won't work for URLs, but at > least it might take you > somewhere if you can't get the other thing working. > > TJG Thanks a lot for this - I may well end up using it. I have a slight worry that it won't work in the face of "funny" ways of opening documents (ie. DDE), but it'll be easy enough to find out. Thanks again for your help, Simon From trentm at activestate.com Mon Apr 21 19:52:38 2008 From: trentm at activestate.com (Trent Mick) Date: Mon, 21 Apr 2008 10:52:38 -0700 Subject: [python-win32] Windows programing cookbook? In-Reply-To: <689306.1271208626041931.JavaMail.root@zimbra> References: <689306.1271208626041931.JavaMail.root@zimbra> Message-ID: <480CD466.5050706@activestate.com> >> I have googled this have not found much. I know about >> Activestate's site but does not seemed to be organized >> in a way to get these easily. (Jumping in late on this thread. Apologies if I've missed a lot of context.) We [ActiveState] hope to be giving a big refresh to the cookbook site in the next month or two. My hope is that the refresh would make it perfect for putting up a bunch of pywin32 programming examples. Part of the re-work of the site will include more typical tagging of recipes -- rather than the somewhat limited categorization there right now. For example, you'd be able to tag all Windows programming examples with "pywin32" or whatever, and then browse only that set of recipes. Any feedback on what kinds of things out of a refreshed cookbook site would be essential for making this all easier would be welcome. Cheers, Trent (Python Lead at ActiveState) -- Trent Mick trentm at activestate.com From timr at probo.com Mon Apr 21 19:54:43 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 21 Apr 2008 10:54:43 -0700 Subject: [python-win32] working Directory get changed-mapi.MAPIInitialize(None) In-Reply-To: References: Message-ID: <480CD4E3.6010907@probo.com> Antony Joseph wrote: > hi, > > 1. mapi.MAPIInitialize(None) changed the working directory to > "C:\Program Files\Common Files\SYSTEM\MSMAPI\1033". > is there anyway to initialize the MAPI which should not change the > current working directory. where = os.getcwd() mapi.MAPIInitialize(None) os.chdir(where) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From theller at ctypes.org Mon Apr 21 20:17:50 2008 From: theller at ctypes.org (Thomas Heller) Date: Mon, 21 Apr 2008 20:17:50 +0200 Subject: [python-win32] os.startfile mysteriously failing In-Reply-To: <480C9CFB.2070907@timgolden.me.uk> References: <8D20BBB55F590E42AADF592A815E86170322A49C@zuk35exm65.ds.mot.com> <480C9CFB.2070907@timgolden.me.uk> Message-ID: Tim Golden schrieb: > King Simon-NFHD78 wrote: >> Hello all, >> >> I am developing an application that, amongst other things, exports files >> and then launches them in their associated applications using >> os.startfile. It also uses webbrowser.open, which I see uses >> os.startfile. >> >> Everything works on my PC and on all the other PCs in the office that I >> have tested on. However, when we released our first version, a few users >> reported unhandled exceptions that seem to be coming from os.startfile. >> Here are some examples: > > [... snipped ...] > > Unless someone comes in with something more authoritative, here > are a few avenues to try: > > 1) According to this: > > http://groups.google.co.uk/group/microsoft.public.platformsdk.shell/msg/943b9844d480b029 > > ShellExecute on a URL invokes a shell extension handler which will operate > in apartment threading mode. (ie you're using COM whether you like it or > not). Exactly how this affects your situation I'm sure I couldn't say, especially > since you seem to have tried that route and you're not specifying a COM > threading model. Some remarks that may or may not be useful: AFAIK, a single threaded COM apartment needs to run a message loop, according to the COM rules. If the OP has a gui-application, and calls os.startfile from the main thread, then this should be no problem. If he has a console application, there normally is no message loop. Looking into the MSDN docs for ShellExecuteEx [1], *this* function allows to set additional flags in the SHELLEXECUTEINFO structure that you pass to it. It seems that SEE_MASK_FLAG_DDEWAIT may be something worth to try out [2]: """ The SEE_MASK_FLAG_DDEWAIT flag must be specified if the thread calling ShellExecuteEx does not have a message loop or if the thread or process will terminate soon after ShellExecuteEx returns. Under such conditions, the calling thread will not be available to complete the DDE conversation, so it is important that ShellExecuteEx complete the conversation before returning control to the calling application. Failure to complete the conversation can result in an unsuccessful launch of the document. """ [1] http://msdn2.microsoft.com/en-us/library/bb762154.aspx [2] http://msdn2.microsoft.com/en-us/library/bb759784(VS.85).aspx Thomas From mdriscoll at co.marshall.ia.us Mon Apr 21 21:24:32 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Mon, 21 Apr 2008 14:24:32 -0500 Subject: [python-win32] Windows programing cookbook? In-Reply-To: <480CD466.5050706@activestate.com> References: <689306.1271208626041931.JavaMail.root@zimbra> <480CD466.5050706@activestate.com> Message-ID: <480CE9F0.9070708@co.marshall.ia.us> Trent, >
>> I have > googled this have not found much. I know about >>> Activestate's site but does not seemed to be organized >>> in a way to get these easily. > > (Jumping in late on this thread. Apologies if I've missed a lot of > context.) > > We [ActiveState] hope to be giving a big refresh to the cookbook site > in the next month or two. My hope is that the refresh would make it > perfect for putting up a bunch of pywin32 programming examples. > > Part of the re-work of the site will include more typical tagging of > recipes -- rather than the somewhat limited categorization there right > now. For example, you'd be able to tag all Windows programming > examples with "pywin32" or whatever, and then browse only that set of > recipes. > > Any feedback on what kinds of things out of a refreshed cookbook site > would be essential for making this all easier would be welcome. > > Cheers, > Trent (Python Lead at ActiveState) > You haven't missed anything. It was only me responding to the OP and no one else has commented. I do think it would be nice if there was a centralized repository of some sort for pywin32 examples and such. Will the tags make it easier or harder to find stuff? I've had problems finding recipes on there because I used one general term and the "chef" used a different general or specific term. I'm not sure how that could be fixed though. Mike From trentm at activestate.com Mon Apr 21 23:19:07 2008 From: trentm at activestate.com (Trent Mick) Date: Mon, 21 Apr 2008 14:19:07 -0700 Subject: [python-win32] Windows programing cookbook? In-Reply-To: <480CE9F0.9070708@co.marshall.ia.us> References: <689306.1271208626041931.JavaMail.root@zimbra> <480CD466.5050706@activestate.com> <480CE9F0.9070708@co.marshall.ia.us> Message-ID: <480D04CB.1030400@activestate.com> Mike Driscoll wrote: > Will > the tags make it easier or harder to find stuff? I've had problems > finding recipes on there because I used one general term and the "chef" > used a different general or specific term. I'm not sure how that could > be fixed though. Certainly I think basic tagging support for the Python Cookbook will help over the static set of categories in use now. It is a valid point, tho. This is a common problem for all sites that use free-form tagging for categorization. My (limited) experience is that some popular tags eventually coalesce -- i.e. people settle on one tag name for one kind of thing. Full-text search is, obviously, that partner to this that can help with finding what you are looking for. For example, I would expect that the vast majority of recipes dealing with PyWin32 would have the words "Python", "Windows" and maybe "win32" in them so a search on those words would tend to hit the recipes you are looking for. Trent -- Trent Mick trentm at activestate.com From mdriscoll at co.marshall.ia.us Mon Apr 21 23:34:21 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Mon, 21 Apr 2008 16:34:21 -0500 Subject: [python-win32] Windows programing cookbook? In-Reply-To: <480D04CB.1030400@activestate.com> References: <689306.1271208626041931.JavaMail.root@zimbra> <480CD466.5050706@activestate.com> <480CE9F0.9070708@co.marshall.ia.us> <480D04CB.1030400@activestate.com> Message-ID: <480D085D.3020203@co.marshall.ia.us> Trent Mick wrote: > Mike Driscoll wrote: >> Will the tags make it easier or harder to find stuff? I've had >> problems finding recipes on there because I used one general term and >> the "chef" used a different general or specific term. I'm not sure >> how that could be fixed though. > > Certainly I think basic tagging support for the Python Cookbook will > help over the static set of categories in use now. > > It is a valid point, tho. This is a common problem for all sites that > use free-form tagging for categorization. My (limited) experience is > that some popular tags eventually coalesce -- i.e. people settle on > one tag name for one kind of thing. > > Full-text search is, obviously, that partner to this that can help > with finding what you are looking for. For example, I would expect > that the vast majority of recipes dealing with PyWin32 would have the > words "Python", "Windows" and maybe "win32" in them so a search on > those words would tend to hit the recipes you are looking for. > > Trent > That's true. I just seem to always hit the weird corner cases and end up screwing around the entire afternoon looking for something that should have been obvious from the beginning. Usually in retrospect, it WAS obvious, but not to me. I'm sure it's not your company's fault and I didn't mean to imply that. If I did, I apologize. Thanks for the updates. I look forward to using them. Mike From mail at timgolden.me.uk Tue Apr 22 04:51:26 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 22 Apr 2008 03:51:26 +0100 Subject: [python-win32] os.startfile mysteriously failing In-Reply-To: <8D20BBB55F590E42AADF592A815E86170322A49C@zuk35exm65.ds.mot.com> References: <8D20BBB55F590E42AADF592A815E86170322A49C@zuk35exm65.ds.mot.com> Message-ID: <480D52AE.70206@timgolden.me.uk> King Simon-NFHD78 wrote: > I am developing an application that, amongst other things, exports files > and then launches them in their associated applications using > os.startfile. It also uses webbrowser.open, which I see uses > os.startfile. > > Everything works on my PC and on all the other PCs in the office that I > have tested on. However, when we released our first version, a few users > reported unhandled exceptions that seem to be coming from os.startfile. Just remembered something mildly obscure which has caused this for us in the past: if the application which is opening (Excel, Google Earth, etc.) throws up some sort of modal dialog box early in the process, ShellExecute will throw back this error. The canonical example is an app which forces you through some sort of first-time wizard, typically for registration. I'm fairly sure we saw it on Acrobat reader when it was doing some sort of "Do you want these updates?" thing as well. In case it helps. TJG From daniel.goncalves at inesc-id.pt Tue Apr 22 10:50:41 2008 From: daniel.goncalves at inesc-id.pt (=?ISO-8859-1?Q?Daniel_Gon=E7alves?=) Date: Tue, 22 Apr 2008 09:50:41 +0100 Subject: [python-win32] Finding the selected file in Windows Explorer Message-ID: <480DA6E1.6070003@inesc-id.pt> Hi! I need to find the selected file(s) in a Windows Explorer window from another program (I'd look at the window that last had focus). I found something in the following page that should do the trick: http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx However, it is not Python and, while I'm a competent Python programmer, Win32, COM and the like are somewhat outside my competences. Does any one know how to do something similar in Python (maybe in a more Pythonic way?) Tks! Daniel Gon?alves From simon.king at motorola.com Tue Apr 22 12:47:37 2008 From: simon.king at motorola.com (King Simon-NFHD78) Date: Tue, 22 Apr 2008 11:47:37 +0100 Subject: [python-win32] os.startfile mysteriously failing In-Reply-To: Message-ID: <8D20BBB55F590E42AADF592A815E8617033F00A0@zuk35exm65.ds.mot.com> Thomas Heller wrote: > > Some remarks that may or may not be useful: > > AFAIK, a single threaded COM apartment needs to run a message loop, > according to the COM rules. If the OP has a gui-application, and > calls os.startfile from the main thread, then this should be > no problem. > > If he has a console application, there normally is no message loop. > > Looking into the MSDN docs for ShellExecuteEx [1], *this* > function allows > to set additional flags in the SHELLEXECUTEINFO structure > that you pass to it. > It seems that SEE_MASK_FLAG_DDEWAIT may be something worth to > try out [2]: > > """ > The SEE_MASK_FLAG_DDEWAIT flag must be specified if the > thread calling ShellExecuteEx > does not have a message loop or if the thread or process will > terminate soon after > ShellExecuteEx returns. Under such conditions, the calling > thread will not be available > to complete the DDE conversation, so it is important that > ShellExecuteEx complete the > conversation before returning control to the calling > application. Failure to complete > the conversation can result in an unsuccessful launch of the document. > """ > > [1] http://msdn2.microsoft.com/en-us/library/bb762154.aspx > [2] http://msdn2.microsoft.com/en-us/library/bb759784(VS.85).aspx > > Thomas > Hi Thomas, Thanks for responding. I do have a GUI application (using wxPython), and I am calling os.startfile from the main thread. However, thanks to yours and Tim's suggestions, I've done some more experimenting, and have discovered the following: I can get webbrowser.open('http://www.python.org') to fail fairly reliably by ensuring that I have lots of tabs open in Firefox (and the option for showing my windows and tabs from last time on startup), then exiting Firefox, then running webbrowser.open('http://www.python.org'). Firefox starts, and it opens a tab for www.python.org, but it also loads all my tabs from the previous session. This seems to take longer than startfile/ShellExecute is prepared to wait, and so it fails with WindowsError: [Error 2] The system cannot find the file specified: 'http://www.python.org'. I'm fairly convinced that this is the same problem Tim referred to about modal dialog boxes. (Out of interest, running 'start http://www.python.org' from a command prompt has a similar problem - it blocks while Firefox is loading all its tabs, but eventually gives up waiting and shows a dialog box saying that the file cannot be found). Perhaps this should be considered a bug in Firefox. If the file I'm trying to launch has a 'simple' file association (such as KML which has a command of 'C:\Program Files\Google\Google Earth\googleearth.exe "%1"'), then os.startfile returns almost immediately. If the file association uses DDE (such as CSV when associated with Excel), then startfile doesn't return until the application has finished opening the file. I'm not actually certain whether the message loop is necessary in this situation - I was calling startfile from a command prompt and it seemed to be working. I've not managed to recreate the 'file not found' error with a CSV file, nor the 'parameter is incorrect' error with the KML file. I think I may make my own startfile function using ShellExecuteEx. All I really want is a 'fire-and-forget' function (for example, if there is no registered handler for the file extension, I would rather the user saw the shell's 'What application would you like to use' dialog than having to make my own). I'll experiment with the SEE_MASK_ASYNCOK flag. Thank you both for your help, Simon From Kyle.Rickey at bakerhughes.com Tue Apr 22 15:23:36 2008 From: Kyle.Rickey at bakerhughes.com (Rickey, Kyle W) Date: Tue, 22 Apr 2008 08:23:36 -0500 Subject: [python-win32] Finding the selected file in Windows Explorer In-Reply-To: <480DA6E1.6070003@inesc-id.pt> References: <480DA6E1.6070003@inesc-id.pt> Message-ID: >From what I understand, you'd probably need to find the listctrl in the explorer window by using EnumChildWindows. From there there's probably a way to get the selected items. I'm no expert, but that might get you started in the right direction until someone can provide a better response. -Kyle Rickey -----Original Message----- From: python-win32-bounces+kyle.rickey=bakerhughes.com at python.org [mailto:python-win32-bounces+kyle.rickey=bakerhughes.com at python.org] On Behalf Of Daniel Gon?alves Sent: Tuesday, April 22, 2008 3:51 AM To: python-win32 at python.org Subject: [python-win32] Finding the selected file in Windows Explorer Hi! I need to find the selected file(s) in a Windows Explorer window from another program (I'd look at the window that last had focus). I found something in the following page that should do the trick: http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx However, it is not Python and, while I'm a competent Python programmer, Win32, COM and the like are somewhat outside my competences. Does any one know how to do something similar in Python (maybe in a more Pythonic way?) Tks! Daniel Gon?alves _______________________________________________ python-win32 mailing list python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32 From mc at mclaveau.com Tue Apr 22 15:43:10 2008 From: mc at mclaveau.com (Michel Claveau) Date: Tue, 22 Apr 2008 15:43:10 +0200 Subject: [python-win32] Finding the selected file in Windows Explorer In-Reply-To: <480DA6E1.6070003@inesc-id.pt> References: <480DA6E1.6070003@inesc-id.pt> Message-ID: Hi! Since Vista, Windows-Explorer and Internet-Explorer are separate. Previously it was possible to drive Windows-Explorer via COM. Vista made that impossible. IMO, you must seek another way that COM. Sorry. Michel Claveau From larry.bates at websafe.com Tue Apr 22 16:02:52 2008 From: larry.bates at websafe.com (Larry Bates) Date: Tue, 22 Apr 2008 09:02:52 -0500 Subject: [python-win32] Finding the selected file in Windows Explorer In-Reply-To: <480DA6E1.6070003@inesc-id.pt> References: <480DA6E1.6070003@inesc-id.pt> Message-ID: Daniel Gon?alves wrote: > Hi! > > I need to find the selected file(s) in a Windows Explorer window from > another program (I'd look at the window that last had focus). I found > something in the following page that should do the trick: > > http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx > > However, it is not Python and, while I'm a competent Python > programmer, Win32, COM and the like are somewhat outside my > competences. > > Does any one know how to do something similar in Python (maybe in a more > Pythonic way?) > > > Tks! > Daniel Gon?alves Daniel, What do you mean by "find the selected files". Give us a little more detail about your use case and we can help. One way of knowing about files that are selected is this: If you selected several files and drag and drop them on a python program the files that are selected will be passed into the program in sys.argv. I don't know if that is what you are looking for or not. -Larry From a1eio at hotmail.com Tue Apr 22 16:11:55 2008 From: a1eio at hotmail.com (Alex Denham) Date: Tue, 22 Apr 2008 15:11:55 +0100 Subject: [python-win32] Drag and Drop issues Message-ID: Hi, I'm trying to implement a drag and drop feature in my Tkinter based gui. I want to be able to drag a file from windows (explorer/desktop etc) into my program. Then i need my program to get the filepath for the file that was dropped. I've tried to search all over the internet, in books and in the win32 documentation provided with the win32 package but i keep finding conflicting information. Furthest i have gotten is the following: _id = root.winfo_id() win32gui.DragAcceptFiles(_id, 1) That works, without that i don't get the little 'drop' icon when i drag something over, however after that i'm completly stuck, i've tried using win32gui.GetMessage() to see if there is anything in that output that relates to a drop, I've tried win32api.DragQueryFile(_id). I think i need to do something using a PyIDropTarget but i have no idea where to import that from, i've tried making a class with that as the name and then initializing it and passing it to pythoncom.RegisterDragDrop(_id, dropTarget) dropTarget being the initialized PyIDropTarget class, however it says, it's not a com object... I think i've just managed to get myself confused, i just need a pointer on the right way to do it, do i use registerdrag drop or do i use dragqueryfile and dragacceptfiles, and how to i check to see if my program has recieved a drop request, is there some sort of event or something i can listen for (thats initially what i thought GetMessage() was for but i'm unsure how to use it) Any help would be much appreciated. And if you need any more info don't hesitate to ask. Thanks in advance Alex _________________________________________________________________ Search and win with BigSnapSearch.com http://www.bigsnapsearch.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From daniel.goncalves at inesc-id.pt Tue Apr 22 18:05:58 2008 From: daniel.goncalves at inesc-id.pt (=?ISO-8859-1?Q?Daniel_Gon=E7alves?=) Date: Tue, 22 Apr 2008 17:05:58 +0100 Subject: [python-win32] Finding the selected file in Windows Explorer In-Reply-To: References: <480DA6E1.6070003@inesc-id.pt> Message-ID: <480E0CE6.5060901@inesc-id.pt> Larry Bates wrote: > Daniel Gon?alves wrote: >> Hi! >> >> I need to find the selected file(s) in a Windows Explorer window from >> another program (I'd look at the window that last had focus). > Daniel, > > What do you mean by "find the selected files". Give us a little more > detail about your use case and we can help. > Hi! What I'm trying to do is to have a program that detects whenever some file(s) are dragged over an area of the screen. Not dropped there, but dragged over it (close to the screen border, for instance). AFAIK, Windows only generates events whenever something is dropped, which will be useless here. I will be using hooks to monitor mouse events and, when the mouse is over the defined region, I need to find out what is being dragged. A way to do estimate this might be to know that the currently focused window is an Explorer window, and query it for the selected items (they will be the ones being dragged). This is only an approximation but might be enough for my ends, if no better way is found. Of course, if there is a way of just asking the OS "what is being dragged right now", that would work even better :) Tks! Daniel > One way of knowing about files that are selected is this: > > If you selected several files and drag and drop them on a python program > the files that are selected will be passed into the program in > sys.argv. I don't know if that is what you are looking for or not. > > -Larry > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 > From timr at probo.com Tue Apr 22 19:07:13 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 22 Apr 2008 10:07:13 -0700 Subject: [python-win32] Finding the selected file in Windows Explorer In-Reply-To: References: <480DA6E1.6070003@inesc-id.pt> Message-ID: <480E1B41.8040403@probo.com> Michel Claveau wrote: > Hi! > > Since Vista, Windows-Explorer and Internet-Explorer are separate. > Previously it was possible to drive Windows-Explorer via COM. > Vista made that impossible. They have ALWAYS been separate. No shared code. The only thing they had in common was one word in the name. > IMO, you must seek another way that COM. Sorry. What leads you to say this? Do you have a reference? Windows Explorer in Vista has been substantially modified, but I have not read of any breaking changes in the shell interface. There are too many third-party tools that rely on it. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Tue Apr 22 19:19:31 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 22 Apr 2008 10:19:31 -0700 Subject: [python-win32] Finding the selected file in Windows Explorer In-Reply-To: <480DA6E1.6070003@inesc-id.pt> References: <480DA6E1.6070003@inesc-id.pt> Message-ID: <480E1E23.5070306@probo.com> Daniel Gon?alves wrote: > Hi! > > I need to find the selected file(s) in a Windows Explorer window from > another program (I'd look at the window that last had focus). I found > something in the following page that should do the trick: > > http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx > > However, it is not Python and, while I'm a competent Python > programmer, Win32, COM and the like are somewhat outside my > competences. WOW, that's fairly amazing. It takes 9 different COM interfaces to get this information. > Does any one know how to do something similar in Python (maybe in a > more Pythonic way?) Unfortunately, it's not a Pythonic task. It's a Windows task. I can give you some hints to get you started, but it's going to be a tedious task with lots of trial and error. import pywintypes import win32com.client CLSID_ShellWindows = pywintypes.IID( '{9ba05972-f6a8-11cf-a442-00a0c90a8f39}' ) o = win32com.client.Dispatch( CLSID_ShellWindows ) for i in range(o.Count): print o.Item(0).Name Now you have an IID_ShellWindows interface. You can use o.Count to find out how many windows there are, and o.Item(i) will return you each window in the collection one at a time. From there, you'll need to query the appropriate subinterfaces, and hope that they are all dispatch interfaces so they can be used from Python. I might be tempted to take the C++ code and make a simple extension DLL. Perhaps Mark or Tim Golden has some better hints. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mdriscoll at co.marshall.ia.us Tue Apr 22 19:41:56 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Tue, 22 Apr 2008 12:41:56 -0500 Subject: [python-win32] Drag and Drop issues Message-ID: <480E2364.90701@co.marshall.ia.us> Alex Denham wrote: > Hi, > > I'm trying to implement a drag and drop feature in my Tkinter based gui. > I want to be able to drag a file from windows (explorer/desktop etc) > into my program. Then i need my program to get the filepath for the > file that was dropped. > > I've tried to search all over the internet, in books and in the win32 > documentation provided with the win32 package but i keep finding > conflicting information. > > Furthest i have gotten is the following: > > _id = root.winfo_id() > win32gui.DragAcceptFiles(_id, 1) > > That works, without that i don't get the little 'drop' icon when i > drag something over, however after that i'm completly stuck, i've > tried using win32gui.GetMessage() to see if there is anything in that > output that relates to a drop, > I've tried win32api.DragQueryFile(_id). > > I think i need to do something using a PyIDropTarget but i have no > idea where to import that from, i've tried making a class with that as > the name and then initializing it and passing it to > pythoncom.RegisterDragDrop(_id, dropTarget) > dropTarget being the initialized PyIDropTarget class, however it says, > it's not a com object... > > I think i've just managed to get myself confused, i just need a > pointer on the right way to do it, do i use registerdrag drop or do i > use dragqueryfile and dragacceptfiles, and how to i check to see if my > program has recieved a drop request, is there some sort of event or > something i can listen for (thats initially what i thought > GetMessage() was for but i'm unsure how to use it) > > Any help would be much appreciated. > And if you need any more info don't hesitate to ask. > > Thanks in advance > Alex I did a quick Google search and found this: http://sourceforge.net/projects/tkdnd Alternatively, I know wxPython has DnD capabilities of sorts too, so if you can't get it in Tkinter, you might check it out there. By the way, did you try asking for help on the Tkinter mailing list? If not, you can find it here: http://mail.python.org/mailman/listinfo/tkinter-discuss Mike From cappy2112 at gmail.com Tue Apr 22 20:03:09 2008 From: cappy2112 at gmail.com (Tony Cappellini) Date: Tue, 22 Apr 2008 11:03:09 -0700 Subject: [python-win32] Size of directory Message-ID: <8249c4ac0804221103mfd184c6x9389b204b01cdca7@mail.gmail.com> When I right click on a directory with windows Explorer, a window is displayed showing Size: Size On Disk: Contains: Created: Attributes: (with the appropriate values for each entry) How do I get the same information via Python ? I've looked at os.stat but os.stat(r'C:\temp')[os.path.stat.ST_SIZE] only returns the size of a "plain file" :( It's really a shame that windows doesn't have a built-in tool to show you a tree of subdirectories, and how much space is occupied by each subdirectory. I guess I need to roll my own- once I know what the underlying call is to get the size of each directory -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry.bates at websafe.com Tue Apr 22 20:10:04 2008 From: larry.bates at websafe.com (Larry Bates) Date: Tue, 22 Apr 2008 13:10:04 -0500 Subject: [python-win32] Size of directory In-Reply-To: <8249c4ac0804221103mfd184c6x9389b204b01cdca7@mail.gmail.com> References: <8249c4ac0804221103mfd184c6x9389b204b01cdca7@mail.gmail.com> Message-ID: Tony Cappellini wrote: > > When I right click on a directory with windows Explorer, a window is > displayed showing > > Size: > Size On Disk: > Contains: > Created: > Attributes: > (with the appropriate values for each entry) > > > How do I get the same information via Python ? > > I've looked at os.stat but > > os.stat(r'C:\temp')[os.path.stat.ST_SIZE] > > only returns the size of a "plain file" :( > > > It's really a shame that windows doesn't have a built-in tool to show > you a tree of subdirectories, and how much space is occupied by each > subdirectory. > > I guess I need to roll my own- once I know what the underlying call is > to get the size of each directory > > > ------------------------------------------------------------------------ > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 You have to walk the directory and accumulate the size. Even Explorer does that (you can see if you do it on a really large directory). -Larry From rdahlstrom at directedge.com Tue Apr 22 20:20:41 2008 From: rdahlstrom at directedge.com (Dahlstrom, Roger) Date: Tue, 22 Apr 2008 14:20:41 -0400 Subject: [python-win32] Size of directory In-Reply-To: <8249c4ac0804221103mfd184c6x9389b204b01cdca7@mail.gmail.com> References: <8249c4ac0804221103mfd184c6x9389b204b01cdca7@mail.gmail.com> Message-ID: <68D737040F1D204CA68A38C372141F44CF0EF2@jc1wsmail3.global.knight.com> You have to walk the directory tree and sum each file's size. Windows does this too - try your right-click properties on a large directory and see how long it takes. That's also what du does. There are, however, some recipes that should make this fairly simple for you - try this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86554 ________________________________ From: python-win32-bounces+rdahlstrom=directedge.com at python.org [mailto:python-win32-bounces+rdahlstrom=directedge.com at python.org] On Behalf Of Tony Cappellini Sent: Tuesday, April 22, 2008 2:03 PM To: python-win32 at python.org Subject: [python-win32] Size of directory When I right click on a directory with windows Explorer, a window is displayed showing Size: Size On Disk: Contains: Created: Attributes: (with the appropriate values for each entry) How do I get the same information via Python ? I've looked at os.stat but os.stat(r'C:\temp')[os.path.stat.ST_SIZE] only returns the size of a "plain file" :( It's really a shame that windows doesn't have a built-in tool to show you a tree of subdirectories, and how much space is occupied by each subdirectory. I guess I need to roll my own- once I know what the underlying call is to get the size of each directory DISCLAIMER: This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof. E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. NOTICE REGARDING PRIVACY AND CONFIDENTIALITY Direct Edge ECN LLC may, at its discretion, monitor and review the content of all e-mail communications. www.directedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry.bates at websafe.com Tue Apr 22 21:19:50 2008 From: larry.bates at websafe.com (Larry Bates) Date: Tue, 22 Apr 2008 14:19:50 -0500 Subject: [python-win32] Finding the selected file in Windows Explorer In-Reply-To: <480E0CE6.5060901@inesc-id.pt> References: <480DA6E1.6070003@inesc-id.pt> <480E0CE6.5060901@inesc-id.pt> Message-ID: Daniel Gon?alves wrote: > Larry Bates wrote: >> Daniel Gon?alves wrote: >>> Hi! >>> >>> I need to find the selected file(s) in a Windows Explorer window from >>> another program (I'd look at the window that last had focus). > > > >> Daniel, >> >> What do you mean by "find the selected files". Give us a little more >> detail about your use case and we can help. >> > > Hi! > > > What I'm trying to do is to have a program that detects whenever some > file(s) are dragged over an area of the screen. Not dropped there, but > dragged over it (close to the screen border, for instance). AFAIK, > Windows only generates events whenever something is dropped, which will > be useless here. > > I will be using hooks to monitor mouse events and, when the mouse is > over the defined region, I need to find out what is being dragged. A way > to do estimate this might be to know that the currently focused window > is an Explorer window, and query it for the selected items (they will be > the ones being dragged). This is only an approximation but might be > enough for my ends, if no better way is found. > > Of course, if there is a way of just asking the OS "what is being > dragged right now", that would work even better :) > > > > Tks! > Daniel > > > >> One way of knowing about files that are selected is this: >> >> If you selected several files and drag and drop them on a python >> program the files that are selected will be passed into the program in >> sys.argv. I don't know if that is what you are looking for or not. >> >> -Larry >> >> _______________________________________________ >> python-win32 mailing list >> python-win32 at python.org >> http://mail.python.org/mailman/listinfo/python-win32 >> The reason for this is that a user can "changed their mind" before the drop. I sometimes do that and press escape to cancel the operation. wxWindows has some several functions that occur while the dragging is taking place and I "think" you can actually tell what is being dragged during the process. -Larry From Brad.Johnson at ballardtech.com Tue Apr 22 21:46:38 2008 From: Brad.Johnson at ballardtech.com (Brad Johnson) Date: Tue, 22 Apr 2008 19:46:38 +0000 (UTC) Subject: [python-win32] Creating an MSI of pywin32 Message-ID: Hello everyone, I am attempting to create an MSI of pywin32 so I can have it silently install with another application. I am running into this error and traceback when executing "python setup.py bdist_msi" running install_egg_info Writing build\bdist.win32\msi\Lib\site-packages\pywin32-210-py2.5.egg-info Traceback (most recent call last): File "setup.py", line 1546, in ('', ('pywin32.pth',)), File "C:\PYTHON25\lib\distutils\core.py", line 151, in setup dist.run_commands() File "C:\PYTHON25\lib\distutils\dist.py", line 974, in run_commands self.run_command(cmd) File "C:\PYTHON25\lib\distutils\dist.py", line 994, in run_command cmd_obj.run() File "C:\PYTHON25\lib\distutils\command\bdist_msi.py", line 215, in run sversion = "%d.%d.%d" % StrictVersion(version).version File "C:\PYTHON25\lib\distutils\version.py", line 40, in __init__ self.parse(vstring) File "C:\PYTHON25\lib\distutils\version.py", line 107, in parse raise ValueError, "invalid version number '%s'" % vstring ValueError: invalid version number '210' Any thoughts? Creating a windows installer via "python setup.py bdist_wininst" works fine. From Brad.Johnson at ballardtech.com Tue Apr 22 21:47:57 2008 From: Brad.Johnson at ballardtech.com (Brad Johnson) Date: Tue, 22 Apr 2008 19:47:57 +0000 (UTC) Subject: [python-win32] holiday References: <02b001c89b5d$56891f70$039b5e50$@com.au> Message-ID: Mark Hammond skippinet.com.au> writes: > > Hi all, > FYI, I'm off on a 2 week vacation to China (wheeee!) > Hope it is an enjoyable break for you, you deserve it :-) From Brad.Johnson at ballardtech.com Tue Apr 22 22:15:34 2008 From: Brad.Johnson at ballardtech.com (Brad Johnson) Date: Tue, 22 Apr 2008 20:15:34 +0000 (UTC) Subject: [python-win32] Creating an MSI of pywin32 References: Message-ID: Brad Johnson ballardtech.com> writes: Note, I can fix this by hard coding a valid version in \distutils\command\bdist_msi.py by changing sversion = "%d.%d.%d" % StrictVersion(version).version to sversion = "210" (where 210 is the build number) But, obviously this just side-steps the problem. From a1eio at hotmail.com Wed Apr 23 13:17:54 2008 From: a1eio at hotmail.com (Alex Denham) Date: Wed, 23 Apr 2008 12:17:54 +0100 Subject: [python-win32] Creating python com objects Message-ID: Hi, Anybody happen to know how to go about creating a COM object that RegisterDragDrop() will actually accept? print dropTarget pythoncom.RegisterDragDrop(_id, dropTarget) Traceback (most recent call last): File "C:\Python25\DragAndDrop.py", line 82, in main() File "C:\Python25\DragAndDrop.py", line 41, in main pythoncom.RegisterDragDrop(_id, dropTarget) ValueError: argument is not a COM object Any help appreciated, Thanks Alex _________________________________________________________________ Search and win with BigSnapSearch.com http://www.bigsnapsearch.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdahlstrom at directedge.com Wed Apr 23 13:33:16 2008 From: rdahlstrom at directedge.com (Dahlstrom, Roger) Date: Wed, 23 Apr 2008 07:33:16 -0400 Subject: [python-win32] Creating python com objects In-Reply-To: References: Message-ID: <68D737040F1D204CA68A38C372141F44CF0EF9@jc1wsmail3.global.knight.com> I might be greatly misinterpreting what you're trying to do here, but RegisterDragDrop registers a window, not a com object. The drop target instance would be associating the target with that particular window. Have you checked out wxDropTarget? ________________________________ From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Alex Denham Sent: Wednesday, April 23, 2008 7:18 AM To: python-win32 Subject: [python-win32] Creating python com objects Hi, Anybody happen to know how to go about creating a COM object that RegisterDragDrop() will actually accept? print dropTarget pythoncom.RegisterDragDrop(_id, dropTarget) Traceback (most recent call last): File "C:\Python25\DragAndDrop.py", line 82, in main() File "C:\Python25\DragAndDrop.py", line 41, in main pythoncom.RegisterDragDrop(_id, dropTarget) ValueError: argument is not a COM object Any help appreciated, Thanks Alex ________________________________ Miss your Messenger buddies when on-the-go? Get Messenger on your mobile! DISCLAIMER: This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof. E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. NOTICE REGARDING PRIVACY AND CONFIDENTIALITY Direct Edge ECN LLC may, at its discretion, monitor and review the content of all e-mail communications. www.directedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From a1eio at hotmail.com Wed Apr 23 13:45:09 2008 From: a1eio at hotmail.com (Alex Denham) Date: Wed, 23 Apr 2008 12:45:09 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: <68D737040F1D204CA68A38C372141F44CF0EF9@jc1wsmail3.global.knight.com> References: <68D737040F1D204CA68A38C372141F44CF0EF9@jc1wsmail3.global.knight.com> Message-ID: I haven't checked anything from wxWidgets and i don't intend to (yet). I have found many functions that appear to help with dragging and dropping in Windows, but practically no documentation to go with. Piecing bits together from google, msdn, PyWin32 documentation, Python Programming on Win32, has just left me confused and unsure about which is the wright way. RegisterDragDrop, aparently (from my understanding) registers a window to allow dragging and dropping, first argument is a window id, the second argument is a 'dropTarget' The documentation i have found follows: (note how helpful it is) RegisterDragDrop(hwnd, dropTarget) Registers the specified window as one that can be the target of an OLE drag-and-drop operation and specifies the PyIDropTarget instance to use for drop operations. Parameters hwnd : long dropTarget : PyIDropTarget documentation for PyIDropTarget: there is none. I'm trying to create this 'dropTarget' and pass it to the RegisterDragDrop function however, i can't do that, because it seems to want a COM object, and my attempts at making a com object don't seem to be good enough for RegisterDragDrop. Thanks Alex From: rdahlstrom at directedge.com Date: Wed, 23 Apr 2008 07:33:16 -0400 To: python-win32 at python.org Subject: Re: [python-win32] Creating python com objects I might be greatly misinterpreting what you're trying to do here, but RegisterDragDrop registers a window, not a com object. The drop target instance would be associating the target with that particular window. Have you checked out wxDropTarget? From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Alex Denham Sent: Wednesday, April 23, 2008 7:18 AM To: python-win32 Subject: [python-win32] Creating python com objects Hi, Anybody happen to know how to go about creating a COM object that RegisterDragDrop() will actually accept? print dropTarget pythoncom.RegisterDragDrop(_id, dropTarget) Traceback (most recent call last): File "C:\Python25\DragAndDrop.py", line 82, in main() File "C:\Python25\DragAndDrop.py", line 41, in main pythoncom.RegisterDragDrop(_id, dropTarget) ValueError: argument is not a COM object Any help appreciated, Thanks Alex Miss your Messenger buddies when on-the-go? Get Messenger on your mobile! DISCLAIMER: This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof. E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission.NOTICE REGARDING PRIVACY AND CONFIDENTIALITY Direct Edge ECN LLC may, at its discretion, monitor and review the content of all e-mail communications.www.directedge.com _________________________________________________________________ Bag extra points with the Walkers Brit Trip Game http://www.walkersbrittrips.co.uk/game -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwupole at msn.com Thu Apr 24 03:15:56 2008 From: rwupole at msn.com (Roger Upole) Date: Wed, 23 Apr 2008 21:15:56 -0400 Subject: [python-win32] Creating python com objects Message-ID: Alex Denham wrote: > Hi, > Anybody happen to know how to go about creating a COM object that > RegisterDragDrop() will actually accept? > > print dropTarget > > > pythoncom.RegisterDragDrop(_id, dropTarget) > > Traceback (most recent call last): > File "C:\Python25\DragAndDrop.py", line 82, in > main() > File "C:\Python25\DragAndDrop.py", line 41, in main > pythoncom.RegisterDragDrop(_id, dropTarget) > ValueError: argument is not a COM object > > Any help appreciated, > > Thanks > Alex How was your dropTarget object created ? Normally, you'd create a class that implements the methods of IDropTarget and either register it or wrap it for local use using pythoncom.WrapObject. It does look like PyIDropTarget is lacking docs, I'll try to improve them. Also, the other interface you'll probably need (PyIDataObject) needs some attention in the docs. Roger From a1eio at hotmail.com Thu Apr 24 11:28:11 2008 From: a1eio at hotmail.com (Alex Denham) Date: Thu, 24 Apr 2008 10:28:11 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: References: Message-ID: class PyIDropTarget: _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] _reg_progid_ = "Python.PyIDropTarget" _reg_clsid_ = '{00000122-0000-0000-C000-000000000046}' def DragEnter(self, args=None): print 'DragEnter: ', args def DragOver(self, args=None): print 'DragOver: ', args def DragLeave(self, args=None): print 'DragLeave: ', args def Drop(self, args=None): print 'Drop: ', args Then i just used the com register thing to register it, then i tried dropTarget = win32com.client.Dispatch("Python.PyIDropTarget") I didn't know about the pythoncomWrapObject however. > From: rwupole at msn.com > To: python-win32 at python.org > Date: Wed, 23 Apr 2008 21:15:56 -0400 > Subject: [python-win32] Creating python com objects > > Alex Denham wrote: > > Hi, > > > Anybody happen to know how to go about creating a COM object that > > RegisterDragDrop() will actually accept? > > > > print dropTarget > > > > > > pythoncom.RegisterDragDrop(_id, dropTarget) > > > > Traceback (most recent call last): > > File "C:\Python25\DragAndDrop.py", line 82, in > > main() > > File "C:\Python25\DragAndDrop.py", line 41, in main > > pythoncom.RegisterDragDrop(_id, dropTarget) > > ValueError: argument is not a COM object > > > > Any help appreciated, > > > > Thanks > > Alex > > How was your dropTarget object created ? > Normally, you'd create a class that implements the > methods of IDropTarget and either register it or > wrap it for local use using pythoncom.WrapObject. > > It does look like PyIDropTarget is lacking docs, I'll > try to improve them. Also, the other interface you'll > probably need (PyIDataObject) needs some > attention in the docs. > > Roger > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Bag extra points with the Walkers Brit Trip Game http://www.walkersbrittrips.co.uk/game -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwupole at msn.com Thu Apr 24 12:52:30 2008 From: rwupole at msn.com (Roger Upole) Date: Thu, 24 Apr 2008 06:52:30 -0400 Subject: [python-win32] Creating python com objects Message-ID: Alex Denham wrote: class PyIDropTarget: _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] _reg_progid_ = "Python.PyIDropTarget" _reg_clsid_ = '{00000122-0000-0000-C000-000000000046}' def DragEnter(self, args=None): print 'DragEnter: ', args def DragOver(self, args=None): print 'DragOver: ', args def DragLeave(self, args=None): print 'DragLeave: ', args def Drop(self, args=None): print 'Drop: ', args Your class also needs to specify the IID of the interface it implements, eg _com_interfaces_=[pythoncom.IID_IDropTarget] Also, the _reg_clsid_ should be a unique GUID that you generate yourself to identify your own implementation of IDropTarget, rather than the system GUID for IDropTarget. Roger From a1eio at hotmail.com Thu Apr 24 13:03:33 2008 From: a1eio at hotmail.com (Alex Denham) Date: Thu, 24 Apr 2008 12:03:33 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: References: Message-ID: ah thanks very much, initially i had a unique GUID however i got giddy and excited when i found 'PyIDropTarget' in one of the modules, unfortunatly it was just an id (i thought it was an object) I'm working my way through python programming on win32, do you know of any other material i can work through? because i'm just lacking when it comes to this. A good example being, i had no idea i had to specify the IID interface! Thanks for your help so far, much appreciated. Alex > From: rwupole at msn.com > To: python-win32 at python.org > Date: Thu, 24 Apr 2008 06:52:30 -0400 > Subject: [python-win32] Creating python com objects > > Alex Denham wrote: > > class PyIDropTarget: > _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] > _reg_progid_ = "Python.PyIDropTarget" > _reg_clsid_ = '{00000122-0000-0000-C000-000000000046}' > def DragEnter(self, args=None): > print 'DragEnter: ', args > def DragOver(self, args=None): > print 'DragOver: ', args > def DragLeave(self, args=None): > print 'DragLeave: ', args > def Drop(self, args=None): > print 'Drop: ', args > > Your class also needs to specify the IID of the interface it > implements, eg > _com_interfaces_=[pythoncom.IID_IDropTarget] > > Also, the _reg_clsid_ should be a unique GUID that you > generate yourself to identify your own implementation of > IDropTarget, rather than the system GUID for IDropTarget. > > Roger > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Search and win with BigSnapSearch.com http://www.bigsnapsearch.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Thu Apr 24 13:11:12 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Apr 2008 12:11:12 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: References: Message-ID: <48106AD0.6090806@timgolden.me.uk> Alex Denham wrote: > class PyIDropTarget: > _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] > _reg_progid_ = "Python.PyIDropTarget" > _reg_clsid_ = '{00000122-0000-0000-C000-000000000046}' > def DragEnter(self, args=None): > print 'DragEnter: ', args > def DragOver(self, args=None): > print 'DragOver: ', args > def DragLeave(self, args=None): > print 'DragLeave: ', args > def Drop(self, args=None): > print 'Drop: ', args > > Then i just used the com register thing to register it, then i tried > dropTarget = win32com.client.Dispatch("Python.PyIDropTarget") > I didn't know about the pythoncomWrapObject however. You can't call Dispatch on this object because it's not implementing IDispatch. I think you'll need something like this (untested): import pythoncom CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}' # Generated by pythoncom.CreateGuid PROGID = "Tim.DropTarget" DESC = "Drop target handler for Tim's app" class DropTarget: _reg_clsid_ = CLSID _reg_progid_ = PROGID _reg_desc_ = DESC _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] _com_interfaces_ = [pythoncom.IID_IDropTarget] def DragEnter(self, args=None): print 'DragEnter: ', args def DragOver(self, args=None): print 'DragOver: ', args def DragLeave(self, args=None): print 'DragLeave: ', args def Drop(self, args=None): print 'Drop: ', args drop_target = pythoncom.WrapObject ( DropTarget, pythoncom.IID_IDropTarget ) #pythoncom.RegisterDragDrop (hWnd, drop_target) From a1eio at hotmail.com Thu Apr 24 14:04:08 2008 From: a1eio at hotmail.com (Alex Denham) Date: Thu, 24 Apr 2008 13:04:08 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: <48106AD0.6090806@timgolden.me.uk> References: <48106AD0.6090806@timgolden.me.uk> Message-ID: Thanks Tim, the program actually reacts when something is dragged over (much better than before). However i'm receiving an error everytime. >>> pythoncom error: Unexpected exception in gateway method 'DragEnter' : DragEnterpythoncom error: Unexpected gateway error Also, in the documentation it says: Drop(pDataObj, pt, dwEffect) Parameters pDataObj : PyIDataObject * How do i link the IDataObject to the IDragTarget? Thanks Alex > Date: Thu, 24 Apr 2008 12:11:12 +0100> From: mail at timgolden.me.uk> CC: python-win32 at python.org> Subject: Re: [python-win32] Creating python com objects> > Alex Denham wrote:> > class PyIDropTarget:> > _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop']> > _reg_progid_ = "Python.PyIDropTarget"> > _reg_clsid_ = '{00000122-0000-0000-C000-000000000046}'> > def DragEnter(self, args=None):> > print 'DragEnter: ', args> > def DragOver(self, args=None):> > print 'DragOver: ', args> > def DragLeave(self, args=None):> > print 'DragLeave: ', args> > def Drop(self, args=None):> > print 'Drop: ', args> > > > Then i just used the com register thing to register it, then i tried > > dropTarget = win32com.client.Dispatch("Python.PyIDropTarget")> > I didn't know about the pythoncomWrapObject however.> > You can't call Dispatch on this object because it's not> implementing IDispatch. I think you'll need something like> this (untested):> > > import pythoncom> > CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}'> # Generated by pythoncom.CreateGuid> PROGID = "Tim.DropTarget"> DESC = "Drop target handler for Tim's app"> > class DropTarget:> _reg_clsid_ = CLSID> _reg_progid_ = PROGID> _reg_desc_ = DESC> _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop']> _com_interfaces_ = [pythoncom.IID_IDropTarget]> > def DragEnter(self, args=None):> print 'DragEnter: ', args> def DragOver(self, args=None):> print 'DragOver: ', args> def DragLeave(self, args=None):> print 'DragLeave: ', args> def Drop(self, args=None):> print 'Drop: ', args> > drop_target = pythoncom.WrapObject (> DropTarget, pythoncom.IID_IDropTarget> )> > #pythoncom.RegisterDragDrop (hWnd, drop_target)> > > _______________________________________________> python-win32 mailing list> python-win32 at python.org> http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Search and win with BigSnapSearch.com http://www.bigsnapsearch.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From Dominique.Holzwarth at ch.delarue.com Thu Apr 24 17:15:17 2008 From: Dominique.Holzwarth at ch.delarue.com (Dominique.Holzwarth at ch.delarue.com) Date: Thu, 24 Apr 2008 16:15:17 +0100 Subject: [python-win32] Apache & mod_python & win32com Message-ID: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com> Hello everyone I'm developing a web application using mod_python and the apache web server. That application has to handle xml files and for that I'm using win32com with with MSXML. My problem is, that apache spawns a new process / thread (not sure wether ist a process or thread. I think it's a thread) per http request. So when multiple users generated requests "at the same time" (new request before the first one is returned) I have multiple threads running. And that's where my win32com code is crashing... Currently, for every request my code does the following (as an example): return win32com.client.Dispatch("Msxml2.DOMDocument.6.0") To get an empty MSXSML DOM object. For multiple requests at the same time I get the following error: File "C:\Program Files\Apache Software Foundation\Apache2.2\TCRExceptionManagerData\database_library\database.py", line 24, in __init__ self.__configFileSchema = self.__XSDSchemaCache() File "C:\Program Files\Apache Software Foundation\Apache2.2\TCRExceptionManagerData\database_library\database.py", line 1774, in __XSDSchemaCache return win32com.client.Dispatch("MSXML2.XMLSchemaCache.6.0") File "C:\Program Files\Python25\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Program Files\Python25\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Program Files\Python25\lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221008, 'CoInitialize has not been called.', None, None) I've read already a bit in this mailing list and someone mentioned that one need to call pythoncom.CoInitialize() and pythoncom.CoUninitialize(). But I don't know where exactly i should call those functions and wether that'll solve my problem... Also, when I do a 'import win32com.pythoncom' I get an error that the module 'pythoncom' does not exist! I would be really happy if someone could help me and tell me how to make my win32com work for multiple threads! Greetings Dominique From a1eio at hotmail.com Thu Apr 24 17:28:01 2008 From: a1eio at hotmail.com (Alex Denham) Date: Thu, 24 Apr 2008 16:28:01 +0100 Subject: [python-win32] Apache & mod_python & win32com In-Reply-To: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com> References: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com> Message-ID: Hi, first of all, just import pythoncom directly import pythoncom As far as where to put pythoncom.CoInitialize() I'm not certain but i think at the top (or start) of your whole application.. if it's threaded then call it for each thread (at the start) "Initializes the COM library on the current thread and identifies the concurrency model as single-thread apartment (STA). Applications must initialize the COM library before they can call COM library functions ..." from: http://msdn2.microsoft.com/en-us/library/ms678543(VS.85).aspx Hope that helps, Alex > From: Dominique.Holzwarth at ch.delarue.com > To: python-win32 at python.org > Date: Thu, 24 Apr 2008 16:15:17 +0100 > Subject: [python-win32] Apache & mod_python & win32com > > Hello everyone > > I'm developing a web application using mod_python and the apache web server. That application has to handle xml files and for that I'm using win32com with with MSXML. > > My problem is, that apache spawns a new process / thread (not sure wether ist a process or thread. I think it's a thread) per http request. So when multiple users generated requests "at the same time" (new request before the first one is returned) I have multiple threads running. And that's where my win32com code is crashing... > > Currently, for every request my code does the following (as an example): > > return win32com.client.Dispatch("Msxml2.DOMDocument.6.0") > > To get an empty MSXSML DOM object. > > For multiple requests at the same time I get the following error: > > File "C:\Program Files\Apache Software Foundation\Apache2.2\TCRExceptionManagerData\database_library\database.py", line 24, in __init__ > self.__configFileSchema = self.__XSDSchemaCache() > > File "C:\Program Files\Apache Software Foundation\Apache2.2\TCRExceptionManagerData\database_library\database.py", line 1774, in __XSDSchemaCache > return win32com.client.Dispatch("MSXML2.XMLSchemaCache.6.0") > > File "C:\Program Files\Python25\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch > dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > > File "C:\Program Files\Python25\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName > return (_GetGoodDispatch(IDispatch, clsctx), userName) > > File "C:\Program Files\Python25\lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) > > com_error: (-2147221008, 'CoInitialize has not been called.', None, None) > > I've read already a bit in this mailing list and someone mentioned that one need to call pythoncom.CoInitialize() and pythoncom.CoUninitialize(). But I don't know where exactly i should call those functions and wether that'll solve my problem... Also, when I do a 'import win32com.pythoncom' I get an error that the module 'pythoncom' does not exist! > > I would be really happy if someone could help me and tell me how to make my win32com work for multiple threads! > > Greetings > Dominique > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Play the Andrex Hello Softie Game & win great prizes http://www.thehellosoftiegame.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From fumanchu at aminus.org Thu Apr 24 17:57:17 2008 From: fumanchu at aminus.org (Robert Brewer) Date: Thu, 24 Apr 2008 08:57:17 -0700 Subject: [python-win32] Apache & mod_python & win32com In-Reply-To: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com> References: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com> Message-ID: Dominique.Holzwarth at ch.delarue.com wrote: > I'm developing a web application using mod_python and the apache web > server. That application has to handle xml files and for that I'm using > win32com with with MSXML. > > My problem is, that apache spawns a new process / thread (not sure > wether ist a process or thread. I think it's a thread) On Windows, almost certainly a thread. Apache on Windows uses the "winnt" MPM, which is multithreaded, not multiprocess. > per http > request. So when multiple users generated requests "at the same time" > (new request before the first one is returned) I have multiple threads > running. And that's where my win32com code is crashing... > > Currently, for every request my code does the following (as an > example): > > return win32com.client.Dispatch("Msxml2.DOMDocument.6.0") > > To get an empty MSXSML DOM object. > > For multiple requests at the same time I get the following error: > > File "C:\Program Files\Apache Software > Foundation\Apache2.2\TCRExceptionManagerData\database_library\database. > py", line 24, in __init__ > self.__configFileSchema = self.__XSDSchemaCache() > > File "C:\Program Files\Apache Software > Foundation\Apache2.2\TCRExceptionManagerData\database_library\database. > py", line 1774, in __XSDSchemaCache > return win32com.client.Dispatch("MSXML2.XMLSchemaCache.6.0") > > File "C:\Program Files\Python25\lib\site- > packages\win32com\client\__init__.py", line 95, in Dispatch > dispatch, userName = > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > > File "C:\Program Files\Python25\lib\site- > packages\win32com\client\dynamic.py", line 98, in > _GetGoodDispatchAndUserName > return (_GetGoodDispatch(IDispatch, clsctx), userName) > > File "C:\Program Files\Python25\lib\site- > packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > > com_error: (-2147221008, 'CoInitialize has not been called.', None, > None) > > I've read already a bit in this mailing list and someone mentioned that > one need to call pythoncom.CoInitialize() and > pythoncom.CoUninitialize(). But I don't know where exactly i should > call those functions and wether that'll solve my problem... Also, when > I do a 'import win32com.pythoncom' I get an error that the module > 'pythoncom' does not exist! > > I would be really happy if someone could help me and tell me how to > make my win32com work for multiple threads! As Alex mentioned, you need to call CoInitialize for each thread. Unfortunately, since Apache is creating the threads for you, you don't have a hook for events to run on thread startup. Instead, you have to watch threads as they go by and call CoInitialize ASAP. Best to do so with a try/finally in case something goes wrong: def handler(req): CoInitialize() try: process(req) return apache.OK finally: CoUninitialize() If for various reasons that can't be made to work (some components just aren't thread safe), another option would be to run all the COM calls in a single thread and use a Queue; request threads would call q.put(xml, reqid) and block, the COM thread would call q.get(), do the work, and shove the result into results[reqid]. Robert Brewer fumanchu at aminus.org From mdriscoll at co.marshall.ia.us Thu Apr 24 17:56:57 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Thu, 24 Apr 2008 10:56:57 -0500 Subject: [python-win32] Apache & mod_python & win32com In-Reply-To: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com> References: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com> Message-ID: <4810ADC9.9080201@co.marshall.ia.us> Dominique.Holzwarth at ch.delarue.com wrote: > Hello everyone > > I'm developing a web application using mod_python and the apache web server. That application has to handle xml files and for that I'm using win32com with with MSXML. > > My problem is, that apache spawns a new process / thread (not sure wether ist a process or thread. I think it's a thread) per http request. So when multiple users generated requests "at the same time" (new request before the first one is returned) I have multiple threads running. And that's where my win32com code is crashing... > > Currently, for every request my code does the following (as an example): > > return win32com.client.Dispatch("Msxml2.DOMDocument.6.0") > > To get an empty MSXSML DOM object. > > For multiple requests at the same time I get the following error: > > File "C:\Program Files\Apache Software Foundation\Apache2.2\TCRExceptionManagerData\database_library\database.py", line 24, in __init__ > self.__configFileSchema =elf.__XSDSchemaCache() > > File "C:\Program Files\Apache Software Foundation\Apache2.2\TCRExceptionManagerData\database_library\database.py", line 1774, in __XSDSchemaCache > return win32com.client.Dispatch("MSXML2.XMLSchemaCache.6.0") > > File "C:\Program Files\Python25\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch > dispatch, userName =ynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > > File "C:\Program Files\Python25\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName > return (_GetGoodDispatch(IDispatch, clsctx), userName) > > File "C:\Program Files\Python25\lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch > IDispatch =ythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) > > com_error: (-2147221008, 'CoInitialize has not been called.', None, None) > > I've read already a bit in this mailing list and someone mentioned that one need to call pythoncom.CoInitialize() and pythoncom.CoUninitialize(). But I don't know where exactly i should call those functions and wether that'll solve my problem... Also, when I do a 'import win32com.pythoncom' I get an error that the module 'pythoncom' does not exist! > > I would be really happy if someone could help me and tell me how to make my win32com work for multiple threads! > > Greetings > Dominique > > > I had this issue when I was using WMI in a thread. I basically just ended up calling CoInitialize() before I called my WMI object (or function) and then CoUninitialize() when the object/function returned. However, if you're messing with XML, I would recommend one of the many excellent XML parsing libraries in Python. I've used the included DOM interface as well as lxml, which is more object-oriented. I've even used pyparsing in one of my scripts...it's pretty new, but the developer for it is very responsive and has good examples and even a small e-book on it. Just some ideas... Mike From fumanchu at aminus.org Thu Apr 24 21:31:14 2008 From: fumanchu at aminus.org (Robert Brewer) Date: Thu, 24 Apr 2008 12:31:14 -0700 Subject: [python-win32] Apache & mod_python & win32com In-Reply-To: <5213E58D85BC414998FA553C701E386C0EDD07FF06@SGBD012511.dlrmail.ad.delarue.com> References: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com>, <5213E58D85BC414998FA553C701E386C0EDD07FF06@SGBD012511.dlrmail.ad.delarue.com> Message-ID: Dominique.Holzwarth at ch.delarue.com wrote: > Thank you Rober & Alex for the answers :-) > But I must admit that I'm still bit uncertain about that whole issue. > As I understood apache it is creating a thread for every request > anyway, or not? (and yes, on windows the MPM winnt is used) As I understand it, Apache creates a pool of threads and re-uses them. From http://httpd.apache.org/docs/2.2/mod/mpm_common.html#threadsperchild: "This directive sets the number of threads created by each child process. The child creates these threads at startup and never creates more." > so wouldn't it be enough to just call CoInitialized() at the start of > my (mod_python) python-handler and CoUnitialize() and the end of my > handler? the try... finally you have added only for the case my script > would "crash", right? so that the CoUnitialize() is called in that case > as well? Yes, exactly. > The idea about the single thread and queue I don't really get to be > honest... what sort of object would be passed in the queue? And how > would I create that queue and the thread? Don't worry about it for now if the try/finally approach works. Ask again if you need to. > I guess you thinking of some > standard python modules (as there's probably a python module for > everything =))? :) Yup, there is a Queue module: http://docs.python.org/lib/module-Queue.html. Robert Brewer fumanchu at aminus.org From mail at timgolden.me.uk Thu Apr 24 21:28:42 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 24 Apr 2008 20:28:42 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: References: <48106AD0.6090806@timgolden.me.uk> Message-ID: <4810DF6A.8080402@timgolden.me.uk> Alex Denham wrote: > > Thanks Tim, the program actually reacts when something is dragged over > (much better than before). > However i'm receiving an error everytime. > > >>> > pythoncom error: Unexpected exception in gateway method 'DragEnter' > : DragEnter > pythoncom error: Unexpected gateway error I've finally got round to producing a test harness to recreate this situation. (I've never actually used this functionality before, I'm afraid). And I get the same error. I've looked at the source code in PyIDropTarget.cpp, but I'm afraid I haven't the energy to plough through the gateway code at the moment trying to find out what's calling what calling what. One thing to correct from my earlier code is that the WrapObject function should specify the IID_IDropTarget interface twice, otherwise you end up with an IDispatch. But that's not the real problem. The "Unexpected exception" seems to mean that something's happened internally to the gateway logic which caused this, and the AttributeError suggests that it's failing to find the DragEnter method. But I can't see whether that's a flaw in my technique for building up the COM object, or a flaw in the gateway code for discerning its attributes. > Also, in the documentation it says: > > *Drop(/pDataObj//, pt//, dwEffect/*) > > > Parameters > > /pDataObj/ : *PyIDataObject ** > > How do i link the IDataObject to the IDragTarget? I don't know that you can, if you're asking: how do I find out where this is coming from?. I think the drag-drop technique is endpoint-agnostic. (A high-sounding phrase I've just invented). The most you can do is get hold of the data. Again, I think. I'm out of my depth so I'm hoping that Roger or Mark or other more knowledgeable people can chip in at this point and help. For the purposes of discussion, I attach below my test harness code which creates a simple window and registers a simple IDropTarget object against it. Sorry to be no more help than this. TJG import os, sys import win32gui import win32con import pythoncom CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}' PROGID = "Tim.DropTarget" DESC = "Drop target handler for Tim's app" class DropTarget: _reg_clsid_ = CLSID _reg_progid_ = PROGID _reg_desc_ = DESC _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] _com_interfaces_ = [pythoncom.IID_IDropTarget] def DragEnter (self, data_object, key_state, point, effect): pass def DragOver (self, key_state, point, effect): pass def DragLeave (self): pass def Drop (self, data_object, key_state, point, effect): pass def create_window (): def OnDestroy (hwnd, msg, wparam, lparam): win32gui.PostQuitMessage (0) wc = win32gui.WNDCLASS () hinst = win32gui.GetModuleHandle(None) wc.lpszClassName = "DragDrop" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; wc.hCursor = win32gui.LoadCursor (0, win32con.IDC_ARROW) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = {win32con.WM_DESTROY : OnDestroy} classAtom = win32gui.RegisterClass (wc) style = win32con.WS_VISIBLE | \ win32con.WS_OVERLAPPED | win32con.WS_SYSMENU return win32gui.CreateWindow ( classAtom, "Drag & Drop demo", style, 0, 0, 100, 100, 0, 0, hinst, None ) if __name__ == '__main__': pythoncom.OleInitialize () drop_target = pythoncom.WrapObject ( DropTarget, pythoncom.IID_IDropTarget, pythoncom.IID_IDropTarget ) pythoncom.RegisterDragDrop (create_window (), drop_target) win32gui.PumpMessages () From a1eio at hotmail.com Thu Apr 24 22:14:20 2008 From: a1eio at hotmail.com (Alex Denham) Date: Thu, 24 Apr 2008 21:14:20 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: <4810DF6A.8080402@timgolden.me.uk> References: <48106AD0.6090806@timgolden.me.uk> <4810DF6A.8080402@timgolden.me.uk> Message-ID: No problems, thanks for your help so far and the code below. The lack of drag and drop isn't stopping my program from working, it's just a feature i would really like to implement. I'll wait for some more help and in the meantime learn more about the win32 modules and windows programming in general. Thanks Tim, and everyone else on the mailing list. Alex > Date: Thu, 24 Apr 2008 20:28:42 +0100 > From: mail at timgolden.me.uk > CC: python-win32 at python.org > Subject: Re: [python-win32] Creating python com objects > > Alex Denham wrote: > > > > Thanks Tim, the program actually reacts when something is dragged over > > (much better than before). > > However i'm receiving an error everytime. > > > > >>> > > pythoncom error: Unexpected exception in gateway method 'DragEnter' > > : DragEnter > > pythoncom error: Unexpected gateway error > > I've finally got round to producing a test harness to > recreate this situation. (I've never actually used > this functionality before, I'm afraid). And I get the > same error. I've looked at the source code in PyIDropTarget.cpp, > but I'm afraid I haven't the energy to plough through the > gateway code at the moment trying to find out what's > calling what calling what. > > One thing to correct from my earlier code is that the > WrapObject function should specify the IID_IDropTarget > interface twice, otherwise you end up with an IDispatch. > But that's not the real problem. The "Unexpected exception" > seems to mean that something's happened internally to the > gateway logic which caused this, and the AttributeError > suggests that it's failing to find the DragEnter method. > But I can't see whether that's a flaw in my technique for > building up the COM object, or a flaw in the gateway code > for discerning its attributes. > > > Also, in the documentation it says: > > > > *Drop(/pDataObj//, pt//, dwEffect/*) > > > > > > Parameters > > > > /pDataObj/ : *PyIDataObject ** > > > > How do i link the IDataObject to the IDragTarget? > > I don't know that you can, if you're asking: how do I > find out where this is coming from?. I think the drag-drop > technique is endpoint-agnostic. (A high-sounding phrase I've > just invented). The most you can do is get hold of the data. > Again, I think. > > I'm out of my depth so I'm hoping that Roger or Mark > or other more knowledgeable people can chip in at this point > and help. > > For the purposes of discussion, I attach below my test harness > code which creates a simple window and registers a simple > IDropTarget object against it. > > Sorry to be no more help than this. > TJG > > > import os, sys > import win32gui > import win32con > import pythoncom > > CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}' > PROGID = "Tim.DropTarget" > DESC = "Drop target handler for Tim's app" > > class DropTarget: > _reg_clsid_ = CLSID > _reg_progid_ = PROGID > _reg_desc_ = DESC > _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] > _com_interfaces_ = [pythoncom.IID_IDropTarget] > > def DragEnter (self, data_object, key_state, point, effect): > pass > def DragOver (self, key_state, point, effect): > pass > def DragLeave (self): > pass > def Drop (self, data_object, key_state, point, effect): > pass > > def create_window (): > def OnDestroy (hwnd, msg, wparam, lparam): > win32gui.PostQuitMessage (0) > > wc = win32gui.WNDCLASS () > hinst = win32gui.GetModuleHandle(None) > wc.lpszClassName = "DragDrop" > wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; > wc.hCursor = win32gui.LoadCursor (0, win32con.IDC_ARROW) > wc.hbrBackground = win32con.COLOR_WINDOW > wc.lpfnWndProc = {win32con.WM_DESTROY : OnDestroy} > classAtom = win32gui.RegisterClass (wc) > style = win32con.WS_VISIBLE | \ > win32con.WS_OVERLAPPED | win32con.WS_SYSMENU > return win32gui.CreateWindow ( > classAtom, > "Drag & Drop demo", > style, > 0, 0, 100, 100, > 0, 0, hinst, None > ) > > if __name__ == '__main__': > pythoncom.OleInitialize () > drop_target = pythoncom.WrapObject ( > DropTarget, > pythoncom.IID_IDropTarget, > pythoncom.IID_IDropTarget > ) > pythoncom.RegisterDragDrop (create_window (), drop_target) > win32gui.PumpMessages () > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Be a superhero and win! Play the Iron Man Mashup Game http://www.ironmanmashup.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From Dominique.Holzwarth at ch.delarue.com Thu Apr 24 21:19:20 2008 From: Dominique.Holzwarth at ch.delarue.com (Dominique.Holzwarth at ch.delarue.com) Date: Thu, 24 Apr 2008 20:19:20 +0100 Subject: [python-win32] Apache & mod_python & win32com In-Reply-To: References: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com>, Message-ID: <5213E58D85BC414998FA553C701E386C0EDD07FF06@SGBD012511.dlrmail.ad.delarue.com> Thank you Rober & Alex for the answers :-) But I must admit that I'm still bit uncertain about that whole issue. As I understood apache it is creating a thread for every request anyway, or not? (and yes, on windows the MPM winnt is used) so wouldn't it be enough to just call CoInitialized() at the start of my (mod_python) python-handler and CoUnitialize() and the end of my handler? the try... finally you have added only for the case my script would "crash", right? so that the CoUnitialize() is called in that case as well? The idea about the single thread and queue I don't really get to be honest... what sort of object would be passed in the queue? And how would I create that queue and the thread? I guess you thinking of some standard python modules (as there's probably a python module for everything =))? Greetings Dominique ________________________________________ Von: Robert Brewer [fumanchu at aminus.org] Gesendet: Donnerstag, 24. April 2008 17:57 An: Holzwarth, Dominique (Berne Bauhaus); python-win32 at python.org Betreff: RE: [python-win32] Apache & mod_python & win32com Dominique.Holzwarth at ch.delarue.com wrote: > I'm developing a web application using mod_python and the apache web > server. That application has to handle xml files and for that I'm using > win32com with with MSXML. > > My problem is, that apache spawns a new process / thread (not sure > wether ist a process or thread. I think it's a thread) On Windows, almost certainly a thread. Apache on Windows uses the "winnt" MPM, which is multithreaded, not multiprocess. > per http > request. So when multiple users generated requests "at the same time" > (new request before the first one is returned) I have multiple threads > running. And that's where my win32com code is crashing... > > Currently, for every request my code does the following (as an > example): > > return win32com.client.Dispatch("Msxml2.DOMDocument.6.0") > > To get an empty MSXSML DOM object. > > For multiple requests at the same time I get the following error: > > File "C:\Program Files\Apache Software > Foundation\Apache2.2\TCRExceptionManagerData\database_library\database. > py", line 24, in __init__ > self.__configFileSchema = self.__XSDSchemaCache() > > File "C:\Program Files\Apache Software > Foundation\Apache2.2\TCRExceptionManagerData\database_library\database. > py", line 1774, in __XSDSchemaCache > return win32com.client.Dispatch("MSXML2.XMLSchemaCache.6.0") > > File "C:\Program Files\Python25\lib\site- > packages\win32com\client\__init__.py", line 95, in Dispatch > dispatch, userName = > dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) > > File "C:\Program Files\Python25\lib\site- > packages\win32com\client\dynamic.py", line 98, in > _GetGoodDispatchAndUserName > return (_GetGoodDispatch(IDispatch, clsctx), userName) > > File "C:\Program Files\Python25\lib\site- > packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch > IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, > pythoncom.IID_IDispatch) > > com_error: (-2147221008, 'CoInitialize has not been called.', None, > None) > > I've read already a bit in this mailing list and someone mentioned that > one need to call pythoncom.CoInitialize() and > pythoncom.CoUninitialize(). But I don't know where exactly i should > call those functions and wether that'll solve my problem... Also, when > I do a 'import win32com.pythoncom' I get an error that the module > 'pythoncom' does not exist! > > I would be really happy if someone could help me and tell me how to > make my win32com work for multiple threads! As Alex mentioned, you need to call CoInitialize for each thread. Unfortunately, since Apache is creating the threads for you, you don't have a hook for events to run on thread startup. Instead, you have to watch threads as they go by and call CoInitialize ASAP. Best to do so with a try/finally in case something goes wrong: def handler(req): CoInitialize() try: process(req) return apache.OK finally: CoUninitialize() If for various reasons that can't be made to work (some components just aren't thread safe), another option would be to run all the COM calls in a single thread and use a Queue; request threads would call q.put(xml, reqid) and block, the COM thread would call q.get(), do the work, and shove the result into results[reqid]. Robert Brewer fumanchu at aminus.org From rwupole at msn.com Thu Apr 24 23:25:03 2008 From: rwupole at msn.com (Roger Upole) Date: Thu, 24 Apr 2008 17:25:03 -0400 Subject: [python-win32] Creating python com objects Message-ID: Tim Golden wrote: > Alex Denham wrote: >> Parameters >> >> /pDataObj/ : *PyIDataObject ** >> >> How do i link the IDataObject to the IDragTarget? > > I don't know that you can, if you're asking: how do I > find out where this is coming from?. I think the drag-drop > technique is endpoint-agnostic. (A high-sounding phrase I've > just invented). Don't forget to trademark it ! > The most you can do is get hold of the data. > Again, I think. This is correct, the IDataObject interface is provided by the object that's being dragged. Unless you're also providing the dragged object the interface should be opaque. > > I'm out of my depth so I'm hoping that Roger or Mark > or other more knowledgeable people can chip in at this point > and help. > > For the purposes of discussion, I attach below my test harness > code which creates a simple window and registers a simple > IDropTarget object against it. > > Sorry to be no more help than this. > TJG > > > import os, sys > import win32gui > import win32con > import pythoncom > > CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}' > PROGID = "Tim.DropTarget" > DESC = "Drop target handler for Tim's app" > > class DropTarget: > _reg_clsid_ = CLSID > _reg_progid_ = PROGID > _reg_desc_ = DESC > _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] > _com_interfaces_ = [pythoncom.IID_IDropTarget] > > def DragEnter (self, data_object, key_state, point, effect): > pass > def DragOver (self, key_state, point, effect): > pass > def DragLeave (self): > pass > def Drop (self, data_object, key_state, point, effect): > pass > > def create_window (): > def OnDestroy (hwnd, msg, wparam, lparam): > win32gui.PostQuitMessage (0) > > wc = win32gui.WNDCLASS () > hinst = win32gui.GetModuleHandle(None) > wc.lpszClassName = "DragDrop" > wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; > wc.hCursor = win32gui.LoadCursor (0, win32con.IDC_ARROW) > wc.hbrBackground = win32con.COLOR_WINDOW > wc.lpfnWndProc = {win32con.WM_DESTROY : OnDestroy} > classAtom = win32gui.RegisterClass (wc) > style = win32con.WS_VISIBLE | \ > win32con.WS_OVERLAPPED | win32con.WS_SYSMENU > return win32gui.CreateWindow ( > classAtom, > "Drag & Drop demo", > style, > 0, 0, 100, 100, > 0, 0, hinst, None > ) > > if __name__ == '__main__': > pythoncom.OleInitialize () > drop_target = pythoncom.WrapObject ( > DropTarget, > pythoncom.IID_IDropTarget, > pythoncom.IID_IDropTarget > ) > pythoncom.RegisterDragDrop (create_window (), drop_target) > win32gui.PumpMessages () > > There's a little extra work you have to do for WrapObject to work locally. See \win32comext\authorization\demos\EditSecurity.py for an example. Roger From a1eio at hotmail.com Fri Apr 25 11:53:04 2008 From: a1eio at hotmail.com (Alex Denham) Date: Fri, 25 Apr 2008 10:53:04 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: References: Message-ID: I've had a look at the example and i can't quite pick out what's being done differently other than pythoncom.WrapObject() is being called within a class and it's being called on the class it's in? Or is it something to do with the arguments passed to wrap object? Thanks for the help. Alex > From: rwupole at msn.com > To: python-win32 at python.org > Date: Thu, 24 Apr 2008 17:25:03 -0400 > Subject: [python-win32] Creating python com objects > > > Tim Golden wrote: > > Alex Denham wrote: > >> Parameters > >> > >> /pDataObj/ : *PyIDataObject ** > >> > >> How do i link the IDataObject to the IDragTarget? > > > > I don't know that you can, if you're asking: how do I > > find out where this is coming from?. I think the drag-drop > > technique is endpoint-agnostic. (A high-sounding phrase I've > > just invented). > > Don't forget to trademark it ! > > > The most you can do is get hold of the data. > > Again, I think. > > This is correct, the IDataObject interface is provided by the object > that's being dragged. Unless you're also providing the dragged > object the interface should be opaque. > > > > > I'm out of my depth so I'm hoping that Roger or Mark > > or other more knowledgeable people can chip in at this point > > and help. > > > > For the purposes of discussion, I attach below my test harness > > code which creates a simple window and registers a simple > > IDropTarget object against it. > > > > Sorry to be no more help than this. > > TJG > > > > > > import os, sys > > import win32gui > > import win32con > > import pythoncom > > > > CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}' > > PROGID = "Tim.DropTarget" > > DESC = "Drop target handler for Tim's app" > > > > class DropTarget: > > _reg_clsid_ = CLSID > > _reg_progid_ = PROGID > > _reg_desc_ = DESC > > _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] > > _com_interfaces_ = [pythoncom.IID_IDropTarget] > > > > def DragEnter (self, data_object, key_state, point, effect): > > pass > > def DragOver (self, key_state, point, effect): > > pass > > def DragLeave (self): > > pass > > def Drop (self, data_object, key_state, point, effect): > > pass > > > > def create_window (): > > def OnDestroy (hwnd, msg, wparam, lparam): > > win32gui.PostQuitMessage (0) > > > > wc = win32gui.WNDCLASS () > > hinst = win32gui.GetModuleHandle(None) > > wc.lpszClassName = "DragDrop" > > wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; > > wc.hCursor = win32gui.LoadCursor (0, win32con.IDC_ARROW) > > wc.hbrBackground = win32con.COLOR_WINDOW > > wc.lpfnWndProc = {win32con.WM_DESTROY : OnDestroy} > > classAtom = win32gui.RegisterClass (wc) > > style = win32con.WS_VISIBLE | \ > > win32con.WS_OVERLAPPED | win32con.WS_SYSMENU > > return win32gui.CreateWindow ( > > classAtom, > > "Drag & Drop demo", > > style, > > 0, 0, 100, 100, > > 0, 0, hinst, None > > ) > > > > if __name__ == '__main__': > > pythoncom.OleInitialize () > > drop_target = pythoncom.WrapObject ( > > DropTarget, > > pythoncom.IID_IDropTarget, > > pythoncom.IID_IDropTarget > > ) > > pythoncom.RegisterDragDrop (create_window (), drop_target) > > win32gui.PumpMessages () > > > > > > There's a little extra work you have to do for WrapObject to work locally. > See \win32comext\authorization\demos\EditSecurity.py for an example. > > Roger > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Be a superhero and win! Play the Iron Man Mashup Game http://www.ironmanmashup.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwupole at msn.com Fri Apr 25 12:14:57 2008 From: rwupole at msn.com (Roger Upole) Date: Fri, 25 Apr 2008 06:14:57 -0400 Subject: [python-win32] Creating python com objects Message-ID: Alex Denham wrote: > I've had a look at the example and i can't quite pick out what's being > done differently other than pythoncom.WrapObject() is being called within > a class and it's being called on the > class it's in? > Or is it something to do with the arguments passed to wrap object? > > Thanks for the help. > Alex The class has to explicitely inherit from a policy class (win32com.server.policy.DesignatedWrapPolicy), and it has to have an __init__ method that calls _wrap_. Also, an instance of the class is passed to WrapObject rather than the class itself. This is snipped from a working example: class IDropTarget(win32com.server.policy.DesignatedWrapPolicy): _com_interfaces_=[pythoncom.IID_IDropTarget] _public_methods_=["DragEnter","DragOver","DragLeave","Drop"] def __init__(self): self._wrap_(self) def DragEnter(self, DataObject, KeyState, pt, Effect): print "DragEnter" print DataObject, KeyState, pt, Effect def DragOver(self, KeyState, pt, Effect): print "DragOver" print KeyState, pt, Effect def DragLeave(self): print "DragLeave" def Drop(self, DataObject, KeyState, pt, Effect): print "Drop" print DataObject, KeyState, pt, Effect dt=IDropTarget() IDT=pythoncom.WrapObject(dt, pythoncom.IID_IDropTarget, pythoncom.IID_IDropTarget) pythoncom.RegisterDragDrop(hwnd, IDT) Roger From josesimas at gmail.com Fri Apr 25 13:02:08 2008 From: josesimas at gmail.com (jose simas) Date: Fri, 25 Apr 2008 12:02:08 +0100 Subject: [python-win32] QueryInterface fails with object passed from VB Message-ID: Hi, I am porting parts of a large VB application to python (using 2.5) where the UI must stay in VB for the moment. I am using the Model View Presenter where my models and presenters are in python and my view is in VB. I am having trouble passing the VB views into my python presenters. The views are UserControls and implement an interface (IViewDataView in the example below) which is defined externally in a type library (ResultsInterfaces in this example). This interface defines the methods that the presenter can call on the view. So the VB code is: Dim presenterInPython As Object Set presenterInPython = CreateObject("VBToPython.MyTest") presenterInPython.Init vbUserControl.Object And the python code is: class MyTest: _public_methods_ = ['Init'] _reg_progid_ = "VBToPython.MyTest" _reg_clsid_ = '{AAAAA649-0AF9-40cf-A51B-4BB10DD33074}' def Init(self, view): import comtypes res_id = comtypes.GUID("{417081F1-179E-4856-B996-03043260AB81}") import comtypes.client as cc cc.GetModule((res_id, 1, 0)) import comtypes.gen.ResultsInterfaces as ResInt internalView = view.QueryInterface(ResInt.IViewDataView) at this point it throws the error (full error at the end): : Only strings and iids can be converted to a CLSID. Could anyone shed some light on what I missing here? I would also appreciate if someone could point me in the direction of a similar example or demo. Cheers Jose The error from PythonWin Trace Collector: Object with win32trace dispatcher created (object=None) in ._QueryInterface_ with unsupported IID IPersistStreamInit ({7FD52380-4E07-101B-AE2D-08002B2EC713}) in ._QueryInterface_ with unsupported IID IPersistPropertyBag ({37D84F60-42CB-11CE-8135-00AA004BB851}) in _GetIDsOfNames_ with '('Init',)' and '1033' in _Invoke_ with 1000 1033 1 (,) Traceback (most recent call last): File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py", line 47, in _Invoke_ return self.policy._Invoke_(dispid, lcid, wFlags, args) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 285, in _Invoke_ return self._invoke_(dispid, lcid, wFlags, args) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 290, in _invoke_ return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 593, in _invokeex_ return func(*args) File "C:\_svn\GXP\branches\v5\Core\src\COMTEST.py", line 37, in Init y = view.QueryInterface(ResInt.IViewDataView) TypeError: Only strings and iids can be converted to a CLSID. pythoncom error: Python error invoking COM method. Traceback (most recent call last): File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py", line 163, in _Invoke_ return DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args) File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py", line 49, in _Invoke_ return self._HandleException_() File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py", line 129, in _HandleException_ reraise() File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py", line 47, in _Invoke_ return self.policy._Invoke_(dispid, lcid, wFlags, args) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 285, in _Invoke_ return self._invoke_(dispid, lcid, wFlags, args) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 290, in _invoke_ return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None) File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 593, in _invokeex_ return func(*args) File "C:\_svn\GXP\branches\v5\Core\src\COMTEST.py", line 37, in Init y = view.QueryInterface(ResInt.IViewDataView) : Only strings and iids can be converted to a CLSID. From fuzzyman at voidspace.org.uk Fri Apr 25 14:10:43 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Fri, 25 Apr 2008 13:10:43 +0100 Subject: [python-win32] Access Denied Errors with IronPython and WMI Message-ID: <4811CA43.5010805@voidspace.org.uk> Hello guys, I'm writing some examples of using IronPython and WMI to connect to computers on the local network. I'm getting some 'access denied' errors and wondered if there was anyone on this list who might be able to help me. If there is then I will post details. All the best, Michael Foord http://www.ironpythoninaction.com/ From mail at timgolden.me.uk Fri Apr 25 18:16:34 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 25 Apr 2008 17:16:34 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: References: Message-ID: <481203E2.4030203@timgolden.me.uk> Well, for those of you still watching this show (!) and just in case anyone comes along in the future with the same question, I attach below a small working example which will accept one or more files dropped onto its Window. It doesn't do anything with the files, bar pull their names from the relevant data structure, but that's up to the specific application. Many thanks to Roger for the critical info to get this working and to Alex for asking the question which started it off. TJG import os, sys import win32gui import win32con import pythoncom import win32com.server.policy from win32com.shell import shell, shellcon # clsid generated by pythoncom.CreateGuid () CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}' PROGID = "Tim.DropTarget" DESC = "Drop target handler for Tim" class DropTarget (win32com.server.policy.DesignatedWrapPolicy): _reg_clsid_ = CLSID _reg_progid_ = PROGID _reg_desc_ = DESC _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] _com_interfaces_ = [pythoncom.IID_IDropTarget] def __init__ (self, hWnd): self._wrap_ (self) self.hWnd = hWnd def DragEnter (self, data_object, key_state, point, effect): if data_object.QueryGetData ((15, None, 1, -1, 1)): return shellcon.DROPEFFECT_COPY else: return shellcon.DROPEFFECT_NONE def DragOver (self, key_state, point, effect): pass def DragLeave (self): pass def Drop (self, data_object, key_state, point, effect): data = data_object.GetData ((15, None, 1, -1, 1)) n_files = shell.DragQueryFileW (data.data_handle, -1) filenames = [ shell.DragQueryFileW (data.data_handle, n_file) \ for n_file in range (n_files) ] def create_window (): def OnDestroy (hwnd, msg, wparam, lparam): win32gui.PostQuitMessage (0) wc = win32gui.WNDCLASS () hinst = win32gui.GetModuleHandle(None) wc.lpszClassName = "DragDrop" wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; wc.hCursor = win32gui.LoadCursor (0, win32con.IDC_ARROW) wc.hbrBackground = win32con.COLOR_WINDOW wc.lpfnWndProc = {win32con.WM_DESTROY : OnDestroy} classAtom = win32gui.RegisterClass (wc) style = win32con.WS_VISIBLE | win32con.WS_OVERLAPPED \ | win32con.WS_SYSMENU return win32gui.CreateWindow ( classAtom, "Drag & Drop demo", style, 0, 0, 100, 100, 0, 0, hinst, None ) if __name__ == '__main__': pythoncom.OleInitialize () hWnd = create_window () drop_target = DropTarget (hWnd) pythoncom.RegisterDragDrop ( hWnd, pythoncom.WrapObject ( drop_target, pythoncom.IID_IDropTarget, pythoncom.IID_IDropTarget ) ) win32gui.PumpMessages () From a1eio at hotmail.com Fri Apr 25 18:24:45 2008 From: a1eio at hotmail.com (Alex Denham) Date: Fri, 25 Apr 2008 17:24:45 +0100 Subject: [python-win32] Creating python com objects In-Reply-To: <481203E2.4030203@timgolden.me.uk> References: <481203E2.4030203@timgolden.me.uk> Message-ID: Thats excellent Tim, I was just about to start digging around for information on how to get the data once it's dropped. Thanks for your help Alex > Date: Fri, 25 Apr 2008 17:16:34 +0100 > From: mail at timgolden.me.uk > CC: python-win32 at python.org > Subject: Re: [python-win32] Creating python com objects > > Well, for those of you still watching this show (!) and > just in case anyone comes along in the future with the > same question, I attach below a small working example > which will accept one or more files dropped onto its > Window. It doesn't do anything with the files, bar pull > their names from the relevant data structure, but that's > up to the specific application. > > Many thanks to Roger for the critical info to get this > working and to Alex for asking the question which started > it off. > > TJG > > > import os, sys > import win32gui > import win32con > import pythoncom > import win32com.server.policy > from win32com.shell import shell, shellcon > > # clsid generated by pythoncom.CreateGuid () > CLSID = '{89DD545A-2C83-4103-AFE3-6CEB7FF5ECA4}' > PROGID = "Tim.DropTarget" > DESC = "Drop target handler for Tim" > > class DropTarget (win32com.server.policy.DesignatedWrapPolicy): > _reg_clsid_ = CLSID > _reg_progid_ = PROGID > _reg_desc_ = DESC > _public_methods_ = ['DragEnter', 'DragOver', 'DragLeave', 'Drop'] > _com_interfaces_ = [pythoncom.IID_IDropTarget] > > def __init__ (self, hWnd): > self._wrap_ (self) > self.hWnd = hWnd > > def DragEnter (self, data_object, key_state, point, effect): > if data_object.QueryGetData ((15, None, 1, -1, 1)): > return shellcon.DROPEFFECT_COPY > else: > return shellcon.DROPEFFECT_NONE > def DragOver (self, key_state, point, effect): > pass > def DragLeave (self): > pass > def Drop (self, data_object, key_state, point, effect): > data = data_object.GetData ((15, None, 1, -1, 1)) > n_files = shell.DragQueryFileW (data.data_handle, -1) > filenames = [ > shell.DragQueryFileW (data.data_handle, n_file) \ > for n_file in range (n_files) > ] > > def create_window (): > def OnDestroy (hwnd, msg, wparam, lparam): > win32gui.PostQuitMessage (0) > > wc = win32gui.WNDCLASS () > hinst = win32gui.GetModuleHandle(None) > wc.lpszClassName = "DragDrop" > wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW; > wc.hCursor = win32gui.LoadCursor (0, win32con.IDC_ARROW) > wc.hbrBackground = win32con.COLOR_WINDOW > wc.lpfnWndProc = {win32con.WM_DESTROY : OnDestroy} > classAtom = win32gui.RegisterClass (wc) > style = win32con.WS_VISIBLE | win32con.WS_OVERLAPPED \ > | win32con.WS_SYSMENU > return win32gui.CreateWindow ( > classAtom, > "Drag & Drop demo", > style, > 0, 0, 100, 100, > 0, 0, hinst, None > ) > > if __name__ == '__main__': > pythoncom.OleInitialize () > hWnd = create_window () > drop_target = DropTarget (hWnd) > pythoncom.RegisterDragDrop ( > hWnd, > pythoncom.WrapObject ( > drop_target, > pythoncom.IID_IDropTarget, > pythoncom.IID_IDropTarget > ) > ) > win32gui.PumpMessages () > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Bag extra points with the Walkers Brit Trip Game http://www.walkersbrittrips.co.uk/game -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Fri Apr 25 20:57:37 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 25 Apr 2008 11:57:37 -0700 Subject: [python-win32] [wxpython-users] Having problems with wxPython - HELP!!! In-Reply-To: References: <20080425162222.AA62F314D9B@riobu.com> <48120D87.2030606@probo.com> Message-ID: <481229A1.9000809@probo.com> Marlin Rowley wrote: > > I want to start from the beginning and work my way to what I have > now. Maybe then, I'll see some things that I didn't. :) > > Let's start with the Frame and Window creation. Right now, I pass a > resolution into my script (rfxRenderView.py 320 240). Let's say it's > 320x240. I expect this to be the resolution of the Window to be drawn > upon, NOT the frame that includes all the widgets. However, this is > exactly what is happening. The problem is that I call Frame's > constructor in my own child frame and I pass it the size so that the > window comes up relatively the size I want, however, the drawing > window will be a little less than that because of the Menu bar. How > do I pass the size of the Frame such that the Window gets created with > 320x240, THEN the Frame builds around that (so the actually size of > the frame+window > 320x240)? The vocabulary here is "window size" (which includes the decorations) and "client region" (which does not). Yes, when you specify a size, that includes the decorations. You want to specify the size of the client region, which you can't do, directly. Although it is possible to compute the size of each of the decorations, it is a tedious process, because of the possibility of themes. All the edges can vary, so you end up fetching a whole bunch of system preferences values. The easiest solution is to fetch your assigned window size and your assigned client size, compute the difference, and adjust yourself accordingly. For example, try adding the following after you create the wx.Frame: ws = self.GetSize() cs = self.GetClientSize() # Bump the window size by the delta between the two. ws.IncBy( *(ws-cs) ) self.SetSize( ws ) -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Fri Apr 25 21:07:49 2008 From: timr at probo.com (Tim Roberts) Date: Fri, 25 Apr 2008 12:07:49 -0700 Subject: [python-win32] [wxpython-users] Having problems with wxPython - HELP!!! In-Reply-To: <481229A1.9000809@probo.com> References: <20080425162222.AA62F314D9B@riobu.com> <48120D87.2030606@probo.com> <481229A1.9000809@probo.com> Message-ID: <48122C05.4080302@probo.com> Tim Roberts wrote: > Marlin Rowley wrote: >> >> I want to start from the beginning and work my way to what I have >> now. Maybe then, I'll see some things that I didn't. :) >> >> Let's start with the Frame and Window creation. Right now, I pass a >> resolution into my script (rfxRenderView.py 320 240). Let's say it's >> 320x240. I expect this to be the resolution of the Window to be >> drawn upon, NOT the frame that includes all the widgets. However, >> this is exactly what is happening. The problem is that I call >> Frame's constructor in my own child frame and I pass it the size so >> that the window comes up relatively the size I want, however, the >> drawing window will be a little less than that because of the Menu >> bar. How do I pass the size of the Frame such that the Window gets >> created with 320x240, THEN the Frame builds around that (so the >> actually size of the frame+window > 320x240)? > > The vocabulary here is "window size" (which includes the decorations) > and "client region" (which does not). Yes, when you specify a size, > that includes the decorations. You want to specify the size of the > client region, which you can't do, directly. Whoops, I sent this to the wrong mailing list. My apologies. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From rwupole at msn.com Fri Apr 25 21:49:33 2008 From: rwupole at msn.com (Roger Upole) Date: Fri, 25 Apr 2008 15:49:33 -0400 Subject: [python-win32] Access Denied Errors with IronPython and WMI Message-ID: Michael Foord wrote: > Hello guys, > > I'm writing some examples of using IronPython and WMI to connect to > computers on the local network. I'm getting some 'access denied' errors > and wondered if there was anyone on this list who might be able to help > me. > > If there is then I will post details. > > All the best, > > > Michael Foord If the target machine has remote administration disabled, you may get an Access denied. Also, there may be custom permissions set on the WMI namespace. Do you get the error when trying to connect, or when calling a particular method ? Roger From fuzzyman at voidspace.org.uk Fri Apr 25 21:55:03 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Fri, 25 Apr 2008 20:55:03 +0100 Subject: [python-win32] Access Denied Errors with IronPython and WMI In-Reply-To: References: Message-ID: <48123717.2030100@voidspace.org.uk> Roger Upole wrote: > Michael Foord wrote: >> Hello guys, >> >> I'm writing some examples of using IronPython and WMI to connect to >> computers on the local network. I'm getting some 'access denied' errors >> and wondered if there was anyone on this list who might be able to >> help me. >> >> If there is then I will post details. >> >> All the best, >> >> >> Michael Foord > > If the target machine has remote administration disabled, you may get an > Access denied. Also, there may be custom permissions set on the WMI > namespace. Do you get the error when trying to connect, or when calling > a particular method ? > Thanks for replying Roger - I'm now away from the office with no access to the network. I've had a couple of pointers to investigate the permissions on the target machine. I'll try this on Monday and see how far I get. Michael > Roger > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From siddhartha.veedaluru at gmail.com Sat Apr 26 06:45:40 2008 From: siddhartha.veedaluru at gmail.com (siddhartha veedaluru) Date: Sat, 26 Apr 2008 10:15:40 +0530 Subject: [python-win32] Create x64 exe using py2exe on 32bit machine Message-ID: <424b71ec0804252145t6dae0af2m8d522e1b362b82@mail.gmail.com> Hi, how can i create an x64 exe of a python script on a 32 bit machine. Please let me know if need any other information Thanks Siddhartha -------------- next part -------------- An HTML attachment was scrubbed... URL: From a1eio at hotmail.com Sat Apr 26 12:04:21 2008 From: a1eio at hotmail.com (Alex Denham) Date: Sat, 26 Apr 2008 11:04:21 +0100 Subject: [python-win32] (no subject) Message-ID: Hi all, I'm just wondering but when i try to access/update anything on my Tkinter GUI from one particular function, my whole program crashes/freezes with no error. The function is part of a class which handles all the GUI drawing/event handling etc. The function in question gets called from a win32 DesignatedWrapPolicy class. Sample code below: [code] # this function is part of an IDropTarget class, the TargetWidget was definined in the __init__ method of this functoin and it points to my class which handles the GUI. def Drop(self, data_object, key_state, point, effect): data = data_object.GetData((15, None, 1, -1, 1)) print data n_files = shell.DragQueryFileW(data.data_handle, -1) print n_files filenames = [shell.DragQueryFileW(data.data_handle, n_file) for n_file in range(n_files)] print filenames self.TargetWidget.filesDropped(filenames) # this calls the filesDropped function of the TargetWidget class and passes the filename list to it. # this function is part of the GUI class (which inherits from Tkinter.Toplevel) the print commands work however if i uncomment the clearInput function (which just calls self.filepathInput.delete(0, END) to clear the text) # the program hangs, same for the second commented line, and anything else that requires a call to tk it appears. Is there some sort of conflict going on between win32 and Tk ?? def filesDropped(self, fileList): print fileList # self.clearInput() # self.filepathInput.insert(Tkinter.END, fileList[0]) [/code] I'm just wondering if there's something i need to do to 'release' the GUI? I'm pretty sure it's got nothing to do with my code elsewhere because it was all working smoothly before, and if i call the filesDropped function from somewhere else (not from the IDropTarget class) i don't have any issues. Thanks in advance, Alex _________________________________________________________________ Be a superhero and win! Play the Iron Man Mashup Game http://www.ironmanmashup.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From tom.moulton at cox.net Tue Apr 15 22:38:34 2008 From: tom.moulton at cox.net (Tom Moulton) Date: Tue, 15 Apr 2008 16:38:34 -0400 Subject: [python-win32] Accessing a Remote Registry.... Message-ID: <20080415163839.93JWJ.117998.imail@eastrmwml14.mgt.cox.net> Much obliged. Worked like a champ, but you already knew that! ;-) Tom From tom.moulton at cox.net Wed Apr 16 15:23:42 2008 From: tom.moulton at cox.net (Tom Moulton) Date: Wed, 16 Apr 2008 9:23:42 -0400 Subject: [python-win32] Accessing a Remote Registry.... Message-ID: <20080416092342.DSZEQ.123463.imail@eastrmwml14.mgt.cox.net> Much obliged. Worked like a champ, but you already knew that! ;-) Tom From le.dahut at laposte.net Wed Apr 23 14:55:54 2008 From: le.dahut at laposte.net (le dahut) Date: Wed, 23 Apr 2008 14:55:54 +0200 Subject: [python-win32] platform.release() and Vista Message-ID: <480F31DA.2010408@laposte.net> Hello, I want to detect the version of windows (2K, XP, Vista). Therefore I used platform.release() but it doesn't work on Vista. Has anyone noticed this before ? From mhammond at skippinet.com.au Sun Apr 27 08:52:36 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 27 Apr 2008 16:52:36 +1000 Subject: [python-win32] Size of directory In-Reply-To: <68D737040F1D204CA68A38C372141F44CF0EF2@jc1wsmail3.global.knight.com> References: <8249c4ac0804221103mfd184c6x9389b204b01cdca7@mail.gmail.com> <68D737040F1D204CA68A38C372141F44CF0EF2@jc1wsmail3.global.knight.com> Message-ID: <001301c8a833$4c5e0e10$e51a2a30$@com.au> > You have to walk the directory tree and sum each file's size.? Windows does this too > - try your right-click properties on a large directory and see how long it takes. > That's also what du does.? There are, however, some recipes that should make this > fairly simple for you - try this: > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86554 The above uses os.listdir(), which I've had problems with in the past with huge directories (I can't recall, but I suspect it was simply performance that sucked). Either way, the fastest I've come up with has been based around: for fd in win32file.FindFilesIterator(os.path.join(dir, "*")): name = fd[8] if name in ('.', '..'): continue See the docs for how the 'fd' tuple is laid out. Cheers, Mark From mhammond at skippinet.com.au Sun Apr 27 09:01:46 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 27 Apr 2008 17:01:46 +1000 Subject: [python-win32] Create x64 exe using py2exe on 32bit machine In-Reply-To: <424b71ec0804252145t6dae0af2m8d522e1b362b82@mail.gmail.com> References: <424b71ec0804252145t6dae0af2m8d522e1b362b82@mail.gmail.com> Message-ID: <001801c8a834$922ce280$b686a780$@com.au> I don't think you can at the moment - you will probably need the SVN version of python 2.6 and then need to make some patches to py2exe (or at least trick it by manually cross-compiling its stubs as 64bit executables). Mark From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of siddhartha veedaluru Sent: Saturday, 26 April 2008 2:46 PM To: python-win32 at python.org Subject: [python-win32] Create x64 exe using py2exe on 32bit machine Hi, how can i create an x64 exe of a python script on a 32 bit machine. Please let me know if need any other information Thanks Siddhartha -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhammond at skippinet.com.au Sun Apr 27 09:07:26 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 27 Apr 2008 17:07:26 +1000 Subject: [python-win32] QueryInterface fails with object passed from VB In-Reply-To: References: Message-ID: <002301c8a835$5c1915a0$144b40e0$@com.au> > import comtypes.gen.ResultsInterfaces as ResInt > internalView = view.QueryInterface(ResInt.IViewDataView) ResInt.IViewDataView needs to be converted to either a pywintypes IID object, or a string in {xxx-xxx-etc} format - but I'm not sure how to convert between comtypes IIDs and pywintypes IIDs. Mark From mhammond at skippinet.com.au Sun Apr 27 09:20:20 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 27 Apr 2008 17:20:20 +1000 Subject: [python-win32] Apache & mod_python & win32com In-Reply-To: <5213E58D85BC414998FA553C701E386C0EDD07FF06@SGBD012511.dlrmail.ad.delarue.com> References: <5213E58D85BC414998FA553C701E386C0EDD14B583@SGBD012511.dlrmail.ad.delarue.com>, <5213E58D85BC414998FA553C701E386C0EDD07FF06@SGBD012511.dlrmail.ad.delarue.com> Message-ID: <002401c8a837$29464d80$7bd2e880$@com.au> > Thank you Rober & Alex for the answers :-) > But I must admit that I'm still bit uncertain about that whole issue. > As I understood apache it is creating a thread for every request > anyway, or not? No - given the docs posted before, they are created once and shared. When a request completes, its thread becomes available to process the next request. Thus, its better perf wise to only call the CoInit functions once as the thread starts. > (and yes, on windows the MPM winnt is used) > so wouldn't it be enough to just call CoInitialized() at the start of > my (mod_python) python-handler and CoUnitialize() and the end of my > handler? the try... finally you have added only for the case my script > would "crash", right? so that the CoUnitialize() is called in that case > as well? CoInit functions can fail if someone else has beaten you to calling CoInit, and requested a different threading model. Ideally, you should call CoInitializeEx(COINIT_MULTITHREADED), and if you happen to be using a free-threaded COM object, your threads will not interfere with each other at all. Apartment threading (the default) may not perform as well. Requesting free-threading should not hurt if the object is not free-threaded, but you would want to make sure :) > The idea about the single thread and queue I don't really get to be > honest... what sort of object would be passed in the queue? And how > would I create that queue and the thread? I guess you thinking of some > standard python modules (as there's probably a python module for > everything =))? Google for something like "consumer and producer pattern" Cheers, Mark From mhammond at skippinet.com.au Sun Apr 27 09:29:47 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 27 Apr 2008 17:29:47 +1000 Subject: [python-win32] Finding the selected file in Windows Explorer In-Reply-To: <480E1B41.8040403@probo.com> References: <480DA6E1.6070003@inesc-id.pt> <480E1B41.8040403@probo.com> Message-ID: <002501c8a838$7b7aa7d0$726ff770$@com.au> > What leads you to say this? Do you have a reference? Windows Explorer > in Vista has been substantially modified, but I have not read of any > breaking changes in the shell interface. A few of the interfaces have been dropped - IColumn* comes to mind. Michel may have been referring to DDE, which I believe is documented as being removed, and is probably also responsible for ShellExecute(Ex) working differently on Vista than on XP - ie, I can't make the code at http://support.microsoft.com/kb/179911 work under Vista - a new top-level Explorer window is always created - which I suspect is the result of no DDE. But sadly I can't find anyone else with that problem, nor an alternative work around. If anyone is keen, I could probably demonstrate this in one of the existing shell demos. Cheers, Mark From josesimas at gmail.com Sun Apr 27 12:18:13 2008 From: josesimas at gmail.com (jose simas) Date: Sun, 27 Apr 2008 11:18:13 +0100 Subject: [python-win32] QueryInterface fails with object passed from VB In-Reply-To: <002301c8a835$5c1915a0$144b40e0$@com.au> References: <002301c8a835$5c1915a0$144b40e0$@com.au> Message-ID: Hi Mark, Thanks for the answer, I tried using the IViewDataView's uiid like this (probably in a naive way): y = view.QueryInterface("{8D2AD79B-1ADD-4181-BAD4-FF0672A9B6E3}") But that produces the error on that line. com_error: (-2147221005, 'Invalid class string', None, None) I read that I can do the same thing with win32com (without using comtypes) but for that I would need to somehow add my custom interface to it. I also read that exist tools to automate this process but so far I could not find them. Where should I start? Cheers Jose On Sun, Apr 27, 2008 at 8:07 AM, Mark Hammond wrote: > > import comtypes.gen.ResultsInterfaces as ResInt > > internalView = view.QueryInterface(ResInt.IViewDataView) > > ResInt.IViewDataView needs to be converted to either a pywintypes IID > object, or a string in {xxx-xxx-etc} format - but I'm not sure how to > convert between comtypes IIDs and pywintypes IIDs. > > Mark > > From mhammond at skippinet.com.au Sun Apr 27 12:53:21 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Sun, 27 Apr 2008 20:53:21 +1000 Subject: [python-win32] QueryInterface fails with object passed from VB In-Reply-To: References: <002301c8a835$5c1915a0$144b40e0$@com.au> Message-ID: <003201c8a854$ebddf3d0$c399db70$@com.au> > Hi Mark, > > Thanks for the answer, I tried using the IViewDataView's uiid like > this (probably in a naive way): > > y = view.QueryInterface("{8D2AD79B-1ADD-4181-BAD4-FF0672A9B6E3}") > > But that produces the error on that line. > > com_error: (-2147221005, 'Invalid class string', None, None) Hrm - try passing 'pywintypes.IID("{8D2AD79B-1ADD-4181-BAD4-FF0672A9B6E3}")' as the IID. > I read that I can do the same thing with win32com (without using > comtypes) but for that I would need to somehow add my custom interface > to it. I also read that exist tools to automate this process but so > far I could not find them. Where should I start? Yeah - if the interface doesn't support IDispatch, your best bet is indeed comtypes. The code as it stands, once you sort out the simple issues, is likely to end up with an E_NOINTERFACE exception :( Mark From josesimas at gmail.com Sun Apr 27 15:24:49 2008 From: josesimas at gmail.com (jose simas) Date: Sun, 27 Apr 2008 14:24:49 +0100 Subject: [python-win32] QueryInterface fails with object passed from VB In-Reply-To: <003201c8a854$ebddf3d0$c399db70$@com.au> References: <002301c8a835$5c1915a0$144b40e0$@com.au> <003201c8a854$ebddf3d0$c399db70$@com.au> Message-ID: Unfortunately got the same error ('Invalid class string') with 'pywintypes.IID("{... You mention not supporting IDispatch but this interface inherits IDispatch. Here is a snippet from it's IDL: [ odl, uuid(8D2AD79B-1ADD-4181-BAD4-FF0672A9B6E3), version(1.0), dual, nonextensible, oleautomation ] interface IViewDataView : IDispatch { [id(0)] HRESULT GetDataSet([out,retval] long*); ... Isn't that the same thing? Jose On Sun, Apr 27, 2008 at 11:53 AM, Mark Hammond wrote: > > Hi Mark, > > > > Thanks for the answer, I tried using the IViewDataView's uiid like > > this (probably in a naive way): > > > > y = view.QueryInterface("{8D2AD79B-1ADD-4181-BAD4-FF0672A9B6E3}") > > > > But that produces the error on that line. > > > > com_error: (-2147221005, 'Invalid class string', None, None) > > Hrm - try passing 'pywintypes.IID("{8D2AD79B-1ADD-4181-BAD4-FF0672A9B6E3}")' > as the IID. > > > I read that I can do the same thing with win32com (without using > > comtypes) but for that I would need to somehow add my custom interface > > to it. I also read that exist tools to automate this process but so > > far I could not find them. Where should I start? > > Yeah - if the interface doesn't support IDispatch, your best bet is indeed > comtypes. The code as it stands, once you sort out the simple issues, is > likely to end up with an E_NOINTERFACE exception :( > > Mark > > From mhammond at skippinet.com.au Mon Apr 28 01:00:49 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 28 Apr 2008 09:00:49 +1000 Subject: [python-win32] QueryInterface fails with object passed from VB In-Reply-To: References: <002301c8a835$5c1915a0$144b40e0$@com.au> <003201c8a854$ebddf3d0$c399db70$@com.au> Message-ID: <004901c8a8ba$8be986e0$a3bc94a0$@com.au> > Unfortunately got the same error ('Invalid class string') with > 'pywintypes.IID("{... That is strange - it appears the object itself is throwing that error code. E_NOINTERFACE is generally the only "expected" error code for QI. > You mention not supporting IDispatch but this interface inherits > IDispatch. Here is a snippet from it's IDL: > > [ > odl, > uuid(8D2AD79B-1ADD-4181-BAD4-FF0672A9B6E3), > version(1.0), > dual, > nonextensible, > oleautomation > ] > interface IViewDataView : IDispatch { > > [id(0)] HRESULT GetDataSet([out,retval] long*); > ... > > Isn't that the same thing? It is - so I've no idea what the problem is :( Mark > > Jose > > On Sun, Apr 27, 2008 at 11:53 AM, Mark Hammond > wrote: > > > Hi Mark, > > > > > > Thanks for the answer, I tried using the IViewDataView's uiid like > > > this (probably in a naive way): > > > > > > y = view.QueryInterface("{8D2AD79B-1ADD-4181-BAD4-FF0672A9B6E3}") > > > > > > But that produces the error on that line. > > > > > > com_error: (-2147221005, 'Invalid class string', None, None) > > > > Hrm - try passing 'pywintypes.IID("{8D2AD79B-1ADD-4181-BAD4- > FF0672A9B6E3}")' > > as the IID. > > > > > I read that I can do the same thing with win32com (without using > > > comtypes) but for that I would need to somehow add my custom > interface > > > to it. I also read that exist tools to automate this process but so > > > far I could not find them. Where should I start? > > > > Yeah - if the interface doesn't support IDispatch, your best bet is > indeed > > comtypes. The code as it stands, once you sort out the simple > issues, is > > likely to end up with an E_NOINTERFACE exception :( > > > > Mark > > > > > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 From Dominique.Holzwarth at ch.delarue.com Mon Apr 28 08:16:46 2008 From: Dominique.Holzwarth at ch.delarue.com (Dominique.Holzwarth at ch.delarue.com) Date: Mon, 28 Apr 2008 07:16:46 +0100 Subject: [python-win32] Apache & mod_python & win32com In-Reply-To: <002401c8a837$29464d80$7bd2e880$@com.au> Message-ID: <5213E58D85BC414998FA553C701E386C0EDD14BBF8@SGBD012511.dlrmail.ad.delarue.com> The problem with apache tho is, that it starts the thread itself and I don't know wether my script runs on a new thread or not. I did some testing with calling CoInitialize at the start of my scripts and CoUnitialize at the end of my script (as suggested by others before) and it seemed to work... Do I understand you correct, that you suggest to use CoInitializeEx instead? My scripts should all use the aparment threading model tho, but I can try and change to CoInitializeEx =) As for the COM objects I'm requesting, these are: win32com.client.Dispatch("MSXML2.XMLSchemaCache.6.0") win32com.client.Dispatch("Msxml2.FreeThreadedDOMDocument.6.0") win32com.client.Dispatch("Msxml2.DOMDocument.6.0") win32com.client.Dispatch("Msxml2.XSLTemplate.6.0") So for the DOM document there seem to be either version, but for the schema and template objects I don't know wether these are free-threaded or not and wether that matters at all... :-/ I have to admit that the whole COM stuff is a bit mysterious for me... Greetings Dominique -----Original Message----- From: Mark Hammond [mailto:mhammond at skippinet.com.au] Sent: Sonntag, 27. April 2008 09:20 To: Holzwarth, Dominique (Berne Bauhaus); python-win32 at python.org Subject: RE: [python-win32] Apache & mod_python & win32com > Thank you Rober & Alex for the answers :-) But I must admit that I'm > still bit uncertain about that whole issue. > As I understood apache it is creating a thread for every request > anyway, or not? No - given the docs posted before, they are created once and shared. When a request completes, its thread becomes available to process the next request. Thus, its better perf wise to only call the CoInit functions once as the thread starts. > (and yes, on windows the MPM winnt is used) so wouldn't it be enough > to just call CoInitialized() at the start of my (mod_python) > python-handler and CoUnitialize() and the end of my handler? the > try... finally you have added only for the case my script would > "crash", right? so that the CoUnitialize() is called in that case as > well? CoInit functions can fail if someone else has beaten you to calling CoInit, and requested a different threading model. Ideally, you should call CoInitializeEx(COINIT_MULTITHREADED), and if you happen to be using a free-threaded COM object, your threads will not interfere with each other at all. Apartment threading (the default) may not perform as well. Requesting free-threading should not hurt if the object is not free-threaded, but you would want to make sure :) > The idea about the single thread and queue I don't really get to be > honest... what sort of object would be passed in the queue? And how > would I create that queue and the thread? I guess you thinking of some > standard python modules (as there's probably a python module for > everything =))? Google for something like "consumer and producer pattern" Cheers, Mark From pyd at pydelens.be Mon Apr 28 08:25:22 2008 From: pyd at pydelens.be (Pierre-Yves Delens) Date: Mon, 28 Apr 2008 08:25:22 +0200 Subject: [python-win32] FileWatcher Message-ID: <48156DD2.3020706@pydelens.be> An HTML attachment was scrubbed... URL: From mhammond at skippinet.com.au Mon Apr 28 08:38:52 2008 From: mhammond at skippinet.com.au (Mark Hammond) Date: Mon, 28 Apr 2008 16:38:52 +1000 Subject: [python-win32] Apache & mod_python & win32com In-Reply-To: <5213E58D85BC414998FA553C701E386C0EDD14BBF8@SGBD012511.dlrmail.ad.delarue.com> References: <002401c8a837$29464d80$7bd2e880$@com.au> <5213E58D85BC414998FA553C701E386C0EDD14BBF8@SGBD012511.dlrmail.ad.delarue.com> Message-ID: <007401c8a8fa$88cf3370$9a6d9a50$@com.au> > The problem with apache tho is, that it starts the thread itself and I > don't know wether my script runs on a new thread or not. Yeah - it sucks if there is no way to hook thread creation. > I did some > testing with calling CoInitialize at the start of my scripts and > CoUnitialize at the end of my script (as suggested by others before) > and it seemed to work... Yes, it will work - it's just slightly slower as it doesn't *need* to be done each time. > Do I understand you correct, that you suggest to use CoInitializeEx > instead? My scripts should all use the aparment threading model tho, > but I can try and change to CoInitializeEx =) See the docs for the functions - CoInitializeEx lets you specify the threading model, CoInitialize() implies it. If you must use apartment threading, then that is fine, and you can use either function to do that (but if you did not need to use it, you may have found free-threading performs better in some cases when multiple threads are running concurrently) > So for the DOM document there seem to be either version, but for the > schema and template objects I don't know wether these are free-threaded > or not and wether that matters at all... :-/ I have to admit that the > whole COM stuff is a bit mysterious for me... Yeah, it is confusing and can generally be ignored if you aren't sharing COM objects between threads etc - ie, just stick with what works ;) Mark From josesimas at gmail.com Mon Apr 28 10:34:27 2008 From: josesimas at gmail.com (jose simas) Date: Mon, 28 Apr 2008 09:34:27 +0100 Subject: [python-win32] QueryInterface fails with object passed from VB In-Reply-To: <004901c8a8ba$8be986e0$a3bc94a0$@com.au> References: <002301c8a835$5c1915a0$144b40e0$@com.au> <003201c8a854$ebddf3d0$c399db70$@com.au> <004901c8a8ba$8be986e0$a3bc94a0$@com.au> Message-ID: No worries Mark, many thanks for your help. I am using the default interface instead which works perfectly. Going through the custom interface would make the code cleaner but I am happy to live with this if that means I can use python in the backend :-) I will post here if I find the answer. Have a good vacation. Cheers Jose From mail at timgolden.me.uk Mon Apr 28 12:39:13 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 28 Apr 2008 11:39:13 +0100 Subject: [python-win32] FileWatcher In-Reply-To: <48156DD2.3020706@pydelens.be> References: <48156DD2.3020706@pydelens.be> Message-ID: <4815A951.3040509@timgolden.me.uk> Pierre-Yves Delens wrote: > Bonjour, > > in the context of CAD management (layersmanagement, etc...), > > we are storing our Layers management in a reference.dwg file, for obvious reasons. > But some aspects of this management have to be maintained in alphanumeric format. > > Therefore > > we need to trigger each time this reference.dwg file is modified. Have a look at this, perhaps: http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html TJG From mdriscoll at co.marshall.ia.us Mon Apr 28 15:28:00 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Mon, 28 Apr 2008 08:28:00 -0500 Subject: [python-win32] FileWatcher In-Reply-To: <48156DD2.3020706@pydelens.be> References: <48156DD2.3020706@pydelens.be> Message-ID: <4815D0E0.9090205@co.marshall.ia.us> Pierre-Yves Delens wrote: > Bonjour, > > in the context of CAD management (layersmanagement, etc...), > > we are storing our Layers management in a reference.dwg file, for > obvious reasons. > But some aspects of this management have to be maintained in > alphanumeric format. > > Therefore > > we need to trigger each time this reference.dwg file is modified. > This trigger would launch a small exe our py script, > so that we can extract datas from it (layers definitions actually), > and integrate them in a database (SqLite ~Python). > We should therefore be able to monitor this file. > > Can Python, can PythonWin help me to do that? > Could you give me the [beginning of ] a clue? > > I read through the book 'Py progamming on Win32', but I didn't find this. > Although I guess that a Win 'service' (the topic is in the book) > should be created. > > I found about "FileWatcher DLL" which is what we need, butthisis in > context of C# and IronPython. I was hoping to find a shorter way > between Python and the file-Sytem. Is there some kind of FileWatcher > DLL accessible from Pywin32? > > Thanks on forward. > > Yours > -- > > __________________________________________________________________ > pour P-Y Delens sprl, Bureau d'Architectes, > > Pierre-Yves Delens, ir-arch. > > Hi Pierre-Yves, I've used Tim Golden's folder watcher script to do this sort of thing. You can check it out as well as a couple of other methods on his site: http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html It uses various parts from the pyWin32 package, so be sure to download that. Mike From mdriscoll at co.marshall.ia.us Mon Apr 28 15:33:50 2008 From: mdriscoll at co.marshall.ia.us (Mike Driscoll) Date: Mon, 28 Apr 2008 08:33:50 -0500 Subject: [python-win32] (no subject) In-Reply-To: References: Message-ID: <4815D23E.7000300@co.marshall.ia.us> Alex Denham wrote: > Hi all, > > I'm just wondering but when i try to access/update anything on my > Tkinter GUI from one particular function, my whole program > crashes/freezes with no error. > > The function is part of a class which handles all the GUI > drawing/event handling etc. > The function in question gets called from a win32 DesignatedWrapPolicy > class. Sample code below: > > [code] > # this function is part of an IDropTarget class, the TargetWidget > was definined in the __init__ method of this functoin and it points to > my class which handles the GUI. > def Drop(self, data_object, key_state, point, effect): > data = data_object.GetData((15, None, 1, -1, 1)) > print data > n_files = shell.DragQueryFileW(data.data_handle, -1) > print n_files > filenames = [shell.DragQueryFileW(data.data_handle, n_file) > for n_file in range(n_files)] > print filenames > self.TargetWidget.filesDropped(filenames) # this calls the > filesDropped function of the TargetWidget class and passes the > filename list to it. > > # this function is part of the GUI class (which inherits from > Tkinter.Toplevel) the print commands work however if i uncomment the > clearInput function (which just calls self.filepathInput.delete(0, > END) to clear the text) > # the program hangs, same for the second commented line, and > anything else that requires a call to tk it appears. Is there some > sort of conflict going on between win32 and Tk ?? > def filesDropped(self, fileList): > print fileList > # self.clearInput() > # self.filepathInput.insert(Tkinter.END, fileList[0]) > [/code] > > I'm just wondering if there's something i need to do to 'release' the GUI? > I'm pretty sure it's got nothing to do with my code elsewhere because > it was all working smoothly before, and if i call the filesDropped > function from somewhere else (not from the IDropTarget class) i don't > have any issues. > > Thanks in advance, > Alex This is just a guess, but you usually cannot update a GUI from an outside process directly. At least, this is true of wxPython. I think your blocking the idle event in Tkinter, which causes it to hang and then when you try to update it, Tkinter crashes because you're making a call on it from what amounts to a separate thread. Instead, you ought to write to a file or post an event when the win32 part is finished that the Tkinter GUI can check periodically and then react. In other words, have the win32 portion of your code write something to a file and have Tkinter check the file every few seconds and then update itself when it finds something in there. In wxPython there is a way to subscribe to special events using the PubSub module. Tkinter probably has its own nomenclature. If you can't figure it out, I'd recommend the Tkinter mailing list. Mike From yung.giang at gmail.com Mon Apr 28 17:38:20 2008 From: yung.giang at gmail.com (Yung Giang) Date: Mon, 28 Apr 2008 11:38:20 -0400 Subject: [python-win32] EOFError on gencache.py in _LoadDicts Message-ID: <80eeb900804280838g4dfff067v3f13e626da0eef85@mail.gmail.com> Has anyone hit this Error? I'm using ActivePython-2.5.2.2-win32-x68 and once in a while I'm hitting this error below. Application,47,2008-04-25 23:46:58,2008-04-25 23:46:58,4,1,Error event,0,None,Python Service," File ""C:\Python25\wuest2.py"", line 17, in import wuestCommon File ""C:\Python25\wuestCommon.py"", line 7, in import wmi File ""C:\Python25\wmi.py"", line 141, in from win32com.client import GetObject, Dispatch File ""C:\Python25\Lib\site-packages\win32com\client\__init__.py"", line 12, in import dynamic, gencache, pythoncom File ""C:\Python25\Lib\site-packages\win32com\client\gencache.py"", line 662, in __init__() File ""C:\Python25\Lib\site-packages\win32com\client\gencache.py"", line 54, in __init__ _LoadDicts() File ""C:\Python25\Lib\site-packages\win32com\client\gencache.py"", line 109, in _LoadDicts version = p.load()||",BAR-6C2FDC684E3,,"Python could not import the service's module File ""C:\Python25\wuest2.py"", line 17, in import wuestCommon File ""C:\Python25\wuestCommon.py"", line 7, in import wmi File ""C:\Python25\wmi.py"", line 141, in from win32com.client import GetObject, Dispatch File ""C:\Python25\Lib\site-packages\win32com\client\__init__.py"", line 12, in import dynamic, gencache, pythoncom File ""C:\Python25\Lib\site-packages\win32com\client\gencache.py"", line 662, in __init__() File ""C:\Python25\Lib\site-packages\win32com\client\gencache.py"", line 54, in __init__ _LoadDicts() File ""C:\Python25\Lib\site-packages\win32com\client\gencache.py"", line 109, in _LoadDicts version = p.load() : ", Thank you for your time, -Yung Giang -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Mon Apr 28 20:40:30 2008 From: timr at probo.com (Tim Roberts) Date: Mon, 28 Apr 2008 11:40:30 -0700 Subject: [python-win32] Create x64 exe using py2exe on 32bit machine In-Reply-To: <424b71ec0804252145t6dae0af2m8d522e1b362b82@mail.gmail.com> References: <424b71ec0804252145t6dae0af2m8d522e1b362b82@mail.gmail.com> Message-ID: <48161A1E.5070707@probo.com> siddhartha veedaluru wrote: > > how can i create an x64 exe of a python script on a 32 bit machine. Why? All of the x64 platforms can run 32-bit executables. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From a1eio at hotmail.com Tue Apr 29 11:42:54 2008 From: a1eio at hotmail.com (Alex Denham) Date: Tue, 29 Apr 2008 10:42:54 +0100 Subject: [python-win32] (no subject) In-Reply-To: <4815D23E.7000300@co.marshall.ia.us> References: <4815D23E.7000300@co.marshall.ia.us> Message-ID: Thanks mike, i was thinking of doing something along those lines using the os modules tmpfile() method. Althought i'm pretty i can post custom events to the Tkinter event loop, will try that first. Thanks > Date: Mon, 28 Apr 2008 08:33:50 -0500 > From: mdriscoll at co.marshall.ia.us > To: a1eio at hotmail.com; python-win32 at python.org > Subject: Re: [python-win32] (no subject) > > Alex Denham wrote: > > Hi all, > > > > I'm just wondering but when i try to access/update anything on my > > Tkinter GUI from one particular function, my whole program > > crashes/freezes with no error. > > > > The function is part of a class which handles all the GUI > > drawing/event handling etc. > > The function in question gets called from a win32 DesignatedWrapPolicy > > class. Sample code below: > > > > [code] > > # this function is part of an IDropTarget class, the TargetWidget > > was definined in the __init__ method of this functoin and it points to > > my class which handles the GUI. > > def Drop(self, data_object, key_state, point, effect): > > data = data_object.GetData((15, None, 1, -1, 1)) > > print data > > n_files = shell.DragQueryFileW(data.data_handle, -1) > > print n_files > > filenames = [shell.DragQueryFileW(data.data_handle, n_file) > > for n_file in range(n_files)] > > print filenames > > self.TargetWidget.filesDropped(filenames) # this calls the > > filesDropped function of the TargetWidget class and passes the > > filename list to it. > > > > # this function is part of the GUI class (which inherits from > > Tkinter.Toplevel) the print commands work however if i uncomment the > > clearInput function (which just calls self.filepathInput.delete(0, > > END) to clear the text) > > # the program hangs, same for the second commented line, and > > anything else that requires a call to tk it appears. Is there some > > sort of conflict going on between win32 and Tk ?? > > def filesDropped(self, fileList): > > print fileList > > # self.clearInput() > > # self.filepathInput.insert(Tkinter.END, fileList[0]) > > [/code] > > > > I'm just wondering if there's something i need to do to 'release' the GUI? > > I'm pretty sure it's got nothing to do with my code elsewhere because > > it was all working smoothly before, and if i call the filesDropped > > function from somewhere else (not from the IDropTarget class) i don't > > have any issues. > > > > Thanks in advance, > > Alex > This is just a guess, but you usually cannot update a GUI from an > outside process directly. At least, this is true of wxPython. I think > your blocking the idle event in Tkinter, which causes it to hang and > then when you try to update it, Tkinter crashes because you're making a > call on it from what amounts to a separate thread. > > Instead, you ought to write to a file or post an event when the win32 > part is finished that the Tkinter GUI can check periodically and then > react. In other words, have the win32 portion of your code write > something to a file and have Tkinter check the file every few seconds > and then update itself when it finds something in there. > > In wxPython there is a way to subscribe to special events using the > PubSub module. Tkinter probably has its own nomenclature. If you can't > figure it out, I'd recommend the Tkinter mailing list. > > Mike _________________________________________________________________ Be a superhero and win! Play the Iron Man Mashup Game http://www.ironmanmashup.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Tue Apr 29 11:58:17 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 29 Apr 2008 10:58:17 +0100 Subject: [python-win32] (no subject) In-Reply-To: References: <4815D23E.7000300@co.marshall.ia.us> Message-ID: <4816F139.3010800@timgolden.me.uk> Alex Denham wrote: > Thanks mike, i was thinking of doing something along those lines using the os modules tmpfile() method. > Althought i'm pretty i can post custom events to the Tkinter event loop, will try that first. Sorry, Alex. I've only just spotted this thread. I think what's happening is that, when a drag-drop is initiated, Windows runs in a mini-messageloop of its own, and when the drop event occurs, you're still in that loop. I'm not sure how that will interract with whatever Windows messageloop Tkinter's running on your behalf. The normal thing would be to post some kind of message asynchronously, allowing your drop code to complete and the app's messageloop can then kick back in and see the message you posted. (waves hands about) TJG From a1eio at hotmail.com Tue Apr 29 14:56:45 2008 From: a1eio at hotmail.com (Alex Denham) Date: Tue, 29 Apr 2008 13:56:45 +0100 Subject: [python-win32] (no subject) In-Reply-To: <4816F139.3010800@timgolden.me.uk> References: <4815D23E.7000300@co.marshall.ia.us> <4816F139.3010800@timgolden.me.uk> Message-ID: Excellent, thanks everyone. Drag and Drop seems to fully work now. Tim, Mike: I ended up just using a global variable, once in the Drop method of the IDropTarget class and once in the filesDropped method in the MainWindow class. [code] def filesDropped(self): global Files if Files: f = Files[0] Files = [] else: pass self.after(1000, self.filesDropped) [/code] Thanks for everyone's help, Alex > Date: Tue, 29 Apr 2008 10:58:17 +0100 > From: mail at timgolden.me.uk > CC: python-win32 at python.org > Subject: Re: [python-win32] (no subject) > > Alex Denham wrote: > > Thanks mike, i was thinking of doing something along those lines using the os modules tmpfile() method. > > Althought i'm pretty i can post custom events to the Tkinter event loop, will try that first. > > Sorry, Alex. I've only just spotted this thread. I think what's happening is that, when a drag-drop > is initiated, Windows runs in a mini-messageloop of its own, and when the drop event occurs, > you're still in that loop. I'm not sure how that will interract with whatever Windows messageloop > Tkinter's running on your behalf. The normal thing would be to post some kind of message > asynchronously, allowing your drop code to complete and the app's messageloop can then > kick back in and see the message you posted. (waves hands about) > > TJG > _______________________________________________ > python-win32 mailing list > python-win32 at python.org > http://mail.python.org/mailman/listinfo/python-win32 _________________________________________________________________ Be a superhero and win! Play the Iron Man Mashup Game http://www.ironmanmashup.co.uk -------------- next part -------------- An HTML attachment was scrubbed... URL: From singhai.nish at gmail.com Tue Apr 29 16:32:11 2008 From: singhai.nish at gmail.com (kNish) Date: Tue, 29 Apr 2008 20:02:11 +0530 Subject: [python-win32] motorola ad Message-ID: <81bfef2e0804290732i2ab517a2l523670de3f1fbc1a@mail.gmail.com> Hi, A question. Have you seen the motorola ad where everything gradually grows out from nothing. How is it possible to make it using python script or MEL script. My guesstimate is 1) create a function with two parameters. This function will have a set driven key for a set of objects. This function will have a return value. It will be a zero or a One. If zero then the transition of those objects is not done. If one, then the transition is done. If so then move on to getting transition effect of other set of objects. 2) call this function randomly for a given set of objects. What is your opinion on this. BRgds, kNish -------------- next part -------------- An HTML attachment was scrubbed... URL: From timr at probo.com Tue Apr 29 19:35:28 2008 From: timr at probo.com (Tim Roberts) Date: Tue, 29 Apr 2008 10:35:28 -0700 Subject: [python-win32] motorola ad In-Reply-To: <81bfef2e0804290732i2ab517a2l523670de3f1fbc1a@mail.gmail.com> References: <81bfef2e0804290732i2ab517a2l523670de3f1fbc1a@mail.gmail.com> Message-ID: <48175C60.9000704@probo.com> kNish wrote: > > A question. Have you seen the motorola ad where everything > gradually grows out from nothing. How is it possible to make it using > python script or MEL script. No, we haven't seen the ad, and your post is senseless without it. What on earth are you talking about? Are you talking about some kind of animation? Is it graphics? Is it video? Is it alive? WHAT "grows" out of nothing? > My guesstimate is > > 1) create a function with two parameters. This function will have a > set driven key for a set of objects. This function will have a return > value. It will be a zero or a One. If zero then the transition of > those objects is not done. If one, then the transition is done. If so > then move on to getting transition effect of other set of objects. > 2) call this function randomly for a given set of objects. > > What is your opinion on this. My opinion is that this whole post is nonsense. Please tell us what you are trying to accomplish. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From mail2spj at yahoo.com Tue Apr 29 22:51:01 2008 From: mail2spj at yahoo.com (SPJ) Date: Tue, 29 Apr 2008 13:51:01 -0700 (PDT) Subject: [python-win32] Getting security permissions for folders on remote file share Message-ID: <718193.99620.qm@web50108.mail.re2.yahoo.com> I have googled on this but have not found a way to get security permissions of all the folders on a remote file share using python win32 module. There are few hundred folders on the server in public share and I need to get who has what permission's for each of the folder there. Would appreciate any help/ pointer's in this regards. Thanks in advance. SPJ ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ From mail at timgolden.me.uk Wed Apr 30 11:22:53 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 30 Apr 2008 10:22:53 +0100 Subject: [python-win32] Getting security permissions for folders on remote file share In-Reply-To: <718193.99620.qm@web50108.mail.re2.yahoo.com> References: <718193.99620.qm@web50108.mail.re2.yahoo.com> Message-ID: <48183A6D.6050004@timgolden.me.uk> SPJ wrote: > I have googled on this but have not found a way to get security permissions of > all the folders on a remote file share using python win32 module. (I hope you know how NTFS security works, because while it's not necessarily used that way, it can get a lot more complex than you might imagine.) It's not clear (to me) whether the files are accessible to you from your machine, but merely happen to be on a remote machine (ie you're doing something like \\other-box\share1\dir\filename); or whether you don't have access from your own machine and need some kind of remote access toolset. If the former, you've got a few options (see below). If the latter, you're more limited, and WMI is probably the way to go. One possibility is to use the cacls or xcacls command line tools to dump the information out. This is pretty much exactly what they're designed to do and they've already done the hard work of determining what's what inside the DACL which you'd otherwise have to do. The downside is that you'd have to parse their output (unless simply dumping it out to a log is acceptable for your purposes). A second possibility is to use the low-level Win32 API to query the security yourself, essentially rolling your own cacls. This has the advantage that you can produce exactly the output you want in the format you need, but the disadvantage that you have to do it all yourself, including working through allow and deny ACEs and inheritance issues. As a trivial starting point, you can have a look at these: http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html http://timgolden.me.uk/python/win32_how_do_i/add-security-to-a-file.html which are clearly only starting points for what you want to do. Look also at the examples in the demos folder of the pywin32 extensions. You could also consider WMI which may be your only possibility if you need to access the security on remote machines (as opposed to via a share). This will take you only a little higher than the Win32 APIs: you still have to do a fair bit of work yourself. But it does allow you to perform the same check across a number of machines. I don't have a WMI security example, but if you wanted to go that way I could run one up. TJG From siddhartha.veedaluru at gmail.com Wed Apr 30 11:52:47 2008 From: siddhartha.veedaluru at gmail.com (siddhartha veedaluru) Date: Wed, 30 Apr 2008 15:22:47 +0530 Subject: [python-win32] Will wmi can a command on remore host and get the return code Message-ID: <424b71ec0804300252y77ce2dfbxfce6091b0953cafa@mail.gmail.com> Hi, I need to run a command on remote machine (may be in another domain also) and get the output and return code of that command or exe. Also i need to copy file to remote machine.? Can i achive it through wmi, if not help how can i get it done. Thanks a million, Siddhartha -------------- next part -------------- An HTML attachment was scrubbed... URL: From mail at timgolden.me.uk Wed Apr 30 12:42:35 2008 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 30 Apr 2008 11:42:35 +0100 Subject: [python-win32] Will wmi can a command on remore host and get the return code In-Reply-To: <424b71ec0804300252y77ce2dfbxfce6091b0953cafa@mail.gmail.com> References: <424b71ec0804300252y77ce2dfbxfce6091b0953cafa@mail.gmail.com> Message-ID: <48184D1B.5050004@timgolden.me.uk> siddhartha veedaluru wrote: > I need to run a command on remote machine (may be in another domain also) > and get the output and return code of that command or exe. > > Also i need to copy file to remote machine.? > > Can i achive it through wmi I would suggest that WMI -- flexible as it undoubtedly is -- is not really the vehicle for this kind of thing. Yes, you can run commands and get the result: import wmi c = wmi.WMI () # specify other machine pid, result = c.Win32_Process.Create (r'cmd /c dir > %TEMP%\dir.log') but WMI isn't, of itself, a file transport mechanism. If any file-sharing mechanism exists between the machines in question (SMB, FTP or whatever) then there's nothing to stop you from using WMI, either via Win32_Process.Create or via CIM_DataFile.Copy. But the only advantage this offers over simply shelling is that you can run from the remote machine, effectively "pulling", say, admin files from a central admin server with appropriate credentials, rather than "pushing" out to every other machine. TJG From bgailer at gmail.com Wed Apr 30 19:08:05 2008 From: bgailer at gmail.com (bob gailer) Date: Wed, 30 Apr 2008 13:08:05 -0400 Subject: [python-win32] Will wmi can a command on remore host and get the return code In-Reply-To: <424b71ec0804300252y77ce2dfbxfce6091b0953cafa@mail.gmail.com> References: <424b71ec0804300252y77ce2dfbxfce6091b0953cafa@mail.gmail.com> Message-ID: <4818A775.2090201@gmail.com> An HTML attachment was scrubbed... URL: From javi at bertayjavi.com Tue Apr 29 13:26:06 2008 From: javi at bertayjavi.com (Javi) Date: Tue, 29 Apr 2008 13:26:06 +0200 Subject: [python-win32] Help about printing In-Reply-To: <4816D36B.6060705@bertayjavi.com> References: <4816D36B.6060705@bertayjavi.com> Message-ID: <481705CE.9010300@bertayjavi.com> Hello, i use python 2.5, and wx, i'm trying to print a bitmap with transparency background but it doesnt print right, i just get a preview right but when i printed it, bitmap transparency background is printed on black. I dont know why , but i need to print it right. All help will be welcome. Thanks. P.D: i tried to print the wxpython demo 2.8 and it happens the same, transparency background is printed on black.