Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
0
    def init(self, item_types, layout):
        """
        Sets up the items box after it has been initialized.

        """

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

        # Create empty list of items
        self.items = []

        # Obtain the proper layout
        if layout in ('h', 'horizontal', 'r', 'row'):
            layout = GL.QHBoxLayout(self)
        elif layout in ('v', 'vertical', 'c', 'col', 'column'):
            layout = GL.QVBoxLayout(self)
        else:
            raise ValueError
        layout.setContentsMargins(0, 0, 0, 0)

        # Initialize all items
        for item_type in item_types:
            # Create item
            item = GW.type_box_dict.get(item_type, item_type)()

            # Add item to items list and layout
            self.items.append(item)
            layout.addWidget(item)

        # Save the number of items
        self.N = len(self.items)
Esempio n. 4
0
    def init(self, widget, text, tooltip):
        """
        Sets up the togglebox after it has been initialized.

        """

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

        # Create a checkbox for toggling the widget
        if text is not None:
            checkbox = GW.QCheckBox(text)
        else:
            checkbox = GW.QCheckBox()
        box_layout.addWidget(checkbox)
        self.checkbox = checkbox
        self.left_box = checkbox

        # Set tooltip
        if tooltip is not None:
            checkbox.setToolTip(tooltip)

        # Add the widget to it
        box_layout.addWidget(widget)
        self.widget = widget
        self.right_box = widget

        # Connect some signals
        get_modified_signal(checkbox).connect(widget.setEnabled)

        # Make sure that the checkbox is unchecked
        set_box_value(checkbox, False)
        widget.setEnabled(False)
Esempio n. 5
0
    def init(self, add_cycler):
        """
        Sets up the color box entry after it has been initialized.

        This function is mainly responsible for creating the color wheel and
        color label, that allow the user to quickly cycle through different
        color options.

        """

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

        # Create a color label
        color_label = self.create_color_label()
        self.color_label = color_label
        box_layout.addWidget(color_label)

        # Create a color combobox
        color_combobox = self.create_color_combobox(add_cycler)
        box_layout.addWidget(color_combobox)
        self.color_combobox = color_combobox

        # Set the default starting color of the color box
        self.set_box_value('C0')
Esempio n. 6
0
    def init(self):
        # Make layout for setting the value range of the histogram
        hist_range_layout = GL.QHBoxLayout(self)
        hist_range_layout.setContentsMargins(0, 0, 0, 0)

        # Make a box for setting the value range of the histogram
        # TODO: Maybe use dual lineedits instead to eliminate range problem?
        hist_range_box = GW.DualSpinBox((float, float),
                                        r"<html>&le; X &le;</html>")
        x_min_box, x_max_box = hist_range_box[:]
        x_min_box.setRange(-9999999, 9999999)
        x_min_box.setToolTip("Minimum value to be included in the histogram")
        x_max_box.setRange(-9999999, 9999999)
        x_max_box.setToolTip("Maximum value to be included in the histogram")
        set_box_value(hist_range_box, (0, 0))
        hist_range_box.setEnabled(False)
        self.range_box = hist_range_box

        # Make a checkbox for enabling/disabling the use of this range
        hist_range_flag = GW.QCheckBox()
        hist_range_flag.setToolTip("Toggle the use of a manual histogram value"
                                   " range")
        set_box_value(hist_range_flag, False)
        self.range_flag = hist_range_flag

        # Connect signals for hist_range_flag
        get_modified_signal(hist_range_flag).connect(hist_range_box.setEnabled)

        # Add everything together
        hist_range_layout.addWidget(hist_range_flag)
        hist_range_layout.addWidget(hist_range_box)
Esempio n. 7
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
Esempio n. 8
0
    def init(self, n, layout):
        """
        Sets up the multi-radiobutton after it has been initialized.

        """

        # Check what type of n has been provided
        if isinstance(n, INT_TYPES):
            # If n is an integer, set all names to empty strings
            names = [''] * n
        elif hasattr(n, '__iter__') and not isinstance(n, STR_TYPES):
            # Else, n must be an iterable of names
            names = list(map(str, n))
            n = len(n)
        else:
            raise TypeError

        # Check what type of layout has been provided
        if isinstance(layout, STR_TYPES):
            # If layout is a string, it is either 'horizontal' or 'vertical'
            if layout in ('h', 'horizontal', 'r', 'row'):
                layout = GL.QHBoxLayout(self)
            elif layout in ('v', 'vertical', 'c', 'col', 'column'):
                layout = GL.QVBoxLayout(self)
            else:
                raise ValueError
        else:
            # Else, layout is a tuple specifying the number of rows and columns
            n_rows, n_cols = layout
            layout = GL.QGridLayout(self)

        # Set contents margins of layout
        layout.setContentsMargins(0, 0, 0, 0)

        # Initialize empty list of radiobuttons
        self.buttons = []

        # Create buttons iterator
        if isinstance(layout, QW.QGridLayout):
            iterator = zip(names, np.ndindex(n_rows, n_cols))
        else:
            iterator = zip(names, repeat(()))

        # Create all requested radiobuttons
        for item in iterator:
            # Create radiobutton
            button = GW.QRadioButton(item[0])

            # Add button to list and layout
            self.buttons.append(button)
            layout.addWidget(button, *item[1])

        # Save the number of radiobuttons
        self.N = len(self.buttons)

        # Save the names
        self.names = names[:self.N]
Esempio n. 9
0
    def init(self):
        # Create layout
        layout = GL.QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)

        # Create combobox
        combobox = GW.QComboBox()
        layout.addWidget(combobox)
        self.combobox = combobox
Esempio n. 10
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")
Esempio n. 11
0
    def create_entry_layout(self):
        # Create layout
        layout = GL.QFormLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        self.layout = layout

        # Create a name editor layout
        name_layout = GL.QHBoxLayout()
        layout.addRow('Name', name_layout)

        # Create entry name editor
        name_box = GW.QLineEdit()
        name_box.setToolTip("Name of this plot entry")
        set_box_value(name_box, self.name)
        get_modified_signal(name_box).connect(self.entryNameChanged)
        name_layout.addWidget(name_box)
        get_modified_signal(name_box).disconnect(self.modified)
        self.name_box = name_box

        # Add a toolbutton for deleting this plot entry
        del_but = GW.QToolButton()
        del_but.setToolTip("Delete this plot entry")
        get_modified_signal(del_but).connect(self.entryRemoveRequested)
        name_layout.addWidget(del_but)

        # 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))

        # Create a combobox for choosing a plot type
        plot_types = GW.QComboBox()
        plot_types.addItems(PLOT_TYPES['2D'])
        plot_types.setToolTip("Select the plot type you wish to use for this "
                              "plot entry")
        set_box_value(plot_types, -1)
        get_modified_signal(plot_types).connect(self.set_plot_type)
        layout.addRow('Type', plot_types)
        self.plot_types = plot_types

        # Add a separator
        layout.addSeparator()

        # Create a dummy entry to start off
        self.plot_entry = GW.QWidget()
        layout.addRow(self.plot_entry)
Esempio n. 12
0
    def init(self):
        """
        Sets up the figure label box after it has been initialized.

        """

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

        # Create a line-edit for setting the label
        label_box = GW.QLineEdit()
        box_layout.addWidget(label_box)
        self.left_box = label_box

        # Create a spinbox for setting the fontsize
        size_box = FontSizeBox()
        box_layout.addWidget(size_box)
        self.right_box = size_box
Esempio n. 13
0
    def add_item(self):
        """
        Adds a new item to the items box.

        """

        # Create an item layout
        item_layout = GL.QHBoxLayout()
        item_layout.setContentsMargins(0, 0, 0, 0)

        # Create a generic box for this item
        item_box = self.item_box()
        item_box.setToolTip("Set value of this item")
        get_modified_signal(item_box).connect(self.modified)

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

        # 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 items layout
        item_layout.addWidget(del_but)
        item_layout.addWidget(item_box)
        self.items_layout.addLayout(item_layout)

        # Emit signal if item_box is not LongGenericBox
        if not isinstance(item_box, GW.LongGenericBox):
            self.modified.emit()
Esempio n. 14
0
    def init(self):
        """
        Sets up the generic value box after it has been initialized.

        """

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

        # Create a combobox for the type
        type_box = GW.QComboBox()
        type_box.addItems(sorted([x.__name__ for x in self.supported_types]))
        type_box.setSizePolicy(QW.QSizePolicy.Fixed, QW.QSizePolicy.Fixed)
        set_box_value(type_box, -1)
        get_modified_signal(type_box).connect(self.create_value_box)
        box_layout.addWidget(type_box)
        self.type_box = type_box

        # Create a default value box
        value_box = GW.QWidget()
        box_layout.addWidget(value_box)
        self.value_box = value_box
Esempio n. 15
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)