[python-win32] can't set a property

2009-12-09 Thread John
Newbie here.  I  thought my question would have been a common one but I have 
checked the archive for the last year and only found one message even close.

I'm attempting to use a OCX designed to talk with QuickBooks.  I'm using 
win32com for the first time and have discovered an issue that I'm sure others 
have run into.  But researching google etc.  has not helped.

obj = win32com.client.Dispatch("InQB.Invoice.1")
#In the VB code 
#obj.ItemName(0) = 'string' 

#in python I'm trying 
obj.ItemName[0] = 'string'
#error is "Instancemethod object does not support item assignment"

I found and ran makepy.py and here is the code it created dealing with my obj.

# The method ItemName is actually a property, but must be used as a method
to correctly pass the arguments
def ItemName(self, ItemIndex=defaultNamedNotOptArg):
        """Line item property: Reference to the kind of item."""
        # Result is a Unicode object
        return self._oleobj_.InvokeTypes(19, LCID, 2, (8, 0), 
((3,1),),ItemIndex )

As I read the above code it can only return a string not assign anything. I'm 
not sure what "InvokeTypes" does.  And "defaultNamedNotOptArg" does not sound 
good.

Just for information the ItemName[0] is an array (I think not a Vb guy) of 
items on a invoice.  ItemName[0] would refer to the first line item on the 
invoice and ItemName[1] the second and ...

So the question is how can I get around this issue?  I'm sure others need to 
set properties (arrays/list) in com objects.

Thanks in advance,

Johnf
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] can't set a property

2009-12-09 Thread John
On Wednesday 09 December 2009 11:21:40 am Tim Roberts wrote:
> John wrote:
> > ...
> > I'm attempting to use a OCX designed to talk with QuickBooks.  I'm using
> > win32com for the first time and have discovered an issue that I'm sure
> > others have run into.  But researching google etc.  has not helped.
> >
> > obj = win32com.client.Dispatch("InQB.Invoice.1")
> > #In the VB code
> > #obj.ItemName(0) = 'string'
> >
> > #in python I'm trying
> > obj.ItemName[0] = 'string'
> > #error is "Instancemethod object does not support item assignment"
> > ...
> > Just for information the ItemName[0] is an array (I think not a Vb guy)
> > of items on a invoice.  ItemName[0] would refer to the first line item on
> > the invoice and ItemName[1] the second and ...
>
> Well, remember that ItemName is not really an array.  It's a function
> that happens to look like an array to VB.
>
> The Python COM support will usually provide Set and Get versions for
> indexed properties.  Try this:
> obj.SetItemName( 0, 'String' )

Wow Tim thanks that appears to work.  But to be honest I don't see where this 
code is located.  

Johnf


___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] unable to read mssql varchar(max)

2010-05-27 Thread John

Hi,

When a ms sql server database column was changed to varchar(max), my 
python code became unable to read that column.  no matter the actual 
value, python sees it as '\x00'.  I use sql server 2008, python 2.4, and 
pywin32-214.  it had worked when the column was a fixed size varchar, eg 
varchar(1000).  essentially my code is:


connectionString=r"driver={SQL Server Native Client 
10.0};server=...;uid=...;pwd=...;database=..."

connection=odbc.odbc(connectionString)
cursor=connection.cursor
cursor.execute("select ...")
cursor.fetchall()

Could anyone suggest what the problem might be?

Thanks,
John


___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] determine the default printer from RDP

2020-02-25 Thread john

Hi,

I need a way to determine the default printer (on the users computer) 
from a RDP session.


The user logs on to a RDP session and win32print.GetDefaultPrinter() 
returns a blank.  That makes sense on the RDP session because there 
aren't any default printers.  RDP printing is directed to the default 
printer on the users desktop.


Is there a way to get the default printer from the RDP session.

Johnf
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] determine the default printer from RDP

2020-02-26 Thread john
Thanks for the response - and yes I do have the printers checkbox - 
checked.  It returns a blank.


Johnf

On 2/26/20 8:48 AM, Terry Davis wrote:

Hi John,

In the Windows RDP client, under "Show Options" -> "Local Resources" 
-> section "Local devices and resources" is "Printers" checked?


I haven't tried what you're referring to, but perhaps that setting is 
relevant to your problem?


- Terry

On Tue, Feb 25, 2020 at 5:51 PM john <mailto:[email protected]>> wrote:


Hi,

I need a way to determine the default printer (on the users
computer) from a RDP session.

The user logs on to a RDP session and
win32print.GetDefaultPrinter() returns a blank.  That makes sense
on the RDP session because there aren't any default printers.  RDP
printing is directed to the default printer on the users desktop.

Is there a way to get the default printer from the RDP session.

Johnf
___
python-win32 mailing list
[email protected] <mailto:[email protected]>
https://mail.python.org/mailman/listinfo/python-win32



___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] determine the default printer from RDP

2020-02-26 Thread john
I was able to discover that a powershell command does in fact find the 
correct default printer.



powershell.exe -command "& {(Get-WmiObject -class win32_printer | where 
{$_.default -eq $true}).name}"

or
 Get-WmiObject -query "SELECT * FROM WIN32_PRINTER WHERE Default = TRUE"


is there something in python-win32 I can do to get the same results.

Johnf

On 2/26/20 8:48 AM, Terry Davis wrote:

Hi John,

In the Windows RDP client, under "Show Options" -> "Local Resources" 
-> section "Local devices and resources" is "Printers" checked?


I haven't tried what you're referring to, but perhaps that setting is 
relevant to your problem?


- Terry

On Tue, Feb 25, 2020 at 5:51 PM john <mailto:[email protected]>> wrote:


Hi,

I need a way to determine the default printer (on the users
computer) from a RDP session.

The user logs on to a RDP session and
win32print.GetDefaultPrinter() returns a blank.  That makes sense
on the RDP session because there aren't any default printers.  RDP
printing is directed to the default printer on the users desktop.

Is there a way to get the default printer from the RDP session.

Johnf
___
python-win32 mailing list
[email protected] <mailto:[email protected]>
https://mail.python.org/mailman/listinfo/python-win32



___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] determine the default printer from RDP

2020-02-27 Thread john

I have discovered a solution to the issue.
import wmi
c = wmi.WMI()
 wql = "SELECT * FROM WIN32_PRINTER WHERE Default = TRUE"

 for printer in c.query(wql):
    selectedPrinter = printer.caption

where selectPrinter is the device name of the printer.

Hope this helps somebody in the future.

Johnf

On 2/26/20 8:48 AM, Terry Davis wrote:

Hi John,

In the Windows RDP client, under "Show Options" -> "Local Resources" 
-> section "Local devices and resources" is "Printers" checked?


I haven't tried what you're referring to, but perhaps that setting is 
relevant to your problem?


- Terry

On Tue, Feb 25, 2020 at 5:51 PM john <mailto:[email protected]>> wrote:


Hi,

I need a way to determine the default printer (on the users
computer) from a RDP session.

The user logs on to a RDP session and
win32print.GetDefaultPrinter() returns a blank.  That makes sense
on the RDP session because there aren't any default printers.  RDP
printing is directed to the default printer on the users desktop.

Is there a way to get the default printer from the RDP session.

Johnf
___
python-win32 mailing list
[email protected] <mailto:[email protected]>
https://mail.python.org/mailman/listinfo/python-win32



___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] A question about custom command options in win32serviceutil

2008-09-02 Thread John Bunting
Hey everyone,

I'm creating a program for my work that will let the users automatically
connect to a server that we have set up and read some data, etc.

I have been trying to figure out a way to use the win32serviceutil custom
options to pass some extra arguments for my users.

as far as I understand it, you have to use a custom function (I think) to
deal with all of your extra arguments that it doesn't recognize.

I would like to be able to apply to my windows class these extra arguments,
as they will just be used to pass data! is it correct in assuming

that i should probably set it up like this...


class service(win32service.ServiceFramework):
def __init__(self):
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] A question about custom command options in win32serviceutil

2008-09-02 Thread John Bunting
sorry pressed enter too soon

Am i just setting up a function to parse the arguments and set class
variables? or is it something else!

Sorry for the double email >.<

~John Bunting

On Tue, Sep 2, 2008 at 1:25 PM, John Bunting <[EMAIL PROTECTED]> wrote:

> Hey everyone,
>
> I'm creating a program for my work that will let the users automatically
> connect to a server that we have set up and read some data, etc.
>
> I have been trying to figure out a way to use the win32serviceutil custom
> options to pass some extra arguments for my users.
>
> as far as I understand it, you have to use a custom function (I think) to
> deal with all of your extra arguments that it doesn't recognize.
>
> I would like to be able to apply to my windows class these extra arguments,
> as they will just be used to pass data! is it correct in assuming
>
> that i should probably set it up like this...
>
>
> class service(win32service.ServiceFramework):
> def __init__(self):
>
>
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Adding an exe to startup...

2008-09-16 Thread John Bunting
Hey everyone,

I've been having some trouble finding information on how to add an exe that
I have created to the startup of my windows box.  I would like to know how I
should go about adding the exe to the startup menu, without using the gui
interface.  I want to be able to automate this because I'm also going to be
giving out some of this code to different users and I don't want to have to
have them manually add the exe.

Thank alot everyone,


~John
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] [Fwd: Re: Problems installing pywin32]

2009-01-18 Thread John Machin

my reply to the OP went him alone, not the list ... sorry.
--- Begin Message ---
Thank you very much John.

Somehow the first thing I came across while searching a python
implementation for win32ras was the source code. When I tried to run it a
message was printed requesting a vs2003 installation.

Anyway, using your advice I found the regular installer and so far it seems
to do well.

Thanks again,

Yaron

On Sun, Jan 18, 2009 at 2:18 PM, John Machin  wrote:

> On 18/01/2009 10:26 PM, Yaron Charka wrote:
>
>> Hi,
>>
>> I'm trying to install pywin32 on an XP machine.
>>
>
> The usual way of *installing* pywin32 so that you can use it is to download
> the installer that is (a) from the latest build and (b) appropriate to the
> version of Python that you are going to use it with (e.g.
> pywin32-212.win32-py2.5.exe) and just run that installer. Do you *really*
> want to compile it from source?
>
>  I was first requested to install vs2003 which I couldn't find.
>>
>
> *What* requested you to install VS2003?
>
>
>  Installing vs2008 didn't solve the problem either.
>>
>> I tried another way and installed mingw32. That seemed to take me a bit
>> further, but not so much...
>>
>
>
>
--- End Message ---
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] AddMembershipRule(SMS_CollectionRuleDirect): Generic failure

2009-04-17 Thread John Randolph
Hi list:

I've been beating my head against this problem for 2 days and can't
figure it out.  Searching the archives produced a semi-relevant thread
from the past but the former fixes haven't worked for me.

Using wmi 1.3.2, I've got the following simple code:

system = wmih.SMS_R_System(NetbiosName=hostname)
new_rule = wmih.SMS_CollectionRuleDirect.new()
new_rule.ResourceID = system[0].ResourceID
new_rule.RuleName = '%s (%d)' % (hostname, system[0].ResourceID)
new_rule.ResourceClassName = 'SMS_R_System'
query_id, rv = c.AddMembershipRule(new_rule)

I've also tried getting the method InParameters, populating them and
calling the method directly as previous list traffic experimented
with.

However, neither method allows me to add the rule.   The code above
produces the following exception:

  File "remotewmi.py", line 115, in PolicyInstall
query_id, rv = c.AddMembershipRule(new_rule)
  File "C:\Documents and Settings\jrand\wmi.py", line 396, in __call__
handle_com_error (error_info)
  File "C:\Documents and Settings\jrand\wmi.py", line 189, in handle_com_error
raise x_wmi, "\n".join (exception_string)
wmi.x_wmi: -0x7ffdfff7 - Exception occurred.
  Error in: SWbemObjectEx
  -0x7ffbefff - Generic failure
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] AddMembershipRule(SMS_CollectionRuleDirect): Generic failure

2009-04-17 Thread John Randolph
On Fri, Apr 17, 2009 at 4:59 PM, John Randolph  wrote:
snip
> wmi.x_wmi: -0x7ffdfff7 - Exception occurred.
>  Error in: SWbemObjectEx
>  -0x7ffbefff - Generic failure
>

(er, message got cut off)

anyway, enabling verbose WMI logging didn't produce anything revealing.
anyone have any tips?

Regards
John
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] AddMembershipRule(SMS_CollectionRuleDirect): Generic failure

2009-04-17 Thread John Randolph
On Fri, Apr 17, 2009 at 5:28 PM, Tim Golden  wrote:
>
> The first suggests a delay might help. The second doesn't come to
> any conclusion except that if the last poster got it working then
> it's something a bit environmental. Try the delay, perhaps.
> FWIW, the WMI code probably isn't calling Put_ on your
> newly-created object, because it (probably) doesn't
> have a Path_ -- it hasn't come off the WMI database.
> According to the example at:
>
>  http://msdn.microsoft.com/en-us/library/ms815919.aspx
>
> that's correct. But just in case it makes a difference
> you can try calling new_rule.Put_ () before you add it
> to the collection. My feeling is that it will fail but
> YMMV.

Hi, thanks for your reply.

Actually I had previously placed a delay between the new_rule creation
and calling AddMembershipRule for another reason -- to make a clear
break in the timestamps on the server side wmi logs.  Unfortunately
the delay doesn't help.

Adding a Put_ gave me a different error, "Attempt to put an instance
with no defined key."   Sensible enough error.

Not sure where to go from here, really.  I've been unable to cough up
anything interesting on the server side, and I'm not very windows or
sms savvy.

Regards,
John


>
> I'm afraid I'm not at all familiar with SMS and I'm certainly
> nowhere near an installation, so it's hard for me to test or
> reproduce the issue. Feel free to post back and I'm happy
> to diagnose at a distance or to produce debug probes in the
> WMI code itself.
>
> TJG
> ___
> python-win32 mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-win32
>
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] AddMembershipRule(SMS_CollectionRuleDirect): Generic failure

2009-04-21 Thread John Randolph
On Sat, Apr 18, 2009 at 8:09 PM, Tim Golden  wrote:
> John Randolph wrote:
>
>> Actually I had previously placed a delay between the new_rule creation
>> and calling AddMembershipRule for another reason -- to make a clear
>> break in the timestamps on the server side wmi logs.  Unfortunately
>> the delay doesn't help.
>
> Shame.
>
>> Adding a Put_ gave me a different error, "Attempt to put an instance
>> with no defined key."
>
> As I expected.
>
>> Not sure where to go from here, really.
>
> Me neither, I'm afraid. I'm more than happy to help
> on the Python-WMI front, but outside that I'd be
> playing guessing games with the SMS side of things.
>
> TJG
>

Tim,

is there any more debugging info I can gain on the python wmi side?
I tried setting debug=True but that gives minimal info, mostly wsql
queries during object selection, etc.

Regards
John
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] AddMembershipRule(SMS_CollectionRuleDirect): Generic failure

2009-05-11 Thread John Randolph
On Tue, Apr 21, 2009 at 3:52 PM, Tim Golden  wrote:
>>>> Actually I had previously placed a delay between the new_rule creation
>>>> and calling AddMembershipRule for another reason -- to make a clear
>>>> break in the timestamps on the server side wmi logs.  Unfortunately
>>>> the delay doesn't help.

Tim, all:

My "Generic Failure" error when calling AddMembershipRule(new rule)
turned out to be permissions related.  My local Windows admins have
segregated read and write access into two groups and my role account
didn't have write access.   oops.

Unfortunately I learned no further details on how to decode "Generic
failure" into "Bad permissions" for the list, though, sorry.   The WMI
service logs look clean so you probably need to dive into the SMS
logs.

Thanks
John
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] [pygtk] ANN: PyGUI 2.1

2009-11-15 Thread John Finlay

Greg Ewing wrote:

John Finlay wrote:
  

Greg,

Why do you post to mailing lists that are unrelated to your project? I 
would appreciate it if in future you didn't post a message about your 
project ot the PyGTK mailing list.



I posted the announcement to the pyobjc, pygtk and pywin32
lists because PyGUI uses all of those libraries, and because
I don't know of any single mailing list where people interested
in Python GUIs in general can be found.

However, if the consensus is that PyGUI announcements are
not welcome on those lists, I will be happy to cease posting
them there.

What is the general feeling out there? Should I stop posting
PyGUI messages to these lists? Is there another GUI-related
list that would be more appropriate?

  

Start your own list for the community that is interested in your project.

John
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] pywin32-214 DLL install error

2010-07-21 Thread Freking John
Hi,
I'm running  XP SP3 and  Python 2.6.2 and I'm trying to install  pywin32-214 
but it fails to load a DLL.  The following is the error message I get at the 
end of the install.

Traceback (most recent call last):
  File "", line 601, in 
  File "", line 313, in install
ImportError: DLL load failed: The specified module could not be found.

When I try to use the module in a python program I get the following error.

Traceback (most recent call last):
  File "C:\WorkArea\Python\excel2007", line 2, in 
import win32com.client as win32
  File "C:\Python26\lib\win32com\__init__.py", line 5, in 
import win32api, sys, os
ImportError: DLL load failed: The specified module could not be found.
>>>

I have tried to uninstall and reinstall install pywin32 but that didn't work. 
And I have tried  moving two DLLs, Pythoncom26.dll and PyWinTypes26.dll, into 
the system32 directory which also didn't work.

Thanks,
John Freking
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] pywin32-214 DLL install error

2010-07-25 Thread Freking John
Paul,
Thanks that worked great.

But, I don't understand what you mean by the import hook doesn't work properly. 
 The .pyd files were in the site-packages subfolders so why couldn't Python 
find them?

Thanks,
John Freking

From: Paul Keating [mailto:[email protected]]
Sent: Saturday, July 24, 2010 6:26 AM
To: Freking John
Subject: Re: [python-win32] pywin32-214 DLL install error

You're on the right track with your focus on .dlls but I'd say the loader can't 
find a .pyd (which is a .dll really) that win32api wants. A brute-force 
solution is to search for win32*.pyd and *winxp*.pyd in python26 and subtree 
(which will be in site-packages\win32 and site-packages\pythonwin), and copy 
them next to python.exe. It should be a total of 30 files.

This is klugy and ugly but it may work. (It's also easy to back out if it 
doesn't work!)

I support an embedded-Python environment where the vendor's import hook that 
doesn't quite work properly with packages, so I have to do that routinely.

If it does work then you can ask again here for a tidier solution.

Paul Keating

- Original Message -
From: Freking John<mailto:[email protected]>
To: '[email protected]'
Sent: Thursday, July 22, 2010 5:01 AM
Subject: [python-win32] pywin32-214 DLL install error

Hi,
I'm running  XP SP3 and  Python 2.6.2 and I'm trying to install  pywin32-214 
but it fails to load a DLL.  The following is the error message I get at the 
end of the install.

Traceback (most recent call last):
  File "", line 601, in 
  File "", line 313, in install
ImportError: DLL load failed: The specified module could not be found.

When I try to use the module in a python program I get the following error.

Traceback (most recent call last):
  File "C:\WorkArea\Python\excel2007", line 2, in 
import win32com.client as win32
  File "C:\Python26\lib\win32com\__init__.py", line 5, in 
import win32api, sys, os
ImportError: DLL load failed: The specified module could not be found.
>>>

I have tried to uninstall and reinstall install pywin32 but that didn't work. 
And I have tried  moving two DLLs, Pythoncom26.dll and PyWinTypes26.dll, into 
the system32 directory which also didn't work.

Thanks,
John Freking

___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com client Workbooks.Open throws exeption

2010-08-18 Thread John Machin

On 19/08/2010 4:00 AM, Tim Roberts wrote:

 @©ħα® wrote:

Workbooks.Open fails randomly throws an exception
...
calling logToXLS() occasionally throws the mentioned error at

xl.Workbooks.Open(filePath)

 File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py",

line 496, in
__getattr__
   raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: Excel.Application.Workbooks


1)is there any limitation on number of characters on filepath?
2)How this issue can be overcome?


That's not saying that the Open call failed.  That's saying that the
Workbooks object did not contain a function called "Open", which is much
stranger.  Have you used makepy on the Office components to create
wrappers for them?  Is this running in an application or in a service? 
Is it possible, when this happens, that your user already has Excel open

doing something else?  (Although I don't quite know how that would lead
to this.)



Tim: I think it's saying that Excel.Application does not have an 
attribute "Workbooks", which is equally strange.


OP: Which build of pywin32 are you running? Have you tried a later build?

___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Creating PyCComboBox?

2011-06-11 Thread John Sheehan
Just my opinion, but if anyone decides to create a combo box, the one that  
has been part of MS Access since at least version 2.0 would be the one to  
model it after.  I have yet to see any combo box in any  
language/platform/application that has worked as well as that one does.


John Sheehan



On Sat, 11 Jun 2011 09:09:06 -0700, Vernon Cole   
wrote:


I've been intending to make enough time to create a combobox for PyGUI.   
In
my humble opinion, the combobox provided by Windows GUI is brain damaged  
to

the point of utter frustration and should not be used for human
consumption.  I sent an epistle to this effect to the wxpython group, and
got the answer "that's what the OS provides."
  The problem is that the Windows combobox does not allow for the user to
type more than one letter to select an item from the list -- there is no
provision for matching to a substring. Let's say that I am trying to  
select

"Wisconsin" from a list of states of the U.S.  I type the "W" and get
"Washington". Then I type the "I" and get "Idaho".  Most frustrating.   
If I
am trying to select "1950" from a list of acceptable years, I must use  
the

mouse, or scroll down 50 times from "1900". Yech!
  I think that a proper combobox will have to be coded at a higher  
level.  I

hope I'm wrong.
--
Vernon Cole

___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] windows service problem and twisted

2011-10-14 Thread John Aherne
I did post this to the twisted list but as I said in the original post, I
think it is more a windows type issue than twisted.

What I am trying to work out is should I import twisted.reactor etc inside
the thread start in SvcDoRUn or import it globally as one of the examples
does.

And then should I be calling the reactor.fromthread in the SvcStop function.

If I import reactor in SvcDoRun will the SvcStop be called in the same
thread or not.

One of the examples import reactor globally, starts the reactor in SvcDoRun
- inside the thread -  and in SvcStop, calls the reactorfromthread. This to
me implies that SvcStop is in a different thread to SvcDoRun. But I could be
completely wrong on this point.

As you can see I am a little bit confused about what is happening here.


I have been looking for some info on running twisted as a Windows Service.

I have found various examples in mailing-lists and blogs that vary in what
seem to be important respects.

I have included them below as 3 examples.

The problem I have is working out which scheme or combination I should be
adopting.
I have tried out some of the options and they appear to work. But I need
something better than seems to work.

My gut reaction is that I should be putting all my imports into SvcDoRun,
since they will be used in the thread.

But if I import the reactor in SvcDoRun, should I be
using reactor.callfromthread(reactor.stop). I think not

I think the use of waitforobject is the right thing to do as well without
fully understanding it at the moment.

If anyone can throw some light on what to do I shall be very grateful.

It could be that I should post this question to python-windows mailing
list since it seems to me more pertinent to windows than twisted.

Thanks for any info.

John Aherne

Here is 1st example.

The reactor is imported globally not in SvcDoRun
It uses the waitforobject to detect stopping the service
The reactor.stop is calledfromthread


[Twisted-Python] How to run Twisted as a service in Windows?

Thomas Jacob jacob at internet24.de
Wed Aug 9 10:49:30 EDT 2006
Previous message: [Twisted-Python] How to run Twisted as a service in
Windows?
Next message: [Twisted-Python] How to run Twisted as a service in Windows?
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
AFAIK, twistd doesn't provide direct support for Windows Services yet
(Is this planned?).

But you can easily wrap a reactor,run() yourself by doing something
like the following using the Win32-Python packages

import win32serviceutil
import win32service
import win32event

from twisted.internet import reactor

import sys


class IMSAgentBase(win32serviceutil.ServiceFramework):
_svc_name_ = "myService"
_svc_display_name_ = "My little Service"
_svc_description_ = "My little Service" # Win2k or later
_svc_deps_ = ["RpcSs"] # Start after the Network has come up...

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
reactor.callFromThread(reactor.stop)
win32event.SetEvent(self.hWaitStop)

def SvcDoRun(self):

# initialize your services here
reactor.run()
win32event.WaitForSingleObject(self.hWaitStop,win32event.INFINITE)

def HandleCommandLine(cls):
win32serviceutil.HandleCommandLine(cls)


Run the above as a script.


Here is the 2nd example.

The imports are global not in SvcDoRun

And the reactor .stop is not called from thread.

And the wait for stop event is in a timeout loop

It uses waitforobject events

It sets installsignalhandlers to 0

 You can then test it out with the sample Echo client from the core docs.

 """qotdservice.py
 Sample Twisted Windows Service
 """

 # Service Utilities
 import win32serviceutil
 import win32service
 import win32event

 # Twisted imports
 from twisted.internet.protocol import Protocol, Factory
 from twisted.internet import reactor

 class QOTD(Protocol):

 def connectionMade(self):
 self.transport.write("An apple a day keeps the doctor away\r\n")
 self.transport.loseConnection()


 class WindowsService(win32serviceutil.ServiceFramework):
 _svc_name_ = "TwistedWin32Service"
 _svc_display_name_ = "Twisted Win32 Service"

 def __init__(self, args):
 win32serviceutil.ServiceFramework.__init__(self, args)
 self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

 def SvcStop(self):
 self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
 win32event.SetEvent(self.hWaitStop)

 def SvcDoRun(self):
 import servicemanager

 self.CheckForQuit()

 factory = Factory()
 factory.protocol = QOTD

 reactor.listenTCP(8007, factory)
 reactor.run

Re: [python-win32] windows service problem and twisted

2011-10-14 Thread John Aherne
On Fri, Oct 14, 2011 at 12:51 PM, Mark Hammond wrote:

> On 14/10/2011 7:47 PM, John Aherne wrote:
> ...
>
>  What I am trying to work out is should I import twisted.reactor etc
>> inside the thread start in SvcDoRUn or import it globally as one of the
>> examples does.
>>
>
> Dunno - does the example work?  If it does, then "yes" but if it doesn't,
> then "maybe not" :)
>
>
>  And then should I be calling the reactor.fromthread in the SvcStop
>> function.
>>
>
> It has been a few years since I've used twisted, but I can't recall what
> that does.
>
>
>  If I import reactor in SvcDoRun will the SvcStop be called in the same
>> thread or not.
>>
>
> Where you do the import doesn't impact this specific question; SvcStop will
> be almost certainly be called on a different thread than the main thread
> (ie, I'm pretty sure Windows itself always calls this on a different thread
> - python/pywin32/twisted have no say in this).
>
>
>  One of the examples import reactor globally, starts the reactor in
>> SvcDoRun - inside the thread -  and in SvcStop, calls the
>> reactorfromthread. This to me implies that SvcStop is in a different
>> thread to SvcDoRun. But I could be completely wrong on this point.
>>
>
> You are correct - it will be a different thread.  But I think that the
> "run" function will be called on the same thread as the module import, so
> exactly when you import the twisted stuff probably doesn't matter - it
> sounds like you are just looking for a way to stop the reactor from a
> different thread (ie, from the SvcStop thread)?
>
>
>
>> As you can see I am a little bit confused about what is happening here.
>>
>>
>> I have been looking for some info on running twisted as a Windows Service.
>>
>> I have found various examples in mailing-lists and blogs that vary in
>> what seem to be important respects.
>>
>> I have included them below as 3 examples.
>>
>> The problem I have is working out which scheme or combination I should
>> be adopting.
>> I have tried out some of the options and they appear to work. But I need
>> something better than seems to work.
>>
>> My gut reaction is that I should be putting all my imports into
>> SvcDoRun, since they will be used in the thread.
>>
>
> Nope - the "top level" imports and the "run" function are almost certainly
> the same thread, and the "stop" function will be called on a thread created
> by Windows - but thread.get_ident() will tell you for sure.
>
> Hope this helps - but if you still have problems, post the shortest
> possible thing that doesn't work as you expect and I might be able to help
> more...
>
> Mark
>
>
>> But if I import the reactor in SvcDoRun, should I be
>> using reactor.callfromthread(**reactor.stop). I think not
>>
>> I think the use of waitforobject is the right thing to do as well
>> without fully understanding it at the moment.
>>
>> If anyone can throw some light on what to do I shall be very grateful.
>>
>> It could be that I should post this question to python-windows mailing
>> list since it seems to me more pertinent to windows than twisted.
>>
>> Thanks for any info.
>>
>> John Aherne
>>
>> Here is 1st example.
>>
>> The reactor is imported globally not in SvcDoRun
>> It uses the waitforobject to detect stopping the service
>> The reactor.stop is calledfromthread
>>
>>
>> [Twisted-Python] How to run Twisted as a service in Windows?
>>
>> Thomas Jacob jacob at internet24.de <http://internet24.de/>
>>
>> Wed Aug 9 10:49:30 EDT 2006
>> Previous message: [Twisted-Python] How to run Twisted as a service in
>> Windows?
>> Next message: [Twisted-Python] How to run Twisted as a service in Windows?
>> Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>> AFAIK, twistd doesn't provide direct support for Windows Services yet
>> (Is this planned?).
>>
>> But you can easily wrap a reactor,run() yourself by doing something
>> like the following using the Win32-Python packages
>>
>> import win32serviceutil
>> import win32service
>> import win32event
>>
>> from twisted.internet import reactor
>>
>> import sys
>>
>>
>> class IMSAgentBase(win32serviceutil.**ServiceFramework):
>> _svc_name_ = "myService"
>> _svc_display_name_ = "My little Service"
>> _svc_description_ = "My little Service" 

[python-win32] Query related to Python

2012-01-26 Thread amy john
Hi,

My name is Nupur Jha. I have one query related to Python.

[1] I would like to know if we update any python file then while
saving it can we extract the updated line and paste in excel.

[2] If so what all we are suppose to do.

I will be thankful if I will get a positive reply from your side.

Thanks & Regards
Nupur Jha
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Casting to IRTDUpdateEvent object

2012-04-06 Thread John S
I'm trying to implement excelRTDserver.py (
http://www.math.uiuc.edu/~gfrancis/illimath/windows/aszgard_mini/movpy-2.0.0-py2.4.4/movpy/lib/win32com/demos/excelRTDServer.py).
I'm running Excel 2010 (32bit) so I change the EXCEL_TLB_MINOR value to 7.
The add-in is visible in the Excel add-ins list and if I enter
=RTD("Python.RTD.TimeServer","","seconds","5") into a cell, I get the
current time. But it never updates. If I change the "5" to another number,
I get an update but after the initial change it never updates.

I've isolated the problem to an exception raised when the callback object
returned by Excel is attempted to be cast into a IRTDUpdateEvent object.
This was discussed on this list previously (
http://mail.python.org/pipermail/python-win32/2011-March/011324.html) but
no solution. I tried the suggested solution of using CastTo, but when
EnsureDispatch is called within gencache.py it raises the exception at the
first line within the try statement (ti = disp._oleobj_.GetTypeInfo()).

So my question is how do I get the callback object to work? Any help would
be greatly appreciated.
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] hook to obtain WM_GESTURE

2013-05-09 Thread John Grant
Hi,

I would like to obtain multi-touch events in my Python code (running inside
Blender's python environment). I have looked around the web for a python
module that works with py 3.3 (others work with py 2.x), but I have not
found one. So, I'm trying to build one.

I believe I can use the 'ctypes' to call the function I need,
GetGestureInfo. This function requires 2 parameters as input, the lParam
from WndProc and a pointer to the GESTUREINFO structure.

* I hope I can use 'ctypes' to declare the GESTUREINFO structure in my
python code.*
I see it is possible to pass structures as pointers using ctypes as well.

*** The problem seems to be obtaining the lParam from WndProc. ***

My idea is to provide a callback function (again using ctypes to declare
this callback) and use the SetWindowsHookEx function, passing my callback
and the WH_CALLWNDPROC hook ID.

Does this sound like it will work? I read somewhere that my callback needs
to be in a DLL. I'm not sure if the Blender python environment will count
as existing in a DLL. I hope I will not need to learn how to build a python
module from a C DLL just to put the callback in a DLL.



I signed up for the ML here because it seems like this is the best place
for Windows expertise concerning Python. I saw a few emails on this list
about hooks and callbacks. I've used the IDE with pywin32 for years - its
the best!

Many thanks for any help on this critical task for my 1st python consulting
gig.

John
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] hook to obtain WM_GESTURE

2013-05-09 Thread John Grant
Hi Tim,

Thanks for the great explanations.

Yes, you are right, I am trying to intercept gestures in a window within
the same process. The Blender application framework has a WndProc in C, and
Blender supports extending itself with user-supplied Python scripts. I am
trying to add gesture support with Python so I can avoid modifying the
Blender C code.

I'm reading through the wxPython article. It looks like a perfect fit for
my problem. It shows everything I need to do, and using ctypes! Thanks!

Although, I am stuck trying to get the HWND from Blender. It seems they
have not exposed the handle yet. I'm looking for win32 API that might
provide it to me, or a list of windows associated with the process.

I guess I have to remove my callback as soon as the WM_DESTROY message is
emitted, and reinstantiate the oldWndProc. That makes sense. I'm glad that
is shown in the article.

I just browsed the Blender C source code and they also use
"SetWindowLongPtr" for GWLP_USERDATA, but not for GWLP_WNDPROC. I think
everything will work out fine when I find the HWND.

Thanks for the expert help.
John


On Thu, May 9, 2013 at 9:46 AM, Tim Roberts  wrote:

> John Grant wrote:
> >
> > I would like to obtain multi-touch events in my Python code (running
> > inside Blender's python environment). I have looked around the web for
> > a python module that works with py 3.3 (others work with py 2.x), but
> > I have not found one. So, I'm trying to build one.
> >
> > I believe I can use the 'ctypes' to call the function I need,
> > GetGestureInfo.
>
> That gets you gestures, but not multitouch.  If all you need is the
> zoom, pan and rotate gestures and a two-finger tap, this will do it.
> For more complicated gestures, most solutions are custom right now.
>
>
> > This function requires 2 parameters as input, the lParam from WndProc
> > and a pointer to the GESTUREINFO structure.
> >
> > * I hope I can use 'ctypes' to declare the GESTUREINFO structure in my
> > python code.*
> > I see it is possible to pass structures as pointers using ctypes as well.
>
> The structure doesn't have any pointers, so this should be straightforward.
>
>
> > *** The problem seems to be obtaining the lParam from WndProc. ***
> >
> > My idea is to provide a callback function (again using ctypes to
> > declare this callback) and use the SetWindowsHookEx function, passing
> > my callback and the WH_CALLWNDPROC hook ID.
> >
> > Does this sound like it will work?
>
> No, a Windows hook is the wrong answer.  That lets you intercept
> messages from other processes (which is why hooks need to be in a DLL --
> the DLL actually gets copied and injected into the processes being
> hooked).  In your case, I assume you're trying to intercept gestures in
> a window within your own process.  Is that right?  As long as you have
> the window handle, all you need to do is subclass the window.  That
> means you make yourself the wndproc for that window, so you get first
> shot at all the messages.
>
> Here's an example that shows how to do this in wxPython, but you can
> eliminate the wxPython part of it.  The key point is using
> win32gui.SetWindowLong to load your own function in
> win32con.GWL_WNDPROC, and remembering the return value so you can call
> the original function.
> http://wiki.wxpython.org/HookingTheWndProc
>
> --
> Tim Roberts, [email protected]
> Providenza & Boekelheide, Inc.
>
> ___
> python-win32 mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-win32
>
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] hook to obtain WM_GESTURE

2013-05-09 Thread John Grant
I believe found access to the HWND.
mHWND = ctypes.windll.user32.GetActiveWindow()



On Thu, May 9, 2013 at 11:13 AM, John Grant  wrote:

> Hi Tim,
>
> Thanks for the great explanations.
>
> Yes, you are right, I am trying to intercept gestures in a window within
> the same process. The Blender application framework has a WndProc in C, and
> Blender supports extending itself with user-supplied Python scripts. I am
> trying to add gesture support with Python so I can avoid modifying the
> Blender C code.
>
> I'm reading through the wxPython article. It looks like a perfect fit for
> my problem. It shows everything I need to do, and using ctypes! Thanks!
>
> Although, I am stuck trying to get the HWND from Blender. It seems they
> have not exposed the handle yet. I'm looking for win32 API that might
> provide it to me, or a list of windows associated with the process.
>
> I guess I have to remove my callback as soon as the WM_DESTROY message is
> emitted, and reinstantiate the oldWndProc. That makes sense. I'm glad that
> is shown in the article.
>
> I just browsed the Blender C source code and they also use
> "SetWindowLongPtr" for GWLP_USERDATA, but not for GWLP_WNDPROC. I think
> everything will work out fine when I find the HWND.
>
> Thanks for the expert help.
> John
>
>
> On Thu, May 9, 2013 at 9:46 AM, Tim Roberts  wrote:
>
>> John Grant wrote:
>> >
>> > I would like to obtain multi-touch events in my Python code (running
>> > inside Blender's python environment). I have looked around the web for
>> > a python module that works with py 3.3 (others work with py 2.x), but
>> > I have not found one. So, I'm trying to build one.
>> >
>> > I believe I can use the 'ctypes' to call the function I need,
>> > GetGestureInfo.
>>
>> That gets you gestures, but not multitouch.  If all you need is the
>> zoom, pan and rotate gestures and a two-finger tap, this will do it.
>> For more complicated gestures, most solutions are custom right now.
>>
>>
>> > This function requires 2 parameters as input, the lParam from WndProc
>> > and a pointer to the GESTUREINFO structure.
>> >
>> > * I hope I can use 'ctypes' to declare the GESTUREINFO structure in my
>> > python code.*
>> > I see it is possible to pass structures as pointers using ctypes as
>> well.
>>
>> The structure doesn't have any pointers, so this should be
>> straightforward.
>>
>>
>> > *** The problem seems to be obtaining the lParam from WndProc. ***
>> >
>> > My idea is to provide a callback function (again using ctypes to
>> > declare this callback) and use the SetWindowsHookEx function, passing
>> > my callback and the WH_CALLWNDPROC hook ID.
>> >
>> > Does this sound like it will work?
>>
>> No, a Windows hook is the wrong answer.  That lets you intercept
>> messages from other processes (which is why hooks need to be in a DLL --
>> the DLL actually gets copied and injected into the processes being
>> hooked).  In your case, I assume you're trying to intercept gestures in
>> a window within your own process.  Is that right?  As long as you have
>> the window handle, all you need to do is subclass the window.  That
>> means you make yourself the wndproc for that window, so you get first
>> shot at all the messages.
>>
>> Here's an example that shows how to do this in wxPython, but you can
>> eliminate the wxPython part of it.  The key point is using
>> win32gui.SetWindowLong to load your own function in
>> win32con.GWL_WNDPROC, and remembering the return value so you can call
>> the original function.
>> http://wiki.wxpython.org/HookingTheWndProc
>>
>> --
>> Tim Roberts, [email protected]
>> Providenza & Boekelheide, Inc.
>>
>> ___
>> python-win32 mailing list
>> [email protected]
>> http://mail.python.org/mailman/listinfo/python-win32
>>
>
>
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] hook to obtain WM_GESTURE

2013-05-09 Thread John Grant
Hi Tim, et al,

I am testing the ctypes technique to intercept messages for my process, as
Tim pointed out I need to do using the SetWindowsLongPtr function.

I am seeing slightly unexpected results. My goal was to make a pass-through
implementation, so my callback does not disrupt the application. I wanted
to print to the shell to show my callback was involved. I am seeing print
statements, but the behavior of the application is slightly different.
Reverse mouse wheel seems to behave differently in the application. Also,
sometimes I see an exception in the shell (OSError: exception...access
violation reading 0xblahblah).

Does anyone see an error with the way I am calling the "oldWndProc" or the
print statement in the code below? Maybe the way I have defined the return
argument for SetWindowLongPtrW is incorrect?

Thanks for any help,
John


from ctypes import *
import ctypes
import ctypes.wintypes
from ctypes import c_long, c_int

# some shortcut definitions
GetActiveWindow = windll.user32.GetActiveWindow
GetActiveWindow.restype = ctypes.wintypes.HWND

LRESULT = ctypes.wintypes.LPARAM
WNDPROC = WINFUNCTYPE(LRESULT, ctypes.wintypes.HWND, ctypes.wintypes.UINT,
ctypes.wintypes.WPARAM, ctypes.wintypes.LPARAM)

SetWindowLongPtrW = ctypes.windll.user32.SetWindowLongPtrW
SetWindowLongPtrW.restype = WNDPROC

CallWindowProc = ctypes.windll.user32.CallWindowProcW
CallWindowProc.restype = LRESULT

#proc type
GWL_WNDPROC = int(-4)

#msg types in case we need them
WM_DESTROY = int('0x0002', 16)
WM_KEYDOWN = int('0x0100', 16)
WM_SIZE = int('0x0005', 16)
WM_CLOSE = int('0x0010', 16)
WM_GESTURE = int('0x0119', 16)
WM_TOUCH = int('0x0240', 16)
WM_GESTURENOTIFY = int('0x011A', 16)
WM_TIMER = int('0x0113', 16)
WM_MOUSEMOVE = int('0x0200', 16)
WM_MOUSEWHEEL = int('0x020A', 16)
WM_KEYUP = int('0x0101', 16)
WM_KEYDOWN = int('0x0101', 16)

# middle mouse button from GetAsyncKeyState()
VK_MBUTTON = int('0x04',16)


#  Multi Touch Support Class --- #
# you should have only one instance of this class per OS window,
# because it adds a member function as the Windows message handler for the
hWnd passed.
class MTHandler(object):
def __init__(self, hWnd):
self.mHWND = hWnd
self.newWndProc = WNDPROC(self.MyWndProc)
self.oldWndProc = SetWindowLongPtrW(self.mHWND, GWL_WNDPROC,
self.newWndProc)
self.inControl = True

def _mouse_handler(self, msg, wParam, lParam):
print('hello mouse move')

def _gesture_handler(msg, wParam, lParam):
print('hello gesture')

def _touch_handler(msg, wParam, lParam):
print('hello touch')

def MyWndProc(self, hWnd, msg, wParam, lParam):
print('hello wndproc', msg, wParam, lParam)

#if (msg == WM_MOUSEMOVE) or (msg==WM_MOUSEWHEEL):
#_mouse_handler(msg, wParam, lParam)

#elif msg == WM_GESTURE:
#_gesture_handler(msg, wParam, lParam)

#elif msg == WM_TOUCH:
#_touch_handler(msg, wParam, lParam)

# source:
# http://wiki.wxpython.org/HookingTheWndProc
#
# Restore the old WndProc.  Notice the use of wxin32api
# instead of win32gui here.  This is to avoid an error due to
# not passing a callable object.
if msg == WM_CLOSE:
if self.inControl:
self.cleanup()

if msg == WM_DESTROY:
if self.inControl:
self.cleanup()

return CallWindowProc(self.oldWndProc, self.mHWND, msg, wParam,
lParam)

def cleanup(self):
SetWindowLongPtrW(self.mHWND, GWL_WNDPROC, self.oldWndProc)
self.inControl = False

def __del__(self):
if self.inControl:
self.cleanup()
#  end Multi Touch Support Class --- #





On Thu, May 9, 2013 at 1:52 PM, John Grant  wrote:

> I believe found access to the HWND.
> mHWND = ctypes.windll.user32.GetActiveWindow()
>
>
>
> On Thu, May 9, 2013 at 11:13 AM, John Grant  wrote:
>
>> Hi Tim,
>>
>> Thanks for the great explanations.
>>
>> Yes, you are right, I am trying to intercept gestures in a window within
>> the same process. The Blender application framework has a WndProc in C, and
>> Blender supports extending itself with user-supplied Python scripts. I am
>> trying to add gesture support with Python so I can avoid modifying the
>> Blender C code.
>>
>> I'm reading through the wxPython article. It looks like a perfect fit for
>> my problem. It shows everything I need to do, and using ctypes! Thanks!
>>
>> Although, I am stuck trying to get the HWND from Blender. It seems they
>> have not exposed the handle yet. I'm looking for win32 API that might
>> provide it to me, or a list of window

Re: [python-win32] hook to obtain WM_GESTURE

2013-05-09 Thread John Grant
I think I finally have a fix. I believe I needed to specify the argtypes
for the function objects loaded by importing ctypes. I did not get the
correct behavior when only specifying the return types. One issue may be
that my return type for 'SetWindowLongPtrW' was a function signature that I
declared with ctypes. This return type might need to match the argtype
of 'CallWindowProc',
which was an int. Now they are both WNDPROC (declared with ctypes).

Thanks for all the help. I feel like I learned a magic trick.
John


On Thu, May 9, 2013 at 5:59 PM, Tim Roberts  wrote:

> John Grant wrote:
> >
> > I was not sure if I could initialize a Python integer with a hex like
> > I can in C. The explicit "cast" was to make sure the default type was
> > not float or unsigned.
>
> Python does not have unsigned types.  Numbers are either integers
> (infinitely large) or floats.
>
>
> > I am seeing an exception that only shows up for some mouse events,
> > sometimes. I can usually reproduce it for a middle-mouse click. The
> > error message is difficult to read as it streams by on the console
> > window (shell), but I've seen a couple things that make me think one
> > of my callbacks is prototyped incorrectly. These are the things I've
> > been able to read while the output quickly streams by.
> > "long int too long"
> > "callback  in line XXX of ctypes.c"
>
> Hmmm.  Not sure I can explain that.
>
> --
> Tim Roberts, [email protected]
> Providenza & Boekelheide, Inc.
>
> ___
> python-win32 mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-win32
>
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Python and Win 7 Registry VirtualStore

2013-06-03 Thread John Spitzer


Hello,

I've searched the python sites and help, library's and all the forums I 
could find, but haven't seen any mention of this. This help line seemed 
like a good place to ask this.


I am on an HP laptop Intel Core 2 Duo, running Windows 7 Pro SP1 32Bit. 
I am using Python 2.7.3.


I have an application I built that ran fine on Windows XP, but now fails 
on Windows 7. The place I'm encountering the problem is where I try to 
read a key from the registry. I believe it's because of the 
Virtualization of the registry on Windows 7. This key is created by 
another app that I'm trying to co-ordinate with. On Windows XP the 
Registry key was:


[HKEY_LOCAL_MACHINE\SOFTWARE\Interface Software\ConnMgr]
"DB Path"="C:\\Documents and Settings\\All Users\\Application 
Data\\"


When this app is installed on Windows 7, the key is directed to the 
registry Virtual Store at:
[HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE\Interface 
Software\ConnMgr]

"DB Path"="C:\\ProgramData\\EnvisionWare\\"

So far that is what I think I'd expected on Windows 7 and the 
virtualization of the registry.


The code fragment that is reading the registry is:
-
from _winreg import *


ConnKey = OpenKey(HKEY_LOCAL_MACHINE, r'SOFTWARE\Interface 
Software\ConnMgr', 0, KEY_READ)

ConnValue = QueryValueEx(ConnKey, "DB Path")
EWDataSource = os.path.split(str(ConnValue[0]))
--
The OpenKey fails with the message: WindowsError: (2, 'The system cannot 
find the file specified"). I believe this is because the key does not 
exist at the path [HKEY_LOCAL_MACHINE\SOFTWARE\Interface Software\ConnMgr].


After all this, the question is: Why isn't the OpenKey call being 
redirected to the VirtualStore? What can I change in the program, ACLs 
or other to make it be redirected?


Any help would be appreciated.
Thanks,
John

--
John Spitzer
[email protected]
503-590-7434

___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python and Win 7 Registry VirtualStore

2013-06-08 Thread John Spitzer

Hello team.

I've done some more testing on this I'm really hoping there is an answer 
to what I'm trying to do. Maybe there is something I'm overlooking or 
don't understand about the registry and permissions on Windows 7 and how 
the _winreg library works.


As shown below, I'm trying to retrieve a value from a registry key. The 
app that is writing the key appears to be coded so that Windows writes 
the key to the VirtualStore area of the registry. Everything I've read 
so far says application programs, if the permissions and access is coded 
correctly, should not access the VS keys directly.


As a test, I put the following two lines in my program:
-
#ConnKey = OpenKey(HKEY_LOCAL_MACHINE, r'SOFTWARE\Interface 
Software\ConnMgr', 0, KEY_READ)
ConnKey = OpenKey(HKEY_CURRENT_USER, 
r'Software\Classes\VirtualStore\MACHINE\SOFTWARE\Interface 
Software\ConnMgr', 0, KEY_READ)

ConnValue = QueryValueEx(ConnKey, "DB Path")
-
When I execute the program with the line that access the HKCU key, the 
program retrieves the key as expected. As shown, it is accessing the key 
explicitly from the virtual store. This shows the key is where I expect 
it and I can access it.


To test the access of the key in HKLM, I manually created the 
appropriate key value in HKLM. This is where the application stored the 
key on Windows XP. I also ran this program both as an administrator and 
standard user. With KEY_READ access, I can read the key. With 
KEY_ALL_ACCESS I get the error: [Error 5] Access is denied.


How do I code this so that the access is directed to the Virtual Store, 
or am I not understanding how this is suppose to work (very possible). I 
am certain that I'm not the first to encounter this behavior.


Thanks for your help,
John

On 06/03/2013 9:51 PM, John Spitzer wrote:


Hello,

I've searched the python sites and help, library's and all the forums 
I could find, but haven't seen any mention of this. This help line 
seemed like a good place to ask this.


I am on an HP laptop Intel Core 2 Duo, running Windows 7 Pro SP1 
32Bit. I am using Python 2.7.3.


I have an application I built that ran fine on Windows XP, but now 
fails on Windows 7. The place I'm encountering the problem is where I 
try to read a key from the registry. I believe it's because of the 
Virtualization of the registry on Windows 7. This key is created by 
another app that I'm trying to co-ordinate with. On Windows XP the 
Registry key was:


[HKEY_LOCAL_MACHINE\SOFTWARE\Interface Software\ConnMgr]
"DB Path"="C:\\Documents and Settings\\All Users\\Application 
Data\\"


When this app is installed on Windows 7, the key is directed to the 
registry Virtual Store at:
[HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE\Interface 
Software\ConnMgr]

"DB Path"="C:\\ProgramData\\EnvisionWare\\"

So far that is what I think I'd expected on Windows 7 and the 
virtualization of the registry.


The code fragment that is reading the registry is:
-
from _winreg import *


ConnKey = OpenKey(HKEY_LOCAL_MACHINE, r'SOFTWARE\Interface 
Software\ConnMgr', 0, KEY_READ)

ConnValue = QueryValueEx(ConnKey, "DB Path")
EWDataSource = os.path.split(str(ConnValue[0]))
--
The OpenKey fails with the message: WindowsError: (2, 'The system 
cannot find the file specified"). I believe this is because the key 
does not exist at the path [HKEY_LOCAL_MACHINE\SOFTWARE\Interface 
Software\ConnMgr].


After all this, the question is: Why isn't the OpenKey call being 
redirected to the VirtualStore? What can I change in the program, ACLs 
or other to make it be redirected?


Any help would be appreciated.
Thanks,
John



--
John Spitzer
[email protected]
503-590-7434

___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Win32 GUI for beginners.

2013-12-31 Thread John Grant
Hi Sean,
My opinion is that you would be better served learning Qt. In some ways
this additional dependency might cloud matters, but for the features you
ask for, Qt will make your development streamlined. You can find more
information about the Python bindings at:
https://wiki.python.org/moin/PyQt

Good luck,
John
On Dec 31, 2013 3:11 AM, "Sean Murphy"  wrote:

> Hi all.
>
> I am very very new to Python. I have read the book on programming for
> Windows with Python that was released in 2000. The book is very good but
> doesn't give me the basic information I am seeking. Since I am a beginner
> programmer.
>
> I want to create a GUI windows app with Python. The program has to use
> default Windows 32 or 64 bit objects. I wish to get the following
> components:
>
> Menu bar
> Listview
> Treeview
> Richedit or a multiline edit field
> A couple of buttons.
> All objects must be able to be access by the keyboard. either via tab
> stops (using the tab or shift tab key) and short cut keys.
>
>
> I have a 70 mb text file that is marked up using YML. I wish to show each
> section in the edit field. The list view shows the name of each item. The
> tree view will contain categories.
>
> I have seen PYGUI which I am not sure if it is easier then using the MSF
> approach which the book above mentions.
>
> So I really need assistance to progress this home bobbie project to expand
> my programming skills. Any wikis, documentations, good code examples with
> explanations, etc I would love to get my hands on.
>
> I am reading about 3 or 4 books on Python to get up to speed. But only
> found one book on Win32 programming. I do not want to have to turn around
> and learn win32 or MFC. If I have to then please point me towards a good
> book or resource.
>
>
> Regards
> Sean
> ___
> python-win32 mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-win32
>
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] pythoncom

2014-10-14 Thread John Sampson
I have a proprietary program with a command interface implemented as an 
ActiveX DLL. Importing win32com.client and pythoncom, I can call 
functions from Python scripts. Some of these work properly in 32-bit 
Windows 7, but others only in 64-bit Windows. Is this because pythoncom 
is designed to work with Windows 64-bit only? Is there a version that 
works with 32-bit Windows?


Regards

John Sampson
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] pythoncom

2014-10-15 Thread John Sampson

On 14/10/2014 18:15, Tim Roberts wrote:

John Sampson wrote:

I have a proprietary program with a command interface implemented as an
ActiveX DLL. Importing win32com.client and pythoncom, I can call
functions from Python scripts. Some of these work properly in 32-bit
Windows 7, but others only in 64-bit Windows. Is this because pythoncom
is designed to work with Windows 64-bit only? Is there a version that
works with 32-bit Windows?

Python is available is both 32-bit and 64-bit forms.  You can use either
one on a 64-bit operating system.

However, a 64-bit process cannot call a 32-bit DLL, nor the reverse.  If
your proprietary program is a 32-bit application, then you need to
install and use a 32-bit Python in order to use it.

You can't install 64-bit product on a 32-bit Windows system, so if you
are having trouble on a 32-bit Windows system, then there is something
else going on.



The interface has a function which returns a string from an array of 
strings as it is supposed to

in Windows 64-bit, or if called from VBA.
In 32-bit Windows Python it returns the number of the item in the array 
instead.


Regards

John Sampson
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] pythoncom

2014-10-16 Thread John Sampson

On 16/10/2014 07:48, Mark Hammond wrote:

On 16/10/2014 12:50 AM, John Sampson wrote:

The interface has a function which returns a string from an array of
strings as it is supposed to
in Windows 64-bit, or if called from VBA.
In 32-bit Windows Python it returns the number of the item in the array
instead.


So to be clear - you have a 64bit version of Windows, and you've 
installed python and pywin32 in both 32 and 64bit variants, *and* 
you've installed the COM object in both 64 and 32bit variants - is 
that correct?


If so, I suspect the problem might be that you've run makepy (or 
previously called EnsureDispatch etc) in the 64bit version but not in 
the 32bit version - check the lib\site-packages\win32com\gen_py 
directory and you might find the generated support in the 64bit 
version and not the other.


HTH,

Mark


I have the 32-bit version of Python on both computers (64-bit Windows 
and 32-bit Windows), installed from the MSI file, so I have not 
personally run makepy on either.
The COM object is part of the same software package, installed on both 
computers. They are different versions, but I thought I had excluded 
that this was where the problem lay. I will have to review this. Looking 
at lib\site-packages\win32com\gen_py I see more files in the version 
causing trouble than in the version that works OK.

How would I recognise the generated support you mention?

Regards

John Sampson
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] pythoncom

2014-10-20 Thread John Sampson

On 20/10/2014 11:27, Mark Hammond wrote:

On 16/10/2014 8:25 pm, John Sampson wrote:

at lib\site-packages\win32com\gen_py I see more files in the version
causing trouble than in the version that works OK.
How would I recognise the generated support you mention?


Those files *are* the generated support.  Try removing all files in 
that dir.


Mark



Many thanks - yes, removing these files seems to have enabled the 
functions that were not working.


Regards

John
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Get key press in Windows 7

2014-11-27 Thread John Sampson
I have tried a module called readchar to make a Python 2.7 script detect 
keystrokes in Windows 7.

I found it via a link from Stack Overflow.
When z  is pressed its output is printed in the console as
u'\x1a'
According to Python 2.7 its type is 'str'. Seeing that it is preceded by 
a 'u', why is it not 'unicode'?
While it appears in the console as above, if it is assigned to a 
variable ( c = repr(readchar.readkey()) )

and then the value of the variable is tested:
print c == u'\x1a'
the answer is 'False'
This does not make sense. What type of object is a keystroke?

Perhaps I need to find some other way for a Python script detect 
keystrokes but I am confused as to what Python sees them as.


Any advice would be welcome.

Regards

John Sampson

___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Get key press in Windows 7

2014-11-27 Thread John Sampson
Many thanks - by excluding repr the code behaves in a comprehensible 
way. The example code that was provided at Stack Overflow included repr 
so I assumed that it was necessary for some reason.

If I were allowed to comment there I would ask why.

Regards

John Sampson

On 27/11/2014 18:26, Randy Syring wrote:

I believe your problem is the use of repr() when assigning to c:

>>> u'\x1a'
u'\x1a'
>>> c = u'\x1a'
>>> c == u'\x1a'
True
>>> repr(c)
"u'\\x1a'"
>>> repr(c) == u'\x1a'
False
>>>


*Randy Syring*
Husband | Father | Redeemed Sinner

/"For what does it profit a man to gain the whole world
and forfeit his soul?" (Mark 8:36 ESV)/

On 11/27/2014 01:06 PM, John Sampson wrote:
I have tried a module called readchar to make a Python 2.7 script 
detect keystrokes in Windows 7.

I found it via a link from Stack Overflow.
When z  is pressed its output is printed in the console as
u'\x1a'
According to Python 2.7 its type is 'str'. Seeing that it is preceded 
by a 'u', why is it not 'unicode'?
While it appears in the console as above, if it is assigned to a 
variable ( c = repr(readchar.readkey()) )

and then the value of the variable is tested:
print c == u'\x1a'
the answer is 'False'
This does not make sense. What type of object is a keystroke?

Perhaps I need to find some other way for a Python script detect 
keystrokes but I am confused as to what Python sees them as.


Any advice would be welcome.

Regards

John Sampson

___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32





___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Repr, and Unicode type [Was: Get key press in Windows 7]

2014-11-28 Thread John Sampson
In answer to Time Roberts, I saw an item prefixed with 'u' (u'\x1a'). 
What is the purpose of this prefix? I would have thought it meant 
'Unicode' but the type according to Python is 'str'.


Thank you for the explanation of 'repr'. The issue turned out to be the 
inclusion of 'repr' in the sample code without evidence or explanation 
of its purpose there. Once I was given a clue that 'repr' was the 
problem and I eliminated it things became clear.


Regards

JohnSampson
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Creating standalone executable

2015-01-06 Thread John Sampson
Is it possible to create a standalone executable (.EXE file) from a 
Python script?


By 'standalone' I mean an executable file that can be placed in any 
folder and contains or finds the libraries, modules etc. that it depends on.


Regards

John Sampson
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Creating standalone executable

2015-01-06 Thread John Sampson
I tried py2exe but the executable file has to be in a specific folder 
along with many other files that py2exe generates. It therefore cannot 
be placed in any folder.

As far as I can see cx-freeze produces a folder, not a single file.

I am looking for a way of producing a single executable file that can be 
run in any folder, and nothing else - that is, standalone.


Regards

John Sampson

On 06/01/2015 13:07, Graeme Glass wrote:

Yes it is.

http://www.py2exe.org/
http://cx-freeze.sourceforge.net/



On 6 January 2015 at 14:50, John Sampson <mailto:[email protected]>> wrote:


Is it possible to create a standalone executable (.EXE file) from
a Python script?

By 'standalone' I mean an executable file that can be placed in
any folder and contains or finds the libraries, modules etc. that
it depends on.

    Regards

John Sampson
___
python-win32 mailing list
[email protected] <mailto:[email protected]>
https://mail.python.org/mailman/listinfo/python-win32




___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Creating standalone executable

2015-01-07 Thread John Sampson
Many thanks - by specifying '-F' I was able to produce an .exe file 
which appeared in the 'build' folder. This could be moved to another 
folder and still work, which is what I was looking for. My only question 
is about the other files in the 'build' folder and its subfolders. Are 
these still needed? If so, what if I make another standalone executable? 
Is there a need for another 'build' folder tree for it, to exist as well 
as the 'build' folder tree for the first standalone executable?


Regards

John Sampson

On 06/01/2015 17:30, J.D. Main wrote:

I've had good success with PyInstaller.

https://github.com/pyinstaller/pyinstaller/wiki

I like it better than Py2Exe - it seems to "just work" without a lot 
of fiddling.




___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Tkinter newbie

2015-03-02 Thread John Sampson

Hello -

I am trying to find out how to write code in Tkinter that opens a 
file-selection dialog so that I can open a file. It would be part of a 
program, not a whole program that does nothing else.


I have found many examples of Tkinter code, each one using a different 
approach, some using a geometry manager, some not, some using an 
object-oriented approach, some not, etc.
What I am looking for are examples of code with explicit explanations of 
each *term* in the code, explaining what it is, what it does and why it 
has to be there, why in one place it has to be self.x but in another it 
has to be x(self), why it has to be followed by '()' in one place but 
not in another, how the variables are scoped and similar questions. At 
the moment all my guesses are wrong.


Are there any such examples?

Regards

John Sampson
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Tkinter newbie

2015-03-03 Thread John Sampson
I had spent a day trying to find a solution. Still, I know now one place 
I won't look for help.


JS


In case of a real person that wanted help:
"We reap what we sow" or "ask niceley and show that you tried yourself to find a 
solution".



___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32


[python-win32] Using a COM interface where the objects don't have ProgIDs

2005-03-23 Thread John Clark
My apologies if this is something that should be obvious to me, but I cannot figure out how to use a typelib if that typelib does not establish ProgID values for the CoClasses.  

The class that was created by EnsureModule() is as follows:

class CaWHarvest(CoClassBaseClass): # A CoClass
# CaWHarvest Class
CLSID = IID('{70107C62-8ABB-11D5-961B-0010A4F73DE4}')
coclass_sources = [
_ICaWHarvestEvents,
]
default_source = _ICaWHarvestEvents
coclass_interfaces = [
ICaWHarvest,
]
default_interface = ICaWHarvest

I have tried calling win32com.client.Dispatch(None, resultCLSID = IID('{70107C62-8ABB-11D5-961B-0010A4F73DE4}')) but this returned a 'Class Not registered' error.  I have searched the registry for the above CLSID and have found entries, so to the best of my knowledge this COM component is registered.  Beyond that I am afraid I have exceeded my knowledge of COM & Python.  

My only experience with calling COM components from Python has been in situations where the class has a ProgID that I would pass into Dispatch() as the parameter... I suppose I could force a programmatic ID by creating something in the registry, but it seems there should be an answer without doing that.  

Could someone point me in the right direction?  I am sure I am just missing something obvious. 

Thanks,
-John___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Fwd: [python-win32] Using a COM interface where the objects don't have ProgIDs

2005-03-23 Thread John Clark
Okay - sorry for the interruption - banging at this for several more minutes gave me the direction I needed.  For anyone else out there struggling, I found that if I call 

win32com.client.dynamic.Dispatch('{70107C62-8ABB-11D5-961B-0010A4F73DE4}')

and if I actually DO register the COM control, rather than just assuming that it's registered because the DLL exists ("Of course it is registered - the file is right there!  No one would place the file on the disk without actually registering the objects...") everything then seems to work as advertised (imagine that :)).

Well, I guess sometimes it just helps to talk it out in email.

-John


On Mar 23, 2005, at 10:21 PM, John Clark wrote:

My apologies if this is something that should be obvious to me, but I cannot figure out how to use a typelib if that typelib does not establish ProgID values for the CoClasses.  

The class that was created by EnsureModule() is as follows:

class CaWHarvest(CoClassBaseClass): # A CoClass
# CaWHarvest Class
CLSID = IID('{70107C62-8ABB-11D5-961B-0010A4F73DE4}')
coclass_sources = [
_ICaWHarvestEvents,
]
default_source = _ICaWHarvestEvents
coclass_interfaces = [
ICaWHarvest,
]
default_interface = ICaWHarvest

I have tried callingΩ win32com.client.Dispatch(None, resultCLSID = IID('{70107C62-8ABB-11D5-961B-0010A4F73DE4}')) but this returned a 'Class Not registered' error.  I have searched the registry for the above CLSID and have found entries, so to the best of my knowledge this COM component is registered.  Beyond that I am afraid I have exceeded my knowledge of COM & Python.  

My only experience with calling COM components from Python has been in situations where the class has a ProgID that I would pass into Dispatch() as the parameter... I suppose I could force a programmatic ID by creating something in the registry, but it seems there should be an answer without doing that.  

Could someone point me in the right direction?  I am sure I am just missing something obvious. 

Thanks,
-John___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Question: Finding the "owner" Of A Process

2005-06-02 Thread Gooch, John
Title: Question: Finding the "owner" Of A Process





I am trying to print out the owner of running process on Windows 2000 Professional ( SP4 ) using WMI, but my call to the "GetOwner" Process defined here - http://msdn.microsoft.com/library/default.asp?url="">, which is part of the Win32_Process Class defined here - http://msdn.microsoft.com/library/default.asp?url=""> .



Here is my code, followed by the error message:



import odbc
import socket
import re
import win32com.client
import win32api
import win32con
import win32file
import pythoncom
import datetime
import os


pythoncom.CoInitialize()
#connect to localhost wmi service
wmi = win32com.client.GetObject('winmgmts://' )
procs = wmi.ExecQuery( "SELECT * FROM WIN32_PROCESS")
user = ""
domain = ""
for proc in procs:
    proc.GetOwner( user, domain )
    print "%s's owner is %s" % ( proc.Name, user   )
x.GetOwner()



Error:
Traceback (most recent call last):
  File "C:\Documents and Settings\John.Gooch\My Documents\File Manager\getowner.py", line 20, in ?
    proc.GetOwner( user, domain )
TypeError: 'int' object is not callable




Any ideas? I tried using the proc.Method('GetOwner') syntax to locate the function, but I don't know how to pass in paramaters ( explained on Microsoft's site ) to the function using that syntax.

Thank You, 



John A. Gooch
Systems Administrator
IT - Tools
EchoStar Satellite L.L.C.
9601 S. Meridian Blvd.
Englewood, CO  80112
Desk: 720-514-5708 






John A. Gooch
Systems Administrator
IT - Tools
EchoStar Satellite L.L.C.
9601 S. Meridian Blvd.
Englewood, CO  80112
Desk: 720-514-5708 



___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Strange page header text in PythonWin

2005-06-03 Thread John Machin
Robert Adams wrote:
> I am somewhat of a newbie to Python, but thanks for the heads-up on 
> where to look.
>  
> Question, since I have not customized anything that I am aware of, my 
> Python environment should be as installed from scratch, so why would I 
> get then strange text in page header ?
>  
> I am running the following, Python 2.3.3, wxPython 2.4.2.4, PythonWin 
> 2.3.3 win32all build 163
>  

Any good reason why you're running old versions of software? I used to 
get that "strange text in page header" problem, but it went away with an 
upgrade.

Cheers,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Editor Replace function limitation

2005-06-08 Thread John Machin
Graeme Glass wrote:

>On python 2.3.4 pythonwin build 203, i don't seem to have a problem.
>can replace much more than 30 chars.
>Not sure what your problem could be, but just thought that i would let
>you know it's must your setup not pythonwin.
>  
>
Graeme, what "setup" do you refer to? PythonWin appears to have no 
configuration opportunity for changing the max size of a text 
replacement -- and indeed I can't imagine that any text editor would 
ever have had such an option, especially after malloc() was invented ...

>(you proberbly already tried this,) but try installing the a diffrent build. 
>
>On 6/8/05, Robert Adams <[EMAIL PROTECTED]> wrote:
>  
>
>> 
>>Do I have a setup issue or is the PythonWin editor Replace function limited
>>to 30 characters ? 
>>
>>
Robert, 

It worked for me on 2.4.1 / build 204. I typed in "abc" then replaced 
"b" by "abyzAB...JK".

The size of the box for typing in the replacement string is only 30 
characters, but it does scroll if you keep on typing -- have you tried 
this? What makes you think it is limited to 30 characters?

Regards,
John

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Editor Replace function limitation

2005-06-08 Thread John Machin
Robert Adams [and everybody else] top-posted and I can't be bother 
rearranging so I'm going with the flow:

What you tried works OK with my set-up (2.4.1, pywin32 build 204).

>Thanks for both your input on this.
>
>I can recreate the problem as follows:
>
>Create a script file with the following,
>123456789012345678901234567890123456789.
>Cut/paste into the "Find What" window, I then only get
>12345678901234567890123456, that is 26 characters not 30, so I obviously can
>not count either.
>Enter var_x, including a space after x into the "Replace with" window, then
>hit replace.
>
>And I end up with var_x 7890123456789
>
>Also, if I keep typing my window does not scroll as you describe.
>
>I am running the following, Python 2.3.3, wxPython 2.4.2.4, PythonWin 2.3.3
>win32all build 163, and FYI, I am forced to run this version in support of
>CAD system.
>
>Regards,
>Robert
>
>-Original Message-
>From: John Machin [mailto:[EMAIL PROTECTED] 
>Sent: Wednesday, June 08, 2005 2:45 PM
>To: Graeme Glass; Robert Adams
>Cc: python-win32
>Subject: Re: [python-win32] Editor Replace function limitation
>
>
>Graeme Glass wrote:
>
>  
>
>>On python 2.3.4 pythonwin build 203, i don't seem to have a problem.
>>can replace much more than 30 chars.
>>Not sure what your problem could be, but just thought that i would let
>>you know it's must your setup not pythonwin.
>> 
>>
>>
>>
>Graeme, what "setup" do you refer to? PythonWin appears to have no 
>configuration opportunity for changing the max size of a text 
>replacement -- and indeed I can't imagine that any text editor would 
>ever have had such an option, especially after malloc() was invented ...
>
>  
>
>>(you proberbly already tried this,) but try installing the a diffrent
>>
>>
>build. 
>  
>
>>On 6/8/05, Robert Adams <[EMAIL PROTECTED]> wrote:
>> 
>>
>>
>>
>>>Do I have a setup issue or is the PythonWin editor Replace function
>>>  
>>>
>limited
>  
>
>>>to 30 characters ? 
>>>   
>>>
>>>  
>>>
>Robert, 
>
>It worked for me on 2.4.1 / build 204. I typed in "abc" then replaced 
>"b" by "abyzAB...JK".
>
>The size of the box for typing in the replacement string is only 30 
>characters, but it does scroll if you keep on typing -- have you tried 
>this? What makes you think it is limited to 30 characters?
>
>Regards,
>John
>
>
>
>
>  
>


___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Forcing win32com.client.dispatch to start up a fresh Excel

2005-06-21 Thread John Machin
[EMAIL PROTECTED] wrote:

>
> Hi,
>
> I'm trying to use Python's win32com interface to drive an excel 
> spreadsheet.
>
> I've managed to have it open the sheet, call a VBA function with 
> arguments, and close it down cleanly.
>
> However, if Excel is already running, it closes the open instance. 
> Which is not good.
>
> Is there a way I can do the equivalent of VBA's CreateObject() with 
> win32com? 


If this means "Can I create a totally different independant instance of 
Excel so that I don't run the risk of stuffing up what the user is doing 
with their existing instance", then I'd like to know too.

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] How to send an array of clusters to labview??

2005-06-28 Thread john taylor
hi all, 

i am using win32com to call labview from python over
COM and i am using early-bounding.

i want to set the value of a control element "array of
cluster" in a VI, and the control in the VI is an
array of clusters, which has the structure (integer,
integer, string).

CODE:
...
>>> paramNames = ["array of cluster"]
>>> paramVals = [(2,3,"hello"), (4,5,"world")] 
>>> vi.Call(paramNames, paramVals) 
Traceback (most recent call last):
  File "", line 1, in ?
  File "labview.py", line 149, in Call
, paramVals)
  File
"C:\Python24\Lib\site-packages\win32com\client\__init__.py",
line 446, in _ApplyTypes_
return self._get_good_object_(
com_error: (-2147352567, 'Ausnahmefehler
aufgetreten.', (5002, 'LabVIEW', 'LabVIEW : paramVals
Typenfehlanpassung. 1D-Array aus Variants wird
erwartet.', None, 0, 0), None)

it says, 1D-Array of Variants is expected.

i've succeeded in sending 1d and 2d arrays, or a
cluster. the only problem is to send an array of
clusters (elements of different types). 

anybody with experience in python/com/labview has
idea?? thanks a lot in advance?

cheers,
john

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] threading in python

2005-06-28 Thread john taylor
hi, 

anybody has called two VIs in parallel?? 

somehow like this: 
*
import win32com.client 
import thread 

lv = win32com.client.Dispatch("LabVIEW.Application") 

def start(): 
vi2 = lv.GetVIReference("p2.vi") 
vi2.Run() 

thr = thread.start_new_thread(start, ()) 

vi1 = lv.GetVIReference("p1.vi") 
vi1.Run() 

*

it doesn't work. i've tried calling functions of usual
objects in several threads like this and everything
was fine. but in this case, there must be sth to take
care of between COM objects and python. 

i've also tried the following: 
1. construct two lv objects in the main thread. 
2. construct lv objects in the main and the new
threads respectively. 
3. construct two vi objects in the main thread. 
4. pass lv or vi as argument when calling new thread. 
none of them works.  

anybody can help? 

cheers, 
john

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] ADSI and LDAP Searches

2005-06-29 Thread Gooch, John
Hey, I am converting a Perl script into a Python script, and the part where
the Perl script is searching Active Directory using the LDAP interface is
throwing me a curve ball.

Here is a search for a Windows Group in Perl:
my $hdb = Win32::OLE->new("ADODB.Connection");
$hdb->{Provider} = "ADsDSOObject";
$hdb->Open("ADSI Provider");  
$rs =
$hdb->Execute("<$adsdomain>;(&(objectCategory=Group)(name=$groupname));adspa
th;SubTree");


Here is what I have in Python so far:
adsi = win32com.client.Dispatch('ADsNameSpaces')
ldap = adsi.getobject('','LDAP:')
DSO = ldap.OpenDSObject("","","", 0)

It errors on the DSO line. I am guessing that the 'DSO' Python object is the
equivalent of the Perl "$hdb" object, but I don't know the syntax. I could
be complete off-base here as the document I have found via Google don't
explain what the code is doing, so I am left guessing.


Any help would be appreciated.

Thank You, 

John A. Gooch
Systems Administrator
IT - Tools
EchoStar Satellite L.L.C.
9601 S. Meridian Blvd.
Englewood, CO  80112
Desk: 720-514-5708 



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Schollnick, Benjamin
Sent: Tuesday, June 21, 2005 11:33 AM
To: Thomas Heller; [email protected]
Subject: Re: [python-win32] LsaLookupNames2



> Problems like this can be solved with dependencywalker
> (google for it). The walker displays binary dependencies for images.

Thankfully dependency issues like this seem to be rare

> Using it I found this: win32net.pyd from build 204 does *not*
> use the LsaLookupNames2 function in advapi32.dll.  However, 
> win32net.pyd links to netapi32.dll (among others), and 
> netapi32.dll links to advapi32.dll, using the name 
> LsaLookupNames2.  This was on WinXP.
> 
> On win2k, netapi32.dll will not link to advapi32's
> LsaLookupNames2 - otherwise it would not work.
> 
> So, your exe *should* be able to run on win2k - except if you
> distribute XP's netapi32.dll with your exe (I've checked this 
> with a trivial py2exe'd script).

I just checked...  And guess what... Py2exe is bundling netapi32.dll... I am
working on a new beta, so I'll test to see if it will work on XP without
netapi32.dll being bundled...  If so, then we should be 
kosher...

Good catch...  I'll have to grab dependencywalker 
to get some practice...

> py2exe isn't very  good at determining which dlls belong to
> the operating system, and so must not be distributed - 
> netapi32.dll is such a beast.  You should remove netapi32.dll 
> from the dist directory, and it should work on win2k.

That's what I suspect

> And sorry for the false alarm on the threads you mention above ;-)

It's okay  I just miss McMillian's installer...
It's unsupported, so I've moved to py2exe...  But 
McMillian's package seemed to be better with
the dependency issues  And offered a few
features that don't exist in py2exe... (Or at least
are not easily handled in py2exe...)

On the plus side, py2exe has handled packages lately
that I just could not get McMillian's installer
to work reliably with...  Which is why I switched...

Oh well... Progress...

- Benjamin
___
Python-win32 mailing list
[email protected] http://mail.python.org/mailman/listinfo/python-win32
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] EasyDialogs - how to set initial path

2005-06-30 Thread John Machin
Radovan Grznarik wrote:

>Hi,
>
>I am using EasyDialogs (AskFileForOpen) and I am not able to set the
>initial open path. I found in Python help
>
Python help describes the *Mac* version; EasyDialogs for Windows by 
Jimmy Retzlaff has slightly different arguments; there is a readme.txt 
in .\site-packages\EasyDialogs -- take a hint :-)

> that it should be 3rd
>parameter,
>
*should* be [you reading this, Jimmy???]. Here's another hint - this is 
_open source_ software, Luke :-)

> then I tried this
>
>filename = EasyDialogs.AskFileForOpen("title","*.*","d:\\")
>
>but it does not work, and opens dialog in actual directory of running script.
>
>os.chdir("d:\\") before AskFileForOpen also does not work.
>  
>
It works, it just doesn't do what you think it should do. WinDOS has a 
current directory on *each* drive. Fire up a DOS box, unless you've 
meddled, the prompt will show C:\something> ... this means the current 
drive is C: and the current directory on C: is \something. If you type 
cd d:\, this sets the current directory on D: to \, but you'll notice 
that your prompt hasn't changed.

>Does anybody have some idea to solve this situation?
>  
>

Yeah. two ideas, actually:
ONE:

 try:
  rtfs()
 except NoSourceError:
  trashthesucker()

TWO:
Keyword arguments are a thing of beauty and a joy forever, even when 
they're in camelCase -- so bloody well stop counting arguments and use 
them!!

>I would be grateful.
>
>Radovan Grznarik
>
>  
>


___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] EasyDialogs - how to set initial path

2005-06-30 Thread John Machin
Radovan Grznarik wrote:

>Thank you very much, I was so close, it's the 4th one:)))
>Next time before the question I will look at the code.
>
>now it works
>filename = EasyDialogs.AskFileForOpen("","","","d:\\")
>  
>

Bletch. Try this:

filename = EasyDialogs.AskFileForOpen(defaultLocation="d:\\")

(Re)read this:

Keyword arguments are a thing of beauty and a joy forever, even when
they're in camelCase -- so bloody well stop counting arguments and use
them!!



___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Querying Password Change Privilege on an Active Directory User Ac count

2005-07-29 Thread Gooch, John
Title: Message



I have 
a script that changes user passwords, and it throws exceptions then executing 
the SetPassword() or SetInfo() commands on a AD user account that it does 
not have "set password" privileges on. To avoid the exception being thrown, I 
would like to have the script check whether or not it has permission to change 
the password before trying to change it ( make sense? ), but I cannot find any 
good documentation on this after a few hours of Googling for it. 

 
Do 
anyone have guidance ( or better yet, an answer ) on figuring out how to 
implement this. 
 
here 
is a small snippet of the code I have now :
 
 
  adsuser = getADSUser( trans.adspath 
)#Retrieve a copy of the users AD Account  if ( 
adsuser ):  trans.email = 
adsuser.mail  
trans.firstname = 
adsuser.givenName 
trans.lastname = adsuser.sn 
trans.displayname = 
adsuser.displayname 
#trans.pwdLastChanged1 = 
adsuser.PasswordLastChanged 
#trans.pwdLastChanged1 = time.strftime( "%Y-%m-%d %H:%M:%S", time.gmtime( 
adsuser.PasswordLastChanged ) 
) trans.pwdLastChanged1 = 
str( adsuser.PasswordLastChanged ) 
 error = NewPassword( 
trans  ) if ( not error 
):    if 
(  validEmail( trans.email )  
):   
try:  
print "new password is %s" % 
trans.password  
adsuser.SetPassword( trans.password  ) 
  
#x=1  
#adsuser.SetInfo()  
print "Password change successful. %s"  % 
trans.username   
except pythoncom.com_error, 
error:  
#print "Password change failed. for %s" % trans.username 
  
return "Set Password failure. COM Error:%s" % str( error 
)   
except Exception, 
error:  
return "Set Password failure. General Error:%s" % str(error)   
   
try:  
adsuser = 
None  
adsuser = getADSUser( trans.adspath ) #Retrieve a copy of the users AD 
Account  
trans.pwdLastChanged2 = str( adsuser.PasswordLastChanged ) 
   
except:  
return "Password change verification failure - Unable to retrieve 
PasswordLastChanged Timestamp after changing the password." % ( 
trans.pwdLastChanged1,trans.pwdLastChanged2 )
 
   
if ( trans.pwdLastChanged1 == trans.pwdLastChanged2  
):   
return "Password change verification failure - PasswordLastChange Value did not 
change after executing the SetPassword Command.Before:%s Date After Date:%s" % ( 
trans.pwdLastChanged1,trans.pwdLastChanged2 
)   
else:   
#print "Password change verification success - PasswordLastChange Value did 
change after executing the SetPassword Command.Before:%s Date After Date:%s" % ( 
trans.pwdLastChanged1,trans.pwdLastChanged2 
)   
return None
Thank 
You, 
 

John A. Gooch 
"May the Python-force be 
with you...always." Systems Administrator EchoStar Satellite L.L.C. Desk: 720-514-5708 

 
 
 
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Querying Password Change Privilege on an Activ e Directory User Ac count

2005-07-29 Thread Gooch, John
It's mostly for testing purposes. The password change affect a few thousand
of our customers, so the group I wrote the script for wants to be able to
disable the SetPassword/SetInfo command to do a test run of the script and
see if it will encounter any permission/other problems before the
"Production" run kicks off. It's all about being proactive, and not having
anything happen that will come to the attention of upper management, who
will want to know why we are not being proactive instead of reactive. That
is, solving problems before they actually are problems, instead of reacting
to error messages after the fact. 

Plus, with an explicit message stating exactly why a password change would
fail, I won't get paged at home at 2am in the morning like I have for the
last three days. Instead they Windows admin can be paged to fix the any
permissions problems while I sleep. :) 

-Original Message-
From: Jim Vickroy [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 29, 2005 12:34 PM
To: Gooch, John
Cc: [email protected]
Subject: Re: [python-win32] Querying Password Change Privilege on an Active
Directory User Ac count


Hello John,

Why does it matter?

Why not just ignore the specific type of exception raised by an invalid 
SetPassword() or SetInfo() request as follows:

try:
   adsuser.SetPassword(trans.password)
   adsuser.SetInfo()
except :
   pass # or whatever
except :
   pass # or whatever
except Exception, details:
pass # or take whatever action is desired

-- jv


   

Gooch, John wrote:

> I have a script that changes user passwords, and it throws exceptions
> then executing the SetPassword() or SetInfo() commands on a AD user 
> account that it does not have "set password" privileges on. To avoid 
> the exception being thrown, I would like to have the script check 
> whether or not it has permission to change the password before trying 
> to change it ( make sense? ), but I cannot find any good documentation 
> on this after a few hours of Googling for it.
>  
> Do anyone have guidance ( or better yet, an answer ) on figuring out
> how to implement this.
>  
> here is a small snippet of the code I have now :
>  
>  
>   adsuser = getADSUser( trans.adspath )#Retrieve a copy of the
> users AD Account
>   if ( adsuser ):
>  trans.email = adsuser.mail
>  trans.firstname = adsuser.givenName
>  trans.lastname = adsuser.sn
>  trans.displayname = adsuser.displayname
>  #trans.pwdLastChanged1 = adsuser.PasswordLastChanged
>  #trans.pwdLastChanged1 = time.strftime( "%Y-%m-%d %H:%M:%S", 
> time.gmtime( adsuser.PasswordLastChanged ) )
>  trans.pwdLastChanged1 = str( adsuser.PasswordLastChanged )
>  error = NewPassword( trans  )
>  if ( not error ):
> if (  validEmail( trans.email )  ):
>try:
>   print "new password is %s" % trans.password
>   adsuser.SetPassword( trans.password  )
>   #x=1
>   #adsuser.SetInfo()
>   print "Password change successful. %s"  % trans.username
>except pythoncom.com_error, error:
>   #print "Password change failed. for %s" % 
> trans.username
>   return "Set Password failure. COM Error:%s" % str( 
> error )
>except Exception, error:
>   return "Set Password failure. General Error:%s" % 
> str(error)  
>try:
>   adsuser = None
>   adsuser = getADSUser( trans.adspath ) #Retrieve a 
> copy of the users AD Account
>   trans.pwdLastChanged2 = str( 
> adsuser.PasswordLastChanged )
>except:
>   return "Password change verification failure - 
> Unable to retrieve PasswordLastChanged Timestamp after changing the 
> password." % ( trans.pwdLastChanged1,trans.pwdLastChanged2 )
>  
>if ( trans.pwdLastChanged1 == trans.pwdLastChanged2  ):
>return "Password change verification failure -
> PasswordLastChange Value did not change after executing the 
> SetPassword Command.Before:%s Date After Date:%s" % ( 
> trans.pwdLastChanged1,trans.pwdLastChanged2 )
>else:
>#print "Password change verification success - 
> PasswordLastChange Value did change after executing the SetPassword 
> Command.Before:%s Date After Date:%s" % ( 
> trans.pwdLastChanged1,trans.pwdLastChanged2 )
>return None
> Thank You,
>  
>
>
> John A. Gooch
> "May the Python-force be wi

Re: [python-win32] detecting windows type

2005-09-08 Thread John Machin
Roel Schroeven wrote:

>le dahut wrote:
>  
>
>>Hello,
>>
>>How is it possible to detect which kind of windows a python script is
>>running on ? (9x, Me, 2k, XP, 2k3)
>>
>>
>
>You can use sys.getwindowsversion() for that. Check MSDN documentation 
>for the precise meaning of the result.
>
>  
>
>  
>
Also check out the platform module:
 >>> import sys
 >>> sys.getwindowsversion()
(5, 1, 2600, 2, 'Service Pack 2')
 >>> import platform as  pl
 >>> pl.platform()
'Windows-XP-5.1.2600-SP2'
 >>> pl.system()
'Windows'
 >>> pl.release()
'XP'
 >>> pl.version()
'5.1.2600'
 >>>
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] wdFormatText

2005-10-23 Thread John Machin
geon wrote:

>Michel Claveau napsal(a):
>
>  
>
>>You can to watch the class I had create, for "to tele-command" word, here:
>>   http://mclaveau.com/ress/python/pxword.htm
>>(and look the "saveas" method)
>> 
>>
>>
>>
>so easy and so much spent my time on it. Thanks a lot. Anyway I wonder
>if this could be found in MSDN documentation or in word macro
>itselfjust for the next time I am in the same situation...
>
>  
>
You are meant to use the names, not magic numbers.

Have you run makepy?

Have you ever heard of Google?
google("wdFormatText") -> first hit is a clue about makepy, second hit 
tells you that the magic number is 2
google("wdFormatText Python") -> 3rd hit points to an Activestate Python 
Cookbook recipe ... which looks as though your code was derived fom it :-)
Later on there's this: 
http://herlock.com/ob/pythoncb/0596007973/chp-2-sect-27.html

By the way, you have u'text' in your code -- are you sure that you don't 
mean u'txt'?

Cheers,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] wdFormatText

2005-10-23 Thread John Machin
Michel Claveau wrote:

> Hi_release_2 !
>
 Anyway I wonder if this could be found in MSDN documentation or in 
 word
 macro itselfjust for the next time I am in the same situation...
>>>
>
I don't know why you are sending this to me -- the above quote is from 
"geon", and as for the story about your ramble through the woods instead 
of RTFM/Google: confession may be good for your soul, but I am not your 
priest :-)

> First, for to find, I have make a word's macro, with :
>reponse = MsgBox(wdFormatText, vbOKOnly, "wdFormatText")
>
>
> Then, I had make a macro, for to list all constants :
>
> Sub Macro6()

[snip]

> End Sub
>
> Result : 63 pages, for to list the constants !
>
> But ("TLI.TLIApplication") is installed only by Visual-Studio (I don't
> have...)
> Then...  I had found the good file (tlbinf32.dll) ont a DK site (URL:
> http://lambdasoft.dk)
>
>
> And then, I remembered MakePy (in PinWin). MakePy gives all information.
> Thanks, M. Hammond.


___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Illegal instruction while installing win32 extensions

2005-11-01 Thread John Machin
Olivier Lefevre wrote:
> Trying to run pywin32-205.win32-py2.4.exe on a Windows XP SP2 machine 
> with a HT P4 processor gives me "The NTVDM CPU has encountered an 
> illegal instruction error". Any idea?
> 

Gives me one of those stupid "do you want to send your life history to 
Microsoft" dialogue boxes, not an error message as quoted above. Looks 
like the offending instruction is in ntdll.dll ...

Works OK on Windows 2000 SP 4, with an AMD Athlon CPU.


___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Installation issues....

2005-11-04 Thread John Augustine
Hello,
I am trying to install Python 2.4.2 on my XP laptop
using the MS installer
(http://www.python.org/ftp/python/2.4.2/python-2.4.2.msi)
and I get this error message when I run it:

The cabinet file "python" required for this
installation is corrupt and cannot be used. This could
indicate network error or problem with the package.

I downloaded it several times using both IE and
mozilla just in case it was a download error. That did
not resolve it. 

Has anybody else encountered this and resolved it? Let
me know how you did it.

Thanks,
John.



__ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Pythonwin - Word automation - Removing watermark not working

2005-11-05 Thread John Machin
Gregory Piñero wrote:

> 
> Would anyone happen to know why this my function removewatermark() in 
> this code isn't working?  I copied it from a Word macro I recorded and 
> it did work when I recorded the macro.  When I run it the watermark 
> doesn't go away.
> 
> I've also attached the code in case the formatting gets messed up from 
> the email.
> 
> 
> 
> import sys
> import os
> from win32com.client import gencache, constants

Idle curiosity: why import constants but not use it?

> WORD='Word.Application'
> False,True=0,-1
> 
> class Word:
> def __init__(self):
> self.app=gencache.EnsureDispatch(WORD)
> self.app.Visible = 1
> self.app.DisplayAlerts = 0

What does this do? Suppress any warnings?

> def open(self,doc):
> self.app.Documents.Open(FileName=doc)
> def removewatermark(self):
> self.app.ActiveDocument.Sections(1).Range.Select()
> self.app.ActiveWindow.ActivePane.View.SeekView = 9 # 
> wdSeekCurrentPageHeader

... the cause of the "idle curiosity" question.

> 
> self.app.Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject1").Select()

Have you tried inspecting self.app.Selection before and after the 
attempt to .Delete() it?

> self.app.Selection.Delete()
> self.app.ActiveWindow.ActivePane.View.SeekView = 0 
> #wdSeekMainDocument
> 
> 

How do you know it didn't work?

Your class and its methods don't have any problems that I can see -- 
but it's early here and I'm not quite awake. Is it possible for you to 
show us the few lines of code that you actually used to test this? You 
know, something like:

wc = Word()
wc.open("myfile.doc")
wc.removewatermark()
# then what?

Cheers,
John

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Pythonwin - Word automation - Removing watermark not working

2005-11-05 Thread John Machin
Gregory Piñero wrote:
> See below:
> 
> On 11/5/05, *John Machin* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
> Gregory Piñero wrote:
> 
>  >
>  > Would anyone happen to know why this my function removewatermark() in
>  > this code isn't working?  I copied it from a Word macro I
> recorded and
>  > it did work when I recorded the macro.  When I run it the watermark
>  > doesn't go away.
>  >
>  > I've also attached the code in case the formatting gets messed up
> from
>  > the email.
>  >
>  >
>  > 
>  > import sys
>  > import os
>  > from win32com.client import gencache, constants
> 
> Idle curiosity: why import constants but not use it?
> 
> 
> It was giving me errors when I tried to use the constants so I stopped 
> using them.  A future question perhaps...
> 
>  > WORD='Word.Application'
>  > False,True=0,-1
>  >
>  > class Word:
>  > def __init__(self):
>  > self.app=gencache.EnsureDispatch(WORD)
>  > self.app.Visible = 1
>  > self.app.DisplayAlerts = 0
> 
> What does this do? Suppress any warnings?
> 
> 
> That is correct.

Try unsuppressing warnings. You may learn something.


>  
> 
>  > def open(self,doc):
>  > self.app.Documents.Open(FileName=doc)
>  > def removewatermark(self):
>  > self.app.ActiveDocument.Sections(1).Range.Select()
>  > self.app.ActiveWindow.ActivePane.View.SeekView = 9 #
>  > wdSeekCurrentPageHeader
> 
> ... the cause of the "idle curiosity" question. 
> 
> 
> This doesn't bother me much to write out numbers.

It mightn't bother you. Seeing hard-coded magic numbers bothers the 
bejasus out of many people.

> 
>  >
>  >
> 
> self.app.Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject1").Select()
> 
> 
> Have you tried inspecting self.app.Selection before and after the
> attempt to .Delete() it?
> 
> 
> What do you mean by inspect?

It is an object. It must have some properties that you can retrieve and 
display so that you have some reassurance that you've actually got the 
object you think you've got.



> 
>  > self.app.Selection.Delete()

What happens if you try foo.Delete() and foo is 
frozen/write-protected/whatever?


>  > self.app.ActiveWindow.ActivePane.View.SeekView = 0
>  > #wdSeekMainDocument
>  > 
>  >
> 
> How do you know it didn't work?
> 
> 
> Well I run my code, word opens the file, other changes happen, but the 
> watermark doesn't dissapear.
> 
> Your class and its methods don't have any problems that I can see --
> but it's early here and I'm not quite awake. Is it possible for you to
> show us the few lines of code that you actually used to test this? You
> know, something like:
> 
> wc = Word()
> wc.open("myfile.doc")
> wc.removewatermark()
> # then what?
> 
> 
> Something like this:
> 
> word=Word()
> word.open("myfile.doc")
> word.replace("[Sender]","Bill Brown") #replace a word
> word.removewatermark()
> word.printdoc(numcopies=3) #prints, works fine
> word.close() #closes doc
> word.quit() #shuts down word
>  
> I only included the relevant parts of this class. So you see some 
> methods above that aren't in my class.  I guess I should have included 
> the whole class, sorry.  Now I can't get back to that code until Tuesday :-(
> But all of the methods work fine except for removewatermark.
> 

We're not interested in the parts of your class that are irrelevant to 
the problem. If by Tuesday, no-one has been able to help you by 
inspecting the code that you have shown so far, considering doing this:

1. Make up a *small* .doc file with your watermark in it. Make it from 
scratch i.e. don't copy an existing file and delete your proprietary 
info -- it may not actually be deleted.
2. Assemble the *minimal* Python script that demonstrates the problem.
3. Send it to this mailing list. Include in your message which version 
of (a) Python (2) win32com (3) MS Word (4) MS Windows you are using.

HTH,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Application exception in Python.dll

2005-11-23 Thread John Machin
[EMAIL PROTECTED] wrote:
> 
[snip]
> The error I'm getting is:
>  Event viewer:
> 
> Faulting application python.exe, version 0.0.0.0, faulting module 
> python24.dll, version 2.4.150.1012, fault address 0x000t2f60

What is that "t" in the middle of a hexadecimal number?

> 
> Doctor Watson:
> The application, C:\Python24\python.exe, generated an 
> application error.
> 
> The exception generated was c005 at address 1E07EF60 
> (python24!PyObject_GetAttr).

Tom, this points squarely at a bug in core Python. Report the problem 
using the SourceForge bug tracker. This mailing list is for Mark 
Hammond's win32all aka pywin32 package.
Cheers,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] os.popen4 and spaces in the directory name

2005-12-04 Thread John Machin
Stephen Briley wrote:
> Hi all,
>  
> I would like to run a program via the os.popen (or similar) commands.  
> However, the path to the executable that I would like to run contains 
> spaces (e.g. C:\program files\some directory\engine\theexe.exe).  The 
> python syntax that I am using is as follows:
>  
>  >>> os.popen4("C:\program files\some 
> directory\engine\theexe.exe")[1].read()
>  
> When I try to run it, I get the following message:
> "'C:\\program' is not recognized as an internal or external 
> command,\noperable program or batch file.\n"

You have more than one problem. Firstly, as you have detected, the 
Windows command interpreter's parser has to be steered away from the 
spaces. You do this by using quotes (so-called double quotes, not 
apostrophes aka single quotes).

Secondly, you need to either double your backslashes or use raw strings; 
otherwise the \t in \theexe will be treated by Python as a TAB, not as 
two characters \ and t, and similarly with \n \r \f etc etc.

So: r'"C:\program files\some directory\engine\theexe.exe"'

>  
[snip]
>  
> This time, it doesn't like the directory named "some directory".  Is 
> there any way around this?  The command runs fine if I open up a Windows 
> command prompt and specify the full directory path to the exe.

Thirdly, there seems to be some perceptual problem here. I don't see how 
it could "run fine" if you type the same guff directly at the command 
prompt. It's the same program processing your input. Example (Windows 
XP, SP 2):

C:\junk>c:\program files\textpad 4\textpad.exe
'c:\program' is not recognized as an internal or external command,
operable program or batch file.

C:\junk>"c:\program files\textpad 4\textpad.exe"
[works OK]

>  I am 
> using python 2.4 on a Windows 2003 server.  I am also running this 
> command on Windows 2003 server. 
>  

Fourthly, this mailing list is for discussion of Mark Hammond's 
python-win32 aka win32all package. news:com.lang.python is more 
appropriate and would give you a wider audience.

Cheers,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32 meta-topic

2005-12-05 Thread John Machin
Tim Golden wrote:
>  
> 
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> On Behalf Of Tim Golden
> Sent: 05 December 2005 15:28
> To: [email protected]
> Subject: Re: [python-win32] win32 meta-topic
> 
> [Jeff Bauer]
> 
> 
>>>this mailing list is for discussion of Mark Hammond's
>>>python-win32 aka win32all package. news:com.lang.python
>>>is more appropriate and would give you a wider audience.
> 
> 
>>I occasionally see this kind of reminder here, but it's
>>not obvious from the name of mailing list
> 
> 
> And, in fact, this appears to be the post which 
> announced this list, and it doesn't suggest that
> it's limited to pywin32 (win32all as was):
> 
> http://groups.google.com/group/comp.lang.python/msg/d168af9b981f38ba
> 
> TJG

Thanks, Tim. Maxima mea culpa. I'll pull my head in :-)

Does anyone have any suggestions on what advice to give (a) people who 
post from work via e-mail, engendering enormous disclaimers (b) possibly 
over-sensitive folk who are annoyed by (a)?

Cheers,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] ADSI and LDAP Searches

2005-12-08 Thread Gooch, John
I am trying to get my Python script to search Active Directory for users
with a certain login name and then have it return their adspath
attribute. Previously, I had a working script that used Tim Golden's
active_directory module, but since the more recent round of NT Server
patches, it no longer works, so now I am trying to make a work around to
this issue. 

Here is what I have that is working ( in my test script ):


import win32com.client 
username = "John.Gooch"


adsi = win32com.client.Dispatch('ADsNameSpaces')
ldap = adsi.getobject('','LDAP:')
DSO = ldap.OpenDSObject( "LDAP://MER2-ECHDC2.echostar.com","","", 1)
_

It works up to here, so now I assume I am connected to Active Direcory
and can now run an LDAP-style search:
_
DSO.execute(";(cn=*);adspath;top")
_

Ok,no go on that line( throws error "AttributeError: .execute"
, but then I am complete guessing the syntax based upon an old Perl
script I had that used to do this job. 


Does anyone have a working example of searching Active Directory? Of you
course you can put in made up domain/server names where necessary. 

Thank You, 


John A. Gooch
Systems Administrator
IT - Tools
EchoStar Satellite L.L.C.
9601 S. Meridian Blvd.
Englewood, CO  80112
Desk: 720-514-5708 



___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel

2006-01-10 Thread John Machin
bob wrote:
> Viola, it displays 6. 

:-)
Cello, it displays 7.
(-:
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel

2006-01-10 Thread John Machin
Stefan Elwesthal wrote:
> Hi all!
> 
> I have to ask, cause two days later I'm starting to get annoyed ;-)
> 
> How could I use PythonCOM and save my re-worked Excel file as an xlCSV file? 
> All I get is
> "SaveAs method in Worksheet class failed".
> 
> Is something wrong with this line?

Yes. Two things.

> sh.SaveAs("C:\file.csv", FileFormat='xlCSV')

(1) Elementary precaution for working with file paths in Windows using 
Python is to use eithereither raw strings or slashes:

sh.SaveAs(r"C:\file.csv", FileFormat='xlCSV')
or
sh.SaveAs("C:/file.csv", FileFormat='xlCSV')

By so doing you don't run the risk of the first letter of a "word" being 
interpreted as a control character (form feed in your case).

(2) The FileFormat argument is an int, not a string

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel

2006-01-10 Thread John Machin
bob wrote:
> At 11:16 AM 1/10/2006, John Machin wrote:
> 
>> bob wrote:
>>
>>> Viola, it displays 6.
>>
>>
>> :-)
>> Cello, it displays 7.
>> (-:
> 
> Version difference? I'm using Excel 2000. and I get xlcsv = 6! But it 
> should stay the same!
> 
> You can also open the object browser (F2) within the VB Editor, select 
> XlFileFormat in the classes list, then select xlCSV in the members list. 
> The value shows up in the gray box below.
> 
> 

Arithmetic progression: violin, viola, cello, bass.
Please adjust your humour detector.



___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Apologies - Spawn problem

2006-01-31 Thread John Machin
Frank Peacock wrote:
> Hello again
> 
> I need to correct the previous email. The correct main.py file is attached
> now.
> 
> The interesting thing is that the naming of the python file does not change
> the result.
> 
> The result always is output to the screen: "Main" and then "Exit", there is
> no "subprocess" outputted.
> 

I'm not about to dump odd files into my root directory; I can't 
reproduce your symptoms using a sub-directory ... see below.
I'm running Win XP Pro SP2; yours is what?
Why are you still running Python 2.1???
BTW, print is not a function, it's a statement.
You should get out of the backslashitis habit 
('c:\python21\\python.exe') very quickly. Apart from the fact that for 
consistency you should have had 'c:\\python21\\python.exe', it is much 
easier to compose and read r'c:\python21\python.exe'.

HTH,
John

C:\junk>type main.py
# Main script
import os

print("main")

os.spawnv(os.P_WAIT, 
'c:\python21\\python.exe',('python.exe','c:\\subprocess.py'
))

print("exit")
C:\junk>type subprocess.py
import sys
print "subprocess", sys.argv

C:\junk>type main2.py
# Main script
import os

print "main"

os.spawnv(
 os.P_WAIT,
 'c:\python21\\python.exe',
 ('"just about any old rubbish"', 'c:\\junk\\subprocess.py',)
 )

print "exit"

 running main with Python 2.4.2
 got IDENTICAL results with 2.1.3
 (by doing c:\python21\python main*.py)
C:\junk>python main.py
main
python.exe: can't open file 'c:\subprocess.py'
exit

C:\junk>python main2.py
main
subprocess ['c:\\junk\\subprocess.py']
exit

C:\junk>

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Using win32com Constants

2006-02-17 Thread John Machin
On 18/02/2006 11:25 AM, Dan Glassman wrote:
> David Carter wrote:
> 
>>>-Original Message-
>>>From: Robert Brewer [mailto:[EMAIL PROTECTED] 
>>>Sent: Friday, February 17, 2006 4:11 PM
>>>To: David Carter; [email protected]
>>>Subject: RE: [python-win32] Using win32com Constants
>>>
>>>
>>>David Carter wrote:
>>>
>>>
>>>>Why is it that when I want to use a win32COM constant such as 
>>>>acViewNormal in an MS Access COM automation session I find I
>>>>have to use some convoluted thing like:
>>>>
>>>>ComConstants = 
>>>>win32com.client.constants.__dict__["__dicts__"][0]
>>>>viewtype = ComConstants['acViewNormal']
>>>>
>>>>Am I missing something obvious? 
>>>
>>>Are you calling Dispatch before referencing the constants?
>>>
>>>http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32
> 
>  >
> 
>>Yes, -those- constants work fine. They're the application specific constants
>>that require the convolution.
> 
> 
> He wasn't suggesting that Dispatch wasn't working, but rather pointing out 
> that the constants don't work until *after* you've called Dispatch.
> 
> The way to use the constants (after calling Dispatch) is like this:
> 
>  >>> win32com.client.constants.acViewNormal
> 
> If that's not working, then I'd say there's nothing *too* obvious that you're 
> missing.  You've obviously run makepy, otherwise even the convolution 
> wouldn't 
> work...
> 

David, Forget your convolvulus; show us a small complete runnable piece 
of code that tries to do what you expect/want, but fails.
Cheers,
John

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel using python

2006-02-20 Thread John Machin
On 20/02/2006 7:46 PM, Tim Golden wrote:
> [yeswanty devi]
> 
> | Hello all,
> |  if we have number of excel sheets in a workbook.can 
> | we access a selected sheet in the workbook. when i try to 
> | acces it always goes to the last sheet. 
> 
> I assume this is the kind of thing you want:
> (somewhat exaggerated example, but ...)
> 
> 
> import os
> import win32com.client
> 
> xl = win32com.client.Dispatch ("Excel.Application")
> #
> # Create a new workbook with a default
> #  number of sheets (probably 3)
> #
> wb = xl.Workbooks.Add ()
> print wb.Sheets.Count
> 
> sheet0 = wb.Sheets[0]
> sheet1 = wb.Sheets[1]
> sheet2 = wb.Sheets[2]
> 
> sheet0.Name = "First sheet"
> sheet1.Name = "Second sheet"
> sheet2.Name = "Third sheet"
> 
> wb.SaveAs (Filename="c:\\temp\\test.xls")
> wb.Close ()
> xl.Quit ()
> 
> os.startfile ("c:\\temp\\test.xls")
> 
> 

Errrmmm ... I got the impression that the OP wanted to access a 
particular sheet in an existing workbook, not to create a new workbook.
The OP didn't say whether he wanted to select by name or number; perhaps 
  some kind soul could tell him both :-)

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel using python

2006-02-20 Thread John Machin
On 20/02/2006 8:02 PM, Tim Golden wrote:
> [John Machin]
> | 
> | On 20/02/2006 7:46 PM, Tim Golden wrote:
> | > [yeswanty devi]
> | > 
> | > | Hello all,
> | > |  if we have number of excel sheets in a workbook.can 
> | > | we access a selected sheet in the workbook. when i try to 
> | > | acces it always goes to the last sheet. 
> | > 
> | > I assume this is the kind of thing you want:
> | > (somewhat exaggerated example, but ...)
> | > 
> 
> [... snip ...]
> 
> | 
> | Errrmmm ... I got the impression that the OP wanted to access a 
> | particular sheet in an existing workbook, not to create a new 
> | workbook.
> 
> I guessed; but I usually try to make my examples run
> on their own two feet (or something!) if only so I
> can test the thing before posting. That's the only
> reason I created the book before selecting the sheets.
> I admit I do assume the existence of c:\temp.
> 
> Good point about the names; I didn't think of that.
> 
> OK, given the workbook created in my previous post...
> 
> 
> import win32com.client
> 
> xl = win32com.client.Dispatch ("Excel.Application")
> wb = xl.Workbooks.Open ("c:\\temp\\test.xls")
> 
> sheet0 = wb.Sheets ("First sheet") # or wb.Sheets[0]
> sheet1 = wb.Sheets ("Second sheet") # or wb.Sheets[1]
> #
> # etc.
> #
> 
> wb.Close ()
> xl.Quit ()
> 
> 
> 
> TJG
> 

OK, great, Tim, we're almost there :-)
"when i try to  acces it always goes to the last sheet." ... looks like 
the OP wants the default sheet to point to some sheet other than the 
last sheet; ho wdo we do that?
Cheers,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel using python

2006-02-20 Thread John Machin
On 20/02/2006 10:15 PM, Tim Golden wrote:
> [John Machin]
> 
> | > OK, given the workbook created in my previous post...
> 
> [ ... snip more code ...]
> 
> | OK, great, Tim, we're almost there :-)
> | "when i try to  acces it always goes to the last sheet." ... 
> | looks like 
> | the OP wants the default sheet to point to some sheet other than the 
> | last sheet; ho wdo we do that?
> 
> I swear this reads like the script of an educational children's
> programme! ;) But you're quite right to point out how scantily
> I read the original question and just dived for my keyboard.
> 
> It's not clear to me what the "default" sheet is. What I didn't
> show in my code examples is the concept of the ActiveSheet which
> can be changed by calling a sheet's .Select method. When the
> workbook is saved, that active sheet is saved with it. (ie the
> activeness of one sheet is saved). Maybe that's the idea?
> [Do you think the OP's still reading?]
> 
> 
> import win32com.client
> 
> xl = win32com.client.Dispatch ("Excel.Application")
> wb = xl.Workbooks.Open ("c:/temp/test.xls")
> print wb.ActiveSheet.Name
> #
> # probably prints "First Sheet"
> #
> wb.Sheets ("Third Sheet").Select ()
> print wb.ActiveSheet.Name
> # prints "Third Sheet"
> 
> wb.Save ()
> wb.Close ()
> 
> wb = xl.Workbooks.Open ("c:/temp/test.xls")
> print wb.ActiveSheet.Name
> #
> # prints "Third Sheet"
> #
> 
> 
> Any better?
> 
> TJG
> 

Tim, that's fantastic. Hold out your hand for the elephant stamp :-)
Is the OP still reading? Yes, I often wonder that too, when threads get 
a bit long. But apart from moderate banter, we haven't got off his 
topic, so let's hope he's hung in there, time zones permitting.
Cheers,
John

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel using python

2006-02-20 Thread John Machin
On 20/02/2006 10:37 PM, Tim Golden wrote:
> | From: John Machin [mailto:[EMAIL PROTECTED] 
> |
> | Tim, that's fantastic. Hold out your hand for the elephant stamp :-)
> 
> Must be an American thing? (Obligatory Monty Python
> reference: I'm sorry, old man, I don't quite follow your
> banter!)
> 

Tim, mate, must it? It's funny how the poms think I'm a seppo, and the 
seppos think I'm a pom ... the reference is to children being rewarded 
for endeavour by having an inked rubber stamp applied to their 
extremities, typically a stamp depicting some nice creature like a 
heffalump or a bunyip.
Cheers,
Jophn
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] COM ports connecting

2006-02-21 Thread John Machin
On 22/02/2006 5:51 AM, Math wrote:
> Hello,
>  
> Anybody could give me an example code of how connect/comunicate through 
> COM ports (i.e. COM1, COM2).
> I'm under windows XP
>  > Thanks!!!
> Math

http://pyserial.sourceforge.net/


___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python Newbie Question

2006-02-22 Thread John Machin
On 23/02/2006 11:53 AM, Heang Lim wrote:
> I've installed Python on my c:\python23 directory and Apache on my
> c:\Apache2 directory.  On my DOS windows, I went to c:\Apache\htdocs
> directory and enter 'python' to go into the interactive mode.  When I
> tried to import some modules such as 'import os' or 'import string', I
> was getting 'ImportError: no module named os', etc.  Am I missing some
> sort of environment variable setting somewhere?   I have my PYTHONPATH
> system variable set to 'c:\python23'.
> 
do this:
DOS-prompt>python
>>> import sys
>>> sys.path
and show us the output (copy/paste).

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python Newbie Question

2006-02-23 Thread John Machin
On 24/02/2006 10:23 AM, Heang Lim wrote:
> I've been fiddling with the setup and it might have done more damage
> than good.  The reason I'm using Python 2.3.5 is because of WindPySend
> DLL that I found on the net to do test automation and it does not
> support Python 2.4.  Not yet at least.  Due to this I'm being forced
> to use 2.3.5.  Thanks for your feed back.  I think I'm going to
> re-install Python instead of trying to fix it.
> 
> HL

Re-installing sounds like a very good idea. Randomly perturbing the 
setup and then ignoring warning messages is not a good idea.

"I'm using Python 2.3.5" is contradicted by your previous message 
"Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] 
on win32". You may have TWO (or more!) installations of Python 2.3. 
Remove ALL traces of ALL installations of Python 2.3 before re-installing.

Please don't top-post.

> On 2/23/06, John Machin <[EMAIL PROTECTED]> wrote:
> 
>>On 24/02/2006 3:02 AM, Heang Lim wrote:
>>
>>>Hello John,
>>>
>>>Here is the sys.path output:
>>>
>>>C:\\Apache2\htdocs>python
>>>'import site' failed; use -v for traceback
>>
>>Hmmm ... either (1) you get this all the time and you didn't think it
>>was worth doing anything about or worth mentioning when you asked your
>>question or (2) you have been fiddling about with your setup since
>>asking :-(
>>
>>So do what it says:
>>dos-prompt>python -v
>>
>>and tell us the output.
>>
>>
>>>Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on 
>>>win32
>>>Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>>>>>import sys
>>>>>>sys.path
>>>
>>>['', 'c:\\Python23', 'C:\\Apache\\Apache2\\htdocs\\python23.zip',
>>
>>The second entry above is from your PYTHONPATH environment variable.
>>Note the capital P. This entry is not useful -- see the multiple
>>occurrences of c:\\python23 below -- and may be causing some confusion.
>>Get rid of it.
>>
>>The third entry is a mind-boggler. The remainder  below is just weird.
>>Here's what a plain vanilla Python 2.3 installation gives on my machine:
>>
>>C:\junk>c:\python23\python
>>Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on
>>win32
>>Type "help", "copyright", "credits" or "license" for more information.
>> >>> import sys
>> >>> sys.path
>>['', 'c:\\python23\\python23.zip', 'C:\\junk', 'c:\\python23\\DLLs',
>>'c:\\python23\\lib', 'c:\\python23\\lib\\plat-win',
>>'c:\\python23\\lib\\lib-tk', 'c:\\python23',
>>'c:\\python23\\lib\\site-packages']
>>
>>Why are you using Python 2.3 at all instead of 2.4? You are not so
>>constrained by Apache AFAICT. Why Python 2.3.3 and not 2.3.5??
>>
>>The general impression is that your Python installation is close to FUBAR.
>>
>>Did you install Python 2.3 in the usual manner? What fiddling about have
>>you been doing since?
>>
>>If you are trying to do mod_python with Apache under Windows, might it
>>not be better asking on the modpython mailing list?
>>
>>
>>>'c:\\python23', 'c:\\py
>>>thon23\\Lib\\site-packages\\DLLs', 'c:\\python23',
>>>'c:\\python23\\Lib\\site-packages\\lib
>>>', 'c:\\python23', 'c:\\python23\\Lib\\site-packages\\lib\\plat-win',
>>>'c:\\python23', 'c:
>>>\\python23\\Lib\\site-packages\\lib\\lib-tk', 'C:\\Apache\\Apache2\\htdocs']
>>>
>>>
>>>Thanks for your response to my email.
>>>
>>>HL
>>>
>>>On 2/22/06, John Machin <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>>On 23/02/2006 11:53 AM, Heang Lim wrote:
>>>>
>>>>
>>>>>I've installed Python on my c:\python23 directory and Apache on my
>>>>>c:\Apache2 directory.  On my DOS windows, I went to c:\Apache\htdocs
>>>>>directory and enter 'python' to go into the interactive mode.  When I
>>>>>tried to import some modules such as 'import os' or 'import string', I
>>>>>was getting 'ImportError: no module named os', etc.  Am I missing some
>>>>>sort of environment variable setting somewhere?   I have my PYTHONPATH
>>>>>system variable set to 'c:\python23'.
>>
>>No you don't; see above.
>>
>>
>>
>>>>do this:
>>>>DOS-prompt>python
>>>>
>>>>
>>>>>>>import sys
>>>>>>>sys.path
>>>>
>>>>and show us the output (copy/paste).
>>>>
>>>>
>>>
>>>
>>>
>>
> 
> 

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] driving MS Access from python

2006-03-13 Thread John Machin
On 14/03/2006 10:04 AM, Phill Atwood wrote:
> Tim,
> 
> Thanks. I've downloaded and installed adodb for Python.  But I guess I 
> need to install mxODBC as well.  But I'm not quite understanding the 
> docs I'm reading on how to do this.  It seems very complex
> 
> Phill
> 

Phill,

Sorry, you've lost me ... I thought "this" (installing mxODBC) was as 
simple as downloading the two installers ("base" and "commercial") that 
match the version of Python that you are using, and running them. What 
docs are you reading?

Cheers,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] driving MS Access from python

2006-03-13 Thread John Machin
On 14/03/2006 11:19 AM, Phill Atwood wrote:
> 
>>
>> Sorry, you've lost me ... I thought "this" (installing mxODBC) was as 
>> simple as downloading the two installers ("base" and "commercial") 
>> that match the version of Python that you are using, and running them. 
>> What docs are you reading?
> 
> http://phplens.com/lens/adodb/adodb-py-docs.htm#databases
> 
> I guess this is more PHP oriented...
> 
> I'm not sure what you are referring to when you say 'two installers 
> "base" and "commercial"'. 

You wrote "But I guess I
need to install mxODBC as well.  But I'm not quite understanding the
docs I'm reading on how to do this."

I.e. IMHO the only reasonable construction was that you were asking how 
to install mxODBC. That's what I replied to. You need to install mx base 
to get the date/time stuff, and mx commercial to get mxODBC.




___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] py2exe & transparent icons

2006-04-18 Thread John Machin
On 19/04/2006 2:49 AM, Metz, Bobby W, WCS wrote:
> All,
>   This may not be the right list for this, but I figured there's
> bound to be some py2exe experts. 
[snip]
There's bound to be even more py2exe experts on 
[EMAIL PROTECTED] :-)

> 
> Thanks,
> 
> Bobby
> ___
> Python-win32 mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-win32
> 
> 

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] SimpleXMLRPCServer Windows service

2006-04-27 Thread John Ferrell

I am trying to create a Windows service
using SimpleXMLRPCServer and win32serviceutil.  The service itself
seems to be working properly (starts, stops, etc) and I can connect using
an XMLRPC client from the localhost.  However when I connect from
a remote client, I either get a socket error or an xmlrpclib.ProtocolError
error.  If I use serve_forever() rather than handle_request(), the
remote clients can connect but it breaks the Windows service functionality
(can't stop the service).  It would seem that the problem is related
to the way the service handles remote connections, but I cannot figure
out what the problem is.  

I have searched around, but can't find
any example code.  Hopefully someone can point me in the right direction.

thanks,
John

## XML-RPC Service
import win32serviceutil
import win32service
import win32event
import win32evtlogutil
import win32file
import servicemanager
import SimpleXMLRPCServer

class OBJECT:
    def hello(self):
        return "Hello
World"

class XMLRPCSERVICE(win32serviceutil.ServiceFramework):
    _svc_name_ = "XMLRPCSERVICE"
    _svc_display_name_ = "XMLRPCSERVICE"
    _svc_description_ = "XMLRPCSERVICE"
        
    def __init__(self, args):
        win32evtlogutil.AddSourceToRegistry(self._svc_display_name_,
sys.executable, "Application")
        win32serviceutil.ServiceFramework.__init__(self,
args)
        
        self.hWaitStop
= win32event.CreateEvent(None, 0, 0, None)
        self.hSockEvent
= win32event.CreateEvent(None, 0, 0, None)

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        ## Write
a started event
        servicemanager.LogMsg(
           
servicemanager.EVENTLOG_INFORMATION_TYPE,
           
servicemanager.PYS_SERVICE_STARTED,
           
(self._svc_name_, ' (%s)' % self._svc_name_))
        
        server =
SimpleXMLRPCServer.SimpleXMLRPCServer(("", 8080))
        object =
OBJECT()
        server.register_instance(object)
        
        while 1:
           
win32file.WSAEventSelect(server, self.hSockEvent,win32file.FD_ACCEPT) 
           
rc = win32event.WaitForMultipleObjects((self.hWaitStop,self.hSockEvent),
0, win32event.INFINITE)
           
if rc == win32event.WAIT_OBJECT_0:
           
    break
           
else:
           
    win32file.WSAEventSelect(server,self.hSockEvent, 0)
           
    server.handle_request()
           
    #server.serve_forever()  ## Works, but breaks the Windows
service functionality
           
        
        ## Write
a stopped event
        win32evtlogutil.ReportEvent(self._svc_name_,
           
                     
  servicemanager.PYS_SERVICE_STOPPED,0,
           
                     
  servicemanager.EVENTLOG_INFORMATION_TYPE,
           
                     
  (self._svc_name_,""))

if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(XMLRPCSERVICE)

--
## XML-RPC Client
import xmlrpclib

server = xmlrpclib.ServerProxy("http://remoteserver:8080")
print server.hello()___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] curses and _curses

2006-05-01 Thread John Machin
On 2/05/2006 8:16 AM, Dean Allen Provins wrote:
> Hello:
> 
> I just installed the 2.4 version of Python on a WinXP box.  I then
> copied over my python code which runs under Linux.  This code uses
> "curses.ascii" (isspace specifically).
> 
> The Win version of the libraries has a curses directory and within it,
> the ascii.py module.  Unfortunately, the __init__.py module in the
> curses directory expects to import "_curses" (as it does on Linux), and
> this is nowhere to be found in the Windows python install directory (it
> is part of a shared library under Linux).
> 
> To get around the problem, I simply commented out the entire __init__.py
> module, but this provides only symptomatic relief.
> 
> Any readers know why the "_curses" library is missing, or in other
> words, have I found an "error of omission"?
> 

http://www.amk.ca/python/howto/curses/

"Nobody has made a Windows port" or words to that effect ...

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] curses and _curses

2006-05-02 Thread John Machin
On 3/05/2006 12:44 AM, Dean Allen Provins wrote:
> Roger Upole wrote:
>> Bill Burns wrote:
>>
>>>> On 2/05/2006 8:16 AM, Dean Allen Provins wrote:
>>>>
>>>>
>>>>> Hello:
>>>>>
>>>>> I just installed the 2.4 version of Python on a WinXP box.  I then
>>>>> copied over my python code which runs under Linux.  This code uses
>>>>> "curses.ascii" (isspace specifically).
>>>>>
>>>>> The Win version of the libraries has a curses directory and within it,
>>>>> the ascii.py module.  Unfortunately, the __init__.py module in the
>>>>> curses directory expects to import "_curses" (as it does on Linux), and
>>>>> this is nowhere to be found in the Windows python install directory (it
>>>>> is part of a shared library under Linux).
>>>>>
>>>>> To get around the problem, I simply commented out the entire __init__.py
>>>>> module, but this provides only symptomatic relief.
>>>>>
>>>>> Any readers know why the "_curses" library is missing, or in other
>>>>> words, have I found an "error of omission"?
>>>>>
>>>>
>>>> http://www.amk.ca/python/howto/curses/
>>>>
>>>> "Nobody has made a Windows port" or words to that effect ...
>>> Actually, I just found this but I've never tried it
>>>
>>> http://adamv.com/dev/python/curses/
>>>
>>> but I believe John is partial right ;-), in the sense that, the Standard 
>>> Python distribution doesn't supply curses for Windows.
>>>
>>> So you have *not* found an "error of omission".
>>>
>>> Google "Windows _curses" on comp.lang.python for more info and other 
>>> possibilities.
>>>
>>> Bill
>>
>> Newer versions of Pywin32 come with a win32console module that
>> allows you to create and interact with console windows.
>>
>>   Roger
> 
> John. Bill and Roger:
> 
> Thanks for your responses.
> 
> Fortunately, I don't need anything from the curses library except the
> "isspace" function in "curses.ascii".  Since the module "_curses" isn't
> available in the WIN version, I've decided to copy the "ascii.py" module
> over to my collection of codes and transfer it to Windows, rather than
> try to import a surgically-altered version of the curses module
> (described above).  This should simplify the installation on other WIN
> machines.
> 

 From curses/ascii.py:

def isspace(c): return _ctoi(c) in (9, 10, 11, 12, 13, 32)

Code reuse is great, but transporting and importing a whole irrelevant 
module to get a fugly ill-coded one-liner and a further unnecessary 
function call (_ctoi) qualifies for bogglement of the month [so far].

Try inserting this OS-independent one-liner in your code somewhere:

def isspace(c): return c in (' ', '\t', '\n', '\r', '\f', '\v')

It appears to work all the way back to Python 2.1 (see below). I could 
arc up the box with 1.5.2 on it and check it out for you if you truly 
rooly want a Python-version-agnostic function :-)

C:\junk>\python21\python
Python 2.1.3 (#35, Apr  8 2002, 17:47:50) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
 >>> def isspace(c): return c in (' ', '\t', '\n', '\r', '\f', '\v')
...
 >>> for x in (666, 1.23, 'a', 'z', 'fubar', ' ', '\t', '\n', '\r', 
'\f', '\v'):
... print repr(x), isspace(x)
...
666 0
1.23 0
'a' 0
'z' 0
'fubar' 0
' ' 1
'\t' 1
'\n' 1
'\r' 1
'\x0c' 1
'\x0b' 1
 >>> for x in (8, 9, 10, 11, 12, 13, 14, 31, 32, 33):
... print x, repr(chr(x)), isspace(chr(x))
...
8 '\x08' 0
9 '\t' 1
10 '\n' 1
11 '\x0b' 1
12 '\x0c' 1
13 '\r' 1
14 '\x0e' 0
31 '\x1f' 0
32 ' ' 1
33 '!' 0
 >>>

HTH,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Why I get wrong filetime values with win32 api(FindFilesW) ?

2006-05-11 Thread John Machin
On 11/05/2006 5:47 PM, Christian Stooker wrote:
> Mark Hammond írta:
>> I'm guessing it is related to the GMT offset.  The MSDN docs for the
>> FILETIME structure say:
>>
>>   Furthermore, FAT records times on disk in local time. However,
>>   NTFS records times on disk in UTC. For more information ...
>>
>> Otherwise I'm afraid I have no idea...
>>
>> Mark
>>
>>   
> 
> Hi !
> 
> As I say: interesting, because os.get*time functions get good result for 
> the files.

[snip]

> 
> As you can see, the different is two hours.
> We are in GMT+01 timezone,

Call me crazy, but the Brits are on summer time (UTC+1) and you should 
be on CEST (Central Europe Summer Time) (UTC+2).

Check this out: http://www.timeanddate.com/worldclock/city.html?n=50

> and I use NTFS and WXP.  
> 

Here's what I got with your code, with NTFS, in eastern Australia 
(UTC+10), local time is after 8 p.m.

C:\junk\winfiletime>winfiletime.py
[u'C:\\junk\\winfiletime\\winfiletime.py']
pw32 1147306617
pyos 1147342617
pw32 Thu May 11 10:16:57 2006
pyos Thu May 11 20:16:57 2006

As expected.




___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Try to got short path for files - but goterror...

2006-05-25 Thread John Machin
On 25/05/2006 8:12 PM, Metz, Bobby W, WWCS wrote:
> Mark,
>   Thanks for that.  I didn't read an earlier entry from the
> submitter close enough.  Someone else had told them that
> GetShortPathName wasn't supported but I didn't pay attention to the W at
> the end...could have saved myself a couple of posts if I had.  I'll
> chalk my "lack of clear direction" up to this as well...I was excluding
> GetShortPathName in my search due to comment below.
> 
>>> Looks like you need a GetShortPathNameW() but it's not
> implemented.
>>> Raise it as an issue on the pywin32 sourceforge bug register.
>>> Tell Mark
>>> I sent you :-)
> 

Oh boy am I glad that's been sorted out. It was in danger of becoming 
"Hysterically Confused Thread of the Month" :-)

Cheers,
"Someone else"


___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] deviceiocontrol string format

2006-05-25 Thread John Machin
On 26/05/2006 4:43 AM, [EMAIL PROTECTED] wrote:
> Dear All,
> 
> I am new to python win32, and i cannot figure out how to format the data 
> string for deviceiocontrol code with win32file.
> 
> I have the following c struct in my driver file:
> typedef struct _WRITE_DEVICE_DATA_INPARAMS
> {
>   UCHAR ucMemorySpace;// 0: I/O Space, 1: Mem Space.
>   ULONG ulPhysicalAddress;// Dword-aligned offset to write to.
>   ULONG ulItemSize;   // 1: Byte, 2: Word, 4: Dword.
>   ULONG ulItemCount;  // Number of bytes, words or 
> dwords.
> 
>   union{
>   UCHAR vucDataBuf[1];
>   USHORT vusDataBuf[1];
>   ULONG vulDataBuf[1];
>   }data;
> 
> }WRITE_DEVICE_DATA_INPARAMS, *PWRITE_DEVICE_DATA_INPARAMS;
> 
> I tried to format my data string like this:
> data=struct.pack('BLLLH',2,1020,2,1,0)
> 
> but got the following error:
> OverflowError: long int too large to convert to int

It would help if you showed the code that you actually executed and the 
traceback.

There is no problem with the above pack call:

Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import struct
 >>> data=struct.pack('BLLLH',2,1020,2,1,0)
 >>> data
'\x02\x00\x00\x00\xfc\x03\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x00\x00'
 >>> hex(1020)
'0x3fc'


Perhaps you meant that the error is coming from deviceiocontrol.

You will notice that the first item is padded out with 3 bytes of \x00 
so that the 2nd item is aligned on a 32-bit boundary. This may be the 
cause of your problem. The error that you got is consistent with 
something trying to convert (positive) 0xFC00L to a *signed* 32-bit 
integer. Why signed, I don't know.

What does &(mystruct.ulPhysicalAddress) - &(mystruct.ucMemorySpace)
[warning: my C is a little rusty!]
give you in C (using the compiler used for the driver)?

If the answer is 1, you need to lose the padding; read the fine print at 
the end of the struct.pack manual section. Note that the default 
alignment used is according to the C compiler used to compile Python 
(Microsoft), which may differ from the alignment used by the compiler 
used for the driver (gcc?).

If the answer is 4, then the problem is not with your usage of struct.pack.

> 
> Apparentely the error is coming from 1020. However it is define as ulong 
> for both case the c struct and the python struct.pack.
> 


HTH,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Building win32 extensions to Python - crash

2006-06-16 Thread John Machin
On 17/06/2006 3:49 AM, Chris Botos wrote:
> James Carroll wrote:
>>> Thanks for your responses.  I went ahead and tried MinGW.  I was able to
>>> build and use screengrabber and other examples.  I also used it as an
>>> example and created successfully a very simple "hello python" extension.
>> Fantastic!  they must be more (binary) compatable than I thought.
> 
> Well, ... I've managed to crash python by using an "ostream" rather than
> "printf".  The code is below.   If I replace the std::cout with a printf
> the code works fine.  The symptom is that the cout is flushed to the
> console as it should be, then the python shell hangs.  A few seconds
> later a "send error report to microsoft" dialog comes up.  Here's some
> of the information it provided, in addition to saying it was an
> unhandled exception:
> Error Signature:
> AppName: python.exe AppVer: 0.0.0.0 ModName: ntdll.dll
> ModVer: 5.1.2600.2180 Offset: 00018fea
> 
> I'm using
> Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
> win32;  MinGW Developer Studio 2.05.
> Does anyone know what I'm doing wrong?

You said it yourself: """using an "ostream" rather than "printf"""".
My guess would be that the MinGW C++ cout data structures are not 
initialised.

My experiences, FWIW: I've been using both MinGW and Borland 5.5 for 
ages, for extensions that I've written myself in C, and also using 
Borland to compile the C code generated by Pyrex. I've never tried to 
wrap an existing C library.

Here are my rules for staying out of trouble:
1. Use C, not C++.
2. If there is a function in the Python/C API that does the job, use it 
in preference to an RTL function. This applies especially to malloc() 
and free().
3. Don't try to use resources across RTL boundaries e.g. trying MinGW 
fwrite() on a (FILE *) that was opened by the MSC RTL and obtained by 
calling PyFile_AsFile()

HTH
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] EasyDialogs - how to set initial path

2006-07-03 Thread John Machin
On 30/06/2005 5:43 PM, Radovan Grznarik wrote:
> Hi,
> 
> I am using EasyDialogs (AskFileForOpen) and I am not able to set the
> initial open path. I found in Python help that it should be 3rd
> parameter,

I doubt it. The Python *documentation*, whose first two lines ("2.7 
EasyDialogs -- Basic Macintosh dialogs", "Availability: Macintosh.) are 
easily ignored, does contain this:

AskFileForOpen( [message] [, typeList] [, defaultLocation] [, 
defaultOptionFlags] etc etc.

But you are running on Windows, and to get as far as you did, you must 
have downloaded Jimmy Retzlaff's 3rd party not quite-compatible subset 
EasyDialogs module.

Then if you use the Python *help*, you get:

C:\junk>python
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
|>> import EasyDialogs
|>> EasyDialogs.__file__
'c:\\python24\\lib\\site-packages\\EasyDialogs\\__init__.pyc'
 >>> help(EasyDialogs.AskFileForOpen)
Help on function AskFileForOpen in module EasyDialogs:

AskFileForOpen(message=None, typeList=None, version=None, 
defaultLocation=None,
dialogOptionFlags=None, location=None, clientName=None,
[snip]


  then I tried this
> 
> filename = EasyDialogs.AskFileForOpen("title","*.*","d:\\")
> 
> but it does not work, and opens dialog in actual directory of running script.

If it's any consolation, you're not the first to get trapped like this :-)

> 
> os.chdir("d:\\") before AskFileForOpen also does not work.
> 

Here's a handy tip: when a function has keyword arguments, use the 
keywords -- not only does it save you counting args, it helps document 
your code.

Here's a (slightly edited) example from one of my scripts:
 import EasyDialogs
 infname = EasyDialogs.AskFileForOpen(
 windowTitle='Fu or Bar file from XYZ',
 typeList=[
 ('All files (*.*)', '*.*'),
 ],
 defaultLocation=r'G:\XYZfiles\FuBar',
 # message='... a message',
 )

Cheers,
John

___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Fatal Error

2006-09-19 Thread John Machin
On 20/09/2006 5:09 AM, Ahmed, Shakir wrote:
> 
> I am running a script and getting the following error, any idea is
> highly appreciated.
> 
> The script is mainly a loop work for sixteen time and raises the error
> on 10th cycle.
> 
> 
> NO free BITSYS Channels (BITCHN)
> 

Dear Shakir,

It is a good idea when asking questions about problems like this to
(1) say what efforts you have made to find a solution yourself
(2) show a snippet of the code and the error details (e.g. Python 
traceback).

I suspect the answer to (1) is "not much". A little googling leads me to 
the impression that you have been struck by a known but unfixed bug in a 
commercial product. According to posts in forums on the vendor's web 
site, the bug appears to happen when the software is accessed via COM 
from any language (e.g. Visual Basic as well as Python) -- so it's not a 
Python problem.

Your e-mail address suggests that you are working for a U.S. state 
government agency, which has presumably paid a licence fee for the 
product. In that case I suggest you avail yourself of whatever support 
options are available from the product vendor.

HTH,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Trying to run an external program

2006-09-20 Thread John Machin
On 21/09/2006 8:03 AM, Brant Sears wrote:
> Hi. I'm new to Python and I am trying to use it on Windows XP. I am trying to 
> use it to replicate the same thing that I do on Linux and Mac via shell 
> scripting (Batch files aren't powerful enough, so I've decided to try to use 
> Python.)
> 
> What I want to do is execute a program and have the results of the execution 
> assigned to a variable. According to the documentation the way to do this is 
> as follows:
> 
> import commands
> x = commands.getstatusoutput('dir')
> 
> This should assign "x" to be the output of the command "dir". However, when I 
> run this (or any other command), x ends up being:
> 
> (1, "'{' is not recognized as an internal or external command,\noperable 
> program or batch file.")

Actually, the output is defined to be a tuple (exitstatus, 
command_result). The exitstatus is 1, and the "is not recognised" thing 
is the result of the command, which was evidently "{" (!!)

> 
>>From looking through the documentation, I'm believing that the implementation 
>>of commands.getstatusoutput is actually some multi-step thing that starts 
>>with issuing the bracket character that is being choked on. This leads me to 
>>believe that Python or perhaps just the commands module is not setup 
>>correctly on my computer.
> 
> I installed Python using the Python2-5.msi link that I found at:
> http://www.python.org/download/releases/2.5/
> 
> I left everything the default during installation, so Python was installed to 
> C:\Python25. The only other thing I did was add this PATH variable on my 
> computer.
> 
> Any ideas on what I might do to troubleshoot this?
> 

(1) Read the manual: "Availability: Unix"
(2) Read line 25 of the source code (c:\python25\lib\commands.py)

Others may know of canned Python solutions for Windows; all I can 
suggest is to write something like the (very short) commands module, 
using the functions in the subprocess module.

HTH,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Picture.Insert, Excel issue

2006-10-01 Thread John Machin
On 2/10/2006 11:51 AM, Jim Chiang wrote:
> I’m trying to very simply insert a picture from a file into an excel 
> spreadsheet. I know how to do this in VBA and it works fine, however 
> when I try this from python I get an error. Doing a search on this 
> turned up nothing.
> 
> The code I’m using is:
> 
> from win32com.client.dynamic import Dispatch
> 
> xl = Dispatch( 'Excel.Application' )
> 
> xl.Visible=1
> 
> xl.Workbooks.Add()
> 
> xl.ActiveSheet.Pictures.Insert("C:\a.jpg")
> 
>  
> 
> Traceback (most recent call last):
> 
>   File "", line 1, in 
> 
> xl.ActiveSheet.Pictures.Insert("C:\a.jpg")
> 
> AttributeError: 'function' object has no attribute 'Insert'
> 
>  
> 
> I’m not sure why I get this issue since 
> ‘ActiveSheet.Pictures.Insert("C:\a.jpg")’ works fine from within Excel. 
> Several internet posts from my searches also suggest to use this method.
> 
>  
> 
> I’ve tried this on both Python 2.1 and 2.5 with the same results.
> 
> Any idea what the problem is or how I can insert the picture??

Four problems:
(1) VBA syntax instead of Python syntax
(2) Not reading error message
(3) Courting danger with backslashes in filenames
(4) Courting danger keeping misc cruft in root directory

Solution:
  xl.ActiveSheet.Pictures().Insert(r"C:\misc_cruft\a.jpg")

HTH,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel win32com newbie question

2006-10-05 Thread John Machin
On 6/10/2006 7:16 AM, Jim Steil wrote:
> I’ve been working this week building some Excel spreadsheets using 
> Python and win32com.  I am not having any trouble getting my sheets 
> built with the proper data in the proper cells, but I’m having a heck of 
> a time trying to find out how I can format my cells to make it look 
> nicer.  I want to set it so most of the columns will resize themselves 
> to the proper width and I would like to adjust the alignment of some 
> columns.  I’ve browsed through the last years worth of archives on this 
> mailing list and searched the web extensively but can’t seem to find how 
> to get it to work.  I’ve come across numerous examples of how to do some 
> things, but they don’t seem to work on my machine.
> 
>  
> 
> Possibly my biggest problem is that I can’t get my machine to give me 
> the Excel constants.  Here is the code I’m doing to try to test the 
> constants and the error I’m getting back. 
> 
>  
> 
> from win32com.client import constants, Dispatch
> 
>  
> 
> x = constants.xlHAlignRight
> 
> Traceback (most recent call last):
> 
>   File "", line 1, in ?
> 
>   File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 
> 168, in __getattr__
> 
> raise AttributeError, a
> 
> AttributeError: xlHAlignRight
> 
>  
> 
> I’m hoping there is something obvious that I’m missing.  I think I can 
> find my way through the rest of my issues if I can just get by this 
> constants problem.  Thanks for any help you can provide.
> 

The constants module is a little bit more dynamic than one would 
normally expect:

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> from win32com.client import Dispatch, constants
 >>> print getattr(constants, 'xlHAlignRight', 'Bt!')
Bt!
 >>> app = Dispatch('Excel.Application')
 >>> print getattr(constants, 'xlHAlignRight', 'Bt!')
-4152
 >>>

HTH,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Excel win32com newbie question

2006-10-06 Thread John Machin
On 6/10/2006 11:34 PM, Jim Steil wrote:
> Thanks for your response too!  Unfortunately, I must have something messed
> up here because this didn't work either.
> 
>>>> from win32com.client import Dispatch, constants
>>>> print getattr(constants, 'xlHAlignRight', 'Bt!')
> Bt!
>>>> app = Dispatch('Excel.Application')
>>>> print getattr(constants, 'xlHAlignRight', 'Bt!')
> Bt!

Yeah well silly me for presuming you had run makepy :-)

> 
> I tried running the makepy.py on the Excell 11.0 Object library and that
> fails on me as well.  Any suggestions?

Tell us a few things you should have supplied w/o being asked:
(1) what version of Python (2.4.what??)
(2) what pywin32 build number
(3) copy/paste of result when you ran makepy

If the makepy gives you a weird syntax error (like the syntax error you 
showed in the response to Tim Roberts), that could be an old bug (in 
Python, I believe). Ensure that you have Python 2.4.3, and the latest 
build of pywin32, and try it again. IIRC, the workaround involved 
editing the file with the syntax error, adding a few spaces to the end 
of the allegedly offending line, and one or two lines before that.

HTH,
John
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python and Excel via Cron

2007-11-21 Thread John Machin
Jd H wrote:
> Hello,
>
>   I have the below python code which opens an excel sheet, runs a macro then 
> save the file. When run from python it runs perfectly. Code is below. File 
> name is test.py
>   
What does "run from python" mean??
>
>   <<< 
>   
What's that "<<<"?? If you meant to type ">>>", don't type, COPY/PASTE!!
>   from win32com.client import Dispatch
>
>   myExcel = Dispatch('Excel.Application')
>   myExcel.Visible = 1
>   myExcel.Workbooks.Add('C:\Python24\test.xls')
>   

1. Dunno how that can work without using raw string; '\t' is a TAB 
character ...
2. Storing data files in a software installation directory is not a good 
idea.
3. Python 2.4?

>   myExcel.Workbooks.Add('C:\Python24\macro.XLA')
>   myExcel.Run('Macro1')
>   myExcel.Application.DisplayAlerts = False
>   myExcel.ActiveWorkbook.SaveAs('C:\Python24\test.xls')
>   myExcel.Quit()
>   >>> 
>
>   When run from cron, it fails at line 3 when it opens the file with below 
> message:
>   
cron on Windows? cygwin?

>
>   Traceback (most recent call last):
> File "c:\Python24\test.py", line 20, in ?
>   jd.Workbooks.Add('C:\Python24\test.xls')
>   
NOT the same code as quoted above (line 3 vs line 20, myExcel vs jd)
> File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 
> 496, in __getattr__
>   raise AttributeError, "%s.%s" % (self._username_, attr)
>   AttributeError: Excel.Application.Workbooks
>
>   Any ideas how to resolve this?
>
More info required: what is your environment, what exactly are you 
doing, exact code that you are trying to execute.
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] JPEG to TIFF conversion

2007-12-10 Thread John Machin
Manjeet Singh wrote:
> Hi,
>I am a new to the image conversion /compression concepts. I have 
> few thousands of images which were scanned in Uncompressed JPEG 
> format(.Tiff and .Jpeg). I am required to convert them to standard 
> tiff files(CCIT Group4). Is there any way to accomplish this in 
> Python? I will be thankful for the comments and suggestions. I am 
> using Python 2.3.
http://www.pythonware.com/products/pil/

This may do the job -- check its manual (data formats in an appendix). 
Runs on any Python-supported platform, not just win32.

Cheers,
John
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


  1   2   >