fullcalendar.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from typing import Any, Callable, Dict, List, Optional
  2. from ..element import Element
  3. from ..events import GenericEventArguments, handle_event
  4. class FullCalendar(Element, component='fullcalendar.js', libraries=['lib/fullcalendar/index.global.min.js']):
  5. def __init__(self, options: Dict[str, Any], on_click: Optional[Callable] = None) -> None:
  6. super().__init__()
  7. self._props['options'] = options
  8. if on_click:
  9. def handle_on_click(e: GenericEventArguments):
  10. handle_event(on_click, e)
  11. self.on("click", handle_on_click, ['info'])
  12. def addevent(self, title, start, end, **args):
  13. event_dict = {"title": title, "start": start, "end": end, **args}
  14. self._props['options']['events'].append(event_dict)
  15. super().update()
  16. self.run_method('update_calendar')
  17. def remove_event(self, title, start, end, **args):
  18. for event in self._props['options']['events']:
  19. if event['title'] == title and event['start'] == start and event['end'] == end:
  20. self._props['options']['events'].remove(event)
  21. break
  22. super().update()
  23. self.run_method('update_calendar')
  24. def get_events(self):
  25. return self._props['options']['events']