dhxpyt.timepicker
class
Timepicker:
14class Timepicker: 15 def __init__(self, config: TimepickerConfig = None, widget_parent: str = None): 16 """ 17 Initializes the TimePicker widget. 18 19 :param config: (Optional) The TimePickerConfig object containing the timepicker configuration. 20 :param widget_parent: (Optional) The ID of the HTML element where the timepicker will be attached. 21 """ 22 if config is None: 23 config = TimepickerConfig() 24 config_dict = config.to_dict() 25 26 # Create the TimePicker instance 27 self.timepicker = js.dhx.TimePicker.new(widget_parent, js.JSON.parse(json.dumps(config_dict))) 28 29 30 """ TimePicker API Functions """ 31 32 def clear(self) -> None: 33 """Clears the value set in the timepicker.""" 34 self.timepicker.clear() 35 36 def destructor(self) -> None: 37 """Destroys the timepicker instance and releases occupied resources.""" 38 self.timepicker.destructor() 39 40 def get_value(self, as_object: bool = False) -> Union[Dict[str, int], str]: 41 """ 42 Returns the current value of a TimePicker. 43 44 :param as_object: (Optional) Specifies that the value will be returned as an object. False by default. 45 :return: Either an object or a string with the value of the timepicker. 46 """ 47 return self.timepicker.getValue(as_object) 48 49 def paint(self) -> None: 50 """Repaints a timepicker on a page.""" 51 self.timepicker.paint() 52 53 def set_value(self, value: Union[Dict[str, int], str, int, list, object]) -> None: 54 """ 55 Sets value for a TimePicker. 56 57 :param value: The value to be set for a timepicker. 58 """ 59 self.timepicker.setValue(value) 60 61 """ TimePicker Event Handlers """ 62 63 def add_event_handler(self, event_name: str, handler: Callable) -> None: 64 """ 65 Adds an event handler for the specified event. 66 67 :param event_name: The name of the event. 68 :param handler: The handler function to attach. 69 """ 70 event_proxy = create_proxy(handler) 71 self.timepicker.events.on(event_name, event_proxy) 72 73 def on_after_apply(self, handler: Callable[[Union[str, Dict[str, int]]], None]) -> None: 74 """ 75 Fires after saving the timepicker value. 76 77 :param handler: The handler function with parameter value (str or dict). 78 """ 79 def event_handler(value): 80 handler(value) 81 self.timepicker.events.on('afterApply', create_proxy(event_handler)) 82 83 def on_after_close(self, handler: Callable[[Union[str, Dict[str, int]]], None]) -> None: 84 """ 85 Fires after closing the timepicker. 86 87 :param handler: The handler function with parameter value (str or dict). 88 """ 89 def event_handler(value): 90 handler(value) 91 self.timepicker.events.on('afterClose', create_proxy(event_handler)) 92 93 def on_before_apply(self, handler: Callable[[Union[str, Dict[str, int]]], Union[bool, None]]) -> None: 94 """ 95 Fires before saving the timepicker value. 96 97 :param handler: The handler function with parameter value (str or dict). Return False to prevent saving. 98 """ 99 def event_handler(value): 100 result = handler(value) 101 if result is False: 102 return js.Boolean(False) 103 self.timepicker.events.on('beforeApply', create_proxy(event_handler)) 104 105 def on_before_change(self, handler: Callable[[Union[str, Dict[str, int]]], Union[bool, None]]) -> None: 106 """ 107 Fires before change of the timepicker value. 108 109 :param handler: The handler function with parameter value (str or dict). Return False to prevent changing. 110 """ 111 def event_handler(value): 112 result = handler(value) 113 if result is False: 114 return js.Boolean(False) 115 self.timepicker.events.on('beforeChange', create_proxy(event_handler)) 116 117 def on_before_close(self, handler: Callable[[Union[str, Dict[str, int]]], Union[bool, None]]) -> None: 118 """ 119 Fires before closing the timepicker. 120 121 :param handler: The handler function with parameter value (str or dict). Return False to prevent closing. 122 """ 123 def event_handler(value): 124 result = handler(value) 125 if result is False: 126 return js.Boolean(False) 127 self.timepicker.events.on('beforeClose', create_proxy(event_handler)) 128 129 def on_change(self, handler: Callable[[Union[str, Dict[str, int]]], None]) -> None: 130 """ 131 Fires on change of the timepicker value. 132 133 :param handler: The handler function with parameter value (str or dict). 134 """ 135 def event_handler(value): 136 handler(value) 137 self.timepicker.events.on('change', create_proxy(event_handler))
Timepicker( config: TimepickerConfig = None, widget_parent: str = None)
15 def __init__(self, config: TimepickerConfig = None, widget_parent: str = None): 16 """ 17 Initializes the TimePicker widget. 18 19 :param config: (Optional) The TimePickerConfig object containing the timepicker configuration. 20 :param widget_parent: (Optional) The ID of the HTML element where the timepicker will be attached. 21 """ 22 if config is None: 23 config = TimepickerConfig() 24 config_dict = config.to_dict() 25 26 # Create the TimePicker instance 27 self.timepicker = js.dhx.TimePicker.new(widget_parent, js.JSON.parse(json.dumps(config_dict)))
Initializes the TimePicker widget.
Parameters
- config: (Optional) The TimePickerConfig object containing the timepicker configuration.
- widget_parent: (Optional) The ID of the HTML element where the timepicker will be attached.
def
clear(self) -> None:
32 def clear(self) -> None: 33 """Clears the value set in the timepicker.""" 34 self.timepicker.clear()
Clears the value set in the timepicker.
def
destructor(self) -> None:
36 def destructor(self) -> None: 37 """Destroys the timepicker instance and releases occupied resources.""" 38 self.timepicker.destructor()
Destroys the timepicker instance and releases occupied resources.
def
get_value(self, as_object: bool = False) -> Union[Dict[str, int], str]:
40 def get_value(self, as_object: bool = False) -> Union[Dict[str, int], str]: 41 """ 42 Returns the current value of a TimePicker. 43 44 :param as_object: (Optional) Specifies that the value will be returned as an object. False by default. 45 :return: Either an object or a string with the value of the timepicker. 46 """ 47 return self.timepicker.getValue(as_object)
Returns the current value of a TimePicker.
Parameters
- as_object: (Optional) Specifies that the value will be returned as an object. False by default.
Returns
Either an object or a string with the value of the timepicker.
def
set_value(self, value: Union[Dict[str, int], str, int, list, object]) -> None:
53 def set_value(self, value: Union[Dict[str, int], str, int, list, object]) -> None: 54 """ 55 Sets value for a TimePicker. 56 57 :param value: The value to be set for a timepicker. 58 """ 59 self.timepicker.setValue(value)
Sets value for a TimePicker.
Parameters
- value: The value to be set for a timepicker.
def
add_event_handler(self, event_name: str, handler: Callable) -> None:
63 def add_event_handler(self, event_name: str, handler: Callable) -> None: 64 """ 65 Adds an event handler for the specified event. 66 67 :param event_name: The name of the event. 68 :param handler: The handler function to attach. 69 """ 70 event_proxy = create_proxy(handler) 71 self.timepicker.events.on(event_name, event_proxy)
Adds an event handler for the specified event.
Parameters
- event_name: The name of the event.
- handler: The handler function to attach.
def
on_after_apply(self, handler: Callable[[Union[str, Dict[str, int]]], NoneType]) -> None:
73 def on_after_apply(self, handler: Callable[[Union[str, Dict[str, int]]], None]) -> None: 74 """ 75 Fires after saving the timepicker value. 76 77 :param handler: The handler function with parameter value (str or dict). 78 """ 79 def event_handler(value): 80 handler(value) 81 self.timepicker.events.on('afterApply', create_proxy(event_handler))
Fires after saving the timepicker value.
Parameters
- handler: The handler function with parameter value (str or dict).
def
on_after_close(self, handler: Callable[[Union[str, Dict[str, int]]], NoneType]) -> None:
83 def on_after_close(self, handler: Callable[[Union[str, Dict[str, int]]], None]) -> None: 84 """ 85 Fires after closing the timepicker. 86 87 :param handler: The handler function with parameter value (str or dict). 88 """ 89 def event_handler(value): 90 handler(value) 91 self.timepicker.events.on('afterClose', create_proxy(event_handler))
Fires after closing the timepicker.
Parameters
- handler: The handler function with parameter value (str or dict).
def
on_before_apply( self, handler: Callable[[Union[str, Dict[str, int]]], Optional[bool]]) -> None:
93 def on_before_apply(self, handler: Callable[[Union[str, Dict[str, int]]], Union[bool, None]]) -> None: 94 """ 95 Fires before saving the timepicker value. 96 97 :param handler: The handler function with parameter value (str or dict). Return False to prevent saving. 98 """ 99 def event_handler(value): 100 result = handler(value) 101 if result is False: 102 return js.Boolean(False) 103 self.timepicker.events.on('beforeApply', create_proxy(event_handler))
Fires before saving the timepicker value.
Parameters
- handler: The handler function with parameter value (str or dict). Return False to prevent saving.
def
on_before_change( self, handler: Callable[[Union[str, Dict[str, int]]], Optional[bool]]) -> None:
105 def on_before_change(self, handler: Callable[[Union[str, Dict[str, int]]], Union[bool, None]]) -> None: 106 """ 107 Fires before change of the timepicker value. 108 109 :param handler: The handler function with parameter value (str or dict). Return False to prevent changing. 110 """ 111 def event_handler(value): 112 result = handler(value) 113 if result is False: 114 return js.Boolean(False) 115 self.timepicker.events.on('beforeChange', create_proxy(event_handler))
Fires before change of the timepicker value.
Parameters
- handler: The handler function with parameter value (str or dict). Return False to prevent changing.
def
on_before_close( self, handler: Callable[[Union[str, Dict[str, int]]], Optional[bool]]) -> None:
117 def on_before_close(self, handler: Callable[[Union[str, Dict[str, int]]], Union[bool, None]]) -> None: 118 """ 119 Fires before closing the timepicker. 120 121 :param handler: The handler function with parameter value (str or dict). Return False to prevent closing. 122 """ 123 def event_handler(value): 124 result = handler(value) 125 if result is False: 126 return js.Boolean(False) 127 self.timepicker.events.on('beforeClose', create_proxy(event_handler))
Fires before closing the timepicker.
Parameters
- handler: The handler function with parameter value (str or dict). Return False to prevent closing.
def
on_change(self, handler: Callable[[Union[str, Dict[str, int]]], NoneType]) -> None:
129 def on_change(self, handler: Callable[[Union[str, Dict[str, int]]], None]) -> None: 130 """ 131 Fires on change of the timepicker value. 132 133 :param handler: The handler function with parameter value (str or dict). 134 """ 135 def event_handler(value): 136 handler(value) 137 self.timepicker.events.on('change', create_proxy(event_handler))
Fires on change of the timepicker value.
Parameters
- handler: The handler function with parameter value (str or dict).
class
TimepickerConfig:
5class TimepickerConfig: 6 """ 7 Configuration class for the TimePicker widget. 8 """ 9 10 def __init__(self, 11 value: Union[Dict[str, int], str, int, list, object] = None, 12 controls: bool = False, 13 css: str = None, 14 timeFormat: int = 24, 15 valueFormat: str = None): 16 """ 17 Initializes the TimePickerConfig. 18 19 :param value: (Optional) The time value to be set on initialization of the timepicker. 20 :param controls: (Optional) Defines whether a timepicker is equipped with the Close and Save buttons. Default is False. 21 :param css: (Optional) Adds style classes to TimePicker. 22 :param timeFormat: (Optional) Defines what clock format is activated: the 12-hour or 24-hour one. Default is 24. 23 :param valueFormat: (Optional) Defines the format of the value to be applied when working with TimePicker events. 24 """ 25 self.value = value 26 self.controls = controls 27 self.css = css 28 self.timeFormat = timeFormat 29 self.valueFormat = valueFormat 30 31 def to_dict(self) -> Dict[str, Any]: 32 """ 33 Converts the TimePickerConfig into a dictionary format. 34 """ 35 config_dict = { 36 'value': self.value, 37 'controls': self.controls, 38 'css': self.css, 39 'timeFormat': self.timeFormat, 40 'valueFormat': self.valueFormat, 41 } 42 # Remove None values 43 config_dict = {k: v for k, v in config_dict.items() if v is not None} 44 return config_dict
Configuration class for the TimePicker widget.
TimepickerConfig( value: Union[Dict[str, int], str, int, list, object] = None, controls: bool = False, css: str = None, timeFormat: int = 24, valueFormat: str = None)
10 def __init__(self, 11 value: Union[Dict[str, int], str, int, list, object] = None, 12 controls: bool = False, 13 css: str = None, 14 timeFormat: int = 24, 15 valueFormat: str = None): 16 """ 17 Initializes the TimePickerConfig. 18 19 :param value: (Optional) The time value to be set on initialization of the timepicker. 20 :param controls: (Optional) Defines whether a timepicker is equipped with the Close and Save buttons. Default is False. 21 :param css: (Optional) Adds style classes to TimePicker. 22 :param timeFormat: (Optional) Defines what clock format is activated: the 12-hour or 24-hour one. Default is 24. 23 :param valueFormat: (Optional) Defines the format of the value to be applied when working with TimePicker events. 24 """ 25 self.value = value 26 self.controls = controls 27 self.css = css 28 self.timeFormat = timeFormat 29 self.valueFormat = valueFormat
Initializes the TimePickerConfig.
Parameters
- value: (Optional) The time value to be set on initialization of the timepicker.
- controls: (Optional) Defines whether a timepicker is equipped with the Close and Save buttons. Default is False.
- css: (Optional) Adds style classes to TimePicker.
- timeFormat: (Optional) Defines what clock format is activated: the 12-hour or 24-hour one. Default is 24.
- valueFormat: (Optional) Defines the format of the value to be applied when working with TimePicker events.
def
to_dict(self) -> Dict[str, Any]:
31 def to_dict(self) -> Dict[str, Any]: 32 """ 33 Converts the TimePickerConfig into a dictionary format. 34 """ 35 config_dict = { 36 'value': self.value, 37 'controls': self.controls, 38 'css': self.css, 39 'timeFormat': self.timeFormat, 40 'valueFormat': self.valueFormat, 41 } 42 # Remove None values 43 config_dict = {k: v for k, v in config_dict.items() if v is not None} 44 return config_dict
Converts the TimePickerConfig into a dictionary format.