def RGB_colourspace_models_chromatically_adapted_primaries_widget(): title_Label = Label( 'RGB Colourspace Models Chromatically Adapted Primaries') title_Label.add_class('widget-title') default_layout = {'flex': '1 1 auto', 'width': 'auto'} input_colourspace_Dropdown = Dropdown( options=sorted(colour.RGB_COLOURSPACES), layout=default_layout) illuminant_Dropdown = Dropdown( options=sorted( colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']), layout=default_layout) chromatic_adaptation_transforms_Dropdown = Dropdown( options=sorted(colour.CHROMATIC_ADAPTATION_TRANSFORMS), layout=default_layout) formatter_Dropdown = Dropdown( options=['str', 'repr'], layout=default_layout) decimals_IntSlider = IntSlider(value=10, max=15, layout=default_layout) primaries_Textarea = Textarea(rows=3, layout=default_layout) primaries_Textarea.add_class('widget-output-textarea') def set_primaries_Textarea(): input_colourspace = colour.RGB_COLOURSPACES[ input_colourspace_Dropdown.value] P = colour.chromatically_adapted_primaries( input_colourspace.primaries, input_colourspace.whitepoint, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer'][ illuminant_Dropdown.value], chromatic_adaptation_transforms_Dropdown.value) with colour.utilities.numpy_print_options( formatter={ 'float': ('{{:0.{0}f}}'.format(decimals_IntSlider.value)).format }, threshold=np.nan): if formatter_Dropdown.value == 'str': P = str(P) elif formatter_Dropdown.value == 'repr': P = repr(P) primaries_Textarea.rows = len(P.split('\n')) primaries_Textarea.value = P def on_input_change(change): if change['type'] == 'change' and change['name'] == 'value': set_primaries_Textarea() input_colourspace_Dropdown.observe(on_input_change) illuminant_Dropdown.observe(on_input_change) chromatic_adaptation_transforms_Dropdown.observe(on_input_change) formatter_Dropdown.observe(on_input_change) decimals_IntSlider.observe(on_input_change) set_primaries_Textarea() widget = Box([ VBox( [ title_Label, Textarea( 'This widget computes the Chromatically Adapted Primaries ' 'of the given RGB Colourspace Model to the given ' 'Illuminant using the ' 'given Chromatic Adaptation Transform.', rows=3, layout=default_layout), Label('Input RGB Colourspace'), input_colourspace_Dropdown, Label('Illuminant'), illuminant_Dropdown, Label('Chromatic Adaptation Transform'), chromatic_adaptation_transforms_Dropdown, Label('Formatter'), formatter_Dropdown, HBox([Label('Decimals:'), decimals_IntSlider]), Label('RGB Transformation Matrix'), primaries_Textarea, ], layout={ 'border': 'solid 2px', 'width': '55%' }) ]) return widget
def RGB_colourspace_models_transformation_matrix_widget(): title_Label = Label('RGB Colourspace Models Transformation Matrix') title_Label.add_class('widget-title') default_layout = {'flex': '1 1 auto', 'width': 'auto'} input_colourspace_Dropdown = Dropdown( options=sorted(colour.RGB_COLOURSPACES), layout=default_layout) output_colourspace_Dropdown = Dropdown( options=sorted(colour.RGB_COLOURSPACES), layout=default_layout) chromatic_adaptation_transforms_Dropdown = Dropdown( options=sorted(colour.CHROMATIC_ADAPTATION_TRANSFORMS), layout=default_layout) formatter_Dropdown = Dropdown( options=['str', 'repr', 'Nuke'], layout=default_layout) decimals_IntSlider = IntSlider(value=10, max=15, layout=default_layout) RGB_to_RGB_matrix_Textarea = Textarea(rows=3, layout=default_layout) RGB_to_RGB_matrix_Textarea.add_class('widget-output-textarea') def set_RGB_to_RGB_matrix_Textarea(): M = colour.RGB_to_RGB_matrix( colour.RGB_COLOURSPACES[input_colourspace_Dropdown.value], colour.RGB_COLOURSPACES[output_colourspace_Dropdown.value], chromatic_adaptation_transforms_Dropdown.value) with colour.utilities.numpy_print_options( formatter={ 'float': ('{{:0.{0}f}}'.format(decimals_IntSlider.value)).format }, threshold=np.nan): if formatter_Dropdown.value == 'str': M = str(M) elif formatter_Dropdown.value == 'repr': M = repr(M) else: M = NUKE_COLORMATRIX_NODE_TEMPLATE.format( nuke_format_matrix(M, decimals_IntSlider.value), '{0}_to_{1}'.format( input_colourspace_Dropdown.value.replace(' ', '_'), output_colourspace_Dropdown.value.replace(' ', '_'))) RGB_to_RGB_matrix_Textarea.rows = len(M.split('\n')) RGB_to_RGB_matrix_Textarea.value = M def on_input_change(change): if change['type'] == 'change' and change['name'] == 'value': set_RGB_to_RGB_matrix_Textarea() input_colourspace_Dropdown.observe(on_input_change) output_colourspace_Dropdown.observe(on_input_change) chromatic_adaptation_transforms_Dropdown.observe(on_input_change) formatter_Dropdown.observe(on_input_change) decimals_IntSlider.observe(on_input_change) set_RGB_to_RGB_matrix_Textarea() widget = Box([ VBox( [ title_Label, Textarea( 'This widget computes the colour transformation ' 'matrix from the Input RGB Colourspace to the ' 'Output RGB Colourspace using the given ' 'Chromatic Adaptation Transform.', rows=2, layout=default_layout), Label('Input RGB Colourspace'), input_colourspace_Dropdown, Label('Output RGB Colourspace'), output_colourspace_Dropdown, Label('Chromatic Adaptation Transform'), chromatic_adaptation_transforms_Dropdown, Label('Formatter'), formatter_Dropdown, HBox([Label('Decimals:'), decimals_IntSlider]), Label('RGB Transformation Matrix'), RGB_to_RGB_matrix_Textarea, ], layout={ 'border': 'solid 2px', 'width': '55%' }) ]) return widget
class IntEditor(_Editor): """TODO: Add docstring here """ _model_name = Unicode('IntEditorModel').tag(sync=True) _view_name = Unicode('IntEditorView').tag(sync=True) __slider = None __min_ipt = None __max_ipt = None __step_ipt = None value = Int(0).tag(sync=False) min = Int(0).tag(sync=False) max = Int(0).tag(sync=False) step = Int(0).tag(sync=False) def __init__(self, value, type='Float', min=1, max=10, step=1, **kwargs): self.value = int(value) description = kwargs[ 'name'] if 'no_name' in kwargs and kwargs['no_name'] else 'value' self.__slider = IntSlider(value, min, max, description=description, continuous_update=False) # self.__min_ipt = IntText(min, description='min') # self.__max_ipt = IntText(max, description='max') # self.__step_ipt = BoundedIntText(step, description='step', min=1, step=step) self.__slider.observe(self.__on_slider_changed, names='value') # self.__min_ipt.observe(self.__on_min_changed, names='value') # self.__max_ipt.observe(self.__on_max_changed, names='value') # self.__step_ipt.observe(self.__on_step_changed, names='value') kwargs['children'] = [ self.__slider, # self.__min_ipt, # self.__max_ipt, # self.__step_ipt ] super().__init__(**kwargs) # def __on_min_changed(self, change): # if self.__min_ipt.value < self.__slider.max: # self.__slider.min = self.__min_ipt.value # else: # self.__min_ipt.value = self.__slider.max - self.__step_ipt.value # self.min = self.__min_ipt.value # def __on_max_changed(self, change): # if self.__max_ipt.value > self.__slider.min: # self.__slider.max = self.__max_ipt.value # else: # self.__max_ipt.value = self.__slider.min + self.__step_ipt.value # self.max = self.__max_ipt.value # def __on_step_changed(self, change): # self.__slider.step = self.__step_ipt.value # self.step = self.__step_ipt.value def __on_slider_changed(self, change): self.value = self.__slider.value