Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cortex-lab/phy
Browse files Browse the repository at this point in the history
  • Loading branch information
rossant committed Jun 15, 2023
2 parents a03baf5 + 97156c6 commit 10e20ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions phy/cluster/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,10 @@ def _save_gui_state(self, gui):
"""Save the GUI state with the cluster view and similarity view."""
gui.state.update_view_state(self.cluster_view, self.cluster_view.state)

# Clear temporary HTML files
self.cluster_view.clear_temporary_files()
self.similarity_view.clear_temporary_files()

def _get_similar_clusters(self, sender, cluster_id):
"""Return the clusters similar to a given cluster."""
sim = self.similarity(cluster_id) or []
Expand Down
19 changes: 17 additions & 2 deletions phy/gui/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import os
import os.path as op
from pathlib import Path
import shutil
import sys
import tempfile
from timeit import default_timer
import traceback

Expand Down Expand Up @@ -466,8 +468,21 @@ def set_html(self, html, callback=None):
self._callback = callback
self.loadFinished.connect(self._loadFinished)
static_dir = str(Path(__file__).parent / 'static') + '/'
base_url = QUrl().fromLocalFile(static_dir)
self.page().setHtml(html, base_url)

# Create local file from HTML
self.clear_temporary_files()
self._tempdir = Path(tempfile.mkdtemp())
shutil.copytree(static_dir, self._tempdir / 'html')
file_path = self._tempdir / 'html' / 'page.html'
with open(file_path, 'w') as f:
f.write(html)
file_url = QUrl().fromLocalFile(str(file_path))
self.page().setUrl(file_url)

def clear_temporary_files(self):
"""Delete the temporary HTML files"""
if hasattr(self, '_tempdir') and self._tempdir.is_dir():
shutil.rmtree(self._tempdir, ignore_errors=True)

def _callable(self, data):
self.html = data
Expand Down

0 comments on commit 10e20ae

Please sign in to comment.