Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
5de5fd49
Kaydet (Commit)
5de5fd49
authored
May 30, 2012
tarafından
Ariel Constenla-Haile
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
i118478 - Implement getInvocationContext in PyUNO ScriptContext
Original author: Tsutomu Uchino <hanya.runo at gmail.com>
üst
d81d9022
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
5 deletions
+51
-5
pythonscript.py
scripting/source/pyprov/pythonscript.py
+51
-5
No files found.
scripting/source/pyprov/pythonscript.py
Dosyayı görüntüle @
5de5fd49
...
...
@@ -113,9 +113,9 @@ log.debug( "pythonscript loading" )
from
com.sun.star.uno
import
RuntimeException
from
com.sun.star.lang
import
XServiceInfo
from
com.sun.star.io
import
IOException
from
com.sun.star.ucb
import
CommandAbortedException
,
XCommandEnvironment
,
XProgressHandler
from
com.sun.star.ucb
import
CommandAbortedException
,
XCommandEnvironment
,
XProgressHandler
,
Command
from
com.sun.star.task
import
XInteractionHandler
from
com.sun.star.beans
import
XPropertySet
from
com.sun.star.beans
import
XPropertySet
,
Property
from
com.sun.star.container
import
XNameContainer
from
com.sun.star.xml.sax
import
XDocumentHandler
,
InputSource
from
com.sun.star.uno
import
Exception
as
UnoException
...
...
@@ -247,12 +247,15 @@ def checkForPythonPathBesideScript( url ):
class
ScriptContext
(
unohelper
.
Base
):
def
__init__
(
self
,
ctx
,
doc
):
def
__init__
(
self
,
ctx
,
doc
,
inv
):
self
.
ctx
=
ctx
self
.
doc
=
doc
self
.
inv
=
inv
# XScriptContext
def
getDocument
(
self
):
if
self
.
doc
:
return
self
.
doc
return
self
.
getDesktop
()
.
getCurrentComponent
()
def
getDesktop
(
self
):
...
...
@@ -262,6 +265,9 @@ class ScriptContext(unohelper.Base):
def
getComponentContext
(
self
):
return
self
.
ctx
def
getInvocationContext
(
self
):
return
self
.
inv
#----------------------------------
# Global Module Administration
# does not fit together with script
...
...
@@ -726,7 +732,32 @@ class CommandEnvironment(unohelper.Base, XCommandEnvironment):
# log.isDebugLevel() and log.debug( "pythonscript: ModifyListener.modified " + str( event ) )
# def disposing( self, event ):
# log.isDebugLevel() and log.debug( "pythonscript: ModifyListener.disposing " + str( event ) )
def
getModelFromDocUrl
(
ctx
,
url
):
"""Get document model from document url."""
doc
=
None
args
=
(
"Local"
,
"Office"
)
ucb
=
ctx
.
getServiceManager
()
.
createInstanceWithArgumentsAndContext
(
"com.sun.star.ucb.UniversalContentBroker"
,
args
,
ctx
)
identifier
=
ucb
.
createContentIdentifier
(
url
)
content
=
ucb
.
queryContent
(
identifier
)
p
=
Property
()
p
.
Name
=
"DocumentModel"
p
.
Handle
=
-
1
c
=
Command
()
c
.
Handle
=
-
1
c
.
Name
=
"getPropertyValues"
c
.
Argument
=
uno
.
Any
(
"[]com.sun.star.beans.Property"
,
(
p
,))
env
=
CommandEnvironment
()
try
:
ret
=
content
.
execute
(
c
,
0
,
env
)
doc
=
ret
.
getObject
(
1
,
None
)
except
Exception
,
e
:
log
.
isErrorLevel
()
and
log
.
error
(
"getModelFromDocUrl:
%
s"
%
url
)
return
doc
def
mapStorageType2PackageContext
(
storageType
):
ret
=
storageType
if
(
storageType
==
"share:uno_packages"
):
...
...
@@ -853,11 +884,26 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
mystr
=
mystr
+
str
(
i
)
log
.
debug
(
"Entering PythonScriptProvider.ctor"
+
mystr
)
doc
=
None
inv
=
None
storageType
=
""
if
isinstance
(
args
[
0
],
unicode
):
storageType
=
args
[
0
]
if
storageType
.
startswith
(
"vnd.sun.star.tdoc"
):
doc
=
getModelFromDocUrl
(
ctx
,
storageType
)
else
:
storageType
=
args
[
0
]
.
SCRIPTING_DOC_URI
inv
=
args
[
0
]
try
:
doc
=
inv
.
ScriptContainer
content
=
ctx
.
getServiceManager
()
.
createInstanceWithContext
(
"com.sun.star.frame.TransientDocumentsDocumentContentFactory"
,
ctx
)
.
createDocumentContent
(
doc
)
storageType
=
content
.
getIdentifier
()
.
getContentIdentifier
()
except
Exception
,
e
:
text
=
lastException2String
()
log
.
error
(
text
)
isPackage
=
storageType
.
endswith
(
":uno_packages"
)
try
:
...
...
@@ -876,7 +922,7 @@ class PythonScriptProvider( unohelper.Base, XBrowseNode, XScriptProvider, XNameC
raise
RuntimeException
(
"PythonScriptProvider couldn't instantiate "
+
ucbService
,
self
)
self
.
provCtx
=
ProviderContext
(
storageType
,
sfa
,
urlHelper
,
ScriptContext
(
uno
.
getComponentContext
(),
None
)
)
storageType
,
sfa
,
urlHelper
,
ScriptContext
(
uno
.
getComponentContext
(),
doc
,
inv
)
)
if
isPackage
:
mapPackageName2Path
=
getPackageName2PathMap
(
sfa
,
storageType
)
self
.
provCtx
.
setPackageAttributes
(
mapPackageName2Path
,
rootUrl
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment