dhxpyt.calendar

1from .calendar import Calendar
2from .calendar_config import CalendarConfig
3
4__all__ = ["Calendar", "CalendarConfig"]
class Calendar:
 12class Calendar:
 13    def __init__(self, config: CalendarConfig, widget_parent: Any = None):
 14        """Initializes the calendar instance."""
 15        self.calendar = js.dhx.Calendar.new(widget_parent, js.JSON.parse(json.dumps(config.to_dict())))
 16
 17    """ Calendar API Functions """
 18
 19    def clear(self) -> None:
 20        """Clears the value set in the calendar."""
 21        self.calendar.clear()
 22
 23    def destructor(self) -> None:
 24        """Removes a calendar instance and releases occupied resources."""
 25        self.calendar.destructor()
 26
 27    def get_current_mode(self) -> str:
 28        """Returns the current mode of displaying the Calendar."""
 29        return self.calendar.getCurrentMode()
 30
 31    def get_value(self, as_date_obj: bool = False) -> Union[Union[str, List[str]], Union[str, List[str]]]:
 32        """Returns the selected date(s)."""
 33        return self.calendar.getValue(as_date_obj)
 34
 35    def link(self, calendar: Any) -> None:
 36        """Links the calendar to another calendar for selecting a date range."""
 37        self.calendar.link(calendar.calendar)
 38
 39    def paint(self) -> None:
 40        """Repaints the calendar on a page."""
 41        self.calendar.paint()
 42
 43    def set_value(self, value: Union[str, List[str], str, List[str]]) -> bool:
 44        """Selects a date in the calendar."""
 45        return self.calendar.setValue(value)
 46
 47    def show_date(self, date: Union[str, str] = None, mode: str = "calendar") -> None:
 48        """Shows a specified date and/or opens the calendar in one of the available modes."""
 49        self.calendar.showDate(date, mode)
 50
 51    """ Calendar Events """
 52
 53    def add_event_handler(self, event_name: str, handler: Callable) -> None:
 54        """Helper method to dynamically add event handlers."""
 55        event_proxy = create_proxy(handler)
 56        self.calendar.events[event_name] = event_proxy
 57
 58    def before_change(self, handler: Callable[[str, str, bool], Union[bool, None]]) -> None:
 59        """Fires before the change of date selection."""
 60        self.add_event_handler('beforeChange', handler)
 61
 62    def cancel_click(self, handler: Callable[[], None]) -> None:
 63        """Fires when the user clicks on the 'Cancel' control."""
 64        self.add_event_handler('cancelClick', handler)
 65
 66    def change(self, handler: Callable[[str, str, bool], None]) -> None:
 67        """Fires on change of date selection."""
 68        self.add_event_handler('change', handler)
 69
 70    def date_mouse_over(self, handler: Callable[[str, str], None]) -> None:
 71        """Fires when the mouse pointer is over a date."""
 72        self.add_event_handler('dateMouseOver', handler)
 73
 74    def mode_change(self, handler: Callable[[str], None]) -> None:
 75        """Fires on change of the calendar mode."""
 76        self.add_event_handler('modeChange', handler)
 77
 78    def month_selected(self, handler: Callable[[int], None]) -> None:
 79        """Fires after a month was selected in the calendar."""
 80        self.add_event_handler('monthSelected', handler)
 81
 82    def year_selected(self, handler: Callable[[int], None]) -> None:
 83        """Fires after a year was selected in the calendar."""
 84        self.add_event_handler('yearSelected', handler)
 85
 86    """ Calendar Properties """
 87
 88    @property
 89    def css(self) -> str:
 90        """Optional. Adds style classes to the calendar."""
 91        return self.calendar.css
 92
 93    @css.setter
 94    def css(self, value: str) -> None:
 95        self.calendar.css = value
 96
 97    @property
 98    def date(self) -> Union[str, str]:
 99        """Optional. Defines the date that will be opened when the calendar is created."""
100        return self.calendar.date
101
102    @date.setter
103    def date(self, value: Union[str, str]) -> None:
104        self.calendar.date = value
105
106    @property
107    def date_format(self) -> str:
108        """Optional. Defines the format of dates in the calendar."""
109        return self.calendar.dateFormat
110
111    @date_format.setter
112    def date_format(self, value: str) -> None:
113        self.calendar.dateFormat = value
114
115    @property
116    def disabled_dates(self) -> Callable[[str], bool]:
117        """Optional. Allows disabling some date intervals."""
118        return self.calendar.disabledDates
119
120    @disabled_dates.setter
121    def disabled_dates(self, value: Callable[[str], bool]) -> None:
122        self.calendar.disabledDates = value
123
124    @property
125    def mark(self) -> Callable[[str], str]:
126        """Optional. Adds a CSS class to specific days."""
127        return self.calendar.mark
128
129    @mark.setter
130    def mark(self, value: Callable[[str], str]) -> None:
131        self.calendar.mark = value
132
133    @property
134    def mode(self) -> str:
135        """Optional. The mode of Calendar initialization."""
136        return self.calendar.mode
137
138    @mode.setter
139    def mode(self, value: str) -> None:
140        self.calendar.mode = value
141
142    @property
143    def range(self) -> bool:
144        """Optional. Enables/disables the possibility to select a range of dates."""
145        return self.calendar.range
146
147    @range.setter
148    def range(self, value: bool) -> None:
149        self.calendar.range = value
150
151    @property
152    def this_month_only(self) -> bool:
153        """Optional. Hides dates of the previous/next months relative to the currently displayed one."""
154        return self.calendar.thisMonthOnly
155
156    @this_month_only.setter
157    def this_month_only(self, value: bool) -> None:
158        self.calendar.thisMonthOnly = value
159
160    @property
161    def time_format(self) -> int:
162        """Optional. Defines the time format for the timepicker in the calendar."""
163        return self.calendar.timeFormat
164
165    @time_format.setter
166    def time_format(self, value: int) -> None:
167        self.calendar.timeFormat = value
168
169    @property
170    def time_picker(self) -> bool:
171        """Optional. Adds a timepicker into the calendar."""
172        return self.calendar.timePicker
173
174    @time_picker.setter
175    def time_picker(self, value: bool) -> None:
176        self.calendar.timePicker = value
177
178    @property
179    def value(self) -> Union[str, List[str], str, List[str]]:
180        """Optional. Selects the day(s) (adds a round blue marker)."""
181        return self.calendar.value
182
183    @value.setter
184    def value(self, value: Union[str, List[str], str, List[str]]) -> None:
185        self.calendar.value = value
186
187    @property
188    def week_numbers(self) -> bool:
189        """Optional. Defines whether to show the numbers of weeks."""
190        return self.calendar.weekNumbers
191
192    @week_numbers.setter
193    def week_numbers(self, value: bool) -> None:
194        self.calendar.weekNumbers = value
195
196    @property
197    def week_start(self) -> str:
198        """Optional. Sets the starting day of the week."""
199        return self.calendar.weekStart
200
201    @week_start.setter
202    def week_start(self, value: str) -> None:
203        self.calendar.weekStart = value
204
205    @property
206    def width(self) -> Union[str, int]:
207        """Optional. Sets the width of the calendar."""
208        return self.calendar.width
209
210    @width.setter
211    def width(self, value: Union[str, int]) -> None:
212        self.calendar.width = value
Calendar( config: CalendarConfig, widget_parent: Any = None)
13    def __init__(self, config: CalendarConfig, widget_parent: Any = None):
14        """Initializes the calendar instance."""
15        self.calendar = js.dhx.Calendar.new(widget_parent, js.JSON.parse(json.dumps(config.to_dict())))

Initializes the calendar instance.

calendar

Calendar API Functions

def clear(self) -> None:
19    def clear(self) -> None:
20        """Clears the value set in the calendar."""
21        self.calendar.clear()

Clears the value set in the calendar.

def destructor(self) -> None:
23    def destructor(self) -> None:
24        """Removes a calendar instance and releases occupied resources."""
25        self.calendar.destructor()

Removes a calendar instance and releases occupied resources.

def get_current_mode(self) -> None:
27    def get_current_mode(self) -> str:
28        """Returns the current mode of displaying the Calendar."""
29        return self.calendar.getCurrentMode()

Returns the current mode of displaying the Calendar.

def get_value(self, as_date_obj: bool = False) -> Optional[List[NoneType]]:
31    def get_value(self, as_date_obj: bool = False) -> Union[Union[str, List[str]], Union[str, List[str]]]:
32        """Returns the selected date(s)."""
33        return self.calendar.getValue(as_date_obj)

Returns the selected date(s).

def paint(self) -> None:
39    def paint(self) -> None:
40        """Repaints the calendar on a page."""
41        self.calendar.paint()

Repaints the calendar on a page.

def set_value(self, value: Optional[List[NoneType]]) -> bool:
43    def set_value(self, value: Union[str, List[str], str, List[str]]) -> bool:
44        """Selects a date in the calendar."""
45        return self.calendar.setValue(value)

Selects a date in the calendar.

def show_date(self, date: NoneType = None, mode: None = 'calendar') -> None:
47    def show_date(self, date: Union[str, str] = None, mode: str = "calendar") -> None:
48        """Shows a specified date and/or opens the calendar in one of the available modes."""
49        self.calendar.showDate(date, mode)

Shows a specified date and/or opens the calendar in one of the available modes.

def add_event_handler(self, event_name: None, handler: Callable) -> None:
53    def add_event_handler(self, event_name: str, handler: Callable) -> None:
54        """Helper method to dynamically add event handlers."""
55        event_proxy = create_proxy(handler)
56        self.calendar.events[event_name] = event_proxy

Helper method to dynamically add event handlers.

def before_change( self, handler: Callable[[NoneType, NoneType, bool], Optional[bool]]) -> None:
58    def before_change(self, handler: Callable[[str, str, bool], Union[bool, None]]) -> None:
59        """Fires before the change of date selection."""
60        self.add_event_handler('beforeChange', handler)

Fires before the change of date selection.

def cancel_click(self, handler: Callable[[], NoneType]) -> None:
62    def cancel_click(self, handler: Callable[[], None]) -> None:
63        """Fires when the user clicks on the 'Cancel' control."""
64        self.add_event_handler('cancelClick', handler)

Fires when the user clicks on the 'Cancel' control.

def change(self, handler: Callable[[NoneType, NoneType, bool], NoneType]) -> None:
66    def change(self, handler: Callable[[str, str, bool], None]) -> None:
67        """Fires on change of date selection."""
68        self.add_event_handler('change', handler)

Fires on change of date selection.

def date_mouse_over(self, handler: Callable[[NoneType, NoneType], NoneType]) -> None:
70    def date_mouse_over(self, handler: Callable[[str, str], None]) -> None:
71        """Fires when the mouse pointer is over a date."""
72        self.add_event_handler('dateMouseOver', handler)

Fires when the mouse pointer is over a date.

def mode_change(self, handler: Callable[[NoneType], NoneType]) -> None:
74    def mode_change(self, handler: Callable[[str], None]) -> None:
75        """Fires on change of the calendar mode."""
76        self.add_event_handler('modeChange', handler)

Fires on change of the calendar mode.

def month_selected(self, handler: Callable[[int], NoneType]) -> None:
78    def month_selected(self, handler: Callable[[int], None]) -> None:
79        """Fires after a month was selected in the calendar."""
80        self.add_event_handler('monthSelected', handler)

Fires after a month was selected in the calendar.

def year_selected(self, handler: Callable[[int], NoneType]) -> None:
82    def year_selected(self, handler: Callable[[int], None]) -> None:
83        """Fires after a year was selected in the calendar."""
84        self.add_event_handler('yearSelected', handler)

Fires after a year was selected in the calendar.

css: None
88    @property
89    def css(self) -> str:
90        """Optional. Adds style classes to the calendar."""
91        return self.calendar.css

Optional. Adds style classes to the calendar.

date: NoneType
 97    @property
 98    def date(self) -> Union[str, str]:
 99        """Optional. Defines the date that will be opened when the calendar is created."""
100        return self.calendar.date

Optional. Defines the date that will be opened when the calendar is created.

date_format: None
106    @property
107    def date_format(self) -> str:
108        """Optional. Defines the format of dates in the calendar."""
109        return self.calendar.dateFormat

Optional. Defines the format of dates in the calendar.

disabled_dates: Callable[[NoneType], bool]
115    @property
116    def disabled_dates(self) -> Callable[[str], bool]:
117        """Optional. Allows disabling some date intervals."""
118        return self.calendar.disabledDates

Optional. Allows disabling some date intervals.

mark: Callable[[NoneType], NoneType]
124    @property
125    def mark(self) -> Callable[[str], str]:
126        """Optional. Adds a CSS class to specific days."""
127        return self.calendar.mark

Optional. Adds a CSS class to specific days.

mode: None
133    @property
134    def mode(self) -> str:
135        """Optional. The mode of Calendar initialization."""
136        return self.calendar.mode

Optional. The mode of Calendar initialization.

range: bool
142    @property
143    def range(self) -> bool:
144        """Optional. Enables/disables the possibility to select a range of dates."""
145        return self.calendar.range

Optional. Enables/disables the possibility to select a range of dates.

this_month_only: bool
151    @property
152    def this_month_only(self) -> bool:
153        """Optional. Hides dates of the previous/next months relative to the currently displayed one."""
154        return self.calendar.thisMonthOnly

Optional. Hides dates of the previous/next months relative to the currently displayed one.

time_format: int
160    @property
161    def time_format(self) -> int:
162        """Optional. Defines the time format for the timepicker in the calendar."""
163        return self.calendar.timeFormat

Optional. Defines the time format for the timepicker in the calendar.

time_picker: bool
169    @property
170    def time_picker(self) -> bool:
171        """Optional. Adds a timepicker into the calendar."""
172        return self.calendar.timePicker

Optional. Adds a timepicker into the calendar.

value: Optional[List[NoneType]]
178    @property
179    def value(self) -> Union[str, List[str], str, List[str]]:
180        """Optional. Selects the day(s) (adds a round blue marker)."""
181        return self.calendar.value

Optional. Selects the day(s) (adds a round blue marker).

week_numbers: bool
187    @property
188    def week_numbers(self) -> bool:
189        """Optional. Defines whether to show the numbers of weeks."""
190        return self.calendar.weekNumbers

Optional. Defines whether to show the numbers of weeks.

week_start: None
196    @property
197    def week_start(self) -> str:
198        """Optional. Sets the starting day of the week."""
199        return self.calendar.weekStart

Optional. Sets the starting day of the week.

width: Optional[int]
205    @property
206    def width(self) -> Union[str, int]:
207        """Optional. Sets the width of the calendar."""
208        return self.calendar.width

Optional. Sets the width of the calendar.

class CalendarConfig(dhxpyt.calendar.calendar_config.ControlConfig):
 8class CalendarConfig(ControlConfig):
 9    """Configuration class for Calendar."""
10    def __init__(self,
11                 date: Union[str, Any] = None,
12                 date_format: str = "%d/%m/%y",
13                 disabled_dates: Callable[[Any], bool] = None,
14                 mark: Callable[[Any], str] = None,
15                 mode: str = "calendar",
16                 range: bool = False,
17                 this_month_only: bool = False,
18                 time_format: int = 24,
19                 time_picker: bool = False,
20                 value: Union[str, Any, List[Union[str, Any]]] = None,
21                 week_numbers: bool = False,
22                 week_start: str = "sunday",
23                 css: str = None,
24                 width: Union[int, str] = "250px"):
25        self.date = date
26        self.date_format = date_format
27        self.disabled_dates = disabled_dates
28        self.mark = mark
29        self.mode = mode
30        self.range = range
31        self.this_month_only = this_month_only
32        self.time_format = time_format
33        self.time_picker = time_picker
34        self.value = value
35        self.week_numbers = week_numbers
36        self.week_start = week_start
37        self.css = css
38        self.width = width

Configuration class for Calendar.

CalendarConfig( date: Union[str, Any] = None, date_format: str = '%d/%m/%y', disabled_dates: Callable[[Any], bool] = None, mark: Callable[[Any], str] = None, mode: str = 'calendar', range: bool = False, this_month_only: bool = False, time_format: int = 24, time_picker: bool = False, value: Union[str, Any, List[Union[str, Any]]] = None, week_numbers: bool = False, week_start: str = 'sunday', css: str = None, width: Union[int, str] = '250px')
10    def __init__(self,
11                 date: Union[str, Any] = None,
12                 date_format: str = "%d/%m/%y",
13                 disabled_dates: Callable[[Any], bool] = None,
14                 mark: Callable[[Any], str] = None,
15                 mode: str = "calendar",
16                 range: bool = False,
17                 this_month_only: bool = False,
18                 time_format: int = 24,
19                 time_picker: bool = False,
20                 value: Union[str, Any, List[Union[str, Any]]] = None,
21                 week_numbers: bool = False,
22                 week_start: str = "sunday",
23                 css: str = None,
24                 width: Union[int, str] = "250px"):
25        self.date = date
26        self.date_format = date_format
27        self.disabled_dates = disabled_dates
28        self.mark = mark
29        self.mode = mode
30        self.range = range
31        self.this_month_only = this_month_only
32        self.time_format = time_format
33        self.time_picker = time_picker
34        self.value = value
35        self.week_numbers = week_numbers
36        self.week_start = week_start
37        self.css = css
38        self.width = width
date
date_format
disabled_dates
mark
mode
range
this_month_only
time_format
time_picker
value
week_numbers
week_start
css
width