Hi all,

I a newbie both in Python and in UNO.
I have done the following code in practicing my new
skill:

import uno

def initDoc(filename):
  unoctx = uno.getComponentContext()
  resolver =
unoctx.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",
unoctx)
  oooctx =
resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
  desktop =
oooctx.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop",
oooctx)
  return desktop.loadComponentFromURL(filename,
"_blank", 0, () )

def replaceStr(document):
  replace = document.createReplaceDescriptor()
  replace.SearchString = "original"
  replace.ReplaceString = "replace"
  document.replaceAll(replace)

#--main--#
filename = "/home/weichong78/test.odt" 
document = initDoc(filename)  
replaceStr(document)
document.store()
document.close(1)

However, when I execute the code, the resulting Writer
open the Text document, replacing the string, show the
progress bar that it saves content and throw the below
exception without actually complete saving them (this
i s verified by the fact that the content of file stay
the same the next time I open them).  I try to read
from the Developer Guide about the XClosable interface
but do not fully understand.  Especially in this case
the document is already provided/opened from existing
file, shouldn't the URL automatically point to it?

Traceback (most recent call last):
  File "ooo-replace.py", line 20, in ?
    document.store()
__main__.com.sun.star.task.ErrorCodeIOException
python: pthread_mutex_lock.c:108:
__pthread_mutex_lock: Assertion `mutex->__data.__owner
== 0' failed.
Aborted

Thanks,
Wei Chong.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to