*Job [#sc2937da] org.openoffice.Office.Job にある構成で特定のイベント発生時に com.sun.star.task.XJob インターフェースの execute メソッドを呼び出させることができます。 以下のコードは最小構成のタスクです。OnNew イベント (ドキュメントが作成されたとき) に execute メソッドが実行されます。 詳細は以下参照。 -[[Developers Guide Jobs>http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Jobs/Jobs]] **構成 [#w8e28d94] #code(){{ <?xml version="1.0"?> <oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:install="http://openoffice.org/2004/installation" oor:name="Jobs" oor:package="org.openoffice.Office"> <node oor:name="Jobs"> <node oor:name="StartIA" oor:op="replace"> <prop oor:name="Service"> <value>mytools.basicide.IATest</value> </prop> </node> </node> <node oor:name="Events"> <node oor:name="OnNew" oor:op="fuse"> <node oor:name="JobList"> <node oor:name="StartIA" oor:op="replace"/> </node> </node> </node> </oor:component-data> }} **コンポーネント [#f49ae583] #code(python){{ #! # -*- coding: utf_8 -*- #import uno # -*- coding: utf-8 -*- import unohelper # interfaces from com.sun.star.task import XJob from com.sun.star.lang import XServiceInfo ImplName = "mytools.basicide.IATest" ServiceNames = ("com.sun.star.task.Job",) class IATest(unohelper.Base, XJob, XServiceInfo): def __init__(self,ctx): self.ctx = ctx print("initialized") # XJob def execute(self, args): print("job executed.") # XServiceInfo def getImplementationName(self): return ImplName def supportsService(self, name): return name in ServiceNames def getSupportedServiceNames(self): return ServiceNames class IATest( unohelper.Base,XJob): def __init__(self,ctx): self.ctx = ctx self.smgr = ctx.ServiceManager # XJob def execute(self,args): #print "started." if args: isDocumentEvent = False basic_doc = None for arg in args: if not arg.Name == "Environment": continue print "Environment: " env_vals = arg.Value for env_val in env_vals: #print env_val.Name if env_val.Name == "EnvType" and env_val.Value == "DOCUMENTEVENT": print env_val.Name,": ",env_val.Value isDocumentEvent = True elif env_val.Name == "EventName": print env_val.Name,": ",env_val.Value elif env_val.Name == "Model": #doc = env_val.Value if env_val.Value and \ env_val.Value.supportsService("com.sun.star.script.BasicIDE"): basic_doc = env_val.Value if basic_doc and isDocumentEvent: print "basic IDE" controller = basic_doc.getCurrentController() if controller: frame = controller.getFrame() print frame.Title comp_win = frame.getComponentWindow() cont_win = frame.getContainerWindow() print comp_win == None print cont_win == None return g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper.addImplementation( IATest, "mytools.basicide.IATest", ("mytools.basicide.IATest",),) IATest, ImplName, ServiceNames) }} |