dhxpyt.colorpicker
13class Colorpicker: 14 def __init__(self, config: ColorpickerConfig = None, widget_parent: Any = None): 15 """Initializes the Colorpicker instance.""" 16 if config is None: 17 config = ColorpickerConfig() 18 self.colorpicker = js.dhx.Colorpicker.new(widget_parent, js.JSON.parse(json.dumps(config.to_dict()))) 19 20 """ Colorpicker API Functions """ 21 22 def clear(self) -> None: 23 """Clears the value set in the colorpicker and removes focus.""" 24 self.colorpicker.clear() 25 26 def destructor(self) -> None: 27 """Releases the occupied resources.""" 28 self.colorpicker.destructor() 29 30 def get_current_mode(self) -> str: 31 """Returns the current mode of displaying Colorpicker ('palette' or 'picker').""" 32 return self.colorpicker.getCurrentMode() 33 34 def get_custom_colors(self) -> List[str]: 35 """Returns an array of selected custom colors.""" 36 return list(self.colorpicker.getCustomColors()) 37 38 def get_value(self) -> str: 39 """Returns the code of a selected color in the Hex format.""" 40 return self.colorpicker.getValue() 41 42 def paint(self) -> None: 43 """Repaints Colorpicker on a page.""" 44 self.colorpicker.paint() 45 46 def set_current_mode(self, view: str) -> None: 47 """Shows Colorpicker either in the 'palette' or 'picker' mode.""" 48 self.colorpicker.setCurrentMode(view) 49 50 def set_custom_colors(self, custom_colors: List[str]) -> None: 51 """Sets custom colors that will be displayed at the bottom of the palette.""" 52 self.colorpicker.setCustomColors(custom_colors) 53 54 def set_focus(self, value: str) -> None: 55 """Sets focus on the specified color value.""" 56 self.colorpicker.setFocus(value) 57 58 def set_value(self, value: str) -> None: 59 """Selects a color in Colorpicker.""" 60 self.colorpicker.setValue(value) 61 62 """ Colorpicker Events """ 63 64 def add_event_handler(self, event_name: str, handler: Callable) -> None: 65 """Helper to add event handlers dynamically.""" 66 event_proxy = create_proxy(handler) 67 self.colorpicker.events.on(event_name, event_proxy) 68 69 def on_apply(self, handler: Callable[[], None]) -> None: 70 """Fires on clicking the 'Select' button.""" 71 self.add_event_handler('apply', handler) 72 73 def on_before_change(self, handler: Callable[[str], Union[bool, None]]) -> None: 74 """Fires before changing the selected color in Colorpicker.""" 75 def event_handler(color): 76 result = handler(color) 77 if result is False: 78 return js.Boolean(False) 79 # Do not return anything to allow the change 80 event_proxy = create_proxy(event_handler) 81 self.colorpicker.events.on('beforeChange', event_proxy) 82 83 def on_cancel_click(self, handler: Callable[[], None]) -> None: 84 """Fires on clicking the 'Cancel' button.""" 85 self.add_event_handler('cancelClick', handler) 86 87 def on_change(self, handler: Callable[[str], None]) -> None: 88 """Fires on changing the selected color in Colorpicker.""" 89 self.add_event_handler('change', handler) 90 91 def on_mode_change(self, handler: Callable[[str], None]) -> None: 92 """Fires on changing the mode of the colorpicker.""" 93 self.add_event_handler('modeChange', handler) 94 95 """ Colorpicker Properties """ 96 97 @property 98 def css(self) -> str: 99 """Gets or sets custom CSS classes for Colorpicker.""" 100 return self.colorpicker.config.css 101 102 @css.setter 103 def css(self, value: str) -> None: 104 self.colorpicker.config.css = value 105 106 @property 107 def custom_colors(self) -> List[str]: 108 """Gets or sets custom colors displayed at the bottom of Colorpicker.""" 109 return self.colorpicker.config.customColors 110 111 @custom_colors.setter 112 def custom_colors(self, value: List[str]) -> None: 113 self.colorpicker.config.customColors = value 114 115 @property 116 def gray_shades(self) -> bool: 117 """Gets or sets whether the gray shades are displayed in the palette.""" 118 return self.colorpicker.config.grayShades 119 120 @gray_shades.setter 121 def gray_shades(self, value: bool) -> None: 122 self.colorpicker.config.grayShades = value 123 124 @property 125 def mode(self) -> str: 126 """Gets or sets the mode of displaying the colorpicker ('palette' or 'picker').""" 127 return self.colorpicker.config.mode 128 129 @mode.setter 130 def mode(self, value: str) -> None: 131 self.colorpicker.config.mode = value 132 133 @property 134 def palette(self) -> List[List[str]]: 135 """Gets or sets the arrays of colors shown in the colorpicker.""" 136 return self.colorpicker.config.palette 137 138 @palette.setter 139 def palette(self, value: List[List[str]]) -> None: 140 self.colorpicker.config.palette = value 141 142 @property 143 def palette_only(self) -> bool: 144 """Gets or sets whether Colorpicker is shown only in the palette mode.""" 145 return self.colorpicker.config.paletteOnly 146 147 @palette_only.setter 148 def palette_only(self, value: bool) -> None: 149 self.colorpicker.config.paletteOnly = value 150 151 @property 152 def picker_only(self) -> bool: 153 """Gets or sets whether Colorpicker is shown only in the picker mode.""" 154 return self.colorpicker.config.pickerOnly 155 156 @picker_only.setter 157 def picker_only(self, value: bool) -> None: 158 self.colorpicker.config.pickerOnly = value 159 160 @property 161 def transparency(self) -> bool: 162 """Gets or sets whether the transparency scale is displayed in the picker mode.""" 163 return self.colorpicker.config.transparency 164 165 @transparency.setter 166 def transparency(self, value: bool) -> None: 167 self.colorpicker.config.transparency = value 168 169 @property 170 def width(self) -> Union[str, int]: 171 """Gets or sets the width of Colorpicker.""" 172 return self.colorpicker.config.width 173 174 @width.setter 175 def width(self, value: Union[str, int]) -> None: 176 self.colorpicker.config.width = value
14 def __init__(self, config: ColorpickerConfig = None, widget_parent: Any = None): 15 """Initializes the Colorpicker instance.""" 16 if config is None: 17 config = ColorpickerConfig() 18 self.colorpicker = js.dhx.Colorpicker.new(widget_parent, js.JSON.parse(json.dumps(config.to_dict())))
Initializes the Colorpicker instance.
22 def clear(self) -> None: 23 """Clears the value set in the colorpicker and removes focus.""" 24 self.colorpicker.clear()
Clears the value set in the colorpicker and removes focus.
26 def destructor(self) -> None: 27 """Releases the occupied resources.""" 28 self.colorpicker.destructor()
Releases the occupied resources.
30 def get_current_mode(self) -> str: 31 """Returns the current mode of displaying Colorpicker ('palette' or 'picker').""" 32 return self.colorpicker.getCurrentMode()
Returns the current mode of displaying Colorpicker ('palette' or 'picker').
34 def get_custom_colors(self) -> List[str]: 35 """Returns an array of selected custom colors.""" 36 return list(self.colorpicker.getCustomColors())
Returns an array of selected custom colors.
38 def get_value(self) -> str: 39 """Returns the code of a selected color in the Hex format.""" 40 return self.colorpicker.getValue()
Returns the code of a selected color in the Hex format.
46 def set_current_mode(self, view: str) -> None: 47 """Shows Colorpicker either in the 'palette' or 'picker' mode.""" 48 self.colorpicker.setCurrentMode(view)
Shows Colorpicker either in the 'palette' or 'picker' mode.
50 def set_custom_colors(self, custom_colors: List[str]) -> None: 51 """Sets custom colors that will be displayed at the bottom of the palette.""" 52 self.colorpicker.setCustomColors(custom_colors)
Sets custom colors that will be displayed at the bottom of the palette.
54 def set_focus(self, value: str) -> None: 55 """Sets focus on the specified color value.""" 56 self.colorpicker.setFocus(value)
Sets focus on the specified color value.
58 def set_value(self, value: str) -> None: 59 """Selects a color in Colorpicker.""" 60 self.colorpicker.setValue(value)
Selects a color in Colorpicker.
64 def add_event_handler(self, event_name: str, handler: Callable) -> None: 65 """Helper to add event handlers dynamically.""" 66 event_proxy = create_proxy(handler) 67 self.colorpicker.events.on(event_name, event_proxy)
Helper to add event handlers dynamically.
69 def on_apply(self, handler: Callable[[], None]) -> None: 70 """Fires on clicking the 'Select' button.""" 71 self.add_event_handler('apply', handler)
Fires on clicking the 'Select' button.
73 def on_before_change(self, handler: Callable[[str], Union[bool, None]]) -> None: 74 """Fires before changing the selected color in Colorpicker.""" 75 def event_handler(color): 76 result = handler(color) 77 if result is False: 78 return js.Boolean(False) 79 # Do not return anything to allow the change 80 event_proxy = create_proxy(event_handler) 81 self.colorpicker.events.on('beforeChange', event_proxy)
Fires before changing the selected color in Colorpicker.
83 def on_cancel_click(self, handler: Callable[[], None]) -> None: 84 """Fires on clicking the 'Cancel' button.""" 85 self.add_event_handler('cancelClick', handler)
Fires on clicking the 'Cancel' button.
87 def on_change(self, handler: Callable[[str], None]) -> None: 88 """Fires on changing the selected color in Colorpicker.""" 89 self.add_event_handler('change', handler)
Fires on changing the selected color in Colorpicker.
91 def on_mode_change(self, handler: Callable[[str], None]) -> None: 92 """Fires on changing the mode of the colorpicker.""" 93 self.add_event_handler('modeChange', handler)
Fires on changing the mode of the colorpicker.
97 @property 98 def css(self) -> str: 99 """Gets or sets custom CSS classes for Colorpicker.""" 100 return self.colorpicker.config.css
Gets or sets custom CSS classes for Colorpicker.
106 @property 107 def custom_colors(self) -> List[str]: 108 """Gets or sets custom colors displayed at the bottom of Colorpicker.""" 109 return self.colorpicker.config.customColors
Gets or sets custom colors displayed at the bottom of Colorpicker.
115 @property 116 def gray_shades(self) -> bool: 117 """Gets or sets whether the gray shades are displayed in the palette.""" 118 return self.colorpicker.config.grayShades
Gets or sets whether the gray shades are displayed in the palette.
124 @property 125 def mode(self) -> str: 126 """Gets or sets the mode of displaying the colorpicker ('palette' or 'picker').""" 127 return self.colorpicker.config.mode
Gets or sets the mode of displaying the colorpicker ('palette' or 'picker').
133 @property 134 def palette(self) -> List[List[str]]: 135 """Gets or sets the arrays of colors shown in the colorpicker.""" 136 return self.colorpicker.config.palette
Gets or sets the arrays of colors shown in the colorpicker.
142 @property 143 def palette_only(self) -> bool: 144 """Gets or sets whether Colorpicker is shown only in the palette mode.""" 145 return self.colorpicker.config.paletteOnly
Gets or sets whether Colorpicker is shown only in the palette mode.
151 @property 152 def picker_only(self) -> bool: 153 """Gets or sets whether Colorpicker is shown only in the picker mode.""" 154 return self.colorpicker.config.pickerOnly
Gets or sets whether Colorpicker is shown only in the picker mode.
5class ColorpickerConfig: 6 """ 7 Configuration class for Colorpicker. Contains properties to customize the colorpicker. 8 """ 9 def __init__(self, 10 css: str = None, 11 customColors: List[str] = None, 12 grayShades: bool = True, 13 mode: str = "palette", 14 palette: List[List[str]] = None, 15 paletteOnly: bool = False, 16 pickerOnly: bool = False, 17 transparency: bool = True, 18 width: Union[str, int] = "238px"): 19 """ 20 :param css: (Optional) Adds custom CSS classes to Colorpicker. 21 :param customColors: (Optional) Shows custom colors at the bottom of Colorpicker. 22 :param grayShades: (Optional) Displays the section with gray shades in the palette. 23 :param mode: (Optional) Specifies the mode of displaying the colorpicker ("palette" or "picker"). 24 :param palette: (Optional) Arrays of colors to show in the colorpicker. 25 :param paletteOnly: (Optional) Shows Colorpicker only in the palette mode. 26 :param pickerOnly: (Optional) Shows Colorpicker only in the picker mode. 27 :param transparency: (Optional) Displays the transparency scale in the picker mode. 28 :param width: (Optional) Sets the width of Colorpicker. 29 """ 30 self.css = css 31 self.customColors = customColors 32 self.grayShades = grayShades 33 self.mode = mode 34 self.palette = palette 35 self.paletteOnly = paletteOnly 36 self.pickerOnly = pickerOnly 37 self.transparency = transparency 38 self.width = width 39 40 def to_dict(self) -> Dict[str, Any]: 41 """ 42 Converts the ColorpickerConfig into a dictionary format that can be 43 passed into the colorpicker constructor. 44 """ 45 config_dict = { 46 'css': self.css, 47 'customColors': self.customColors, 48 'grayShades': self.grayShades, 49 'mode': self.mode, 50 'palette': self.palette, 51 'paletteOnly': self.paletteOnly, 52 'pickerOnly': self.pickerOnly, 53 'transparency': self.transparency, 54 'width': self.width 55 } 56 # Remove None values to avoid passing undefined properties 57 return {k: v for k, v in config_dict.items() if v is not None}
Configuration class for Colorpicker. Contains properties to customize the colorpicker.
9 def __init__(self, 10 css: str = None, 11 customColors: List[str] = None, 12 grayShades: bool = True, 13 mode: str = "palette", 14 palette: List[List[str]] = None, 15 paletteOnly: bool = False, 16 pickerOnly: bool = False, 17 transparency: bool = True, 18 width: Union[str, int] = "238px"): 19 """ 20 :param css: (Optional) Adds custom CSS classes to Colorpicker. 21 :param customColors: (Optional) Shows custom colors at the bottom of Colorpicker. 22 :param grayShades: (Optional) Displays the section with gray shades in the palette. 23 :param mode: (Optional) Specifies the mode of displaying the colorpicker ("palette" or "picker"). 24 :param palette: (Optional) Arrays of colors to show in the colorpicker. 25 :param paletteOnly: (Optional) Shows Colorpicker only in the palette mode. 26 :param pickerOnly: (Optional) Shows Colorpicker only in the picker mode. 27 :param transparency: (Optional) Displays the transparency scale in the picker mode. 28 :param width: (Optional) Sets the width of Colorpicker. 29 """ 30 self.css = css 31 self.customColors = customColors 32 self.grayShades = grayShades 33 self.mode = mode 34 self.palette = palette 35 self.paletteOnly = paletteOnly 36 self.pickerOnly = pickerOnly 37 self.transparency = transparency 38 self.width = width
Parameters
- css: (Optional) Adds custom CSS classes to Colorpicker.
- customColors: (Optional) Shows custom colors at the bottom of Colorpicker.
- grayShades: (Optional) Displays the section with gray shades in the palette.
- mode: (Optional) Specifies the mode of displaying the colorpicker ("palette" or "picker").
- palette: (Optional) Arrays of colors to show in the colorpicker.
- paletteOnly: (Optional) Shows Colorpicker only in the palette mode.
- pickerOnly: (Optional) Shows Colorpicker only in the picker mode.
- transparency: (Optional) Displays the transparency scale in the picker mode.
- width: (Optional) Sets the width of Colorpicker.
40 def to_dict(self) -> Dict[str, Any]: 41 """ 42 Converts the ColorpickerConfig into a dictionary format that can be 43 passed into the colorpicker constructor. 44 """ 45 config_dict = { 46 'css': self.css, 47 'customColors': self.customColors, 48 'grayShades': self.grayShades, 49 'mode': self.mode, 50 'palette': self.palette, 51 'paletteOnly': self.paletteOnly, 52 'pickerOnly': self.pickerOnly, 53 'transparency': self.transparency, 54 'width': self.width 55 } 56 # Remove None values to avoid passing undefined properties 57 return {k: v for k, v in config_dict.items() if v is not None}
Converts the ColorpickerConfig into a dictionary format that can be passed into the colorpicker constructor.