EasySci commited on
Commit
1da9cce
·
1 Parent(s): 72a4c8b

Update app2.py

Browse files
Files changed (1) hide show
  1. app2.py +16 -55
app2.py CHANGED
@@ -10,29 +10,15 @@ import param
10
  import TLDR
11
  from src.search import Search_Papers
12
 
13
- # Create the MainBody class
14
  class MainBody(param.Parameterized):
15
  main_body = param.List(default=[pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})])
16
 
17
  @param.depends("main_body")
18
  def update(self):
19
  return pn.Column(*self.main_body)
20
-
21
- # Initialize the MainBody instance
22
  main_body_instance = MainBody()
23
 
24
- # Store the initial content of the main panel in the MainBody instance
25
- main_body_instance.main_body = [pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})]
26
- initial_main_body = main_body_instance.main_body.copy()
27
-
28
- # Function to reset the main panel content to the initial content
29
- def reset_main_panel(event):
30
- # Clear the existing main panel content if it's not the initial content
31
- if main_body_instance.main_body != initial_main_body:
32
- main_body_instance.main_body.clear()
33
- main_body_instance.main_body.extend(initial_main_body)
34
- main_body_instance.param.trigger('main_body') # Trigger the update manually
35
-
36
  paper_list = [] # Add this line to initialize paper_list as an empty list
37
 
38
  main_body = [pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})]
@@ -60,9 +46,10 @@ def display_selected_value(event):
60
  select.param.watch(display_selected_value, 'value')
61
  select2.param.watch(display_selected_value, 'value')
62
 
 
63
  # Create a column layout for the buttons inside the toggleable sidebar
64
  buttons = pn.Column(
65
- button1, button2, button3,
66
  pn.Column(
67
  select,
68
  select2,
@@ -76,10 +63,13 @@ buttons = pn.Column(
76
  def toggle_settings(event):
77
  buttons[-1].visible = event.new
78
 
79
- button3.param.watch(toggle_settings, 'value')
80
 
81
- # Attach the reset_main_panel function to the on_click event of button1
82
- button1.on_click(reset_main_panel)
 
 
 
83
 
84
  # Function to update the main panel content when button3 is pressed
85
  def update_main_panel_button3(event):
@@ -87,25 +77,10 @@ def update_main_panel_button3(event):
87
  main_body_instance.main_body.append(pn.pane.Markdown("You pressed button3!"))
88
  main_body_instance.param.trigger('main_body') # Trigger the update manually
89
 
90
- # Attach the functions to the on_click event of button1 and button3
 
91
  button3.on_click(update_main_panel_button3)
92
 
93
- # Create the main panel with some initial content
94
- main_panel = pn.Column(pn.pane.Markdown("# Main Panel"))
95
-
96
- # Define a callback to show/hide the select buttons when "Settings" button is toggled
97
- def toggle_date_picker(event):
98
- if event.new:
99
- # Create a FloatPanel and place the DatePicker inside it
100
- float_panel = pn.layout.FloatPanel(date_picker, name="Free Floating FloatPanel", contained=False, position='bottom_left')
101
- float_panel.show()
102
- else:
103
- # Remove any existing FloatPanel if the toggle is set to False
104
- try:
105
- float_panel.close()
106
- except NameError:
107
- pass
108
-
109
  # List to store the entered options
110
  loaded_dict = TLDR.load_categories()
111
 
@@ -136,10 +111,8 @@ def add_to_header(event):
136
  paper_list_itr = TLDR.run_code(option, loaded_dict)
137
  paper_list.append(paper_list_itr)
138
  filter_list.value = [] # Clear the selected options after adding them to the header
139
-
140
- # Update the main panel content
141
- main_body_instance.main_body = TLDR.update_mainTLDR(buttons_to_add, paper_list)
142
- main_body_instance.param.trigger('main_body') # Trigger the update manually
143
 
144
  add_to_header_button.on_click(add_to_header)
145
 
@@ -166,9 +139,6 @@ def remove_from_header(event):
166
  buttons_to_add.remove(button.name) # Remove from the header buttons list
167
  filter_list.options.append(button.name) # Add back to the filter list options
168
  update_header() # Update the header and filter list
169
- # Update the main panel content
170
- main_body_instance.main_body = TLDR.update_mainTLDR(buttons_to_add, paper_list)
171
- main_body_instance.param.trigger('main_body') # Trigger the update manually
172
 
173
  # MultiChoice widget to display the filter options with delete buttons
174
  filter_list = pn.widgets.MultiChoice(
@@ -185,25 +155,16 @@ filter_list = pn.widgets.MultiChoice(
185
  # Layout using Template
186
  template = pn.template.FastListTemplate(
187
  title="EasySciRead",
188
- header=[
189
- pn.Row(
190
- header_buttons, width=750, sizing_mode='stretch_width'
191
- ),
192
- pn.Row(filter_list, width=250),
193
- pn.Row(add_to_header_button, width=55)
194
- ],
195
- main=main_body_instance.update,
196
  sidebar=[buttons],
197
  accent_base_color="#88d8b0",
198
  header_background="#FFFFFF",
199
  header_color="#000000",
200
  text_align='center',
201
  sidebar_width=160,
202
- sizing_mode='stretch_both'
203
  )
204
 
205
- # Update the header to populate the header buttons initially
206
- update_header()
207
-
208
  # Run the app
209
  template.servable()
 
10
  import TLDR
11
  from src.search import Search_Papers
12
 
 
13
  class MainBody(param.Parameterized):
14
  main_body = param.List(default=[pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})])
15
 
16
  @param.depends("main_body")
17
  def update(self):
18
  return pn.Column(*self.main_body)
19
+
 
20
  main_body_instance = MainBody()
21
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  paper_list = [] # Add this line to initialize paper_list as an empty list
23
 
24
  main_body = [pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'})]
 
46
  select.param.watch(display_selected_value, 'value')
47
  select2.param.watch(display_selected_value, 'value')
48
 
49
+
50
  # Create a column layout for the buttons inside the toggleable sidebar
51
  buttons = pn.Column(
52
+ button1, button2, button3, button4,
53
  pn.Column(
54
  select,
55
  select2,
 
63
  def toggle_settings(event):
64
  buttons[-1].visible = event.new
65
 
66
+ button4.param.watch(toggle_settings, 'value')
67
 
68
+ # Function to reset the main panel content to the initial content
69
+ def reset_main_panel(event):
70
+ main_body_instance.main_body.clear() # Clear the existing main panel content
71
+ main_body_instance.main_body.append(pn.pane.LaTeX("Please select some tags!", styles={'font-size': '20pt'}))
72
+ main_body_instance.param.trigger('main_body') # Trigger the update manually
73
 
74
  # Function to update the main panel content when button3 is pressed
75
  def update_main_panel_button3(event):
 
77
  main_body_instance.main_body.append(pn.pane.Markdown("You pressed button3!"))
78
  main_body_instance.param.trigger('main_body') # Trigger the update manually
79
 
80
+ # Attach the reset_main_panel function to the on_click event of button1
81
+ button1.on_click(reset_main_panel)
82
  button3.on_click(update_main_panel_button3)
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  # List to store the entered options
85
  loaded_dict = TLDR.load_categories()
86
 
 
111
  paper_list_itr = TLDR.run_code(option, loaded_dict)
112
  paper_list.append(paper_list_itr)
113
  filter_list.value = [] # Clear the selected options after adding them to the header
114
+ update_header() # Update the header after adding options
115
+
 
 
116
 
117
  add_to_header_button.on_click(add_to_header)
118
 
 
139
  buttons_to_add.remove(button.name) # Remove from the header buttons list
140
  filter_list.options.append(button.name) # Add back to the filter list options
141
  update_header() # Update the header and filter list
 
 
 
142
 
143
  # MultiChoice widget to display the filter options with delete buttons
144
  filter_list = pn.widgets.MultiChoice(
 
155
  # Layout using Template
156
  template = pn.template.FastListTemplate(
157
  title="EasySciRead",
158
+ 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)],
159
+ main= main_body_instance.update,
 
 
 
 
 
 
160
  sidebar=[buttons],
161
  accent_base_color="#88d8b0",
162
  header_background="#FFFFFF",
163
  header_color="#000000",
164
  text_align='center',
165
  sidebar_width=160,
166
+ sizing_mode = 'stretch_both'
167
  )
168
 
 
 
 
169
  # Run the app
170
  template.servable()