import panel as pn pn.extension('katex') import pytz from datetime import date from datetime import datetime from dateutil.relativedelta import relativedelta, MO import param import TLDR from src.search import Search_Papers # Create the MainBody class class MainBody(param.Parameterized): main_body = param.List(default=[pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})]) @param.depends("main_body") def update(self): return pn.Column(*self.main_body) # Initialize the MainBody instance main_body_instance = MainBody() # Store the initial content of the main panel in the MainBody instance main_body_instance.main_body = [pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})] initial_main_body = main_body_instance.main_body.copy() # Function to reset the main panel content to the initial content def reset_main_panel(event): # Clear the existing main panel content if it's not the initial content if main_body_instance.main_body != initial_main_body: main_body_instance.main_body.clear() main_body_instance.main_body.extend(initial_main_body) main_body_instance.param.trigger('main_body') # Trigger the update manually paper_list = [] # Add this line to initialize paper_list as an empty list main_body = [pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})] # Create buttons for the toggleable sidebar # button1 = pn.widgets.Button(name="🏠 Home", button_type='default', button_style='outline', width=140) # button2 = pn.widgets.Button(name='📁 My papers', button_type='default', button_style='outline', width=140) # button3 = pn.widgets.Toggle(name='⚙️ Settings', button_type='default', button_style='outline', width=140, value=False) # Create buttons for the toggleable sidebar button1 = pn.widgets.Button(icon='home', name="Daily papers", icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140) button2 = pn.widgets.Button(icon='calendar-filled', name="Search papers", icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140) button3 = pn.widgets.Button(icon='file-analytics', name='My papers', icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140) button4 = pn.widgets.Toggle(name='Accessibility',icon='settings', icon_size='1.5em', button_type='default', button_style='outline', width=140, value=False) # Custom RadioButtonGroup widget select = pn.widgets.RadioButtonGroup(value="Scientic", options=["General", "Scientic"], name='String', align='center', button_type='default') # , align='center' select2 = pn.widgets.RadioButtonGroup(value="Normal", options=["Bionic", "Normal"], name='String', align='center', button_type='default') # Define a callback to display the selected value def display_selected_value(event): print(f"Selected value: {event.new}", flush=True) # Attach the callback to the value_change event of the RadioButtonGroup select.param.watch(display_selected_value, 'value') select2.param.watch(display_selected_value, 'value') # Create a column layout for the buttons inside the toggleable sidebar buttons = pn.Column( button1, button2, button3, pn.Column( select, select2, visible=True, sizing_mode='stretch_width', ), css_classes=['hidden'] ) # Define a callback to show/hide the select buttons when "Settings" button is toggled def toggle_settings(event): buttons[-1].visible = event.new button3.param.watch(toggle_settings, 'value') # Attach the reset_main_panel function to the on_click event of button1 button1.on_click(reset_main_panel) # Function to update the main panel content when button3 is pressed def update_main_panel_button3(event): main_body_instance.main_body.clear() # Clear the existing main panel content main_body_instance.main_body.append(pn.pane.Markdown("You pressed button3!")) main_body_instance.param.trigger('main_body') # Trigger the update manually # Attach the functions to the on_click event of button1 and button3 button3.on_click(update_main_panel_button3) # Create the main panel with some initial content main_panel = pn.Column(pn.pane.Markdown("# Main Panel")) # Define a callback to show/hide the select buttons when "Settings" button is toggled def toggle_date_picker(event): if event.new: # Create a FloatPanel and place the DatePicker inside it float_panel = pn.layout.FloatPanel(date_picker, name="Free Floating FloatPanel", contained=False, position='bottom_left') float_panel.show() else: # Remove any existing FloatPanel if the toggle is set to False try: float_panel.close() except NameError: pass # List to store the entered options loaded_dict = TLDR.load_categories() arxiv_tags = list(loaded_dict.keys()) entered_options = list(loaded_dict.values()) # Create buttons for the header header_buttons = pn.Row(sizing_mode='stretch_width', css_classes=['header-buttons']) # "+" button to trigger the addition to the header add_to_header_button = pn.widgets.Button(name="", icon='search', icon_size='1.5em', button_style = 'outline',button_type = 'light') # List to store the names of buttons to be added to the header buttons_to_add = [] paper_list = [] # Callback for adding selected options to the list def add_to_header(event): global paper_list selected_options = filter_list.value if selected_options: for option in selected_options: if option not in buttons_to_add: # Check if option is already in header buttons_to_add.append(option) # Add to header if not already present paper_list_itr = TLDR.run_code(option, loaded_dict) paper_list.append(paper_list_itr) filter_list.value = [] # Clear the selected options after adding them to the header # Update the main panel content main_body_instance.main_body = TLDR.update_mainTLDR(buttons_to_add, paper_list, "Search Papers", "general", 0) main_body_instance.param.trigger('main_body') # Trigger the update manually add_to_header_button.on_click(add_to_header) # Function to update the header layout with the newly created buttons def update_header(): global paper_list header_buttons.clear() # Clear the existing buttons for button_name in buttons_to_add: header_button = pn.widgets.Button(name=button_name, button_type = 'primary', button_style = 'outline') header_button.on_click(remove_from_header) # Add callback to remove the header button header_buttons.append(header_button) buttons_to_add # Update the filter list options to exclude buttons that are already in the header filter_list.options = [option for option in entered_options if option not in buttons_to_add] main_body_instance.main_body = TLDR.update_mainTLDR(buttons_to_add, paper_list, "Search Papers", "general", 0) # Callback to remove the clicked header button def remove_from_header(event): global paper_list button = event.obj # Get the clicked button if button.name in buttons_to_add: del paper_list[buttons_to_add.index(button.name)] buttons_to_add.remove(button.name) # Remove from the header buttons list filter_list.options.append(button.name) # Add back to the filter list options update_header() # Update the header and filter list # Update the main panel content main_body_instance.main_body = TLDR.update_mainTLDR(buttons_to_add, paper_list) main_body_instance.param.trigger('main_body') # Trigger the update manually # MultiChoice widget to display the filter options with delete buttons filter_list = pn.widgets.MultiChoice( name='', value=[], options=entered_options, margin=(20, 10), sizing_mode='fixed', solid=False, styles={'background': '#f0f0f0'}, placeholder="Search Topics" ) # Layout using Template template = pn.template.FastListTemplate( title="EasySciRead", header=[ pn.Row( header_buttons, width=750, sizing_mode='stretch_width' ), pn.Row(filter_list, width=250), pn.Row(add_to_header_button, width=55) ], main=main_body_instance.update, sidebar=[buttons], accent_base_color="#88d8b0", header_background="#FFFFFF", header_color="#000000", text_align='center', sidebar_width=160, sizing_mode='stretch_both' ) # Update the header to populate the header buttons initially update_header() # Run the app template.servable()