section_calendar.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from widgets import *
  2. import section_profile_editor
  3. import timetable_calendar
  4. _calendar: ReactiveCalendarWidget
  5. def _on_selection_changed(calendar: ReactiveCalendarWidget) -> None:
  6. selected_date = calendar.selectedDate()
  7. profile_id = timetable_calendar.get_profile_id(selected_date)
  8. section_profile_editor.update(profile_id, selected_date)
  9. def update() -> None:
  10. global _calendar
  11. _on_selection_changed(_calendar)
  12. _calendar.updateCells()
  13. def create() -> QWidget:
  14. global _calendar
  15. frame = SectionFrame()
  16. _calendar = ReactiveCalendarWidget()
  17. _calendar.setGridVisible(True)
  18. _calendar.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
  19. _calendar.setSelectionMode(QCalendarWidget.SelectionMode.SingleSelection)
  20. _calendar.setVerticalHeaderFormat(QCalendarWidget.VerticalHeaderFormat.NoVerticalHeader)
  21. _calendar.selectionChanged.connect(lambda: _on_selection_changed(_calendar))
  22. # Это спровоцирует отображения редактора профилей
  23. update()
  24. layout = QHBoxLayout(frame)
  25. layout.setContentsMargins(0, 0, 0, 0)
  26. layout.addWidget(_calendar)
  27. return frame