Skip to content

Commit

Permalink
Update demo app pages with new code and examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
hreikin committed Mar 11, 2023
1 parent bc3253a commit a795487
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pages/Gallery.py
Expand Up @@ -22,8 +22,8 @@
from streamlit_uploads_library.library import Library
class Gallery(Library):
def __init__(self, directory, expanded=False, file_extensions=(".png", ".jpg", ".jpeg"), number_of_columns=5, show_details=False):
super(Gallery, self).__init__(directory, expanded, file_extensions, number_of_columns, show_details)
def __init__(self, directory, file_extensions=(".png", ".jpg", ".jpeg"), number_of_columns=5):
super(Gallery, self).__init__(directory, file_extensions, number_of_columns)
def fetch_files(self):
return super().fetch_files()
Expand Down Expand Up @@ -60,7 +60,7 @@ def create_gallery(_self):
st.markdown(body=configuration)
st.code(body=example_usage_code)
default_gallery = Gallery(directory="assets")
gallery_with_columns = Gallery(directory="assets", number_of_columns=3)
gallery_with_columns = Gallery(directory="assets", number_of_columns=4)

with st.expander(label="**Source Code**", expanded=True):
st.code(body=source_code)
25 changes: 22 additions & 3 deletions pages/Library.py
Expand Up @@ -23,6 +23,8 @@
from pathlib import Path
from math import ceil
logger = logging.getLogger(__name__)
class Library():
"""Create a simple library out of streamlit widgets.
Expand Down Expand Up @@ -71,9 +73,15 @@ def fetch_files(self):
def update_file(self, old_file, new_file, del_check=False):
if del_check == False:
old_file.rename(old_file.with_stem(new_file))
try:
old_file.rename(old_file.with_stem(new_file))
except FileExistsError as e:
logger.warning(e)
else:
old_file.unlink()
try:
old_file.unlink()
except FileNotFoundError as e:
logger.warning(e)
st.cache_resource.clear()
st.experimental_rerun()
Expand Down Expand Up @@ -125,6 +133,15 @@ def create_library(_self, number_of_columns, show_details):
for img in _self.library_files[_self.filename_idx:(_self.filename_idx + number_of_columns)]:
with _self.imgs_columns[_self.col_idx]:
st.image(img, use_column_width="auto")
st.write(
"""<style>
[data-testid="stHorizontalBlock"] {
align-items: center;
}
</style>
""",
unsafe_allow_html=True
)
if show_details == True:
with _self.details_columns[_self.col_idx]:
# with st.expander(label="Details", expanded=_self.expanded_details):
Expand Down Expand Up @@ -156,7 +173,9 @@ def create_library(_self, number_of_columns, show_details):
return _self.library_container
'''

library = Library(directory="assets", number_of_columns=5)
library = Library(directory="assets")
library_details = Library(directory="assets", expanded_details=False)
library_with_columns = Library(directory="assets", number_of_columns=4)

with st.expander(label="**Source Code**", expanded=True):
st.code(body=source_code)

0 comments on commit a795487

Please sign in to comment.