Exemple #1
0
    def init(self):
        """
        Sets up the exception dialog after it has been initialized.

        This function is mainly responsible for gathering all required
        information; formatting it; and drawing the dialog.

        """

        # Create a window layout
        grid_layout = GL.QGridLayout(self)
        grid_layout.setColumnStretch(2, 1)
        grid_layout.setRowStretch(3, 1)

        # Set properties of message box
        self.setWindowModality(QC.Qt.ApplicationModal)
        self.setAttribute(QC.Qt.WA_DeleteOnClose)
        self.setWindowTitle("ERROR")
        self.setWindowFlags(QC.Qt.MSWindowsOwnDC | QC.Qt.Dialog
                            | QC.Qt.WindowTitleHint
                            | QC.Qt.WindowSystemMenuHint
                            | QC.Qt.WindowCloseButtonHint)

        # Set the icon of the exception on the left
        icon_label = GW.QLabel()
        pixmap = GW.QMessageBox.standardIcon(GW.QMessageBox.Critical)
        icon_label.setPixmap(pixmap)
        grid_layout.addWidget(icon_label, 0, 0, 2, 1, QC.Qt.AlignTop)

        # Add a spacer item
        spacer_item = QW.QSpacerItem(7, 1, QW.QSizePolicy.Fixed,
                                     QW.QSizePolicy.Fixed)
        grid_layout.addItem(spacer_item, 0, 1, 2, 1)

        # Set the text of the exception
        exc_str = self.format_exception()
        exc_label = GW.QLabel(exc_str)
        grid_layout.addWidget(exc_label, 0, 2, 1, 1)

        # Create a button box for the buttons
        button_box = QW.QDialogButtonBox()
        grid_layout.addWidget(button_box, 2, 0, 1, grid_layout.columnCount())

        # Create traceback box
        self.tb_box = self.create_traceback_box()
        grid_layout.addWidget(self.tb_box, 3, 0, 1, grid_layout.columnCount())

        # Create traceback button
        self.tb_but =\
            button_box.addButton(self.tb_labels[self.tb_box.isHidden()],
                                 button_box.ActionRole)
        self.tb_but.clicked.connect(self.toggle_traceback_box)

        # Create an 'ok' button
        ok_but = button_box.addButton(button_box.Ok)
        ok_but.clicked.connect(self.close)
        ok_but.setDefault(True)

        # Update the size
        self.update_size()
Exemple #2
0
    def init(self):
        """
        Sets up the entries box after it has been initialized.

        """

        # Set the height of a single entry
        self.entry_height = 24

        # Create empty dict of non-generic entry types
        self.entry_types = {}

        # Create empty dict of entry defaults
        self.entry_defaults = {}

        # Create empty set of banned entry names
        self.banned_names = sset()

        # Create the box_layout
        box_layout = GL.QVBoxLayout(self)
        box_layout.setContentsMargins(0, 0, 0, 0)

        # Create the entries_grid
        entries_grid = GL.QGridLayout()
        entries_grid.setContentsMargins(0, 0, 0, 0)
        entries_grid.setColumnStretch(1, 1)
        entries_grid.setColumnStretch(2, 2)
        box_layout.addLayout(entries_grid)
        self.entries_grid = entries_grid

        # Add a header
        entries_grid.addWidget(GW.QLabel(""), 0, 0)
        entries_grid.addWidget(GW.QLabel("Entry name"), 0, 1)
        entries_grid.addWidget(GW.QLabel("Entry value"), 0, 2)

        # Add an 'Add'-button
        add_but = GW.QToolButton()
        add_but.setFixedSize(self.entry_height, self.entry_height)
        add_but.setToolTip("Add new entry")
        get_modified_signal(add_but).connect(self.add_entry)
        box_layout.addWidget(add_but)

        # If this theme has an 'add' icon, use it
        if QG.QIcon.hasThemeIcon('add'):
            add_but.setIcon(QG.QIcon.fromTheme('add'))
        # Else, use a simple plus
        else:
            add_but.setText('+')

        # Set size policy
        self.setSizePolicy(QW.QSizePolicy.Preferred, QW.QSizePolicy.Fixed)

        # Set a minimum width for the first column
        self.entries_grid.setColumnMinimumWidth(0, self.entry_height)
Exemple #3
0
    def init(self, types, sep):
        """
        Sets up the dual spinbox after it has been initialized.

        """

        # Make dict with different line-edits
        box_types = {float: GW.QDoubleSpinBox, int: GW.QSpinBox}

        # Save provided types
        self.types = types

        # Create the box_layout
        box_layout = GL.QHBoxLayout(self)
        box_layout.setContentsMargins(0, 0, 0, 0)

        # Create two spinboxes with the provided types
        # LEFT
        left_box = box_types[types[0]]()
        box_layout.addWidget(left_box)
        self.left_box = left_box

        # RIGHT
        right_box = box_types[types[1]]()
        box_layout.addWidget(right_box)
        self.right_box = right_box

        # If sep is not None, create label and add it
        if sep is not None:
            sep_label = GW.QLabel(sep)
            sep_label.setSizePolicy(QW.QSizePolicy.Fixed, QW.QSizePolicy.Fixed)
            box_layout.insertWidget(1, sep_label)
Exemple #4
0
    def init(self, editable, sep):
        """
        Sets up the dual combobox after it has been initialized.

        """

        # Create the box_layout
        box_layout = GL.QHBoxLayout(self)
        box_layout.setContentsMargins(0, 0, 0, 0)

        # Create two comboboxes with the provided editability
        # LEFT
        left_box = EditableComboBox() if editable[0] else GW.QComboBox()
        box_layout.addWidget(left_box)
        self.left_box = left_box

        # RIGHT
        right_box = EditableComboBox() if editable[1] else GW.QComboBox()
        box_layout.addWidget(right_box)
        self.right_box = right_box

        # If sep is not None, create label and add it
        if sep is not None:
            sep_label = GW.QLabel(sep)
            sep_label.setSizePolicy(QW.QSizePolicy.Fixed, QW.QSizePolicy.Fixed)
            box_layout.insertWidget(1, sep_label)
Exemple #5
0
    def add_entry(self):
        """
        Adds a new entry to the entries box.

        """

        # Create a combobox with the name of the entry
        name_box = self.get_entry_name_box()
        name_box.setToolTip("Select or type name for this entry")
        name_box.addItems(self.entry_types.keys())
        set_box_value(name_box, -1)
        get_modified_signal(name_box).connect(
            lambda: self.create_value_box(name_box))

        # Create a 'Delete'-button
        del_but = GW.QToolButton()
        del_but.setFixedSize(self.entry_height, self.entry_height)
        del_but.setToolTip("Delete this entry")
        get_modified_signal(del_but).connect(
            lambda: self.remove_entry(name_box))

        # If this theme has a 'remove' icon, use it
        if QG.QIcon.hasThemeIcon('remove'):
            del_but.setIcon(QG.QIcon.fromTheme('remove'))
        # Else, use a standard icon
        else:
            del_but.setIcon(del_but.style().standardIcon(
                QW.QStyle.SP_DialogCloseButton))

        # Add a new row to the grid layout
        next_row = self.entries_grid.getItemPosition(
            self.entries_grid.count() - 1)[0] + 1
        self.entries_grid.addWidget(del_but, next_row, 0)
        self.entries_grid.addWidget(name_box, next_row, 1)
        self.entries_grid.addWidget(GW.QLabel(), next_row, 2)
Exemple #6
0
    def _init_toolbar(self):
        # Create pointer in figure manager to this toolbar
        self.canvas.manager.toolbar = self

        # Store the base dir for images for NavigationToolbar2QT
        self.basedir = str(cbook._get_data_path('images'))

        # Determine what icon color to use
        background_color = self.palette().color(self.backgroundRole())
        foreground_color = self.palette().color(self.foregroundRole())
        icon_color = (foreground_color
                      if background_color.value() < 128 else None)

        # Create list of info for the toolbuttons
        button_info = [
            ('Home', 'Reset to original view', 'home', 'home'),
            ('Back', 'Back to previous view', 'back', 'back'),
            ('Forward', 'Forward to next view', 'forward', 'forward'),
            (None, None, None, None),
            ('Pan', 'Pan with left button, zoom with right', 'move', 'pan'),
            ('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'),
            (None, None, None, None),
            ('Options', 'Add, remove, and edit figure elements',
             'qt4_editor_options', 'options'),
            ('Save', 'Save the figure', 'filesave', 'save_figure')
        ]

        # Loop over all items in button_info and create the actions
        for text, tooltip, image_file, func in button_info:
            # If text is None, a separator is required
            if text is None:
                self.addSeparator()
            # Else, create an action
            else:
                # Create action
                action = GW.QAction(self,
                                    text,
                                    tooltip=tooltip,
                                    icon=self._icon(image_file + '.png',
                                                    icon_color),
                                    triggered=getattr(self, func))
                self.addAction(action)

                # Add action to self._actions
                self._actions[func] = action

                # Make zoom and pan checkable
                if func in ['zoom', 'pan']:
                    action.setCheckable(True)

        # Add separator
        self.addSeparator()

        # Add a label that contains the coordinates of the figure
        coord_label = GW.QLabel('')
        coord_label.setSizePolicy(QW.QSizePolicy.Expanding,
                                  QW.QSizePolicy.Ignored)
        self.addWidget(coord_label)
        self.status_message.connect(coord_label.setText)
Exemple #7
0
    def init(self):
        # Install event filter to catch events that should close the popup
        self.installEventFilter(self)

        # Set dialog flags
        self.setWindowFlags(QC.Qt.Popup | QC.Qt.FramelessWindowHint)

        # Create a form layout
        layout = GL.QFormLayout(self)

        # Add a label stating the base name of the column
        self.base_name_label = GW.QLabel("")
        self.base_name_label.setAlignment(QC.Qt.AlignCenter)
        layout.addRow(self.base_name_label)

        # Create a n_val label
        n_val_box = GW.QLabel()
        n_val_box.setToolTip("Number of values in this column")

        # Add it to the layout
        layout.addRow("# of values", n_val_box)
        self.n_val_box = n_val_box

        # Create a name line-edit
        name_box = GW.QLineEdit()
        name_box.setToolTip("Set a custom name for this column or leave empty "
                            "to use its default name")
        get_modified_signal(name_box).connect(self.column_name_changed)

        # Add it to the layout
        layout.addRow("Name", name_box)
        self.name_box = name_box

        # Create a dtype combobox
        dtype_box = GW.QComboBox()
        dtype_box.setToolTip("Set the data type for this column")
        dtype_box.addItems(self.model.dtypes.values())
        dtype_box.popup_hidden.connect(lambda: name_box.setFocus(True))

        # Add it to the layout
        layout.addRow("Data type", dtype_box)
        self.dtype_box = dtype_box
Exemple #8
0
    def create_plots_tab(self):
        # Create a tab
        tab = GW.BaseBox()
        get_modified_signal(tab).connect(self.enable_apply_button)

        # Create layout
        layout = GL.QFormLayout(tab)

        # PLOT
        # Create a plot picker layout
        plot_layout = GL.QHBoxLayout()
        layout.addRow(plot_layout)

        # Create a label
        plot_label = GW.QLabel("Plot")
        plot_label.setSizePolicy(QW.QSizePolicy.Fixed, QW.QSizePolicy.Fixed)
        plot_layout.addWidget(plot_label)

        # Create a combobox for choosing an existing plot
        plot_entries = GW.QComboBox()
        plot_entries.setToolTip("Select the plot entry you wish to edit")
        plot_layout.addWidget(plot_entries)
        get_modified_signal(plot_entries).disconnect(tab.modified)
        self.plot_entries = plot_entries

        # Add a toolbutton for adding a new plot entry
        add_but = GW.QToolButton()
        add_but.setToolTip("Add new plot entry")
        get_modified_signal(add_but).connect(self.add_entry)
        plot_layout.addWidget(add_but)

        # If this theme has an 'add' icon, use it
        if QG.QIcon.hasThemeIcon('add'):
            add_but.setIcon(QG.QIcon.fromTheme('add'))
        # Else, use a simple plus
        else:
            add_but.setText('+')

        # Add a separator
        layout.addSeparator()

        # Add a stacked widget here for dividing the plots
        plot_pages = GW.QStackedWidget()
        get_modified_signal(plot_entries,
                            int).connect(plot_pages.setCurrentIndex)
        layout.addRow(plot_pages)
        self.plot_pages = plot_pages

        # Return tab
        return (tab, "Plots")
Exemple #9
0
    def create_color_label(self):
        """
        Creates a special label that shows the currently selected or hovered
        color, and returns it.

        """

        # Create the color label
        color_label = GW.QLabel()

        # Set some properties
        color_label.setFrameShape(QW.QFrame.StyledPanel)
        color_label.setScaledContents(True)
        color_label.setToolTip("Click to open the custom color picker")
        color_label.setSizePolicy(QW.QSizePolicy.Fixed, QW.QSizePolicy.Fixed)
        color_label.mousePressed.connect(self.show_colorpicker)

        # Return it
        return (color_label)
Exemple #10
0
    def init(self):
        # Create layout
        layout = GL.QVBoxLayout(self)

        # COLORMAPS
        # Create 'Colormaps' group box
        colormaps_group = GW.QGroupBox('Import colormaps')
        layout.addWidget(colormaps_group)
        colormaps_layout = GL.QFormLayout(colormaps_group)

        # Add label with explaining text
        cmaps_label = GW.QLabel(
            "You can import several Python packages that register colormaps in"
            " <u>matplotlib</u> before a figure is created. Packages that are "
            "not installed are ignored. Please provide each package separated "
            "by a comma, like: <i>cmasher, cmocean</i>")
        colormaps_layout.addRow(cmaps_label)

        # Create box for setting the colormap packages that must be imported
        cmap_pkg_box = GW.QLineEdit()
        colormaps_layout.addRow("Packages:", cmap_pkg_box)
        self.add_config_entry('cmap_packages', cmap_pkg_box, True)

        # RCPARAMS
        # Create 'rcParams' group box
        rcParams_group = GW.QGroupBox('rcParams')
        layout.addWidget(rcParams_group)
        rcParams_layout = GL.QVBoxLayout(rcParams_group)

        # Add label with explaining text
        rcParams_label = GW.QLabel(
            "You can modify most of the <u>rcParams</u> used in "
            "<u>matplotlib</u> below. Adding an entry will override the value "
            "for that specific parameter for every figure created.<br>"
            "See <a href=\"%s\">here</a> for an overview with descriptions of "
            "each parameter." %
            ("https://matplotlib.org/tutorials/introductory/customizing.html"))
        rcParams_layout.addWidget(rcParams_label)

        # Add separator
        rcParams_layout.addSeparator()

        # Create entries_box
        entries_box = GW.EntriesBox()
        rcParams_layout.addWidget(entries_box)
        self.add_config_entry('rcParams', entries_box)

        # Create list of all prefixes that should be skipped
        prefix_skip = ('_internal', 'agg', 'animation', 'backend',
                       'boxplot.bootstrap', 'datapath', 'docstring',
                       'figure.figsize', 'figure.max_open_warning',
                       'image.aspect', 'image.composite_image', 'image.origin',
                       'interactive', 'keymap', 'lines.color', 'mpl_toolkits',
                       'path', 'pdf', 'pgf', 'ps', 'savefig', 'svg',
                       'text.kerning_factor', 'tk', 'toolbar', 'verbose',
                       'webagg')

        # Create a combobox factory for text weights
        text_weight_box = create_combobox(
            ['normal', 'bold', 'bolder', 'lighter', '100', '200', '300', '400',
             '500', '600', '700', '800', '900'])

        # Create dict of all rcParams that use specific widgets
        key_widgets = {
            'axes.autolimit_mode': create_combobox(['data', 'round_numbers']),
            'axes.axisbelow': lambda: BoolComboBox([True, 'line', False]),
            'axes.edgecolor': GW.ColorBox,
            'axes.facecolor': GW.ColorBox,
            'axes.formatter.limits': lambda: GW.ItemsBox([int]*2),
            'axes.formatter.min_exponent': GW.QSpinBox,
            'axes.formatter.offset_threshold': GW.QSpinBox,
            'axes.formatter.use_locale': GW.QCheckBox,
            'axes.formatter.use_mathtext': GW.QCheckBox,
            'axes.formatter.useoffset': GW.QCheckBox,
            'axes.grid': GW.QCheckBox,
            'axes.grid.axes': create_combobox(['major', 'minor', 'both']),
            'axes.grid.which': create_combobox(['major', 'minor', 'both']),
            'axes.labelcolor': GW.ColorBox,
            'axes.labelpad': GW.FontSizeBox,
            'axes.labelsize': GW.FontSizeBox,
            'axes.labelweight': text_weight_box,
            'axes.linewidth': GW.FontSizeBox,
            'axes.prop_cycle': lambda: GW.GenericItemsBox(
                lambda: GW.ColorBox(False)),
            'axes.spines.bottom': GW.QCheckBox,
            'axes.spines.left': GW.QCheckBox,
            'axes.spines.right': GW.QCheckBox,
            'axes.spines.top': GW.QCheckBox,
            'axes.titlecolor': lambda: AutoToggleBox(GW.ColorBox(), 'auto'),
            'axes.titlelocation': create_combobox(['left', 'center', 'right']),
            'axes.titlepad': GW.FontSizeBox,
            'axes.titlesize': GW.FontSizeBox,
            'axes.titleweight': text_weight_box,
            'axes.unicode_minus': GW.QCheckBox,
            'axes.xmargin': UnitySpinBox,
            'axes.ymargin': UnitySpinBox,
            'axes3d.grid': GW.QCheckBox,
            'boxplot.boxprops.color': GW.ColorBox,
            'boxplot.boxprops.linestyle': GW.LineStyleBox,
            'boxplot.boxprops.linewidth': GW.FontSizeBox,
            'boxplot.capprops.color': GW.ColorBox,
            'boxplot.capprops.linestyle': GW.LineStyleBox,
            'boxplot.capprops.linewidth': GW.FontSizeBox,
            'boxplot.flierprops.color': GW.ColorBox,
            'boxplot.flierprops.linestyle': GW.LineStyleBox,
            'boxplot.flierprops.linewidth': GW.FontSizeBox,
            'boxplot.flierprops.marker': GW.MarkerStyleBox,
            'boxplot.flierprops.markeredgecolor': lambda: AutoToggleBox(
                GW.ColorBox(), 'none'),
            'boxplot.flierprops.markeredgewidth': GW.FontSizeBox,
            'boxplot.flierprops.markerfacecolor': lambda: AutoToggleBox(
                GW.ColorBox(), 'none'),
            'boxplot.flierprops.markersize': GW.FontSizeBox,
            'boxplot.meanline': GW.QCheckBox,
            'boxplot.meanprops.color': GW.ColorBox,
            'boxplot.meanprops.linestyle': GW.LineStyleBox,
            'boxplot.meanprops.linewidth': GW.FontSizeBox,
            'boxplot.meanprops.marker': GW.MarkerStyleBox,
            'boxplot.meanprops.markeredgecolor': lambda: AutoToggleBox(
                GW.ColorBox(), 'none'),
            'boxplot.meanprops.markerfacecolor': lambda: AutoToggleBox(
                GW.ColorBox(), 'none'),
            'boxplot.meanprops.markersize': GW.FontSizeBox,
            'boxplot.medianprops.color': GW.ColorBox,
            'boxplot.medianprops.linestyle': GW.LineStyleBox,
            'boxplot.medianprops.linewidth': GW.FontSizeBox,
            'boxplot.notch': GW.QCheckBox,
            'boxplot.showbox': GW.QCheckBox,
            'boxplot.showcaps': GW.QCheckBox,
            'boxplot.showfliers': GW.QCheckBox,
            'boxplot.showmeans': GW.QCheckBox,
            'boxplot.vertical': GW.QCheckBox,
            'boxplot.whiskerprops.color': GW.ColorBox,
            'boxplot.whiskerprops.linestyle': GW.LineStyleBox,
            'boxplot.whiskerprops.linewidth': GW.FontSizeBox,
            'boxplot.whiskers': GW.FloatLineEdit,
            'contour.corner_mask': lambda: BoolComboBox(
                [True, False, 'legacy']),
            'contour.negative_linestyle': GW.LineStyleBox,
            'date.autoformatter.day': GW.QLineEdit,
            'date.autoformatter.hour': GW.QLineEdit,
            'date.autoformatter.microsecond': GW.QLineEdit,
            'date.autoformatter.minute': GW.QLineEdit,
            'date.autoformatter.month': GW.QLineEdit,
            'date.autoformatter.second': GW.QLineEdit,
            'date.autoformatter.year': GW.QLineEdit,
            'errorbar.capsize': GW.FloatLineEdit,
            'figure.autolayout': GW.QCheckBox,
            'figure.constrained_layout.h_pad': UnitySpinBox,
            'figure.constrained_layout.hspace': UnitySpinBox,
            'figure.constrained_layout.use': GW.QCheckBox,
            'figure.constrained_layout.w_pad': UnitySpinBox,
            'figure.constrained_layout.wspace': UnitySpinBox,
            'figure.dpi': GW.FloatLineEdit,
            'figure.edgecolor': GW.ColorBox,
            'figure.facecolor': GW.ColorBox,
            'figure.frameon': GW.QCheckBox,
            'figure.subplot.bottom': UnitySpinBox,
            'figure.subplot.hspace': UnitySpinBox,
            'figure.subplot.left': UnitySpinBox,
            'figure.subplot.right': UnitySpinBox,
            'figure.subplot.top': UnitySpinBox,
            'figure.subplot.wspace': UnitySpinBox,
            'figure.titlesize': GW.FontSizeBox,
            'figure.titleweight': text_weight_box,
            'font.cursive': lambda: GW.GenericItemsBox(GW.QFontComboBox),
            'font.family': lambda: GW.GenericItemsBox(GW.QFontComboBox),
            'font.fantasy': lambda: GW.GenericItemsBox(GW.QFontComboBox),
            'font.monospace': lambda: GW.GenericItemsBox(GW.QFontComboBox),
            'font.sans-serif': lambda: GW.GenericItemsBox(GW.QFontComboBox),
            'font.serif': lambda: GW.GenericItemsBox(GW.QFontComboBox),
            'font.size': GW.FontSizeBox,
            'font.stretch': create_combobox(
                ['ultra-condensed', 'extra-condensed', 'condensed',
                 'semi-condensed', 'normal', 'semi-expanded', 'expanded',
                 'extra-expanded', 'ultra-expanded', 'wider', 'narrower']),
            'font.style': create_combobox(['normal', 'italic', 'oblique']),
            'font.variant': create_combobox(['normal', 'small-caps']),
            'font.weight': text_weight_box,
            'grid.alpha': UnitySpinBox,
            'grid.color': GW.ColorBox,
            'grid.linestyle': GW.LineStyleBox,
            'grid.linewidth': GW.FontSizeBox,
            'hatch.color': GW.ColorBox,
            'hatch.linewidth': GW.FontSizeBox,
            'hist.bins': get_n_bins_box,
            'image.cmap': GW.ColorMapBox,
            'image.interpolation': create_combobox(
                ['none', 'antialiased', 'nearest', 'bilinear', 'bicubic',
                 'spline16', 'spline36', 'hanning', 'hamming', 'hermite',
                 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel',
                 'mitchell', 'sinc', 'lanczos']),
            'image.lut': GW.IntLineEdit,
            'image.resample': GW.QCheckBox,
            'legend.borderaxespad': GW.FontSizeBox,
            'legend.borderpad': GW.FontSizeBox,
            'legend.columnspacing': GW.FontSizeBox,
            'legend.edgecolor': GW.ColorBox,
            'legend.facecolor': lambda: AutoToggleBox(
                GW.ColorBox(), 'inherit'),
            'legend.fancybox': GW.QCheckBox,
            'legend.fontsize': GW.FontSizeBox,
            'legend.framealpha': UnitySpinBox,
            'legend.frameon': GW.QCheckBox,
            'legend.handleheight': GW.FontSizeBox,
            'legend.handlelength': GW.FontSizeBox,
            'legend.handletextpad': GW.FontSizeBox,
            'legend.labelspacing': GW.FontSizeBox,
            'legend.loc': create_combobox(mpl.legend.Legend.codes.keys()),
            'legend.markerscale': GW.FloatLineEdit,
            'legend.numpoints': GW.IntLineEdit,
            'legend.scatterpoints': GW.IntLineEdit,
            'legend.shadow': GW.QCheckBox,
            'legend.title_fontsize': lambda: AutoToggleBox(
                GW.FontSizeBox(), None),
            'lines.antialiased': GW.QCheckBox,
            'lines.dash_capstyle': create_combobox(
                ['butt', 'projecting', 'round']),
            'lines.dash_joinstyle': create_combobox(
                ['bevel', 'miter', 'round']),
            'lines.dashdot_pattern': lambda: GW.ItemsBox([float]*4),
            'lines.dashed_pattern': lambda: GW.ItemsBox([float]*2),
            'lines.dotted_pattern': lambda: GW.ItemsBox([float]*2),
            'lines.linestyle': GW.LineStyleBox,
            'lines.linewidth': GW.FontSizeBox,
            'lines.marker': GW.MarkerStyleBox,
            'lines.markeredgecolor': lambda: AutoToggleBox(
                GW.ColorBox(), 'auto'),
            'lines.markeredgewidth': GW.FontSizeBox,
            'lines.markerfacecolor': lambda: AutoToggleBox(
                GW.ColorBox(), 'auto'),
            'lines.markersize': GW.FontSizeBox,
            'lines.scale_dashes': GW.QCheckBox,
            'lines.solid_capstyle': create_combobox(
                ['butt', 'projecting', 'round']),
            'lines.solid_joinstyle': create_combobox(
                ['bevel', 'miter', 'round']),
            'markers.fillstyle': create_combobox(
                ['full', 'left', 'right', 'bottom', 'top', 'none']),
            'mathtext.bf': GW.QLineEdit,
            'mathtext.cal': GW.QLineEdit,
            'mathtext.default': GW.QLineEdit,
            'mathtext.fallback_to_cm': GW.QCheckBox,
            'mathtext.fontset': create_combobox(
                ['dejavusans', 'cm', 'stix', 'stixsans', 'custom']),
            'mathtext.it': GW.QLineEdit,
            'mathtext.rm': GW.QLineEdit,
            'mathtext.sf': GW.QLineEdit,
            'mathtext.tt': GW.QLineEdit,
            'patch.antialiased': GW.QCheckBox,
            'patch.edgecolor': GW.ColorBox,
            'patch.facecolor': GW.ColorBox,
            'patch.force_edgecolor': GW.QCheckBox,
            'patch.linewidth': GW.FontSizeBox,
            'polaraxes.grid': GW.QCheckBox,
            'scatter.edgecolors': lambda: AutoToggleBox(
                GW.ColorBox(), 'face'),
            'scatter.marker': GW.MarkerStyleBox,
            'text.antialiased': GW.QCheckBox,
            'text.color': GW.ColorBox,
            'text.hinting': create_combobox(
                ['either', 'native', 'auto', 'none']),
            'text.hinting_factor': GW.IntLineEdit,
            'text.latex.preamble': GW.QLineEdit,
            'text.latex.preview': GW.QCheckBox,
            'text.usetex': GW.QCheckBox,
            'timezone': GW.QLineEdit,
            'xtick.alignment': create_combobox(['left', 'center', 'right']),
            'xtick.bottom': GW.QCheckBox,
            'xtick.color': GW.ColorBox,
            'xtick.direction': create_combobox(['in', 'out', 'inout']),
            'xtick.labelbottom': GW.QCheckBox,
            'xtick.labelsize': GW.FontSizeBox,
            'xtick.labeltop': GW.QCheckBox,
            'xtick.major.bottom': GW.QCheckBox,
            'xtick.major.pad': GW.FontSizeBox,
            'xtick.major.size': GW.FontSizeBox,
            'xtick.major.top': GW.QCheckBox,
            'xtick.major.width': GW.FontSizeBox,
            'xtick.minor.bottom': GW.QCheckBox,
            'xtick.minor.pad': GW.FontSizeBox,
            'xtick.minor.size': GW.FontSizeBox,
            'xtick.minor.top': GW.QCheckBox,
            'xtick.minor.visible': GW.QCheckBox,
            'xtick.minor.width': GW.FontSizeBox,
            'xtick.top': GW.QCheckBox,
            'ytick.alignment': create_combobox(
                ['left_baseline', 'center_baseline', 'right_baseline']),
            'ytick.color': GW.ColorBox,
            'ytick.direction': create_combobox(['in', 'out', 'inout']),
            'ytick.labelleft': GW.QCheckBox,
            'ytick.labelright': GW.QCheckBox,
            'ytick.labelsize': GW.FontSizeBox,
            'ytick.left': GW.QCheckBox,
            'ytick.major.left': GW.QCheckBox,
            'ytick.major.pad': GW.FontSizeBox,
            'ytick.major.right': GW.QCheckBox,
            'ytick.major.size': GW.FontSizeBox,
            'ytick.major.width': GW.FontSizeBox,
            'ytick.minor.left': GW.QCheckBox,
            'ytick.minor.pad': GW.FontSizeBox,
            'ytick.minor.right': GW.QCheckBox,
            'ytick.minor.size': GW.FontSizeBox,
            'ytick.minor.visible': GW.QCheckBox,
            'ytick.minor.width': GW.FontSizeBox,
            'ytick.right': GW.QCheckBox}

        # Initialize empty dict of entry_types
        entry_types = sdict()

        # Loop over all rcParams and determine what widget to use
        for key, value in rcParamsDefault.items():
            # Check if key starts with anything in prefix_skip
            if key.startswith(prefix_skip):
                # If so, continue
                continue

            # Obtain proper box
            box = key_widgets.get(key, GW.LongGenericBox)

            # If key is 'axes.prop_cycle', obtain the proper value
            if(key == 'axes.prop_cycle'):
                value = value.by_key()['color']

            # Add box to entry_types dict with default value
            entry_types[key] = (box, value)

        # Add all rcParams entries to the box
        entries_box.addEntryTypes(entry_types)
Exemple #11
0
    def init(self, import_func=None):
        # Create a layout
        layout = GL.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)

        # Create a dimensions layout
        dimensions_layout = GL.QHBoxLayout()
        layout.addLayout(dimensions_layout)

        # Add a label to this layout
        dimensions_layout.addWidget(GW.QLabel('Dimensions: '))

        # Create dual spinbox for setting n_rows and n_cols
        dimensions_box = GW.DualSpinBox((int, int), "X")
        dimensions_layout.addWidget(dimensions_box)
        n_rows_box, n_cols_box = dimensions_box[:]
        n_rows_box.setRange(0, 9999999)
        n_rows_box.setToolTip("Number of rows in this data table (max. %i)" %
                              (n_rows_box.maximum()))
        n_cols_box.setRange(0, 702)
        n_cols_box.setToolTip(
            "Number of columns in this data table (max. %i)" %
            (n_cols_box.maximum()))
        self.dimensions_box = dimensions_box

        # Create a layout for applying or reverting the dimensions
        buttons_layout = GL.QHBoxLayout()
        buttons_layout.setContentsMargins(0, 0, 0, 0)
        buttons_layout.setSpacing(0)
        dimensions_layout.addLayout(buttons_layout)

        # If this theme has a 'cancel' icon, use it
        if QG.QIcon.hasThemeIcon('cancel'):
            rev_icon = QG.QIcon.fromTheme('cancel')
        # Else, use a standard icon
        else:
            rev_icon = self.style().standardIcon(
                QW.QStyle.SP_DialogCancelButton)

        # Create a revert toolbutton
        rev_but = GW.QToolButton()
        rev_but.setToolTip("Revert to current data table dimensions")
        rev_but.setIcon(rev_icon)
        get_modified_signal(rev_but).connect(self.revert_table_dimensions)
        buttons_layout.addWidget(rev_but)

        # If this theme has an 'apply' icon, use it
        if QG.QIcon.hasThemeIcon('apply'):
            app_icon = QG.QIcon.fromTheme('apply')
        # Else, use a standard icon
        else:
            app_icon = self.style().standardIcon(
                QW.QStyle.SP_DialogApplyButton)

        # Create an apply toolbutton
        app_but = GW.QToolButton()
        app_but.setToolTip("Apply new data table dimensions")
        app_but.setIcon(app_icon)
        get_modified_signal(app_but).connect(self.apply_table_dimensions)
        buttons_layout.addWidget(app_but)

        # Add a stretcher
        dimensions_layout.addStretch()

        # Create the DataTableView object
        self.view = DataTableView(self, import_func)

        # Set initial values of the spinboxes
        self.revert_table_dimensions()

        # Connect signals from data table view
        self.view.model().rowCountChanged.connect(
            lambda x: set_box_value(n_rows_box, x))
        self.view.model().columnCountChanged.connect(
            lambda x: set_box_value(n_cols_box, x))
        self.view.model().lastColumnRemoved.connect(
            lambda: n_rows_box.setEnabled(False))
        self.view.model().firstColumnInserted.connect(
            lambda: n_rows_box.setEnabled(True))

        # Add data_table to the layout
        layout.addWidget(self.view)