diff options
author | teh_coderer <me@tehcoderer.com> | 2023-06-07 18:01:08 -0400 |
---|---|---|
committer | teh_coderer <me@tehcoderer.com> | 2023-06-07 18:01:08 -0400 |
commit | 828f0f8e697104002b98ae46d75aba19a1f660f5 (patch) | |
tree | 412af3ac33d2f8f385ac0d5424219c1722d3bf13 | |
parent | 316e83dc003f613c51a6ba2c8fedfc3e480a0236 (diff) |
for @DidierRLopes mickey mouse
-rw-r--r-- | openbb_terminal/core/plots/backend.py | 52 | ||||
-rw-r--r-- | params.py | 11 | ||||
-rw-r--r-- | test.html | 37 |
3 files changed, 100 insertions, 0 deletions
diff --git a/openbb_terminal/core/plots/backend.py b/openbb_terminal/core/plots/backend.py index 1d05b006c1b..0e8468ee589 100644 --- a/openbb_terminal/core/plots/backend.py +++ b/openbb_terminal/core/plots/backend.py @@ -387,6 +387,58 @@ class Backend(PyWry): super().close() + async def get_results(self, description: str) -> dict: + """Wait for completion of interactive task and return the data. + + Parameters + ---------- + description : str + Description of the task to console print while waiting. + + Returns + ------- + dict + The data returned from pywry backend. + """ + console.print( + f"[green]{description}[/]\n\n" + "[yellow]If the window is closed you can continue by pressing Ctrl+C.[/]" + ) + while True: + try: + data: dict = self.recv.get(block=False) or {} + if data.get("result", False): + return json.loads(data["result"]) + except Exception: # pylint: disable=W0703 + pass + + await asyncio.sleep(1) + + def call_routine(self, title, params_list: list, path: Path) -> Optional[dict]: + self.loop.run_until_complete(self.check_backend()) + + outgoing = dict( + html=path.resolve(), + json_data=json.dumps({"params": params_list}), + **self.get_kwargs(title), + width=900, + height=800, + ) + self.send_outgoing(outgoing) + + messages_dict = dict( + message="Choose your args SHILL", + interrupt="Perfect phone call", + ) + + try: + return self.loop.run_until_complete( + self.get_results(messages_dict["message"]) + ) + except KeyboardInterrupt: + console.print(f"\n[red]{messages_dict['interrupt']}[/red]") + return None + async def download_plotly_js(): """Download or updates plotly.js to the assets folder.""" diff --git a/params.py b/params.py new file mode 100644 index 00000000000..c3861749b4f --- /dev/null +++ b/params.py @@ -0,0 +1,11 @@ +from pathlib import Path + +from openbb_terminal.core.plots.backend import plots_backend + +plots_backend().start(True) +args = plots_backend().call_routine( + "test", ["this", "cucumbers", "that"], Path(__file__).parent / "test.html" +) + +for key, value in args.items(): + print(key, value) diff --git a/test.html b/test.html new file mode 100644 index 00000000000..4fd4b7cecf4 --- /dev/null +++ b/test.html @@ -0,0 +1,37 @@ +<html> +<body> + <br> + <br> + <br> + <br> + <br> + <br> + <div id="sexy_time"></div> + + <script> + function sendData() { + let data = {}; + let inputs = document.getElementById('sexy_time').getElementsByTagName('input'); + for (let i = 0; i < inputs.length; i++) { + data[inputs[i].name] = inputs[i].value; + } + window.pywry.result(JSON.stringify(data)); + } + if (window.json_data) { + let json_data = window.json_data; + if (typeof json_data === 'string') { + json_data = JSON.parse(json_data); + } + console.log(json_data); + let sexy_time = document.getElementById('sexy_time').innerHTML; + json_data.params.forEach((parm) => { + sexy_time += `<label for="${parm}">${parm}</label>`; + sexy_time += `<input type"text" name="${parm}"></input>`; + }); + + sexy_time += `<button onclick="sendData()">Submit</button>`; + document.getElementById('sexy_time').innerHTML = sexy_time; + } + </script> +</body> +</html> |