def create_type_alpha(self): # Make double spinbox for alpha alpha_box = QW_QDoubleSpinBox() alpha_box.setRange(0, 1) set_box_value(alpha_box, 1) alpha_box.setToolTip("Alpha value to use for the plotted data") return(alpha_box)
def set_color(self, color): """ Sets the current color to the provided `color`, and updates the entry in the combobox and the label accordingly. %(qt_slot)s Parameters ---------- color : str The color that needs to be used as the current color. The provided `color` can be any string that is accepted as a color by matplotlib. If `color` is invalid, it is set to the current default color instead. """ # If color can be converted to a hex integer, do so and add hash to it try: int(color, 16) except ValueError: pass else: # Make sure that color has a length of 6 if (len(color) == 6): color = "#%s" % (color) # Set the color label default_flag = self.set_color_label(color) # If default was not used, set the combobox to the proper value as well if not default_flag: set_box_value(self.color_combobox, color)
def create_type_markersize(self): # Make a double spinbox for markersize markersize_box = QW_QDoubleSpinBox() markersize_box.setRange(0, 9999999) markersize_box.setSuffix(" pts") markersize_box.setToolTip("Size of the plotted markers") set_box_value(markersize_box, rcParams['lines.markersize']) return(markersize_box)
def create_type_linewidth(self): # Make a double spinbox for linewidth linewidth_box = QW_QDoubleSpinBox() linewidth_box.setRange(0, 9999999) linewidth_box.setSuffix(" pts") set_box_value(linewidth_box, rcParams['lines.linewidth']) linewidth_box.setToolTip("Width of the plotted line") return(linewidth_box)
def create_type_dpi(self): # Make spinbox for dpi dpi_box = QW_QSpinBox() dpi_box.setRange(1, 9999999) set_box_value(dpi_box, rcParams['figure.dpi']) dpi_box.setToolTip("DPI (dots per inch) to use for the projection " "figure") return(dpi_box)
def discard_value(self): """ Qt slot that discards the current value and sets it back to its saved value. """ set_box_value(self._box, self._value)
def reset_value(self): """ Qt slot that resets the current value of this options entry to its default value. """ set_box_value(self._box, self._default)
def set_box_value(self, value): """ Sets the current value of the figsize box to `value`. Parameters ---------- value : tuple A tuple containing the width and height values of the figsize, formatted as `(width, height)`. """ set_box_value(self.width_box, value[0]) set_box_value(self.height_box, value[1])
def set_box_value(self, value): """ Sets the value type to `type(value)` and the field value to `value`. Parameters ---------- value : bool, float, int or str The value to use for this default box. The type of `value` determines which field box must be used. """ set_box_value(self.type_box, self.type_dict[type(value)]) set_box_value(self.value_box, value)
def create_type_linestyle(self): # Obtain list with all supported linestyles linestyles_lst = [(key, value[6:]) for key, value in lineStyles.items() if value != '_draw_nothing'] linestyles_lst.sort(key=lambda x: x[0]) # Make combobox for linestyles linestyle_box = QW_QComboBox() for i, (linestyle, tooltip) in enumerate(linestyles_lst): linestyle_box.addItem(linestyle) linestyle_box.setItemData(i, tooltip, QC.Qt.ToolTipRole) set_box_value(linestyle_box, rcParams['lines.linestyle']) linestyle_box.setToolTip("Linestyle to be used for the corresponding " "plot type") return(linestyle_box)
def create_type_marker(self): # Obtain list with all supported markers markers_lst = [(key, value) for key, value in lineMarkers.items() if(value != 'nothing' and isinstance(key, str))] markers_lst.append(('', 'nothing')) markers_lst.sort(key=lambda x: x[0]) # Make combobox for markers marker_box = QW_QComboBox() for i, (marker, tooltip) in enumerate(markers_lst): marker_box.addItem(marker) marker_box.setItemData(i, tooltip, QC.Qt.ToolTipRole) set_box_value(marker_box, rcParams['lines.marker']) marker_box.setToolTip("Marker to be used for the corresponding plot " "type") return(marker_box)
def set_box_value(self, cmap): """ Sets the current colormap to `cmap`. Parameters ---------- cmap : :obj:`~matplotlib.colors.Colormap` object The colormap that must be used for this colormap box. """ # Obtain the name of the provided colormap name = cmap.name # Set this as the current colormap set_box_value(self.cmaps_box, name)
def init(self): """ Sets up the figure size entry after it has been initialized. This function is mainly responsible for simply creating the two double spinboxes that allow for the width and height to be set. """ # Create the box_layout box_layout = QW.QHBoxLayout(self) box_layout.setContentsMargins(0, 0, 0, 0) self.setToolTip("Figure size dimensions to use for the projection " "figure") # Create two double spinboxes for the width and height # WIDTH width_box = QW_QDoubleSpinBox() width_box.setRange(1, 9999999) width_box.setSuffix("'") width_box.setStepType(width_box.AdaptiveDecimalStepType) width_box.setToolTip("Width (in inches) of projection figure") self.width_box = width_box # HEIGHT height_box = QW_QDoubleSpinBox() height_box.setRange(1, 9999999) height_box.setSuffix("'") height_box.setToolTip("Height (in inches) of projection figure") self.height_box = height_box # Also create a textlabel with 'X' x_label = QW.QLabel('X') x_label.setSizePolicy(QW.QSizePolicy.Fixed, QW.QSizePolicy.Fixed) # Add everything to the box_layout box_layout.addWidget(width_box) box_layout.addWidget(x_label) box_layout.addWidget(height_box) # Set default value set_box_value(self, rcParams['figure.figsize'])
def set_box_value(self, page_dict): """ Sets the current value of the kwargs dict page to `page_dict`. Parameters ---------- page_dict : dict A dict containing all entries that this kwargs dict page must have. Current entries that are also in `page_dict` will be reused, otherwise they are deleted. """ # Make empty dict containing all current valid entries cur_entry_dict = sdict() # Remove all entries from kwargs_grid for row in range(1, self.kwargs_grid.rowCount()): # Obtain item that should contain the entry_type in this row entry_type_item = self.kwargs_grid.itemAtPosition(row, 1) # If entry_type_item is None, this row contains no items if entry_type_item is None: continue # Obtain the entry_type entry_type = get_box_value(entry_type_item.widget()) # Delete this entry if not in page_dict or if it is not allowed if(entry_type not in page_dict or not entry_type or entry_type in self.banned_entries): self.remove_editable_entry(entry_type_item.widget()) continue # If this entry appears multiple times, delete its previous entry if entry_type in cur_entry_dict: for item in cur_entry_dict[entry_type]: item.widget().close() del item cur_entry_dict.pop(entry_type) # Add this entry to cur_entry_dict cur_entry_dict[entry_type] =\ [self.kwargs_grid.takeAt(3) for _ in range(3)] # Loop over all items in page_dict and act accordingly for row, (entry_type, field_value) in enumerate(page_dict.items(), 1): # Check if this entry_type already existed if entry_type in cur_entry_dict: # If so, put it back into kwargs_grid for col, item in enumerate(cur_entry_dict[entry_type]): self.kwargs_grid.addItem(item, row, col) else: # If not, add it to kwargs_grid self.add_editable_entry() # Set this new entry to the proper type set_box_value(self.kwargs_grid.itemAtPosition(row, 1).widget(), entry_type) # Set the value of the corresponding field set_box_value(self.kwargs_grid.itemAtPosition(row, 2).widget(), field_value)
def init(self): # Define set of CMasher colormaps that should be at the top cmr_cmaps = sset( ['dusk', 'freeze', 'gothic', 'heat', 'rainforest', 'sunburst']) # Check that all of those colormaps are available in CMasher cmr_cmaps.intersection_update(cmr.cm.cmap_d) # Obtain a set with default MPL colormaps that should be at the top std_cmaps = sset(['cividis', 'inferno', 'magma', 'plasma', 'viridis']) # Add CMasher colormaps to it std_cmaps.update(['cmr.' + cmap for cmap in cmr_cmaps]) # Obtain reversed set of recommended colormaps std_cmaps_r = sset([cmap + '_r' for cmap in std_cmaps]) # Obtain a list with all colormaps and their reverses all_cmaps = sset( [cmap for cmap in cm.cmap_d if not cmap.endswith('_r')]) all_cmaps_r = sset([cmap for cmap in cm.cmap_d if cmap.endswith('_r')]) # Gather all sets together cmaps = (std_cmaps, std_cmaps_r, all_cmaps, all_cmaps_r) # Determine the cumulative lengths of all four sets cum_len = np.cumsum(list(map(len, cmaps))) # Set the size for the colormap previews cmap_size = (100, 15) # If the colormap icons have not been created yet, do that now if not hasattr(self, 'cmap_icons'): cmap_icons = sdict() for cmap in chain(all_cmaps, all_cmaps_r): cmap_icons[cmap] = self.create_cmap_icon(cmap, cmap_size) ColorMapBox.cmap_icons = cmap_icons # Create a layout for this widget box_layout = QW.QHBoxLayout(self) box_layout.setContentsMargins(0, 0, 0, 0) self.setToolTip("Colormap to be used for the corresponding plot type") # Create a combobox for cmaps cmaps_box = QW_QComboBox() for cmap in chain(*cmaps): cmap_icon = self.cmap_icons[cmap] cmaps_box.addItem(cmap_icon, cmap) # Add some separators for i in reversed(cum_len[:-1]): cmaps_box.insertSeparator(i) cmaps_box.insertSeparator(cum_len[1] + 1) # Set remaining properties set_box_value(cmaps_box, rcParams['image.cmap']) cmaps_box.setIconSize(QC.QSize(*cmap_size)) cmaps_box.currentTextChanged.connect(self.cmap_selected) # Add cmaps_box to layout box_layout.addWidget(cmaps_box) self.cmaps_box = cmaps_box