If your Jep interpreter is on a different thread then you will need to write the logic to push the button in Java and then you can call the Java code from Python and the Java will be able to execute on the main thread.
package com.myAddons.myRunnableExecution;
import com.raytheon.viz.gfe.core.DataManager;
public class myRunnableExecution implements Runnable {
public void run() {
DataManager.getCurrentInstance().getGridManager().toggleTemporalEditor();
}}
import SmartScriptfrom java.lang import ClassLoader, Classfrom java.lang.reflect import Arrayfrom java.io import Filefrom java.net import URLClassLoader, URLfrom org.eclipse.swt.widgets import Display
cl = ClassLoader.getSystemClassLoader()jarFile = File("/localapps/runtime/myJava/myRunnableExecution.jar") uriCL = jarFile.toURI().toURL() urlCls = Class.forName("java.net.URL")urlArr = Array.newInstance(urlCls,1)Array.set(urlArr, 0, uriCL)myCL = URLClassLoader(urlArr,cl)from com.myAddons import myRunnableExecution
class Procedure (SmartScript.SmartScript): def __init__(self, dbss): SmartScript.SmartScript.__init__(self, dbss) def execute(self, editArea, timeRange, varDict): Display.getDefault().asyncExec(myRunnableExecution.run())
!ENTRY com.raytheon.viz.gfe 2 0 2019-12-22 00:23:45.994!MESSAGE Error in procedure ToggleTestPostingVersionNEW!STACK 0jep.JepException: <type 'exceptions.ImportError'>: com.myAddons.myRunnableExecution.run cannot be found by com.raytheon.viz.gfe_1.17.0.2019111211 at /awips2/python/lib/python2.7/site-packages/jep/java_import_hook.__getattr__(java_import_hook.py:32) at /home/donal.harrigan/caveData/etc/user/donal.harrigan/gfe/userPython/procedures/ToggleTestPostingVersionNEW.execute(ToggleTestPostingVersionNEW.py:35) at /home/donal.harrigan/caveData/common/base/python/MasterInterface.runMethod(MasterInterface.py:141) at /awips2/cave/etc/gfe/userPython/utilities/ProcedureInterface.runProcedure(ProcedureInterface.py:111) at jep.Jep.eval(Native Method) at jep.Jep.eval(Jep.java:609) at com.raytheon.uf.common.python.PythonScript.internalExecute(PythonScript.java:285) at com.raytheon.viz.gfe.procedures.ProcedureController.executeProcedure(ProcedureController.java:155) at com.raytheon.viz.gfe.procedures.ProcedureJobPool$ProcedureJob.execute(ProcedureJobPool.java:381) at com.raytheon.viz.gfe.procedures.ProcedureJobPool$ProcedureJob.processRequest(ProcedureJobPool.java:345) at com.raytheon.viz.gfe.procedures.ProcedureJobPool$ProcedureJob.run(ProcedureJobPool.java:324) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)Caused by: java.lang.ClassNotFoundException: com.myAddons.myRunnableExecution.run cannot be found by com.raytheon.viz.gfe_1.17.0.2019111211 at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364) at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 8 more
from com.myAddons import myRunnableExecution
myRunnableExecution =
myCL.loadClass("com.myAddons.myRunnableExecution")
myRunnableExecution =
Class.forName("
com.myAddons.myRunnableExecution
", True, myCL);
Display.getDefault().asyncExec(myRunnableExecution.run())
Display.getDefault().asyncExec(myRunnableExecution())
from org.eclipse.ui import PlatformUIfrom com.raytheon.viz.gfe.core import DataManager
jarFile = File("/localapps/runtime/myJava/myRunnableExecution.jar") uriCL = jarFile.toURI().toURL()
cl = ClassLoader.getSystemClassLoader()
urlCls = Class.forName("java.net.URL")urlArr = Array.newInstance(urlCls,1)Array.set(urlArr, 0, uriCL)myCL = URLClassLoader(urlArr,cl)
myRunnableExecution = Class.forName("com.myAddons.myRunnableExecution.myRunnableExecution", True, myCL)
class Procedure (SmartScript.SmartScript): def __init__(self, dbss): SmartScript.SmartScript.__init__(self, dbss) def execute(self, editArea, timeRange, varDict):
wbws = PlatformUI.getWorkbench().getWorkbenchWindows() for wbWindow in wbws: dm = DataManager.getInstance(wbWindow) print dm Display.getDefault().asyncExec(myRunnableExecution())
com.raytheon.viz.gfe.core.DataManager
package com.myAddons.myRunnableExecution;
import org.eclipse.ui.PlatformUI;import org.eclipse.ui.IWorkbenchWindow;
import com.raytheon.viz.gfe.core.DataManager;
public class myRunnableExecution implements Runnable {
public void run() {
System.out.print("2"); int i; DataManager dm; IWorkbenchWindow wbwArr[] = PlatformUI.getWorkbench().getWorkbenchWindows(); System.out.print(wbwArr); for (i=0; i < wbwArr.length; i++) { dm = DataManager.getInstance(wbwArr[i]); System.out.print(dm); } }}
Unhandled event loop exceptionorg.eclipse.swt.SWTException: Failed to execute runnable (java.lang.IllegalStateException: Workbench has not been created yet.) at org.eclipse.swt.SWT.error(SWT.java:4533) at org.eclipse.swt.SWT.error(SWT.java:4448) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:185) at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4528) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4146) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150) at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:687) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:604) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148) at com.raytheon.uf.viz.personalities.cave.component.CAVEApplication.startComponent(CAVEApplication.java:173) at com.raytheon.uf.viz.application.VizApplication.start(VizApplication.java:102) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610) at org.eclipse.equinox.launcher.Main.run(Main.java:1519) at org.eclipse.equinox.launcher.Main.main(Main.java:1492)Caused by: java.lang.IllegalStateException: Workbench has not been created yet. at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:93) at com.myAddons.myRunnableExecution.myRunnableExecution.run(myRunnableExecution.java:18) at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:182) ... 25 more
Manifest-Version: 1.0Class-Path: /awips2/cave/plugins/com.raytheon.viz.gfe_1.17.0.201911121 1/com.raytheon.viz.gfe.jar /awips2/edex/lib/plugins/com.raytheon.uf.c ommon.time.jar /awips2/cave/plugins/com.raytheon.uf.common.time_1.16. 0.2019111211/ /awips2/cave/plugins/com.raytheon.viz.ui_1.16.0.2019111 211/com.raytheon.viz.ui.jar /awips2/cave/plugins/com.raytheon.uf.comm on.jms_1.18.0.2019111211.jar /awips2/cave/plugins/com.raytheon.uf.com mon.status_1.17.0.2019111211.jar /awips2/cave/plugins/com.raytheon.uf .viz.core_1.16.1.2019111211/com.raytheon.uf.viz.core.jar /awips2/cave /plugins/org.eclipse.ui_3.108.0.v20160518-1929.jar /awips2/cave/plugi ns/org.eclipse.ui.workbench_3.108.1.v20160819-2118.jar /awips2/cave/p lugins/org.eclipse.jface_3.12.0.v20160518-1929.jar /awips2/cave/plugi ns/org.eclipse.e4.ui.workbench3_0.13.100.v20160506-0759.jar /awips2/c ave/plugins/org.eclipse.core.runtime_3.12.0.v20160606-1342.jar /awips 2/cave/plugins/org.eclipse.equinox.common_3.8.0.v20160509-1230.jar /a wips2/cave/plugins/org.eclipse.ui.navigator.resources_3.5.100.v201605 18-1929.jar /awips2/cave/plugins/org.eclipse.e4.ui.workbench_1.4.0.v2 0160517-1624.jar /awips2/cave/plugins/org.eclipse.core.commands_3.8.0 .v20160316-1921.jar /awips2/cave/plugins/org.eclipse.e4.core.di_1.6.1 .v20160712-0927.jar /awips2/cave/plugins/org.eclipse.e4.ui.model.work bench_1.2.0.v20160229-1459.jar /awips2/cave/plugins/org.eclipse.swt_3 .105.1.v20160907-0248.jar /awips2/cave/plugins/org.eclipse.swt.gtk.li nux.x86_64_3.105.1.v20160907-0248.jar /awips2/cave/plugins/org.eclips e.osgi_3.11.1.v20160708-1632.jar /awips2/cave/plugins/org.eclipse.osg i.services_3.5.100.v20160504-1419.jar /awips2/cave/plugins/org.eclips e.core.jobs_3.8.0.v20160509-0411.jar /awips2/cave/plugins/org.eclipse .equinox.registry_3.6.100.v20160223-2218.jar Created-By: 1.8.0_144 (Oracle Corporation)Main-Class: com.myAddons.myRunnableExecution.myRunnableExecution
Display.getDefault().asyncExec(myRunnableExecution(dm))
package com.myAddons.myRunnableExecution;
import com.raytheon.viz.gfe.core.DataManager;
public class myRunnableExecution implements Runnable {
DataManager dataManager; public myRunnableExecution(DataManager dataManager) { System.out.print(dataManager); this.dataManager = dataManager; }
public void run() { System.out.print("here"); System.out.print(this.dataManager); }}
!ENTRY com.raytheon.viz.gfe 2 0 2019-12-28 07:15:51.669
!MESSAGE Error in procedure ToggleTestPostingVersionNEW!STACK 0
jep.JepException: <type 'exceptions.TypeError'>: Error converting parameter 1: Expected com.raytheon.viz.gfe.core.DataManager but received a com.raytheon.viz.gfe.core.DataManager. at /home/donal.harrigan/caveData/etc/user/donal.harrigan/gfe/userPython/procedures/ToggleTestPostingVersionNEW.execute(ToggleTestPostingVersionNEW.py:41)
cl = ClassLoader.getSystemClassLoader()
from java.lang import Thread
cl = Thread.currentThread().getContextClassLoader()
import jep
cl = jep.__loader__
from org.eclipse.core.runtime import Platform
from org.osgi.framework.wiring import BundleWiring
cl = Platform.getBundle("com.raytheon.viz.gfe").adapt(BundleWiring).getClassLoader().