Skip to content

Commit

Permalink
Strip out the different view functionality in favour of letting the u…
Browse files Browse the repository at this point in the history
…ser decide how to display it.
  • Loading branch information
hreikin committed Mar 9, 2023
1 parent 7dbe804 commit 69df61d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/streamlit_uploads_library/gallery.py
Expand Up @@ -3,8 +3,8 @@
from src.streamlit_uploads_library.library import Library

class Gallery(Library):
def __init__(self, directory, expanded=True, file_extensions=(".png", ".jpg", ".jpeg"), gallery_type="container", label="**Gallery**" or None, number_of_columns=5, show_filename=False):
super(Gallery, self).__init__(directory, expanded, file_extensions, gallery_type, label, number_of_columns, show_filename)
def __init__(self, directory, file_extensions=(".png", ".jpg", ".jpeg"), number_of_columns=5, show_details=False):
super(Gallery, self).__init__(directory, file_extensions, number_of_columns, show_details)

def fetch_files(self):
return super().fetch_files()
Expand Down
40 changes: 8 additions & 32 deletions src/streamlit_uploads_library/library.py
Expand Up @@ -15,27 +15,18 @@ class Library():
st.set_page_config(page_title="Streamlit Uploads Library", layout="wide")
default_library = Library(directory="assets")
library_with_columns = Library(directory="assets", label="**Library - Columns**", number_of_columns=3)
expander_library = Library(directory="assets", expanded=True, library_type="expander", label="**Library - Expander**")
multiple_options_library = Library(directory="assets", library_type="expander", label="**Library - Multiple Options**", number_of_columns=3, show_filename=False)
Args:
directory (str): A str() of the path to the folder containing the library images, for example, "assets".
expanded (bool): A bool(), passing False starts the expander type library closed, default is open and True.
file_extensions (tuple): A tuple() containing strings of the file extensions to include in the library, default is (".png", ".jpg", ".jpeg").
library_type (str): A str() with either "container" or "expander" used as the keyword, the default is "container".
label (str or None): A str() containing the name of the library, passing None disables the label. The default value is "Library".
number_of_columns (int): An int() defining the number of required columns, default is 5.
show_filenames (bool): A bool(), passing True displays the filenames, the default is False which hides them.
show_details (bool): A bool() to show or hide the file and edit details, False hides them, default is True to show them.
"""
def __init__(self, directory, expanded=True, file_extensions=(".png", ".jpg", ".jpeg"), library_type="container", label="**Library**" or None, number_of_columns=5, show_filename=False):
def __init__(self, directory, file_extensions=(".png", ".jpg", ".jpeg"), number_of_columns=5, show_details=True):
self.directory = Path(directory).resolve()
self.expanded = expanded
self.file_extensions = file_extensions
self.library_type = library_type
self.label = label
self.number_of_columns = number_of_columns
self.show_filename = show_filename
self.show_details = show_details
self.library = self.create_library()

def fetch_files(self):
Expand All @@ -62,36 +53,21 @@ def create_library(_self):
Creates a library using columns out of streamlit widgets.
Returns:
container_or_expander (st.container or st.expander): A streamlit widget containing the library.
library_container (st.container or st.expander): A streamlit widget containing the library.
"""
if _self.library_type == "expander":
if _self.label == None:
_self.label = ""
_self.container_or_expander = st.expander(label=_self.label, expanded=_self.expanded)
else:
_self.container_or_expander = st.expander(label=_self.label, expanded=_self.expanded)
else:
_self.container_or_expander = st.container()
with _self.container_or_expander:
if _self.label == None:
pass
else:
_self.library_label = st.markdown(f"**{_self.label}**")
with _self.container_or_expander:
_self.library_container = st.container()
with _self.library_container:
_self.col_idx = 0
_self.filename_idx = 0
_self.max_idx = _self.number_of_columns-1
_self.library_files, _self.library_filenames = _self.fetch_files()
_self.all_columns = list(st.columns(_self.number_of_columns))
for img in _self.library_files:
with _self.all_columns[_self.col_idx]:
if _self.show_filename == True:
st.image(img, caption=_self.library_filenames[_self.filename_idx], use_column_width=True)
else:
st.image(img, use_column_width=True)
st.image(img, use_column_width=True)
if _self.col_idx < _self.max_idx:
_self.col_idx += 1
else:
_self.col_idx = 0
_self.filename_idx += 1
return _self.container_or_expander
return _self.library_container

0 comments on commit 69df61d

Please sign in to comment.