Source code for solidipes.reports.widgets.solidipes_buttons

import base64
import os
from typing import TYPE_CHECKING, Literal, Optional
from uuid import uuid4

if TYPE_CHECKING:
    import streamlit as st
else:
    import lazy_loader as lazy

    st = lazy.load("streamlit")

from solidipes.utils.git_infos import GitInfos

from .solidipes_widget import SolidipesWidget as SPW

################################################################
jupyter_icon_filename = os.path.join(os.path.dirname(__file__), "../jupyter_logo.png")
_jupyter_icon = base64.b64encode(open(jupyter_icon_filename, "rb").read()).decode("utf-8")
_git_infos = GitInfos()
################################################################


[docs] class SolidipesButtons(SPW): def __init__(self, **kwargs): super().__init__(**kwargs) self.git_infos = _git_infos
[docs] def _force_rescan_button(self): return self.layout.button("Force new file scan", use_container_width=True)
[docs] def _open_in_gitlab_button(self, origin): if origin is not None: self._link_button("View/Edit in Gitlab repository", origin, use_container_width=True) else: self.layout.error("Gitlab origin not accessible")
[docs] def _open_in_jupyterlab_button(self): with self.layout: self._write_jupyter_link()
[docs] def _open_in_filebrowser_button(self): with self.layout: self._write_filebrowser_link()
[docs] def _iframe_filebrowser(self, dirname): dirname = os.path.abspath(dirname) try: _link = self._get_filebrowser_link() st.markdown( f""" <iframe width="100%" height="800px" src="{_link}" title="Acquisition File Browser" style="flex-grow: 1; border: none; margin: 0; padding: 0;"></iframe> """, unsafe_allow_html=True, ) except RuntimeError as e: st.markdown( '<center> <h1 style="font-size: 10em">⚠ </h1> <br><h2> You are using the web report on your local' " machine ; the acquisition step should be done locally. </h2><br><h4> The report was launched from" f' the following directory : <em><a href="file://{dirname}"> {dirname} </a></em> <br>Please edit your' " files in that directory via your computer’s file browser.</h4></center>", unsafe_allow_html=True, ) with st.expander("detail"): st.warning(str(e))
################################################################ # def get_file_title(self, e): # path = e.file_info.path # if isinstance(e.f, FileSequence): # path = e.f.path # # file_title = f"{path}" # # if isinstance(e.f, FileSequence): # file_size = e.total_size # else: # file_size = e.file_info.size # # file_title += f"&nbsp; &nbsp; **{e.file_info.type.strip()}/{DataSize(file_size):.2a}** " # title = file_title # # if e.state.valid and (not e.discussions or e.archived_discussions): # title = ":white_check_mark: &nbsp; &nbsp;" + file_title # else: # title = ":no_entry_sign: &nbsp; &nbsp; " + file_title # # # if e.discussions or e.state.view: # # title += "&nbsp; :arrow_forward: &nbsp; &nbsp; " # # if e.state.view: # title += "&nbsp; :open_book:" # # if e.discussions: # title += "&nbsp;:e-mail: &nbsp; :arrow_forward: **You have a message**" # # return title # # def get_file_edit_link(self, e): # _path = e.file_info.path # while os.path.islink(_path): # dirname = os.path.dirname(_path) # _path = os.path.join(dirname, os.readlink(_path)) # # url = self.git_infos.origin + "/-/edit/master/data/" + _path # return url # # def show_discussions(self, e): # from solidipes.reports.widgets.custom_widgets import SpeechBubble # # if not e.discussions: # return # if not e.archived_discussions: # st.markdown("### :speech_balloon: Discussions") # for author, message in e.discussions: # SpeechBubble(author, message) # st.markdown("<br>", unsafe_allow_html=True) # # st.button( # "Respond", # on_click=lambda: setattr(e.state, "adding_comment", True), # key=f"respond_button_{e.unique_identifier}", # ) # st.markdown("---") # # if self.show_advanced: # if e.discussions: # st.markdown("---") # if not e.archived_discussions: # st.button("Archive messages", on_click=e.archive_discussions()) # else: # st.button("Unarchive messages", on_click=e.archive_discussions(False)) # # st.markdown("---")