By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

How do I get type methods?

P: n/a
Hello!

If I do

import uno
localContext=uno.getComponentContext()

then localContext is of type <type 'pyuno'>
I guess it's a new type provided by PyUNO extension.
localContext.__class__ is None
Is there any way to list all methods of that new type, via Python C
API or through interpreter (other then dir(localContext) )?
What I want is to call localContext's methods like in the tutorial
example:

x=MyClass()
MyClass.f(x)

Thank you,
Dmitri

May 3 '07 #1
Share this Question
Share on Google+
11 Replies


P: n/a
ya********@yahoo.com schrieb:
Hello!

If I do

import uno
localContext=uno.getComponentContext()

then localContext is of type <type 'pyuno'>
I guess it's a new type provided by PyUNO extension.
localContext.__class__ is None
Is there any way to list all methods of that new type, via Python C
API or through interpreter (other then dir(localContext) )?
What's wrong about `dir()`?
What I want is to call localContext's methods like in the tutorial
example:

x=MyClass()
MyClass.f(x)
I'd prefer::

x = MyClass()
x.f()
>
Thank you,
Dmitri
May 3 '07 #2

P: n/a
On May 4, 3:21 am, Stargaming <stargam...@gmail.comwrote:
What's wrong about `dir()`?
x = MyClass()
x.f()
I want to cashe pointers to Python functions in a non-Python app.
'dir()' requires an argument, and I want to get function pointers
before I have any variable of given type or class.
That's why 'MyClass.f(x)'
I'm not against 'dir(MyClass)'; the question is, what should I 'dir()'
to get methods of 'pyuno' type instance?

Sincerely yours,
Dmitri

May 4 '07 #3

P: n/a
En Fri, 04 May 2007 01:34:20 -0300, <ya********@yahoo.comescribiˇ:
I'm not against 'dir(MyClass)'; the question is, what should I 'dir()'
to get methods of 'pyuno' type instance?
Usually instances don't have its own methods, they get them from the
class. So you actually need dir(MyClass).
Note that dir() might not show all available methods.

--
Gabriel Genellina
May 4 '07 #4

P: n/a
On 4 ═┴╩, 09:08, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Fri, 04 May 2007 01:34:20 -0300, <yavanna...@yahoo.comescribio:
I'm not against 'dir(MyClass)'; the question is, what should I 'dir()'
to get methods of 'pyuno' type instance?
Usually instances don't have its own methods, they get them from the
class. So you actually need dir(MyClass).
Note that dir() might not show all available methods.
Let me retype my question: what I 'dir()' in case of 'pyuno' type
instance?
Or in case of 'dict' type instance? Or in case of any other new python
type?

May 4 '07 #5

P: n/a
On May 4, 7:59 am, yavanna...@yahoo.com wrote:
On 4 ═┴╩, 09:08, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Fri, 04 May 2007 01:34:20 -0300, <yavanna...@yahoo.comescribio:
I'm not against 'dir(MyClass)'; the question is, what should I 'dir()'
to get methods of 'pyuno' type instance?
Usually instances don't have its own methods, they get them from the
class. So you actually need dir(MyClass).
Note that dir() might not show all available methods.

Let me retype my question: what I 'dir()' in case of 'pyuno' type
instance?
Or in case of 'dict' type instance? Or in case of any other new python
type?
>>class Foo:
.... def f(self,x):
.... print x+1
.... def g(self,x):
.... print x-1
....
>>dir(Foo)
['__doc__', '__module__', 'f', 'g']

Is this not what you want? These are the only methods in the Foo
class.

Tom

May 4 '07 #6

P: n/a
In <11**********************@c35g2000hsg.googlegroups .com>, Thomas Nelson
wrote:
On May 4, 7:59 am, yavanna...@yahoo.com wrote:
>Let me retype my question: what I 'dir()' in case of 'pyuno' type
instance?
Or in case of 'dict' type instance? Or in case of any other new python
type?
>>>class Foo:
... def f(self,x):
... print x+1
... def g(self,x):
... print x-1
...
>>>dir(Foo)
['__doc__', '__module__', 'f', 'g']

Is this not what you want? These are the only methods in the Foo
class.
The OPs problem is, there is no access to the class or type because
there is no name. You can get just instances from a factory function.

Ciao,
Marc 'BlackJack' Rintsch
May 4 '07 #7

P: n/a
On May 3, 8:33 pm, yavanna...@yahoo.com wrote:
Hello!

If I do

import uno
localContext=uno.getComponentContext()
dir(type(localContext))

Perhaps ?

Fuzzyman
http://www.voidspace.org.uk/ironpython/index.shtml

then localContext is of type <type 'pyuno'>
I guess it's a new type provided by PyUNO extension.
localContext.__class__ is None
Is there any way to list all methods of that new type, via Python C
API or through interpreter (other then dir(localContext) )?
What I want is to call localContext's methods like in the tutorial
example:

x=MyClass()
MyClass.f(x)

Thank you,
Dmitri

May 4 '07 #8

P: n/a
On May 5, 1:17 am, Fuzzyman <fuzzy...@gmail.comwrote:
dir(type(localContext))
Perhaps ?
It gives
['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute__',
'__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__']

while

import sys
dir(type(sys.modules))

gives
['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__',
'__doc__', '__eq__', '__ge__', '__getattribute__', '__getitem__',
'__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__',
'__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__setitem__', '__str__', 'clear', 'copy',
'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys',
'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update',
'values']

so I guess PyUNO extension doesn't provide proper introspection :-(

May 5 '07 #9

P: n/a
On May 4, 7:13 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
The OPs problem is, there is no access to the class or type because
there is no name.
Exactly :-(
You can get just instances from a factory function.
Worse, if I call

localContext.ServiceManage

I'll get something with different set of methods, but of the same type
- 'pyuno' :-(

May 5 '07 #10

P: n/a
On Sat, 2007-05-05 at 01:19 -0700, ya********@yahoo.com wrote:
On May 4, 7:13 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
The OPs problem is, there is no access to the class or type because
there is no name.

Exactly :-(
You can get just instances from a factory function.

Worse, if I call

localContext.ServiceManage

I'll get something with different set of methods, but of the same type
- 'pyuno' :-(
'pyuno' objects are proxy objects that represent UNO objects, services,
and interfaces. Since all attribute lookups are handled by the UNO
bridge, the proxy object doesn't actually know what attributes it has,
which is why it won't respond anything useful to the usual dir()
inspection.

To list the methods and properties that the UNO object behind a pyuno
proxy object has, you need to use UNO inspection capabilities. Something
like the following seems to work:

# unodir.py
def unodir(unoobj):
import uno
from com.sun.star.beans.MethodConcept import ALL as ALLMETHS
from com.sun.star.beans.PropertyConcept import ALL as ALLPROPS
ctx = uno.getComponentContext()
introspection = ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.beans.Introspection", ctx)
access = introspection.inspect(unoobj)
meths = access.getMethods(ALLMETHS)
props = access.getProperties(ALLPROPS)
return [ x.getName() for x in meths ] + [ x.Name for x in props ]
>>import uno
from unodir import unodir
localContext = uno.getComponentContext()
unodir(localContext)
[u'queryInterface', u'acquire', u'release', u'getValueByName',
u'getServiceManager', u'getElementType', u'hasElements', u'getByName',
u'getElementNames', u'hasByName', u'replaceByName', u'insertByName',
u'removeByName', u'getTypes', u'getImplementationId', u'queryAdapter',
u'dispose', u'addEventListener', u'removeEventListener',
u'ServiceManager', u'ElementType', u'ElementNames', u'Types',
u'ImplementationId']

Hope this helps,

Carsten
May 5 '07 #11

P: n/a
On May 5, 5:21 pm, Carsten Haese <cars...@uniqsys.comwrote:
'pyuno' objects are proxy objects that represent UNO objects, services,
and interfaces. Since all attribute lookups are handled by the UNO
bridge, the proxy object doesn't actually know what attributes it has,
which is why it won't respond anything useful to the usual dir()
inspection.
I suspected something like that, but couldn't quite believe as CORBA
proxies generated by C++/C/Java/Lisp/Python IDL compiler are normal
classes which know what methods they have...
To list the methods and properties that the UNO object behind a pyuno
proxy object has, you need to use UNO inspection capabilities. Something
like the following seems to work:
Thanks a lot! After reading your example I googled and found
unohelper.inspect, which provides all information. But I still need
instances, as 'dir(XSingleComponentFactory)' gives just ['__doc__',
'__module__', '__pyunointerface__'], and
'unohelper.inspect(XSingleComponentFactory, sys.stdout)' gives
segmentation fault.

Sincerely yours,
Dmitri

May 6 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.