Ejemplo n.º 1
0
 def test_zoom_to_selection(self):
     """Test the automatic zoom to the selection"""
     self.test_creation()
     editor = self.digitizer._samples_editor
     table = editor.table
     model = table.model()
     df = self.reader.sample_locs
     for ax in unique_everseen(mark.ax for mark in self.straditizer.marks):
         ax.set_ylim(-1, 0)
         ax.set_xlim(-1, 0)
     editor.cb_zoom_to_selection.setChecked(True)
     # select the last row
     table.selectRow(len(df) - 1)
     y = getattr(model, '_y0', 0) + df.index[-1]
     try:
         starts = model._bounds[:, 0]
     except AttributeError:
         starts = np.zeros(len(df.columns))
     for col, ax in enumerate(
             unique_everseen(mark.ax for mark in self.straditizer.marks)):
         if col == len(df.columns):
             continue
         val = starts[col] + df.iloc[-1, col]
         xmin, xmax = ax.get_xlim()
         ymax, ymin = ax.get_ylim()
         self.assertGreaterEqual(val, xmin)
         self.assertLessEqual(val, xmax)
         self.assertGreater(y, ymin)
         self.assertLess(y, ymax)
     editor.cb_zoom_to_selection.setChecked(False)
Ejemplo n.º 2
0
 def setup_fmt_completion_model(self):
     fmtos = list(unique_everseen(map(
         self.get_name, chain.from_iterable(self.fmtos))))
     model = self.fmto_completer.model()
     model.setRowCount(len(fmtos))
     for i, name in enumerate(fmtos):
         model.setItem(i, QStandardItem(name))
Ejemplo n.º 3
0
 def setup_fmt_completion_model(self):
     fmtos = list(
         unique_everseen(map(self.get_name,
                             chain.from_iterable(self.fmtos))))
     model = self.fmto_completer.model()
     model.setRowCount(len(fmtos))
     for i, name in enumerate(fmtos):
         model.setItem(i, QStandardItem(name))
Ejemplo n.º 4
0
    def refresh(self, ds) -> None:
        """Refresh this widget from the given dataset."""
        self.setEnabled(bool(self.sp))

        if self.sp:
            with self.block_combos():
                self.combo_dims.clear()
                all_dims = list(
                    chain.from_iterable(
                        [[d for i, d in enumerate(a.dims) if a.shape[i] > 1]
                         for a in arr.psy.iter_base_variables]
                        for arr in self.sp[0]))
                intersection = set(all_dims[0])
                for dims in all_dims[1:]:
                    intersection.intersection_update(dims)
                new_dims = list(
                    filter(lambda d: d in intersection,
                           unique_everseen(chain.from_iterable(all_dims))))

                self.combo_dims.addItems(new_dims)
                self.combo_dims.setCurrentIndex(
                    new_dims.index(self.data.dims[-1]))

                # fill lines combo
                current = self.combo_lines.currentIndex()
                self.combo_lines.clear()
                descriptions = self.item_texts
                short_descs = [textwrap.shorten(s, 50) for s in descriptions]
                self.combo_lines.addItems(short_descs)
                for i, desc in enumerate(descriptions):
                    self.combo_lines.setItemData(i, desc,
                                                 QtCore.Qt.ToolTipRole)
                if current < len(descriptions):
                    self.combo_lines.setCurrentText(short_descs[current])
        else:
            with self.block_combos():
                self.combo_dims.clear()
                self.combo_lines.clear()
Ejemplo n.º 5
0
        ('regular', QtGui.QFont.Normal),
        ('book', QtGui.QFont.Normal),
        ('medium', QtGui.QFont.Normal),
        ('roman', QtGui.QFont.Normal),
        ('semibold', QtGui.QFont.DemiBold),
        ('demibold', QtGui.QFont.DemiBold),
        ('demi', QtGui.QFont.DemiBold),
        ('bold', QtGui.QFont.Bold),
        ('heavy', QtGui.QFont.Bold),
        ('extra bold', QtGui.QFont.Black),
        ('black', QtGui.QFont.Black),
    ])

weights_qt2mpl = OrderedDict(
    map(reversed,
        utils.unique_everseen(weights_mpl2qt.items(), key=lambda t: t[1])))


def mpl_weight2qt(weight):
    """Convert a weight from matplotlib definition to a Qt weight

    Parameters
    ----------
    weight: int or string
        Either an integer between 1 and 1000 or a string out of
        :attr:`weights_mpl2qt`

    Returns
    -------
    int
        One type of the PyQt5.QtGui.QFont.Weight"""
Ejemplo n.º 6
0
 def test_key(self):
     self.assertEqual(
         list(utils.unique_everseen([1, 1, 2, 3, 4, 3],
                                    key=lambda i: i % 3)), [1, 2, 3])
Ejemplo n.º 7
0
 def test_simple(self):
     self.assertEqual(list(utils.unique_everseen([1, 1, 2, 3, 4, 3])),
                      [1, 2, 3, 4])