Ejemplo n.º 1
0
 def test_column_major_index_too_large(self):
     # Test when the index is too large for the total number of elements
     # The indices would look like:
     # 0  2  3  4
     # 1  /  /  /
     with self.assertRaises(ValueError):
         column_major_to_row_major(
             index=10,
             n=5,
             num_rows=2,
             num_cols=4,
         )
Ejemplo n.º 2
0
def convert_index(source, index):
    """Helper function to convert an index for a GridSizer so that the
    index counts over the grid in the correct direction.
    The grid is always populated in row major order, however, the elements
    are assigned to each entry in the grid so that when displayed they appear
    in column major order.
    Sizers are indexed in the order they are populated, so to access
    the correct element we may need to convert a column-major based index
    into a row-major one.

    Parameters
    ----------
    control : CustomEditor
        The Custom CheckList Editor of interest. Its control is the wx.Panel
        containing child objects organized with a wx.GridSizer
    index : int
        the index of interest
    """
    sizer = source.control.GetSizer()
    if isinstance(sizer, wx.BoxSizer):
        return index
    n = len(source.names)
    num_cols = sizer.GetCols()
    num_rows = sizer.GetEffectiveRowsCount()
    return column_major_to_row_major(index, n, num_rows, num_cols)
Ejemplo n.º 3
0
def convert_index(layout, index, row_major):
    """ Helper function to convert an index for a QGridLayout so that the
    index counts over the grid in the correct direction.
    The grid is always populated in row major order. The row_major trait of a
    Radio Enum Editor simply changes what elements are assigned to each entry
    in the grid, so that when displayed, they appear in column major order.
    Qlayouts are indexed in the order they are populated, so to access
    the correct element we may need to convert a column-major based index
    into a row-major one.

    Parameters
    ----------
    layout : QGridLayout
        The layout of interest
    index : int
        the index of interest
    row_major : bool
        whether or not the grid entries are organized in row major order
    """
    if row_major:
        return index
    else:
        n = layout.count()
        num_cols = layout.columnCount()
        num_rows = layout.rowCount()
        return column_major_to_row_major(index, n, num_rows, num_cols)
Ejemplo n.º 4
0
 def test_column_major_index_long_overhang(self):
     # This is the layout for displaying numbers from 0-9 with column
     # major setup:
     # 0  2  3  4
     # 1  /  /  /
     # The index should be populated (row first) in this order:
     # 0, 2, 3, 4, 1
     actual = column_major_to_row_major(
         index=4,
         n=5,
         num_rows=2,
         num_cols=4,
     )
     self.assertEqual(actual, 3)
Ejemplo n.º 5
0
 def test_column_major_index_index_overhanging(self):
     # This is the layout for displaying numbers from 0-9 with column
     # major setup:
     # 0  3  6  8
     # 1  4  7  9
     # 2  5  /  /
     # The index should be populated (row first) in this order:
     # 0, 3, 6, 8, 1, 4, 7, 9, 2, 5
     actual = column_major_to_row_major(
         index=9,
         n=10,
         num_rows=3,
         num_cols=4,
     )
     self.assertEqual(actual, 7)
Ejemplo n.º 6
0
 def test_column_major_index_full_grid(self):
     # This is the layout for displaying numbers from 0-9 with column
     # major setup:
     # 0  3  6  9   12
     # 1  4  7  10  13
     # 2  5  8  11  14
     # The index should be populated (row first) in this order:
     # 0, 3, 6, 9, 12, 1, 4, 7, 10, 13, 2, 5, 8, 11, 14
     actual = column_major_to_row_major(
         index=11,
         n=15,
         num_rows=3,
         num_cols=5,
     )
     self.assertEqual(actual, 13)
Ejemplo n.º 7
0
 def test_column_major_index_in_grid_last_row(self):
     # Test when the index is small enough to be within the upper, filled
     # grid.
     # This is the layout for displaying numbers from 0-9 with column
     # major setup:
     # 0  3  6  8
     # 1  4  7  9
     # 2  5  /  /
     # The index should be populated (row first) in this order:
     # 0, 3, 6, 8, 1, 4, 7, 9, 2, 5
     actual = column_major_to_row_major(
         index=4,
         n=10,
         num_rows=3,
         num_cols=4,
     )
     self.assertEqual(actual, 5)
Ejemplo n.º 8
0
def convert_index(layout, index):
    """ Helper function to convert an index for a QGridLayout so that the
    index counts over the grid in the correct direction.
    The grid is always populated in row major order, but it is done so in
    such a way that the entries appear in column major order.
    Qlayouts are indexed in the order they are populated, so to access
    the correct element we may need to convert a column-major based index
    into a row-major one.

    Parameters
    ----------
    layout : QGridLayout
        The layout of interest
    index : int
        the index of interest
    """
    n = layout.count()
    num_cols = layout.columnCount()
    num_rows = layout.rowCount()
    return column_major_to_row_major(index, n, num_rows, num_cols)