Update tab_gallery_sorter.py

This commit is contained in:
2026-01-18 23:22:08 +01:00
parent 0b791984c7
commit 82d091b1ed

View File

@@ -34,6 +34,11 @@ def cb_apply_batch(current_batch, path_o, cleanup_mode):
"""Commits the batch to disk.""" """Commits the batch to disk."""
SorterEngine.commit_batch(current_batch, path_o, cleanup_mode) SorterEngine.commit_batch(current_batch, path_o, cleanup_mode)
def cb_change_page(delta):
"""Updates the page number before the script runs."""
if 't5_page' not in st.session_state:
st.session_state.t5_page = 0
st.session_state.t5_page += delta
# ========================================== # ==========================================
# 2. FRAGMENT: SIDEBAR (Category Manager) # 2. FRAGMENT: SIDEBAR (Category Manager)
@@ -237,25 +242,35 @@ def render(quality, profile_name):
total_items = len(all_images) total_items = len(all_images)
total_pages = math.ceil(total_items / page_size) total_pages = math.ceil(total_items / page_size)
if st.session_state.t5_page >= total_pages: st.session_state.t5_page = max(0, total_pages - 1) if st.session_state.t5_page >= total_pages:
st.session_state.t5_page = max(0, total_pages - 1)
if st.session_state.t5_page < 0:
st.session_state.t5_page = 0
start_idx = st.session_state.t5_page * page_size start_idx = st.session_state.t5_page * page_size
end_idx = start_idx + page_size end_idx = start_idx + page_size
current_batch = all_images[start_idx:end_idx] current_batch = all_images[start_idx:end_idx]
# --- NAVIGATION CONTROLS --- # --- NAVIGATION CONTROLS (Optimized) ---
def nav_controls(key): def nav_controls(key):
c1, c2, c3 = st.columns([1, 2, 1]) c1, c2, c3 = st.columns([1, 2, 1])
if c1.button("⬅️ Prev", disabled=(st.session_state.t5_page==0), key=f"p_{key}"):
st.session_state.t5_page -= 1 # Previous Button
st.rerun() # We pass -1 to the callback to subtract a page
c2.markdown(f"<div style='text-align:center'><b>Page {st.session_state.t5_page+1} / {total_pages}</b></div>", unsafe_allow_html=True) c1.button("⬅️ Prev",
if c3.button("Next ➡️", disabled=(st.session_state.t5_page>=total_pages-1), key=f"n_{key}"): disabled=(st.session_state.t5_page == 0),
st.session_state.t5_page += 1 on_click=cb_change_page, args=(-1,),
st.rerun() key=f"p_{key}")
nav_controls("top") # Page Indicator
st.divider() c2.markdown(f"<div style='text-align:center; padding-top: 5px;'><b>Page {st.session_state.t5_page + 1} / {total_pages}</b></div>", unsafe_allow_html=True)
# Next Button
# We pass 1 to the callback to add a page
c3.button("Next ➡️",
disabled=(st.session_state.t5_page >= total_pages - 1),
on_click=cb_change_page, args=(1,),
key=f"n_{key}")
# --- RENDER GALLERY (FRAGMENT) --- # --- RENDER GALLERY (FRAGMENT) ---
render_gallery_grid(current_batch, quality, grid_cols) render_gallery_grid(current_batch, quality, grid_cols)