-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setup_show_ext() function (#1024)
- Loading branch information
Showing
5 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
python-package/lets_plot/frontend_context/_webbr_html_page_ctx.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# Copyright (c) 2019. JetBrains s.r.o. | ||
# Use of this source code is governed by the MIT license that can be found in the LICENSE file. | ||
# | ||
import io | ||
import webbrowser | ||
import tempfile | ||
from typing import Dict | ||
|
||
from ._frontend_ctx import FrontendContext | ||
from .. import _kbridge as kbr | ||
|
||
|
||
class WebBrHtmlPageContext(FrontendContext): | ||
|
||
def __init__(self, exec: str, new: bool) -> None: | ||
super().__init__() | ||
self.exec = exec | ||
self.new = new | ||
|
||
def show(self, plot_spec: Dict) -> str: | ||
html_page = kbr._generate_static_html_page(plot_spec, iframe=False) | ||
|
||
path = tempfile.NamedTemporaryFile(suffix=".html", delete=False).name | ||
io.open(path, 'w').write(html_page) | ||
|
||
webbrowser.get(self.exec).open('file:https://' + path, new=1 if self.new else 2) |