win32com problem

2006-10-24 Thread cfriedalek
I'm interacting with a third party application using python and com.
However having problems and don't know what to look at next to resolve
the issue.

The app. can be driven by VBS. The following VBS code works:

Set Synergy = CreateObject("synergy.Synergy")
Synergy.OpenProject "D:/temp/project.mpi"
Synergy.Project.OpenItemByName "test_bar_3d_6l_pc1", "Study"
Set Tet = Synergy.StudyDoc.GetFirstTet()
While Not Tet Is Nothing
  Str = Tet.ConvertToString() + " "
  Set Tet = Synergy.StudyDoc.GetNextTet(Tet)
  MsgBox Str
WEnd

This prints "TE1" "TE2" etc


The "same" code in python returns > with each call
to the GetNextTet method.

import win32com.client
from win32com.client import Dispatch
Synergy = win32com.client.Dispatch("synergy.Synergy")
Synergy.OpenProject("D:/temp/project.mpi")
Synergy.Project.OpenItemByName("test_bar_3d_6l_pc1", "Study")
tet = Synergy.StudyDoc.GetFirstTet
while tet:
print str(tet)
tet = Synergy.StudyDoc.GetNextTet(tet)

Any clues on what I'm doing wrong, or how to investigate whether there
is a bug in win32com or in the third party apps com implementation.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32com problem

2006-10-24 Thread cfriedalek
> tet = Synergy.StudyDoc.GetFirstTet(), perhaps?

com_error: (-2147352573, 'Member not found.', None, None)

Sorry, should have mentioned that I tried that already. Any thoughts on
how to establish if the problem is with win32com or the 3rd party app?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32com problem

2006-10-25 Thread cfriedalek

Gabriel Genellina wrote:
> Run it on the debugger step by step, and inspect all the intermediate objects.
> Synergy.StudyDoc might be a function, by example, so you should add
> another pair of ().
> This is not obvious looking at the VB code.

(Sorry, tied up this arvo so I could respond to your suggestion
earlier.)

Here's part of a debug session.

(Pdb) type(Synergy.StudyDoc)


(Pdb) type(Synergy.StudyDoc.GetFirstTet)


(Pdb) Synergy.StudyDoc.GetFirstTet
>

(Pdb) dir (Synergy.StudyDoc)
['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum',
'_Release_', '__A
ttrToID__', '__LazyMap__', '__call__', '__cmp__', '__doc__',
'__getattr__', '__g
etitem__', '__init__', '__int__', '__len__', '__module__',
'__nonzero__', '__rep
r__', '__setattr__', '__setitem__', '__str__', '_builtMethods_',
'_enum_', '_fin
d_dispatch_type_', '_get_good_object_', '_get_good_single_object_',
'_lazydata_'
, '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_',
'_print_details_
', '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_']

(Pdb) dir (Synergy.StudyDoc.GetFirstTet)
['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum',
'_Release_', '__A
ttrToID__', '__LazyMap__', '__call__', '__cmp__', '__doc__',
'__getattr__', '__g
etitem__', '__init__', '__int__', '__len__', '__module__',
'__nonzero__', '__rep
r__', '__setattr__', '__setitem__', '__str__', '_builtMethods_',
'_enum_', '_fin
d_dispatch_type_', '_get_good_object_', '_get_good_single_object_',
'_lazydata_'
, '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_',
'_print_details_
', '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_']

I'm pretty green with this kind of introspection (but willing to dig in
and learn). With the VBS code seems like GetFirstTet is a method of
StudyDoc that returns a variable which converted to string yields "TE1"
 etc. But that doesn't seem to be true for python.

Is there any other way I can find out what attributes etc are available
to the GetFirstTet instance?

The type library is not supplied with the app. so if my basic
understanding is correct, I can't early bind.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32com problem - Problem Solved

2006-10-25 Thread cfriedalek
Problem solved.

Turns out it was a problem of mistranslating VBS code to Python.

The PYTHON line "print str(tet)" casts tet to a string and prints. This
is what I thought the VBS line "Str = Tet.ConvertToString()" was doing.
But of course "ConvertToString()" is a method of a Tet instance. So in
python the correct line should have been "print tet.ConvertToString".

Learning all the time.

-- 
http://mail.python.org/mailman/listinfo/python-list


How does python handle VBS "Nothing" keyword

2006-12-14 Thread cfriedalek
I'm writing a python script using win32com to call a 3rd party program
via its VBS based API.

In VBS a query to get some plot data goes like this:

Plot.QueryBegin datacode, Nothing

What is this in python?

Plot.QueryBegin(datacode, None) does not work. I get a type mismatch
error as follows:

com_error: (-2147352571, 'Type mismatch.', None, 2)

I've tried "", False, 0 as alternative to None but these don't work
either. So what is mapped to "Nothing"?

tia

-- 
http://mail.python.org/mailman/listinfo/python-list


tricky(?) win32com question - Mark Hammond or other experts please.

2006-12-19 Thread cfriedalek
OK, I've asked this earlier this week with no response. Since then I've
also received a suggestion from the app developers but that failed with
the same type error problem. Hopefully Mark Hammond or other experts
can offer a suggestion as to how to get around this problem. I'm
foolish enough to think that a solution can be found. Or can someone
suggest how to pm Mark.

---

I'm using pywin32com to drive a 3rd party app. The app has a VBS based
API.  In VBS a specific query for data goes like this:

Plot.QueryBegin datacode, Nothing

where datacode is a number and Nothing is a VBS type/keyword

The nominal python equivalent doesn't work. Plot.QueryBegin(datacode,
None) gives a type mismatch error as follows: com_error: (-2147352571,
'Type mismatch.', None, 2)

>From what I've been able to discover Nothing is not a null, 0, False,
""

Table 12.2 of
http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html does not
mention Nothing in its list of Variant types.

Please, any clues about how to handle this (apart from running the
query in VBS). I so much more prefer python.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: matplotlib basic question

2007-04-19 Thread cfriedalek

> So, first off, what's up with the [ at 0x017C38C8>] line that shows up after my plot command?  And second,
> when I call show(), a new figure pops up with my sin wave -- seems all
> right, yes? But I'm not given another >>> prompt in IDLE until or
> unless I close the figure that popped up with the show() call.
This may not be strictly correct but  thats a reference to the plot
instance which is subsequently passed to show().
If you don't want to see it put a semicolon at the end of your command
eg. plot(range(5));

The issue with IDLE is to due with lack of connection between the
python interpreter event loop and the event loop of matplotlib (I
think). For me the solution was to install the ipython shell (http://
ipython.scipy.org/moin/). If you run ipython with the -pylab flag then
you can matplotlib interactively. For example

plot(range(5),'bo')
show()
clf()
plot([1,2,3,4,5],range(0,10,2),'r-')
(no need for another show() command since the graphics display is
already visible ... unless of course I deleted it in between plot
commands)

hth


-- 
http://mail.python.org/mailman/listinfo/python-list


class __getitem__ when item is not a sequence ???

2007-04-19 Thread cfriedalek
Sorry for the vague subject. Not sure what the right terminology is.

How can I use an instance's data by reference to the instance name,
not the instance attribute? OK the question is probably really poor
but hopefully an example will make it clear.

> x=1
> type(x)

> x.__add__(1)
2
> print x
1
> 3*x
3

In this case x is an integer. My understanding is that x in an
instance of an integer class. Since it refers to only a single value
things like print x, 3*x etc operate on the instance name which seems
to refer to the instance data, not the instance itself. I want to do
the same for my own classes.

For example:
> class y:
 def __init__(self,val):
 self.val = val
> y1 = y(10)
> print y1
<__main__.y instance at 0x043C7B20>
> 3*y1
: unsupported operand type(s) for *:
'int' and 'instance

I have been able to do this by overriding __getitem__ when self.val is
a sequence. But I can't find out what to do when self.val is a simple
type like int, float etc.

-- 
http://mail.python.org/mailman/listinfo/python-list


win32com Excel bug?

2006-04-18 Thread cfriedalek
I'm driving Excel from python, largely successfully. Now I'm trying to
add errorbars to XY scatter plots. Keep getting a com_error. Can't
track down the problem.

I modified a simple example to duplicate the problem. Thanks to Mathieu
Fenniak http://www.stompstompstomp.com/weblog/entries/67/ for the code.

The traceback is shown below. You can see that the Excel chart series
has a method called ErrorBar. But when I try to use it with any or all
of its allowed arguments, it fails. The traceback goes into the guts of
win32com but I don't really have a clue at that point. (Happy to learn
something new though).

The relevant Excel VBA language doc is here.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaxl11/html/xlmthErrorBar1_HV03076818.asp

Hope someone can help. Losing hair  fast!



In [16]: %run test.py
--Return--
> c:\python23\lib\pdb.py(992)set_trace()->None
-> Pdb().set_trace()
(Pdb) c
There's a method waiting
---
pywintypes.com_error Traceback (most
recent call
 last)

c:\temp\mpival\test.py
 79
 80 # A simple example:
---> 81 plot( (1,2,3,4,5), (6,7,8,9,10) )
 82
 83 # Some more data:

c:\temp\mpival\test.py in plot(x, y, xAxisLog, yAxisLog)
 35 if series.ErrorBar:
 36 print "There's a method waiting"
---> 37 series.ErrorBar(Direction = constants.xlY)
 38
 39

C:\Python23\lib\site-packages\win32com\gen_py\00020813---C000-00
46x0x1x4.py in ErrorBar(self, Direction, Include, Type, Amount,
MinusValues)
  22722 , MinusValues=defaultNamedOptArg):
  22723 return self._ApplyTypes_(152, 1, (12, 0), ((3,
1), (3, 1
), (3, 1), (12, 17), (12, 17)), 'ErrorBar', None,Direction
> 22724 , Include, Type, Amount, MinusValues)
  22725
  22726 def Paste(self):

C:\Python23\lib\site-packages\win32com\client\__init__.py in
_ApplyTypes_(self,
dispid, wFlags, retType, argTypes, user, resultCLSID, *args)
444 def _ApplyTypes_(self, dispid, wFlags, retType,
argTypes, user,
445  resultCLSID, *args):
--> 446 return self._get_good_object_(
447 self._oleobj_.InvokeTypes(
448   dispid, 0, wFlags, retType,
argTypes, *arg
s),

com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel',
'ErrorBar
 method of Series class failed', 'C:\\Program Files (x86)\\Microsoft
Office\\Off
ice10\\1033\\xlmain10.chm', 0, -2146827284), None)
WARNING: Failure executing file: 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: win32com Excel bug?

2006-04-19 Thread cfriedalek
yth (Yes That Helped).

You know how it goes, I thought I'd already tried to include all
arguments. Obviously I didn't, or stuffed it up in some other way.
Also some confusion about the meaning of "required" and "default". The
doc explains these arguments as required, but some have defaults. I
guess I thought if they had defaults then they didn't need to be
specified.

Anyway, problem solved. Thanks again.

-- 
http://mail.python.org/mailman/listinfo/python-list