Skip to content

Commit

Permalink
implement dynamic form
Browse files Browse the repository at this point in the history
  • Loading branch information
Leemoonsoo committed Mar 19, 2017
1 parent 00e6aed commit a405a93
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,10 @@ public InterpreterResult interpret(String cmd, InterpreterContext contextInterpr
}
}

public InterpreterContext getCurrentInterpreterContext() {
return context;
}

public void interrupt() throws IOException {
if (pythonPid > -1) {
logger.info("Sending SIGINT signal to PID : " + pythonPid);
Expand Down
35 changes: 26 additions & 9 deletions python/src/main/resources/python/zeppelin_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,41 @@ def flush(self):


class PyZeppelinContext(object):
""" If py4j is detected, these class will be override
with the implementation in bootstrap_input.py
""" A context impl that uses Py4j to communicate to JVM
"""
errorMsg = "You must install py4j Python module " \
"(pip install py4j) to use Zeppelin dynamic forms features"

def __init__(self):
def __init__(self, z):
self.z = z
self.paramOption = gateway.jvm.org.apache.zeppelin.display.Input.ParamOption
self.javaList = gateway.jvm.java.util.ArrayList
self.max_result = 1000
self._displayhook = lambda *args: None
self._setup_matplotlib()

def getInterpreterContext(self):
return self.z.getCurrentInterpreterContext()

def input(self, name, defaultValue=""):
print(self.errorMsg)
return self.z.getGui().input(name, defaultValue)

def select(self, name, options, defaultValue=""):
print(self.errorMsg)
javaOptions = gateway.new_array(self.paramOption, len(options))
i = 0
for tuple in options:
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
i += 1
return self.z.getGui().select(name, defaultValue, javaOptions)

def checkbox(self, name, options, defaultChecked=[]):
print(self.errorMsg)
javaOptions = gateway.new_array(self.paramOption, len(options))
i = 0
for tuple in options:
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
i += 1
javaDefaultCheck = self.javaList()
for check in defaultChecked:
javaDefaultCheck.append(check)
return self.z.getGui().checkbox(name, javaDefaultCheck, javaOptions)

def show(self, p, **kwargs):
if hasattr(p, '__name__') and p.__name__ == "matplotlib.pyplot":
Expand Down Expand Up @@ -187,7 +203,8 @@ def handler_stop_signals(sig, frame):
intp = gateway.entry_point
intp.onPythonScriptInitialized(os.getpid())

z = PyZeppelinContext()
java_import(gateway.jvm, "org.apache.zeppelin.display.Input")
z = PyZeppelinContext(intp)
z._setup_matplotlib()

output = Logger()
Expand Down

0 comments on commit a405a93

Please sign in to comment.