Kaydet (Commit) 801a501e authored tarafından Oliver Bolte's avatar Oliver Bolte

INTEGRATION: CWS pyunofixes2 (1.4.34); FILE MERGED

2006/01/11 22:14:05 jbu 1.4.34.2: #i54155# ensuring now, that a linefeed is appended to the script when necessary, some additional code cleanup
2006/01/07 20:07:23 jbu 1.4.34.1: #i54157# added a flush in log function (needed on win32)
üst 217271de
...@@ -62,6 +62,7 @@ class Logger(LogLevel): ...@@ -62,6 +62,7 @@ class Logger(LogLevel):
"] " + "] " +
msg + msg +
"\n" ) "\n" )
self.target.flush()
log = Logger( getLogTarget() ) log = Logger( getLogTarget() )
...@@ -119,6 +120,11 @@ def hasChanged( oldDate, newDate ): ...@@ -119,6 +120,11 @@ def hasChanged( oldDate, newDate ):
newDate.Seconds > oldDate.Seconds or \ newDate.Seconds > oldDate.Seconds or \
newDate.HundredthSeconds > oldDate.HundredthSeconds newDate.HundredthSeconds > oldDate.HundredthSeconds
def ensureCodeEndsWithLinefeed( code ):
if not code.endswith( "\n" ):
code = code + "\n"
return code
class ScriptContext(unohelper.Base): class ScriptContext(unohelper.Base):
def __init__( self, ctx, doc ): def __init__( self, ctx, doc ):
self.ctx = ctx self.ctx = ctx
...@@ -140,31 +146,31 @@ class ScriptContext(unohelper.Base): ...@@ -140,31 +146,31 @@ class ScriptContext(unohelper.Base):
# does not fit together with script # does not fit together with script
# engine lifetime management # engine lifetime management
#---------------------------------- #----------------------------------
g_scriptContext = ScriptContext( uno.getComponentContext(), None ) #g_scriptContext = ScriptContext( uno.getComponentContext(), None )
g_modules = {} #g_modules = {}
def getModuleByUrl( url, sfa ): #def getModuleByUrl( url, sfa ):
entry = g_modules.get(url) # entry = g_modules.get(url)
load = True # load = True
lastRead = sfa.getDateTimeModified( url ) # lastRead = sfa.getDateTimeModified( url )
if entry: # if entry:
if hasChanged( entry.lastRead, lastRead ): # if hasChanged( entry.lastRead, lastRead ):
log.isDebugLevel() and log.debug("file " + url + " has changed, reloading") # log.isDebugLevel() and log.debug("file " + url + " has changed, reloading")
else: # else:
load = False # load = False
#
if load: # if load:
log.isDebugLevel() and log.debug( "opening >" + url + "<" ) # log.isDebugLevel() and log.debug( "opening >" + url + "<" )
#
code = readTextFromStream( sfa.openFileRead( url ) ) # code = readTextFromStream( sfa.openFileRead( url ) )
# execute the module # execute the module
entry = ModuleEntry( lastRead, imp.new_module("ooo_script_framework") ) # entry = ModuleEntry( lastRead, imp.new_module("ooo_script_framework") )
entry.module.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = g_scriptContext # entry.module.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = g_scriptContext
entry.module.__file__ = url # entry.module.__file__ = url
exec code in entry.module.__dict__ # exec code in entry.module.__dict__
g_modules[ url ] = entry # g_modules[ url ] = entry
log.isDebugLevel() and log.debug( "mapped " + url + " to " + str( entry.module ) ) # log.isDebugLevel() and log.debug( "mapped " + url + " to " + str( entry.module ) )
return entry.module # return entry.module
class ProviderContext: class ProviderContext:
def __init__( self, storageType, sfa, uriHelper, scriptContext ): def __init__( self, storageType, sfa, uriHelper, scriptContext ):
...@@ -248,6 +254,7 @@ class ProviderContext: ...@@ -248,6 +254,7 @@ class ProviderContext:
log.isDebugLevel() and log.debug( "opening >" + url + "<" ) log.isDebugLevel() and log.debug( "opening >" + url + "<" )
code = readTextFromStream( self.sfa.openFileRead( url ) ) code = readTextFromStream( self.sfa.openFileRead( url ) )
code = ensureCodeEndsWithLinefeed( code )
# execute the module # execute the module
entry = ModuleEntry( lastRead, imp.new_module("ooo_script_framework") ) entry = ModuleEntry( lastRead, imp.new_module("ooo_script_framework") )
...@@ -319,6 +326,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode , XPropertySet, XInvocation, ...@@ -319,6 +326,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode , XPropertySet, XInvocation,
"ScriptBindingLibrary.MacroEditor?location=application") "ScriptBindingLibrary.MacroEditor?location=application")
code = readTextFromStream(self.provCtx.sfa.openFileRead(self.uri)) code = readTextFromStream(self.provCtx.sfa.openFileRead(self.uri))
code = ensureCodeEndsWithLinefeed( code )
self.editor.getControl("EditorTextField").setText(code) self.editor.getControl("EditorTextField").setText(code)
self.editor.getControl("RunButton").setActionCommand("Run") self.editor.getControl("RunButton").setActionCommand("Run")
...@@ -334,6 +342,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode , XPropertySet, XInvocation, ...@@ -334,6 +342,7 @@ class ScriptBrowseNode( unohelper.Base, XBrowseNode , XPropertySet, XInvocation,
try: try:
if event.ActionCommand == "Run": if event.ActionCommand == "Run":
code = self.editor.getControl("EditorTextField").getText() code = self.editor.getControl("EditorTextField").getText()
code = ensureCodeEndsWithLinefeed( code )
mod = imp.new_module("ooo_script_framework") mod = imp.new_module("ooo_script_framework")
mod.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = self.provCtx.scriptContext mod.__dict__[GLOBAL_SCRIPTCONTEXT_NAME] = self.provCtx.scriptContext
exec code in mod.__dict__ exec code in mod.__dict__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment