Exemplo n.º 1
0
    def test_get_merging_cell(self):
        """Test get_merging_cell"""

        selection_1 = Selection([(2, 2)], [(5, 5)], [], [], [])
        selection_2 = Selection([(3, 2)], [(9, 9)], [], [], [])
        selection_3 = Selection([(2, 2)], [(9, 9)], [], [], [])

        attr_dict_1 = AttrDict([("merge_area", (2, 2, 5, 5))])
        attr_dict_2 = AttrDict([("merge_area", (3, 2, 9, 9))])
        attr_dict_3 = AttrDict([("merge_area", (2, 2, 9, 9))])

        cell_attribute_1 = CellAttribute(selection_1, 0, attr_dict_1)
        cell_attribute_2 = CellAttribute(selection_2, 0, attr_dict_2)
        cell_attribute_3 = CellAttribute(selection_3, 1, attr_dict_3)

        self.cell_attr.append(cell_attribute_1)
        self.cell_attr.append(cell_attribute_2)
        self.cell_attr.append(cell_attribute_3)

        # Cell 1. 1, 0 is not merged
        assert self.cell_attr.get_merging_cell((1, 1, 0)) is None

        # Cell 3. 3, 0 is merged to cell 3, 2, 0
        assert self.cell_attr.get_merging_cell((3, 3, 0)) == (2, 2, 0)

        # Cell 2. 2, 0 is merged to cell 2, 2, 0
        assert self.cell_attr.get_merging_cell((2, 2, 0)) == (2, 2, 0)
Exemplo n.º 2
0
    def _adjust_merge_area(self, attrs, insertion_point, no_to_insert, axis):
        """Returns an updated merge area

        :param attrs: Cell attribute dictionary that shall be adjusted
        :type attrs: dict
        :param insertion_point: Point on axis before insertion takes place
        :type insertion_point: int
        :param no_to_insert: Number of rows/cols/tabs that shall be inserted
        :type no_to_insert: int, >=0
        :param axis: Specifies number of dimension, i.e. 0 == row, 1 == col
        :type axis: int in range(2)

        """

        assert axis in range(2)

        if "merge_area" not in attrs or attrs["merge_area"] is None:
            return

        top, left, bottom, right = attrs["merge_area"]
        selection = Selection([(top, left)], [(bottom, right)], [], [], [])

        selection.insert(insertion_point, no_to_insert, axis)

        __top, __left = selection.block_tl[0]
        __bottom, __right = selection.block_br[0]

        # Adjust merge area if it is beyond the grid shape
        rows, cols, tabs = self.shape

        if __top < 0 and __bottom < 0 or __top >= rows and __bottom >= rows or\
           __left < 0 and __right < 0 or __left >= cols and __right >= cols:
            return

        if __top < 0:
            __top = 0

        if __top >= rows:
            __top = rows - 1

        if __bottom < 0:
            __bottom = 0

        if __bottom >= rows:
            __bottom = rows - 1

        if __left < 0:
            __left = 0

        if __left >= cols:
            __left = cols - 1

        if __right < 0:
            __right = 0

        if __right >= cols:
            __right = cols - 1

        return __top, __left, __bottom, __right
Exemplo n.º 3
0
    def test_Selection_contains_mol5(self):
        """The Selection object ":Glu" does contain the molecule None."""

        # The Selection object.
        obj = Selection(":Glu")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_mol())
Exemplo n.º 4
0
    def test_Selection_contains_mol3(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the molecule 'XXX'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_mol('XXX'))
Exemplo n.º 5
0
    def test_Selection_range_contains_spinid2(self):
        """The Selection object ":1-70" does not contain the spin ':71@C'."""

        # The Selection object.
        obj = Selection(":1-70")

        # Check that the residue ID is in the selection.
        self.assert_(not obj.contains_spin_id(':71@C'))
Exemplo n.º 6
0
    def test_Selection_range_contains_spinid(self):
        """The Selection object ":1-70" contains the spin ':1@N'."""

        # The Selection object.
        obj = Selection(":1-70")

        # Check that the residue ID is in the selection.
        self.assert_(obj.contains_spin_id(':1@N'))
Exemplo n.º 7
0
    def test_Selection_contains_spin_re2(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the spin '*C*' of the mol 'RNA'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_spin(spin_name='*C*', mol='RNA'))
Exemplo n.º 8
0
    def test_Selection_contains_spin7(self):
        """The Selection object "#Ap4Aase" does not contain the spin None of the mol 'RNA'."""

        # The Selection object.
        obj = Selection("#Ap4Aase")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_spin(mol='RNA'))
Exemplo n.º 9
0
    def test_Selection_contains_spin6(self):
        """The Selection object "#Ap4Aase" does contains the spin None."""

        # The Selection object.
        obj = Selection("#Ap4Aase")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_spin(mol='Ap4Aase'))
Exemplo n.º 10
0
    def test_Selection_contains_spin5(self):
        """The Selection object "#Ap4Aase:Glu | #RNA:14@C8" does not contain the spin None."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA:14@C8")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_spin())
Exemplo n.º 11
0
    def test_Selection_contains_spin4(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the spin 'N3'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_spin(spin_name='N3'))
Exemplo n.º 12
0
    def test_Selection_contains_res_re2(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the res '*G*' of the mol 'Ap4Aase'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_res(res_name='*G*', mol='Ap4Aase'))
Exemplo n.º 13
0
    def test_Selection_contains_res4(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the res 'Ala'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_res(res_name='Ala'))
Exemplo n.º 14
0
    def test_Selection_contains_mol_re2(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the molecule '*R*'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_mol('*R*'))
Exemplo n.º 15
0
    def test_Selection_contains_mol5(self):
        """The Selection object ":Glu" does contain the molecule None."""

        # The Selection object.
        obj = Selection(":Glu")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_mol())
Exemplo n.º 16
0
    def test_Selection_contains_mol_re2(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the molecule '*R*'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_mol('*R*'))
Exemplo n.º 17
0
    def test_Selection_contains_res4(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the res 'Ala'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_res(res_name='Ala'))
Exemplo n.º 18
0
    def test_Selection_contains_spin4(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the spin 'N3'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_spin(spin_name='N3'))
Exemplo n.º 19
0
    def test_Selection_range_contains_spinid(self):
        """The Selection object ":1-70" contains the spin ':1@N'."""

        # The Selection object.
        obj = Selection(":1-70")

        # Check that the residue ID is in the selection.
        self.assert_(obj.contains_spin_id(':1@N'))
Exemplo n.º 20
0
    def test_Selection_contains_spin5(self):
        """The Selection object "#Ap4Aase:Glu | #RNA:14@C8" does not contain the spin None."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA:14@C8")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_spin())
Exemplo n.º 21
0
    def test_Selection_range_contains_spinid2(self):
        """The Selection object ":1-70" does not contain the spin ':71@C'."""

        # The Selection object.
        obj = Selection(":1-70")

        # Check that the residue ID is in the selection.
        self.assert_(not obj.contains_spin_id(':71@C'))
Exemplo n.º 22
0
    def test_Selection_contains_spin_re2(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the spin '*C*' of the mol 'RNA'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_spin(spin_name='*C*', mol='RNA'))
Exemplo n.º 23
0
    def test_Selection_contains_res_re2(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" contains the res '*G*' of the mol 'Ap4Aase'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_res(res_name='*G*', mol='Ap4Aase'))
Exemplo n.º 24
0
    def test_Selection_contains_spin7(self):
        """The Selection object "#Ap4Aase" does not contain the spin None of the mol 'RNA'."""

        # The Selection object.
        obj = Selection("#Ap4Aase")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_spin(mol='RNA'))
Exemplo n.º 25
0
    def test_Selection_contains_spin6(self):
        """The Selection object "#Ap4Aase" does contains the spin None."""

        # The Selection object.
        obj = Selection("#Ap4Aase")

        # Check if the molecule is in the selection.
        self.assert_(obj.contains_spin(mol='Ap4Aase'))
Exemplo n.º 26
0
    def test_Selection_contains_mol3(self):
        """The Selection object "#Ap4Aase:Glu | #RNA@C8" does not contain the molecule 'XXX'."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Check if the molecule is in the selection.
        self.assert_(not obj.contains_mol('XXX'))
Exemplo n.º 27
0
    def test_getitem(self):
        """Test __getitem__"""

        selection_1 = Selection([(2, 2)], [(4, 5)], [55], [55, 66], [(34, 56)])
        selection_2 = Selection([], [], [], [], [(32, 53), (34, 56)])

        self.cell_attr.append((selection_1, 0, {"testattr": 3}))
        self.cell_attr.append((selection_2, 0, {"testattr": 2}))

        assert self.cell_attr[32, 53, 0]["testattr"] == 2
        assert self.cell_attr[2, 2, 0]["testattr"] == 3
Exemplo n.º 28
0
    def redo(self):
        # Store content of deleted columns
        self.old_col_widths = copy(self.model.code_array.col_widths)
        self.old_cell_attributes = copy(self.model.code_array.cell_attributes)
        self.old_code = {}
        columns = list(range(self.first, self.last+1))
        selection = Selection([], [], [], columns, [])
        for key in selection.cell_generator(self.model.shape, self.grid.table):
            self.old_code[key] = self.model.code_array(key)

        with self.model.removing_columns(self.index, self.first, self.last):
            self.model.removeColumns(self.column, self.count)
        self.grid.table_choice.on_table_changed(self.grid.current)
Exemplo n.º 29
0
    def redo(self):
        # Store content of deleted rows
        self.old_row_heights = copy(self.model.code_array.row_heights)
        self.old_cell_attributes = copy(self.model.code_array.cell_attributes)
        self.old_code = {}
        rows = list(range(self.first, self.last+1))
        selection = Selection([], [], rows, [], [])
        for key in selection.cell_generator(self.model.shape, self.grid.table):
            self.old_code[key] = self.model.code_array(key)

        with self.model.removing_rows(self.index, self.first, self.last):
            self.model.removeRows(self.row, self.count)
        self.grid.table_choice.on_table_changed(self.grid.current)
Exemplo n.º 30
0
    def test_getitem(self):
        """Test __getitem__"""

        selection_1 = Selection([(2, 2)], [(4, 5)], [55], [55, 66], [(34, 56)])
        selection_2 = Selection([], [], [], [], [(32, 53), (34, 56)])

        ca1 = CellAttribute(selection_1, 0, AttrDict([("testattr", 3)]))
        ca2 = CellAttribute(selection_2, 0, AttrDict([("testattr", 2)]))

        self.cell_attr.append(ca1)
        self.cell_attr.append(ca2)

        assert self.cell_attr[32, 53, 0].testattr == 2
        assert self.cell_attr[2, 2, 0].testattr == 3
Exemplo n.º 31
0
    def test_Selection_memory(self):
        """Test that the Selection object has no memory of previous selections."""

        # The original Selection object.
        obj = Selection(":1@16")

        # The new Selection object.
        obj = Selection(":13")

        # Test the highest level object.
        self.assertEqual(obj._union, None)
        self.assertEqual(obj._intersect, None)
        self.assertEqual(obj.molecules, [])
        self.assertEqual(obj.residues, [13])
        self.assertEqual(obj.spins, [])
Exemplo n.º 32
0
    def test_Selection_boolean_or(self):
        """Test the Selection object for boolean '|' mol-res-spin selections."""

        # The Selection object.
        obj = Selection("#Ap4Aase:Glu | #RNA@C8")

        # Test the highest level object.
        self.assertNotEqual(obj._union, None)
        self.assertEqual(obj._intersect, None)
        self.assertEqual(obj.molecules, [])
        self.assertEqual(obj.residues, [])
        self.assertEqual(obj.spins, [])

        # Test the 1st union.
        self.assertEqual(obj._union[0]._union, None)
        self.assertEqual(obj._union[0]._intersect, None)
        self.assertEqual(obj._union[0].molecules, ['Ap4Aase'])
        self.assertEqual(obj._union[0].residues, ['Glu'])
        self.assertEqual(obj._union[0].spins, [])

        # Test the 2nd union.
        self.assertEqual(obj._union[1]._union, None)
        self.assertEqual(obj._union[1]._intersect, None)
        self.assertEqual(obj._union[1].molecules, ['RNA'])
        self.assertEqual(obj._union[1].residues, [])
        self.assertEqual(obj._union[1].spins, ['C8'])
Exemplo n.º 33
0
    def test_Selection_boolean_and(self):
        """Test the Selection object for boolean '&' mol-res-spin selections."""

        # The Selection object.
        obj = Selection("#Ap4Aase:4 & :Pro@Ca")

        # Test the highest level object.
        self.assertEqual(obj._union, None)
        self.assertNotEqual(obj._intersect, None)
        self.assertEqual(obj.molecules, [])
        self.assertEqual(obj.residues, [])
        self.assertEqual(obj.spins, [])

        # Test the first intersection.
        self.assertEqual(obj._intersect[0]._union, None)
        self.assertEqual(obj._intersect[0]._intersect, None)
        self.assertEqual(obj._intersect[0].molecules, ['Ap4Aase'])
        self.assertEqual(obj._intersect[0].residues, [4])
        self.assertEqual(obj._intersect[0].spins, [])

        # Test the second intersection.
        self.assertEqual(obj._intersect[1]._union, None)
        self.assertEqual(obj._intersect[1]._intersect, None)
        self.assertEqual(obj._intersect[1].molecules, [])
        self.assertEqual(obj._intersect[1].residues, ['Pro'])
        self.assertEqual(obj._intersect[1].spins, ['Ca'])
Exemplo n.º 34
0
    def _code_convert_1_2(self, key, code):
        """Converts chart and image code from v1.0 to v2.0"""
        def get_image_code(image_data, width, height):
            """Returns code string for v2.0"""

            image_buffer_tpl = 'bz2.decompress(base64.b85decode({data}))'
            image_array_tpl = 'numpy.frombuffer({buffer}, dtype="uint8")'
            image_matrix_tpl = '{array}.reshape({height}, {width}, 3)'

            image_buffer = image_buffer_tpl.format(data=image_data)
            image_array = image_array_tpl.format(buffer=image_buffer)
            image_matrix = image_matrix_tpl.format(array=image_array,
                                                   height=height,
                                                   width=width)

            return image_matrix

        start_str = "bz2.decompress(base64.b64decode('"
        size_start_str = "wx.ImageFromData("
        if size_start_str in code and start_str in code:
            size_start = code.index(size_start_str) + len(size_start_str)
            size_str_list = code[size_start:].split(",")[:2]
            width, height = tuple(map(int, size_str_list))

            # We have a cell that displays a bitmap
            data_start = code.index(start_str) + len(start_str)
            data_stop = code.find("'", data_start)
            enc_data = bytes(code[data_start:data_stop], encoding='utf-8')
            compressed_image_data = b64decode(enc_data)
            reenc_data = b85encode(compressed_image_data)
            code = get_image_code(repr(reenc_data), width, height)

            selection = Selection([], [], [], [], [(key[0], key[1])])
            tab = key[2]
            attrs = {"renderer": "image"}
            self.cell_attributes_postfixes.append((selection, tab, attrs))

        elif "charts.ChartFigure(" in code:
            # We have a matplotlib figure
            selection = Selection([], [], [], [], [(key[0], key[1])])
            tab = key[2]
            attrs = {"renderer": "matplotlib"}
            self.cell_attributes_postfixes.append((selection, tab, attrs))

        return code
Exemplo n.º 35
0
def sel_domain(domain_id=None, boolean='OR', change_all=False):
    """Select all spins and interatomic data containers of the given domain.

    @keyword domain_id:     The domain ID string.
    @type domain_id:        str or None
    @param boolean:         The boolean operator used to select the spin systems with.  It can be one of 'OR', 'NOR', 'AND', 'NAND', 'XOR', or 'XNOR'. This will be ignored if the change_all flag is set.
    @type boolean:          str
    @keyword change_all:    A flag which if True will cause all spins and interatomic data containers outside of the domain to be deselected.
    @type change_all:       bool
    """

    # Test if the current data pipe exists.
    check_pipe()

    # Test if the domain is defined.
    if not hasattr(cdp, 'domain') or domain_id not in cdp.domain:
        raise RelaxNoDomainError(domain_id)

    # The domain selection object.
    domain = Selection(cdp.domain[domain_id])

    # Loop over the spins and select as required.
    for spin, mol_name, res_num, res_name in spin_loop(full_info=True):
        # Inside the domain.
        if domain.contains_spin(spin_name=spin.name, spin_num=spin.num, res_name=res_name, res_num=res_num, mol=mol_name):
            spin.select = boolean_select(current=spin.select, boolean=boolean)

        # Deselect spins outside of the domain.
        elif change_all:
            spin.select = False

    # Interatomic data loop.
    for interatom in interatomic_loop():
        # Decode the spin ids.
        mol_name1, res_num1, res_name1, spin_num1, spin_name1 = spin_id_to_data_list(interatom.spin_id1)
        mol_name2, res_num2, res_name2, spin_num2, spin_name2 = spin_id_to_data_list(interatom.spin_id2)

        # Inside the domain.
        if domain.contains_spin(spin_name=spin_name1, spin_num=spin_num1, res_name=res_name1, res_num=res_num1, mol=mol_name1) or domain.contains_spin(spin_name=spin_name2, spin_num=spin_num2, res_name=res_name2, res_num=res_num2, mol=mol_name2):
            interatom.select = boolean_select(current=interatom.select, boolean=boolean)

        # Deselect containers outside of the domain.
        elif change_all:
            interatom.select = False
Exemplo n.º 36
0
def sel_domain(domain_id=None, boolean='OR', change_all=False):
    """Select all spins and interatomic data containers of the given domain.

    @keyword domain_id:     The domain ID string.
    @type domain_id:        str or None
    @param boolean:         The boolean operator used to select the spin systems with.  It can be one of 'OR', 'NOR', 'AND', 'NAND', 'XOR', or 'XNOR'. This will be ignored if the change_all flag is set.
    @type boolean:          str
    @keyword change_all:    A flag which if True will cause all spins and interatomic data containers outside of the domain to be deselected.
    @type change_all:       bool
    """

    # Test if the current data pipe exists.
    pipes.test()

    # Test if the domain is defined.
    if not hasattr(cdp, 'domain') or domain_id not in cdp.domain:
        raise RelaxNoDomainError(domain_id)

    # The domain selection object.
    domain = Selection(cdp.domain[domain_id])

    # Loop over the spins and select as required.
    for spin, mol_name, res_num, res_name in spin_loop(full_info=True):
        # Inside the domain.
        if domain.contains_spin(spin_name=spin.name, spin_num=spin.num, res_name=res_name, res_num=res_num, mol=mol_name):
            spin.select = boolean_select(current=spin.select, boolean=boolean)

        # Deselect spins outside of the domain.
        elif change_all:
            spin.select = False

    # Interatomic data loop.
    for interatom in interatomic_loop():
        # Decode the spin ids.
        mol_name1, res_num1, res_name1, spin_num1, spin_name1 = spin_id_to_data_list(interatom.spin_id1)
        mol_name2, res_num2, res_name2, spin_num2, spin_name2 = spin_id_to_data_list(interatom.spin_id2)

        # Inside the domain.
        if domain.contains_spin(spin_name=spin_name1, spin_num=spin_num1, res_name=res_name1, res_num=res_num1, mol=mol_name1) or domain.contains_spin(spin_name=spin_name2, spin_num=spin_num2, res_name=res_name2, res_num=res_num2, mol=mol_name2):
            interatom.select = boolean_select(current=interatom.select, boolean=boolean)

        # Deselect containers outside of the domain.
        elif change_all:
            interatom.select = False
Exemplo n.º 37
0
    def test_get_merging_cell(self):
        """Test get_merging_cell"""

        selection_1 = Selection([(2, 2)], [(5, 5)], [], [], [])
        selection_2 = Selection([(3, 2)], [(9, 9)], [], [], [])
        selection_3 = Selection([(2, 2)], [(9, 9)], [], [], [])

        self.cell_attr.append((selection_1, 0, {"merge_area": (2, 2, 5, 5)}))
        self.cell_attr.append((selection_2, 0, {"merge_area": (3, 2, 9, 9)}))
        self.cell_attr.append((selection_3, 1, {"merge_area": (2, 2, 9, 9)}))

        # Cell 1. 1, 0 is not merged
        assert self.cell_attr.get_merging_cell((1, 1, 0)) is None

        # Cell 3. 3, 0 is merged to cell 3, 2, 0
        assert self.cell_attr.get_merging_cell((3, 3, 0)) == (2, 2, 0)

        # Cell 2. 2, 0 is merged to cell 2, 2, 0
        assert self.cell_attr.get_merging_cell((2, 2, 0)) == (2, 2, 0)
Exemplo n.º 38
0
    def _pys2attributes_10(self, line):
        """Updates attributes in code_array - for save file version 1.0"""

        splitline = self._split_tidy(line)

        selection_data = list(map(ast.literal_eval, splitline[:5]))
        selection = Selection(*selection_data)

        tab = int(splitline[5])

        attrs = {}

        old_merged_cells = {}

        for col, ele in enumerate(splitline[6:]):
            if not (col % 2):
                # Odd entries are keys
                key = ast.literal_eval(ele)

            else:
                # Even cols are values
                value = ast.literal_eval(ele)

                # Convert old wx color values and merged cells
                key_, value_ = self._attr_convert_1to2(key, value)

                if key_ is None and value_ is not None:
                    # We have a merged cell
                    old_merged_cells[value_[:2]] = value_
                try:
                    attrs.pop("merge_area")
                except KeyError:
                    pass
                attrs[key_] = value_

        self.code_array.cell_attributes.append((selection, tab, attrs))

        for key in old_merged_cells:
            selection = Selection([], [], [], [], [key])
            attrs = {"merge_area": old_merged_cells[key]}
            self.code_array.cell_attributes.append((selection, tab, attrs))
        old_merged_cells.clear()
Exemplo n.º 39
0
    def _pys2attributes(self, line):
        """Updates attributes in code_array"""

        splitline = self._split_tidy(line)

        selection_data = list(map(ast.literal_eval, splitline[:5]))
        selection = Selection(*selection_data)

        tab = int(splitline[5])

        attrs = {}
        for col, ele in enumerate(splitline[6:]):
            if not (col % 2):
                # Odd entries are keys
                key = ast.literal_eval(ele)

            else:
                # Even cols are values
                value = ast.literal_eval(ele)

                # Convert old wx color values
                if self.version <= 1.0:
                    color_attrs = [
                        "bordercolor_bottom", "bordercolor_right", "bgcolor",
                        "textcolor"
                    ]
                    if key in color_attrs:
                        value = wxcolor2rgb(value)

                    elif key == "fontweight":
                        value = wx2qt_fontweights[value]

                    elif key == "fontstyle":
                        value = wx2qt_fontstyles[value]

                    elif key == "markup" and value:
                        key = "renderer"
                        value = "markup"

                    # Update justifiaction and alignment values
                    elif key in ["vertical_align", "justification"]:
                        just_align_value_tansitions = {
                            "left": "justify_left",
                            "center": "justify_center",
                            "right": "justify_right",
                            "top": "align_top",
                            "middle": "align_center",
                            "bottom": "align_bottom",
                        }
                        value = just_align_value_tansitions[value]

                attrs[key] = value

        self.code_array.cell_attributes.append((selection, tab, attrs))
Exemplo n.º 40
0
    def test_append(self):
        """Test append"""

        selection = Selection([], [], [], [], [(23, 12)])
        table = 0
        attr = AttrDict([("angle", 0.2)])

        self.cell_attr.append(CellAttribute(selection, table, attr))

        # Check if 1 item - the actual action has been added
        assert not self.cell_attr._attr_cache
Exemplo n.º 41
0
    def test_set_cell_attributes(self):
        """Unit test for _set_cell_attributes"""

        cell_attributes = self.data_array.cell_attributes

        attr = CellAttribute(Selection([], [], [], [], []), 0,
                             AttrDict([("Test", None)]))
        cell_attributes.clear()
        cell_attributes.append(attr)

        assert self.data_array.cell_attributes == cell_attributes
Exemplo n.º 42
0
    def redo(self):
        row, column, table = current = self.current

        # Remove and store frozen cache content
        self.res_obj = self.model.code_array.frozen_cache.pop(repr(current))

        # Remove the frozen state
        selection = Selection([], [], [], [], [(row, column)])
        attr = selection, table, {"frozen": False}
        self.model.setData([], attr, Qt.DecorationRole)
        self.model.dataChanged.emit(QModelIndex(), QModelIndex())
Exemplo n.º 43
0
    def test_append(self):
        """Test append"""

        selection = Selection([], [], [], [], [(23, 12)])
        table = 0
        attr = {"angle": 0.2}

        self.cell_attr.append((selection, table, attr))

        # Check if 1 item - the actual action has been added
        assert not self.cell_attr._attr_cache