File size: 8,944 Bytes
ab2fd74
f3d3d17
e187e71
1b19799
 
 
 
88041f6
b3cab10
23ab556
1b19799
2f2818f
88041f6
f260a00
 
fdb3810
 
f260a00
 
 
 
1da9cce
88041f6
 
fd0a806
6a14743
f260a00
51057f3
e9ea94f
f00306b
 
 
 
 
b463b02
f00306b
 
 
8e189fc
7c0fda5
184c116
cabdb7b
1440463
d874818
1440463
5f19ec5
1440463
d874818
 
8d33d20
9b7c81d
8289aee
95a81e1
1da9cce
95a81e1
 
 
dccf541
10c9d19
95a81e1
 
fc29acd
2f2818f
5f19ec5
 
95a81e1
d3714db
1da9cce
5f19ec5
373a8e6
 
0795d0b
e339013
07a60bf
1edc318
0795d0b
 
fda61e7
373a8e6
fc3b6f0
9947be3
fc3b6f0
07a60bf
1edc318
775bcf5
184c116
 
0795d0b
 
fda61e7
9947be3
 
 
0795d0b
9947be3
373a8e6
184c116
2862361
1edc318
184c116
 
373a8e6
 
0795d0b
 
9947be3
0795d0b
373a8e6
0795d0b
373a8e6
 
fc3b6f0
ae52cd1
373a8e6
 
 
 
 
2f2818f
5528737
0355503
98fe342
 
2f2818f
 
 
 
 
184c116
2f2818f
 
 
 
6d1e68a
 
2f2818f
 
bdd543f
 
2f2818f
 
 
 
 
7c53290
 
5af9b8e
2f2818f
1da9cce
 
56b994a
f275b6d
2f2818f
 
 
4e6b4b4
2f2818f
4ef8e77
2f2818f
184c116
2f2818f
 
e4257aa
2f2818f
 
70e3528
2e79090
81c6aaf
 
b20a3e6
81c6aaf
 
4fa35ce
81c6aaf
 
 
 
2f2818f
 
 
 
 
 
 
 
 
 
 
81c6aaf
2f2818f
 
 
1da9cce
 
2f2818f
 
 
 
 
6e17e42
3baa447
 
2f2818f
 
 
184c116
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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

class MainBody(param.Parameterized):
    main_body = param.List(default=[pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt' , 'font-weight':'bold'})])

    @param.depends("main_body")
    def update(self):
        return pn.Column(*self.main_body)
    
    def add_panel_to_main_body(self, panel):
        self.main_body.append(panel)
        
main_body_instance = MainBody()

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(icon='home', name="Daily papers", icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140, align='center' )
# button2 = pn.widgets.Button(icon='calendar-filled', name="Search papers", icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140, align='center')
# button3 = pn.widgets.Button(icon='file-analytics', name='My papers', icon_size='1.5em', button_type = 'primary', button_style = 'outline', width = 140, align='center')
# button4 = pn.widgets.Toggle(name='Accessibility',icon='settings', icon_size='1.5em', button_type='primary', button_style='outline', width=140, align='center', value=False)

button1 = pn.widgets.Button(name="πŸ“‹ Daily papers", button_type = 'default', button_style = 'outline', width = 140, align='center' )
button2 = pn.widgets.Button(name="πŸ“† Search papers", button_type = 'default', button_style = 'outline', width = 140, align='center')
button3 = pn.widgets.Button(name='πŸ“ My papers', button_type = 'default', button_style = 'outline', width = 140, align='center')
button4 = pn.widgets.Toggle(name='βš™οΈ Accessibility', button_type='default', button_style='outline', width=140, align='center', 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, button4,
    pn.Column(
        select,
        select2,
        visible=False,
        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

button4.param.watch(toggle_settings, 'value')

# Dictionary to store the previous content of main_panel and main_panel_button3
previous_content = {}
current_state = 'main_panel'  # Variable to keep track of the current state

# Function to reset the main panel content to the initial content and store the previous content
def reset_main_panel(event):
    global previous_content, current_state
    # Store the previous content of the current state if it's not already stored
    previous_content[current_state] = main_body_instance.main_body.copy()

    # Update the current state to mail_panel
    current_state = 'main_panel'
    
    # Reset the main panel to the initial state
    main_body_instance.main_body.clear()  # Clear the existing main panel content

# Function to update the main panel content when button3 is pressed
def update_main_panel_button3(event):
    global previous_content, current_state
    # Store the previous content of the current state if it's not already stored
    previous_content[current_state] = main_body_instance.main_body.copy()

    # Update the current state to main_panel_button3
    current_state = 'main_panel_button3'

    # Reset the main panel to the desired content when button3 is pressed
    main_body_instance.main_body.clear()  # Clear the existing main panel content

# Attach the functions to the on_click event of button1 and button3
button1.on_click(reset_main_panel)
button3.on_click(update_main_panel_button3)

# Function to check if there's previous content and display it, otherwise show a default message
def show_previous_content(event):
    global previous_content, current_state
    # Check if there's previous content for the current state
    print(current_state, flush = True)
    if current_state in previous_content:
        main_body_instance.main_body.clear()  # Clear the existing main panel content
        main_body_instance.main_body.extend(previous_content[current_state])  # Add the previous content
    else:
        main_body_instance.main_body.clear()  # Clear the existing main panel content
        main_body_instance.main_body.append(pn.pane.Markdown("### No previous content available!"))
    main_body_instance.param.trigger('main_body')  # Trigger the update manually

# Attach the show_previous_content function to the on_click event of button1 and button3
button1.on_click(show_previous_content)
button3.on_click(show_previous_content)

# 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_header()  # Update the header after adding options


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)
    
# 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
    
# 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',
    header_links=True,  # Add this line to enable smooth scrolling
)

# Run the app
template.servable()