예제 #1
0
 def clr_picker(clr, cache=False):
     if cache:
         clr_picker = ColorPicker(concise=True, value=to_hex(self.colormap[clr][0:3]), 
                 disabled=False, layout=Layout(width="30px"))
     else:
         clr_picker = ColorPicker(concise=True, value=to_hex(self.colormap[clr][0:3]), 
                 disabled=False, layout=Layout(width="25px", margin="0 0 0 8px"))
     clr_picker.observing = True
     def handle_color_picker(change):
         self.colormap[clr] = to_rgba(change.new, 1)
         self.model.plot.colormap = ListedColormap(self.colormap)
         self.model.plot.backend.plot._update_image()
     clr_picker.observe(handle_color_picker, names='value')
     self.colorpickers[clr] = clr_picker
     return clr_picker
예제 #2
0
    def display_rendering_settings(self):
        """Display visual controls for renderer settings"""
        def update_params(_):
            """Update renderer params"""
            self._client.set_renderer(
                accumulation=checkbox_accumulation.value,
                background_color=matplotlib.colors.to_rgb(
                    colorpicker_background.value),
                head_light=checkbox_head_light.value,
                samples_per_pixel=slider_samples_per_pixel.value,
                max_accum_frames=slider_max_accum_frames.value,
                subsampling=slider_sub_sampling.value)

        params = self._client.get_renderer()
        slider_samples_per_pixel = IntSlider(description='Samples per pixel',
                                             min=1,
                                             max=1024,
                                             value=params['samples_per_pixel'])
        slider_samples_per_pixel.observe(update_params)
        slider_max_accum_frames = IntSlider(
            description='Max accumulation frames',
            min=1,
            max=1024,
            value=params['max_accum_frames'])
        slider_max_accum_frames.observe(update_params, 'value')
        slider_sub_sampling = IntSlider(description='Sub-sampling',
                                        min=1,
                                        max=16,
                                        value=params['subsampling'])
        slider_sub_sampling.observe(update_params, 'value')
        colorpicker_background = ColorPicker(description='Background color',
                                             value=matplotlib.colors.to_hex(
                                                 params['background_color']))
        colorpicker_background.observe(update_params, 'value')
        checkbox_head_light = Checkbox(description='Head light',
                                       value=params['head_light'])
        checkbox_head_light.observe(update_params, 'value')
        checkbox_accumulation = Checkbox(description='Accumulation',
                                         value=params['accumulation'])
        checkbox_accumulation.observe(update_params, 'value')
        hbox_1 = HBox([
            slider_samples_per_pixel, slider_sub_sampling,
            slider_max_accum_frames
        ])
        hbox_2 = HBox([
            colorpicker_background, checkbox_head_light, checkbox_accumulation
        ])
        display(VBox([hbox_1, hbox_2], layout=DEFAULT_GRID_LAYOUT))
예제 #3
0
        def clr_picker(enum_color, cache=False, miss_acc=False):
            '''

            '''
            def handle_color_picker(change):
                print(enum_color, change)
                self.colormap[enum_color] = to_rgba(change.new, 1)
                self.model.plot.colormap = ListedColormap(self.colormap)
                self.model.plot.backend.plot.update_image()
            

            if cache:
                clr_picker = ColorPicker(concise=True, value=to_hex(self.colormap[enum_color][0:3]), 
                        disabled=False, layout=Layout(width="30px"))
            else:
                clr_picker = ColorPicker(concise=True, value=to_hex(self.colormap[enum_color][0:3]), 
                        disabled=False, layout=Layout(width="25px", margin="0 4px 0 4px"))
            
            clr_picker.observe(handle_color_picker, names='value')
            self.colorpickers[enum_color] = clr_picker

            clr_picker.observing = True
            return clr_picker
예제 #4
0
def draw_roaming_ui():
    global iter_slider, reset_button, color_it_button, juliabrot_button, canvases
    global drawing, uly_select, ulx_select, color_list, picker1, picker2, bump_ud_slider, hue_slider, sat_slider, val_slider
    global lry_select, lrx_select, color_it, modulo_slider, picker3, bump_lr_slider, zoom_slider, save_button

    # This establishes the size of the preview gui
    drawing = False
    color_it = True
    uly_select = 0
    ulx_select = 0
    lry_select = jgrid.settings.sizeY
    lrx_select = jgrid.settings.sizeX
    canvases = MultiCanvas(3,
                           width=jgrid.settings.sizeX * 2.5,
                           height=jgrid.settings.sizeY + 75)
    canvases[drawing_layer].font = '25px serif'
    canvases[drawing_layer].fill_style = '#aaaaaa'
    canvases[drawing_layer].line_width = 3
    canvases[interaction_layer].font = '35px serif'
    canvases[interaction_layer].fill_style = '#eee800'
    canvases[interaction_layer].stroke_style = '#ffffff'
    canvases[interaction_layer].line_width = 3
    iter_slider = FloatLogSlider(description='Iterations:',
                                 base=10,
                                 value=jgrid.settings.max_iterations,
                                 min=1,
                                 max=7,
                                 step=.01,
                                 continuous_update=False)
    iter_slider.observe(handler=iter_slider_handler, names='value')
    max_lr_bump = jgrid.settings.sizeX
    max_ud_bump = jgrid.settings.sizeY
    bump_ud_slider = IntSlider(description='Bump UD pix:',
                               value=1,
                               min=0,
                               max=max_ud_bump,
                               step=1,
                               continuous_update=False)
    bump_lr_slider = IntSlider(description='Bump LR pix:',
                               value=1,
                               min=0,
                               max=max_lr_bump,
                               step=1,
                               continuous_update=False)
    zoom_slider = FloatSlider(description='Zoom:',
                              value=2.0,
                              min=0.0,
                              max=1000.0,
                              step=.001,
                              continuous_update=False)
    #zoom_slider.observe(handler=zoom_button_handler, names='value')
    hue_slider = FloatSlider(description='Hue :',
                             value=jgrid.settings.hue,
                             min=0.0,
                             max=1.0,
                             step=.001,
                             continuous_update=False)
    sat_slider = FloatSlider(description='Sat:',
                             value=jgrid.settings.sat,
                             min=0.0,
                             max=1.0,
                             step=.01,
                             continuous_update=False)
    val_slider = FloatSlider(description='Val:',
                             value=jgrid.settings.val,
                             min=0.0,
                             max=1.0,
                             step=.02,
                             continuous_update=False)
    hue_slider.observe(handler=hue_slider_handler, names='value')
    sat_slider.observe(handler=sat_slider_handler, names='value')
    val_slider.observe(handler=val_slider_handler, names='value')
    modulo_slider = IntSlider(description='Modulo:',
                              value=jgrid.settings.modulo,
                              min=1,
                              max=1000000,
                              step=1,
                              continuous_update=False)
    modulo_slider.observe(handler=modulo_slider_handler, names='value')
    canvases[interaction_layer].on_mouse_down(on_mouse_down)
    canvases[interaction_layer].on_mouse_move(on_mouse_move)
    reset_button = Button(description='Zoom',
                          disabled=False,
                          button_style='',
                          tooltip='Click to use zoom slider setting for zoom',
                          icon='')
    reset_button.on_click(zoom_button_handler)
    save_button = Button(description='Save',
                         disabled=False,
                         button_style='',
                         tooltip='Click to save as JSON settings file',
                         icon='')
    save_button.on_click(save_button_handler)
    color_it_button = Button(description='Color/BW',
                             disabled=False,
                             button_style='',
                             tooltip='Click for BW or Color',
                             icon='')
    color_it_button.on_click(color_button_handler)
    juliabrot_button = Button(description='JM Mode',
                              disabled=False,
                              button_style='',
                              tooltip='Click for Julia or Mandelbrot',
                              icon='')
    juliabrot_button.on_click(juliabrot_button_handler)
    undo_button = Button(description='Undo',
                         disabled=False,
                         button_style='',
                         tooltip='Click to revert to last view',
                         icon='')
    undo_button.on_click(undo_button_handler)
    bleft_button = Button(description='Bump L',
                          disabled=False,
                          button_style='',
                          tooltip='Click to nudge left num bump LR pixels',
                          icon='')
    bleft_button.on_click(bleft_button_handler)
    bright_button = Button(description='Bump R',
                           disabled=False,
                           button_style='',
                           tooltip='Click to nudge right num bump LR pixels',
                           icon='')
    bright_button.on_click(bright_button_handler)
    bup_button = Button(description='Bump U',
                        disabled=False,
                        button_style='',
                        tooltip='Click to nudge up num bump UD pixels',
                        icon='')
    bup_button.on_click(bup_button_handler)
    bdown_button = Button(description='Bump D',
                          disabled=False,
                          button_style='',
                          tooltip='Click to nudge down bump UD pixels',
                          icon='')
    bdown_button.on_click(bdown_button_handler)
    picker1 = ColorPicker(description='M Color:', value=jgrid.settings.m_color)
    #picker2 = ColorPicker(description='Color 1:', value='#fff800')
    #picker3 = ColorPicker(description='Color 2:', value='#fff800')
    picker1.observe(color_picker1_handler, names='value')
    #picker2.observe(color_picker2_handler, names='value')
    #picker3.observe(color_picker3_handler, names='value')
    color_list = Dropdown(disabled=False,
                          options=[('Rainbow', 1), ('Classic', 2), ('Log', 3),
                                   ('RGB Max Iter', 4), ('Rainbow 2', 5)],
                          value=jgrid.settings.color_mode,
                          description='Color Mode:',
                          tooltip='Select built-in coloring options')
    color_list.observe(color_select_handler, names='value')
    draw_fractal(canvases, jgrid.tile_list)
    display_info(canvases, jgrid)
    return AppLayout(center=canvases,
                     header=HBox((iter_slider, bump_ud_slider, bump_lr_slider,
                                  zoom_slider)),
                     right_sidebar=VBox(
                         (picker1, color_list, hue_slider, sat_slider,
                          val_slider, modulo_slider)),
                     footer=HBox(
                         (bleft_button, bright_button, bup_button,
                          bdown_button, color_it_button, juliabrot_button,
                          reset_button, undo_button, save_button)))
예제 #5
0
    def __init__(self,
                 position: str = "bottomleft",
                 attr_name: str = "style",
                 kind: str = "stroke",
                 orientation: str = "horizontal",
                 transparent: bool = False,
                 a_map: Map = None,
                 layer: Layer = None,
                 place_control: bool = True):
        """Add a widget to the map that allows styling some given layer.

        At the moment only the stroke color, opacity and weight can be changed
        using a color picker and sliders. Dash array might follow later.

        :param m: The map object to which to add a styling widget.
        :param layer: The layer object which is to be styled.
        :param attr_name: The layer's attribute name storing the style object.
            This is usually one of: "style", "hover_style", and "point_style"
        :param kind: The kind of style, either "stroke" or "fill".
        :param orientation: The orientation of the UI elements, either "horizontal"
            (default) or "vertical".
        :param transparent: A flag to indicate if the widget background should be
            transparent (default: ``False``). 
        :param position: The map corner where this widget will be placed. 

        TODO: The UI elements should reflect changes to the layer triggered by
              others. 
        """
        assert kind in ["stroke", "fill"]
        assert orientation in ["horizontal", "vertical"]

        def restyle(change):
            if change["type"] != "change":
                return
            owner = change["owner"]
            style_copy = copy.copy(getattr(layer, attr_name))
            attr_map = {
                p: "color" if kind == "stroke" else "fillColor",
                o: "opacity" if kind == "stroke" else "fillOpacity",
                w: "weight"
            }
            if owner in [p, o, w]:
                style_copy[attr_map[owner]] = owner.value
                setattr(layer, attr_name, style_copy)

        def close(button):
            a_map.remove_control(wc)

        attr = getattr(layer, attr_name)
        style = getattr(layer, "style")

        b = ToggleButton(description="Stroke",
                         value=True,
                         tooltip="Stroke or not?")
        dummy = ToggleButton(value=not b.value)
        b.layout.width = "80px"

        name = "color" if kind == "stroke" else "fillColor"
        p = ColorPicker(value=attr.get(name, style.get(name, "#3885ff")))
        p.layout.width = "100px"

        name = "opacity" if kind == "stroke" else "fillOpacity"
        o = FloatSlider(min=0,
                        max=1,
                        value=attr.get(name, style.get(name, 0.5)))
        o.layout.width = "200px"

        w = IntSlider(min=0,
                      max=50,
                      value=attr.get("weight", style.get("weight", 5)))
        w.layout.width = "200px"

        layout = Layout(width="28px", height="28px", padding="0px 0px 0px 4px")
        q = Button(tooltip="Close",
                   icon="close",
                   button_style="info",
                   layout=layout)

        for el in [p, o, w] if kind == "stroke" else [p, o]:
            link((dummy, "value"), (el, "disabled"))

        p.observe(restyle)
        o.observe(restyle)
        if kind == "stroke":
            w.observe(restyle)
        else:
            w.disabled = True
        q.on_click(close)

        desc = HTML(f"{kind} {attr_name}")

        if orientation == "horizontal":
            self.widget = HBox([desc, p, w, o, q])
        elif orientation == "vertical":
            self.widget = VBox([HBox([desc, q]), p, w, o])

        wc = WidgetControl(widget=self.widget,
                           position=position,
                           transparent_bg=transparent)
        a_map.add_control(wc)