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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import panel as pn
2
+ import param
3
+ from typing import List, Tuple
4
+
5
+ pn.extension("floatpanel")
6
+
7
+
8
+ class MainHeader(pn.viewable.Viewer):
9
+ """
10
+ MainHeader class represents the header section of the dashboard.
11
+ It includes a heading, subheading, and a series of buttons with configurable actions.
12
+ """
13
+
14
+ # Parameters for the header and subheading text
15
+ heading: str = param.String(
16
+ default="Default Heading", doc="The heading text", allow_refs=True
17
+ )
18
+ subheading: str = param.String(
19
+ default="Default Subheading", doc="The subheading text", allow_refs=True
20
+ )
21
+
22
+ # Parameters for the names of up to 12 buttons
23
+ button_1_name: str = param.String(
24
+ default="Button 1", doc="Name for Button 1", allow_refs=True
25
+ )
26
+ button_2_name: str = param.String(
27
+ default="Button 2", doc="Name for Button 2", allow_refs=True
28
+ )
29
+ button_3_name: str = param.String(
30
+ default="Button 3", doc="Name for Button 3", allow_refs=True
31
+ )
32
+ button_4_name: str = param.String(
33
+ default="Button 4", doc="Name for Button 4", allow_refs=True
34
+ )
35
+ button_5_name: str = param.String(
36
+ default="Button 5", doc="Name for Button 5", allow_refs=True
37
+ )
38
+ button_6_name: str = param.String(
39
+ default="Button 6", doc="Name for Button 6", allow_refs=True
40
+ )
41
+ button_7_name: str = param.String(
42
+ default="Button 7", doc="Name for Button 7", allow_refs=True
43
+ )
44
+ button_8_name: str = param.String(
45
+ default="Button 8", doc="Name for Button 8", allow_refs=True
46
+ )
47
+ button_9_name: str = param.String(
48
+ default="Button 9", doc="Name for Button 9", allow_refs=True
49
+ )
50
+ button_10_name: str = param.String(
51
+ default="Button 10", doc="Name for Button 10", allow_refs=True
52
+ )
53
+ button_11_name: str = param.String(
54
+ default="Button 11", doc="Name for Button 11", allow_refs=True
55
+ )
56
+ button_12_name: str = param.String(
57
+ default="Button 12", doc="Name for Button 12", allow_refs=True
58
+ )
59
+
60
+ # Parameters for the actions associated with each button
61
+ button_1_action = param.Parameter(doc="Action for Button 1")
62
+ button_2_action = param.Parameter(doc="Action for Button 2")
63
+ button_3_action = param.Parameter(doc="Action for Button 3")
64
+ button_4_action = param.Parameter(doc="Action for Button 4")
65
+ button_5_action = param.Parameter(doc="Action for Button 5")
66
+ button_6_action = param.Parameter(doc="Action for Button 6")
67
+ button_7_action = param.Parameter(doc="Action for Button 7")
68
+ button_8_action = param.Parameter(doc="Action for Button 8")
69
+ button_9_action = param.Parameter(doc="Action for Button 9")
70
+ button_10_action = param.Parameter(doc="Action for Button 10")
71
+ button_11_action = param.Parameter(doc="Action for Button 11")
72
+ button_12_action = param.Parameter(doc="Action for Button 12")
73
+
74
+ def __init__(self, **params):
75
+ """
76
+ Initializes the MainHeader class with the provided parameters.
77
+ """
78
+ super().__init__(**params)
79
+
80
+ def __panel__(self):
81
+ """
82
+ Returns the Panel layout for the header, including the heading, subheading, and buttons.
83
+ """
84
+ # Create HTML panes for heading and subheading
85
+ heading_pane = pn.pane.HTML(
86
+ pn.bind(lambda heading: f"<h1>{heading}</h1>", self.param.heading)
87
+ )
88
+
89
+ subheading_pane = pn.pane.HTML(
90
+ pn.bind(lambda subheading: f"<h4>{subheading}</h4>", self.param.subheading)
91
+ )
92
+
93
+ # Create buttons based on the provided names and actions
94
+ buttons = []
95
+ if self.button_1_name and self.button_1_action:
96
+ buttons.append(
97
+ pn.widgets.Button(
98
+ name=self.button_1_name,
99
+ button_type="primary",
100
+ width=70,
101
+ height=30,
102
+ margin=(5, 5),
103
+ on_click=self.button_1_action,
104
+ )
105
+ )
106
+ if self.button_2_name and self.button_2_action:
107
+ buttons.append(
108
+ pn.widgets.Button(
109
+ name=self.button_2_name,
110
+ button_type="primary",
111
+ width=70,
112
+ height=30,
113
+ margin=(5, 5),
114
+ on_click=self.button_2_action,
115
+ )
116
+ )
117
+ if self.button_3_name and self.button_3_action:
118
+ buttons.append(
119
+ pn.widgets.Button(
120
+ name=self.button_3_name,
121
+ button_type="primary",
122
+ width=70,
123
+ height=30,
124
+ margin=(5, 5),
125
+ on_click=self.button_3_action,
126
+ )
127
+ )
128
+ if self.button_4_name and self.button_4_action:
129
+ buttons.append(
130
+ pn.widgets.Button(
131
+ name=self.button_4_name,
132
+ button_type="primary",
133
+ width=70,
134
+ height=30,
135
+ margin=(5, 5),
136
+ on_click=self.button_4_action,
137
+ )
138
+ )
139
+ if self.button_5_name and self.button_5_action:
140
+ buttons.append(
141
+ pn.widgets.Button(
142
+ name=self.button_5_name,
143
+ button_type="primary",
144
+ width=70,
145
+ height=30,
146
+ margin=(5, 5),
147
+ on_click=self.button_5_action,
148
+ )
149
+ )
150
+ if self.button_6_name and self.button_6_action:
151
+ buttons.append(
152
+ pn.widgets.Button(
153
+ name=self.button_6_name,
154
+ button_type="primary",
155
+ width=70,
156
+ height=30,
157
+ margin=(5, 5),
158
+ on_click=self.button_6_action,
159
+ )
160
+ )
161
+ if self.button_7_name and self.button_7_action:
162
+ buttons.append(
163
+ pn.widgets.Button(
164
+ name=self.button_7_name,
165
+ button_type="primary",
166
+ width=70,
167
+ height=30,
168
+ margin=(5, 5),
169
+ on_click=self.button_7_action,
170
+ )
171
+ )
172
+ if self.button_8_name and self.button_8_action:
173
+ buttons.append(
174
+ pn.widgets.Button(
175
+ name=self.button_8_name,
176
+ button_type="primary",
177
+ width=70,
178
+ height=30,
179
+ margin=(5, 5),
180
+ on_click=self.button_8_action,
181
+ )
182
+ )
183
+ if self.button_9_name and self.button_9_action:
184
+ buttons.append(
185
+ pn.widgets.Button(
186
+ name=self.button_9_name,
187
+ button_type="primary",
188
+ width=70,
189
+ height=30,
190
+ margin=(5, 5),
191
+ on_click=self.button_9_action,
192
+ )
193
+ )
194
+ if self.button_10_name and self.button_10_action:
195
+ buttons.append(
196
+ pn.widgets.Button(
197
+ name=self.button_10_name,
198
+ button_type="primary",
199
+ width=70,
200
+ height=30,
201
+ margin=(5, 5),
202
+ on_click=self.button_10_action,
203
+ )
204
+ )
205
+ if self.button_11_name and self.button_11_action:
206
+ buttons.append(
207
+ pn.widgets.Button(
208
+ name=self.button_11_name,
209
+ button_type="primary",
210
+ width=70,
211
+ height=30,
212
+ margin=(5, 5),
213
+ on_click=self.button_11_action,
214
+ )
215
+ )
216
+ if self.button_12_name and self.button_12_action:
217
+ buttons.append(
218
+ pn.widgets.Button(
219
+ name=self.button_12_name,
220
+ button_type="primary",
221
+ width=70,
222
+ height=30,
223
+ margin=(5, 5),
224
+ on_click=self.button_12_action,
225
+ )
226
+ )
227
+
228
+ # Create the layout for the header
229
+ layout_items = [heading_pane]
230
+ if self.subheading and self.subheading != "Default Subheading":
231
+ layout_items.append(subheading_pane)
232
+
233
+ # Create the layout for the header
234
+ layout = pn.Row(
235
+ pn.Column(*layout_items),
236
+ pn.FlexBox(
237
+ *buttons,
238
+ align_items="center",
239
+ justify_content="end",
240
+ flex_wrap="wrap",
241
+ ),
242
+ )
243
+
244
+ return layout
245
+
246
+
247
+ class MainArea(pn.viewable.Viewer):
248
+ """
249
+ MainArea class represents the main content area of the dashboard, containing multiple tabs.
250
+ """
251
+
252
+ # Parameter for the content of the tabs, as a dictionary with tab names as keys and content as values
253
+ tabs_content: dict = param.Dict(
254
+ default={},
255
+ doc="Dictionary with tab names as keys and content as values",
256
+ allow_refs=True,
257
+ )
258
+
259
+ def __init__(self, **params):
260
+ """
261
+ Initializes the MainArea class with the provided parameters.
262
+ """
263
+ super().__init__(**params)
264
+
265
+ def __panel__(self):
266
+ """
267
+ Returns the Panel layout for the main area, which includes tabs with their respective content.
268
+ """
269
+ tabs = pn.Tabs(dynamic=True)
270
+ for tab_name, content in self.tabs_content.items():
271
+ tabs.append((tab_name, content))
272
+
273
+ flexbox_layout = pn.FlexBox(
274
+ tabs,
275
+ sizing_mode="stretch_both",
276
+ align_items="stretch",
277
+ justify_content="space-between",
278
+ )
279
+ return flexbox_layout
280
+
281
+
282
+ class OutputBox(pn.viewable.Viewer):
283
+ """
284
+ OutputBox class represents a box to display output content.
285
+ """
286
+
287
+ # Parameter for the content to display in the output box
288
+ output_content: str = param.String(
289
+ default="", doc="Content to display in the output box", allow_refs=True
290
+ )
291
+
292
+ def __init__(self, **params):
293
+ """
294
+ Initializes the OutputBox class with the provided parameters.
295
+ """
296
+ super().__init__(**params)
297
+
298
+ def __panel__(self):
299
+ """
300
+ Returns the Panel layout for the output box, including a heading and the content.
301
+ """
302
+ heading = pn.pane.Markdown("<h2> Output </h2>")
303
+ output_box = pn.widgets.TextAreaInput(
304
+ name="",
305
+ value=self.output_content,
306
+ disabled=True,
307
+ min_height=220,
308
+ sizing_mode="stretch_both",
309
+ )
310
+ return pn.Column(heading, output_box, sizing_mode="stretch_both")
311
+
312
+
313
+ class WarningBox(pn.viewable.Viewer):
314
+ """
315
+ WarningBox class represents a box to display warning content.
316
+ """
317
+
318
+ # Parameter for the content to display in the warning box
319
+ warning_content: str = param.String(
320
+ default="", doc="Content to display in the warning box", allow_refs=True
321
+ )
322
+
323
+ def __init__(self, **params):
324
+ """
325
+ Initializes the WarningBox class with the provided parameters.
326
+ """
327
+ super().__init__(**params)
328
+
329
+ def __panel__(self):
330
+ """
331
+ Returns the Panel layout for the warning box, including a heading and the content.
332
+ """
333
+ heading = pn.pane.Markdown("<h2> Warning</h2>")
334
+ warning_box = pn.widgets.TextAreaInput(
335
+ name="",
336
+ value=self.warning_content,
337
+ disabled=True,
338
+ min_height=220,
339
+ sizing_mode="stretch_both",
340
+ )
341
+ return pn.Column(heading, warning_box, sizing_mode="stretch_both")
342
+
343
+
344
+ class PlotsContainer(pn.viewable.Viewer):
345
+ """
346
+ PlotsContainer class represents a container for displaying multiple plots.
347
+ """
348
+
349
+ flexbox_contents: list = param.List(default=[], doc="Contents for FlexBox containers", allow_refs=True)
350
+
351
+ def __init__(self, *contents, **params):
352
+ super().__init__(**params)
353
+ self.flexbox_contents = list(contents)
354
+
355
+ def __panel__(self):
356
+ """
357
+ Returns the Panel layout for the plots container.
358
+ """
359
+ title = pn.pane.Markdown("<h2> Plots </h2>", align="center")
360
+ flexbox_container = pn.FlexBox(
361
+ *self.flexbox_contents,
362
+ flex_direction='row',
363
+ align_content='space-evenly',
364
+ align_items="center",
365
+ justify_content="center",
366
+ flex_wrap="wrap"
367
+ )
368
+ return pn.Column(title, flexbox_container, sizing_mode="stretch_both")
369
+
370
+ class HelpBox(pn.viewable.Viewer):
371
+ """
372
+ HelpBox class represents a box to display help or documentation content.
373
+ """
374
+
375
+ # Parameters for the title and content of the help box
376
+ title: str = param.String(
377
+ default="Help", doc="Title for the help box", allow_refs=True
378
+ )
379
+ help_content: str = param.String(
380
+ default="", doc="Markdown content for the help box", allow_refs=True
381
+ )
382
+
383
+ def __init__(self, **params):
384
+ """
385
+ Initializes the HelpBox class with the provided parameters.
386
+ """
387
+ super().__init__(**params)
388
+
389
+ def __panel__(self):
390
+ """
391
+ Returns the Panel layout for the help box, including a heading and Markdown content.
392
+ """
393
+ heading = pn.pane.Markdown(f"<h2> {self.title}</h2>")
394
+ help_markdown = pn.pane.Markdown(self.help_content, sizing_mode="stretch_both")
395
+ return pn.Column(heading, help_markdown, sizing_mode="stretch_both")
396
+
397
+
398
+ class Footer(pn.viewable.Viewer):
399
+ """
400
+ Footer class represents the footer section of the dashboard.
401
+ It includes the main content, additional links, and icon buttons.
402
+ """
403
+
404
+ # Parameters for the main content, additional links, and icons in the footer
405
+ main_content: str = param.String(
406
+ default="", doc="Main content to display in the footer", allow_refs=True
407
+ )
408
+ additional_links: List[str] = param.List(
409
+ default=[], doc="List of additional links as markdown strings", allow_refs=True
410
+ )
411
+ icons: List[pn.viewable.Viewer] = param.List(
412
+ default=[], doc="List of icon buttons", allow_refs=True
413
+ )
414
+
415
+ def __init__(self, **params):
416
+ """
417
+ Initializes the Footer class with the provided parameters.
418
+ """
419
+ super().__init__(**params)
420
+
421
+ def __panel__(self):
422
+ """
423
+ Returns the Panel layout for the footer, including logo, name, links, icons, and contact information.
424
+ """
425
+ logo = pn.pane.PNG(
426
+ "../assets/images/stingray_explorer.png",
427
+ width=100,
428
+ height=100,
429
+ align="center",
430
+ )
431
+ name = pn.pane.Markdown("Stingray Explorer", align="center")
432
+
433
+ logo_name_pane = pn.FlexBox(
434
+ logo,
435
+ name,
436
+ flex_direction="column",
437
+ justify_content="center",
438
+ align_items="center",
439
+ )
440
+
441
+ links = [pn.pane.Markdown(link) for link in self.additional_links]
442
+
443
+ links_pane = pn.FlexBox(
444
+ *links,
445
+ flex_direction="column",
446
+ justify_content="center",
447
+ align_items="center",
448
+ )
449
+
450
+ icons_pane = pn.FlexBox(
451
+ *self.icons,
452
+ flex_direction="column",
453
+ justify_content="center",
454
+ align_items="center",
455
+ )
456
+
457
+ contact_us_pane = pn.FlexBox(
458
+ pn.pane.Markdown("Email: kartik4321mandar@gmail.com"),
459
+ pn.pane.Markdown("Slack: @kartikmandar"),
460
+ flex_direction="row",
461
+ justify_content="center",
462
+ align_items="center",
463
+ )
464
+
465
+ copyright_pane = pn.pane.Markdown(
466
+ """
467
+ &copy; 2024, Stingray. All rights reserved.
468
+ """,
469
+ )
470
+
471
+ pane1 = pn.FlexBox(
472
+ logo_name_pane,
473
+ links_pane,
474
+ icons_pane,
475
+ flex_direction="row",
476
+ justify_content="space-between",
477
+ align_items="center",
478
+ )
479
+
480
+ pane2 = pn.FlexBox(
481
+ contact_us_pane,
482
+ flex_direction="column",
483
+ justify_content="center",
484
+ align_items="center",
485
+ )
486
+
487
+ pane3 = pn.FlexBox(
488
+ copyright_pane,
489
+ flex_direction="row",
490
+ justify_content="center",
491
+ align_items="center",
492
+ )
493
+
494
+ footer = pn.FlexBox(
495
+ pane1,
496
+ pane2,
497
+ pane3,
498
+ flex_direction="row",
499
+ justify_content="center",
500
+ align_items="center",
501
+ )
502
+
503
+ return footer
504
+
505
+
506
+ # Custom warning handler
507
+ class WarningHandler:
508
+ def __init__(self):
509
+ self.warnings = []
510
+
511
+ def warn(
512
+ self, message, category=None, filename=None, lineno=None, file=None, line=None
513
+ ):
514
+ warning_message = f"Message: {message}\nCategory: {category.__name__ if category else 'N/A'}\nFile: {filename if filename else 'N/A'}\nLine: {lineno if lineno else 'N/A'}\n"
515
+ self.warnings.append(warning_message)
516
+
517
+
518
+ class FloatingPlot(pn.viewable.Viewer):
519
+ """
520
+ Floating Plot Container class represents a container for displaying a single plot.
521
+ """
522
+
523
+ # Parameters for the title and content of Floating Panel
524
+ title: str = param.String(default="", doc="Title for Floating Panel")
525
+ content: pn.viewable.Viewer = param.Parameter(
526
+ default=None, doc="Content for Floating Panel"
527
+ )
528
+
529
+ def __init__(self, title="", content=None, **params):
530
+ """
531
+ Initializes FloatingPlot class with the provided parameters.
532
+ """
533
+ super().__init__(**params)
534
+ self.title = title
535
+ self.content = content
536
+
537
+ @property
538
+ def object(self):
539
+ print(f"Object property called for {self.content}")
540
+ return self.content
541
+
542
+
543
+ def __panel__(self):
544
+ """
545
+ Returns the floating panel which contains the content with the appropriate heading.
546
+ """
547
+ if not self.title or not self.content:
548
+ raise ValueError("Title and content must be provided.")
549
+
550
+ float_panel = pn.layout.FloatPanel(
551
+ self.content,
552
+ name=str(self.title),
553
+ contained=False,
554
+ position="center",
555
+ width=700,
556
+ height=700,
557
+ margin=20,
558
+ theme="success",
559
+ )
560
+ return float_panel
561
+