[python-win32] handling paths in windows services

2005-09-09 Thread Jason
I get the following error when trying to run a python script as a service

The instance's SvcRun() method failed 
  File "win32serviceutil.pyc", line 742, in SvcRun
  File "winService.pyc", line 134, in SvcDoRun
  File "winService.pyc", line 83, in RunMe
  File "config.pyc", line 28, in readConfig
exceptions.IOError: (2, 'No such file or directory', 'svc.cfg')

The 'svc.cfg' is on the the same directory that contains the python
script, but its path is obviously not available to the windows
service. Short of using absolute paths, what would be the correct way
to handle this.

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


[python-win32] LVM_GETITEMPOSITION

2009-02-06 Thread Jason Hilton
Okay, so I am new to python win32 development and I am trying to find the 
location of icons on the desktop. I understand that the desktop is just a 
listview control so theoretically I should be able to use this code-

from commctrl import *
from win32gui import *
from ctypes import *

class POINT(Structure):
 _fields_=[('x',c_long),('y',c_long)]

desk=1435653    # Handle to the desktop. I just made this up for the example 
here.

SendMessage(desk,LVM_GETITEMPOSITION,0,POINT())


I think this is supposed to return the point that the icon in index 0 is 
located at, but when I try to use this, explorer crashes. I have researched 
this online and found similar predicaments that other people have had where 
explorer crashed using GETITEMPOSITION, but those examples are in other 
programming languages that I can't read and don't understand, and I haven't 
found any examples in Python on how to overcome this problem, if indeed it is 
possible.

Any help?






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


[python-win32] Restarting Python interpreter used by Classic ASP?

2009-04-17 Thread Jason Baker
I've got some Python code that needs to interact with some Classic ASP code.
 So I've got some Python Classic ASP files that import other Python modules.
 What I would like to do is find a way to restart the Python interpreter so
that I can force it to reload all loaded modules.  However, I don't really
seem to be able to find any way to do this without restarting all of IIS.
Is there any way to do what I want to do?

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


[python-win32] Why can I compile a C extension if I replace python25.lib with python25.dll?

2009-08-07 Thread Jason Baker
I've been trying to get Storm's C extensions to compile under windows.
 For some reason, it wasn't able to find python25.dll, even if I paste
it directly under libs or DLLs.  My theory was that it was finding
python25.lib (which I'm guessing is a static library) and trying to
use that instead.

If I remove python25.lib and replace it with python25.dll, it works
fine.  This solution doesn't really seem like a good one to me though.
 Is there a better solution?
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Why can I compile a C extension if I replace python25.lib with python25.dll?

2009-08-07 Thread Jason Baker
On Fri, Aug 7, 2009 at 11:40 AM, Tim Roberts wrote:
> Jason Baker wrote:
>> I've been trying to get Storm's C extensions to compile under windows.
>>  For some reason, it wasn't able to find python25.dll, even if I paste
>> it directly under libs or DLLs.  My theory was that it was finding
>> python25.lib (which I'm guessing is a static library) and trying to
>> use that instead.
>>
>
> No.  Python25.lib is an import library.  It doesn't contain any code.
> All it contains is special linker records that say "this entry point
> will be found in python25.dll at run-time".
>
> You need Python25.lib when you build the extension.  You need
> Python25.dll when you run a program that uses it.
>
>> If I remove python25.lib and replace it with python25.dll, it works
>> fine.  This solution doesn't really seem like a good one to me though.
>>
>
> That doesn't make sense.  The linker won't use python25.dll.  It can't
> -- it's not in the right format.  The linker needs the .lib.  Then, when
> you run the app, the DLL must be accessible somewhere.  Does the build
> process try to test the extensions?
>
> --
> Tim Roberts, [email protected]
> Providenza & Boekelheide, Inc.
>
> ___
> python-win32 mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-win32
>

Nope.  I get linker errors saying it cant find a whole slew of symbols
from the Python library.  I haven't been able to figure out any other
way to get it to work without replacing python25.lib with python25.dll
(from C:\WINDOWS\SYSTEM32).

If it makes any difference, I'm using MinGW to build this.
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Calling Excel function GetSaveAsFilename, parameter ignored

2011-07-12 Thread Jason Veldicott
Hi,

I am wanting to display a file "Save As..." dialog in Excel through Pywin.
 I am doing this by calling
Application.GetSaveAsFilename<http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._application.getsaveasfilename.aspx>().
 The problem however is that the parameter supplied to this function,
InitialFilename, seems to be ignored by Excel.  Perhaps it's not getting
through to Excel.  When VBA was used to call the same function, the initial
filename displayed correctly.

Not being able to specify an initial filename is inconvenient if not
unsatisfactory from application usability point of view, and one wonders if
other functions might also be affected.   If anyone has any suggestions as
to why this might be happening, or even what a solution may be, I would be
glad to hear from you.

I am using Python 2.7 on Win 7, Office 2010 (v14), and a very recent stable
release of pywin (pywin32-216.win32-py2.7).

Code to recreate the problem:

app = Dispatch("Excel.Application")
app.Visible=True
books=app.Workbooks
books.Open(Filename="C:/temp/test.xlsx")
app.GetSaveAsFilename(InitialFilename="filename.xlsx")  # <<<<<<< THIS
PARAMETER IS IGNORED
app.Quit()

Pywin generated function for the GetSaveAsFilename function (in which it can
be seen that the parameter InitialFilename is handled):

def GetSaveAsFilename(self, InitialFilename=defaultNamedOptArg,
FileFilter=defaultNamedOptArg, FilterIndex=defaultNamedOptArg,
Title=defaultNamedOptArg
, ButtonText=defaultNamedOptArg):
return self._ApplyTypes_(1076, 1, (12, 0), ((12, 17), (12, 17), (12, 17),
(12, 17), (12, 17)), u'GetSaveAsFilename', None,InitialFilename
, FileFilter, FilterIndex, Title, ButtonText)

At the moment, development is stopped in its tracks, so comments are greatly
appreciated.

Thanks

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


Re: [python-win32] python-win32 Digest, Vol 100, Issue 14

2011-07-13 Thread Jason Veldicott
That was it - invoking the function with the FileFilter parameter as well
resulted in the display of the InitialFilename as desired.  Your googling
has saved my day. Many thanks Andrew.

I might say though, that googling on Excel in general seems to bring up a
lot of noisy hits, but more to the point one would not expect the display of
InitialFilename to depend on filter specification especially as it wasn't
required in VBA and it isn't mentioned in Microsoft's documentation of the
function.



On Wed, Jul 13, 2011 at 8:00 PM,  wrote:

> Send python-win32 mailing list submissions to
>[email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/python-win32
> or, via email, send a message with subject or body 'help' to
>[email protected]
>
> You can reach the person managing the list at
>[email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of python-win32 digest..."
>
>
> Today's Topics:
>
>   1. Calling Excel function GetSaveAsFilename, parameter ignored
>  (Jason Veldicott)
>   2. Re: Calling Excel function GetSaveAsFilename, parameter
>  ignored [SEC=PERSONAL] (Andrew MacIntyre)
>
>
> ------
>
> Message: 1
> Date: Wed, 13 Jul 2011 16:36:24 +1000
> From: Jason Veldicott 
> To: [email protected]
> Subject: [python-win32] Calling Excel function GetSaveAsFilename,
>parameter ignored
> Message-ID:
> >
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> I am wanting to display a file "Save As..." dialog in Excel through Pywin.
>  I am doing this by calling
> Application.GetSaveAsFilename<
> http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._application.getsaveasfilename.aspx
> >().
>  The problem however is that the parameter supplied to this function,
> InitialFilename, seems to be ignored by Excel.  Perhaps it's not getting
> through to Excel.  When VBA was used to call the same function, the initial
> filename displayed correctly.
>
> Not being able to specify an initial filename is inconvenient if not
> unsatisfactory from application usability point of view, and one wonders if
> other functions might also be affected.   If anyone has any suggestions as
> to why this might be happening, or even what a solution may be, I would be
> glad to hear from you.
>
> I am using Python 2.7 on Win 7, Office 2010 (v14), and a very recent stable
> release of pywin (pywin32-216.win32-py2.7).
>
> Code to recreate the problem:
>
> app = Dispatch("Excel.Application")
> app.Visible=True
> books=app.Workbooks
> books.Open(Filename="C:/temp/test.xlsx")
> app.GetSaveAsFilename(InitialFilename="filename.xlsx")  # <<<<<<< THIS
> PARAMETER IS IGNORED
> app.Quit()
>
> Pywin generated function for the GetSaveAsFilename function (in which it
> can
> be seen that the parameter InitialFilename is handled):
>
> def GetSaveAsFilename(self, InitialFilename=defaultNamedOptArg,
> FileFilter=defaultNamedOptArg, FilterIndex=defaultNamedOptArg,
> Title=defaultNamedOptArg
> , ButtonText=defaultNamedOptArg):
> return self._ApplyTypes_(1076, 1, (12, 0), ((12, 17), (12, 17), (12, 17),
> (12, 17), (12, 17)), u'GetSaveAsFilename', None,InitialFilename
> , FileFilter, FilterIndex, Title, ButtonText)
>
> At the moment, development is stopped in its tracks, so comments are
> greatly
> appreciated.
>
> Thanks
>
> Jason
> -- next part --
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/python-win32/attachments/20110713/c0173b52/attachment-0001.html
> >
>
> --
>
> Message: 2
> Date: Wed, 13 Jul 2011 07:50:01 +
> From: "Andrew MacIntyre" 
> To: "[email protected]" 
> Subject: Re: [python-win32] Calling Excel function GetSaveAsFilename,
>parameter ignored [SEC=PERSONAL]
> Message-ID:
>
>  
>
> Content-Type: text/plain; charset=iso-8859-1
>
> > From:  Jason Veldicott
> >
> > I am wanting to display a file "Save As..." dialog in Excel through
> Pywin. ?I am doing
> > this by calling?Application.GetSaveAsFilename(). ?The problem however is
> that the
> > parameter supplied to this function, InitialFilename, seems to be ignored
> by Excel.
> >?Perhaps it's not getting through to Excel. ?When VBA was used to call the
> same
> 

RE: [python-win32] ActiveX components with Events

2004-12-17 Thread Hihn, Jason

I will attempt to use my psychic powers and read into this situation
more than you have told.

That ActiveX is coded in VB, hence the OCX. The VB is calling
form.show(). I bet (if all previous assumptiona are correct) that you
could fix the subliminal message by calling form.load()

I will stop now before people start thinking that I am proud of knowing
VB.

>
>   Sorry that was a bad explanation - the control _is_ an
ActiveX
> exe - not an ocx - it simply brings up a form (which in actual fact I
> then hide immediatly, I can't stop the form appearing in the first
place
> - it has to appear for a few millisecs like a subliminal message).
The
> component is an out of process exe - I did find something like
DoEvents
> in pythoncom.PumpWaitingMessages - however I still can't get the
> win32com/python interation working, events are not simply not fired in
> my code.
>
> I think that I will have to write a thin wrapper in VB or C# to
> access the underlying ActiveX exe (and protect the exe from the
> vagarities of the interface) which can then be accesssed with win32com
-
> bit of a pain because it means that I have a maintenance issue (I work
> in a pure python shop and VB/C# code cannot be maintained by anyone
> except for me) but hey, its a protection against future redundancies
> !  However if you know any gotchyas with ActiveX exe/win32com
> integration that I could look out for then that would be great.
>
> Thanks for your help.
>
> Cheers,
>
> Neil
>
> ___
> Python-win32 mailing list
> [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/python-win32



__
This electronic message may contain proprietary and confidential information of 
Verint Systems Inc., its affiliates and/or subsidiaries.
The information is intended to be for the use of the individual(s) or
entity(ies) named above.  If you are not the intended recipient (or authorized 
to receive this e-mail for the intended recipient), you may not use, copy, 
disclose or distribute to anyone this message or any information contained in 
this message.  If you have received this electronic message in error, please 
notify us by replying to this e-mail. (1)
___
Python-win32 mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/python-win32


[python-win32] Question about printing through IE

2006-03-23 Thread Jason Robinson
 
  
Hi, Being relatively new to Python (and no advanced programmer anyhow) I have a question.. For a work related program I need my Python script to be able to change printer settings in IE before printing. I have a script which creates an HTML file with images and text and it uses the ShellExecute approach to print it to a printer (using IE obviously). Only problem is I need it to access the IE printing settings directly and modify them before printing (margins etc etc). I've searched the web throughout but can't figure out where to start... 
Any hints on what I should do? Cheers for any help!
-- Jason Robinson[EMAIL PROTECTED]MSN: [EMAIL PROTECTED]AIM: jaywinx 
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] Question about printing through IE

2006-03-30 Thread Jason Robinson
 
Roger,
 
Thanks! I'm currently fixing the program to make a pdf file instead.. but being able to program it to do the page setup stuff for IE would be easier..
 
Will look into that registry stuff.. need to find out how to access it first :)
 
-Jason
 
On 3/30/06, Roger Upole <[EMAIL PROTECTED]> wrote:
Jason Robinson wrote:>   Hi,>> Being relatively new to Python (and no advanced programmer anyhow) I have a
> question..>> For a work related program I need my Python script to be able to change> printer settings in IE before printing. I have a script which creates an> HTML file with images and text and it uses the ShellExecute approach to
> print it to a printer (using IE obviously). Only problem is I need it to> access the IE printing settings directly and modify them before printing> (margins etc etc). I've searched the web throughout but can't figure out
> where to start...>> Any hints on what I should do?>> Cheers for any help!IE stores printing parameters in the registry atHKCU\Software\Microsoft\Internet Explorer\PageSetup.
For options not covered there, you can use functions inthe win32print module to change your default printer settings,but they'll apply to anything you print, not just IE. hth  Roger
___Python-win32 mailing [email protected]://mail.python.org/mailman/listinfo/python-win32
-- Jason Robinson[EMAIL PROTECTED]http://jaywink.1g.fi for pics, gigs & mixes
tel. +358468507826MSN: [EMAIL PROTECTED]AIM: jaywinx 
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] issues with win32com constants and static/dynamic dispatch

2007-07-04 Thread Jason Ferrara

On Jul 4, 2007, at 11:20 AM, Simon Dahlbacka wrote:

my best guess is that you should be using .ProductName (capital p)  
as static dispatch is case sensitive..


/S


Thats not it.

productName is the correct case.

And also..

>>> print c
  
>>> dir(c)
['QueryInterface', '__class__', '__cmp__', '__delattr__', '__doc__',  
'__getattri
bute__', '__hash__', '__init__', '__new__', '__reduce__',  
'__reduce_ex__', '__re

pr__', '__setattr__', '__str__']

That doesn't look right at all. Shouldn't I see the COM methods and  
attributes? For objects that do work I get stuff that looks much more  
sensible.


>>> print mi
0x13079016>

>>> dir(mi)
['CLSID', 'CloseCameras', 'OpenCameras', '_ApplyTypes_', '__cmp__',  
'__doc__', '
__getattr__', '__init__', '__module__', '__repr__', '__setattr__',  
'_get_good_ob
ject_', '_get_good_single_object_', '_oleobj_', '_prop_map_get_',  
'_prop_map_put

_', 'coclass_clsid']




On 7/4/07, Jason Ferrara < [EMAIL PROTECTED]> wrote:
I'm trying to use a COM library from python.

If I use dynamic dispatch, the com objects all behave correctly,  
but the constants defined in the COM library don't show up.


If I use static dispatch, the constants show up, but COM objects  
returned by calls into the COM library seem broken.


As example, starting with dynamic dispatch

  Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32  
bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more  
information.

  >>> import win32com.client
  >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib")
  >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging 
\sensor_data")

  >>> c=cams[0]
  >>> print c
  
  >>> print c.productName
  Micron Imaging DEMO2

So far everything is fine, but now...

  >>> print win32com.client.constants.MI_BAYER_8
  Traceback (most recent call last):
File "", line 1, in 
File "C:\Python25\Lib\site-packages\win32com\client 
\__init__.py", line 168, in

   __getattr__
  raise AttributeError, a
  AttributeError: MI_BAYER_8

This is no good. So now I try static dispatch

  Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32  
bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more  
information.

  >>> import win32com.client
  >>> mi= win32com.client.gencache.EnsureDispatch("MIDLIBCom.MIDLib")
  >>> print win32com.client.constants.MI_BAYER_8
  1

Things are looking better, but now...

  >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging 
\sensor_data")

  >>> c=cams[0]
  >>> print c
  
  >>> print c.productName
  Traceback (most recent call last):
File "", line 1, in 
  AttributeError: 'PyIUnknown' object has no attribute 'productName'


So whats going on here? What am I doing wrong?

Thanks

- J






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




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


[python-win32] issues with win32com constants and static/dynamic dispatch

2007-07-04 Thread Jason Ferrara

I'm trying to use a COM library from python.

If I use dynamic dispatch, the com objects all behave correctly, but  
the constants defined in the COM library don't show up.


If I use static dispatch, the constants show up, but COM objects  
returned by calls into the COM library seem broken.


As example, starting with dynamic dispatch

  Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32  
bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more  
information.

  >>> import win32com.client
  >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib")
  >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging 
\sensor_data")

  >>> c=cams[0]
  >>> print c
  
  >>> print c.productName
  Micron Imaging DEMO2

So far everything is fine, but now...

  >>> print win32com.client.constants.MI_BAYER_8
  Traceback (most recent call last):
File "", line 1, in 
File "C:\Python25\Lib\site-packages\win32com\client 
\__init__.py", line 168, in

   __getattr__
  raise AttributeError, a
  AttributeError: MI_BAYER_8

This is no good. So now I try static dispatch

  Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32  
bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more  
information.

  >>> import win32com.client
  >>> mi=win32com.client.gencache.EnsureDispatch("MIDLIBCom.MIDLib")
  >>> print win32com.client.constants.MI_BAYER_8
  1

Things are looking better, but now...

  >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging 
\sensor_data")

  >>> c=cams[0]
  >>> print c
  
  >>> print c.productName
  Traceback (most recent call last):
File "", line 1, in 
  AttributeError: 'PyIUnknown' object has no attribute 'productName'


So whats going on here? What am I doing wrong?

Thanks

- J





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


[python-win32] win32com array handling bug?

2007-07-04 Thread Jason Ferrara
I'm making a COM call that should return a two dimensional array, but  
instead I get back a buffer that appears to only contain a single row  
from the array.

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit  
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import win32com.client
 >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib")
 >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data")
 >>> c=cams[0]
 >>> c.startTransport()
 >>> c.updateFrameSize(c.sensor.width, c.sensor.height, 8,0)
 >>> f=c.grabFrame()

At this point f should be a 2048 by 1536 array of bytes, but instead...

 >>> len(f)
2048
 >>> type(f)


I know the COM library is returning the right data because if I do a  
similar trick with IronPython...

IronPython 1.1 (1.1) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
 >>> import clr
 >>> clr.AddReferenceToFile("MIDLIBCOMLib.dll")
 >>> import MIDLIBCOMLib
 >>> mi=MIDLIBCOMLib.MIDLibClass()
 >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging\sensor_data")
 >>> c=cams[0]
 >>> c.startTransport()
 >>> c.updateFrameSize(c.sensor.width, c.sensor.height, 8,0)
 >>> f=c.grabFrame()
 >>> len(f)
3145728
 >>> type(f)

 >>>

Its been squashed down to a 1 dimensional array, but at least all the  
data is there.
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] win32com array handling bug?

2007-07-04 Thread Jason Ferrara
On Jul 4, 2007, at 7:12 PM, Mark Hammond wrote:
>
>>
>> At this point f should be a 2048 by 1536 array of bytes, but
>> instead...
>>
> len(f)
>> 2048
> type(f)
>> 
>
> Arrays of type VT_UI1 are returned as buffers.  You should find the  
> length
> of f is 1536, and you can treat it as a string (ie, just index into  
> it to
> fetch the values, len() to get the length, slice it, etc).  This is
> primarily done as an optimization, so we don't need to waste time  
> and space
> building lists of lists of integers when the data is more naturally a
> 'string of bytes' anyway.
>
> Mark
>

I don't quite follow.

I understand (well, I think I understand) how a buffer works. The  
problem is that the length is wrong.

As shown above, the length of f is 2048. If the array was being  
returned correctly
as a buffer, then the length should be 3145728 (2048 * 1536).
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32


Re: [python-win32] issues with win32com constants and static/dynamicdispatch

2007-07-04 Thread Jason Ferrara

c = win32com.client.Dispatch(c.QueryInterface(pythoncom.IID_IDispatch))

works. Thanks!

FYI, c=win32com.client.Dispatch(c) does not.

>>> c=win32com.client.Dispatch(c)
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python25\Lib\site-packages\win32com\client\__init__.py",  
line 96, in Dispatch
return __WrapDispatch(dispatch, userName, resultCLSID, typeinfo,  
UnicodeToString, clsctx)
  File "C:\Python25\Lib\site-packages\win32com\client\__init__.py",  
line 44, in __WrapDispatch
return dynamic.Dispatch(dispatch, userName, WrapperClass,  
typeinfo, UnicodeToString=UnicodeToString,clsctx=clsctx)
  File "C:\Python25\lib\site-packages\win32com\client\dynamic.py",  
line 111, in Dispatch

typeinfo = IDispatch.GetTypeInfo()
AttributeError: 'PyIUnknown' object has no attribute 'GetTypeInfo'




On Jul 4, 2007, at 7:03 PM, Mark Hammond wrote:

That is strange - the problem is that the resulting COM object is  
returning an IUnknown rather than an IDispatch.  A work around  
should be to say:


c = cams[0]
c = win32com.client.Dispatch(c)

or possibly:

c = win32com.client.Dispatch(c.QueryInterface 
(pythoncom.IID_IDispatch))


I think we could also argue this is a bug in win32com - it should  
try and QI any IUnknown objects - but changing this might break  
existing code...


Mark
-Original Message-
From: [EMAIL PROTECTED] [mailto:python-win32- 
[EMAIL PROTECTED] Behalf Of Jason Ferrara

Sent: Thursday, 5 July 2007 12:30 AM
To: [email protected]
Subject: [python-win32] issues with win32com constants and static/ 
dynamicdispatch


I'm trying to use a COM library from python.

If I use dynamic dispatch, the com objects all behave correctly,  
but the constants defined in the COM library don't show up.


If I use static dispatch, the constants show up, but COM objects  
returned by calls into the COM library seem broken.


As example, starting with dynamic dispatch

  Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32  
bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more  
information.

  >>> import win32com.client
  >>> mi=win32com.client.Dispatch("MIDLIBCom.MIDLib")
  >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging 
\sensor_data")

  >>> c=cams[0]
  >>> print c
  
  >>> print c.productName
  Micron Imaging DEMO2

So far everything is fine, but now...

  >>> print win32com.client.constants.MI_BAYER_8
  Traceback (most recent call last):
File "", line 1, in 
File "C:\Python25\Lib\site-packages\win32com\client 
\__init__.py", line 168, in

   __getattr__
  raise AttributeError, a
  AttributeError: MI_BAYER_8

This is no good. So now I try static dispatch

  Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32  
bit (Intel)] on win32
  Type "help", "copyright", "credits" or "license" for more  
information.

  >>> import win32com.client
  >>> mi=win32com.client.gencache.EnsureDispatch("MIDLIBCom.MIDLib")
  >>> print win32com.client.constants.MI_BAYER_8
  1

Things are looking better, but now...

  >>> cams=mi.OpenCameras("C:\Program Files\Micron Imaging 
\sensor_data")

  >>> c=cams[0]
  >>> print c
  
  >>> print c.productName
  Traceback (most recent call last):
File "", line 1, in 
  AttributeError: 'PyIUnknown' object has no attribute 'productName'


So whats going on here? What am I doing wrong?

Thanks

- J







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


Re: [python-win32] win32com array handling bug?

2007-07-13 Thread Jason Ferrara
If I make the following change to oleargs.cpp

--- oleargs.cpp.orig2007-07-13 11:21:30.711416000 -0400
+++ oleargs.cpp 2007-07-13 11:22:46.764499200 -0400
@@ -834,6 +834,16 @@
 if (FAILED(hres))
 return PyCom_BuildPyException(hres);
 long cElems = ub-lb+1;
+   for(UINT d = dimNo+ 1; d<=nDims; d++)
+   {
+   hres = SafeArrayGetLBound(psa, d, &lb);
+   if (FAILED(hres))
+   return PyCom_BuildPyException(hres);
+   hres = SafeArrayGetUBound(psa, d, &ub);
+   if (FAILED(hres))
+   return PyCom_BuildPyException(hres);
+   cElems *= (ub - lb + 1);
+   }
 long dataSize = cElems * sizeof(unsigned char);
 PyObject *ret = PyBuffer_New(dataSize);
 if (ret!=NULL) {

then I get the full array back, but of course it comes back as an  
array of 1 dimension. The original dimension information is lost.  
Which leads to the question of what is the correct object to return  
in this case.

I don't think that a tuple of buffers, as you describe below, is  
really the right thing. For that to work either you have to reverse  
the dimension order of the array, or the buffers have to contain data  
that originally wasn't contiguous (the buffers hold columns instead  
of rows). Neither seems particularly useful.

Would it make sense to return an object thats a buffer that holds the  
full array data, but also has some additional attribute that contains  
the original array dimensions? For my particular case that would be  
the idea, since I want to feed the data into PIL.Image.frombuffer,  
which takes a buffer plus a size tuple. But I'm not sure what the  
best choice would be for general use.

Also, what is the procedure for building a windows installer for  
pywin32? I can't seem to find any documentation on that. I'd like to  
create an installer that contains the above patch that I can use  
until fix makes it into an offical pywin32 release.

Thanks

  -J


On Jul 4, 2007, at 7:35 PM, Mark Hammond wrote:

>> On Jul 4, 2007, at 7:12 PM, Mark Hammond wrote:
>>>
>>> Arrays of type VT_UI1 are returned as buffers.  You should
>> find the
>>> length
>>> of f is 1536, and you can treat it as a string (ie, just
>> index into
>>> it to
>>> fetch the values, len() to get the length, slice it, etc).  This is
>>> primarily done as an optimization, so we don't need to waste time
>>> and space
>>> building lists of lists of integers when the data is more
>> naturally a
>>> 'string of bytes' anyway.
>>>
>>> Mark
>>>
>>
>> I don't quite follow.
>>
>> I understand (well, I think I understand) how a buffer works. The
>> problem is that the length is wrong.
>>
>> As shown above, the length of f is 2048. If the array was being
>> returned correctly
>> as a buffer, then the length should be 3145728 (2048 * 1536).
>
> Hrm - I misunderstood.  a 2048x1536 array of bytes *should* be  
> returned as a
> list with 2048 entries, each being a buffer of size 1536.  I guess  
> I'll need
> to try and reproduce this in the test suite...
>
> Mark
>

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


[python-win32] stat fields seem wrong when accessing files over SMB on Windows

2023-06-01 Thread Jason Bowen

Hey Python on Windows folks,

I just wanted to send this as a heads up about what seems to be a bug 
I've run into with newer pre-GA releases of Python 3.12 (cf. 3.12a7 and 
3.12b1).


I've filed an issue on the CPython repo: 
https://github.com/python/cpython/issues/105212


The gist is that up to 3.12a6 I get meaningful information from stat 
(either os.stat or pathlib.Path.stat) from a file accessed from a 
Windows Server 2019 VM over SMB 3.1 and after upgrading beyond that I 
get all zeros for time fields.


The offending commit seems to be this one: 
https://github.com/python/cpython/commit/0f175766e27642108c65bba04bbd54dcf8799b0e


Just a heads up for folks who might be playing with Python 3.12 early 
(now with pathlib.Path.walk!) in a Windows/CIFS/SMB environment.


I still have a feeling I'm going to be told that I'm "holding it wrong" 
with this (and I welcome it if that's the case).


Cheers!

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


Re: [python-win32] how to best use datetime objects in pywin32?

2009-01-13 Thread Jason R. Coombs
Thanks for the words of encouragement.

> -Original Message-
> From: Vernon Cole [mailto:[email protected]]
> Sent: Tuesday, 13 January, 2009 12:19
> 
> Second, I am frustrated with the fact that Python's datetime
> implementation is incomplete, since it lacks any standard way of
> getting a time-zone-aware local time. It it truely mind boggling that
> even datetime.datetime.utcnow() is time zone naive! If I specifically
> ask for "utc" am I not specifying a time zone?!  Mark said that "the
> datetime module almost encourages timezone naïve objects." I would say
> that it almost _forces_ it, since tzinfo objects are difficult to
> construct. The only way I found to approximate my local timezone was
> to go back to the old "time" module like  "delta =
> datetime.timedelta(seconds=time.timezone)".

The reason datetime doesn't provide timezone aware calls is because it
explicitly refuses to provide a tz implementation.  I was a little surprised
by this decision at first, but I realized later why this was a good idea.
Because there is no authoritative database of timezone data, they would be
hard pressed to provide a "best of breed" solution for a default timezone
implementation.  By leaving the spec open, they left functionality lacking,
but also drove others like us to implement various implementations with
their various strengths and weaknesses.

> 
> So, I am delighted that I am now able to say:
> now = datetime.datetime.now(win32timezone.GetLocalTimeZone())
> [note: "tzinfo=" is superfluous]

Please note that the current implementation of GetLocalTimeZone is fairly
costly, parsing through the entire registry of time zones to find the
correct one.  A future implementation will drastically limit this cost.

> My suggestion is this:
> Let's make a module with a non-Windows-specific name (and provide for
> a posix version of it also) so that I can write system independent
> code. 

I've heard this request before, but the library is build on the assumption
that the win32apis are available.  I would say it's out of scope for this
library to determine the local time zone for other platforms.  That said, I
find cross-platform compatibility very attractive.

I did some looking into it, and I think the problem would be quite
challenging.  That is, the logic for getting the local time on Linux is
different from Mac, and both are quite different from Windows.  Separate
libraries would be necessary to handle the various cases.

I'm happy to provide a compatible interface such that one could opt to use
win32timezone if the OS is Windows and choose the compatible library
otherwise, but I feel the effort to include Linux and Mac support would be
as much effort as the original library.

Still, I may consider it at some point.

> Also, it would be nice if the name were not quite so verbose. In
> my ideal world, little typing should be required to do common things.
> I would like to see something like:
> 
> >>>herenow = datetime.datetime.now(timezone.local)
> >>>gmt = datetime.datetime.now(timezone.utc)

I assume you meant "gmt = datetime.datetime.utcnow(timezone.utc)"

What about instead
>>> timezone.now()
And 
>>> timezone.utcnow()

Both of which call the respective functions in datetime.datetime and attach
the appropriate timezone?


Jason


smime.p7s
Description: S/MIME cryptographic signature
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32