[python-win32] (no subject)
I am writing a simple client and server that communicate using a duplex-mode named pipe on Windows. For my initial effort, the server used the Windows API calls to set up the pipe and communicate with it, but the client used the regular Python file methods. This works for exactly one transaction. That is --The client writes a message to the pipe --The server reads it --The server writes its response --The client reads the response. But the second time around, I receive IOError: [Errno 0] Error when the client attempts to write the message. 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 dont 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' ) 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) CLIENT_PIPE.WRITE( 'C' ) CLIENT_PIPE.flush() And the results: SERVER: Received request "A"--answering CLIENT: answer 0 received: "B" Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pywin32-210.0001_s-py2.5-win32.egg\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Python25\Lib\site-packages\pyccf\simple_server_test.py", line 42, in CLIENT_PIPE.write( 'A' ) IOError: [Errno 0] Error --Dan Menes ___ python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Duplex pipes issue (was (no subject))
Thank you, Tim, That fixed it! (and apologies to the list for initially sending this with no subject). --Dan > [email protected] 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, [email protected] > Providenza & Boekelheide, Inc. > > ___ > python-win32 mailing list > [email protected] > http://mail.python.org/mailman/listinfo/python-win32 > ___ python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
[python-win32] pywin32 and Windows Filtering Platform?
I have been developing in python for a few years now on unix. I'm dipping my feet into the windows world and am still a total newbie as far as python and windows goes. I am curious if I can access the Windows Filtering Platform api using Python and pywin32. As best as I can tell after a few hours of research is that it is possible but I am having troubles figuring out where to begin. If anyone can help by confirming that if it is or is not possible it would be great. If it is indeed possible can someone point me to some documentation or something that might help get me started? -Dan ___ python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
[python-win32] Trying to send info through serial port
Hello,
I need to be able to send some information through my computer's serial port. I
am using python version 2.6, the pyserial 1.21 module, and the pywin module. My
code seems to be sending info somewhere, because any print statement I add
after the import serial command doesn't show up in my terminal window. However,
the device connected to my serial port doesn't seem to be registering any
received information. I want to send the string "FREQ 720 MHz."
If anyone could help me out with this code, it would be greatly appreciated:
import serial
ser = serial.Serial(0) #if port has specific name, use: ser =
serial.Serial('portName', 19200, timeout=0)
print ser.portstr #should tell you what specific port was used
ser.write('FREQ 720 MHz')
ser.close()
Thanks,
Dan
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
[python-win32] Problem with Pyserial
Hello,
I am trying to send some information out of my computer's serial port. I found
the code posted below online, and the person who posted it said it worked for
them. However, when I tried the code, nothing was sent through the serial port
but I didn't receive any error messages. Does anyone know what the problem
could be?
import serial
ser=serial.Serial(0)
ser.baudrate=9600
ser.port=0
ser.open()
ser.write("hello\n")
ser.close()
Thanks,
Dan
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] problem AddLine AutoCAD win32com.client
Daniel,
I've tested a prerelease version of pywin32 that contains the new
win32com.client.VARIANT class and it works well with AutoCAD. Once
released, you can write something like this:
import win32com.client
import pythoncom
def POINT(x,y,z):
return win32com.client.VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8,
(x,y,z))
acad = win32com.client.Dispatch('AutoCAD.Application')
ms = acad.ActiveDocument.ModelSpace
ms.AddLine(POINT(0,0,0), POINT(1,1,0))
Additional information in Mark's original post on win32com.client.VARIANT:
http://mail.python.org/pipermail/python-win32/2011-October/011844.html
-drg
On Wed, Feb 1, 2012 at 5:29 PM, DANIEL POSE wrote:
> I have used array module because it worked with comtypes module. If I use
> simple list it doesn't work with comtypes nor pywin32.
> If I use:
>
> pt1 = [0.0,0.0,0.0]
> pt2 =[1.0,1.0,0.0]
>
> Then Python responds:
>
>
>
> Traceback (most recent call last):
> File "", line 1, in
> File
> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\startup.py",
> line 128, in runfile
> execfile(filename, glbs)
> File "C:\Documents and Settings\Administrador\Mis
> documentos\DropboxDani\Dropbox\PYTHON\PruebaAutoCADLinea.py", line 16, in
>
> line = ms.AddLine(pt1, pt2)
>
> File ">", line 3, in AddLine
> com_error: (-2147352567, 'Ocurri\xf3 una excepci\xf3n.', (0, None, None,
> None, 0, -2147024809), None)
>
>
>
>
> 2012/2/1 Mark Hammond
>
>> Re-added the python-win32 list - please keep replies on list.
>>
>> Your code uses:
>>
>>
>> > pt1 = array.array('d', [0.0,0.0,0.0])
>> > pt2=array.array('d',[1.0,1.0,_**_0.0])
>>
>> But these aren't supported by pywin32 in the way you expect - what
>> happens if you change this to:
>>
>> pt1 = [0.0,0.0,0.0]
>> pt2 =[1.0,1.0,0.0]
>>
>> ?
>>
>> Mark
>>
>>
>>
>> On 2/02/2012 7:12 AM, DANIEL POSE wrote:
>>
>>> Hello Mark,
>>>
>>> I understand the AutoCAD problem, but in my profession it is the most
>>> extended software for CAD. In my opinion it justify the efford to make
>>> automation tools.
>>> Here I post the answer from Python when I try to draw a line using
>>> win32com.client code in my last mail:
>>>
>>> Traceback (most recent call last):
>>> File "", line 1, in
>>> File
>>> "C:\Python27\lib\site-**packages\spyderlib\widgets\**
>>> externalshell\startup.py",
>>> line 128, in runfile
>>> execfile(filename, glbs)
>>> File "C:\Documents and Settings\Usuario\Escritorio\**borrar.py", line
>>> 15, in
>>> line = ms.AddLine(pt1, pt2) #This draw a line in AutoCAD
>>> File ">", line 3, in AddLine
>>> com_error: (-2147352567, 'Ocurri\xf3 una excepci\xf3n.', (0, None, None,
>>> None, 0, -2147024809), None)
>>>
>>> Thank you in advance,
>>> Daniel Pose.
>>>
>>> 2012/2/1 Mark Hammond >> >
>>>
>>>
>>>Sadly not many people have access to autocad so it is hard to test.
>>>What errors do you get using win32com?
>>>
>>>Mark
>>>
>>>
>>>On 1/02/2012 5:11 AM, DANIEL POSE wrote:
>>>
>>>Hello,
>>>
>>>Recently I try to write some code to automate AutoCAD from
>>> Python. I
>>>have to draw lines from Python using win32com.client module, but I
>>>obtain error. By other hand I solved the problem using comtypes
>>>module.
>>>However, If I try to obtain block attributes information, comtypes
>>>doesn't work but win32com.client work properly.
>>>
>>>AutoCAD attributes working code (work for win32com.client but no
>>> for
>>>comtypes):
>>>[code]
>>>import win32com.client
>>>acad= win32com.client.Dispatch("__**AutoCAD.Application")
>>>doc = acad.ActiveDocument
>>>seleccion=doc.SelectionSets.__**Add('selection1')
>>>
>>>seleccion.SelectOnScreen()
>>>for objeto in seleccion:
>>> if objeto.ObjectName=='__**AcDbBlockReference':
>>> bloque=objeto.GetAttributes()
>>> bloque[0].TagString='__**newattributename' #This change
>>>
>>>the name
>>>for the first attribute in the selected block
>>>[/code]
>>>
>>>Draw line (work for comtypes but doesn't work for
>>> win32com.client):
>>>[code]
>>>import comtypes.client
>>>import array
>>>acad = comtypes.client.__**GetActiveObject("AutoCAD.__**
>>> Application")
>>>
>>>doc = acad.ActiveDocument
>>>ms = doc.ModelSpace
>>>pt1 = array.array('d', [0.0,0.0,0.0])
>>>pt2=array.array('d',[1.0,1.0,_**_0.0])
>>>
>>>line = ms.AddLine(pt1, pt2) #This draw a line in AutoCAD
>>>[\code]
>>>
>>>My question is: Is posible to fix the problem using win32com to
>>> draw
>>>autocad line in order to avoid comtypes use?
>>>I found on the web several coments to the problem, but no
>>> solution.
>>>
>>>Thanks for help,
>>>Daniel Pose.
>>>
>>>
>>>__**_
Re: [python-win32] speed up win32com.client
VBA is faster because it's running in-process inside AutoCAD (everything is
loaded into acad.exe). Python runs out-of-process (AutoCAD objects need to
be passed back and forth between acad.exe and python.exe).
You can use AutoCAD's ObjectARX API to embed python inside AutoCAD and make
python in-process; you'll get a significant speedup. You'll need to know
C++ in order to do that. Let me know if you'd like further details.
64-bit AutoCAD runs VBA out-of-process because there is no 64-bit VBA;
you'd see the same slowness there that you're seeing with python.
-drg
On Mon, May 7, 2012 at 5:26 PM, DANIEL POSE wrote:
> Hello,
>
> I am writing code to program AutoCAD access from Python using pywin32.
> When I need to work with a high number of AutoCAD objects, it is faster to
> use vba than python.
> Are there some way to speed up python code in order to work faster with
> AutoCAD elements?
> For example in the next code when I work with 512 AutoCAD blocks:
>
> import win32com.client
>
> import time
>
> t1=time.clock()
>
> acad= win32com.client.Dispatch("AutoCAD.Application")
>
> doc = acad.ActiveDocument
>
> seleccion=doc.SelectionSets.Add('selection6')
>
> seleccion.SelectOnScreen()
>
> t2=time.clock()
>
> M=[]
>
> for objeto in seleccion:
>
> if objeto.ObjectName=='AcDbBlockReference':
>
> M.append(objeto.InsertionPoint)
>
> t3=time.clock()
>
> print 'M_dimension=',len(M)
>
> R=[]
>
> for m in M:
>
> for x in M:
>
> R.append(max(m)+max(x))
>
> print 'R_dimension=',len(R)
>
> t4=time.clock()
>
> t_block1=t2-t1
>
> t_block2=t3-t2
>
> t_block3=t4-t3
>
> print 't_block1=',t_block1
>
> print 't_block2=',t_block2
>
> print 't_block3=',t_block3
>
>
> The output for the code is the following:
>
> M_dimension= 512
> R_dimension= 262144
> t_block1= 4.25343304805
> t_block2= 3.88635510938
> t_block3= 0.487477319045
>
>
> Then it is faster to work with R than M, even though R is bigger.
>
> Some suggestions for speed up pywin32 code in this example?
>
>
> Best Regards,
>
> Daniel Pose.
>
>
>
>
>
>
> ___
> python-win32 mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-win32
>
>
___
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] VARIANT parameter
On Fri, Oct 12, 2012 at 6:27 AM, Matteo Boscolo wrote: > sometimes you need a combination of variant type like > win32com.client.VARIANT(VT_VARIANT | VT_NULL,None) > In this case, AutoCAD and Intellicad want: filterType = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_I2, [0]) filterData = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_VARIANT, ['LINE']) -drg On Fri, Oct 12, 2012 at 6:27 AM, Matteo Boscolo wrote: > > sometimes you need a combination of variant type like > win32com.client.VARIANT(VT_VARIANT | VT_NULL,None) > > it's better to pass tuple instead of list .. may be this could help .. > > regards, > Matteo > > Il 12/10/2012 13:13, Johannes Frank ha scritto: > > Hello, > > I am trying to access an AutoCAD clone, intellicad, via win32com. I > managed to access, but now I am stuck. > AutoCAD as well as Intellicad want > > filterType=VARIANT(pythoncom.VT_ARRAY,[0]) > filterData=VARIANT(pythoncom.VT_ARRAY,['LINE']) > dwg.ActiveSpace = cnsts.vicModelSpace > > sel.Select(cnsts.vicSelectionSetAll,None,None,filterType,filterData) > > I get an error: > > MemoryError: CreatingSafeArray > > In VB6 I pass two variant arrays in VB.NET 2010 I pass an integer array > and an object array. > > Now how do I find out how to pass this parameter in pythoncom / win32com > > Thank you for your attention > > Kind Regards > > -- > Dipl.-Ing. (FH) Johannes-Maria Frank > Bildungsberater > Königsberger-Str. 19b > 76139 Karlsruhe > Tel. +49(170) 3833849 > e-mail: [email protected] > > > > ___ > python-win32 mailing > [email protected]://mail.python.org/mailman/listinfo/python-win32 > > > > ___ > 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] getting underlying OLE object identity for win32com objects
Hi all,
I'm trying to figure out if there is a canonical way to get the identity
of an object that has been wrapped by the win32com module, so that it
can be compared to other objects.
For example, I can use this code to get a handle to the same object
twice in the JMP application, but the two tables do not have the same
"object identity" at the Python level:
from win32com.client import gencache
mod = gencache.GetModuleForProgID("JMP.Application")
app = mod.Application()
table = app.GetTableHandleFromName("Table1")
same_table = app.GetTableHandleFromName("Table1")
print table
print same_table
print table is same_table
#
#
# False
It appears that all win32com OLE automation objects also have an
_oleobj_ property. _oleobj_ is a PyIDispatch object
(http://docs.activestate.com/activepython/3.1/pywin32/PyIDispatch.html),
which only has a few methods, none of which seem pertinent to the
question of object identity. However, the repr() of _oleobj_ seems to
point to the underlying OLE automation object:
print table._oleobj_
print same_table._oleobj_
#
#
In order to confirm that two objects refer to the same underlying OLE
object, I've resorted to parsing the `repr()` strings and comparing the
hexadecimal addresses ("`obj at 0x...`").
Is there a better way to do this?
Thanks,
Dan Lenski
ps- I also posted this on StackOverflow
(http://stackoverflow.com/questions/26068864) but it doesn't seem to
have gotten many eyeballs there.
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] getting underlying OLE object identity for win32com objects
Tim Roberts probo.com> writes: > Right. They are two separate Python objects. > > print table > print same_table > print table is same_table > > "is" will obviously fail, because it is checking for two identical > Python objects. However, did you try the == operator? The source code > seems to imply that the __eq__ operator is delegated to the _oleobj_ > properties, which do know about COM object identity. > > Assuming the straight "==" didn't work, I would think a better way would > be simply to compare the _oleobj_: > > if table._oleobj_ == same_table._oleobj_: > > The source code in dynamic.py says the _oleobj_ members know how to > compare themselves. Thanks very much, Tim. I feel quite sheepish but didn't consider the == operator since I'm so used to using "is" for this purpose with Python objects. Both versions that you suggested do the trick: table==same_table and table._oleobj_==same_table._oleobj_ Thanks, Dan ___ python-win32 mailing list [email protected] https://mail.python.org/mailman/listinfo/python-win32
[python-win32] IIS CGI installation
I have found a lot of links to http://www.e-coli.net/pyiis_server.html, however, this page starts out with: "This is really very easy. It is also not a good idea for both security and performance reasons." What are the security and performance issues, and how can they be overcome? I am wanting to use Python for CGI on a shared Windows 2000 Server with IIS, so security and performance are of utmost importance. Thanks in advance. --df ___ Python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
[python-win32] Autocad automation via COM: Passing coordinates as arguments (suggested fix within)
> From: wccppp <[EMAIL PROTECTED]>
> Subject: [python-win32] question about COM again: variable type?
>
> [code]
> ms.AddPoint([0.0, 0.0, 0.0]) # this line gives the problem
> [/code]
>
> # Result is of type IAcadPoint
> def AddPoint(self, Point=defaultNamedNotOptArg):
> """Creates a Point object at a given location"""
> ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12,
> 1),),Point)
> if ret is not None:
> ret = Dispatch(ret, 'AddPoint',
> '{35AF3AB5-755E-4AC9-8BAF-31B532870751}', UnicodeToString=0)
> return ret
>
Sorry for the long reply.
The type library for AutoCad 2006 says that coordinates should be
passed as variants, so makepy's output is correct. But you can change
the makepy-generated file to process the argument as an array of doubles
instead of a variant and it will work. I'm not sure if that's because
the interface will also accept a 'raw' array, or if pythoncom is
magically wrapping the array in a variant.
Taking from the AddPoint method of the IAcadModelSpace class that you've
included:
[code]
ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0), ((12, 1),),Point)
[/code]
The (12, 1) part describes the Point argument as an (Variant, Input),
roughly. This should be changed to (8197, 1), which is (Array of
Doubles, Input):
[code]
ret = self._oleobj_.InvokeTypes(1562, LCID, 1, (9, 0),((8197,1),),Point)
[/code]
Unfortunately, this happens all over the place -- not just the AddPoint
method. It would be very tedious to go through makepy's output and
make the >1500 changes. (12, 1) cannot be changed globally in there. It
also happens for more than just coordinate arguments; the Select methods
of SelectionSet objects have filters which are also arrays wrapped in a
variant. I haven't run across any others; the code below fixes
everything I've found.
My solution was to change build.py (does some of makepy's work; located
in %pythoninstalldir%\lib\site-packages\win32com\client\) to apply this
Variant -> Array change for me when processing the type library. The
line numbers I reference are from pywin32 2.07; I tried to include
enough context to find the right parts of build.py in case yours is
different.
My understanding of COM is not good, and these changes to build.py don't
seem suitably robust. It does a small check to see if it's processing
an Autocad library, but I suggest restoring build.py to its original
state after processing your Autocad type libraries. You'll lose these
fixes for dynamic dispatch in that case.
I would be grateful if somebody could point out any red flags or suggest
a better approach.
Near the top of build.py (~line 52):
[code]
NoTranslateMap = {}
for v in NoTranslateTypes:
NoTranslateMap[v] = None
#My addition starts here
AutocadTranslateMap = {
('alignpoint','anglevertex','arccenter','arcpoint','axisdir',
'axispoint','basepoint','boundry','center','centerpoint',
'chordpoint','controlpoint','controlpoints','coordinates',
'definitionpoint','dimlinelocation','direction',
'directionvector','endpoint','endtangent','extline1point',
'extline1startpoint','extline2endpoint','extline2point',
'extline2startpoint','farchordpoint','firstendpoint','fitpoint',
'fitpoints','frompoint','insertionpoint','inspoint','jogpoint',
'knots','knotvalues','leader1point','leader2point',
'leaderendpoint','limits','lowerleft','lowleft','majoraxis',
'normal','origin','overridecenter','overridecenterpos',
'plotorigin','point','point1','point2','point3','point4',
'pointsarray','pointslist','pointsmatrix','porigin',
'secondendpoint','secondpoint','snapbasepoint','startpoint',
'starttangent','target','targetpoint','textalignmentpoint',
'textpoint','textpos','textposition','topoint',
'transformationmatrix','upperright','vertex','vertexlist',
'vertices','verticeslist','weights','wpt','wpt1','wpt2',
'xaxispoint','xline1point','xline2point','xvector',
'yaxispoint','yvector'): 8197,
('filtertype',): 8193,
('filterdata',): 8204
}
#My addition ends here
class MapEntry:
"Simple holder for named attibutes - items in a map."
def __init__(self, desc_or_id, names=None, doc=None,
resultCLSID=pythoncom.IID_NULL, resultDoc = None, hidden=0):
[/code]
Then, in the _AddFunc_ method of class DispatchItem (~line 175):
Note that the code below has been stripped of its indentation to
hopefully make it more readable in email. Indentation within the posted
code is correct, but the entire code block needs to be indented to match
its context in build.py.
[code]
fdesc.rettype = typerepr, flag, defval, resultCLSID
# Translate any Alias or Enums in argument list.
argList = []
#Changes begin here;
#for argDesc in fdesc.args:
for index, argDesc in enumerate(fdesc.args):
typerepr, flag, defval = argDesc
#Catch only if reasonably sure this is Autocad
if self.pyth
[python-win32] Explicit variant types for Invoke & InvokeTypes (Was Re: Autocad.*)
own to solve a less general case than Mark describes above: the Variant() class could be used *just* so that a user could build an array of objects typed to their choosing. I think this would still be useful, and it would likely be forward-compatible with a solution for the general case. So...if nobody else has a pressing need for this, or time to help with it, (Mark & other CVS committers) would you accept a less general patch? Thanks all! -Dan Glassman ___ Python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Unable to close Excel, error in dynamic.py
George Flaherty wrote:
> I have been messing around Excel, but when I run the following example I get
> an error?
>
> Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
from win32com.client import Dispatch
xlApp = Dispatch("Excel.Application")
xlApp.Visible = 1
xlApp.Workbooks.Add()
>
xlApp.ActiveSheet.Cells(1,1).Value = 'Python Rules!'
xlApp.ActiveWorkbook.ActiveSheet.Cells(1,2).Value = 'Python Rules 2!'
>>> xlApp.ActiveWorkbook.Close(SaveChanges=0)
>>> xlApp.Quit()
Workbooks have the Close method.
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Explicit variant types for Invoke & InvokeTypes (WasRe: Autocad.*)
Mark Hammond wrote:
>> if ( PySequence_Check(obuse) )
>> {
>>V_ARRAY(var) = NULL; // not a valid, existing array.
>>ok = PyCom_SAFEARRAYFromPyObject(obuse, &V_ARRAY(var), rawVT);
>>V_VT(var) = VT_ARRAY | rawVT;
>> }
>> else
>> {
>>PythonOleArgHelper helper;
>>helper.m_reqdType = rawVT;
>>V_VT(var) = rawVT;
>>ok = helper.MakeObjToVariant(obuse, var);
>
> The problem may well be your use of PySequence_Check() - that will succeed
> for a string. You are then likely to end up with a VT_UI8 array. I think
> you should *always* defer to MakeObjToVariant - that function will check the
> VT, and if an array is requested it will do the right thing - ie, the
> variant-type should *always* drive the conversion process in this case,
> rather than the object value.
Ah -- the lightbulb above my head is now lit. Thank you!
> Yep, I think this is looking quite reasonable. Regarding testing, the best
> thing is probably to try and use win32com\test\testvb.py. If you have VB
> and the pywin32 sources, you should be able to create the test DLL from the
> com\TestSources\PyCOMVBTest directory. testvb.py exercises *lots* of
> different variant types, so somehow arranging (by copy-paste if necessary)
> for those tests to be called with a new Variant object would be excellent.
> If you don't have VB, let me know and I will send you a compliled DLL.
Got the tests, passed the tests! The original testvb.py also passes, so
I can't have messed anything up *too* much! :)
I don't want to post such long code, so I'm hosting it. If the links
don't work for any interested party, please just email me and I'll get
you a copy. I'm quite enjoying this learning experience and am open to
all suggestions.
Test file:
http://www.originalrog.org/testvb_variantclass.py
My first try at class Variant (and some helpers):
http://www.originalrog.org/VariantUtils.py
That is the class definition which passed the tests. I hope a new-style
class is okay; I figured it would be, given the python versions for
which pywin32 "binaries" are distributed. If not, I don't think there's
anything that can't be rewritten in classic style.
A brief interactive session showing some class behaviour:
http://www.originalrog.org/variantclass_interactive.txt
The C++ implementation is below. I erased some of this
thread...so...context: this is in oleargs.cpp in
PyCom_VariantFromPyObject(). I put this clause just before the
PySequence_Check() clause instead of at the top; figure it won't be used
as often as the other clauses.
[code]
else if (strcmp(obj->ob_type->ob_type->tp_name, "VariantBase") == 0)
{
PyObject* typeAttr = PyString_FromString("_com_variant_type_");
PyObject* valAttr = PyString_FromString("_com_variant_value_");
if (!(typeAttr && valAttr))
return FALSE;
PyObject* reqdType = PyObject_GenericGetAttr(obj, typeAttr);
if (!reqdType)
return FALSE;
VARENUM rawVT = (VARENUM)PyInt_AsLong(reqdType);
PyObject* obuse = PyObject_GenericGetAttr(obj, valAttr);
if (!obuse)
{
Py_XDECREF(reqdType);
return FALSE;
}
PythonOleArgHelper helper;
helper.m_reqdType = V_VT(var) = rawVT;
helper.MakeObjToVariant(obuse, var);
Py_XDECREF(reqdType);
Py_XDECREF(obuse);
}
// NOTE: PySequence_Check may return true for instance objects,
...
[/code]
Cheers!
-Dan Glassman
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Explicit variant types for Invoke & InvokeTypes (WasRe: Autocad.*)
Dan Glassman wrote: > I don't want to post such long code, so I'm hosting it. If the links > don't work for any interested party, please just email me and I'll get > you a copy. I'm quite enjoying this learning experience and am open to > all suggestions. > > Test file: > http://www.originalrog.org/testvb_variantclass.py > Updated the test file; wanted to be sure that my use of the variant class' Value property to check "return" values wasn't skewing the results: http://www.originarog.org/testvb_variantclass2.py. Still passed, so it's apparent that _getValue(), which is the Value properties' getter, is working just as it should. Also realized that the SAFEARRAY support in oleargs.cpp uses PyCom_VariantFromPyObject, so the variant class can get used when the TYPEDESC calls for those, too. I applied the Variant class to those portions of the test; still passes with no changes required. -drg ___ Python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Excel advanced find
Tim Golden wrote:
> [EMAIL PROTECTED]
>
> | Hello all,
> |
> | I'm having some trouble on the find function in Excel. A
> | simple Find statement works fine, but as soon as I want to
> | use an advanced option (xlByColumns) I get an error.
> |
>
> [... snip ...]
>
> | findcell =
> | xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValue
> | s,constants.xlWhole,constants.xlByColumns,constants.xlNext,Fal
> | se,False,None)
>
> | And this is the output:
> | C:\temp\python\excel>python findtest.py
> | $D$5
> | Traceback (most recent call last):
> | File "findtest.py", line 20, in ?
> | findcell =
> | xlApp.ActiveSheet.UsedRange.Find('FXN3',None,constants.xlValues,c
> | onstants.xlWhole,constants.xlByColumns,constants.xlNext,False,
> | False,None)
> | File "C:\Program
> | Files\python24\lib\site-packages\win32com\gen_py\00020813-000
> | 0--C000-0046x0x1x4.py", line 21407, in Find
> | , MatchCase, MatchByte, SearchFormat)
> | pywintypes.com_error: (-2147352567, 'Exception occurred.',
> | (0, None, None, None,
> | 0, -2147352571), 9)
>
> *Very* quick and untested response: try using named
> params for the Find method. At the very least, you
> can then miss out the default values and it might
> narrow the prob. down
When you use None, the arguments will still be presented to the Excel
interface as Null. It would appear that the Excel interface doesn't
like either the [After] arg nor the [SearchFormat] arg to be Null.
Named arguments will work as suggested; this will prevent those
arguments from being presented to the Excel interface at all. You can
also use pythoncom.Missing, which is another way to prevent arguments
from being presented to the interface:
[code]
from pythoncom import Missing
usedRange = xlApp.ActiveSheet.UsedRange
usedRange.Find('FXN3', Missing, constants.xlValues,
constants.xlWhole, constants,xlByColumns,
constants.xlNext, False, False, Missing)
[/code]
--
-Dan Glassman
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
[python-win32] [Fwd: Re: Excel advanced find]
Dan Glassman wrote:
> Named arguments will work as suggested; this will prevent those
> arguments from being presented to the Excel interface at all. You can
> also use pythoncom.Missing, which is another way to prevent arguments
> from being presented to the interface:
>
> [code]
> from pythoncom import Missing
> usedRange = xlApp.ActiveSheet.UsedRange
> usedRange.Find('FXN3', Missing, constants.xlValues,
> constants.xlWhole, constants,xlByColumns,
> constants.xlNext, False, False, Missing)
> [/code]
Whoa -- disregard that suggestion; that was really bad idea on my
part. All the arguments after the first Missing get ignored if you do that.
Named arguments, then.
--
-Dan Glassman
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Using win32com Constants
David Carter wrote: >>-Original Message- >>From: Robert Brewer [mailto:[EMAIL PROTECTED] >>Sent: Friday, February 17, 2006 4:11 PM >>To: David Carter; [email protected] >>Subject: RE: [python-win32] Using win32com Constants >> >> >>David Carter wrote: >> >>>Why is it that when I want to use a win32COM constant such as >>>acViewNormal in an MS Access COM automation session I find I >>>have to use some convoluted thing like: >>> >>> ComConstants = >>>win32com.client.constants.__dict__["__dicts__"][0] >>> viewtype = ComConstants['acViewNormal'] >>> >>>Am I missing something obvious? >> >>Are you calling Dispatch before referencing the constants? >> >>http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/pywin32 > > Yes, -those- constants work fine. They're the application specific constants > that require the convolution. He wasn't suggesting that Dispatch wasn't working, but rather pointing out that the constants don't work until *after* you've called Dispatch. The way to use the constants (after calling Dispatch) is like this: >>> win32com.client.constants.acViewNormal If that's not working, then I'd say there's nothing *too* obvious that you're missing. You've obviously run makepy, otherwise even the convolution wouldn't work... -drg ___ Python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Adding AutoCAD Points.
Tim Riley wrote:
> Has anyone come up with a way to add AutoCAD points using Python and
> win32? Do I have to use Makepy on the type library? For example adding a
> line to Modelspace requires you to call the AddLine method that accepts
> two arrays of doubles.
>
> Any help/tips would be greatly appreciated.
AutoCAD underspecifies the type of variant it's expecting for such
functions -- the type library requests only a variant instead of an
array of doubles (whereas the documentation is quite clear about what is
needed.)
I've been sitting for **way too long** on a patch that allows you to
specify the type of variant you'd like, permitting something like:
import pythoncom
import win32com.client
from win32com.client.variant import MakeVariant
acad = win32com.client.Dispatch('autocad.application')
dwg = acad.ActiveDocument
ms = dwg.ModelSpace
point1 = (0,0,0)
point2 = (1,1,0)
point1 = MakeVariant(pythoncom.VT_ARRAY | pythoncom.VT_R4, point1)
point2 = MakeVariant(pythoncom.VT_ARRAY | pythoncom.VT_R4, point2)
line = ms.AddLine(point1, point2)
Since I'd last looked at this, AutoCAD 2007 got released and the issue
wasn't resolved on their end. Unfortunately, Open Design Alliance'
DWGDirectX library duplicates that bug.
I *finally* started looking at this again just last week and am in the
process of writing a test suite for it. I'll be emailing Mark Hammond
with my progress (initial efforts way back when were overly rigid and
testing wasn't up to snuff). I'll copy you on that update when I send
it tomorrow. It's so nice to have a break from CAD work. :)
Mark and I had taken that discussion off the list way back in February,
and I'll leave it to him if he wants it back on the list.
Cheers!
-drg
___
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32
[python-win32] Memory Leak in MFC/C++ based Python Extended/Embedded code.
Hi all, I have a MS Windows/MFC based C++ code that I have implemented Python embedding/extending in. (I am using Visual Studio 2003.) The code seems to do what I have intended except it always reports a memory leak when it exits. I tried all kinds of things but there did not seem to be anything I could do to get rid of it. So... I built a new MFC project and the only things I added was... #include at the top of the application class .cpp file and the following two lines Py_Initialize(); Py_Finalize(); in the application class constructor. The minimal code STILL reports a memory error. It looks like the memory leak had nothing to do with my code. Anybody have any ideas how to fix this? Background: I am using Python 2.5.1. I am not using BOOST::PYTHON (I am using BOOST::NUMERIC and BOOST::SHARED_PTR for other things in the code - maybe I should use BOOST::PYTHON - maybe their shared_ptr's would take care of this for me? ). I also am not using SWIG or any other "helpers". Any help would be greatly appreciated. If this is not the right forum please advise where to post this. It got to figure that someone has seen this before - considering as long as Python has been around and as big as the developer community is. Thanks in advance for your collective help. Dannyt ___ python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
[python-win32] Possible leak in the win32evtlog module when using EvtSubscribe
Good day,
I have been using the win32evtlog.EvtSubscribe function to subscribe for
changes in the event log and saw that under a stress of event logs being
generated, the memory of the Python process increases significantly and
never goes back. I have removed all of the code in my callback so I'm doing
nothing in the callback and still seeing what seems to be a significant
memory leak (Increasing quickly to many MBs)
All I'm doing is :
def my_event_handler():
pass
subscription = win32evtlog.EvtSubscribe('Security',
win32evtlog.EvtSubscribeToFutureEvents,
\
None, Callback=my_event_handler, Context=None,
Query=None)
And then in another process creating tons of event logs by doing :
while True:
x = win32security.LogonUser("Dan Cohen","", "X",3,0)
x = None
Which creates a lot of event logs of type user logon.
The installed version is 219 which seems to be the most recent.
Would very much appreciate your help,
Dany
___
python-win32 mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-win32
[python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in
I apologize in advance for the basic question, but I have spent about 40 hours researching how to make the demo "outlookAddin.py" load on my Outlook 2016 32 bit application. I am running Python version 3.7 and I can successfully run the outlookAddin.py script from PyCharm. But then when I open outlook, I always receive the message "... not loaded. a runtime error occurred during the loading of the com add-in". I am sure that I missing a very basic step to make this run, but I can't seem to find anything online. Do I need to do something to compile the outlookAddin.py script before or after I run it? Or should the add-in load after it is registered? I'm so sorry for such a basic question. Thank you! Dan ___ python-win32 mailing list [email protected] https://mail.python.org/mailman/listinfo/python-win32
Re: [python-win32] Outlook Add-In Demo Question ... A runtime error occurred during the loading of the com add-in
You all are brilliant for responding. Thank you for being so kind! I will try these fixes and get back to you. Thank you so much!!! On Wed, Dec 8, 2021 at 4:32 PM Mark Hammond wrote: > Another possibility for the failure is the environment office is running > under (which broadly speaking can be described as the PATH). > > Back in the day, it was very common for Python and pywin32 to end up > sticking stuff in the system32 directory, then things like COM would > work in almost every context, as the system directory was (almost) > always on the path. > > However, these days that's far less likely to be true - so the problem > might be as simple as the fact that pythonXX.dll and pythoncomXX.dll > can't be located when office is running, although can be in your pycharm > environment. > > Ensuring the directory with these files is on the PATH for office is the > generic advice, but it's difficult to give more specific advice without > knowing more about your specific environment. > > Cheers, > > Mark > > On 8/12/2021 1:49 pm, Dan Moisan wrote: > > I apologize in advance for the basic question, but I have spent about 40 > > hours researching how to make the demo "outlookAddin.py" load on my > > Outlook 2016 32 bit application. I am running Python version 3.7 and I > > can successfully run the outlookAddin.py script from PyCharm. But then > > when I open outlook, I always receive the message "... not loaded. a > > runtime error occurred during the loading of the com add-in". > > > > I am sure that I missing a very basic step to make this run, but I can't > > seem to find anything online. Do I need to do something to compile the > > outlookAddin.py script before or after I run it? Or should the add-in > > load after it is registered? I'm so sorry for such a basic question. > > > > Thank you! > > > > Dan > > > > ___ > > python-win32 mailing list > > [email protected] > > https://mail.python.org/mailman/listinfo/python-win32 > > ___ python-win32 mailing list [email protected] https://mail.python.org/mailman/listinfo/python-win32
