Example #1
0
    def remove_entry(self):
        # Obtain the index and widget of the currently shown plot entry
        index = get_box_value(self.plot_entries, int)
        name = get_box_value(self.plot_entries, str)
        widget = self.plot_pages.currentWidget()

        # If index is -1, return
        if (index == -1):
            return

        # Show a warning message asking if the user really wants to remove it
        # TODO: Should this be removed once changes can be discarded?
        button_clicked = GW.QMessageBox.warning(
            self, "WARNING: Delete plot",
            ("Are you sure you want to delete the plot with name <b>%s</b>? "
             "(<i>Note: This action is irreversible!</i>)" % (name)),
            GW.QMessageBox.Yes | GW.QMessageBox.No, GW.QMessageBox.No)

        # Remove the entry and page at this index if the user answered 'yes'
        if (button_clicked == GW.QMessageBox.Yes):
            self.plot_entries.removeItem(index)
            self.plot_pages.removeWidget(widget)
            widget.setParent(None)
            widget.close()
            del widget
Example #2
0
    def get_box_value(self, *value_sig):
        """
        Returns the current values of this entries box as a dict.

        Returns
        -------
        entries_dict : dict
            A dict with the entries currently in this entries box, formatted as
            `{'<entry_name>': <entry_value>}`.

        """

        # Create an empty dict to hold the entry values in
        entries_dict = dict()

        # Loop over all entries in the entries grid and save them to the dict
        for i in range(4, 4 + 3 * self.entryCount(), 3):
            # Obtain the name of this entry
            name_box = self.entries_grid.itemAt(i).widget()
            entry_name = get_box_value(name_box)

            # If the entry_name is invalid, skip this entry
            if not self.is_valid(name_box):
                continue

            # Obtain the value of this entry
            value_box = self.entries_grid.itemAt(i + 1).widget()
            entry_value = get_box_value(value_box)

            # Add this entry to the dict
            entries_dict[entry_name] = entry_value

        # Return entries_dict
        return (entries_dict)
Example #3
0
    def hideEvent(self, *args, **kwargs):
        # Set the column name and dtype
        self.set_column_name(get_box_value(self.name_box))
        self.set_column_dtype(get_box_value(self.dtype_box))

        # Tell data table to update the header of the requested column
        self.data_table.h_header.headerDataChanged(QC.Qt.Horizontal, self.col,
                                                   self.col)

        # Call super event
        super().hideEvent(*args, **kwargs)
Example #4
0
    def get_box_value(self, *value_sig):
        # Obtain value of checkbox
        check = get_box_value(self.checkbox)

        # If True, value is obtained from the widget
        if check:
            value = get_box_value(self.widget, *value_sig)
        else:
            value = self.untoggled

        # Return value
        return(value)
Example #5
0
    def update_plot(self):
        # Draw the plot
        self.draw_plot()

        # If scatter currently exists, update it
        if self.plot is not None:
            # Set label
            self.plot.set_label(get_box_value(self.data_label_box))

            # Update marker style, size and color
            self.plot.set_marker(get_box_value(self.marker_style_box))
            self.plot.set_markersize(get_box_value(self.marker_size_box))
            self.plot.set_markeredgecolor(get_box_value(self.marker_color_box))
            self.plot.set_markerfacecolor(get_box_value(self.marker_color_box))
Example #6
0
    def get_box_value(self, *value_sig):
        """
        Returns the current values of this figure label box as a tuple.

        Returns
        -------
        value : tuple
            A tuple containing the values of the figure label box, formatted as
            `(label, {'fontsize': size})`.

        """

        return(get_box_value(self.left_box),
               {'fontsize': get_box_value(self.right_box)})
Example #7
0
    def get_box_value(self, *value_sig):
        """
        Returns the current values of this items box as a list.

        Returns
        -------
        value_list : list
            A list with the values of all items currently in this items box.

        """

        # Create an empty list to hold the item values in
        value_list = []

        # Loop over all items in the items form and save them to the list
        for i in range(self.itemCount()):
            # Obtain the value of this entry
            item_layout = self.items_layout.itemAt(i)
            item_box = item_layout.itemAt(1).widget()
            item_value = get_box_value(item_box)

            # Add this item to the list if it is not None
            if item_value is not None:
                value_list.append(item_value)

        # Return value_list
        return (value_list)
Example #8
0
    def apply_table_dimensions(self):
        # Obtain the values of the dimensions_box
        n_rows, n_cols = get_box_value(self.dimensions_box)

        # Set the rows and columns in the model
        self.view.setRowCount(n_rows)
        self.view.setColumnCount(n_cols)
Example #9
0
    def init(self):
        # Check if this class has been initialized before, and do so if not
        if not self.init_flag:
            self.first_init()

        # Create a layout for this widget
        box_layout = GL.QHBoxLayout(self)
        box_layout.setContentsMargins(0, 0, 0, 0)

        # Create a combobox for cmaps
        cmaps_box = GW.EditableComboBox()
        validator = GW.ComboBoxValidator(cmaps_box)
        cmaps_box.setValidator(validator)

        # Add all colormaps to cmaps_box
        for cmap in self.cmaps_cl:
            cmap_icon = self.cmap_icons[cmap]
            cmaps_box.addItem(cmap_icon, cmap)

        # Add some separators
        for i in reversed(self.cum_len[:-2]):
            cmaps_box.insertSeparator(i)

        # Set remaining properties
        set_box_value(cmaps_box, rcParams['image.cmap'])
        cmaps_box.setIconSize(QC.QSize(*self.cmap_size))
        cmaps_box.completer().popup().setIconSize(QC.QSize(*self.cmap_size))
        get_modified_signal(cmaps_box, str).connect(self.cmap_selected)
        cmaps_box.focusLost.connect(
            lambda: set_box_value(cmaps_box, get_box_value(cmaps_box, int)))

        # Add cmaps_box to layout
        box_layout.addWidget(cmaps_box)
        self.cmaps_box = cmaps_box
Example #10
0
    def remove_item(self, item_layout):
        """
        Removes the item associated with the provided `item_layout` from the
        items box.

        """

        # Obtain the value in the layout
        item_box = item_layout.itemAt(1).widget()
        item_value = get_box_value(item_box)

        # If item_value is not None, a modified signal must be emitted later
        emit_signal = (item_value is not None)

        # Remove corresponding item layout
        self.items_layout.removeItem(item_layout)

        # Remove the two items in item_layout
        for _ in range(2):
            # Remove the current item at index 0
            item = item_layout.takeAt(0)

            # Close the widget in this item and delete it
            item.widget().close()
            del item

        # Emit modified signal if required
        if emit_signal:
            self.modified.emit()
Example #11
0
    def update_plot(self):
        # Draw the plot
        self.draw_plot()

        # If histograms currently exist, update them
        if self.plot is not None:
            # Obtain the labels and colors of all elements
            labels = get_box_value(self.multi_data_box, 'data_label_box')
            colors = get_box_value(self.multi_data_box, 'hist_color_box')

            for i, (plot, label,
                    color) in enumerate(zip(self.plot, labels, colors)):
                # Set label
                plot.set_label(label)

                # Update bin colors
                for patch in plot.patches:
                    patch.set_color(color)
Example #12
0
    def get_box_value(self, *value_sig):
        # Obtain the current index of this combobox
        index = get_box_value(self.combobox, int)

        # Obtain the corresponding user data
        value = self.combobox.itemData(index)

        # Return value
        return (value)
Example #13
0
    def get_box_value(self, *value_sig):
        # Use normal method
        value = get_box_value(self, *value_sig, no_custom=True)

        # If the returned value is a bool and bools are used, convert value
        if value in ('True', 'False', 'None') and self.uses_bools:
            value = literal_eval(value)

        # Return value
        return(value)
Example #14
0
    def add_options_entry(self, widget):
        """
        Adds the provided `widget` as an options entry to this options dialog.
        This allows for the values of `widget` to be tracked and potentially
        discarded/reverted.

        """

        # Add widget as an entry to options_dict
        self.options_dict[widget] = get_box_value(widget)
        get_modified_signal(widget).connect(self.enable_apply_button)
Example #15
0
    def set_legend(self):
        # Obtain the legend_flag
        flag, loc = get_box_value(self.legend_togglebox)

        # If flag is True, create a legend
        if flag:
            self.axis.legend(loc=loc)

        # Else, remove the current one if it exists
        elif self.axis.legend_ is not None:
            self.axis.legend_.remove()
Example #16
0
    def get_box_value(self, *value_sig):
        """
        Returns the current values of this togglebox as a tuple.

        Returns
        -------
        value : bool or tuple
            A tuple containing the values of the checkbox and widget, formatted
            as `(checkbox, widget)`.
            If `value_sig` contains type 'bool', only the value of `checkbox`
            is returned.

        """

        # If solely the value of the checkbox was requested, return it
        if bool in value_sig:
            return (get_box_value(self.checkbox))
        # Else, return the checkbox and widget values
        else:
            return (get_box_value(self.checkbox),
                    get_box_value(self.widget, *value_sig))
Example #17
0
    def get_box_value(self, *value_sig):
        """
        Returns the current color value of the color combobox.

        Returns
        -------
        color : str
            The current matplotlib color value.

        """

        # Return the value currently set
        return (get_box_value(self.color_combobox, *value_sig))
Example #18
0
    def draw_plot(self):
        # Obtain the x and y columns
        try:
            xcol = get_box_value(self.x_data_box)[1]
            ycol = get_box_value(self.y_data_box)[1]
        # If any of the columns cannot be called, return
        except IndexError:
            self.remove_plot()
            return

        # If either xcol or ycol is None, return
        if xcol is None or ycol is None:
            self.remove_plot()
            return

        # If xcol and ycol are not the same shape, return
        if (len(xcol) != len(ycol)):
            self.remove_plot()
            return

        # If the current saved scatter is not already in the figure, make one
        if self.plot not in self.axis.lines:
            # Make and update plot
            self.plot = self.axis.plot(xcol, ycol)[0]
            self.plot.set_linestyle('')

            # Obtain label currently set in label box
            label = get_box_value(self.data_label_box)

            # If label is not empty, reuse it in the plot
            if label:
                self.plot.set_label(label)
            # Else, obtain its label from MPL
            else:
                set_box_value(self.data_label_box, self.plot.get_label())

            # If the figure currently has no title, set it
            title_box = self.options.title_box[0]
            if not get_box_value(title_box):
                set_box_value(title_box, "%s vs. %s" % (xcol.name, ycol.name))

            # If the figure currently has no axes labels, set them
            x_label_box = self.options.x_label_box[0]
            y_label_box = self.options.y_label_box[0]
            if not (get_box_value(x_label_box) or get_box_value(y_label_box)):
                set_box_value(x_label_box, xcol.name)
                set_box_value(y_label_box, ycol.name)

        # If it does exist, check if it requires updating
        else:
            # Obtain the data currently used for this plot
            xcol_cur = self.plot.get_xdata()
            ycol_cur = self.plot.get_ydata()

            # If there are differences, update plot
            if not (xcol_cur == xcol).all():
                self.plot.set_xdata(xcol)
            if not (ycol_cur == ycol).all():
                self.plot.set_ydata(ycol)
Example #19
0
    def set_tab_name(self):
        """
        Sets the name of the tab that was being edited when this
        :obj:`~TabNameEditor` was called.

        """

        # Obtain the current text in the lineedit
        name = get_box_value(self)

        # If name is not empty, set name
        if name:
            # Set the name of the tab indicated with index
            self.tabbar.setTabText(self.index, name)
Example #20
0
    def is_valid(self, name_box):
        # Determine the current value of the name_box
        entry_name = get_box_value(name_box)

        # Check if the name_box is editable
        if name_box.isEditable():
            # If so, check if its current input is valid
            valid = name_box.lineEdit().hasAcceptableInput()
        else:
            # If not, check if the current input is not empty
            valid = bool(entry_name)

        # Return valid
        return (valid)
Example #21
0
    def apply_options(self):
        """
        Applies all current values of all figure options.

        """

        # Emit the applying signal
        self.applying.emit()

        # Apply all new values
        for widget in self.options_dict.keys():
            self.options_dict[widget] = get_box_value(widget)

        # Disable the apply button
        self.disable_apply_button()
Example #22
0
    def set_box_value(self, value_list, *value_sig):
        """
        Sets the values of the items in this items box to the provided
        `value_list`.

        Parameters
        ----------
        value_list : list
            A list containing the values of all items that must be set in this
            items box.

        """

        # Hide the items box to allow for its values to be set properly
        self.hide()

        # Remove all items from the items box, registering their values
        cur_items_dict = {}
        for _ in range(self.itemCount()):
            # Remove this item and obtain its value
            layout = self.items_layout.takeAt(0)
            value = get_box_value(layout.itemAt(1).widget())

            # Check if it is required later
            if value in value_list:
                # If so, store for later
                cur_items_dict[value] = layout
            else:
                # If not, delete it
                self.remove_item(layout)

        # Add all items in value_list
        for row, value in enumerate(value_list):
            # Check if this value is in cur_items_dict
            if value in cur_items_dict:
                # If so, put it back into the items box
                self.items_layout.insertLayout(row, cur_items_dict.pop(value))
            else:
                # If not, add a new item
                self.add_item()

                # Set the value of this item
                item_layout = self.items_layout.itemAt(row)
                item_box = item_layout.itemAt(1).widget()
                set_box_value(item_box, value)

        # Show the items box again now that its values have been set
        self.show()
Example #23
0
    def get_box_value(self, *value_sig):
        """
        Returns the current value of the value box.

        Returns
        -------
        value : bool, float, int or str
            The current value of this generic value box.

        """

        # If value_box is currently a QWidget, return None
        if type(self.value_box) is GW.QWidget:
            return (None)
        # Else, return its actual value
        else:
            return (get_box_value(self.value_box, *value_sig))
Example #24
0
    def update_plot(self):
        # Draw the plot
        self.draw_plot()

        # If line currently exists, update it
        if self.plot is not None:
            # Set plot label
            self.plot.set_label(get_box_value(self.data_label_box))

            # Update line style, width and color
            self.plot.set_linestyle(get_box_value(self.line_style_box))
            self.plot.set_linewidth(get_box_value(self.line_width_box))
            self.plot.set_color(get_box_value(self.line_color_box))

            # Update marker style, size and color
            self.plot.set_marker(get_box_value(self.marker_style_box))
            self.plot.set_markersize(get_box_value(self.marker_size_box))
            self.plot.set_markeredgecolor(get_box_value(self.marker_color_box))
            self.plot.set_markerfacecolor(get_box_value(self.marker_color_box))
Example #25
0
    def get_box_value(self, *value_sig):
        """
        Returns the current colormap of the colormap box.

        Returns
        -------
        cmap : str or :obj:`~matplotlib.colors.Colormap` object
            The currently selected colormap.

        """

        # Obtain the value
        cmap = get_box_value(self.cmaps_box)

        # Obtain the Colormap object if requested
        if Colormap in value_sig:
            cmap = plt.get_cmap(cmap)

        # Return it
        return (cmap)
Example #26
0
    def get_box_value(self, *value_sig):
        """
        Returns the current values of this items box as a list.

        Returns
        -------
        items_list : object or list
            If `value_sig` contains a single index, the value of the
            corresponding item.
            Otherwise, a list with the values of all items in this items box.

        """

        # Check if value_sig contains an integer
        if value_sig and isinstance(value_sig[0], INT_TYPES):
            # If so, return the value of that specific item
            return (get_box_value(self.items[value_sig[0]], *value_sig[1:]))
        else:
            # If not, return the values of all items
            return (list(map(get_box_value, self.items)))
Example #27
0
    def get_box_value(self, *value_sig):
        """
        Returns the current values for the config section belonging to this
        config page.

        Returns
        -------
        config_dict : dict
            Dict containing the current config section values.

        """

        # Create empty dict of config values
        config_dict = sdict()

        # Retrieve values of all config entries
        for key, entry_box in self.config_entries.items():
            config_dict[key] = get_box_value(entry_box)

        # Return the config_dict
        return(config_dict)
Example #28
0
    def get_box_value(self, *value_sig):
        """
        Returns the index or text of the current radiobutton that is set to
        *True*.

        Returns
        -------
        value : int or str
            The index or text of the current radiobutton that is set to *True*.

        """

        # Obtain the index of the current radiobutton
        index = np.argmax(list(map(get_box_value, self.buttons)))

        # If value_sig is not int, return its text
        if int not in value_sig:
            return (get_box_value(self[index], str))
        # Else, return its index
        else:
            return (index)
Example #29
0
File: data.py Project: 1313e/GuiPy
    def get_box_value(self, *args, **kwargs):
        """
        Returns the currently selected data table and its associated column.

        Returns
        -------
        data_table : :obj:`~guipy.plugins.data_table.widgets.DataTableWidget` \
            object
            The data table that is currently set in this data column box.
        data_column : :obj:`~guipy.plugins.data_table.widgets.DataTableColumn`\
            object
            The data table column in `data_table` that is currently set.

        """

        # Obtain the currently selected column
        column_index = get_box_value(self.columns_box, int)

        # If currently a valid column is selected, return table and column
        if (column_index != -1):
            return (self.data_table, self.model.dataColumn(column_index))
        # Else, return (None, None)
        else:
            return (None, None)
Example #30
0
File: data.py Project: 1313e/GuiPy
    def remove_columns(self, parent, first, last):
        """
        Removes the columns from the columns box between given `first` and
        `last`.

        Parameters
        ----------
        parent : :obj:`~PyQt5.QtCore.QModelIndex` object
            The parent that was used in the data table model.
            This function does not need it.
        first : int
            The logical index of the first column that was removed.
        last : int
            The logical index of the last column that was removed.

        """

        # If the currently set column has been removed, set it to -1
        if get_box_value(self.columns_box, int) in range(first, last + 1):
            set_box_value(self.columns_box, -1)

        # Remove all columns between first and last+1 from the columns box
        for i in reversed(range(first, last + 1)):
            self.columns_box.removeItem(i)