Re: [python-win32] Friendlier pywintypes.com_error messages

2008-08-08 Thread Tim Roberts

Brad Johnson wrote:

I am using pywin32 scripting as a client to my C++ COM application. Many of my
functions in C++ are returning errors such as E_FAIL, E_POINTER, E_INVALIDARG,
etc...
  


...which are, after all, just numbers.  E_FAIL is 0x80004005, which 
shows in the exception report as -2147467259.  E_POINTER is 0x80004003.  
E_INVALIDARG is 0x80070057.



However, the error message in Python is often cryptic such as a simple
"Exception occurred" with the error code.
  


The code is buried in that report.  One trick is not to look at the 
first large negative number (which is usually the generic "an error 
occurred" error), but instead look for the second large negative number:


>>/ com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0,
/ >>/ -2147467259), None)
/

Here, -2147352567 is DISP_E_EXCEPTION, which means "exception 
occurred".  The real error code is -2147467259, which is 0x80004005, 
which is E_FAIL.



I suppose I could handle these exceptions and somehow post my own strings as the
error message, but I figured I'd ask if there is a list of supported error codes
that give more information.
  


Not sure what you mean by "supported error codes".  There are HRESULT 
error numbers spread all over the include files in the Platform SDK.  
The most common (like the three you mentioned) are in WinError.h.


--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Play MP3s from Windows, Just Works

2008-08-18 Thread Tim Roberts

Vernon Cole wrote:
As always, remember that mp3 is proprietary, and the owner has shown 
willingness to be nasty about licensing it. Therefore, anything that 
is "easy to install" is possibly illegal and/or will open you to a 
lawsuit. If you are doing new work, better to use ogg.


That statement is not technically correct.  MP3 is not proprietary, and 
the format is not "owned" by any one organization or individual.  It is 
an ISO standard.  Several institutions do claim to own patents that 
cover MP3, just as with all of the MPEG standards.


Many of the patent holders have already said they will not assert their 
patent rights on free and/or open source decoders and encoders.


However, you are correct to point out that the legal situation is murky.

--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] GetModuleFileName requires Process or Thread handle?

2008-08-18 Thread Tim Roberts

Walter Decker wrote:

Hello,
 
Can someone help me diagnose why the following fails to retrieve the 
'exe' name KillByName?

...
  for pid in processList:
try:
  print "KillByName pid: " + str(pid)
  handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, 
False, pid)

  print "KillByName handle: " + str(handle)
  exe = win32api.GetModuleFileName(handle)
...
Is a handle a handle a handle? The win32api.CreateProcess that started 
the process returns two (2) handles (hProcess and hThread) and the 
OpenProcess
call above returns the second of those two handles (the hThread). Is 
it that I need the 'other' handle as in:

"The result is a tuple of (hProcess, hThread, dwProcessId, dwThreadId)"
to send to win32api.GetModuleFileName(handle)?


No, handles are not interchangable.  Window handles, process handles, 
thread handles, file handles, event handles, registry handles, and 
module handles are all completely different spaces.  GetModuleFileName 
requires an HMODULE -- a handle to a module.  In fact, an HMODULE is 
actually just the virtual address where the module is loaded *within 
your own process*.  (The module handle of your main executable is 
0x0040).  You cannot call GetModuleFileName across processes.


--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] help with parsing email

2008-08-18 Thread Tim Roberts

Ahmed, Shakir wrote:

Thanks everyone who tried to help me to parse incoming email from an exchange 
server:

Now, I am getting following error; I am not sure where I am doing wrong. I appreciate any help how to resolve this error and extract emails from an exchange server. 



First I tried:
  

mailserver = 'EXCHVS01.my.org'
mailuser = 'myname'
mailpasswd = 'mypass'
mailserver = poplib.POP3(mailserver)


Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python24\lib\poplib.py", line 96, in __init__
raise socket.error, msg
error: (10061, 'Connection refused')
  


Are you absolutely sure that your Exchange server includes the POP 
gateway?  Remember that Outlook communicates with Exchange through a 
custom set of protocols.  The POP gateway is optional, and many 
corporate environments turn it off.


--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] PyCEdit issue

2008-08-18 Thread Tim Roberts

Marc-André Belzile wrote:
Ok that works. Is it a limitation with the windows control or PyCEdit? 
  


The Windows multi-line edit control requires \r\n between lines.  If 
that's what PyCEdit uses, then that's where it comes from.


--
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] help with parsing email

2008-08-19 Thread Tim Roberts
Mike Driscoll wrote:
> Ahmed, Shakir wrote:
>> but I am getting error before that point and could not go to the user
>> account or pass.
>>
>> M =oplib.POP3(mailserver)
>> Traceback (most recent call last):
>>   File "", line 1, in ?
>>   File "C:\Python24\lib\poplib.py", line 96, in __init__
>> raise socket.error, msg
>> error: (10061, 'Connection refused')
>>
>>
>>   
>
> Some POP3 servers require secure connections too. I've dealt with one
> that had TLS enabled, so I had to use an external TLS Python module to
> connect to it. I would check Outlook's settings and see if it has SSL
> or TLS enabled.

I thought I wrote this to the list, but I don't see it.

Outlook and Exchange communicate through a private set of protocols. 
They do not use POP.  The POP gateway is an optional extension for
Exchange, and in many corporate environments it is disabled.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Change account email option

2008-08-19 Thread Tim Roberts
Russell Smith wrote:
> Is there anyway you could change the email for my account
> ([EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>) to
> [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>? I am getting way
> too many of these python win32 e-mails and I would like them
> redirected to my alt e-mail address

"Way too many"?  We rarely get more than 10 messages a day.  There have
only been 73 for the whole month of August.

Do you know that you have the option of getting a "digest", where it
only sends you one message per day?  Follow the link at the bottom of
each message to get to a place where you can set this up.

Mailman doesn't provide a way to do simple renaming, other than running
a shell command on the server itself.  The easiest way is to unsubscribe
the old and resubscribe the new.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Detect if user has a window opened in full screen mode?

2008-08-21 Thread Tim Roberts
Patrick Li wrote:
>
> Is there a way I can detect whether or not the user has any window
> that is running in full screen mode? (Playing a game that takes up the
> entire screen, or having the browser maximized, etc)

Why on earth would you care?

I don't know of any API that can  answer this question.  Note that
DirectX games use a very different method of going fullscreen than
maximized applications.  For maximized applications, you could enumerate
through all of the top-level windows and find their window rectangles. 
For DirectX games, that wouldn't work.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] os.startwith issue dealing with .tif (winxp)

2008-08-29 Thread Tim Roberts
geoff wrote:
> Hi Folks;
>
> I have an application that stores images in a database.
> When the images are extracted, we use the files extension and
> os.startwith("filename") to allows the OS to select the users
> desingated program to open the file.
>
> Sometimes ... this goes astray.  For some mysterious reason, WinXP's
> file type associates get removed, atleast for TIF files.
>   

TIFF files are not normally associated with a program on Windows XP.

> what I would like to do is that if os.startwith fails, try to open the
> file with a specific program.  In the case of image files, the Ms
> Picture and Fax Viewer.
>
> How do I find the default path to an installed program ?
> Do I need the GUID and then look for the registry key ??
>   

No, that doesn't work for applications, only for COM objects.

However, in this specific case, you are in luck.  The "Microsoft Picture
and FAX Viewer" happens to live inside of a system DLL, and that DLL
always lives in the Windows "system32" directory.  So, you can do this:
rundll32.exe shimgvw.dll,ImageView_Fullscreen path\to\image\file.tiff

Whitespace is important; don't put any before or after that "comma".

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] ImportError: No system modul

2008-09-10 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
>  I am tring to work on Excel File through python. 
>
>  I am using Python 2.4.2 and work on xp with an administration authorization. 
>   
>  I implimented like that: 
>   
>  *
>  * 
>  ** 
>  ... 
>  import win32com.client 
>  ... 
>  class Python_skript(Object): 
>   
> def __init__(self, fileName=None): 
>self.xlapp = win32com.client.dynamic.Dispatch("Excel.Application") 
>if fileName: 
>   self.xlbook = self.xlapp.Workbooks.Open(fileName) 
>else: 
>   self.xlbook = self.xlapp.Workbooks.Add() ... 
>  **
>  
>   
>  I got the error message: "ImportError: No system modul 'pythoncom' 
> (pythoncom24.dll)"
>
>  Although the file pythoncom24.dll does exist. 
>   

It must do more than "exist", of course.  It must be in the right spot. 
How did you install pywin32?  Where does it exist?  And what does this say?
import sys
print sys.path

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Accessing other interfaces of a Dispatch created COM object

2008-09-10 Thread Tim Roberts
Alec Munro wrote:
> Ok, perhaps this will be useful.
>
> (Neither of these examples include the core arguments of the methods,
> just the ones specific to InvokeTypes)
>
> What I call a method from I1, it calls _oleobj_.InvokeTypes with the
> following arguments:
>
> 18, 0x0, 1, (24, 0), ((8, 1),)
>
> When I use the method from I2, it calls _ApplyTypes_(), which calls
> _oleobj_.InvokeTypes with the following arguments:
>
> 1, 0x0, 1, (24, 0), ((3, 1), (12, 1), (16396, 2))
>
> Now, from my reading (of old messages by Mark :) ), the last two
> parameters specify method return type and argument type.

Well, it's the 4th argument that gives the return type.  24 is VT_VOID. 
That's unusual for a COM type.

> In this case,
> it seems like both methods return VOID, which seems fine. I'm a little
> more concerned about the argument type. The first method is supposed
> to take a single string, so that looks fine.

Right; 8 is VT_BSTR, which is the typical COM Unicope string type.

> The second method takes
> an integer, a VT_TYPE, and a variant. I don't know if the
> representation here accurately represents that.
>   

3 is VT_I4 (long), 12 is VT_VARIANT, and 16396 is a VT_VARIANT passed by
reference, meaning an output parameter.

> So, I'm fairly certain this puts that problem at something that
> happens in InvokeTypes, unrelated to the arguments I passed in. I get
> the impression that InvokeTypes is something of Microsofts, and
> there's isn't really any way to observe what it's doing?
>   

I've lost track.  What's the root problem?  Is it still  the "Library
not registered" issue when you call a method in Interface_2?  Was this
all registered through a type library, or through a regsvr32 call, or what?

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Accessing other interfaces of a Dispatch created COM object

2008-09-10 Thread Tim Roberts
Alec Munro wrote:
> Thanks for the clarification Tim.
>
> My root problem is still the "Library not registered" issue. As far as
> how it was registered:
>
>  * I maintain a dll that defines a class that implements I1 and I2. I
> use regsvr to register this dll.
>  * I1 and I2 come from a third party, and in order for my dll to work
> properly, it has to implement them (actually I2 is optional).
>  * I don't know how I1 and I2 are registered. I do know that if I use
> the COM browser, I can go to Registered Type Libraries, find one with
> the typelibname that is associated with my CastTo created objects,
> which has "Type Library" underneath it, and underneath that are
> entries for I1, I2, several related interfaces, and a variety of
> coclasses. Like this:
>  - TypeLibName 1.0 TypeLibrary
>  -- IID: {00..00}
>  -- Type Library
>  --- I1 - Dispatch
>  --- I2 - Dispatch
>  --- IX - Dispatch
>  --- CX - CoClass
>
> I've just spent some time hunting through the registry to determine
> the differences between I1 and I2.
>
> Looking the gen_py files, they have the same package CLSID, and the
> same class coclass_clsid. But their class CLSIDs differ.
>   

Well, we may be getting confused about identifiers here.  The IID listed
below the typename is the type library UUID.  It identifies the type
library, which is just a collection of definitions.  Within the type
library, you have interfaces, and you have coclasses.  An interface also
has an IID, and that's the important IID to use when you query for an
interface.  A coclass is a concrete object that implements one or more
of the interfaces -- the "default" object for those interfaces, if you
like.  A coclass is identified by a CLSID.

In gen_py, the "CLSID = IID(...)" line at the top of the file should be
the type library UUID.  The "CLSID = IID(...)" line at the top of each
class is the IID for the interface being exposed by this coclass.  The
coclass_clsid is the model coclass that implements the interface.  If
you try to create an object of this type, PythonCom will essentially do
a CoCreateObject on the coclass_clsid, using the IID of the interface.

So, your two interface should have different CLSID lines at the top of
the class, and you should find those IIDs listed in
HKEY_CLASSES_ROOT\Interface.

> So I searched through the registry for those CLSIDs. They show up in
> the same places, once each under HKEY_CLASSES_ROOT and
> HKEY_LOCAL_MACHINE.

HKEY_CLASSES_ROOT is just a "symbolic link" shortcut to
HKEY_LOCAL_MACHINE\Software\Classes.  Everything in one will be in the
other.

No solution yet, but maybe this provides more background information.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Accessing other interfaces of a Dispatch created COM object

2008-09-10 Thread Tim Roberts
Alec Munro wrote:
> I've searched through the registry for the GUIDs I found associated
> with the CLSIDs of the classes. They seem to be IIDs of type
> libraries.
>
> The first one, associated with I1, seems to refer to a _basicUHI.tlb
> file that was distributed with SDK the third-party provides for
> creating the DLL we use.
>
> The second one, associated with I2, refers to a .dll file distributed
> with the third-parties application (the one that makes use of our
> DLL).
>
> In Visual Studio, if I look at the definition of I2, it opens up a
> _basicUHI.tlh file in a temp directory. Am I correct in assuming the
> .tlh file is automatically generated by VS to display a representation
> of the .tlb file?
>
> I found regtlibv12, and ran it against _basicUHI.tlb. Now the COM
> Browser has a "TypeLibName 2.0 Type Library" entry, but if I try to
> access it, or run makepy against it, I get "_basicUHI.tlb can not be
> loaded" or "Error loading type library/DLL.", respectively.
>
> This feels like it must be the source of the problem, but I'm not
> really sure what to do next.
>   

Take the IID of the type library for _basicUHI.tlb.  Now, look that up
in HKEY_CLASSES_ROOT\TypeLib.  Somewhere in there, there should be a
path to the TLB.  Make sure the path is correct.

You might also try running regsvr32 on the DLL file associated with I2.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] VARIANT as byref parameter

2008-09-16 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
> I'm trying to call a COM-function which first parameter is a reference to a 
> VARIANT. The COM object that contains this function supports early-bound 
> automation over MakePy.
>
> The corresponding C-code  is:
>
> LONG lValue;
> lValue = plQueryNote->GetVarSize();
> LPBYTE buff = new BYTE[lValue];
> VARIANT varData;
> varData.vt = VT_BYREF;
> varData.byref = buff;
> plQueryNote->ReadVarBlock(&varData,0,lValue);
>
> I have no idea how to define the VARIANT and how to pass it as 
> byref-style-parameter in python with win32com. I found no documentation for a 
> problem like this in the web. It would be great if someone could help me.

Is the parameter declared as [out,retval] in the type library?  If so,
then Python should create the variant and return it to you:
varData = QueryNote.ReadVarBlock( 0, lValue )

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Fwd: Modifying the system menu

2008-09-17 Thread Tim Roberts
James Matthews wrote:
>
> Hi all,
>I am trying to modify the system menu of all the applications in
> my machine.
>For example say - I am creating multiple desktops for windows  -
> and I want to give every application the capability to be moved across
> different desktops. So I wanted to modify the basic system menu list
> to include the new options.
>
>The methods I could think of are -
> 1. Modify the basic windows set of system menu values (best option)

There is no central repository where this is stored, so there's no place
to change.


> 2. Poll every few milliseconds and modify the system menu values of
> the active window

Ick  Windows don't come and go that often, and you only need to do this
once for each application.

The correct option is (3) install a Windows hook to watch for new
application to activate, and modify the menu in the hook.  You will have
to use a hook in order to catch the menu item being chosen anyway. 
There are Python modules to handle some kinds of hooks, but overall this
would be much easier in C.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] VARIANT as byref parameter

2008-09-17 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
>
> > Is the parameter declared as [out,retval] in the type library?
>
> This is how the function is declared in the file that MakePy has
> generated:
>
>  def ReadVarBlock(self, pbBuff=defaultNamedNotOptArg,
> dwOffset=defaultNamedNotOptArg, dwLen=defaultNamedNotOptArg):
>   return self._oleobj_.InvokeTypes(58, LCID, 1, (3, 0), ((16396, 0),
> (3, 0), (3, 0)),pbBuff
>, dwOffset, dwLen)
>
> > If so, then Python should create the variant and return it to you:
> >varData = QueryNote.ReadVarBlock( 0, lValue )
>
> This line produces a type mismatch error.
>

Well, that implies that the buffer is an in/out variant, not an output. 
I'm not sure how to construct a buffer Pythoncom will correctly
translate in this instance.  Mark, maybe?

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Pythonwin telit

2008-09-18 Thread Tim Roberts
Juan Manuel Pubill wrote:
>
> Hola quería saber si hay posibilidad de conseguir alguna versión más
> nueva que la que distribuye Telit del pythonwin porque es poco estable
> y tiene varios bugs.
>

BabelFish translates this as:
> Hello it wanted to know if there is possibility of securing some
> version newer than the one than it distributes Telit of pythonwin
> because he is little stable and it has several bugs. Immediately thank
> you very much

You can always fetch the latest version directly from the source,
http://sourceforge.net/projects/pywin32.

However, there haven't been any significant bugs in quite a long time. 
What version are you using, and what "bugs" do you see?

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Virtual print driver - similiar to winpdf

2008-09-22 Thread Tim Roberts
geoff wrote:
> Would creating a virtual print driver be possible with pywin32,
> similiar to the windows pdf driver ?
> WE have an old application that outputs data to a dotmatrix printer.
> WE would like to extend this application and integrate it with another
> application and the simplest way to do this would be to capture the
> print output, extract some information from the print output and then
> forward that information to a database application.
>
> Any suggestions.
>
> I have found a couple of websites about print drivers (google is my
> friend !) but thought I might ask here for some advice and guidance.
>   

This is trickier than you might guess.  Does the application actually
write to the printer using a Windows printer driver?  Some old
applications that just used a printer for logging wrote directly to the
parallel ports.  That kind of thing is almost impossible to trap.  If it
does, how does it pick the printer?  If it doesn't present you with a
dialog, then it might be picking the printer by name.  That means you
can't just install your own driver, unless you use the same name.  If it
does present you with a dialog, can you use the Generic / Text-Only
printer driver, and have it dump to a text file?  (That's one of the
standard printer drivers built-in to Windows.)

If you really need a driver, you are not going to be able to do this
from Python.  There are a sample printer drivers in the WDK (Windows
Driver Kit).  It is not a project to be undertaken lightly.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Controlling Excel via COM: errors with conditional formatting

2008-09-24 Thread Tim Roberts
kurt munson wrote:
> I  have written a Python program to control MS Excel via
> win32com.client. This allows me to create and control an Excel
> spreadsheet.
>
> I want to use Excel's conditional formatting to color certain cells,
> but I can't get it to work.
>
> Here's the code I use:
>
> |import win32com.client
> xl= win32com.client.Dispatch("Excel.Application")
> 
> 
> 
> channamesSheet.Cells(6,3).FormatConditions.Add() Type:=1,
> Operator:=4, Formula1:="=C5"
> channamesSheet.Cells(6,3).FormatConditions(1).Interior.ColorIndex = 3|
>
> I got this code from a record and replay macro in Excel, then swapped
> out the xl constants for numeric values (1 and 4).
>
> This gives me a syntax error when running.
>
> I have tried both .Add and .Add(), since sometimes these () are necessary.
>
> What am I doing wrong?

What you are doing wrong is writing Python scripts as if it were Visual
Basic.  Solomon gave you the code, but you need to understand that
Python and Visual Basic are different languages.  When Excel records a
macro, it records it in Visual Basic.  The "Arg:=Value" syntax is a
Visual Basic syntax.  The "sometimes these () are necessary" comment
comes from Visual Basic.

By the way, after you use Dispatch, all of Excel's "xl" constants are
available to you.
    import win32com.client
xl = win32com.client.dispatch( "Excel.Application" )
print win32com.clients.constants.xlLandscape

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32console attach problems

2008-10-03 Thread Tim Roberts
Stian wrote:
>
>
> I'm experiencing concurring problems when attempting to attach to a
> console using the PyWin32 win32console. I have an application which
> may attach to a console, send ctrl+c to it and then detach - using
> win32console. If I do this "too soon" after the console is started the
> AttachConsole fails, throwing an exception. Fair enough. My issue is
> that after one such a failing attempt all following AttachConsole
> attempts will fail the same way.

What error do you get?  MSDN describes several different error returns.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] help with python COM server needed

2008-10-03 Thread Tim Roberts
aivars wrote:
> Hello,
> basically I rewrote an example by Mark Hammond trying to create a
> simple trial COM server as per his Python programming on Win32 book
> The problem is that when run from VB6 (Excel VBA) it gives me an error
>
> exceptions.typeerror
> ReturnAmount() takes no arguments (1 given)
>   

It's true that your ReturnAmount function takes no arguments.  How did
you call it?

>con = sqlite3.connect("e://pythonexamples//aivars2.db")
>   

If you use forward slashes, just use one at a time.  If you use backward
slashes, THEN you need to double them.

>cur = con.cursor()
>
>konts='71302'
>d1='2008-01-01'
>d2='2008-09-30'
>
>cur.execute("select coalesce(sum(summa),0) as AD from so2
> where deb = (?) and date(datums) between (?) and (?)", \
>(konts, d1, d2))
>   

sqlite3 uses the ? method of parameter substitution.  You don't need
those extra parentheses (that is, use ? not (?) ).  Also, you don't need
the backslash at end of line; Python will keep continuing the statement
as long as you are inside an open set of parentheses.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32console attach problems

2008-10-03 Thread Tim Roberts
Stian wrote:
> > What error do you get?  MSDN describes several different error returns.
> Actually I was wrong. The first error is "Handle is invalid". Then all
> following errors are "Access is denied.", which seems to be the same
> error I get when a console is already attached. But if this was the
> case - shouldn't it be fixed with the win32console.FreeConsole I
> always call before attaching?

Well, let me ask a silly question.  Are you running this from a "pyw"
app, using Pythonw.exe, so you don't have a console of your own?

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32console attach problems

2008-10-06 Thread Tim Roberts
Stian wrote:
> > Well, let me ask a silly question.  Are you running this from a "pyw"
> > app, using Pythonw.exe, so you don't have a console of your own?
>  
> Well, that's not a silly question for me - I'm rather new to Python.
> Anyway - let me tell you a bit more about how this is put together if
> that may be relevant.
> I have a GUI written with wxWidgets/wxPython. A .exe-file is created
> using pyinstaller. I don't think pyw is explicitly used, but I see
> something about pythonw in the pyinstaller files. Perhaps this is used
> here?

On Windows, by default, scripts with a .py extension are run by
Python.exe, which is a console application.  If you can write to stdout
and see the results in a console window, then you have a console. 
Scripts with a .pyw extension are run by Pythonw.exe, which is a Windows
application.  Those scripts do not have a console.  If your installer is
embedding pythonw.exe as the executioner, then that's probably what
you're using.


> My GUI starts a console using win32process like this:
> ...
> Does this make it any clarify what may be wrong?

No.  ;)  I don't see anything immediately obvious.  If it were me, I'd
write a tiny C application to try the exact same APIs to kill your
console app, just to make sure that the sequence does work as expected. 
Print out the "pid", then pass that to the C app by hand.  Remember to
make it a Windows app (WinMain instead of main) so that you don't get
your own console.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] help with python COM server needed

2008-10-06 Thread Tim Roberts
aivars wrote:
> this is how I call it from VB:
>
> Sub testPython()
>
> Dim a
> Dim response
>
> Set a = CreateObject("Aivars.ReturnSaldo")
> response = a.ReturnAmount() '--->error here
>
> Worksheets("Sheet1").Range("a1").Value = response
> End Sub
>   

Function calls in VB with no parameters don't use  parens.  I think you
want this:
response = a.ReturnAmount

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32console attach problems

2008-10-07 Thread Tim Roberts
Stian wrote:
> > I've seen this myself, but couldn't reliably reproduce it.
> > If I recall, allocating a new console, and then immediately
> > freeing it seemed to clear the 'in-between' state.
>  
> Man, that did the trick! Thanks! I added a win32console.AllocConsole()
> before the FreeConsole() in the first try-except-clause, and this
> fixes my problem. However, I do think this look like a hack due to
> issues in the win32console module, but as long as it works I'm happy.

The win32console module is a very, very thin layer over the API.  It
doesn't keep any state.  My uneducated guess is that you are seeing an
issue with the underlying Win32 APIs, not in the win32console module itself.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem in accessing the Message body of Outlook Inbox.

2008-10-09 Thread Tim Roberts
venu madhav wrote:
> Hi all,
> How can I access the body of a mail in Outlook Inbox? I tried
> various options like message.Body or message.Mesg etc. but didn't
> work. I could get the subject of the mail using message.Subject
> though.

Show us the code you used.  There are several ways to get to Outlook,
and the solution depends on what you used.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem in accessing the Message body of Outlook Inbox.

2008-10-10 Thread Tim Roberts
venu madhav wrote:
>
> Here is the code:
>
> rom win32com.client import Dispatch
>
> session = Dispatch("MAPI.session")
> session.Logon('outlook')  # MAPI profile name
> inbox = session.Inbox
> for i in range(inbox.Messages.Count):
> message = inbox.Messages.Item(i + 1)
> f.write(message.Subject+"\n\n")
> f.write(message.Body+"\n\n\n")
>
>   Hope you could get some idea based on this..

I believe you want the "Text" property, not the "Body" property.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Please help, run into a COM object issue using the windows media SDK, thanks!

2008-10-10 Thread Tim Roberts
jjpet wrote:
> Thanks Mark!
>
> Does PythonWin (or wxPython) provide any way to drive a script as if running 
> it in the PythonWin GUI?
>   

The key, I believe, is that you need a message loop.  A standard console
app doesn't have one, so it waits forever for a response from a message.

Any of the GUI frameworks will supply a message loop.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] how do I build pywin32?

2008-10-13 Thread Tim Roberts
Tim Newsham wrote:
> I have downloaded and built python2.4.5 using visual studio 7.1sp1.
> I have installed windows server 2008 sdk.  When I try to build
> pywin32-212 I get an error:
> ...
> which seems to be some incompatibility between the headers from
> visual studio 7.1 and the win sdk?  What do I need to install to
> properly build pywin32?

It may be worth trying an older version of the SDK.  The Vista SDK
version of specstrings.h does not try to include sal.h.

There is a 5 year gap between VS7.1 and the WS2008 SDK.

Why are you building Python from scratch?  Just curious.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] how do I build pywin32?

2008-10-13 Thread Tim Roberts
Tim Newsham wrote:
>>> visual studio 7.1 and the win sdk?  What do I need to install to
>>> properly build pywin32?
>>
>> It may be worth trying an older version of the SDK.  The Vista SDK
>> version of specstrings.h does not try to include sal.h.
>
> Vista SDK worked a lot better, but did not make it all the way through:
>
> e:\pywin32-212\pywin32-212\com\win32comext\mapi\src\PyIMAPIProp.h(6) :
> error C2143: syntax error : missing ';' before '*'
> e:\pywin32-212\pywin32-212\com\win32comext\mapi\src\PyIMAPIProp.h(6) :
> error C2501: 'PyIMAPIProp::GetI' : missing storage-class or type
> specifiers
> e:\pywin32-212\pywin32-212\com\win32comext\mapi\src\PyIMAPIProp.h(6) :
> warning C4183: 'GetI': missing return type; assumed to be a member
> function returning 'int'
> e:\pywin32-212\pywin32-212\com\win32comext\mapi\src\PyIProfSect.h(6) :
> error C2143: syntax error : missing ';' before '*'
> e:\pywin32-212\pywin32-212\com\win32comext\mapi\src\PyIProfSect.h(6) :
> error C2501: 'PyIProfSect::GetI' : missing storage-class or type
> specifiers
> e:\pywin32-212\pywin32-212\com\win32comext\mapi\src\PyIProfSect.h(6) :
> warning C4183: 'GetI': missing return type; assumed to be a member
> function returning 'int'
> com\win32comext\mapi\src\PyIProfSect.cpp(646) : error C2143: syntax
> error : missing ';' before '*'
> com\win32comext\mapi\src\PyIProfSect.cpp(646) : error C2501:
> 'IProfSect' : missing storage-class or type specifiers
> com\win32comext\mapi\src\PyIProfSect.cpp(647) : error C2501:
> 'PyIProfSect::GetI' : missing storage-class or type specifiers
> com\win32comext\mapi\src\PyIProfSect.cpp(648) : error C2059: syntax
> error : ')'
>
> (either on IMAPIProp or PyObject, probably the former)

Yes, but that's not sensible.  That code hasn't changed in 9 years. 
IMAPIProp and IProfSect both live in the SDK in mapidefs.h.

Didn't you have to install SWIG to run this?  What version did you get? 
Perhaps you should check those files to see if anything looks unusual. 
Both of them are generated by SWIG.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] COM server and function parameters

2008-10-15 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
> Hi all,
> I still have some problems with my server.
>
> I have a function that should return three parameters defined as:
>
>  HRESULT GetInfo([out] BSTR *name, [out] BSTR *version, [out] BSTR
> *description);
>
> If I return a tuple with three string I get an error saying that the number
> of returned parameters is wrong (3 in place of 4). I read this post
> http://markmail.org/message/rjpdosrliyne65fd
> and added a fourth parameter as first one with a 0 value (OK). 
> I'm not sure this is a right solution and I'd like to ask if something has
> changed from that post. 
>   

I would think this is fairly clear.  Your function returns four things:
an HRESULT and three strings.  That's what your tuple needs to contain.

> Unfortunately I cannot test if the values returned are good since after that
> call I get another call to another function that raise an exception.
> The other function is defined as
>
>  HRESULT func2([out] IEnumString ** param1);
>
> I can creat an object that implement IEnumString and return it but after
> that I get a QueryInterface on it with iid set to IID_NULL (a list of 0s).
>   

Again, this function returns two things: an HRESULT and an interface. 
Are you returning a two-tuple?

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem in accessing the Message body of Outlook Inbox.

2008-10-16 Thread Tim Roberts
venu madhav wrote:
> Hi all,
> As of now I got access to the text of the message. Now if I
> want to access the sender address and the receiver address of a mail
> how can I do that? I tried giving message.To and message.From both of
> which didn't work.. :-(. I tried searching in Google for them but
> couldn't come out with the solution.

Are you doing this by guessing, or have you actually read about the CDO
Object Model?
http://msdn.microsoft.com/en-us/library/ms526930.aspx

"To" cannot be a simple property, because a message can have many
recipients.  In CDO, the MAPI.Message object has a "Recipients"
collection, which is a set of "Recipient" objects.  Each "Recipient" has
Address, Name, and Type properties.

The "Sender" property has the From address.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] COM -- Dispatch() parameter

2008-10-21 Thread Tim Roberts
Ferdinand Sousa wrote:
>
> To automate Word using COM, we use the Dispatch function:
> Dispatch("Word.Application")
>
> What parameter must be passed to Dispatch to launch Adobe Acrobat 7.0
> Professional?
> Is it the VersionIndependentProgID registry key? Even so, there are so
> many things in the registry that go like "Acrobat ...",
> "AcroIE.Helper", "PDFMaker. ..." it is a nightmare to find out what is
> the correct item you need.

Unfortunately, you have to be TOLD this kind of information.  It's not
possible to extract it through reflection.  You can often find
documentation for specific applications by searching for the app name
plus "com object model".  To make it more difficult, Adobe has changed
their names from version to version.  In the old versions, you wanted
"AcroExch.PDDoc"

Adobe has a great deal of technical documentation on their web site: 
http://www.adobe.com/devnet/acrobat/.  The detailed COM stuff is in
their "Interapplication Communication Reference":
   
http://partners.adobe.com/public/developer/en/acrobat/sdk/IACReference.pdf

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Feature request: adding unicode method to CDispatch

2008-10-21 Thread Tim Roberts
Jacek Pliszka wrote:
> Would it be a problem to add __unicode__  method like this:
>
>def __unicode__(self):
>try:
>return unicode(self.__call__())
>except pythoncom.com_error, details:
>if details[0] not in ERRORS_BAD_CONTEXT:
>raise
>return self.__repr__()
>
> to class CDispatch in  win32com/client/dynamic.py   ?
>
> It would help me a lot - I need unicode data from objects.
>
> Or is there a way to get them ?
>   

Can you provide an example where the default behavior doesn't do what
you expect?  Usually, if a method is returning a string, it will be a
Unicode string, because that's the COM standard.  If a method returns a
single-byte string, it's probably better to convert it yourself.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Feature request: adding unicode method to CDispatch

2008-10-21 Thread Tim Roberts
Jacek Pliszka wrote:
> Hi!
>
> I have something like this:
>
> wrd=Dispatch("Word.Application")
> doc=wrd.Documents.Open('test.doc')
> for j in doc.Tables:
> s=unicode(j)
> ... here I do a few searches on the date inside the table 
>
> How can I do it without the method I mentioned ? I use it here to be
> able to do s=unicode(j).
>   

You're relying on a bunch of automatic conversions here, some of which
do conversions that you don't want.

"j" is not a string here -- it is a Table object.  The default property
of the Table object is a Range object.  The default property of the
Range object is the Text object, which IS a Unicode string.  So, instead
of relying on the default conversions, if you say this explicitly:

for j = doc.Tables
    xxx = j.Range.Text

you'll find that xxx *IS* a Unicode string.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Feature request: adding unicode method to CDispatch

2008-10-21 Thread Tim Roberts
Tim Roberts wrote:
>
> You're relying on a bunch of automatic conversions here, some of which
> do conversions that you don't want.
>
> "j" is not a string here -- it is a Table object.  The default property
> of the Table object is a Range object.  The default property of the
> Range object is the Text object, which IS a Unicode string.  So, instead
> of relying on the default conversions, if you say this explicitly:
>
> for j = doc.Tables
> xxx = j.Range.Text
>
> you'll find that xxx *IS* a Unicode string.
>   

The astute reader will, of course, have noticed and fixed the silly
syntax in my for statement:
    for j in doc.Tables:
xxx = j.Range.Text

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Interacting with the desktop as a service onVista

2008-10-22 Thread Tim Roberts
Matt Herbert (matherbe) wrote:
> My situation is I have a python service which runs 24/7. Occasionally
> The service needs to access windows on the desktop. That is, it needs to
> enumerate all the windows, find a specific pop-up, and press a button.
>   

Wow, this sounds like an incredible hack impersonating as a feature. 
For my own curiousity, is this for a test lab somewhere, or is this
actually part of a product?

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Interacting with the desktop as a service onVista

2008-10-24 Thread Tim Roberts
Matt Herbert (matherbe) wrote:
> Steven,
>  
> Thanks, I will give this a try.
>  
> So then, is it fair to say that it is not possible (on Vista) to have
> a service spawn a process as a different user, and have that new
> process interact with the desktop?

No, that's not fair to say!  The mechanism you are using should work. 
That's the mechanism Microsoft recommends. There's something going wrong
in the process, but the concept is correct.  I didn't reply because I
couldn't spot the problem off the top of my head, but you are on the
right track.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Getting a users token

2008-10-24 Thread Tim Roberts
Matt Herbert (matherbe) wrote:
> Anybody know how to get a token for the current user? I'm thinking
> something similar to win32api.GetUserName, but instead it would return
> the token??
>   

I suspect you want OpenProcessToken or OpenThreadToken, assuming your
process is running as the current user.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] force outlook ui update

2008-10-27 Thread Tim Roberts
Christian K. wrote:
>
> I noticed that after having written e.g. to the PR_SUBJECT of a mapi
> IMessage, e.g.:
>
> msg = self.msgstore._OpenEntry(self.id, None, mapi.MAPI_BEST_ACCESS)
> msg.SetProps([(PR_SUBJECT, self._subject)])
> msg.SaveChanges(mapi.KEEP_OPEN_READWRITE)
>
> the subject field in the inbox list changes immedately but the subject
> line of the message itself (either shown in the embedded panel or in
> its own frame) does not. After a couple of other actions, i.e.
> selecting and deslecting other items the message subject will be
> updated in every place.
>
> Is there a way to force an UI update?

No.  MAPI controls the mail engine, not the user interface.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] force outlook ui update

2008-10-29 Thread Tim Roberts
Christan K. wrote:
> Tim Roberts  probo.com> writes:
>   
>> Christian K. wrote:
>> 
>>> the subject field in the inbox list changes immedately but the subject
>>> line of the message itself (either shown in the embedded panel or in
>>> its own frame) does not. After a couple of other actions, i.e.
>>> selecting and deslecting other items the message subject will be
>>> updated in every place.
>>>
>>> Is there a way to force an UI update?
>>>   
>> No.  MAPI controls the mail engine, not the user interface.
>> 
>
> Actually I did not expect to find something within mapi. Do you have any 
> ideas 
> where to look for these gui related issues?
>   

I guess it depends on what you are really trying to do, and on how
general you need this to be.  MAPI is an abstraction.  There is no
promise that MAPI requests will have any effect at all on a user
interface.  The fact that you are seeing something update at all
surprises me.  The effect would be very different if you happened to be
running a different MAPI provider.  It might not even show a UI at all.

If what you really want to do is control Outlook, then Tim G is right --
you need to control Outlook through Outlook's object model.  If what you
really want to do is send email, then MAPI is a more general answer, but
you give up the user interface.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] force outlook ui update

2008-10-30 Thread Tim Roberts
Christan K. wrote:
> Thank you both for your comments. In fact I naivly assumed that, thinking in 
> terms of a mvc pattern, the outlook gui was the view and mapi manipulated the 
> model so that the gui would be aware of every change in the model. Obviously 
> this is not the case.

That is not an unreasonable expectation, but unfortunately, that is not
the case.  MAPI is a general-purpose email interface.  The model is that
there is some anonymous and faceless server that is offering to handle
MAPI requests.  MAPI was actually developed well before Outlook; Outlook
offers MAPI services only because it is sensible for it to do so, but
it's an add-on.  It's not a core part of Outlook's world, and as you can
see, the integration is not particularly tight.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Python and Microsoft Media Server

2008-10-30 Thread Tim Roberts
Aleksandr VLADIMIRSKIY wrote:
> Hello,
>
> I have a request to test validity of a set of videos hosted on a Microsoft 
> Media Server. It doesn't appear that the standard library urllib urlopen 
> method is capable of reading mms:// urls. Is there a Python library that 
> could help in this case?
>   

MMS is a proprietary protocol invented by Microsoft: 
http://msdn.microsoft.com/en-us/library/cc234711.aspx.  It's similar to
RTSP, and uses TCP port 1755.

When you say "test the validity", what exactly do you mean?  Are you
just trying to figure out whether the URL is alive or not?  I think you
could use the socket module to send a ping request to the port and see
if you get a response.  If you are actually trying to figure out whether
the movie is playable, then you'll have to use a media player of some kind.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] how to call the dll in python

2008-11-03 Thread Tim Roberts
ysystudio wrote:
> I have a windows dll1.dll with a export function:
>  
> int f1(char filename,char **buf,int *bufLen)
> {
> int len;
> //got the length of file anyway,such as 100
> len = 100;//len = getLen(filename);
> *buf = (char*)calloc(100);
> *bufLen = len;
> return 0;
> }
>  
> then how can I call the f1 function with python.

I assume this is just an example, because this is not a good way to
design a DLL.  It is never a good idea to allocate memory in one DLL and
pass it to another, because they might be using different C runtime
libraries.  If you need to fill in a string, you should allocate the
buffer in the calling program, then hand in the buffer and the length to
let the DLL fill it in.

In general, you use the ctypes module to call into foreign DLLs.  The
details depend strongly on the parameters.  If you could be a little
more specific about what you need, we could provide better advice.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] PythonWin

2008-11-13 Thread Tim Roberts
Harald Armin Massa wrote:
> Maybe, just maybe, you could be better of to "downgrade" to Python 2.5
> if you are just a beginner with Python and want to use some
> description from the web. Many tools and documentations are not
> updated to Python 2.6 yet.
>   

This is reasonable advice, but since he's a beginner, I'd like to expand
on WHY this is reasonable advice.

Python is in the middle of a rather significant transition, from Python
2 to Python 3.  Python 3 makes some many changes in the language, some
of which are incompatible with current code.  This was done to clean up
some of the things that should have been cleaned up long ago, but
couldn't because of compatibility.  Python 3.0 should be formally
released within the next 4 weeks or so.

Python 2.6 is a special "bridge" release; it contains some of the Python
3.0 changes, but in a way that helps you identify things that will need
to be migrated.  Because of that, it issues warnings for constructs that
are valid in Python 2.x, but will be invalid in Python 3.x.  For someone
who is just beginning, that is an unnecessary distraction.

Python 2.x and Python 3.x will coexist in the world for many years yet,
so there's nothing wrong with learning Python 2.x today.  But to do
that, I agree with Harald that you should probably start with Python
2.5.  Virtually all of the major tools work with Python 2.5.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Scary message when opening the Interpreter

2008-11-14 Thread Tim Roberts
Echavarria Gregory, Maria Angelica wrote:
> Hello group! I'm a new member, I hope to be of help some time! As today, I 
> have troubles, hope you can solve them:
>
> When I open my Python interpreter, this is appearing instead of the command
> arrows (>>>):
>
>   File "boot_com_servers.py", line 21, in 
>   File "C:\Python25\lib\site-packages\pythoncom.py", line 3, in
> 
> pywintypes.__import_pywin32_system_module__("pythoncom", globals
> ())
>   File "C:\Python25\lib\site-packages\win32\lib\pywintypes.py", line
> 98, in __import_pywin32_system_module__
> ('.dll', 'rb', imp.C_EXTENSION))
> ImportError: DLL load failed: The specified procedure could not be
> found.
>
> I also noticed some basic commands are not working.
> What should I do?
> I'm afraid to update and replace all the modules of different parties that I 
> have compiled
> and installed in my directory, and don't know how to do it without damaging 
> everything...
>   

This looks like a problem with mixed versions.  Are you saying that you
built Python and Python-Win32 from source?  If so, may I ask why?  There
is virtually no benefit to doing so on Windows.  The pre-built
executables provide everything you need.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to make python scripts output to current cmd window? (like linux terminal)

2008-11-17 Thread Tim Roberts
sayeo87 wrote:
> Right now on Windows I have added ".py" to my PATHEXT so that I can run .py
> files by doing ./.py. But when I do this the output of the program
> goes to a new command prompt window which instantly disappears. How can I
> instead make the output go to the current command prompt window I'm working
> in, like in a linux terminal?
>
> Sorry if this has been answered before but I've googled high and low and
> still can't seem to find how to do this.
>   

What PATHEXT lets you do is run the command without specifying a path at
all.  As long as the file is in the same directory, the file association
will work.  PATHEXT allows you to put Python scripts in your c:\bin
directory, for example, and then use them without specifying the path or
the extension.  So, I have a Python version of "which" that I store in
my \bin directory under the name "which.py".  But from a command line,
all I have to type is "which".

I'm surprised by your description.  Check your file associations.  From
your command line, say
assoc .py
On my machine, it says:
.py=Python.File

Then, check the ftype:
ftype Python.File
On my machine, it says:
python.file="C:\Apps\Python24\Python.exe" "%1" "%*

I see that you wrote "./.py".  Was that an accident, or are
you using a shell other than "cmd"?

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to make python scripts output to current cmd window? (like linux terminal)

2008-11-17 Thread Tim Roberts
Tim Roberts wrote:
> sayeo87 wrote:
>   
>> Right now on Windows I have added ".py" to my PATHEXT so that I can run .py
>> files by doing ./.py. But when I do this the output of the program
>> goes to a new command prompt window which instantly disappears. How can I
>> instead make the output go to the current command prompt window I'm working
>> in, like in a linux terminal?
>>
>> Sorry if this has been answered before but I've googled high and low and
>> still can't seem to find how to do this.
>>   
>> 
>
> What PATHEXT lets you do is run the command without specifying a path at
> all.

I realized when I read my reply that I really did nothing to clear up
any confusion.  Allow me to provide an example.

Let's say I have c:\bin\remote.py, and client.py in the current
directory.  WIthout the file associations for .py and .pyw, I can say:
python client.py
pythonw client.py
If I set up file associations for .py and .py, then I can also say:
client.py
.\client.py
Further, as long as "c:\bin" is in the path, I can also say:
remote.py

When I add .PY and .PYW to PATHEXT, that also lets me say:
client
remote

without the extension.  That's the sole purpose for PATHEXT.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to make python scripts output to current cmd window? (like linux terminal)

2008-11-18 Thread Tim Roberts
Mike Driscoll wrote:
> Tim Roberts wrote:
>>  
>> I realized when I read my reply that I really did nothing to clear up
>> any confusion.  Allow me to provide an example.
>>
>> Let's say I have c:\bin\remote.py, and client.py in the current
>> directory.  WIthout the file associations for .py and .pyw, I can say:
>> python client.py
>> pythonw client.py
>> If I set up file associations for .py and .py, then I can also say:
>> client.py
>> .\client.py
>> Further, as long as "c:\bin" is in the path, I can also say:
>> remote.py
>>   
>
>
> Sorry to intrude, but what is "C:\bin" ? I don't have it on Windows XP
> and I couldn't find a "bin" folder in my Python25 directory either. Is
> this some kind of custom wizardry on your part?

It's not wizardry.  I spend most of my life in a command line, so my
computer is organized to make command line life easier, using lessons
learned from Unix.  I create directories called \apps, \bin, \etc, and
\tmp.  If I install a program that I think I will need in a command
line, I install it in \Apps instead of "\Program Files" (because it's
shorter, and because spaces are evil).  All the tools I write, all the
command line tools I download, and shortcut batch files to the other
tools I need all go in c:\bin.  That way, I can put "C:\bin" in the
path, instead of cluttering it up with dozens of directories that each
have one tool.  A long path costs performance.

Some people think they are stuck with the "\Documents and Settings" and
"\Program Files" nonsense that Microsoft dictates.  Not so.  It's your
computer, do what works for YOU.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] getting integer value for worksheet.Cells(row, col).Value

2008-11-19 Thread Tim Roberts
Greg Antal wrote:
>
> I think "Val" will be a method on the Excel server. For example, if
> you have
> xl = win32com.client.Dispatch("Excel.Application")
>
> for your server, you would have say something like
> iValue = xl.Val(worksheet.Cells(row, col).Value)
>
> Again, I haven't used Excel this way, so I'm just going by standard
> object-oriented practice. You'll have to work out those details yourself.

No.  Bob had the right answer here.  "Val" is a Visual Basic function,
because the sample snippet was Visual Basic code.  To do the same
conversion in Python, you need to use a Python function -- int() in this
case.

Cells().Value returns a string.  It's just that simple.  If you want an
integer, you convert it.  No mystery, no COM.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] dispatch and minimize the window?

2008-11-20 Thread Tim Roberts
Pahud wrote:
>
> I am trying to use win32com.client.Dispatch() to run my program but I
> would like to minimize it in the system tray. What can I do?

Your message could mean several things.

Are you saying that you have written a COM server, and when someone
starts your COM server using Dispatch, you want to put an icon in the
tray?  If so, it's entirely up to your COM server to do this.  There are
a number of example on Google of how to put an icon in the tray.  Here's
one:
http://www.brunningonline.net/simon/blog/archives/SysTrayIcon.py.html

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Simple context-menu question.

2008-11-25 Thread Tim Roberts
Joel Bryan Juliano wrote:
> Based on the context_menu.py example found in
> win32comext\shell\demos\servers\context_menu.py, there is a function
> callback when an item is chosen,
>
> def InvokeCommand(self, ci):
> mask, hwnd, verb, params, dir, nShow, hotkey, hicon = ci
> win32gui.MessageBox(hwnd, "Hello", "Wow", win32con.MB_OK)
>
> My question is how can I get the current names of the "MenuName >
> SubMenuName > SubItemName" when InvokeCommand is called? I apologize
> if this may sound like a dumb question, I'm really new to win32/COM
> programming.. My approach is when I get the names, I can easily call a
> function for them, since the subitems are dynamic and always changing.
>   

You can't get the names.  What you get is the menu identifier (idCmd in
the sample) of the item that was clicked, as the "verb" -- the 3rd
member of the tuple you get in InvokeCommand.  It's up to you to assign
a meaning to that identifier.  The Win32 menu handling doesn't track the
menu "tree".  The tree is only meaningful for display.  It only notifies
you that a menu item was clicked.

I would also caution you that it is not good practice to create deeply
nested context menus.  It makes for a very confusing user experience.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Fwd: Accessing Modification Time of an Outlook Mail in Python

2008-11-25 Thread Tim Roberts
venu madhav wrote:
>
> Hi all,
>   I am writing a small application which reads the contents of an
> Outlook Mail using python. I am able to read the contents, subject
> along with senders and receivers of a mail using MAPI objects. But may
> I know how can I get access to the "modification time" or the
> receiving time of an outlook mail in Python. For the others I have
> used message object of MAPI session.

http://msdn.microsoft.com/en-us/library/ms526861.aspx

You should be able to fetch message.TimeLastModified, but be aware that
email messages do not really have a "modification time".  The only thing
they have is the "Date:" header, which is really the creation time
(message.TimeCreated).

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Simple context-menu question.

2008-11-25 Thread Tim Roberts
Mike Driscoll wrote:
> Tim Roberts wrote:
>> Joel Bryan Juliano wrote:
>>  
>>>
>>> My question is how can I get the current names of the "MenuName >
>>> SubMenuName > SubItemName" when InvokeCommand is called? 
>>
>> I would also caution you that it is not good practice to create deeply
>> nested context menus.  It makes for a very confusing user experience.   
>
> And if you "really" need to know the names in the menus then you
> should just design your own using a Python GUI toolkit, like Tkinter
> or wxPython.

Well, he's working on a shell extension plugin here.  The message loop
belongs to Windows Explorer, and events are delivered through COM server
callbacks.  I'm not convinced it can be mated to either wx or Tkinter.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem in accessing the Sender and Receiver addresses of an outlook mail

2008-12-03 Thread Tim Roberts
venu madhav wrote:
>
>   I am trying to use python for extracting contents of an
> outlook email. For extracting the list of Recipients addresses I tried
> using
> the "MAPI.message.Recipients.Address" property, but the problem I
> am facing is that it is giving the complete DN name which is putting
> me in further complications. Is there any way to obtain the actual
> SMTP mail address ([EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>)
> of both sender and receiver from the above object? I searched for it
> in the MSDN help but couldn't succeed.

This depends on your mail server.  If you are using Exchange, and are
looking at an internal message, it's not using SMTP, and might be
configured to deliver only to DN names.  The "Type" property of the
address tells you which address type it is.

http://www.ssuet.edu.pk/taimoor/books/0-672-30928-9/ch4.htm

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Problem in accessing the Sender and Receiver addresses of an outlook mail

2008-12-04 Thread Tim Roberts
venu madhav wrote:
>
> I am using Exchange server and partial code is given below
> message = inbox.Messages.Item(11)
> objRecip = message.Recipients.Item(1)
> typ = objRecip.AddressEntry.Type
> print " the type of address "
> print typ
>
> Its output is
> **
>  the type of address 
> EX
> ***
> Please let me know if I can provide you any other information.

Yep, you have a native Exchange address.  The message does not contain
the SMTP address, because Exchange doesn't use that for delivery.  If
you really need the SMTP address for this person, you will have to go
look it up in the Exchange address book using the address you got. 
Here's an article from microsoft.public.platformsdk.mapi that talks a
little about this:
*http://tinyurl.com/6mfqqo*

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] rebooting windows from Python?

2008-12-04 Thread Tim Roberts
Alec Bennett wrote:
> I'm wondering if there's some way to reboot or shutdown Windows from within 
> Python? 
>
> I can log out like this:
>
> win32api.ExitWindowsEx(4)
>
> And according to the documentation, I should be able to shutdown like this:
>
> win32api.ExitWindowsEx(2)
>
> But that returns the following error:
>
> 'A required privilege is not held by the client.'
>
> Is there some way to do this? Currently I'm running shutdown.exe, which 
> works, but I'd rather do it directly if possible.
>   

Yes -- you have to acquire the required privilege.  ;)  The mechanism to
do so is tedious, and involves fetching your current privilege token,
then adjusting it in place.  You can read about it in the MSDN page on
ExitWindowsEx:
http://msdn.microsoft.com/en-us/library/aa376868.aspx

Personally, and it really is a personal preference, I think it's a lot
less trouble, and a lot easier to understand, just to use the tools at
my disposal:
subprocess.call( "shutdown", "-r" )

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the registry and creating reg files

2008-12-04 Thread Tim Roberts
Mike Driscoll wrote:
>
> We're doing what amounts to a registry session audit here at work, so
> I need to walk a specific set of subfolders in our registry and get
> the contents thereof. The subfolders will vary from user to user. I
> found Tim Golden's excellent registry walking script on his website here:
>
> http://timgolden.me.uk/python-on-windows/programming-areas/registry/walk-the-registry.html
>
>
> My problem is that I need to output the data into *.reg files. Is
> there a builtin way to do that with _winreg or PyWin32 or do I just
> need to roll my own?

I'm not answering the question you asked, but are you aware of the very
handy "reg" tool included with XP?  "reg export" can export a full key
in a format that is compatible with regedit.
reg export HKLM\system\CurrentControlSet\Services\vgasave  xxx.reg

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the registry and creating reg files

2008-12-04 Thread Tim Roberts
Alec Bennett wrote:
> Reg files are just text files, so why not just create the text files yourself?
>
> Here's a reg file for example:
>
> REGEDIT4
>
> [HKEY_LOCAL_MACHINE\SOFTWARE\Gizmoware\Whatever]
>
> "Name"="Yada"
> "Number"="something"
>   

Because Mike said he needed to extract sections from the existing
registry for audit purposes.  It's up to him to decide whether that's
easier by writing Python or by using "reg export".

Is "something" a number?  ;)

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the registry and creating reg files

2008-12-05 Thread Tim Roberts
Tim Golden wrote:
>
> [*} One note which I remember: the .reg files are usually UTF16LE;
> not sure if that's important or not.

Regedit and "reg export" create UTF16 files, but regedit and "reg
import" are perfectly happy to read 8-bit .reg files.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the registry and creating reg files

2008-12-05 Thread Tim Roberts
Dahlstrom, Roger wrote:
> If you can read the registry, you can save it without any other special 
> permissions.  It is just text.
>
> Just export a branch of your own registry and open it with notepad to see the 
> format.  I do it all the time, it works fine.
>   

Well, you are simplifying things a bit too much.  The registry itself is
NOT, in fact, text.  It is an indexed, hierarchical database.  You can
certainly use regedit to export a key to text, but the question here was
about doing it programmatically, without regedit.  Regedit supports the
backup/restore function that Tim mentioned, but to do so, it has to
acquire backup privileges.  If you want to use the same functions from
your own program, YOU have to acquire the backup privileges.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the registry and creating reg files

2008-12-05 Thread Tim Roberts
Dahlstrom, Roger wrote:
> ...  Basically what I'm saying is not that you need *no* permissions, just 
> that you don't need any *special* permissions - if you have permission to 
> read it and enumerate the subkeys, that is (at least in my experience, maybe 
> I'm not doing exactly what the request is) sufficient.

Almost.  The RegSaveKey and RegRestoreKey functions, which export and
import entire subtrees, need the SE_BACKUP_NAME privilege.  The
administrator account can get that privilege, but you have to use APIs
to ask for it.

http://msdn.microsoft.com/en-us/library/ms724917.aspx

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the registry and creating reg files

2008-12-05 Thread Tim Roberts
Dahlstrom, Roger wrote:
> Well, like I said, I've never done it in Python, and this is going back a 
> bit, so some things might be different, but I'm not talking about RegSaveKey 
> or RegRestoreKey, I'm talking about using EnumKey and CreateKey.  As far as I 
> can remember, I didn't have any special permissions for that.
>   

You are quite correct.  It's only those two specific functions
(RegSaveKey and RegRestoreKey) that need special privileges.  It just so
happens that's what Tim G was talking about.

So, we're all in violent agreement...

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Simulating a mouse click - lParam

2008-12-05 Thread Tim Roberts
Rickey, Kyle W wrote:
>
> Let’s say I’ve got a window for which I want to simulate a mouse click
> at a specific x, y coordinate. I already have the hwnd but I’m not
> sure how to construct the lParam. I’ve used SendMessage in the past to
> click on buttons, etc., but I knew their hwnds. How do I construct the
> lParam. Per the MSDN docs:
>
>  
>
> http://msdn.microsoft.com/en-us/library/ms645607(VS.85).aspx
> <http://msdn.microsoft.com/en-us/library/ms645607%28VS.85%29.aspx>
>
> /lParam/
>
> The low-order word specifies the x-coordinate of the cursor. The
> coordinate is relative to the upper-left corner of the client area.
>
> The high-order word specifies the y-coordinate of the cursor. The
> coordinate is relative to the upper-left corner of the client area.
>
> lParam = ???
>
> win32gui.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, 0, lParam)
>
> win32gui.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, lParam)
>
>  
>
> Any help would be greatly appreciated. I also can’t help but wonder if
> I’m going about this the wrong way. My end goal is clicking on a
> certain Tab in a TabCtrl (in this case _/wx/_SysTabCtl32). I used
> EnumChildWindows to find all the main window’s children, but couldn’t
> find the tabs. So figured I would try to ‘click’ on the tab.
>

Two ways.  This works as long as both coordinates are positive:
lParam = (y << 16) | x

The more robust way is like this:
lParam = struct.unpack( 'L', struct.unpack( 'hh', x, y ) )[0]

However, it would be much better to talk to the tab control directly. 
Are you doing this from inside the owning wx application?  If so, you
should be able to get the tab control object and call the methods
directly.  Even if you can only get the handle, you can use TCM_SETCURSEL.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the registry and creating reg files

2008-12-05 Thread Tim Roberts
Dahlstrom, Roger wrote:
> I think my mistake was assuming that reading the values was going to be 
> sufficient.  For all the purposes I've used, it was.  For my edification, 
> what's the functional difference?  I mean, what I was doing was able to walk 
> the registry, extract information, save it for later, modify it, then 
> re-insert it in to the registry.  What's different with saving and restoring, 
> or is it just the neater API?
>   

RegSaveKey and RegRestoreKey use a binary format.  It's a direct copy of
the database nodes from the registry file itself.  RegRestoreKey doesn't
merge the new information with the existing information, like the text
APIs do.  Instead, it completely replaces the entire tree being
restored.  It's really a backup operation.  Thus, these are considered
more dangerous APIs, and that's why these need special privileges.

At least, that's my story, and I'm sticking to it.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Simulating a mouse click - lParam

2008-12-05 Thread Tim Roberts
Rickey, Kyle W wrote:
> Thanks Tim. I used the following to select my tab of interest:
>
> TCM_SETCURSEL = 0x130C
> win32gui.SendMessage(hwnd, TCM_SETCURSEL, 3, 0)
>
> However, according to MSDN:
> http://msdn.microsoft.com/en-us/library/bb760612(VS.85).aspx
> "Remarks
>
> A tab control does not send a TCN_SELCHANGING or TCN_SELCHANGE
> notification message when a tab is selected using this message."
>
> So of course nothing happens after the tab is selected. Ie, the window
> is not updated to show the different controls etc. And unfortunately,
> the window of interest is a 3rd party app, so I don't have direct access
> to the controls and their methods :(
>   

Assuming you have the top-most window of the app, you should be able to
use FindWindowEx to find the tab control by class name; you shouldn't
have to enumerate for it.  After you send TCM_SETCURSEL, you should be
able to call InvalidateRect to force the window to redraw.

Do you have the Windows SDK installed?  You can use the "spyxx" tool to
explore the window configuration of the app you're examining.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Walking the registry and creating reg files

2008-12-08 Thread Tim Roberts
Dahlstrom, Roger wrote:
> OK - so if I'm correct in understanding this, let's say hypothetically, I 
> have something like so...
>
> HKLM...
> something
> something else
> something else
> something else
>
> If I were to use my operation, and export the entire tree, I would get a copy 
> of the above, but then if someone modified it such that there were four 
> "something else"s, and I merged my copy back in, the end result would be the 
> same four "something else"s, while with your method, I would end up with the 
> original three?  Is that right?
>   

Yes, but remember that RegSaveKey uses an undocumented binary format
that matches the internal registry database format.  Joe User isn't
going to go in and modify the saved file.  It was really designed for
backup and restore.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] get window title

2008-12-09 Thread Tim Roberts
Billy Pilgrim wrote:
>
> I am rather new to python and haven't been able to find a solution to
> this (in python or in any other language). 
>
> The problem:  I am trying to find a way to iterate over the set of
> open windows, and retrieve/extract the window title. 
>
> The real project, stupid as it is, is to find the 'Freecell' window
> and extract the game number -- which is part of the title. 

I hesitate to turn on my sarcasm generator, but I find it hard to
believe that you actually looked for a solution to this.  Any number of
good Google phrases should have brought you the pieces you need to make
this happen.

import win32gui

def winEnumHandler( hwnd, ctx ):
if win32gui.IsWindowVisible( hwnd ):
print hex(hwnd), win32gui.GetWindowText( hwnd )

win32gui.EnumWindows( winEnumHandler, None );

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] get window title

2008-12-09 Thread Tim Roberts
Billy Pilgrim wrote:
> So I presume that window text and title are the same?
> (text, IMHO, implies contents of window).

That's actually a reasonable question, so I'll turn off the sarcasm
engine.  ;)

The "GetWindowText" and "SetWindowText" APIs are generic, and can be
used with almost any kind of window.  The definition of what "window
text" means depends on the type of the window.  Remember that almost
everything you see on your screen is a window; there are typically
thousands of windows on your desktop at any given time, contained within
one another.  For dialogs and top-level windows, it means the title bar
text.  For edit boxes, it means the contents.  For static text, it means
the text.  For buttons, it means the button caption.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Passing data in a windows message

2008-12-10 Thread Tim Roberts
Tim Golden wrote:
> I'm using win32gui.PyGetBufferAddressAndLen to pass the address &
> length of a marshalled object as the wparam / lparam of a windows
> message. Something like this:
>
> address, length = \
>  win32gui.PyGetBufferAddressAndLen (buffer (marshal.dumps (message)))
> PostMessage (self.hwnd, self.WM_PROGRESS_MESSAGE, length, address)
>
> where "message" here is actually a unicode object.

But, "marshal.dumps" creates a temporary object, "buffer" creates
another temporary to wrap it, but when that statement ends, both
temporary objects no longer have any references, so they will get
garbage collected.  Won't they?  Now, if you had written it this way:

  hold_me = marshal.dumps( message )
  address, length = win32gui.PyGetBufferAddressandLen( buffer(hold_me) )

then I think it would work, because the marshaled buffer still has a
reference.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Getting active SMTP servers via python.

2008-12-10 Thread Tim Roberts
Dominick Lauzon wrote:
>
> I am attempting to determine the accessible SMTP servers on a given
> desktop to avoir various users for having to predefine in a given
> script to facilitate distribution.
>
>  
>
> Is this possible ?
>

No.  There is no way to determine this a priori, and many commercial
environments do not have SMTP servers at all (Exchange clients, for
example).  You must ask the user to configure this.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Passing data in a windows message

2008-12-10 Thread Tim Roberts
Thomas Heller wrote:
> Since you used PostMessage, the message is simply posted to the thread's
> message queue. You have no control when it is processed; so I fear you
> must keep the posted 'object' alive even longer.
>   

This is a good point that I overlooked.  If you used SendMessage, it
would block until the other end acknowledged it.

-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Writing to Excel performance

2008-12-12 Thread Tim Roberts
Dahlstrom, Roger wrote:
> Couple of tricks I've used with some success...
>  
> 1.  If this is data only, and not formulas, you can write the data as
> an html table, but name the file something.xls - Excel will open it
> natively.
> 2.  If you need special formatting or formulas, you can write the data
> as Excel's HTML templates (make a sample file in Excel, save it as
> html, then you can see how to do it)
>  
> I believe #1 to be a security flaw in windows - that you can just name
> a file anything, and the application will open it,

No, it's not a security flaw.  The file still has to be in a format that
Excel knows how to import.  Excel just happens to understand a lot of
formats, and it reads the file to figure out what the format really is. 
It doesn't trust the extension.  Internet Explorer uses the same
tactic.  When a web page sends an attachment, it doesn't trust the MIME
type.  It reads the file to detect the file type.

If you rename an executable to xxx.xls and try to open it within it
Excel, it will complain about the format.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Writing to Excel performance

2008-12-12 Thread Tim Roberts
Dahlstrom, Roger wrote:
> I understand where you're coming from, I just don't like how Windows handles 
> such things.  My opinion is that determining file type by extension 
> (arbitrary at that) is a bad thing to begin with.
>   

This is veering a bit off-topic for this mailing list, but I'd be
curious to hear what alternatives you would suggest.  It's a difficult
problem to solve generically, but if you've brainstormed about it, I'd
like to hear your thoughts.  The extension scheme has always seemed
quite sensible to me.

Windows, for the most part, uses the extension to look up a handler in
the registry.  The old Mac OS used a fourcc scheme, where you embedded a
code identifier in the resource fork of the file itself.  That makes
many things unnecessarily hard.  Linux uses the "shebang" technique,
where the first line of a file (#!) identifies the handler.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Post Message

2008-12-15 Thread Tim Roberts
Ferdinand Sousa wrote:
>
> I have written a small script to automate a process. The issue is that
> a "Save As" pops up at the end. Using Winspector, I could come up with
> this:
> win32gui.PostMessage(win_hdl,con.WM_COMMAND,1,0) # handle to the "Save
> As" window, message type, Control ID of the "Save"
> button
>  This works perfectly. However, now I would like to modify the "File
> name" field so that I can change the default save location. It is a
> combo box and has a control ID 1148. Using intuition, I tried
> WM_SETTEXT, but no luck. Any pointers?
> If possible, could any one point out any general, simple-to-use help
> on the PostMessage function?

What process are you automating?  Many big applications today can be
controlled by COM, which is a much more reliable and predictable method
of control than hacking window messages.

Remember that the "Save As" dialog is in a separate top-level window,
and because it is modal, it has its own message loop.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] no array returned in output parameter

2008-12-15 Thread Tim Roberts
Enric Jaen wrote:
> I have the following method generated by makepy.py:
>
> def GetFilters(self, pvarFilterArray=defaultNamedNotOptArg, 
> pnArraySize=defaultNamedNotOptArg):
> """method GetFilters"""
> return self._oleobj_.InvokeTypes(68, LCID, 1, (24, 0), ((16396, 0), 
> (16387, 0)),pvarFilterArray
> , pnArraySize)
>
>
> As you see, the method has two output params: The first is of type pointer to 
> a Variant (which the COM object should fill with an array) and the second a 
> pointer to a type long.
>
> But when I invoke that method it returns a tuple as if there were no data:
>   
>>>> r.GetFilters()
>>>> 
> (None, 0)
>
> i.e array is Null with size is 0. 
>
> The same is happening with other methods that have an output array.
>
>
> - Which type represents 16396 ? 
>   

That's 12 + 0x4000, so it's VT_VARIANT + VT_BYREF.  That is, a variant
output parameter.  16387 is VT_I4 + VT_BYREF, or a long integer output
parameter.

Are you 100% convinced that the object has an array of filters to
return?  How do you know?

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Transmit HID device with python on Windows

2008-12-15 Thread Tim Roberts
Wang Yongqing wrote:
>
> I have a USB hid device, and I want to use the python to communicate
> with it on the Windows.
>
> My question is whether there is a python module which could be used to
> this program.

The "libhid" project has a Windows version and includes a Python binding.
http://libhid.alioth.debian.org/

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] no array returned in output parameter

2008-12-15 Thread Tim Roberts
Enric Jaen wrote:
> I am 100 % sure because I have tested it with a VB program and it returns 
> data.
>   

What are you controlling here?  Is this Flash?

> As I have seen from previous posts in this mailinglist, the memory is 
> allocated at the COM side. 
>   

Yes, but that should be irrelevant.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Internet Explorer Session independent Creation

2008-12-17 Thread Tim Roberts
Romain Gilles wrote:
>
> I'm new in python and I would like to know how I can create 2 (and
> more) session independent Internet Explorer.
>
> This is my actual code:
>
>  
>
> ie1 = Dispatch("InternetExplorer.Application")
>
> ie1.Navigate(url)
>
> login(ie1)
>
>  
>
> ie2 = Dispatch("InternetExplorer.Application")
>
> ie2.Navigate(url)
>
> ...
>
>  
>
> In this example when the 'ie2' instance navigate to the url it is
> automatically authenticated as if ie1 and ie2 shared the same credential.
>
> But what I want is truly independent internet explorer instance.
>
>  
>
> Somebody can help me?
>

I'm not convinced this is possible.  When you run several instances of
IE via COM, they all try to route to the same process, which means they
will share credentials.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Post Message

2008-12-17 Thread Tim Roberts
Ferdinand Sousa wrote:
>
> Actually, I am using COM to control Adobe Acrobat 7. I searched high
> and low for methods to enable pdfs for commenting in Adobe Reader, and
> the only method I could find was to execute the appropriate menu item
> in Acrobat. I did all this in COM. The problem is that once that
> option is executed, the Save As dialog pops up. Now, I am able to
> click the Save button (as mentioned in my previous mail).

Have you downloaded the Adobe "Interapplication Communication API
Reference" document that describes the COM interface to Acrobat?  The
AcroExch.PDDoc interface includes a "Save" method to save the file.  I
don't immediately see how annotations are enabled; is that one of the
keys in the "Info" dictionary?

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] kernal32.DeviceIoControl Operation Aborted

2008-12-18 Thread Tim Roberts
Red Rackham wrote:
> Hi.  I'm a bit of a novice with ctypes and this is my first post here
> so please forgive any detected newbiness.  After trying and searching
> I hereby give up and appeal to the pros out there who may be more
> intimately familiar with DeviceIoControl usage. 
>  
> I'm trying use Python to access a USB device based on Cypress FX2
> (EZ-USB) type part.
>

First, are you using a driver that supports the Cypress standard
ioctls?  If you are using one of the standard Cypress drivers, then you
are, but if this is a device that has its own driver, you might not.


> The first operation I'm attempting is to access a command that is
> supposed to return the microcontroller's PORTA value.  Here's a
> minimal amount of code:
>  
>   retCode = k32.DeviceIoControl(
>dev.deviceHandle,
>IOCTL_EZUSB_VENDOR_OR_CLASS_REQUEST,
>byref(vrControl),
>sizeof(VENDOR_OR_CLASS_REQUEST_CONTROL),
>pBuffer,
>c_ushort(255), # READ_LENGTH,
>byref(retBytes),
>None)
>  
> Where the vrControl is a struct like this:
>   vrControl = VENDOR_OR_CLASS_REQUEST_CONTROL()
>   vrControl.direction = VENDOR_REQUEST_DIRECTION_DEVICE2HOST
>   vrControl.requestType = VENDOR_REQUEST_REQUESTTYPE_VENDOR
>   vrControl.recipient = VENDOR_REQUEST_RECIPIENT_ENDPOINT
>   vrControl.reqTypeResdBits = 0
>   vrControl.request = VR_PORTS
>   vrControl.value = VR_PORTS_READ << 8 | value
>   vrControl.index = port
>

Are you sure your firmware supports the VR_PORTS request?  Is this
something you added to your firmware?

What does your CreateFile call look like?

Technically, this request violates the USB spec.  You should be using
VENDOR_REQUEST_RECIPIENT_DEVICE; you can't use an endpoint request
unless the wIndex value specifies an endpoint number that is currently
configured.  Before changing that, you'd have to make sure the firmware
was also set up for that.

I almost hate to suggest it, but you might try writing this same
sequence as a short, standalone C program, just to make sure that the
Python wrapper isn't interfering.  I don't see any reason why it should,
but it's one less variable.


> kernal32.DeviceIoControl returns a 0, and kernal32.GetLastError() is
> returning a 995, which is, "ERROR_OPERATION_ABORTED.  The I/O
> operation has been aborted because of either a thread exit or an
> application request" ...
>  
> The reason for the abort does not make sense to me.  Anyone know what
> would most commonly cause this?  What should be my next step?
>

ERROR_OPERATION_ABORTED maps to STATUS_CANCELED in the driver world. 
That's a very specific error, which happens only when a driver has
requested that your I/O request be canceled.  That can happen if you hit
Ctrl-C, or if you unplugged the device.  However, it shouldn't happen
with ordinary requests, unless your driver is enforcing some kind of a
timeout.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] kernal32.DeviceIoControl Operation Aborted

2008-12-19 Thread Tim Roberts
Red Rackham wrote:
>
> I think I have finally figured it out.  Thanks for the suggestion, I
> ran the executable (compiled C code) and it worked, and it returned 0x8B.
>  
> Previously I saw this value and thought was bunkum.  I thought it was
> incorrect because of the way ctypes encodes a string buffer: ('value',
> '\x8b|').  I was probably thrown off by the '|' in the string.  Not
> sure why that gets returned.  I guess to get a real value out of that
> buffer you have to use the 're' module or something.
>

You need to use your head to figure this out, and thinking of the "re"
module is not using your head.

The only way to pass buffers around in Python 2 is as strings.  The
answer is that your ioctl is returning TWO bytes: 8B and 7C.  It is not
uncommon practice in FX2 firmware to return an error code in the first
byte, so perhaps the port value is actually the second byte: 7C.  You
can tell this for sure by checking the firmware source code.

If you really want to handle the result as hex byte values, you can use
struct or array:

import struct
s = '\x8b|'
t = struct.unpack('BB', s )
print [hex(i) for i in t]

import array
x = array('B')
x.fromstring( s )
t = x.tolist()
print [hex(i) for i in t]


> Except that now I'm trying to read PORTD which is also returning the
> same value (0x8B) but I'm expecting a different value.  So either it's
> just a coincidence that I read 0x8B, or I have my data aligned wrong
> and it's getting a '0' in the field where it's expecting a 7 for PORTD.

Are you getting two bytes here as well?  What's the second byte?

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] kernal32.DeviceIoControl Operation Aborted

2008-12-19 Thread Tim Roberts
Red Rackham wrote:
> Mystery solved.  The value on the port had changed from 0x09 to 0x76
> from the time I used the c-based program to the time I came along and
> red it in Python.  Went back and used the c-based program and found
> the port was indeed 0x76.
>  
> I used your "array" example:
> x = array.array('B')
> x.fromstring( buffer )
> t = x.tolist()
> print [hex(i) for i in t]
>  
> and got back "['0x8b', '0x7c', '0x0', '0x0', '0xff', '0x0', '0xfe',
> '0xb1', '0xff', '0x0', '0x0', '0x0',".
>  
> Woo hoo  I didn't know that the "array" class was capable of this,
> which is why I was considering the "re" module.
>

Python is an excellent language for dealing with hardware, but if you do
very much of it, you'll find that the "array" and "struct" modules
become indispensable parts of your daily toolkit.

I write drivers for a living, both Windows and Linux.  My debug and
diagnostic tools are almost always written in Python, because it's so
easy to experiment.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Welcome to the "python-win32" mailing list

2008-12-29 Thread Tim Roberts
Joshua Lim wrote:
> Hi everyone,
>
> I'm new to python or C.  I've been trying to get open source pyrad, a
> socket radius python app, to work on win32, and encountered an error:
>
> Traceback (most recent call last):
>   File "C:\Python25\pyrad\example\server.py", line 36, in 
> srv.Run()
>   File "C:\Python25\pyrad\example\server.py", line 256, in Run
>
> AttributeError: 'module' object has no attribute 'poll'
>
> A quick Google revealed that the error has something to do with Linux
> poll not working under windows.  I searched Pyrad code, server.py,
> line 256, and this brought up the following:
>
> def Run(self):
> """Main loop.
>
> This method is the main loop for a RADIUS server. It waits
> for packets to arrive via the network and calls other methods
>   &nbs p; to process them.
> """
> self._poll=select.poll()
> self._fdmap={}
> self._PrepareSockets()
>
> while 1:
> for (fd, event) in self._poll.poll():
> if event==select.POLLIN:
> try:
> fdo=self._fdmap[fd]
> self._ProcessInput(fdo)
> exc ept ServerPacketError, err:
> logger.info("Dropping
> packet: " + str(err))
> except packet.PacketError, err:
> logger.info("Received a broken packet: " +
> str(err))
> else:
> logger.e rror("Unexpected
> event in server main loop")
>
>
>
> As i understand, i need to change the code to use select.select().  I
> tried replacing "select.poll()" with "select.select()" but got a new
> error:
>
> TypeError: select expected at least 3 arguments, got 0
>
> What should i do?  Would appreciate any tip.  :)

Well, "select" is not just a drop-in replacement for "poll", although it
can serve the same function.  Without looking at the rest of the source,
you probably want something like this:

   def Run( self ):
self._fdmap = {}
self._PrepareSockets()
while 1:
fdi = select.select( self._fdmap, [], [] )[0]
if fdi:
self._ProcessInput( fdi[0] )
else:
logger.error( "select returned empty." )

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Welcome to the "python-win32" mailing list

2008-12-29 Thread Tim Roberts
Tim Roberts wrote:
> Well, "select" is not just a drop-in replacement for "poll", although it
> can serve the same function.  Without looking at the rest of the source,
> you probably want something like this:
>
>def Run( self ):
> self._fdmap = {}
> self._PrepareSockets()
> while 1:
> fdi = select.select( self._fdmap, [], [] )[0]
>   

I just realized this is not correct.  _fdmap is a dictionary, and it
needs to be a list of FDs.  _fdmap probably contains the list of read
FDs, write FDs, and other FDs -- exactly the way select.select wants
them -- but you'll have to look inside _PrepareSockets to know how to
pull out the three individual lists.

OK, after looking at the source, I think the list of fds is actually the
keys of the dictionary, so we need two small changes:

   def Run( self ):
self._fdmap = {}
self._PrepareSockets()
while 1:
fdi = select.select( self._fdmap.keys(), [], [] )[0]
if fdi:
self._ProcessInput( self._fdmap[fdi[0]] )
else:
        logger.error( "select returned empty." )

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Welcome to the "python-win32" mailing list

2008-12-30 Thread Tim Roberts
Joshua Lim wrote:
> Thanks Mike, it didn't occur to me that indentations are required.  :o

You may want to take some time to get comfortable with Python before
making a change like this.  Indentation is a fundamental part of Python
syntax, replacing the { curly braces of C } and the begin/end of
Pascal.  It is NOT optional.  It must look exactly like my example. 
Further, you should configure your editor so that you always use spaces
for indentation, or always use tabs.  Mixing spaces and tabs will get
you into trouble.

 
> C:\Python25\pyrad\example>c:\python25\python server.py
> Traceback (most recent call last):
>   File "server.py", line 3, in 
> from pyrad import dictionary, packet, server
>   File "C:\Python25\pyrad\example\server.py", line 259, in 
> NameError: name 'self' is not defined
>  
> Now a new error.  Line 259 refers to "fdi = select.select(
> self._fdmap.keys(), [], [] )[0]"

You still have an indentation problem.  This line should be part of the
Run function, which includes "self" as a parameter.  That line must be
indented from the "while" statement, which is indented from the "def"
statement.  If you had that line at the same indentation as the "def",
you'd see this error, because it would not be part of the function.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Multiple Extraction - ArcGIS9.2

2009-01-05 Thread Tim Roberts
bikash.sherc...@gmail.com wrote:
> I am very beginner and would like to customize ArcGIS using python
> scripting for my thesis. I have to iterate Extract by Mask tool to
> extract several raster layer using watershed boundary (vector) and
> tried to with the attacthed code. But I am unable to get the result
> and got the following error:
>  
>
> Running script multiExtract...
>
> Error in script multiExtract.
>
> Error in executing: cmd.exe /C C:\EROSIO~1\MULTIE~1.PY "'C:\HfT
> Thesis_Bikash\thesis data\A2008257NDVI.tif';'C:\HfT
> Thesis_Bikash\thesis data\A2008273NDVI.tif'" "C:\HfT
> Thesis_Bikash\thesis data\exactbound_gcs.shp" "#"
>
> Failed to execute (multiExtract_4).
>
> End Time: Mon Jan 05 14:23:36 2009 (Elapsed Time: 1.00 seconds)
>
> I will pleased to hear any sugestion. Thanks

Do you actually have Python installed?  My guess from this is that the
.py extension has not been registered.  You can check this from a
command line:

C:\tmp>assoc .py
.py=Python.File

C:\tmp>ftype python.file
python.file="C:\Apps\Python24\python.exe" "%1" %*

C:\tmp>

If those are missing, and you know that the Python interpreter exists on
your disk, you can set it up yourself using commands like this,
substituting your own path, of course:

assoc .py=Python.File
ftype Python.File="C:\Python24\python.exe" "%1" %*
assoc .pyw=Python.NoConFile
ftype Python.NoConFile="C:\Python24\pythonw.exe" "%1" %*

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] building pywin32 for python 2.6...

2009-01-05 Thread Tim Roberts
Raymond Stewart wrote:
>
> I am having a hard time building Mark Hammond’s pywin32 extension with
> python 2.6.1. I followed the readme and used the setup.py. I have the
> latest Windows SDK installed, and the Direct X SDK installed as well.
> I am building on Vista. I have both Python 2.5 and 2.6 installed as
> well as VC2003, VC2005, and VC2008. I changes the path statement to
> point at \python26. Not sure what else I need to do. The docs are
> pretty thin on building configurations.
>
> Here is what I am getting…
>
> C:\Users\raymond.stewart\Desktop\pywin32-212>setup.py -q  build
>
> Building pywin32 2.5.212.0
>
> PyACL.cpp
>
> C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\specstrings.h(9)
> : fatal error C1083: Cannot open include file: 'sal.h': No such file
> or directory error: command '"C:\Program Files (x86)\Microsoft Visual
> Studio .NET 2003\Vc7\bin\cl.exe"' failed with exit status 2
>

You are using the very latest SDK (6001) but an old compiler (Visual
Studio 2003).  If you read the release notes, you'll see that the 6001
SDK no longer supports Visual Studio 2003.  You need to switch to VS2005
or VS2008.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Multiple Extraction - ArcGIS9.2

2009-01-06 Thread Tim Roberts
bikash.sherc...@gmail.com wrote:
> yes they are really missing and tried to set up as per your
> suggestion. but I got the following errors:
>  
> Access is denied.
> Error occurred while processing: Python.File
>  
> Access is denied.
> Error occurred while processing: .pyw.
>  
> Access is denied.
> Error occurred while processing: Python.NoConFile
>  
> For your information, my operating system is windows vista (32bit).
> Does it make any difference?

You must be running as an "unprivileged user".  The "assoc" command has
to write to the HKEY_LOCAL_MACHINE part of the registry, which cannot be
done as an unprivileged user.

Are you absolutely certain Python is installed?  If so, you can change
your script command line.  Right now, it says:

C:\EROSIO~1\MULTIE~1.PY 'C:\HfT Thesis_Bikash\thesis
data\A2008257NDVI.tif';'C:\HfT Thesis_Bikash\thesis
data\A2008273NDVI.tif'" "C:\HfT Thesis_Bikash\thesis data\exactbound_gcs.shp

Just change that to invoke the Python interpreter directly, instead of
getting it via the extension.  Something like this:

C:\Python24\Python.exe C:\EROSIO~1\MULTIE~1.PY 'C:\HfT
Thesis_Bikash\thesis data\A2008257NDVI.tif';'C:\HfT Thesis_Bikash\thesis
data\A2008273NDVI.tif' 'C:\HfT Thesis_Bikash\thesis data\exactbound_gcs.shp'

I may have the quoting wrong.  You'll have to see what is required by
ArcGIS.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Windows Service and APPDATA for AUTO startup

2009-01-06 Thread Tim Roberts
jim.vick...@noaa.gov wrote:
> Hello everyone,
> *_
> Background
> _*
>
>1. I've created a Windows Service that looks for its configuration
>   data in a sub-folder of/ os.environ['APPDATA']/.
>2. The Service is configured to automatically start after host reboot.
>3. The Service runs successfully when manually started under its
>   custom (i,e,, not Local System) account.
>4. The Service fails with a /*KeyError: ('APPDATA',)*/ exception
>   when automatically starting after a host reboot.
>
> _*Questions*_
>
>1. Is there some configuration procedure I've overlooked for the
>   custom account the Service runs under?
>

Is this a custom account you created?  Does it actually have a profile
(C:\Documents and Settings\Custom User\Application Data)?

>1. Is this use of /os.environ['APPDATA']/ feasible for AUTO-start
>   Services?  If not, what are preferred folders for
>   application-specific data; my preference is to avoid
>   /pythonxx\Lib\site-packages\.../
>

APPDATA works if the account really does have a profile.  If not, one
common place is to use a folder in \Program Files.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Windows Service and APPDATA for AUTO startup

2009-01-06 Thread Tim Roberts
Jim Vickroy wrote:
> Tim Roberts wrote:
>> Is this a custom account you created?  Does it actually have a profile
>> (C:\Documents and Settings\Custom User\Application Data)?  
>>
> Yes, that folder does exist.  When started manually (with that
> account) the Service works;  the Service fails, as noted above, when
> started automatically after reboot.

Right.  Boot-start services do not get environment variables.  Those
aren't set until session manager runs, which (I believe) doesn't happen
until login.

You might consider creating an HKEY_LOCAL_MACHINE registry entry to hold
the path, then shove the proper value into the registry when the service
is installed.  Installation should happen during a session.  Don't use
HKEY_CURRENT_USER, because that doesn't exist until after login, either.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Dispatching a win32com from within a win32service

2009-01-19 Thread Tim Roberts
Richard Zinn wrote:
>
> I've got an python app that I'm trying to access the iTunes com API
> with, and this app runs as a Windows service.  When I run it I get
> these GetGoodDispatchAndUserName errors.  I think it ends up being
> related to the service not having security access to the Com
> interface?  I've tried setting the --username --password params when I
> start the service like so:

This error, 80080005, can be caused by a timeout when starting an
external COM server..  iTunes happens to take a long time to start up.

Are you trying to run this before login?  There's an issue here, in that
iTunes needs to display a user interface, which it can't really do until
someone has logged in,

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] (no subject)

2009-01-22 Thread Tim Roberts
d...@shragmir.com wrote:
> This is not the end of the world, because I can write the client
> application to use win32 API calls instead of the Python calls.  But does
> anyone have any notion of why this is happening?  I am hoping the answer
> may help me write clients in other applications (where I don’t have access
> to the win32 API).
>
> This code demonstrates the behavior:
>
> import win32file
> import win32pipe
> import threading
> import time
> class Server( threading.Thread ):
> def run( self ):
> self.pipeHandle = win32pipe.CreateNamedPipe(
> '.\\pipe\\testpipe',
> win32pipe.PIPE_ACCESS_DUPLEX,
> win32pipe.PIPE_TYPE_BYTE |
> win32pipe.PIPE_READMODE_BYTE |
> win32pipe.PIPE_WAIT,
> 50,
> 4096,
> 4096,
> 1,
> None)
>
> if self.pipeHandle == win32file.INVALID_HANDLE_VALUE:
> print 'Failed to create named pipe!'
> print 'Exiting...'
> sys.exit(1)
>
> win32pipe.ConnectNamedPipe( self.pipeHandle )
> while True:
> e, v = win32file.ReadFile( self.pipeHandle, 1, None )
> if v == 'A':
> print 'SERVER: Received request "%s"--answering' %v
> err, j = win32file.WriteFile( self.pipeHandle, 'B' )
> win32file.FlushFileBuffers( self.pipeHandle )
> else:
> print 'SERVER: Received request "%s"--exiting' %v
> break
>
> print "SERVER: Exiting server"
>
> SERVER = Server()
> SERVER.start()
> time.sleep(0.1)
> CLIENT_PIPE = open( '.\\pipe\\testpipe', 'a+b' )
>   

You probably want "r+b", although I don't think it really makes a
difference here.

> for i in range( 10 ):
> CLIENT_PIPE.write( 'A' )
> CLIENT_PIPE.flush()
> reply = CLIENT_PIPE.read( 1 )
> print 'CLIENT: answer %d received: "%s"'%(i, reply)
>   

The issue here is with the Python file wrappers.  You have to take SOME
kind of action to allow the Python file wrapper to turn around from
reading back to writing.  If you add
CLIENT_PIPE.seek(0,0)
at the end of the loop, after the read, then it works.  That is...

> CLIENT_PIPE.WRITE( 'C' )
> CLIENT_PIPE.flush()
>   

...it works after you fix the spelling of "WRITE" there.  ;)

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] GetWindowsVersion on Longhorn

2009-01-22 Thread Tim Roberts
Matt Herbert (matherbe) wrote:
> Just wondering if there is a way to differentiate Windows Server 2008
> from Windows Vista? All the normal methods I would use aren't cutting
> it. For instance, sys.getwindowsversion() and platform.uname() are
> returning exactly the same thing for Vista and Windows 2008.
>   

Yes, this is a common issue.  The fact is that Vista SP1 is exactly the
same code as Windows Server 2008.  There is no difference.  Thus, for
the most part you shouldn't care.

You can dig the real system name from the registry. 
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion should have what you need.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] ImportError: DLL load failed: The specified procedure could not be found.

2009-01-26 Thread Tim Roberts
Liu, Donald (H USA) wrote:
> Hi Mark,
>
> Thanks for your reply.  I ran "dir c:\Windows\system32\py*.dll", and got
> the following:
>
> C:\>dir Windows\system32\py*.dll
>  Volume in drive C is System
>  Volume Serial Number is F8F2-995F
>
>  Directory of C:\Windows\system32
>
> 03/27/2008  06:12 PM 2,117,632 python25.dll
> 03/27/2008  06:13 PM   323,584 pythoncom25.dll
> 03/27/2008  06:13 PM98,304 pywintypes25.dll
>3 File(s)  2,539,520 bytes
>0 Dir(s)  12,925,677,568 bytes free
>
> Looks like there's only one set of these files in the system32
> directory.
>   

Of course; Windows does not allow multiple versions in a single
directory.  What Mark suggested is that you compare those versions to
whatever versions are contained in your Python directory.  For example:
dir /s \Python25\py*.dll

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to calc amount of avail RAM in a process ?

2009-01-29 Thread Tim Roberts
geoff wrote:
> I am hoping someone could steer me in the right direction on how to
> calculate the amount of RAM available to a process.
>
> I found the post below from Tim Roberts - a belated thanks Tim for
> your patient responses ! and it seems we regularly hit this limit.
>
> We have an application that needs to display a large number of bitmaps
> (ie 100+) at one time.  Currently we are just reading the file and
> storing as a wx.Image in RAM.  I would seem we are hitting the 2.0G
> limited mentioned in the post below and I am wondering if there is
> some strategy we could use to go beyond this -- other than thumbnails
> and reading as necessary from the filesystem.
>   

There's no easy fix.  Thumbnails and some kind of least-recently-used
caching scheme are probably your best choices.  As Steven pointed out,
you could always install a Win64 system and a 64-bit Python.  Then, you
can get about 8TB of process space.  However, that's not particularly
friendly to your end users, if you need to distribute this.

> At minimum though I would like to be able to 'prompt' the user to
> close some applications (ie mail clients, spreadsheets, etc) to free
> up some more space before our process starts.
> --- or would that even make a difference ?
>   

No.  The 2GB address space limit is per process.  It doesn't matter what
other processes are doing.  You can even have several processes using
2GB of memory, although your disk will get a good workout.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Opening and enumerating resource many times

2009-01-29 Thread Tim Roberts
Gustavo Tabares wrote:
> Hi all,
>
> I'm having a problem when opening and enumerating a network resource
> many times.  For example:
>
> i = 0
>
> while i < 1:
>handle =
> win32wnet.WNetOpenEnum(win32netcon.RESOURCE_CONNECTED,
> win32netcon.RESOURCETYPE_ANY, 0, None)
>partial_nr_list = win32wnet.WNetEnumResource(handle)
>while partial_nr_list:
>partial_nr_list = win32wnet.WNetEnumResource(handle)
>win32wnet.WNetCloseEnum(handle)
>
>i += 1
>
>
> This eventually fails with:
>
> Traceback (most recent call last):
>  File "C:\qtest.py", line 17, in 
>partial_nr_list = win32wnet.WNetEnumResource(handle)
> MemoryError: VirtualAlloc error in WNetEnumResource
>   

Sure enough, if you watch this application in Task Manager, you can see
the memory usage going up smoothly over time.  On my system, however,
10,000 iterations is not nearly enough; memory usage rises to about 6MB,
and then it terminates normally.

Also, it's definitely the WNetEnumResource call that does it.  If you
comment that out, there's no leak.  It doesn't seem to be a Python
garbage issue; I added a forced garbage collection in every loop, and it
still happened.

I haven't found any web articles about this.  Very interesting...

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to calc amount of avail RAM in a process ?

2009-01-29 Thread Tim Roberts
geoff wrote:
> Any tips/hints on calculating the potentially available space ?
>   

Do you mean the total amount of process virtual memory space still
available?  You can actually get that from the GlobalMemoryStatusEx
API.  There's no Python wrapper for that, as far as I know, but here's a
ctypes wrapper.  Note that this does not return the total CONTIGUOUS
memory space, but for your purposes, that's probably not critical.

from ctypes import *
from ctypes.wintypes import *

class MEMORYSTATUSEX(Structure):
_fields_ = [
('dwLength', DWORD),
('dwMemoryLoad', DWORD),
('ullTotalPhys', c_ulonglong),
('ullAvailPhys', c_ulonglong),
('ullTotalPageFile', c_ulonglong),
('ullAvailPageFile', c_ulonglong),
('ullTotalVirtual', c_ulonglong),
('ullAvailVirtual', c_ulonglong),
('ullExtendedVirtual', c_ulonglong),
]

def GlobalMemoryStatusEx():
x = MEMORYSTATUSEX()
x.dwLength = sizeof(x)
windll.kernel32.GlobalMemoryStatusEx(byref(x))
return x

z = GlobalMemoryStatusEx()
print z.ullAvailVirtual

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to calc amount of avail RAM in a process ?

2009-01-29 Thread Tim Roberts
Steven James wrote:
> Not an expert on this, but googling "win32 performance counters" led
> me here:
>
> http://msdn.microsoft.com/en-us/library/aa373193(VS.85).aspx
> <http://msdn.microsoft.com/en-us/library/aa373193%28VS.85%29.aspx>
>
> Should let you get the available physical memory in the system. Not
> sure that you can specify to Windows that you want physical memory
> when you create the image objects, but it might be OK as a rough guide
> of whether there is memory available or not.

No, that's useless for this purpose.  Windows is a virtual memory
system.  Even if you only have 256MB of physical RAM, your process can
still allocate up to 2GB of memory.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] How to calc amount of avail RAM in a process ?

2009-01-29 Thread Tim Roberts
geoff wrote:
>
> There does appear to be this win32api.GlobalMemoryStatusEx().
>   

It wasn't in mine (I checked there first!), but I am a couple of
releases behind.

> In monitoring my system before and after the process crashed, it
> yielded this result below
> - it is supposed to be a table, but I think the HTML is mangling the 
> formatting.
>
>  key: start  crash(   
>  diff)
>TotalPageFile:   6256201728  6256201728(   0)
> AvailVirtual:   2068193280   346382336( -1721810944)
>   MemoryLoad:   33  73(   
>40)
>TotalPhys:   4284137472  4284137472(   0)
> AvailExtendedVirtual:0   0(   
> 0)
>   Length:   64  64(   0)
> TotalVirtual:   2147352576  2147352576(   0)
>AvailPhys:   2849738752  1146531840( -1703206912)
>AvailPageFile:   4721647616  3014774784( -1706872832)
>   

So, you have used 1.7GB of your 2GB.  It's likely that the remaining
350MB is so badly fragmented that you can't get a single chunk as large
as you need.

> If understand your guidance above, monitoring the 'AvailVirtual'
> should allow be to intelligently guess when the user is approaching
> the 'cliff' as the process is running.
>   

Yes, indeed.

> And I would think that examining the AvailPhys should tell me before
> the process starts if there might be a problem/issue with the system
> doing some sort of memory swapping/caching to the pagefile ?
>   

I would caution you not to draw any conclusions based on the physical
numbers.  You WANT your system to be using all of its physical memory. 
Unused physical memory is just wasted money.  The operating system will
page things in and out as needed, on a demand basis, to make sure that
pages you are really USING stay in memory.  The other pages will be used
by DLLs, other processes, and disk caching.  Also remember that, if the
page file gets low, the system will allocate more.

-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

___
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


  1   2   3   4   5   6   7   8   9   10   >