-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfullcalendar.py
55 lines (42 loc) · 2.09 KB
/
fullcalendar.py
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
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional
from nicegui.element import Element
from nicegui.events import handle_event
class FullCalendar(Element, component='fullcalendar.js'):
def __init__(self, options: Dict[str, Any], on_click: Optional[Callable] = None) -> None:
"""FullCalendar
An element that integrates the FullCalendar library (https://fullcalendar.io/) to create an interactive calendar display.
:param options: dictionary of FullCalendar properties for customization, such as "initialView", "slotMinTime", "slotMaxTime", "allDaySlot", "timeZone", "height", and "events".
:param on_click: callback that is called when a calendar event is clicked.
"""
super().__init__()
self.add_resource(Path(__file__).parent / 'lib')
self._props['options'] = options
if on_click:
self.on('click', lambda e: handle_event(on_click, e))
def add_event(self, title: str, start: str, end: str, **kwargs) -> None:
"""Add an event to the calendar.
:param title: title of the event
:param start: start time of the event
:param end: end time of the event
"""
event_dict = {'title': title, 'start': start, 'end': end, **kwargs}
self._props['options']['events'].append(event_dict)
self.update()
self.run_method('update_calendar')
def remove_event(self, title: str, start: str, end: str) -> None:
"""Remove an event from the calendar.
:param title: title of the event
:param start: start time of the event
:param end: end time of the event
"""
for event in self._props['options']['events']:
if event['title'] == title and event['start'] == start and event['end'] == end:
self._props['options']['events'].remove(event)
break
self.update()
self.run_method('update_calendar')
@property
def events(self) -> List[Dict]:
"""List of events currently displayed in the calendar."""
return self._props['options']['events']