Hello all, I built libreoffice with python3.3 today in order to adapt python code to this version and I realized python3.3 has a different behaviour interacting with UNO components than python2.7 does. Just to check it I created a simple script:
import unohelper def test(): localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", localContext ) ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) smgr = ctx.ServiceManager desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx) print(dir(desktop)) desktop.addTerminateListener(TerminateListenerProcAdapter(test)) model = desktop.getCurrentComponent() text = model.Text cursor = text.createTextCursor() text.insertString( cursor, "Hello World", 0 ) ctx.ServiceManager from com.sun.star.frame import XTerminateListener class TerminateListenerProcAdapter(unohelper.Base, XTerminateListener): def __init__( self, oProcToCall): self.oProcToCall = oProcToCall if __name__ == "__main__": test() in python2.7 it works perfecty but in python3.3 it throws 2 exceptions. print(dir(desktop)): Traceback (most recent call last): File "test.py", line 25, in <module> test() File "test.py", line 11, in test print(dir(desktop)) TypeError: object does not provide __dir__ Error in sys.excepthook: Traceback (most recent call last): File "/home/xisco/libo/install/program/uno.py", line 286, in _uno_import d[x] = pyuno.getClass( name + "." + x ) uno.RuntimeException: pyuno.getClass: uno exception apport.fileutils.likely_packaged is unknown During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/xisco/libo/install/program/uno.py", line 290, in _uno_import d[x] = Enum( name , x ) File "/home/xisco/libo/install/program/uno.py", line 123, in __init__ pyuno.checkEnum( self ) uno.RuntimeException: attributes typeName and/or value of uno.Enum are not strings During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/xisco/libo/install/program/uno.py", line 294, in _uno_import d[x] = getConstantByName( name + "." + x ) File "/home/xisco/libo/install/program/uno.py", line 48, in getConstantByName return pyuno.getConstantByName( constant ) uno.RuntimeException: apport.fileutils.likely_packaged During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 64, in apport_excepthook from apport.fileutils import likely_packaged, get_recent_crashes File "/home/xisco/libo/install/program/uno.py", line 297, in _uno_import raise ImportError( "type "+ name + "." +x + " is unknown" ) ImportError: type apport.fileutils.likely_packaged is unknown Original exception was: Traceback (most recent call last): File "test.py", line 25, in <module> test() File "test.py", line 11, in test print(dir(desktop)) TypeError: object does not provide __dir__ and desktop.addTerminateListener(TerminateListenerProcAdapter(test)) ( comenting previous line): Traceback (most recent call last): File "test.py", line 25, in <module> test() File "test.py", line 12, in test desktop.addTerminateListener(TerminateListenerProcAdapter(test)) uno.RuntimeException: Couldn't convert <__main__.TerminateListenerProcAdapter object at 0xb70cb9ec> to a UNO type; caught exception: attributes typeName and/or value of uno.Enum are not strings Error in sys.excepthook: Traceback (most recent call last): File "/home/xisco/libo/install/program/uno.py", line 286, in _uno_import d[x] = pyuno.getClass( name + "." + x ) uno.RuntimeException: pyuno.getClass: uno exception apport.fileutils.likely_packaged is unknown During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/xisco/libo/install/program/uno.py", line 290, in _uno_import d[x] = Enum( name , x ) File "/home/xisco/libo/install/program/uno.py", line 123, in __init__ pyuno.checkEnum( self ) uno.RuntimeException: attributes typeName and/or value of uno.Enum are not strings During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/xisco/libo/install/program/uno.py", line 294, in _uno_import d[x] = getConstantByName( name + "." + x ) File "/home/xisco/libo/install/program/uno.py", line 48, in getConstantByName return pyuno.getConstantByName( constant ) uno.RuntimeException: apport.fileutils.likely_packaged During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 64, in apport_excepthook from apport.fileutils import likely_packaged, get_recent_crashes File "/home/xisco/libo/install/program/uno.py", line 297, in _uno_import raise ImportError( "type "+ name + "." +x + " is unknown" ) ImportError: type apport.fileutils.likely_packaged is unknown Original exception was: Traceback (most recent call last): File "test.py", line 25, in <module> test() File "test.py", line 12, in test desktop.addTerminateListener(TerminateListenerProcAdapter(test)) uno.RuntimeException: Couldn't convert <__main__.TerminateListenerProcAdapter object at 0xb70cb9ec> to a UNO type; caught exception: attributes typeName and/or value of uno.Enum are not strings any idea ? Regards, Xisco Faulí
_______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice